diff --git a/src/CallModel.h b/src/CallModel.h index 924264d8f9907556eafa1ba2bc373069b484dc1b..ad2c8847fad92e2d912f4e73c70ae9ea20b825a8 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 2145ac8cf2901c67eca394acac68c3269b090f5a..a776e6fbb42b207dbf2c49eb4d617ec6cd20d96c 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 *