From 71e593f8525535ab21851941b7c0fe072a365301 Mon Sep 17 00:00:00 2001
From: Emmanuel Lepage <emmanuel.lepage@savoirfairelinux.com>
Date: Wed, 2 May 2012 17:06:39 -0400
Subject: [PATCH] [ #10222 ] Use categorized views, fix bookmark

---
 src/CallModel.h   |  9 +++++----
 src/CallModel.hpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/src/CallModel.h b/src/CallModel.h
index 924264d8..ad2c8847 100644
--- a/src/CallModel.h
+++ b/src/CallModel.h
@@ -126,10 +126,11 @@ class LIB_EXPORT CallModel : public CallModelBase {
       void removeConference          ( Call* call                                  );
 
       //Getters
-      int size                                  ();
-      CallList                 getCallList      ();
-      static const CallHash&   getHistory       ();
-      static const QStringList getHistoryCallId ();
+      int size                                        ();
+      CallList                 getCallList            ();
+      static const CallHash&   getHistory             ();
+      static const QStringList getNumbersByPopularity ();
+      static const QStringList getHistoryCallId       ();
 
       //Account related
       static Account* getCurrentAccount  (                     );
diff --git a/src/CallModel.hpp b/src/CallModel.hpp
index 2145ac8c..a776e6fb 100644
--- a/src/CallModel.hpp
+++ b/src/CallModel.hpp
@@ -53,6 +53,27 @@ template  <typename CallWidget, typename Index> typename CallModel<CallWidget,In
 template  <typename CallWidget, typename Index> typename CallModel<CallWidget,Index>::InternalIndex  CallModel<CallWidget,Index>::m_sPrivateCallList_index  ;
 template  <typename CallWidget, typename Index> typename CallModel<CallWidget,Index>::InternalWidget CallModel<CallWidget,Index>::m_sPrivateCallList_widget ;
 
+/*****************************************************************************
+ *                                                                           *
+ *                             Private classes                               *
+ *                                                                           *
+ ****************************************************************************/
+class SortableCallSource {
+public:
+   SortableCallSource(Call* call=0) : count(0),callInfo(call) {}
+   uint count;
+   Call* callInfo;
+   const bool operator<(SortableCallSource other) {
+      return (other.count > count);
+   }
+};
+
+inline bool operator< (const SortableCallSource & s1, const SortableCallSource & s2)
+{
+    return  s1.count < s2.count;
+}
+
+
 /*****************************************************************************
  *                                                                           *
  *                               Constructor                                 *
@@ -427,6 +448,32 @@ template<typename CallWidget, typename Index> void CallModel<CallWidget,Index>::
    }
 }
 
+///Sort all history call by popularity and return the result (most popular first)
+template<typename CallWidget, typename Index> const QStringList CallModel<CallWidget,Index>::getNumbersByPopularity()
+{
+   QHash<QString,SortableCallSource*> hc;
+   foreach (Call* call, getHistory()) {
+      if (!hc[call->getPeerPhoneNumber()]) {
+         hc[call->getPeerPhoneNumber()] = new SortableCallSource(call);
+      }
+      hc[call->getPeerPhoneNumber()]->count++;
+   }
+   QList<SortableCallSource> userList;
+   foreach (SortableCallSource* i,hc) {
+      userList << *i;
+   }
+   qSort(userList);
+   QStringList cl;
+   for (int i=userList.size()-1;i >=0 ;i--) {
+      cl << userList[i].callInfo->getPeerPhoneNumber();
+   }
+   foreach (SortableCallSource* i,hc) {
+      delete i;
+   }
+   
+   return cl;
+}
+
 /*****************************************************************************
  *                                                                           *
  *                           Account related code                            *
-- 
GitLab