1
/****************************************************************************
2
* Copyright (C) 2013-2014 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 "lastusednumbermodel.h"
20
#include "phonenumber.h"
22
LastUsedNumberModel* LastUsedNumberModel::m_spInstance = nullptr;
24
struct ChainedPhoneNumber {
25
ChainedPhoneNumber(PhoneNumber* n) : m_pPrevious(nullptr),m_pNext(nullptr),m_pSelf(n){}
26
ChainedPhoneNumber* m_pPrevious;
27
ChainedPhoneNumber* m_pNext;
31
LastUsedNumberModel::LastUsedNumberModel() : QAbstractListModel(),m_pFirstNode(nullptr),m_IsValid(false)
33
for (int i=0;i<MAX_ITEM;i++) m_lLastNumbers[i] = nullptr;
36
LastUsedNumberModel* LastUsedNumberModel::instance()
39
m_spInstance = new LastUsedNumberModel();
44
///Push 'call' phoneNumber on the top of the stack
45
void LastUsedNumberModel::addCall(Call* call)
47
PhoneNumber* number = call->peerPhoneNumber();
48
ChainedPhoneNumber* node = m_hNumbers[number];
49
if (!number || ( node && m_pFirstNode == node) ) {
51
//TODO enable threaded numbers now
56
node = new ChainedPhoneNumber(number);
57
m_hNumbers[number] = node;
60
if (node->m_pPrevious)
61
node->m_pPrevious->m_pNext = node->m_pNext;
63
node->m_pNext->m_pPrevious = node->m_pPrevious;
66
m_pFirstNode->m_pPrevious = node;
67
node->m_pNext = m_pFirstNode;
75
QVariant LastUsedNumberModel::data( const QModelIndex& index, int role) const
80
ChainedPhoneNumber* current = m_pFirstNode;
81
for (int i=0;i<MAX_ITEM;i++) { //Can only grow, no need to clear
82
const_cast<LastUsedNumberModel*>(this)->m_lLastNumbers[i] = current;
83
current = current->m_pNext;
87
const_cast<LastUsedNumberModel*>(this)->m_IsValid = true;
90
case Qt::DisplayRole: {
91
return m_lLastNumbers[index.row()]->m_pSelf->uri();
97
int LastUsedNumberModel::rowCount( const QModelIndex& parent) const
101
return m_hNumbers.size() < LastUsedNumberModel::MAX_ITEM?m_hNumbers.size():LastUsedNumberModel::MAX_ITEM;
104
Qt::ItemFlags LastUsedNumberModel::flags( const QModelIndex& index) const
107
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
110
bool LastUsedNumberModel::setData( const QModelIndex& index, const QVariant &value, int role)