From c86edc0c7954a5dec11fbb300432c57fafd87385 Mon Sep 17 00:00:00 2001
From: Emmanuel Lepage <emmanuel.lepage@savoirfairelinux.com>
Date: Tue, 15 May 2012 14:08:52 -0400
Subject: [PATCH] [ #10724 ] Add bookmarks to the dataengine

---
 kde/src/klib/dataengine/sflphonEngine.cpp | 40 +++++++++++++++++++++--
 kde/src/klib/dataengine/sflphonEngine.h   |  1 +
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/kde/src/klib/dataengine/sflphonEngine.cpp b/kde/src/klib/dataengine/sflphonEngine.cpp
index 046c24e4f7..cffd9f1447 100644
--- a/kde/src/klib/dataengine/sflphonEngine.cpp
+++ b/kde/src/klib/dataengine/sflphonEngine.cpp
@@ -12,6 +12,7 @@
 #include "../../lib/sflphone_const.h"
 #include "../../klib/AkonadiBackend.h"
 #include "../../klib/HelperFunctions.h"
+#include "../../klib/ConfigurationSkeleton.h"
 #include "sflphoneService.h">
 
 CallModel<>* SFLPhoneEngine::m_pModel = NULL;
@@ -56,6 +57,9 @@ bool SFLPhoneEngine::sourceRequestEvent(const QString &name)
    else if ( name == "contacts"    ) {
       updateContacts();
    }
+   else if ( name == "bookmark"    ) {
+      updateBookmarkList();
+   }
    return true;//updateSourceEvent(name);
 }
 
@@ -67,7 +71,7 @@ bool SFLPhoneEngine::updateSourceEvent(const QString &name)
 
 QStringList SFLPhoneEngine::sources() const {
    QStringList toReturn;
-   toReturn << "calls" << "history" << "conferences" << "info" << "accounts" << "contacts";
+   toReturn << "calls" << "history" << "conferences" << "info" << "accounts" << "contacts" << "bookmark";
    return toReturn;
 }
 
@@ -116,7 +120,6 @@ void SFLPhoneEngine::updateHistory()
    setHistoryCategory(list,HistorySortingMode::Date);
 
    foreach (Call* oldCall, list) {
-      qDebug() << oldCall->getStopTimeStamp();
       historyCall[oldCall->getCallId()][ "peerName"   ] = oldCall->getPeerName();
       historyCall[oldCall->getCallId()][ "peerNumber" ] = oldCall->getPeerPhoneNumber();
       historyCall[oldCall->getCallId()][ "length"     ] = oldCall->getStopTimeStamp().toInt() - oldCall->getStartTimeStamp().toInt();
@@ -140,6 +143,38 @@ void SFLPhoneEngine::updateCallList()
    }
 }
 
+void SFLPhoneEngine::updateBookmarkList()
+{
+   removeAllData("bookmark");
+   int i=0;
+   QStringList cl = getModel()->getNumbersByPopularity();
+   for (;i < ((cl.size() < 10)?cl.size():10);i++) {
+      QHash<QString,QVariant> pop;
+      Contact* cont = AkonadiBackend::getInstance()->getContactByPhone(cl[i],true);
+      if (cont) {
+         pop["peerName"     ] = cont->getFormattedName();
+      }
+      else {
+         pop["peerName"     ] = cl[i];
+      }
+      pop["peerNumber"   ] = cl[i];
+      pop["section"      ] = "Popular";
+      pop["listPriority" ] = 1000;
+      setData("bookmark", QString::number(i), pop);
+   }
+
+   //TODO Wont work for now
+   foreach (QString nb, ConfigurationSkeleton::bookmarkList()) {
+      i++;
+      QHash<QString,QVariant> pop;
+      pop["peerName"     ] = "TODO";
+      pop["peerNumber"   ] = nb;
+      pop["section"      ] = "1";
+      pop["listPriority" ] = 0;
+      setData("bookmark", QString::number(i), pop);
+   }
+}
+
 void SFLPhoneEngine::updateConferenceList()
 {
    foreach (Call* call, m_pModel->getCalls()) {
@@ -172,6 +207,7 @@ void SFLPhoneEngine::updateCollection()
       setData("contacts", QString::number(i), QVariant(cont));
       i++;
    }
+   updateBookmarkList();
 }
 
 void SFLPhoneEngine::updateContacts()
diff --git a/kde/src/klib/dataengine/sflphonEngine.h b/kde/src/klib/dataengine/sflphonEngine.h
index 47370f3065..0b31dc848d 100644
--- a/kde/src/klib/dataengine/sflphonEngine.h
+++ b/kde/src/klib/dataengine/sflphonEngine.h
@@ -61,6 +61,7 @@ class SFLPhoneEngine : public Plasma::DataEngine,public SortableDockCommon<>
       void updateAccounts       ();
       void updateConferenceList ();
       void updateContacts       ();
+      void updateBookmarkList   ();
       void updateInfo();
    private slots:
       void updateCollection();
-- 
GitLab