2
* Copyright (C) 2012-2013 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
#ifndef __MOSTCALLEDCONTACTSMODEL_H__
18
#define __MOSTCALLEDCONTACTSMODEL_H__
20
#include <QtCore/QAbstractListModel>
21
#include <QtCore/QScopedPointer>
22
#include <QtCore/QDateTime>
24
#include <QtContacts/QContactManager>
26
struct MostCalledContactsModelData
33
class MostCalledContactsModel : public QAbstractListModel
36
Q_PROPERTY(QAbstractItemModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
37
Q_PROPERTY(uint maxCount READ maxCount WRITE setMaxCount NOTIFY maxCountChanged)
38
Q_PROPERTY(int callAverage READ callAverage NOTIFY callAverageChanged)
39
Q_PROPERTY(QDateTime startInterval READ startInterval WRITE setStartInterval NOTIFY startIntervalChanged)
40
Q_PROPERTY(bool outdated READ outdated NOTIFY outdatedChange)
49
MostCalledContactsModel(QObject *parent=0);
50
~MostCalledContactsModel();
52
QVariant data(const QModelIndex &index, int role) const;
53
QHash<int, QByteArray> roleNames() const;
54
int rowCount(const QModelIndex&) const;
56
QAbstractItemModel *sourceModel() const;
57
void setSourceModel(QAbstractItemModel *model);
59
uint maxCount() const;
60
void setMaxCount(uint value);
62
int callAverage() const;
63
bool outdated() const;
65
QDateTime startInterval() const;
66
void setStartInterval(const QDateTime &value);
68
Q_INVOKABLE void update();
71
void maxCountChanged(uint value);
72
void callAverageChanged(int value);
73
void startIntervalChanged(const QDateTime &value);
74
void sourceModelChanged(QAbstractItemModel *value);
75
void outdatedChange(bool value);
78
void markAsOutdated();
81
QAbstractItemModel *m_sourceModel;
82
QScopedPointer<QtContacts::QContactManager> m_manager;
83
QList<MostCalledContactsModelData> m_data;
86
QDateTime m_startInterval;
88
bool m_reloadingModel;
90
QString fetchContactId(const QString &phoneNumber);
91
QVariant getSourceData(int row, int role);