From 8049e3f510b547224ef392b658a3d03693743b1a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Peter=20K=C3=BCmmel?= Date: Mon, 21 Dec 2009 13:11:17 +0000 Subject: [PATCH] move calls to Buffer::errors and Buffer::message to GUI thread git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32606 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 2 +- src/frontends/qt4/GuiProgress.cpp | 2 +- src/frontends/qt4/GuiView.cpp | 28 ++++++++++++++++++++++++---- src/frontends/qt4/GuiView.h | 13 ++++++++++++- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 6da2e91de7..9768b48009 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -350,7 +350,7 @@ Buffer::~Buffer() if (!isClean()) { docstring msg = _("LyX attempted to close a document that had unsaved changes!\n"); msg += emergencyWrite(); - frontend::Alert::warning(_("Attempting to close changed document!"), msg); + Alert::warning(_("Attempting to close changed document!"), msg); } // clear references to children in macro tables diff --git a/src/frontends/qt4/GuiProgress.cpp b/src/frontends/qt4/GuiProgress.cpp index c6c5506bd0..35bcb0e23f 100644 --- a/src/frontends/qt4/GuiProgress.cpp +++ b/src/frontends/qt4/GuiProgress.cpp @@ -97,7 +97,7 @@ void GuiProgress::doClearMessages() void GuiProgress::appendText(QString const & text) { - view_->message(qstring_to_ucs4(text)); + view_->updateMessage(text); } diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 373e015c6b..57339ee1d1 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -193,7 +193,7 @@ struct GuiView::GuiViewPrivate stack_widget_->addWidget(bg_widget_); stack_widget_->addWidget(splitter_); setBackground(); - progress = new GuiProgress(gv); + progress_ = new GuiProgress(gv); } ~GuiViewPrivate() @@ -201,7 +201,7 @@ struct GuiView::GuiViewPrivate delete splitter_; delete bg_widget_; delete stack_widget_; - delete progress; + delete progress_; } QMenu * toolBarPopup(GuiView * parent) @@ -287,7 +287,7 @@ public: BackgroundWidget * bg_widget_; /// view's toolbars ToolbarMap toolbars_; - GuiProgress* progress; + ProgressInterface* progress_; /// The main layout box. /** * \warning Don't Delete! The layout box is actually owned by @@ -385,6 +385,9 @@ GuiView::GuiView(int id) connect(&d.autosave_watcher_, SIGNAL(finished()), this, SLOT(threadFinished())); #endif + + connect(this, SIGNAL(triggerShowDialog(QString const &, QString const &, Inset *)), + SLOT(doShowDialog(QString const &, QString const &, Inset *))); } @@ -697,8 +700,15 @@ void GuiView::message(docstring const & str) { if (ForkedProcess::iAmAChild()) return; + + // call is moved to GUI-thread by GuiProgress + d.progress_->appendMessage(toqstr(str)); +} - statusBar()->showMessage(toqstr(str)); + +void GuiView::updateMessage(QString const & str) +{ + statusBar()->showMessage(str); d.statusbar_timer_.stop(); d.statusbar_timer_.start(3000); } @@ -3250,10 +3260,20 @@ Dialog * GuiView::findOrBuild(string const & name, bool hide_it) void GuiView::showDialog(string const & name, string const & data, Inset * inset) +{ + triggerShowDialog(toqstr(name), toqstr(data), inset); +} + + +void GuiView::doShowDialog(QString const & qname, QString const & qdata, + Inset * inset) { if (d.in_show_) return; + const string name = fromqstr(qname); + const string data = fromqstr(qdata); + d.in_show_ = true; try { Dialog * dialog = findOrBuild(name, false); diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 02bb82dfb9..44d491e80c 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -72,7 +72,12 @@ public: BufferView const * documentBufferView() const; void newDocument(std::string const & filename, bool fromTemplate); + + /// could be called from any thread void message(docstring const &); + /// must be called from GUI thread + void updateMessage(QString const & str); + bool getStatus(FuncRequest const & cmd, FuncStatus & flag); bool dispatch(FuncRequest const & cmd); void restartCursor(); @@ -158,6 +163,7 @@ public: Q_SIGNALS: void closing(int); + void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset); public Q_SLOTS: /// idle timeout. @@ -183,6 +189,10 @@ private Q_SLOTS: /// For completion of autosave or exporrt threads. void threadFinished(); + /// must be called in GUI thread + void doShowDialog(QString const & qname, QString const & qdata, + Inset * inset); + private: /// Open given child document in current buffer directory. void openChildDocument(std::string const & filename); @@ -243,7 +253,8 @@ public: */ void updateDialogs(); - /** \param name == "bibtex", "citation" etc; an identifier used to + /** Show dialog could be called from arbitrary threads. + \param name == "bibtex", "citation" etc; an identifier used to launch a particular dialog. \param data is a string representation of the Inset contents. It is often little more than the output from Inset::write. -- 2.39.2