[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdelibs/frameworks] tier1/kwidgetsaddons/src: Introduce KMessageBoxNotifyInterface
From: Aurélien Gâteau <agateau () kde ! org>
Date: 2013-10-21 15:56:35
Message-ID: E1VYHqN-00017A-QX () scm ! kde ! org
[Download RAW message or body]
Git commit 442048afa7220b7358afa48ad2a7ff7838d0cb0d by Aurélien Gâteau.
Committed on 16/10/2013 at 12:40.
Pushed by gateau into branch 'frameworks'.
Introduce KMessageBoxNotifyInterface
Part of http://git.reviewboard.kde.org/r/113266/
M +5 -38 tier1/kwidgetsaddons/src/kmessagebox.cpp
M +8 -0 tier1/kwidgetsaddons/src/kmessagebox.h
M +25 -0 tier1/kwidgetsaddons/src/kmessagebox_p.cpp
M +3 -0 tier1/kwidgetsaddons/src/kmessagebox_p.h
C +20 -7 tier1/kwidgetsaddons/src/kmessageboxnotifyinterface.h [from: \
tier1/kwidgetsaddons/src/kmessagebox_p.h - 062% similarity] [License: UNKNOWN] *
The files marked with a * at the end have a non valid license. Please read: \
http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are \
listed at that page.
http://commits.kde.org/kdelibs/442048afa7220b7358afa48ad2a7ff7838d0cb0d
diff --git a/tier1/kwidgetsaddons/src/kmessagebox.cpp \
b/tier1/kwidgetsaddons/src/kmessagebox.cpp index 1cb18f0..0e99976 100644
--- a/tier1/kwidgetsaddons/src/kmessagebox.cpp
+++ b/tier1/kwidgetsaddons/src/kmessagebox.cpp
@@ -117,43 +117,6 @@ static QIcon themedMessageBoxIcon(QMessageBox::Icon icon)
}
}
-static void sendNotification( QString message, //krazy:exclude=passbyvalue
- const QStringList& strlist,
- QMessageBox::Icon icon,
- WId parent_id )
-{
- // create the message for KNotify
- QString messageType;
- switch (icon) {
- case QMessageBox::Warning:
- messageType = QStringLiteral("messageWarning");
- break;
- case QMessageBox::Critical:
- messageType = QStringLiteral("messageCritical");
- break;
- case QMessageBox::Question:
- messageType = QStringLiteral("messageQuestion");
- break;
- default:
- messageType = QStringLiteral("messageInformation");
- break;
- }
-
- if ( !strlist.isEmpty() ) {
- for ( QStringList::ConstIterator it = strlist.begin(); it != strlist.end(); \
++it ) {
- message += QLatin1Char('\n') + *it;
- }
- }
-
-#if 0
- // NOTE waiting for the notification framework plan
- if ( !message.isEmpty() ) {
- KNotification::event( messageType, message, QPixmap(), QWidget::find( \
parent_id ),
- KNotification::DefaultEvent | \
KNotification::CloseOnTimeout );
- }
-#endif
-}
-
static void applyOptions( QDialog* dialog, KMessageBox::Options options )
{
if ( options & KMessageBox::WindowModal ) {
@@ -412,7 +375,11 @@ QDialogButtonBox::StandardButton createKMessageBox(QDialog \
*dialog, QDialogButto
#ifndef Q_OS_WIN // FIXME problems with KNotify on Windows
if ((options & KMessageBox::Notify)) {
- sendNotification(text, strlist, notifyType, \
dialog->topLevelWidget()->winId()); + QString message = text;
+ if (!strlist.isEmpty()) {
+ message += QLatin1Char('\n') + strlist.join(QLatin1Char('\n'));
+ }
+ notifyInterface()->sendNotification(notifyType, message, \
dialog->topLevelWidget()); }
#endif
diff --git a/tier1/kwidgetsaddons/src/kmessagebox.h \
b/tier1/kwidgetsaddons/src/kmessagebox.h index f7ebe51..4d3c7cf 100644
--- a/tier1/kwidgetsaddons/src/kmessagebox.h
+++ b/tier1/kwidgetsaddons/src/kmessagebox.h
@@ -31,6 +31,7 @@
#include <kwidgetsaddons_export.h>
class KMessageBoxDontAskAgainInterface;
+class KMessageBoxNotifyInterface;
class QDialog;
class QDialogButtonBox;
class QWidget;
@@ -795,6 +796,13 @@ namespace KMessageBox
KWIDGETSADDONS_EXPORT void \
setDontShowAgainInterface(KMessageBoxDontAskAgainInterface* dontAskAgainInterface);
/**
+ * Use @p notifyInterface to send notifications
+ *
+ * @since 5.0
+ */
+ KWIDGETSADDONS_EXPORT void setNotifyInterface(KMessageBoxNotifyInterface \
*notifyInterface); +
+ /**
* Create content and layout of a standard dialog
*
* @param dialog The parent dialog base
diff --git a/tier1/kwidgetsaddons/src/kmessagebox_p.cpp \
b/tier1/kwidgetsaddons/src/kmessagebox_p.cpp index 81a0bf6..b4ecb3e 100644
--- a/tier1/kwidgetsaddons/src/kmessagebox_p.cpp
+++ b/tier1/kwidgetsaddons/src/kmessagebox_p.cpp
@@ -61,8 +61,15 @@ private:
QHash<QString, KMessageBox::ButtonCode> m_saved;
};
+class KMessageBoxNotifyDummy : public KMessageBoxNotifyInterface
+{
+public:
+ void sendNotification(QMessageBox::Icon /*notificationType*/, const QString \
&/*message*/, QWidget */*parent*/) {} +};
+
// TODO should we use QSharedPointer here?
static KMessageBoxDontAskAgainInterface* s_dontAskAgainInterface = 0;
+static KMessageBoxNotifyInterface* s_notifyInterface = 0;
static void loadKMessageBoxPlugin()
{
@@ -74,12 +81,16 @@ static void loadKMessageBoxPlugin()
QObject *rootObj = lib.instance();
if (rootObj) {
s_dontAskAgainInterface = \
rootObj->property(KMESSAGEBOXDONTASKAGAIN_PROPERTY).value<KMessageBoxDontAskAgainInterface \
*>(); + s_notifyInterface = \
rootObj->property(KMESSAGEBOXNOTIFY_PROPERTY).value<KMessageBoxNotifyInterface *>(); \
} }
// TODO use Qt-5.1's Q_GLOBAL_STATIC
if (!s_dontAskAgainInterface) {
s_dontAskAgainInterface = new KMessageBoxDontAskAgainMemoryStorage;
}
+ if (!s_notifyInterface) {
+ s_notifyInterface = new KMessageBoxNotifyDummy;
+ }
}
KMessageBoxDontAskAgainInterface *dontAskAgainInterface()
@@ -90,6 +101,14 @@ KMessageBoxDontAskAgainInterface *dontAskAgainInterface()
return s_dontAskAgainInterface;
}
+KMessageBoxNotifyInterface *notifyInterface()
+{
+ if (!s_notifyInterface) {
+ loadKMessageBoxPlugin();
+ }
+ return s_notifyInterface;
+}
+
void setDontShowAgainInterface(KMessageBoxDontAskAgainInterface* \
dontAskAgainInterface) {
Q_ASSERT(dontAskAgainInterface != 0);
@@ -97,4 +116,10 @@ void setDontShowAgainInterface(KMessageBoxDontAskAgainInterface* \
dontAskAgainInt s_dontAskAgainInterface = dontAskAgainInterface;
}
+void setNotifyInterface(KMessageBoxNotifyInterface *notifyInterface)
+{
+ Q_ASSERT(notifyInterface != 0);
+ s_notifyInterface = notifyInterface;
+}
+
} // KMessageBox namespace
diff --git a/tier1/kwidgetsaddons/src/kmessagebox_p.h \
b/tier1/kwidgetsaddons/src/kmessagebox_p.h index 77948ad..54cc5f5 100644
--- a/tier1/kwidgetsaddons/src/kmessagebox_p.h
+++ b/tier1/kwidgetsaddons/src/kmessagebox_p.h
@@ -21,11 +21,14 @@
#define KMESSAGEBOX_P_H
#include <kmessageboxdontaskagaininterface.h>
+#include <kmessageboxnotifyinterface.h>
namespace KMessageBox {
KMessageBoxDontAskAgainInterface *dontAskAgainInterface();
+KMessageBoxNotifyInterface *notifyInterface();
+
} // KMessageBox
#endif /* KMESSAGEBOX_P_H */
diff --git a/tier1/kwidgetsaddons/src/kmessagebox_p.h \
b/tier1/kwidgetsaddons/src/kmessageboxnotifyinterface.h similarity index 62%
copy from tier1/kwidgetsaddons/src/kmessagebox_p.h
copy to tier1/kwidgetsaddons/src/kmessageboxnotifyinterface.h
index 77948ad..fb1361b 100644
--- a/tier1/kwidgetsaddons/src/kmessagebox_p.h
+++ b/tier1/kwidgetsaddons/src/kmessageboxnotifyinterface.h
@@ -17,15 +17,28 @@
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
-#ifndef KMESSAGEBOX_P_H
-#define KMESSAGEBOX_P_H
-#include <kmessageboxdontaskagaininterface.h>
+#ifndef KMESSAGEBOXNOTIFYINTERFACE_H
+#define KMESSAGEBOXNOTIFYINTERFACE_H
-namespace KMessageBox {
+#include "kmessagebox.h"
+#include <qmetatype.h>
-KMessageBoxDontAskAgainInterface *dontAskAgainInterface();
+/**
+ * @internal
+ * Used internally by KMessageBox, implemented by plugin, for dynamic dependency on \
KNotification. + */
+class KMessageBoxNotifyInterface
+{
+public:
+ KMessageBoxNotifyInterface() {}
+ virtual ~KMessageBoxNotifyInterface() {}
+
+ virtual void sendNotification(QMessageBox::Icon notificationType, const QString \
&message, QWidget *parent) = 0; +};
+
+Q_DECLARE_METATYPE(KMessageBoxNotifyInterface *)
-} // KMessageBox
+#define KMESSAGEBOXNOTIFY_PROPERTY "KMessageBoxNotify"
-#endif /* KMESSAGEBOX_P_H */
+#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic