~ken-vandine/address-book-app/add_profile

« back to all changes in this revision

Viewing changes to src/imports/Ubuntu/Contacts/mostcalledproxymodel.h

  • Committer: CI bot
  • Author(s): Tarmac, Renato Araujo Oliveira Filho
  • Date: 2014-07-04 14:55:22 UTC
  • mfrom: (169.22.12 release-2014-07-02)
  • Revision ID: ps-jenkins@lists.canonical.com-20140704145522-7r65oy9m1zarc7yz
* Implemented MostCalledContactsModel in C++ as a proxy model for HistoryEventModel;
* Enabled share button again.
* Fixed build warning: comparison with string literal results in unspecified behavior;
* Implemented swipe to delete. Fixes: 1323577

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012-2013 Canonical, Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 */
 
16
 
 
17
#ifndef __MOSTCALLEDCONTACTSMODEL_H__
 
18
#define __MOSTCALLEDCONTACTSMODEL_H__
 
19
 
 
20
#include <QtCore/QAbstractListModel>
 
21
#include <QtCore/QScopedPointer>
 
22
#include <QtCore/QDateTime>
 
23
 
 
24
#include <QtContacts/QContactManager>
 
25
 
 
26
struct MostCalledContactsModelData
 
27
{
 
28
    QString contactId;
 
29
    QString phoneNumber;
 
30
    int callCount;
 
31
};
 
32
 
 
33
class MostCalledContactsModel : public QAbstractListModel
 
34
{
 
35
    Q_OBJECT
 
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)
 
41
 
 
42
public:
 
43
    enum Role {
 
44
        ContactIdRole = 0,
 
45
        PhoneNumberRole,
 
46
        CallCountRole
 
47
    };
 
48
 
 
49
    MostCalledContactsModel(QObject *parent=0);
 
50
    ~MostCalledContactsModel();
 
51
 
 
52
    QVariant data(const QModelIndex &index, int role) const;
 
53
    QHash<int, QByteArray> roleNames() const;
 
54
    int rowCount(const QModelIndex&) const;
 
55
 
 
56
    QAbstractItemModel *sourceModel() const;
 
57
    void setSourceModel(QAbstractItemModel *model);
 
58
 
 
59
    uint maxCount() const;
 
60
    void setMaxCount(uint value);
 
61
 
 
62
    int callAverage() const;
 
63
    bool outdated() const;
 
64
 
 
65
    QDateTime startInterval() const;
 
66
    void setStartInterval(const QDateTime &value);
 
67
 
 
68
    Q_INVOKABLE void update();
 
69
 
 
70
Q_SIGNALS:
 
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);
 
76
 
 
77
private Q_SLOTS:
 
78
    void markAsOutdated();
 
79
 
 
80
private:
 
81
    QAbstractItemModel *m_sourceModel;
 
82
    QScopedPointer<QtContacts::QContactManager> m_manager;
 
83
    QList<MostCalledContactsModelData> m_data;
 
84
    uint m_maxCount;
 
85
    int m_average;
 
86
    QDateTime m_startInterval;
 
87
    bool m_outdated;
 
88
    bool m_reloadingModel;
 
89
 
 
90
    QString fetchContactId(const QString &phoneNumber);
 
91
    QVariant getSourceData(int row, int role);
 
92
};
 
93
 
 
94
 
 
95
#endif