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
***************************************************************************/
20
#ifndef ACCOUNT_LIST_H
21
#define ACCOUNT_LIST_H
24
#include <QtCore/QVector>
25
#include <QtCore/QStringList>
26
#include <QtCore/QAbstractListModel>
30
// #include "dbus/metatypes.h"
32
class AccountListColorVisitor;
34
///AccountList: List of all daemon accounts
35
class LIB_EXPORT AccountListModel : public QAbstractListModel {
36
#pragma GCC diagnostic push
37
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
39
#pragma GCC diagnostic pop
43
//Static getter and destructor
44
static AccountListModel* instance();
45
static void destroy();
48
const QVector<Account*>& getAccounts ( );
49
QVector<Account*> getAccountsByState ( const QString& state );
50
Q_INVOKABLE Account* getAccountById ( const QString& id ) const;
51
Q_INVOKABLE QList<Account*> getAccountsByHostNames (const QString& hostName ) const;
53
Account* firstRegisteredAccount ( ) const;
54
Account* getDefaultAccount ( ) const;
55
static Account* currentAccount ( );
56
Account* getAccountByModelIndex ( const QModelIndex& item ) const;
57
static QString getSimilarAliasIndex ( const QString& alias );
58
AccountListColorVisitor* colorVisitor ( );
60
//Abstract model accessors
61
QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const;
62
int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
63
Qt::ItemFlags flags ( const QModelIndex& index ) const;
66
void setPriorAccount ( const Account* );
67
virtual bool setData ( const QModelIndex& index, const QVariant &value, int role);
68
void setColorVisitor ( AccountListColorVisitor* visitor );
69
void setDefaultAccount(Account* a);
72
Q_INVOKABLE Account* addAccount ( const QString & alias );
73
Q_INVOKABLE void removeAccount ( Account* account );
74
void removeAccount ( QModelIndex index );
76
Q_INVOKABLE bool accountUp ( int index );
77
Q_INVOKABLE bool accountDown ( int index );
78
Q_INVOKABLE void cancel ( );
81
Account* operator[] (int i) ;
82
Account* operator[] (const QString& i) ;
83
const Account* operator[] (int i) const;
86
//Constructors & Destructors
87
explicit AccountListModel();
93
QVector<Account*> m_lAccounts ;
94
static AccountListModel* m_spAccountList ;
95
static Account* m_spPriorAccount ;
96
Account* m_pDefaultAccount ;
97
AccountListColorVisitor* m_pColorVisitor ;
98
QStringList m_lDeletedAccounts;
102
void updateAccounts();
103
void registerAllAccounts();
106
void accountChanged(const QString& account,const QString& state, int code);
107
void accountChanged(Account* a);
108
void slotVoiceMailNotify( const QString& accountID , int count );
111
///The account list changed
112
void accountListUpdated();
113
///Emitted when an account state change
114
void accountStateChanged ( Account* account, QString state);
115
///Emitted when an account enable attribute change
116
void accountEnabledChanged( Account* source );
117
///Emitted when the default account change
118
void defaultAccountChanged( Account* a );
119
///Emitted when the default account change
120
void priorAccountChanged ( Account* a );
121
///Emitted when one account registration state change
122
void accountRegistrationChanged(Account* a, bool registration);
123
///Emitted when the network is down
125
///Emitted when a new voice mail is available
126
void voiceMailNotify(Account* account, int count);
128
Q_DECLARE_METATYPE(AccountListModel*)
130
class LIB_EXPORT AccountListNoCheckProxyModel : public QAbstractListModel
133
virtual QVariant data(const QModelIndex& index,int role = Qt::DisplayRole ) const;
134
virtual bool setData( const QModelIndex& index, const QVariant &value, int role);
135
virtual Qt::ItemFlags flags (const QModelIndex& index) const;
136
virtual int rowCount(const QModelIndex& parent = QModelIndex() ) const;