~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to kde/src/lib/lastusednumbermodel.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 *   Copyright (C) 2013-2014 by Savoir-Faire Linux                          *
 
3
 *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
 
4
 *                                                                          *
 
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.     *
 
9
 *                                                                          *
 
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.                        *
 
14
 *                                                                          *
 
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"
 
19
#include "call.h"
 
20
#include "phonenumber.h"
 
21
 
 
22
LastUsedNumberModel* LastUsedNumberModel::m_spInstance = nullptr;
 
23
 
 
24
struct ChainedPhoneNumber {
 
25
   ChainedPhoneNumber(PhoneNumber* n) : m_pPrevious(nullptr),m_pNext(nullptr),m_pSelf(n){}
 
26
   ChainedPhoneNumber* m_pPrevious;
 
27
   ChainedPhoneNumber* m_pNext;
 
28
   PhoneNumber*  m_pSelf;
 
29
};
 
30
 
 
31
LastUsedNumberModel::LastUsedNumberModel() : QAbstractListModel(),m_pFirstNode(nullptr),m_IsValid(false)
 
32
{
 
33
   for (int i=0;i<MAX_ITEM;i++) m_lLastNumbers[i] = nullptr;
 
34
}
 
35
 
 
36
LastUsedNumberModel* LastUsedNumberModel::instance()
 
37
{
 
38
   if (!m_spInstance) {
 
39
      m_spInstance = new LastUsedNumberModel();
 
40
   }
 
41
   return m_spInstance;
 
42
}
 
43
 
 
44
///Push 'call' phoneNumber on the top of the stack
 
45
void LastUsedNumberModel::addCall(Call* call)
 
46
{
 
47
   PhoneNumber* number = call->peerPhoneNumber();
 
48
   ChainedPhoneNumber* node = m_hNumbers[number];
 
49
   if (!number || ( node && m_pFirstNode == node) ) {
 
50
      
 
51
      //TODO enable threaded numbers now
 
52
      return;
 
53
   }
 
54
 
 
55
   if (!node) {
 
56
      node = new ChainedPhoneNumber(number);
 
57
      m_hNumbers[number] = node;
 
58
   }
 
59
   else {
 
60
      if (node->m_pPrevious)
 
61
         node->m_pPrevious->m_pNext = node->m_pNext;
 
62
      if (node->m_pNext)
 
63
         node->m_pNext->m_pPrevious = node->m_pPrevious;
 
64
   }
 
65
   if (m_pFirstNode) {
 
66
      m_pFirstNode->m_pPrevious = node;
 
67
      node->m_pNext = m_pFirstNode;
 
68
   }
 
69
   m_pFirstNode = node;
 
70
   m_IsValid = false;
 
71
   emit layoutChanged();
 
72
}
 
73
 
 
74
 
 
75
QVariant LastUsedNumberModel::data( const QModelIndex& index, int role) const
 
76
{
 
77
   if (!index.isValid())
 
78
      return QVariant();
 
79
   if (!m_IsValid) {
 
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;
 
84
         if (!current)
 
85
            break;
 
86
      }
 
87
      const_cast<LastUsedNumberModel*>(this)->m_IsValid = true;
 
88
   }
 
89
   switch (role) {
 
90
      case Qt::DisplayRole: {
 
91
         return m_lLastNumbers[index.row()]->m_pSelf->uri();
 
92
      }
 
93
   };
 
94
   return QVariant();
 
95
}
 
96
 
 
97
int LastUsedNumberModel::rowCount( const QModelIndex& parent) const
 
98
{
 
99
   if (parent.isValid())
 
100
      return 0;
 
101
   return m_hNumbers.size() < LastUsedNumberModel::MAX_ITEM?m_hNumbers.size():LastUsedNumberModel::MAX_ITEM;
 
102
}
 
103
 
 
104
Qt::ItemFlags LastUsedNumberModel::flags( const QModelIndex& index) const
 
105
{
 
106
   Q_UNUSED(index)
 
107
   return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
 
108
}
 
109
 
 
110
bool LastUsedNumberModel::setData( const QModelIndex& index, const QVariant &value, int role)
 
111
{
 
112
   Q_UNUSED(index)
 
113
   Q_UNUSED(value)
 
114
   Q_UNUSED(role)
 
115
   return false;
 
116
}