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

List:       kde-commits
Subject:    KDE/kdeplasma-addons/applets/pastebin
From:       Artur Duque de Souza <asouza () kde ! org>
Date:       2010-11-08 22:24:58
Message-ID: 20101108222458.43F27AC89B () svn ! kde ! org
[Download RAW message or body]

SVN commit 1194401 by asouza:

Fully support GHNS on pastebin applet

Finished some little things that will make it fully work,
like refreshing the list of providers when one is installed
or removed using GHNS dialog.


 M  +52 -14    pastebin.cpp  
 M  +4 -1      pastebin.h  


--- trunk/KDE/kdeplasma-addons/applets/pastebin/pastebin.cpp #1194400:1194401
@@ -72,6 +72,12 @@
     // connect to all sources of our 'share' dataengine
     m_engine = dataEngine("org.kde.plasma.dataengine.share");
     m_engine->connectAllSources(this);
+
+    // to detect when the mimetypes were added again after a refresh
+    connect(m_engine, SIGNAL(sourceAdded(const QString&)),
+            this, SLOT(sourceAdded(const QString&)));
+    connect(m_engine, SIGNAL(sourceRemoved(const QString&)),
+            this, SLOT(sourceRemoved(const QString&)));
 }
 
 Pastebin::~Pastebin()
@@ -105,22 +111,51 @@
     Plasma::ToolTipManager::self()->setContent(this, toolTipData);
 }
 
-void Pastebin::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data)
+void Pastebin::dataUpdated(const QString &source, const Plasma::DataEngine::Data &data)
 {
     // update the options
-    if (sourceName != "Mimetypes") {
+    if (source != "Mimetypes") {
         const QString mimetype = data.value("Mimetypes").toString();
 
         if (mimetype.startsWith("text/")) {
-            m_txtServers.insert(data.value("Name").toString(), sourceName);
+            m_txtServers.insert(data.value("Name").toString(), source);
         } else if (mimetype.startsWith("image/")) {
-            m_imgServers.insert(data.value("Name").toString(), sourceName);
+            m_imgServers.insert(data.value("Name").toString(), source);
         } else {
             kDebug() << "Mimetype not supported by this applet";
         }
     }
 }
 
+void Pastebin::sourceAdded(const QString &source)
+{
+    // update the options
+    if (source != "Mimetypes") {
+        const Plasma::DataEngine::Data data = m_engine->query(source);
+        const QString mimetype = data.value("Mimetypes").toString();
+
+        if (mimetype.startsWith("text/")) {
+            m_txtServers.insert(data.value("Name").toString(), source);
+        } else if (mimetype.startsWith("image/")) {
+            m_imgServers.insert(data.value("Name").toString(), source);
+        } else {
+            kDebug() << "Mimetype not supported by this applet";
+        }
+    }
+}
+
+void Pastebin::sourceRemoved(const QString &source)
+{
+    // update the options
+    if (source != "Mimetypes") {
+        QString key = m_txtServers.key(source);
+        m_txtServers.remove(key);
+
+        key = m_imgServers.key(source);
+        m_imgServers.remove(key);
+    }
+}
+
 void Pastebin::setHistorySize(int max)
 {
     if (max <= 0) {
@@ -392,29 +427,35 @@
     if (!m_newStuffDialog) {
         QString ghns("pastebin.knsrc");
         m_newStuffDialog = new KNS3::DownloadDialog( ghns );
-        connect(m_newStuffDialog, SIGNAL(accepted()), SLOT(newStuffFinished()));
+        connect(m_newStuffDialog, SIGNAL(accepted()),
+                this, SLOT(newStuffFinished()));
     }
     m_newStuffDialog->show();
 }
 
 void Pastebin::newStuffFinished()
 {
-    kDebug() << "\n\n\n\n\n----> CHANGED: " << m_newStuffDialog->changedEntries().count();
+    if ( m_newStuffDialog->changedEntries().count() ) {
+        // refresh the options of config dialog
+        refreshConfigDialog();
 
-    if ( m_newStuffDialog->changedEntries().count() ) {
+        // setup the config dialog to last options
         KConfigGroup cg = config();
+        uiConfig.textServer->setCurrentItem(cg.readEntry("TextProvider", ""));
+        uiConfig.imageServer->setCurrentItem(cg.readEntry("ImageProvider", ""));
+    }
+}
 
+void Pastebin::refreshConfigDialog()
+{
         // setup text
         uiConfig.textServer->clear();
         uiConfig.textServer->addItems(m_txtServers.keys());
-        uiConfig.textServer->setCurrentItem(cg.readEntry("TextProvider", ""));
 
         // setup image
         uiConfig.imageServer->clear();
         uiConfig.imageServer->addItems(m_imgServers.keys());
-        uiConfig.imageServer->setCurrentItem(cg.readEntry("ImageProvider", ""));
     }
-}
 
 void Pastebin::createConfigurationInterface(KConfigDialog *parent)
 {
@@ -424,16 +465,13 @@
     uiConfig.setupUi(general);
 
     connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
-    connect(parent, SIGNAL(cancelClicked()), this, SLOT(closeServerDialog()));
     parent->addPage(general, i18n("General"), Applet::icon());
 
     uiConfig.ghnsButton->setIcon(KIcon("get-hot-new-stuff"));
     connect(uiConfig.ghnsButton, SIGNAL(clicked()), this, SLOT(getNewStuff()));
 
-    uiConfig.textServer->addItems(m_txtServers.keys());
+    refreshConfigDialog();
     uiConfig.textServer->setCurrentItem(cg.readEntry("TextProvider", ""));
-
-    uiConfig.imageServer->addItems(m_imgServers.keys());
     uiConfig.imageServer->setCurrentItem(cg.readEntry("ImageProvider", ""));
 
     uiConfig.historySize->setValue(m_historySize);
--- trunk/KDE/kdeplasma-addons/applets/pastebin/pastebin.h #1194400:1194401
@@ -90,7 +90,9 @@
 public slots:
     void configAccepted();
     void configChanged();
-    void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
+    void dataUpdated(const QString &source, const Plasma::DataEngine::Data &data);
+    void sourceAdded(const QString &source);
+    void sourceRemoved(const QString &source);
 
 protected slots:
     virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
@@ -119,6 +121,7 @@
     void postingFinished(KJob *job);
     void getNewStuff();
     void newStuffFinished();
+    void refreshConfigDialog();
 
 private:
     int iconSize();
[prev in list] [next in list] [prev in thread] [next in thread] 

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