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 PRESENCESTATUSMODEL_H
19
#define PRESENCESTATUSMODEL_H
23
#include <QtCore/QString>
24
#include <QtCore/QAbstractTableModel>
26
class PresenceSerializationVisitor;
28
///CredentialModel: A model for account credentials
29
class LIB_EXPORT PresenceStatusModel : public QAbstractTableModel {
30
#pragma GCC diagnostic push
31
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
33
#pragma GCC diagnostic pop
36
//Internal representation
55
void addStatus(StatusData* status);
56
void setPresenceVisitor(PresenceSerializationVisitor* visitor);
59
Q_PROPERTY( QString customMessage READ customMessage WRITE setCustomMessage NOTIFY customMessageChanged(QString) )
60
Q_PROPERTY( bool useCustomStatus READ useCustomStatus WRITE setUseCustomStatus NOTIFY useCustomStatusChanged(bool) )
61
Q_PROPERTY( bool customStatus READ customStatus WRITE setCustomStatus NOTIFY customStatusChanged(bool) )
62
Q_PROPERTY( bool currentStatus READ currentStatus NOTIFY currentStatusChanged(bool) )
63
Q_PROPERTY( QString currentMessage READ currentMessage NOTIFY currentMessageChanged(QString) )
64
Q_PROPERTY( QModelIndex defaultStatus READ defaultStatus WRITE setDefaultStatus NOTIFY defaultStatusChanged(QModelIndex) )
65
Q_PROPERTY( QString currentName READ currentName NOTIFY currentNameChanged(QString) )
68
explicit PresenceStatusModel(QObject* parent = nullptr);
69
virtual ~PresenceStatusModel();
71
//Abstract model members
72
virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole ) const;
73
virtual int rowCount (const QModelIndex& parent = QModelIndex() ) const;
74
virtual int columnCount(const QModelIndex& parent = QModelIndex() ) const;
75
virtual Qt::ItemFlags flags (const QModelIndex& index ) const;
76
virtual bool setData (const QModelIndex& index, const QVariant &value, int role ) ;
77
virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
80
static PresenceStatusModel* instance();
83
void setDefaultStatus( const QModelIndex& idx );
86
QString customMessage () const;
87
bool useCustomStatus () const;
88
bool customStatus () const;
89
bool currentStatus () const;
90
QString currentMessage () const;
91
QString currentName () const;
92
QModelIndex defaultStatus () const;
97
QVector<StatusData*> m_lStatuses ;
98
QString m_CustomMessage ;
99
bool m_UseCustomStatus ;
100
bool m_CustomStatus ;
101
StatusData* m_pCurrentStatus ;
102
StatusData* m_pDefaultStatus ;
103
PresenceSerializationVisitor* m_pVisitor;
106
static PresenceStatusModel* m_spInstance;
110
void removeRow ( const QModelIndex& index );
112
void moveUp ( const QModelIndex& index );
113
void moveDown ( const QModelIndex& index );
114
void setUseCustomStatus( bool useCustom );
115
void setCustomStatus ( bool status );
116
void setCurrentIndex ( const QModelIndex& index );
117
void setCustomMessage ( const QString& message );
120
void currentIndexChanged ( const QModelIndex& current );
121
void currentNameChanged ( const QString& name );
122
void useCustomStatusChanged( bool useCustom );
123
void customMessageChanged ( const QString& message );
124
void customStatusChanged ( bool status );
125
void defaultStatusChanged ( const QModelIndex& def );
126
void currentMessageChanged ( const QString& message );
127
void currentStatusChanged ( bool status );
131
Q_DECLARE_METATYPE( PresenceStatusModel* )