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
#ifndef PHONEDIRECTORYMODEL_H
19
#define PHONEDIRECTORYMODEL_H
23
#include <QtCore/QString>
24
#include <QtCore/QAbstractTableModel>
31
class TemporaryPhoneNumber;
33
///CredentialModel: A model for account credentials
34
class LIB_EXPORT PhoneDirectoryModel : public QAbstractTableModel {
36
//NumberCompletionModel need direct access to the indexes
37
friend class NumberCompletionModel;
39
//Friend unit test class
40
friend class AutoCompletionTest;
42
//Phone number need to update the indexes as they change
43
friend class PhoneNumber ;
45
#pragma GCC diagnostic push
46
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
48
#pragma GCC diagnostic pop
50
Q_PROPERTY(int count READ count )
52
virtual ~PhoneDirectoryModel();
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;
63
static PhoneDirectoryModel* instance();
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);
74
bool callWithAccount() const;
77
void setCallWithAccount(bool value);
80
QVector<PhoneNumber*> getNumbersByPopularity() const;
83
//Internal data structures
84
///@struct NumberWrapper Wrap phone numbers to prevent collisions
85
struct NumberWrapper {
86
QVector<PhoneNumber*> numbers;
105
POPULARITY_INDEX = 12,
109
PRESENCE_MESSAGE = 16,
114
explicit PhoneDirectoryModel(QObject* parent = nullptr);
117
void indexNumber(PhoneNumber* number, const QStringList& names);
120
static PhoneDirectoryModel* m_spInstance;
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 ;
132
void slotCallAdded(Call* call);
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?
139
Q_DECLARE_METATYPE(PhoneDirectoryModel*)