- 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
This commit is contained in:
Peter Kümmel 2009-12-21 11:48:19 +00:00
parent 363809c7e0
commit dd4cbb3591
7 changed files with 146 additions and 111 deletions

View File

@ -315,7 +315,6 @@ Menuset
OptItem "View Master Document|M" "master-buffer-view" OptItem "View Master Document|M" "master-buffer-view"
OptItem "Update Master Document|a" "master-buffer-update" OptItem "Update Master Document|a" "master-buffer-update"
Separator Separator
Item "Show process messages" "dialog-toggle progress"
Item "Split View Into Left and Right Half|i" "split-view horizontal" 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 "Split View Into Upper and Lower Half|e" "split-view vertical"
Item "Close Current View|w" "close-tab-group" Item "Close Current View|w" "close-tab-group"

View File

@ -14,17 +14,18 @@
#include "alert.h" #include "alert.h"
#include "frontends/Application.h" #include "frontends/Application.h"
#include "qt_helpers.h" #include "qt_helpers.h"
#include "LyX.h" // for lyx::use_gui #include "LyX.h" // for lyx::use_gui
#include "ui_AskForTextUi.h" #include "ui_AskForTextUi.h"
#include "ui_ToggleWarningUi.h"
#include "support/gettext.h" #include "support/gettext.h"
#include "support/debug.h" #include "support/debug.h"
#include "support/docstring.h" #include "support/docstring.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/ProgressInterface.h"
#include <QApplication> #include <QApplication>
#include <QCheckBox> #include <QCheckBox>
@ -43,15 +44,6 @@ namespace lyx {
namespace frontend { 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) 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) int argc = 1;
return; char * argv[1];
QApplication app(argc, argv);
QSettings settings; switch (mode)
if (settings.value("hidden_warnings/" + toqstr(msg), false).toBool()) {
return; case QMessageBox::Information: QMessageBox::information(0, title, msg); break;
case QMessageBox::Warning: QMessageBox::warning(0, title, msg); break;
GuiToggleWarningDialog * dlg = case QMessageBox::Critical: QMessageBox::critical(0, title, msg); break;
new GuiToggleWarningDialog(qApp->focusWidget()); default: break;
}
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);
} }
@ -196,26 +180,23 @@ void warning(docstring const & title0, docstring const & message,
docstring const title = bformat(_("LyX: %1$s"), title0); docstring const title = bformat(_("LyX: %1$s"), title0);
if (theApp() == 0) { if (theApp() == 0) {
int argc = 1; noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Warning);
char * argv[1];
QApplication app(argc, argv);
QMessageBox::warning(0,
toqstr(title),
toqstr(formatted(message)));
return; return;
} }
if (!askshowagain)
QMessageBox::warning(qApp->focusWidget(), if (!askshowagain) {
ProgressInterface::instance()->warning(
toqstr(title), toqstr(title),
toqstr(formatted(message))); toqstr(formatted(message)));
else } else {
toggleWarning(title, message); ProgressInterface::instance()->toggleWarning(
toqstr(title),
toqstr(message),
toqstr(formatted(message)));
}
} }
int argc = 1;
char * argv[1];
void error(docstring const & title0, docstring const & message) void error(docstring const & title0, docstring const & message)
{ {
lyxerr << "Error: " << title0 << '\n' lyxerr << "Error: " << title0 << '\n'
@ -226,16 +207,15 @@ void error(docstring const & title0, docstring const & message)
return; return;
docstring const title = bformat(_("LyX: %1$s"), title0); docstring const title = bformat(_("LyX: %1$s"), title0);
if (theApp() == 0) { if (theApp() == 0) {
QApplication app(argc, argv); noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Critical);
QMessageBox::critical(0,
toqstr(title),
toqstr(formatted(message)));
return; return;
} }
QMessageBox::critical(qApp->focusWidget(),
toqstr(title), ProgressInterface::instance()->error(
toqstr(formatted(message))); toqstr(title),
toqstr(formatted(message)));
} }
@ -250,9 +230,15 @@ void information(docstring const & title0, docstring const & message)
return; return;
docstring const title = bformat(_("LyX: %1$s"), title0); docstring const title = bformat(_("LyX: %1$s"), title0);
QMessageBox::information(qApp->focusWidget(),
toqstr(title), if (theApp() == 0) {
toqstr(formatted(message))); noAppDialog(toqstr(title), toqstr(formatted(message)), QMessageBox::Information);
return;
}
ProgressInterface::instance()->information(
toqstr(title),
toqstr(formatted(message)));
} }

View File

@ -12,51 +12,74 @@
#include <config.h> #include <config.h>
#include "GuiProgress.h" #include "GuiProgress.h"
#include "ui_ToggleWarningUi.h"
#include "qt_helpers.h" #include "qt_helpers.h"
#include "support/Systemcall.h" #include "support/Systemcall.h"
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QTime>
#include <QMessageBox>
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
class GuiToggleWarningDialog : public QDialog, public Ui::ToggleWarningUi
GuiProgress::GuiProgress(GuiView & parent, Qt::DockWidgetArea area,
Qt::WindowFlags flags) : DockView(parent, "progress", "External tools", area, flags)
{ {
setWindowTitle(qt_("Tool monitoring")); public:
setWidget(&text_edit); GuiToggleWarningDialog(QWidget * parent) : QDialog(parent)
text_edit.setReadOnly(true); {
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(processStarted(QString const &)), SLOT(doProcessStarted(QString const &)));
connect(this, SIGNAL(processFinished(QString const &)), SLOT(doProcessFinished(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(appendMessage(QString const &)), SLOT(doAppendMessage(QString const &)));
connect(this, SIGNAL(appendError(QString const &)), SLOT(doAppendError(QString const &))); connect(this, SIGNAL(appendError(QString const &)), SLOT(doAppendError(QString const &)));
connect(this, SIGNAL(clearMessages()), SLOT(doClearMessages())); 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) 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) 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) 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() void GuiProgress::doClearMessages()
{ {
text_edit.clear(); view_->message(docstring());
} }
void GuiProgress::appendText(QString const & text) void GuiProgress::appendText(QString const & text)
{ {
text_edit.insertPlainText(text); view_->message(qstring_to_ucs4(text));
text_edit.ensureCursorVisible();
} }
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);
} }
void GuiProgress::doError(QString const & title, QString const & message)
Dialog * createGuiProgress(GuiView & lv)
{ {
GuiView & guiview = static_cast<GuiView &>(lv); QMessageBox::critical(qApp->focusWidget(), title, message);
#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
} }
void GuiProgress::doInformation(QString const & title, QString const & message)
{
QMessageBox::information(qApp->focusWidget(), title, message);
}
} // namespace frontend } // namespace frontend
} // namespace lyx } // namespace lyx

View File

@ -27,17 +27,15 @@ namespace lyx {
namespace frontend { namespace frontend {
class GuiProgress : class GuiProgress :
public DockView, public QObject,
public lyx::support::ProgressInterface public lyx::support::ProgressInterface
{ {
Q_OBJECT Q_OBJECT
public: public:
GuiProgress( GuiProgress(GuiView * view);
GuiView & parent, ///< the main window where to dock.
Qt::DockWidgetArea area, ///< Position of the dock (and also drawer)
Qt::WindowFlags flags = 0);
Q_SIGNALS: Q_SIGNALS:
void processStarted(QString const &); void processStarted(QString const &);
@ -46,6 +44,12 @@ Q_SIGNALS:
void appendError(QString const &); void appendError(QString const &);
void clearMessages(); 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: private Q_SLOTS:
void doProcessStarted(QString const &); void doProcessStarted(QString const &);
void doProcessFinished(QString const &); void doProcessFinished(QString const &);
@ -53,25 +57,15 @@ private Q_SLOTS:
void doAppendError(QString const &); void doAppendError(QString const &);
void doClearMessages(); 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 doWarning(QString const &, QString const &);
void showEvent(QShowEvent*); void doToggleWarning(QString const & title, QString const & msg, QString const & formatted);
void hideEvent(QHideEvent*); void doError(QString const &, QString const &);
void doInformation(QString const &, QString const &);
private: private:
QTextEdit text_edit; GuiView* view_;
void appendText(QString const &); void appendText(QString const &);
}; };

View File

@ -77,6 +77,7 @@
#include "support/Systemcall.h" #include "support/Systemcall.h"
#include "support/Timeout.h" #include "support/Timeout.h"
#include "support/ProgressInterface.h" #include "support/ProgressInterface.h"
#include "GuiProgress.h"
#include <QAction> #include <QAction>
#include <QApplication> #include <QApplication>
@ -192,6 +193,7 @@ struct GuiView::GuiViewPrivate
stack_widget_->addWidget(bg_widget_); stack_widget_->addWidget(bg_widget_);
stack_widget_->addWidget(splitter_); stack_widget_->addWidget(splitter_);
setBackground(); setBackground();
progress = new GuiProgress(gv);
} }
~GuiViewPrivate() ~GuiViewPrivate()
@ -199,6 +201,7 @@ struct GuiView::GuiViewPrivate
delete splitter_; delete splitter_;
delete bg_widget_; delete bg_widget_;
delete stack_widget_; delete stack_widget_;
delete progress;
} }
QMenu * toolBarPopup(GuiView * parent) QMenu * toolBarPopup(GuiView * parent)
@ -284,6 +287,7 @@ public:
BackgroundWidget * bg_widget_; BackgroundWidget * bg_widget_;
/// view's toolbars /// view's toolbars
ToolbarMap toolbars_; ToolbarMap toolbars_;
GuiProgress* progress;
/// The main layout box. /// The main layout box.
/** /**
* \warning Don't Delete! The layout box is actually owned by * \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 == "file" //FIXME: should be removed.
|| name == "prefs" || name == "prefs"
|| name == "texinfo" || name == "texinfo"
|| name == "progress"
|| name == "compare"; || name == "compare";
else if (name == "print") else if (name == "print")
enable = doc_buffer->isExportable("dvi") enable = doc_buffer->isExportable("dvi")
@ -2691,6 +2694,9 @@ bool GuiView::dispatch(FuncRequest const & cmd)
if (argument.empty()) if (argument.empty())
format = doc_buffer->getDefaultOutputFormat(); format = doc_buffer->getDefaultOutputFormat();
#if EXPORT_in_THREAD && (QT_VERSION >= 0x040400) #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
ProgressInterface::instance()->clearMessages();
QString time = QTime::currentTime().toString(Qt::SystemLocaleShortDate);
ProgressInterface::instance()->appendMessage(time + ": Exporting ...\n");
QFuture<docstring> f = QtConcurrent::run(exportAndDestroy, QFuture<docstring> f = QtConcurrent::run(exportAndDestroy,
doc_buffer->clone(), format); doc_buffer->clone(), format);
d.setPreviewFuture(f); d.setPreviewFuture(f);
@ -2706,6 +2712,9 @@ bool GuiView::dispatch(FuncRequest const & cmd)
if (argument.empty()) if (argument.empty())
format = doc_buffer->getDefaultOutputFormat(); format = doc_buffer->getDefaultOutputFormat();
#if EXPORT_in_THREAD && (QT_VERSION >= 0x040400) #if EXPORT_in_THREAD && (QT_VERSION >= 0x040400)
ProgressInterface::instance()->clearMessages();
QString time = QTime::currentTime().toString(Qt::SystemLocaleShortDate);
ProgressInterface::instance()->appendMessage(time + ": Previewing ...\n");
QFuture<docstring> f = QtConcurrent::run(previewAndDestroy, QFuture<docstring> f = QtConcurrent::run(previewAndDestroy,
doc_buffer->clone(), format); doc_buffer->clone(), format);
d.setPreviewFuture(f); d.setPreviewFuture(f);
@ -3175,7 +3184,7 @@ char const * const dialognames[] = {
"mathmatrix", "mathspace", "nomenclature", "nomencl_print", "note", "mathmatrix", "mathspace", "nomenclature", "nomencl_print", "note",
"paragraph", "phantom", "prefs", "print", "ref", "sendto", "space", "paragraph", "phantom", "prefs", "print", "ref", "sendto", "space",
"spellchecker", "symbols", "tabular", "tabularcreate", "thesaurus", "texinfo", "spellchecker", "symbols", "tabular", "tabularcreate", "thesaurus", "texinfo",
"toc", "view-source", "vspace", "wrap", "progress" }; "toc", "view-source", "vspace", "wrap"};
char const * const * const end_dialognames = char const * const * const end_dialognames =
dialognames + (sizeof(dialognames) / sizeof(char *)); dialognames + (sizeof(dialognames) / sizeof(char *));
@ -3373,7 +3382,8 @@ Dialog * createGuiHyperlink(GuiView & lv);
Dialog * createGuiVSpace(GuiView & lv); Dialog * createGuiVSpace(GuiView & lv);
Dialog * createGuiViewSource(GuiView & lv); Dialog * createGuiViewSource(GuiView & lv);
Dialog * createGuiWrap(GuiView & lv); Dialog * createGuiWrap(GuiView & lv);
Dialog * createGuiProgress(GuiView & lv);
Dialog * GuiView::build(string const & name) Dialog * GuiView::build(string const & name)
{ {
@ -3477,8 +3487,6 @@ Dialog * GuiView::build(string const & name)
return createGuiVSpace(*this); return createGuiVSpace(*this);
if (name == "wrap") if (name == "wrap")
return createGuiWrap(*this); return createGuiWrap(*this);
if (name == "progress")
return createGuiProgress(*this);
return 0; return 0;
} }

View File

@ -31,6 +31,13 @@ public:
virtual void appendError(QString const &) = 0; virtual void appendError(QString const &) = 0;
virtual void clearMessages() = 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 void setInstance(ProgressInterface*);
static ProgressInterface* instance(); static ProgressInterface* instance();

View File

@ -61,6 +61,11 @@ public:
void appendMessage(QString const &) {} void appendMessage(QString const &) {}
void appendError(QString const &) {} void appendError(QString const &) {}
void clearMessages() {} 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_); const QString data = QString::fromLocal8Bit(outdata_);
if (!data.isEmpty()) if (!data.isEmpty()) {
ProgressInterface::instance()->appendMessage(data); // TODO No good messages from the processes. Disable batch mode?
//ProgressInterface::instance()->appendMessage(data);
}
processEvents(); processEvents();
} }