From dd4cbb3591d20498e6410f1156f4f99e306ad73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20K=C3=BCmmel?= Date: Mon, 21 Dec 2009 11:48:19 +0000 Subject: [PATCH] - Show progress information in status bar. - Remove progress view because ATM we don't have to show anything usefull. - move Alert:: void functions into GUI thread git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32604 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ui/stdmenus.inc | 1 - src/frontends/qt4/GuiAlert.cpp | 90 +++++++++++++------------------ src/frontends/qt4/GuiProgress.cpp | 88 ++++++++++++++++++++---------- src/frontends/qt4/GuiProgress.h | 42 +++++++-------- src/frontends/qt4/GuiView.cpp | 18 +++++-- src/support/ProgressInterface.h | 7 +++ src/support/Systemcall.cpp | 11 +++- 7 files changed, 146 insertions(+), 111 deletions(-) diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc index c391338aa5..436a0ca316 100644 --- a/lib/ui/stdmenus.inc +++ b/lib/ui/stdmenus.inc @@ -315,7 +315,6 @@ Menuset OptItem "View Master Document|M" "master-buffer-view" OptItem "Update Master Document|a" "master-buffer-update" Separator - Item "Show process messages" "dialog-toggle progress" Item "Split View Into Left and Right Half|i" "split-view horizontal" Item "Split View Into Upper and Lower Half|e" "split-view vertical" Item "Close Current View|w" "close-tab-group" diff --git a/src/frontends/qt4/GuiAlert.cpp b/src/frontends/qt4/GuiAlert.cpp index 983d58d1c1..fdb2065c08 100644 --- a/src/frontends/qt4/GuiAlert.cpp +++ b/src/frontends/qt4/GuiAlert.cpp @@ -14,17 +14,18 @@ #include "alert.h" + #include "frontends/Application.h" #include "qt_helpers.h" #include "LyX.h" // for lyx::use_gui #include "ui_AskForTextUi.h" -#include "ui_ToggleWarningUi.h" #include "support/gettext.h" #include "support/debug.h" #include "support/docstring.h" #include "support/lstrings.h" +#include "support/ProgressInterface.h" #include #include @@ -43,15 +44,6 @@ namespace lyx { namespace frontend { -class GuiToggleWarningDialog : public QDialog, public Ui::ToggleWarningUi -{ -public: - GuiToggleWarningDialog(QWidget * parent) : QDialog(parent) - { - Ui::ToggleWarningUi::setupUi(this); - QDialog::setModal(true); - } -}; static docstring const formatted(docstring const & text) @@ -114,26 +106,18 @@ static docstring const formatted(docstring const & text) } -void toggleWarning(docstring const & title, docstring const & msg) +void noAppDialog(QString const & title, QString const & msg, QMessageBox::Icon mode) { - if (!use_gui) - return; - - QSettings settings; - if (settings.value("hidden_warnings/" + toqstr(msg), false).toBool()) - return; - - GuiToggleWarningDialog * dlg = - new GuiToggleWarningDialog(qApp->focusWidget()); - - dlg->setWindowTitle(toqstr(title)); - dlg->messageLA->setText(toqstr(formatted(msg))); - dlg->dontShowAgainCB->setChecked(false); - - if (dlg->exec() == QDialog::Accepted) - if (dlg->dontShowAgainCB->isChecked()) - settings.setValue("hidden_warnings/" - + toqstr(msg), true); + int argc = 1; + char * argv[1]; + QApplication app(argc, argv); + switch (mode) + { + case QMessageBox::Information: QMessageBox::information(0, title, msg); break; + case QMessageBox::Warning: QMessageBox::warning(0, title, msg); break; + case QMessageBox::Critical: QMessageBox::critical(0, title, msg); break; + default: break; + } } @@ -196,26 +180,23 @@ void warning(docstring const & title0, docstring const & message, docstring const title = bformat(_("LyX: %1$s"), title0); if (theApp() == 0) { - int argc = 1; - char * argv[1]; - QApplication app(argc, argv); - QMessageBox::warning(0, - toqstr(title), - toqstr(formatted(message))); + noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Warning); return; } - if (!askshowagain) - QMessageBox::warning(qApp->focusWidget(), + + if (!askshowagain) { + ProgressInterface::instance()->warning( toqstr(title), toqstr(formatted(message))); - else - toggleWarning(title, message); + } else { + ProgressInterface::instance()->toggleWarning( + toqstr(title), + toqstr(message), + toqstr(formatted(message))); + } } -int argc = 1; -char * argv[1]; - void error(docstring const & title0, docstring const & message) { lyxerr << "Error: " << title0 << '\n' @@ -226,16 +207,15 @@ void error(docstring const & title0, docstring const & message) return; docstring const title = bformat(_("LyX: %1$s"), title0); + if (theApp() == 0) { - QApplication app(argc, argv); - QMessageBox::critical(0, - toqstr(title), - toqstr(formatted(message))); + noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Critical); return; } - QMessageBox::critical(qApp->focusWidget(), - toqstr(title), - toqstr(formatted(message))); + + ProgressInterface::instance()->error( + toqstr(title), + toqstr(formatted(message))); } @@ -250,9 +230,15 @@ void information(docstring const & title0, docstring const & message) return; docstring const title = bformat(_("LyX: %1$s"), title0); - QMessageBox::information(qApp->focusWidget(), - toqstr(title), - toqstr(formatted(message))); + + if (theApp() == 0) { + noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Information); + return; + } + + ProgressInterface::instance()->information( + toqstr(title), + toqstr(formatted(message))); } diff --git a/src/frontends/qt4/GuiProgress.cpp b/src/frontends/qt4/GuiProgress.cpp index b421616ab4..c6c5506bd0 100644 --- a/src/frontends/qt4/GuiProgress.cpp +++ b/src/frontends/qt4/GuiProgress.cpp @@ -12,51 +12,74 @@ #include #include "GuiProgress.h" +#include "ui_ToggleWarningUi.h" #include "qt_helpers.h" #include "support/Systemcall.h" #include -#include +#include +#include + namespace lyx { namespace frontend { - -GuiProgress::GuiProgress(GuiView & parent, Qt::DockWidgetArea area, - Qt::WindowFlags flags) : DockView(parent, "progress", "External tools", area, flags) +class GuiToggleWarningDialog : public QDialog, public Ui::ToggleWarningUi { - setWindowTitle(qt_("Tool monitoring")); - setWidget(&text_edit); - text_edit.setReadOnly(true); +public: + GuiToggleWarningDialog(QWidget * parent) : QDialog(parent) + { + Ui::ToggleWarningUi::setupUi(this); + QDialog::setModal(true); + } +}; + + + +GuiProgress::GuiProgress(GuiView * view) : view_(view) +{ connect(this, SIGNAL(processStarted(QString const &)), SLOT(doProcessStarted(QString const &))); connect(this, SIGNAL(processFinished(QString const &)), SLOT(doProcessFinished(QString const &))); connect(this, SIGNAL(appendMessage(QString const &)), SLOT(doAppendMessage(QString const &))); connect(this, SIGNAL(appendError(QString const &)), SLOT(doAppendError(QString const &))); connect(this, SIGNAL(clearMessages()), SLOT(doClearMessages())); + + // Alert interface + connect(this, SIGNAL(warning(QString const &, QString const &)), + SLOT(doWarning(QString const &, QString const &))); + connect(this, SIGNAL(toggleWarning(QString const &, QString const &, QString const &)), + SLOT(doToggleWarning(QString const &, QString const &, QString const &))); + connect(this, SIGNAL(error(QString const &, QString const &)), + SLOT(doError(QString const &, QString const &))); + connect(this, SIGNAL(information(QString const &, QString const &)), + SLOT(doInformation(QString const &, QString const &))); + + support::ProgressInterface::setInstance(this); } void GuiProgress::doProcessStarted(QString const & cmd) { - appendText("Process started : " + cmd + "\n"); + QString time = QTime::currentTime().toString(Qt::SystemLocaleShortDate); + appendText(time + ": <" + cmd + "> started\n"); } void GuiProgress::doProcessFinished(QString const & cmd) { - appendText("Process finished: " + cmd + "\n"); + QString time = QTime::currentTime().toString(Qt::SystemLocaleShortDate); + appendText(time + ": <" + cmd + "> done\n"); } void GuiProgress::doAppendMessage(QString const & msg) { - // No good messages from the processes - //appendText(msg); + appendText(msg); } @@ -68,42 +91,53 @@ void GuiProgress::doAppendError(QString const & msg) void GuiProgress::doClearMessages() { - text_edit.clear(); + view_->message(docstring()); } void GuiProgress::appendText(QString const & text) { - text_edit.insertPlainText(text); - text_edit.ensureCursorVisible(); + view_->message(qstring_to_ucs4(text)); } -void GuiProgress::showEvent(QShowEvent*) +void GuiProgress::doWarning(QString const & title, QString const & message) { - support::ProgressInterface::setInstance(this); + QMessageBox::warning(qApp->focusWidget(), title, message); } -void GuiProgress::hideEvent(QHideEvent*) +void GuiProgress::doToggleWarning(QString const & title, QString const & msg, QString const & formatted) { - support::ProgressInterface::setInstance(0); + QSettings settings; + if (settings.value("hidden_warnings/" + msg, false).toBool()) + return; + + GuiToggleWarningDialog * dlg = + new GuiToggleWarningDialog(qApp->focusWidget()); + + dlg->setWindowTitle(title); + dlg->messageLA->setText(formatted); + dlg->dontShowAgainCB->setChecked(false); + + if (dlg->exec() == QDialog::Accepted) + if (dlg->dontShowAgainCB->isChecked()) + settings.setValue("hidden_warnings/" + + msg, true); } - -Dialog * createGuiProgress(GuiView & lv) +void GuiProgress::doError(QString const & title, QString const & message) { - GuiView & guiview = static_cast(lv); -#ifdef Q_WS_MACX - // TODO where to show up on the Mac? - //return new GuiProgress(guiview, Qt::RightDockWidgetArea, Qt::Drawer); -#else - return new GuiProgress(guiview, Qt::BottomDockWidgetArea); -#endif + QMessageBox::critical(qApp->focusWidget(), title, message); } +void GuiProgress::doInformation(QString const & title, QString const & message) +{ + QMessageBox::information(qApp->focusWidget(), title, message); +} + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiProgress.h b/src/frontends/qt4/GuiProgress.h index 79891548c1..a47eb74986 100644 --- a/src/frontends/qt4/GuiProgress.h +++ b/src/frontends/qt4/GuiProgress.h @@ -27,17 +27,15 @@ namespace lyx { namespace frontend { -class GuiProgress : - public DockView, - public lyx::support::ProgressInterface +class GuiProgress : + public QObject, + public lyx::support::ProgressInterface { - Q_OBJECT + public: - GuiProgress( - GuiView & parent, ///< the main window where to dock. - Qt::DockWidgetArea area, ///< Position of the dock (and also drawer) - Qt::WindowFlags flags = 0); + GuiProgress(GuiView * view); + Q_SIGNALS: void processStarted(QString const &); @@ -46,6 +44,12 @@ Q_SIGNALS: void appendError(QString const &); void clearMessages(); + // Alert interface + void warning(QString const & title, QString const & message); + void toggleWarning(QString const & title, QString const & msg, QString const & formatted); + void error(QString const & title, QString const & message); + void information(QString const & title, QString const & message); + private Q_SLOTS: void doProcessStarted(QString const &); void doProcessFinished(QString const &); @@ -53,25 +57,15 @@ private Q_SLOTS: void doAppendError(QString const &); void doClearMessages(); -public: - /// Controller inherited method. - ///@{ - bool initialiseParams(std::string const &) { return true; } - void clearParams() {} - void dispatchParams() {} - bool isBufferDependent() const { return false; } - bool canApply() const { return true; } - bool canApplyToReadOnly() const { return true; } - void updateView() {} - ///@} - - void showEvent(QShowEvent*); - void hideEvent(QHideEvent*); + void doWarning(QString const &, QString const &); + void doToggleWarning(QString const & title, QString const & msg, QString const & formatted); + void doError(QString const &, QString const &); + void doInformation(QString const &, QString const &); + private: - QTextEdit text_edit; - + GuiView* view_; void appendText(QString const &); }; diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index de7d60e125..373e015c6b 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -77,6 +77,7 @@ #include "support/Systemcall.h" #include "support/Timeout.h" #include "support/ProgressInterface.h" +#include "GuiProgress.h" #include #include @@ -192,6 +193,7 @@ struct GuiView::GuiViewPrivate stack_widget_->addWidget(bg_widget_); stack_widget_->addWidget(splitter_); setBackground(); + progress = new GuiProgress(gv); } ~GuiViewPrivate() @@ -199,6 +201,7 @@ struct GuiView::GuiViewPrivate delete splitter_; delete bg_widget_; delete stack_widget_; + delete progress; } QMenu * toolBarPopup(GuiView * parent) @@ -284,6 +287,7 @@ public: BackgroundWidget * bg_widget_; /// view's toolbars ToolbarMap toolbars_; + GuiProgress* progress; /// The main layout box. /** * \warning Don't Delete! The layout box is actually owned by @@ -1420,7 +1424,6 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag) || name == "file" //FIXME: should be removed. || name == "prefs" || name == "texinfo" - || name == "progress" || name == "compare"; else if (name == "print") enable = doc_buffer->isExportable("dvi") @@ -2691,6 +2694,9 @@ bool GuiView::dispatch(FuncRequest const & cmd) if (argument.empty()) format = doc_buffer->getDefaultOutputFormat(); #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400) + ProgressInterface::instance()->clearMessages(); + QString time = QTime::currentTime().toString(Qt::SystemLocaleShortDate); + ProgressInterface::instance()->appendMessage(time + ": Exporting ...\n"); QFuture f = QtConcurrent::run(exportAndDestroy, doc_buffer->clone(), format); d.setPreviewFuture(f); @@ -2706,6 +2712,9 @@ bool GuiView::dispatch(FuncRequest const & cmd) if (argument.empty()) format = doc_buffer->getDefaultOutputFormat(); #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400) + ProgressInterface::instance()->clearMessages(); + QString time = QTime::currentTime().toString(Qt::SystemLocaleShortDate); + ProgressInterface::instance()->appendMessage(time + ": Previewing ...\n"); QFuture f = QtConcurrent::run(previewAndDestroy, doc_buffer->clone(), format); d.setPreviewFuture(f); @@ -3175,7 +3184,7 @@ char const * const dialognames[] = { "mathmatrix", "mathspace", "nomenclature", "nomencl_print", "note", "paragraph", "phantom", "prefs", "print", "ref", "sendto", "space", "spellchecker", "symbols", "tabular", "tabularcreate", "thesaurus", "texinfo", -"toc", "view-source", "vspace", "wrap", "progress" }; +"toc", "view-source", "vspace", "wrap"}; char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -3373,7 +3382,8 @@ Dialog * createGuiHyperlink(GuiView & lv); Dialog * createGuiVSpace(GuiView & lv); Dialog * createGuiViewSource(GuiView & lv); Dialog * createGuiWrap(GuiView & lv); -Dialog * createGuiProgress(GuiView & lv); + + Dialog * GuiView::build(string const & name) { @@ -3477,8 +3487,6 @@ Dialog * GuiView::build(string const & name) return createGuiVSpace(*this); if (name == "wrap") return createGuiWrap(*this); - if (name == "progress") - return createGuiProgress(*this); return 0; } diff --git a/src/support/ProgressInterface.h b/src/support/ProgressInterface.h index 4199fd82ae..1fdd3b417b 100644 --- a/src/support/ProgressInterface.h +++ b/src/support/ProgressInterface.h @@ -31,6 +31,13 @@ public: virtual void appendError(QString const &) = 0; virtual void clearMessages() = 0; + // Alert interface + virtual void warning(QString const & title, QString const & message) = 0; + virtual void toggleWarning(QString const & title, QString const & msg, QString const & formatted) = 0; + virtual void error(QString const & title, QString const & message) = 0; + virtual void information(QString const & title, QString const & message) = 0; + + static void setInstance(ProgressInterface*); static ProgressInterface* instance(); diff --git a/src/support/Systemcall.cpp b/src/support/Systemcall.cpp index 2a1154cf2d..5ba04cce4a 100644 --- a/src/support/Systemcall.cpp +++ b/src/support/Systemcall.cpp @@ -61,6 +61,11 @@ public: void appendMessage(QString const &) {} void appendError(QString const &) {} void clearMessages() {} + + void warning(QString const &, QString const &) {} + void toggleWarning(QString const &, QString const &, QString const &) {} + void error(QString const &, QString const &) {} + void information(QString const &, QString const &) {} }; @@ -369,8 +374,10 @@ void SystemcallPrivate::stdOut() } } const QString data = QString::fromLocal8Bit(outdata_); - if (!data.isEmpty()) - ProgressInterface::instance()->appendMessage(data); + if (!data.isEmpty()) { + // TODO No good messages from the processes. Disable batch mode? + //ProgressInterface::instance()->appendMessage(data); + } processEvents(); }