[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdelibs/frameworks] tier1/kwidgetsaddons/src: Move plugin handling to kmessagebox_p.*
From:       Aurélien Gâteau <agateau () kde ! org>
Date:       2013-10-21 15:56:34
Message-ID: E1VYHqM-00017A-Ha () scm ! kde ! org
[Download RAW message or body]

Git commit 4dbea75e35bf2075705a5a7e95a2dfd73d9d1c9b by Aurélien Gâteau.
Committed on 16/10/2013 at 12:45.
Pushed by gateau into branch 'frameworks'.

Move plugin handling to kmessagebox_p.*

Part of http://git.reviewboard.kde.org/r/113266/

M  +1    -0    tier1/kwidgetsaddons/src/CMakeLists.txt
M  +1    -68   tier1/kwidgetsaddons/src/kmessagebox.cpp
M  +2    -0    tier1/kwidgetsaddons/src/kmessagebox.h
A  +100  -0    tier1/kwidgetsaddons/src/kmessagebox_p.cpp     [License: LGPL \
(v2/3+eV)] A  +31   -0    tier1/kwidgetsaddons/src/kmessagebox_p.h     [License: LGPL \
(v2/3+eV)]

http://commits.kde.org/kdelibs/4dbea75e35bf2075705a5a7e95a2dfd73d9d1c9b

diff --git a/tier1/kwidgetsaddons/src/CMakeLists.txt \
b/tier1/kwidgetsaddons/src/CMakeLists.txt index 50c578a..064945a 100644
--- a/tier1/kwidgetsaddons/src/CMakeLists.txt
+++ b/tier1/kwidgetsaddons/src/CMakeLists.txt
@@ -18,6 +18,7 @@ set(kwidgetsaddons_SRCS
   kguiitem.cpp
   kled.cpp
   kmessagebox.cpp
+  kmessagebox_p.cpp
   kmultitabbar.cpp
   kstandardguiitem.cpp
   kurllabel.cpp # Not good enough quality. Needs to use QUrl instead of QString and \
                should not inherit QLabel, but hold it as a member instead.
diff --git a/tier1/kwidgetsaddons/src/kmessagebox.cpp \
b/tier1/kwidgetsaddons/src/kmessagebox.cpp index b2345d0..1cb18f0 100644
--- a/tier1/kwidgetsaddons/src/kmessagebox.cpp
+++ b/tier1/kwidgetsaddons/src/kmessagebox.cpp
@@ -19,7 +19,7 @@
 */
 
 #include "kmessagebox.h"
-#include "kmessageboxdontaskagaininterface.h"
+#include "kmessagebox_p.h"
 
 #include <QtCore/QPointer>
 #include <QCheckBox>
@@ -34,7 +34,6 @@
 #include <QScrollArea>
 #include <QScrollBar>
 #include <QTextDocumentFragment>
-#include <QPluginLoader>
 #include <QTextBrowser>
 #include <QWindow>
 
@@ -450,72 +449,6 @@ ButtonCode questionYesNo(QWidget *parent, const QString &text,
                             buttonYes, buttonNo, dontAskAgainName, options);
 }
 
