]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiAlert.cpp
If we are in a closeEvent, we don't want to close all buffers, because these may...
[lyx.git] / src / frontends / qt4 / GuiAlert.cpp
index 75da5ee21e2a8c766378bbfcd2070f959865bdc8..983d58d1c1056f6d05268c481ea7f88fc849a9b7 100644 (file)
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author John Levon
+ * \author Jürgen Spitzmüller
  * \author Abdelrazak Younes
  *
  * Full author contact details are available in file CREDITS.
@@ -18,6 +19,7 @@
 #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/lstrings.h"
 
 #include <QApplication>
+#include <QCheckBox>
 #include <QMessageBox>
 #include <QLineEdit>
 #include <QInputDialog>
+#include <QSettings>
 
 #include <iomanip>
 #include <iostream>
@@ -39,6 +43,17 @@ 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)
 {
        const int w = 80;
@@ -99,6 +114,29 @@ static docstring const formatted(docstring const & text)
 }
 
 
+void toggleWarning(docstring const & title, docstring const & msg)
+{
+       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);
+}
+
+
 namespace Alert {
 
 int prompt(docstring const & title0, docstring const & question,
@@ -145,7 +183,8 @@ int prompt(docstring const & title0, docstring const & question,
 }
 
 
-void warning(docstring const & title0, docstring const & message)
+void warning(docstring const & title0, docstring const & message,
+            bool const & askshowagain)
 {
        lyxerr << "Warning: " << title0 << '\n'
               << "----------------------------------------\n"
@@ -165,12 +204,18 @@ void warning(docstring const & title0, docstring const & message)
                        toqstr(formatted(message)));
                return;
        }
-       QMessageBox::warning(qApp->focusWidget(),
-                            toqstr(title),
-                            toqstr(formatted(message)));
+       if (!askshowagain)
+               QMessageBox::warning(qApp->focusWidget(),
+                               toqstr(title),
+                               toqstr(formatted(message)));
+       else
+               toggleWarning(title, message);
 }
 
 
+int argc = 1;
+char * argv[1];
+
 void error(docstring const & title0, docstring const & message)
 {
        lyxerr << "Error: " << title0 << '\n'
@@ -182,8 +227,6 @@ void error(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::critical(0,
                        toqstr(title),
@@ -236,7 +279,7 @@ bool askForText(docstring & response, docstring const & msg,
                QLineEdit::Normal,
                toqstr(dflt), &ok);
 
-       if (ok && !text.isEmpty()) {
+       if (ok) {
                response = qstring_to_ucs4(text);
                return true;
        }