[kde-doc-english] [trojita] src: GUI: tell the user that "close" actually means "minimize to systray"
Jan Kundrát
jkt at flaska.net
Sat May 25 06:12:15 UTC 2013
Git commit d93221e70bd9b318ef90e0b30e4b65da9f303a37 by Jan Kundrát.
Committed on 25/05/2013 at 08:09.
Pushed by jkt into branch 'master'.
GUI: tell the user that "close" actually means "minimize to systray"
Thanks to Franz Fellner <alpine.art.de at gmail.com> for his bugreport and to
http://wayback.archive.org/web/20090527102002/http://blog.beef.de/2008/01/12/qmessagebox-widgets/
for a nice idea on how to hack QMessageBox with this feature.
refs #67
M +1 -0 src/Common/SettingsNames.cpp
M +1 -1 src/Common/SettingsNames.h
M +29 -0 src/Gui/Util.cpp
M +4 -0 src/Gui/Util.h
M +3 -0 src/Gui/Window.cpp
http://commits.kde.org/trojita/d93221e70bd9b318ef90e0b30e4b65da9f303a37
diff --git a/src/Common/SettingsNames.cpp b/src/Common/SettingsNames.cpp
index 08e4d3d..1cac921 100644
--- a/src/Common/SettingsNames.cpp
+++ b/src/Common/SettingsNames.cpp
@@ -82,6 +82,7 @@ QString SettingsNames::guiMainWindowLayoutCompact = QLatin1String("compact");
QString SettingsNames::guiMainWindowLayoutWide = QLatin1String("wide");
QString SettingsNames::guiPreferPlaintextRendering = QLatin1String("gui/preferPlaintextRendering");
QString SettingsNames::guiShowSystray = QLatin1String("gui/showSystray");
+QString SettingsNames::guiOnSystrayClose = QLatin1String("gui/onSystrayClose");
QString SettingsNames::appLoadHomepage = QLatin1String("app.updates.checkEnabled");
QString SettingsNames::knownEmailsKey = QLatin1String("addressBook/knownEmails");
diff --git a/src/Common/SettingsNames.h b/src/Common/SettingsNames.h
index 492c8db..50867bf 100644
--- a/src/Common/SettingsNames.h
+++ b/src/Common/SettingsNames.h
@@ -46,7 +46,7 @@ struct SettingsNames {
static QString guiPreferPlaintextRendering;
static QString guiMainWindowLayout, guiMainWindowLayoutCompact, guiMainWindowLayoutWide;
static QString appLoadHomepage;
- static QString guiShowSystray;
+ static QString guiShowSystray, guiOnSystrayClose;
static QString knownEmailsKey;
};
diff --git a/src/Gui/Util.cpp b/src/Gui/Util.cpp
index c5e3cf3..329039d 100644
--- a/src/Gui/Util.cpp
+++ b/src/Gui/Util.cpp
@@ -23,13 +23,16 @@
#include <QApplication>
+#include <QCheckBox>
#include <QCursor> // for Util::centerWidgetOnScreen
#include <QDesktopWidget> // for Util::centerWidgetOnScreen
#include <QDir>
+#include <QGridLayout>
#include <QProcess>
#include <QSettings>
#include "Util.h"
+#include "Window.h"
namespace {
@@ -202,6 +205,32 @@ QFont systemMonospaceFont()
return font;
}
+/** @short Ask for something and provide a facility to not ask again
+
+Check settings whether an option is already set to ignore this question. If not, ask the user and remember whether
+she wants to be asked again.
+*/
+int askForSomethingUnlessTold(const QString &title, const QString &message, const QString &settingsName,
+ QMessageBox::StandardButtons buttons, QWidget *parent)
+{
+ int saved = QSettings().value(settingsName, -1).toInt();
+ if (saved != -1) {
+ // This means that we're not supposed to ask again
+ return saved;
+ }
+
+ QMessageBox box(QMessageBox::Question, title, message, QMessageBox::NoButton, parent);
+ box.setStandardButtons(buttons);
+ QCheckBox *checkbox = new QCheckBox(Gui::MainWindow::tr("Don't ask again"), &box);
+ QGridLayout *layout = qobject_cast<QGridLayout*>(box.layout());
+ Q_ASSERT(layout);
+ layout->addWidget(checkbox, 1, 1);
+ int res = box.exec();
+ if (checkbox->isChecked())
+ QSettings().setValue(settingsName, res);
+ return res;
+}
+
} // namespace Util
} // namespace Gui
diff --git a/src/Gui/Util.h b/src/Gui/Util.h
index a23d2f7..3ffcf47 100644
--- a/src/Gui/Util.h
+++ b/src/Gui/Util.h
@@ -25,6 +25,7 @@
#ifndef GUI_UTIL_H
#define GUI_UTIL_H
+#include <QMessageBox>
#include <QString>
class QColor;
@@ -46,6 +47,9 @@ QColor tintColor(const QColor &color, const QColor &tintColor);
QFont systemMonospaceFont();
+int askForSomethingUnlessTold(const QString &title, const QString &message, const QString &settingsName,
+ QMessageBox::StandardButtons buttons, QWidget *parent);
+
} // namespace Util
} // namespace Gui
diff --git a/src/Gui/Window.cpp b/src/Gui/Window.cpp
index 424204e..0e7ef54 100644
--- a/src/Gui/Window.cpp
+++ b/src/Gui/Window.cpp
@@ -814,6 +814,9 @@ void MainWindow::handleTrayIconChange()
void MainWindow::closeEvent(QCloseEvent *event)
{
if (m_trayIcon && m_trayIcon->isVisible()) {
+ Util::askForSomethingUnlessTold(trUtf8("Trojitá"),
+ tr("The application will continue in systray. This can be disabled within the settings."),
+ Common::SettingsNames::guiOnSystrayClose, QMessageBox::Ok, this);
hide();
event->ignore();
}
More information about the kde-doc-english
mailing list