-class KMessageBoxDontAskAgainMemoryStorage : public KMessageBoxDontAskAgainInterface
-{
-public:
-    KMessageBoxDontAskAgainMemoryStorage() {}
-    virtual ~KMessageBoxDontAskAgainMemoryStorage() {}
-
-    virtual bool shouldBeShownYesNo(const QString &dontShowAgainName, \
                KMessageBox::ButtonCode &result) {
-        KMessageBox::ButtonCode code = m_saved.value(dontShowAgainName, \
                KMessageBox::ButtonCode(0));
-        if (code == KMessageBox::Yes || code == KMessageBox::No) {
-            result = code;
-            return false;
-        }
-        return true;
-    }
-    virtual bool shouldBeShownContinue(const QString &dontShowAgainName) {
-        KMessageBox::ButtonCode code = m_saved.value(dontShowAgainName, \
                KMessageBox::Yes);
-        return code == KMessageBox::Yes;
-    }
-    virtual void saveDontShowAgainYesNo(const QString &dontShowAgainName, \
                KMessageBox::ButtonCode result) {
-        m_saved[dontShowAgainName] = result;
-    }
-    virtual void saveDontShowAgainContinue(const QString &dontShowAgainName) {
-        m_saved[dontShowAgainName] = KMessageBox::No;
-    }
-    virtual void enableAllMessages() {
-        m_saved.clear();
-    }
-    virtual void enableMessage(const QString& dontShowAgainName) {
-        m_saved.remove(dontShowAgainName);
-    }
-    virtual void setConfig(KConfig *) {}
-
-private:
-    QHash<QString, KMessageBox::ButtonCode> m_saved;
-};
-
-// TODO should we use QSharedPointer here?
-static KMessageBoxDontAskAgainInterface* s_dontAskAgainInterface = 0;
-static KMessageBoxDontAskAgainInterface* dontAskAgainInterface() {
-    if (!s_dontAskAgainInterface) {
-        static bool triedLoadingPlugin = false;
-        if (!triedLoadingPlugin) {
-            triedLoadingPlugin = true;
-
-            QPluginLoader lib(QStringLiteral("kf5/frameworkintegrationplugin"));
-            QObject* rootObj = lib.instance();
-            if (rootObj) {
-                s_dontAskAgainInterface = \
rootObj->property(KMESSAGEBOXDONTASKAGAIN_PROPERTY).value<KMessageBoxDontAskAgainInterface \
                *>();
-            }
-        }
-        // TODO use Qt-5.1's Q_GLOBAL_STATIC
-        if (!s_dontAskAgainInterface) {
-            s_dontAskAgainInterface = new KMessageBoxDontAskAgainMemoryStorage;
-        }
-    }
-    return s_dontAskAgainInterface;
-}
-
-void setDontShowAgainInterface(KMessageBoxDontAskAgainInterface* \
                dontAskAgainInterface)
-{
-    Q_ASSERT(dontAskAgainInterface != 0);
-    // FIXME should we delete s_dontAskAgainInterface before? Or perhaps use smart \
                pointers to avoid problems?
-    s_dontAskAgainInterface = dontAskAgainInterface;
-}
-
-
 bool shouldBeShownYesNo(const QString &dontShowAgainName,
                                      ButtonCode &result)
 {
diff --git a/tier1/kwidgetsaddons/src/kmessagebox.h \
b/tier1/kwidgetsaddons/src/kmessagebox.h index 9a76c23..f7ebe51 100644
--- a/tier1/kwidgetsaddons/src/kmessagebox.h
+++ b/tier1/kwidgetsaddons/src/kmessagebox.h
@@ -789,6 +789,8 @@ namespace KMessageBox
 
     /**
      * Use @p dontAskAgainInterface for all settings related to the donShowAgain \
feature +     *
+     * @since 5.0
      */
     KWIDGETSADDONS_EXPORT void \
setDontShowAgainInterface(KMessageBoxDontAskAgainInterface* dontAskAgainInterface);  
diff --git a/tier1/kwidgetsaddons/src/kmessagebox_p.cpp \
b/tier1/kwidgetsaddons/src/kmessagebox_p.cpp new file mode 100644
index 0000000..77a6aac
--- /dev/null
+++ b/tier1/kwidgetsaddons/src/kmessagebox_p.cpp
@@ -0,0 +1,100 @@
+/*  This file is part of the KDE libraries
+ *  Copyright 2012 David Faure <faure+bluesystems@kde.org>
+ *  Copyright 2013 Aurélien Gâteau <agateau@kde.org>
+ *
+ *  This library is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License or ( at
+ *  your option ) version 3 or, at the discretion of KDE e.V. ( which shall
+ *  act as a proxy as in section 14 of the GPLv3 ), any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+#include "kmessagebox_p.h"
+
+#include <QPluginLoader>
+#include <QVariant>
+
+namespace KMessageBox {
+
+class KMessageBoxDontAskAgainMemoryStorage : public KMessageBoxDontAskAgainInterface
+{
+public:
+    KMessageBoxDontAskAgainMemoryStorage() {}
+    virtual ~KMessageBoxDontAskAgainMemoryStorage() {}
+
+    virtual bool shouldBeShownYesNo(const QString &dontShowAgainName, \
KMessageBox::ButtonCode &result) { +        KMessageBox::ButtonCode code = \
m_saved.value(dontShowAgainName, KMessageBox::ButtonCode(0)); +        if (code == \
KMessageBox::Yes || code == KMessageBox::No) { +            result = code;
+            return false;
+        }
+        return true;
+    }
+    virtual bool shouldBeShownContinue(const QString &dontShowAgainName) {
+        KMessageBox::ButtonCode code = m_saved.value(dontShowAgainName, \
KMessageBox::Yes); +        return code == KMessageBox::Yes;
+    }
+    virtual void saveDontShowAgainYesNo(const QString &dontShowAgainName, \
KMessageBox::ButtonCode result) { +        m_saved[dontShowAgainName] = result;
+    }
+    virtual void saveDontShowAgainContinue(const QString &dontShowAgainName) {
+        m_saved[dontShowAgainName] = KMessageBox::No;
+    }
+    virtual void enableAllMessages() {
+        m_saved.clear();
+    }
+    virtual void enableMessage(const QString& dontShowAgainName) {
+        m_saved.remove(dontShowAgainName);
+    }
+    virtual void setConfig(KConfig *) {}
+
+private:
+    QHash<QString, KMessageBox::ButtonCode> m_saved;
+};
+
+// TODO should we use QSharedPointer here?
+static KMessageBoxDontAskAgainInterface* s_dontAskAgainInterface = 0;
+
+static void loadKMessageBoxPlugin()
+{
+    static bool triedLoadingPlugin = false;
+    if (!triedLoadingPlugin) {
+        triedLoadingPlugin = true;
+
+        QPluginLoader lib(QStringLiteral("kf5/frameworkintegrationplugin"));
+        QObject *rootObj = lib.instance();
+        if (rootObj) {
+            s_dontAskAgainInterface = \
rootObj->property(KMESSAGEBOXDONTASKAGAIN_PROPERTY).value<KMessageBoxDontAskAgainInterface \
*>(); +        }
+    }
+    // TODO use Qt-5.1's Q_GLOBAL_STATIC
+    if (!s_dontAskAgainInterface) {
+        s_dontAskAgainInterface = new KMessageBoxDontAskAgainMemoryStorage;
+    }
+}
+
+KMessageBoxDontAskAgainInterface *dontAskAgainInterface()
+{
+    if (!s_dontAskAgainInterface) {
+        loadKMessageBoxPlugin();
+    }
+    return s_dontAskAgainInterface;
+}
+
+void setDontShowAgainInterface(KMessageBoxDontAskAgainInterface* \
dontAskAgainInterface) +{
+    Q_ASSERT(dontAskAgainInterface != 0);
+    // FIXME should we delete s_dontAskAgainInterface before? Or perhaps use smart \
pointers to avoid problems? +    s_dontAskAgainInterface = dontAskAgainInterface;
+}
+
+} // KMessageBox namespace
diff --git a/tier1/kwidgetsaddons/src/kmessagebox_p.h \
b/tier1/kwidgetsaddons/src/kmessagebox_p.h new file mode 100644
index 0000000..77948ad
--- /dev/null
+++ b/tier1/kwidgetsaddons/src/kmessagebox_p.h
@@ -0,0 +1,31 @@
+/*  This file is part of the KDE libraries
+ *  Copyright 2013 Aurélien Gâteau <agateau@kde.org>
+ *
+ *  This library is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License or ( at
+ *  your option ) version 3 or, at the discretion of KDE e.V. ( which shall
+ *  act as a proxy as in section 14 of the GPLv3 ), any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  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>
+
+namespace KMessageBox {
+
+KMessageBoxDontAskAgainInterface *dontAskAgainInterface();
+
+} // KMessageBox
+
+#endif /* KMESSAGEBOX_P_H */


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic