[SCM] ktp-approver packaging branch, master, updated. debian/15.12.1-1-299-g62cbbd7

Maximiliano Curia maxy at moszumanska.debian.org
Fri May 27 09:13:08 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-approver.git;a=commitdiff;h=8bd895a

The following commit has been merged in the master branch:
commit 8bd895a74fddc46c6f0bdf1f619a940d70e23d15
Author: George Kiagiadakis <george.kiagiadakis at collabora.co.uk>
Date:   Thu Jan 27 20:38:50 2011 +0200

    Implement reading handler preferences from a config file.
---
 src/handlewithcaller.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++-
 src/handlewithcaller.h   |  1 +
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/src/handlewithcaller.cpp b/src/handlewithcaller.cpp
index 659a867..2781733 100644
--- a/src/handlewithcaller.cpp
+++ b/src/handlewithcaller.cpp
@@ -16,19 +16,63 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 #include "handlewithcaller.h"
+#include "tpkdeapproverfactory.h"
+#include <KConfig>
+#include <KConfigGroup>
+#include <KDebug>
 #include <TelepathyQt4/PendingOperation>
+#include <TelepathyQt4/Channel>
 
 HandleWithCaller::HandleWithCaller(const Tp::ChannelDispatchOperationPtr & dispatchOperation,
                                    QObject *parent)
     : QObject(parent)
 {
     m_dispatchOperation = dispatchOperation;
-    m_possibleHandlers = dispatchOperation->possibleHandlers();
+
+    findHandlers();
     Q_ASSERT(!m_possibleHandlers.isEmpty());
 
     callHandleWith();
 }
 
+void HandleWithCaller::findHandlers()
+{
+    KConfig config(TpKDEApproverFactory::componentData());
+    KConfigGroup group(&config, "HandlerPreferences");
+
+    //realistically, dispatch operations only have one channel
+    //FIXME if there ever exists a case where a dispatch operation has more
+    //than one channels, fix this code to do something more appropriate
+    QString channelType = m_dispatchOperation->channels()[0]->channelType();
+
+    QStringList preferredHandlers = group.readEntry(channelType, QStringList());
+    QStringList possibleHandlers = m_dispatchOperation->possibleHandlers();
+
+    kDebug() << "Preferred:" << preferredHandlers;
+    kDebug() << "Possible:" << possibleHandlers;
+
+    //intersect the two lists, while respecting the order
+    //of preference that was read from the config file
+    QStringList::iterator it = preferredHandlers.begin();
+    while(it != preferredHandlers.end()) {
+        int index = possibleHandlers.indexOf(*it);
+        if (index != -1) {
+            possibleHandlers.removeAt(index);
+            ++it;
+        } else {
+            it = preferredHandlers.erase(it);
+        }
+    }
+
+    //preferredHandlers now contains the intersection. Because the intersection
+    //can lead to an empty list, we append the rest of the possible handlers
+    //to make sure it is not going to be empty.
+    preferredHandlers.append(possibleHandlers);
+
+    m_possibleHandlers = preferredHandlers;
+    kDebug() << "Final:" << m_possibleHandlers;
+}
+
 void HandleWithCaller::callHandleWith()
 {
     Tp::PendingOperation *op = m_dispatchOperation->handleWith(m_possibleHandlers.first());
diff --git a/src/handlewithcaller.h b/src/handlewithcaller.h
index 1e026a6..4478f59 100644
--- a/src/handlewithcaller.h
+++ b/src/handlewithcaller.h
@@ -31,6 +31,7 @@ private Q_SLOTS:
     void onHandleWithFinished(Tp::PendingOperation *operation);
 
 private:
+    void findHandlers();
     void callHandleWith();
 
     Tp::ChannelDispatchOperationPtr m_dispatchOperation;

-- 
ktp-approver packaging



More information about the pkg-kde-commits mailing list