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

« back to all changes in this revision

Viewing changes to kde/src/lib/phonedirectorymodel.h

  • 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
#ifndef PHONEDIRECTORYMODEL_H
 
19
#define PHONEDIRECTORYMODEL_H
 
20
#include "typedefs.h"
 
21
 
 
22
//Qt
 
23
#include <QtCore/QString>
 
24
#include <QtCore/QAbstractTableModel>
 
25
 
 
26
//SFLPhone
 
27
class PhoneNumber         ;
 
28
class Contact             ;
 
29
class Account             ;
 
30
class Call                ;
 
31
class TemporaryPhoneNumber;
 
32
 
 
33
///CredentialModel: A model for account credentials
 
34
class LIB_EXPORT PhoneDirectoryModel : public QAbstractTableModel {
 
35
 
 
36
   //NumberCompletionModel need direct access to the indexes
 
37
   friend class NumberCompletionModel;
 
38
 
 
39
   //Friend unit test class
 
40
   friend class AutoCompletionTest;
 
41
 
 
42
   //Phone number need to update the indexes as they change
 
43
   friend class PhoneNumber          ;
 
44
 
 
45
   #pragma GCC diagnostic push
 
46
   #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
 
47
   Q_OBJECT
 
48
   #pragma GCC diagnostic pop
 
49
public:
 
50
   Q_PROPERTY(int count READ count )
 
51
 
 
52
   virtual ~PhoneDirectoryModel();
 
53
 
 
54
   //Abstract model members
 
55
   virtual QVariant      data       (const QModelIndex& index, int role = Qt::DisplayRole                 ) const;
 
56
   virtual int           rowCount   (const QModelIndex& parent = QModelIndex()                            ) const;
 
57
   virtual int           columnCount(const QModelIndex& parent = QModelIndex()                            ) const;
 
58
   virtual Qt::ItemFlags flags      (const QModelIndex& index                                             ) const;
 
59
   virtual bool          setData    (const QModelIndex& index, const QVariant &value, int role            )      ;
 
60
   virtual QVariant      headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
 
61
 
 
62
   //Singleton
 
63
   static PhoneDirectoryModel* instance();
 
64
 
 
65
   //Factory
 
66
   Q_INVOKABLE PhoneNumber* getNumber(const QString& uri, const QString& type = QString());
 
67
   Q_INVOKABLE PhoneNumber* getNumber(const QString& uri, Account* account, const QString& type = QString());
 
68
   Q_INVOKABLE PhoneNumber* getNumber(const QString& uri, Contact* contact, Account* account = nullptr, const QString& type = QString());
 
69
   Q_INVOKABLE PhoneNumber* fromHash(const QString& hash);
 
70
   Q_INVOKABLE PhoneNumber* fromTemporary(const TemporaryPhoneNumber* number);
 
71
 
 
72
   //Getter
 
73
   int count() const;
 
74
   bool callWithAccount() const;
 
75
 
 
76
   //Setters
 
77
   void setCallWithAccount(bool value);
 
78
 
 
79
   //Static
 
80
   QVector<PhoneNumber*> getNumbersByPopularity() const;
 
81
 
 
82
protected:
 
83
   //Internal data structures
 
84
   ///@struct NumberWrapper Wrap phone numbers to prevent collisions
 
85
   struct NumberWrapper {
 
86
      QVector<PhoneNumber*> numbers;
 
87
   };
 
88
 
 
89
private:
 
90
 
 
91
   //Model columns
 
92
   enum class Columns {
 
93
      URI              = 0,
 
94
      TYPE             = 1,
 
95
      CONTACT          = 2,
 
96
      ACCOUNT          = 3,
 
97
      STATE            = 4,
 
98
      CALL_COUNT       = 5,
 
99
      WEEK_COUNT       = 6,
 
100
      TRIM_COUNT       = 7,
 
101
      HAVE_CALLED      = 8,
 
102
      LAST_USED        = 9,
 
103
      NAME_COUNT       = 10,
 
104
      TOTAL_SECONDS    = 11,
 
105
      POPULARITY_INDEX = 12,
 
106
      BOOKMARED        = 13,
 
107
      TRACKED          = 14,
 
108
      PRESENT          = 15,
 
109
      PRESENCE_MESSAGE = 16,
 
110
      UID              = 17,
 
111
   };
 
112
 
 
113
   //Constructor
 
114
   explicit PhoneDirectoryModel(QObject* parent = nullptr);
 
115
 
 
116
   //Helpers
 
117
   void indexNumber(PhoneNumber* number, const QStringList& names);
 
118
 
 
119
   //Singleton
 
120
   static PhoneDirectoryModel* m_spInstance;
 
121
 
 
122
   //Attributes
 
123
   QVector<PhoneNumber*>         m_lNumbers         ;
 
124
   QHash<QString,NumberWrapper*> m_hDirectory       ;
 
125
   QVector<PhoneNumber*>         m_lPopularityIndex ;
 
126
   QMap<QString,NumberWrapper*>  m_lSortedNames     ;
 
127
   QMap<QString,NumberWrapper*>  m_hSortedNumbers   ;
 
128
   QHash<QString,NumberWrapper*> m_hNumbersByNames  ;
 
129
   bool                          m_CallWithAccount  ;
 
130
 
 
131
private Q_SLOTS:
 
132
   void slotCallAdded(Call* call);
 
133
   void slotChanged();
 
134
 
 
135
   //From DBus
 
136
   void slotNewBuddySubscription(const QString& uri, const QString& accountId, bool status, const QString& message);
 
137
//    void slotStatusChanges(const QString& accountId, const QString& uri, bool status); //Deprecated?
 
138
};
 
139
Q_DECLARE_METATYPE(PhoneDirectoryModel*)
 
140
 
 
141
#endif