1
/****************************************************************************
2
* Copyright (C) 2012-2013 by Savoir-Faire Linux *
3
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
5
* This library is free software; you can redistribute it and/or *
6
* modify it under the terms of the GNU Lesser General Public *
7
* License as published by the Free Software Foundation; either *
8
* version 2.1 of the License, or (at your option) any later version. *
10
* This library is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13
* Lesser General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17
***************************************************************************/
18
#include "historymodel.h"
19
#include "callmanager_interface_singleton.h"
20
#include "configurationmanager_interface_singleton.h"
24
/*****************************************************************************
28
****************************************************************************/
30
///SortableCallSource: helper class to make sorting possible
31
class SortableCallSource {
33
SortableCallSource(Call* call=0) : count(0),callInfo(call) {}
36
bool operator<(SortableCallSource other) {
37
return (other.count > count);
41
inline bool operator< (const SortableCallSource & s1, const SortableCallSource & s2)
43
return s1.count < s2.count;
46
HistoryModel* HistoryModel::m_spInstance = nullptr;
47
CallMap HistoryModel::m_sHistoryCalls ;
50
/*****************************************************************************
54
****************************************************************************/
57
HistoryModel::HistoryModel():m_HistoryInit(false)
59
ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
60
const QVector< QMap<QString, QString> > history = configurationManager.getHistory();
61
foreach (const MapStringString& hc, history) {
62
Call* pastCall = Call::buildHistoryCall(
64
hc[ TIMESTAMP_START_KEY ].toUInt(),
65
hc[ TIMESTAMP_STOP_KEY ].toUInt(),
66
hc[ ACCOUNT_ID_KEY ] ,
67
hc[ DISPLAY_NAME_KEY ] ,
68
hc[ PEER_NUMBER_KEY ] ,
71
if (pastCall->getPeerName().isEmpty()) {
72
pastCall->setPeerName("Unknown");
74
pastCall->setRecordingPath(hc[ RECORDING_PATH_KEY ]);
81
HistoryModel::~HistoryModel()
83
m_spInstance = nullptr;
87
HistoryModel* HistoryModel::self()
90
m_spInstance = new HistoryModel();
95
/*****************************************************************************
97
* History related code *
99
****************************************************************************/
102
void HistoryModel::add(Call* call)
104
self()->addPriv(call);
108
void HistoryModel::addPriv(Call* call)
111
m_sHistoryCalls[call->getStartTimeStamp()] = call;
113
emit newHistoryCall(call);
114
emit historyChanged();
117
///Return the history list
118
const CallMap& HistoryModel::getHistory()
121
return m_sHistoryCalls;
124
///Return a list of all previous calls
125
const QStringList HistoryModel::getHistoryCallId()
128
QStringList toReturn;
129
foreach(Call* call, m_sHistoryCalls) {
130
toReturn << call->getCallId();
135
///Sort all history call by popularity and return the result (most popular first)
136
const QStringList HistoryModel::getNumbersByPopularity()
139
QHash<QString,SortableCallSource*> hc;
140
foreach (Call* call, getHistory()) {
141
if (!hc[call->getPeerPhoneNumber()]) {
142
hc[call->getPeerPhoneNumber()] = new SortableCallSource(call);
144
hc[call->getPeerPhoneNumber()]->count++;
146
QList<SortableCallSource> userList;
147
foreach (SortableCallSource* i,hc) {
152
for (int i=userList.size()-1;i >=0 ;i--) {
153
cl << userList[i].callInfo->getPeerPhoneNumber();
155
foreach (SortableCallSource* i,hc) {
160
} //getNumbersByPopularity