1
/****************************************************************************
2
* Copyright (C) 2009-2014 by Savoir-Faire Linux *
3
* Author : Jérémy Quentin <jeremy.quentin@savoirfairelinux.com> *
4
* Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Lesser General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2.1 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14
* Lesser General Public License for more details. *
16
* You should have received a copy of the GNU General Public License *
17
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
18
***************************************************************************/
19
#ifndef ABSTRACTCONTACTBACKEND_H
20
#define ABSTRACTCONTACTBACKEND_H
24
#include <QStringList>
26
#include <QtCore/QAbstractItemModel>
36
typedef QList<Contact*> ContactList;
38
///AbstractContactBackend: Allow different way to handle contact without poluting the library
39
class LIB_EXPORT AbstractContactBackend : public QAbstractItemModel {
40
#pragma GCC diagnostic push
41
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
43
#pragma GCC diagnostic pop
50
FormattedLastUsed = 104,
51
IndexedLastUsed = 105,
54
Filter = 200, //All roles, all at once
55
DropState = 300, //State for drag and drop
58
explicit AbstractContactBackend(QObject* parent = nullptr);
59
virtual ~AbstractContactBackend();
61
///Get a contact using a phone number
62
///@param resolveDNS interpret the number as is (false) or parse it to extract the domain and number (true)
63
// virtual Contact* getContactByPhone ( const QString& phoneNumber , bool resolveDNS = false, Account* a = nullptr) = 0;
65
///Return a contact (or nullptr) according to the contact unique identifier
66
virtual Contact* getContactByUid ( const QString& uid ) = 0;
67
///Edit 'contact', the implementation may be a GUI or somehting else
68
virtual void editContact ( Contact* contact ) = 0;
69
///Add a new contact to the backend
70
virtual void addNewContact ( Contact* contact ) = 0;
72
virtual const ContactList& getContactList() const = 0;
74
///Add a new phone number to an existing contact
75
virtual void addPhoneNumber( Contact* contact , QString number, QString type )=0;
77
//Model implementation
78
virtual bool setData ( const QModelIndex& index, const QVariant &value, int role ) __attribute__ ((const));
79
virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const;
80
virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
81
virtual Qt::ItemFlags flags ( const QModelIndex& index ) const;
82
virtual int columnCount ( const QModelIndex& parent = QModelIndex() ) const;
83
virtual QModelIndex parent ( const QModelIndex& index ) const;
84
virtual QModelIndex index ( int row, int column, const QModelIndex& parent=QModelIndex()) const;
85
virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
90
virtual ContactList update_slot() = 0;
93
QString getUserFromPhone (const QString &phoneNumber);
96
QHash<QString,Contact*> m_ContactByUid ;
102
void slotReloadModel();
105
void collectionChanged();
106
void newContactAdded(Contact* c);