]> 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 512700421b882953e356fc968cad6bdc355ebca9..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.
 #include "frontends/Application.h"
 
 #include "qt_helpers.h"
-#include "support/debug.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 <QApplication>
+#include <QCheckBox>
 #include <QMessageBox>
 #include <QLineEdit>
 #include <QInputDialog>
+#include <QSettings>
 
 #include <iomanip>
+#include <iostream>
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 namespace frontend {
 
-using support::bformat;
+
+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)
 {
@@ -52,7 +68,7 @@ static docstring const formatted(docstring const & text)
        while (true) {
                size_t const nxtpos1 = text.find(' ',  curpos);
                size_t const nxtpos2 = text.find('\n', curpos);
-               size_t const nxtpos = std::min(nxtpos1, nxtpos2);
+               size_t const nxtpos = min(nxtpos1, nxtpos2);
 
                docstring const word =
                        nxtpos == docstring::npos ?
@@ -98,22 +114,46 @@ 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,
                  int default_button, int cancel_button,
                  docstring const & b1, docstring const & b2, docstring const & b3)
 {
+       //lyxerr << "PROMPT" << title0 << "FOCUS: " << qApp->focusWidget() << endl;
        if (!use_gui || lyxerr.debugging()) {
-               lyxerr << to_utf8(title0) << '\n'
+               lyxerr << title0 << '\n'
                       << "----------------------------------------\n"
-                      << to_utf8(question) << endl;
+                      << question << endl;
 
                lyxerr << "Assuming answer is ";
                switch (default_button) {
-               case 0: lyxerr << to_utf8(b1) << endl;
-               case 1: lyxerr << to_utf8(b2) << endl;
-               case 2: lyxerr << to_utf8(b3) << endl;
+               case 0: lyxerr << b1 << endl;
+               case 1: lyxerr << b2 << endl;
+               case 2: lyxerr << b3 << endl;
                }
                if (!use_gui)
                        return default_button;
@@ -127,6 +167,7 @@ int prompt(docstring const & title0, docstring const & question,
        qApp->changeOverrideCursor(Qt::ArrowCursor);
 
        // FIXME replace that with guiApp->currentView()
+       //LYXERR0("FOCUS: " << qApp->focusWidget());
        int res = QMessageBox::information(qApp->focusWidget(),
                                           toqstr(title),
                                           toqstr(formatted(question)),
@@ -142,11 +183,12 @@ 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: " << to_utf8(title0) << '\n'
+       lyxerr << "Warning: " << title0 << '\n'
               << "----------------------------------------\n"
-              << to_utf8(message) << endl;
+              << message << endl;
 
        if (!use_gui)
                return;
@@ -162,25 +204,29 @@ 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: " << to_utf8(title0) << '\n'
+       lyxerr << "Error: " << title0 << '\n'
               << "----------------------------------------\n"
-              << to_utf8(message) << endl;
+              << message << endl;
 
        if (!use_gui)
                return;
 
        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),
@@ -196,9 +242,9 @@ void error(docstring const & title0, docstring const & message)
 void information(docstring const & title0, docstring const & message)
 {
        if (!use_gui || lyxerr.debugging())
-               lyxerr << to_utf8(title0) << '\n'
+               lyxerr << title0 << '\n'
                       << "----------------------------------------\n"
-                      << to_utf8(message) << endl;
+                      << message << endl;
 
        if (!use_gui)
                return;
@@ -215,8 +261,8 @@ bool askForText(docstring & response, docstring const & msg,
 {
        if (!use_gui || lyxerr.debugging()) {
                lyxerr << "----------------------------------------\n"
-                      << to_utf8(msg) << '\n'
-                      << "Assuming answer is " << to_utf8(dflt) << '\n'
+                      << msg << '\n'
+                      << "Assuming answer is " << dflt << '\n'
                       << "----------------------------------------" << endl;
                if (!use_gui) {
                        response = dflt;
@@ -233,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;
        }