Merge lp:~renatofilho/address-book-app/no-most-called into lp:address-book-app

Proposed by Renato Araujo Oliveira Filho
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 667
Merged at revision: 666
Proposed branch: lp:~renatofilho/address-book-app/no-most-called
Merge into: lp:address-book-app
Diff against target: 822 lines (+1/-727)
9 files modified
debian/control (+1/-3)
src/imports/Ubuntu/Contacts/CMakeLists.txt (+0/-4)
src/imports/Ubuntu/Contacts/ContactListView.qml (+0/-13)
src/imports/Ubuntu/Contacts/MostCalledList.qml (+0/-115)
src/imports/Ubuntu/Contacts/MostCalledModel.qml (+0/-102)
src/imports/Ubuntu/Contacts/mostcalledproxymodel.cpp (+0/-374)
src/imports/Ubuntu/Contacts/mostcalledproxymodel.h (+0/-112)
src/imports/Ubuntu/Contacts/plugin.cpp (+0/-2)
src/imports/Ubuntu/Contacts/qmldir (+0/-2)
To merge this branch: bzr merge lp:~renatofilho/address-book-app/no-most-called
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
system-apps-ci-bot continuous-integration Approve
Review via email: mp+313059@code.launchpad.net

Commit message

Remove MostCalledList.

It will be moved to dialer-app.

To post a comment you must log in.
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :

PASSED: Continuous integration, rev:666
https://jenkins.canonical.com/system-apps/job/lp-address-book-app-ci/52/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build/2180
    SUCCESS: https://jenkins.canonical.com/system-apps/job/test-0-autopkgtest/label=phone-armhf,release=vivid+overlay,testname=default/562
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/2183
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/2010
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/2010/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2010
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2010/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=zesty/2010
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=zesty/2010/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/2010
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/2010/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2010
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2010/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=zesty/2010
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=zesty/2010/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/2010
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/2010/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/2010
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/2010/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=zesty/2010
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=zesty/2010/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-address-book-app-ci/52/rebuild

review: Approve (continuous-integration)
667. By Renato Araujo Oliveira Filho

Remove 'qtdeclarative5-ubuntu-content1' as dep for 's390x' arch.

Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :

PASSED: Continuous integration, rev:667
https://jenkins.canonical.com/system-apps/job/lp-address-book-app-ci/53/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build/2188
    SUCCESS: https://jenkins.canonical.com/system-apps/job/test-0-autopkgtest/label=phone-armhf,release=vivid+overlay,testname=default/563
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/2191
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/2018
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/2018/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2018
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/2018/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=zesty/2018
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=zesty/2018/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/2018
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/2018/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2018
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/2018/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=zesty/2018
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=zesty/2018/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/2018
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/2018/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/2018
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/2018/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=zesty/2018
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=zesty/2018/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-address-book-app-ci/53/rebuild

review: Approve (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2016-11-24 18:54:55 +0000
+++ debian/control 2016-12-14 13:04:55 +0000
@@ -23,8 +23,7 @@
23 qtdeclarative5-gsettings1.0 [amd64 armhf i386],23 qtdeclarative5-gsettings1.0 [amd64 armhf i386],
24 qml-module-ofono [amd64 armhf i386],24 qml-module-ofono [amd64 armhf i386],
25 qtdeclarative5-qtcontacts-plugin [amd64 armhf i386],25 qtdeclarative5-qtcontacts-plugin [amd64 armhf i386],
26 qtdeclarative5-ubuntu-content1 [amd64 armhf i386 s390x],26 qtdeclarative5-ubuntu-content1 [amd64 armhf i386],
27 qtdeclarative5-ubuntu-history0.1 [amd64 armhf i386],
28 qtdeclarative5-ubuntu-keyboard-extensions0.1 [amd64 armhf i386],27 qtdeclarative5-ubuntu-keyboard-extensions0.1 [amd64 armhf i386],
29 qtdeclarative5-buteo-syncfw0.1 [amd64 armhf i386],28 qtdeclarative5-buteo-syncfw0.1 [amd64 armhf i386],
30 qtdeclarative5-ubuntu-telephony-phonenumber0.1 [amd64 armhf i386],29 qtdeclarative5-ubuntu-telephony-phonenumber0.1 [amd64 armhf i386],
@@ -59,7 +58,6 @@
59 qtdeclarative5-qtquick2-plugin,58 qtdeclarative5-qtquick2-plugin,
60 qml-module-ofono,59 qml-module-ofono,
61 qtdeclarative5-ubuntu-addressbook0.1 (= ${binary:Version}),60 qtdeclarative5-ubuntu-addressbook0.1 (= ${binary:Version}),
62 qtdeclarative5-ubuntu-history0.1,
63 qtdeclarative5-ubuntu-keyboard-extensions0.1,61 qtdeclarative5-ubuntu-keyboard-extensions0.1,
64 qtdeclarative5-ubuntu-telephony-phonenumber0.1 (>= 0.1+14.10.20140715.1),62 qtdeclarative5-ubuntu-telephony-phonenumber0.1 (>= 0.1+14.10.20140715.1),
65 ${misc:Depends},63 ${misc:Depends},
6664
=== modified file 'src/imports/Ubuntu/Contacts/CMakeLists.txt'
--- src/imports/Ubuntu/Contacts/CMakeLists.txt 2016-01-22 14:51:39 +0000
+++ src/imports/Ubuntu/Contacts/CMakeLists.txt 2016-12-14 13:04:55 +0000
@@ -18,8 +18,6 @@
18 FastScroll.qml18 FastScroll.qml
19 ListItemWithActionsCheckBox.qml19 ListItemWithActionsCheckBox.qml
20 ListItemWithActions.qml20 ListItemWithActions.qml
21 MostCalledList.qml
22 MostCalledModel.qml
23 MultipleSelectionListView.qml21 MultipleSelectionListView.qml
24 MultipleSelectionVisualModel.qml22 MultipleSelectionVisualModel.qml
25 Ofono.qml23 Ofono.qml
@@ -40,8 +38,6 @@
40 contacts.cpp38 contacts.cpp
41 imagescalethread.h39 imagescalethread.h
42 imagescalethread.cpp40 imagescalethread.cpp
43 mostcalledproxymodel.h
44 mostcalledproxymodel.cpp
45 plugin.h41 plugin.h
46 plugin.cpp42 plugin.cpp
47 simcardcontacts.h43 simcardcontacts.h
4844
=== modified file 'src/imports/Ubuntu/Contacts/ContactListView.qml'
--- src/imports/Ubuntu/Contacts/ContactListView.qml 2016-09-19 20:47:48 +0000
+++ src/imports/Ubuntu/Contacts/ContactListView.qml 2016-12-14 13:04:55 +0000
@@ -570,19 +570,6 @@
570 }570 }
571 }571 }
572 }572 }
573
574 MostCalledList {
575 id: mostCalledView
576
577 anchors {
578 left: parent.left
579 right: parent.right
580 margins: units.gu(1)
581 }
582 parentView: view
583 visible: view.favouritesIsSelected
584 height: visible && (count > 0) ? childrenRect.height : 0
585 }
586 }573 }
587 onError: root.error(message)574 onError: root.error(message)
588 onContactClicked: root.contactClicked(contact)575 onContactClicked: root.contactClicked(contact)
589576
=== removed file 'src/imports/Ubuntu/Contacts/MostCalledList.qml'
--- src/imports/Ubuntu/Contacts/MostCalledList.qml 2016-05-05 15:55:23 +0000
+++ src/imports/Ubuntu/Contacts/MostCalledList.qml 1970-01-01 00:00:00 +0000
@@ -1,115 +0,0 @@
1/*
2 * Copyright (C) 2012-2014 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
17import QtQuick 2.4
18
19Column {
20 id: root
21
22 property alias parentView: scrollAnimation.target
23 readonly property alias count: callerRepeat.count
24
25 /* internal */
26 property int _nextCurrentIndex: -1
27
28
29 function makeItemVisible(item)
30 {
31 if (!item) {
32 return
33 }
34
35 var itemY = parent.y + root.y + item.y
36 var areaY = parentView.contentY
37 if (itemY < areaY) {
38 // move foward
39 scrollAnimation.to = itemY
40 } else if ((areaY + parentView.height) < (itemY + item.height)) {
41 // move backward
42 scrollAnimation.to = itemY + item.height
43 } else {
44 return
45 }
46 scrollAnimation.restart()
47 }
48
49 SmoothedAnimation {
50 id: scrollAnimation
51
52 property: "contentY"
53 velocity: parentView.highlightMoveVelocity
54 duration: parentView.highlightMoveDuration
55 }
56
57 SectionDelegate {
58 anchors {
59 left: parent.left
60 right: parent.right
61 margins: units.gu(2)
62 }
63 text: i18n.dtr("address-book-app", "Frequently called")
64 visible: (root.count > 0)
65 }
66
67 Repeater {
68 id: callerRepeat
69
70 model: MostCalledModel {
71 id: calledModel
72
73 onContactClicked: parentView.contactClicked(contact)
74 onAddContactClicked: parentView.addContactClicked(label)
75 onCurrentIndexChanged: {
76 if (currentIndex !== -1) {
77 parentView.currentIndex = -1
78 root._nextCurrentIndex = currentIndex
79 }
80 }
81 }
82 }
83
84 Connections {
85 target: parentView
86 onCurrentIndexChanged: {
87 if (parentView.currentIndex !== -1) {
88 calledModel.currentIndex = -1
89 }
90 }
91 }
92
93 onHeightChanged: {
94 if (root._nextCurrentIndex != -1) {
95 heightChangedTimeout.restart()
96 }
97 }
98
99 Timer {
100 id: heightChangedTimeout
101 interval: 100
102 onTriggered: {
103 makeItemVisible(callerRepeat.itemAt(root._nextCurrentIndex))
104 root._nextCurrentIndex = -1
105 }
106 }
107
108 onVisibleChanged: {
109 // update the model every time that it became visible
110 // in fact calling update only reloads the model data if it has changed
111 if (visible) {
112 calledModel.model.update()
113 }
114 }
115}
1160
=== removed file 'src/imports/Ubuntu/Contacts/MostCalledModel.qml'
--- src/imports/Ubuntu/Contacts/MostCalledModel.qml 2015-10-26 13:18:11 +0000
+++ src/imports/Ubuntu/Contacts/MostCalledModel.qml 1970-01-01 00:00:00 +0000
@@ -1,102 +0,0 @@
1/*
2 * Copyright (C) 2012-2015 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
18import QtQuick 2.4
19import QtContacts 5.0
20
21import Ubuntu.History 0.1
22import Ubuntu.Contacts 0.1 as ContactUI
23
24VisualDataModel {
25 id: root
26
27 property var contactModel: null
28 property int currentIndex: -1
29 property alias callAverage: mostCalledModel.callAverage
30
31 signal contactClicked(int index, QtObject contact)
32 signal addContactClicked(string label)
33 signal loaded()
34
35 property var baseModel: HistoryEventModel {
36 id: historyEventModel
37
38 type: HistoryThreadModel.EventTypeVoice
39 sort: HistorySort {
40 sortField: "timestamp"
41 sortOrder: HistorySort.DescendingOrder
42 }
43 filter: HistoryFilter {
44 filterProperty: "senderId"
45 filterValue: "self"
46 matchFlags: HistoryFilter.MatchCaseSensitive
47 }
48 onCanFetchMoreChanged: {
49 if (count === 0) {
50 mostCalledModel.update()
51 }
52 }
53 }
54
55 model: ContactUI.MostCalledContactsModel {
56 id: mostCalledModel
57
58 startInterval: new Date((new Date().getTime() - 2592000000)) // one month ago
59 maxCount: 5
60 onLoaded: root.loaded()
61 sourceModel: historyEventModel
62 }
63
64 delegate: ContactDelegate {
65 id: contactDelegate
66
67 readonly property alias contact: contactFetch.contact
68 property var contents
69
70 defaultAvatarUrl: "image://theme/contacts"
71 width: parent ? parent.width : 0
72 isCurrentItem: root.currentIndex === index
73 locked: true
74
75 // collapse the item before remove it, to avoid crash
76 ListView.onRemove: SequentialAnimation {
77 ScriptAction {
78 script: {
79 if (contactDelegate.state !== "") {
80 historyModel.currentIndex = -1
81 }
82 }
83 }
84 }
85
86 onClicked: {
87 if (contact) {
88 root.contactClicked(index, contact)
89 } else {
90 root.addContactClicked(name.text)
91 }
92 }
93
94 // delegate does not support more than one child
95 contents: ContactFetch {
96 id: contactFetch
97 model: contactsModel
98 }
99
100 Component.onCompleted: contactFetch.fetchContact(contactId)
101 }
102}
1030
=== removed file 'src/imports/Ubuntu/Contacts/mostcalledproxymodel.cpp'
--- src/imports/Ubuntu/Contacts/mostcalledproxymodel.cpp 2016-05-05 15:56:00 +0000
+++ src/imports/Ubuntu/Contacts/mostcalledproxymodel.cpp 1970-01-01 00:00:00 +0000
@@ -1,374 +0,0 @@
1/*
2 * Copyright (C) 2012-2015 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#include "mostcalledproxymodel.h"
18
19#include <QtContacts/QContactManager>
20#include <QtContacts/QContactFilter>
21#include <QtContacts/QContactPhoneNumber>
22#include <QtContacts/QContactFetchRequest>
23
24#include <QDebug>
25
26using namespace QtContacts;
27
28bool mostCalledContactsModelDataGreaterThan(const MostCalledContactsModelData &d1, const MostCalledContactsModelData &d2)
29{
30 return d1.callCount > d2.callCount;
31}
32
33MostCalledContactsModel::MostCalledContactsModel(QObject *parent)
34 : QAbstractListModel(parent),
35 m_sourceModel(0),
36 m_currentFetch(0),
37 m_manager(new QContactManager("galera")),
38 m_maxCount(20),
39 m_average(0),
40 m_outdated(true),
41 m_reloadingModel(false),
42 m_aboutToQuit(false)
43{
44 connect(this, SIGNAL(sourceModelChanged(QAbstractItemModel*)), SLOT(markAsOutdated()));
45 connect(this, SIGNAL(maxCountChanged(uint)), SLOT(markAsOutdated()));
46 connect(this, SIGNAL(startIntervalChanged(QDateTime)), SLOT(markAsOutdated()));
47}
48
49MostCalledContactsModel::~MostCalledContactsModel()
50{
51 m_aboutToQuit = true;
52 m_phones.clear();
53
54 if (m_currentFetch) {
55 m_currentFetch->cancel();
56 }
57}
58
59QVariant MostCalledContactsModel::data(const QModelIndex &index, int role) const
60{
61 if (!index.isValid()) {
62 return QVariant();
63 }
64
65 int row = index.row();
66 if ((row >= 0) && (row < m_data.size())) {
67 switch (role)
68 {
69 case MostCalledContactsModel::ContactIdRole:
70 return m_data[row].contactId;
71 case MostCalledContactsModel::PhoneNumberRole:
72 return m_data[row].phoneNumber;
73 case MostCalledContactsModel::CallCountRole:
74 return m_data[row].callCount;
75 default:
76 return QVariant();
77 }
78 }
79 return QVariant();
80}
81
82QHash<int, QByteArray> MostCalledContactsModel::roleNames() const
83{
84 static QHash<int, QByteArray> roles;
85 if (roles.isEmpty()) {
86 roles.insert(MostCalledContactsModel::ContactIdRole, "contactId");
87 roles.insert(MostCalledContactsModel::PhoneNumberRole, "phoneNumber");
88 roles.insert(MostCalledContactsModel::CallCountRole, "callCount");
89 }
90 return roles;
91}
92
93int MostCalledContactsModel::rowCount(const QModelIndex &) const
94{
95 return m_data.size();
96}
97
98QAbstractItemModel *MostCalledContactsModel::sourceModel() const
99{
100 return m_sourceModel;
101}
102
103void MostCalledContactsModel::setSourceModel(QAbstractItemModel *model)
104{
105 if (m_sourceModel != model) {
106 if (m_sourceModel) {
107 disconnect(m_sourceModel);
108 }
109
110 m_sourceModel = model;
111 connect(m_sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(markAsOutdated()));
112 connect(m_sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(markAsOutdated()));
113 connect(m_sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(markAsOutdated()));
114 connect(m_sourceModel, SIGNAL(modelReset()), SLOT(markAsOutdated()));
115
116 Q_EMIT sourceModelChanged(m_sourceModel);
117 }
118}
119
120
121uint MostCalledContactsModel::maxCount() const
122{
123 return m_maxCount;
124}
125
126void MostCalledContactsModel::setMaxCount(uint value)
127{
128 if (m_maxCount != value) {
129 m_maxCount = value;
130 Q_EMIT maxCountChanged(m_maxCount);
131 }
132}
133
134int MostCalledContactsModel::callAverage() const
135{
136 return m_average;
137}
138
139QDateTime MostCalledContactsModel::startInterval() const
140{
141 return m_startInterval;
142}
143
144void MostCalledContactsModel::setStartInterval(const QDateTime &value)
145{
146 if (m_startInterval != value) {
147 m_startInterval = value;
148 Q_EMIT startIntervalChanged(m_startInterval);
149 }
150}
151
152QVariant MostCalledContactsModel::getSourceData(int row, int role)
153{
154 QAbstractItemModel *source = sourceModel();
155 if (!source) {
156 return QVariant();
157 }
158
159 while ((source->rowCount() <= row) && (source->canFetchMore(QModelIndex()))) {
160 source->fetchMore(QModelIndex());
161 }
162
163 if (source->rowCount() < row) {
164 return QVariant();
165 }
166
167 QModelIndex sourceIndex = source->index(row, 0);
168 return source->data(sourceIndex, role);
169}
170
171void MostCalledContactsModel::update()
172{
173 // skip update if not necessary
174 if (!m_outdated || m_reloadingModel) {
175 return;
176 }
177
178 if (m_maxCount <= 0) {
179 qWarning() << "update model requested with invalid maxCount";
180 m_outdated = false;
181 return;
182 }
183
184 if (!m_startInterval.isValid()) {
185 qWarning() << "Update model requested with invalid startInterval";
186 m_outdated = false;
187 return;
188 }
189
190 QAbstractItemModel *source = sourceModel();
191 if (!source) {
192 qWarning() << "Update model requested with null source model";
193 m_outdated = false;
194 return;
195 }
196
197 m_totalCalls = 0;
198 m_phones.clear();
199 m_phoneToContactCache.clear();
200 m_contactsData.clear();
201 queryContacts();
202}
203
204void MostCalledContactsModel::queryContacts()
205{
206 // get all phone in the date inteval
207 QHash<int, QByteArray> roles = sourceModel()->roleNames();
208 int participantsRole = roles.key("participants", -1);
209 int timestampRole = roles.key("timestamp", -1);
210 int row = 0;
211
212 Q_ASSERT(participantsRole != -1);
213 Q_ASSERT(timestampRole != -1);
214
215 while(true) {
216 QVariant date = getSourceData(row, timestampRole);
217
218 // end of source model
219 if (date.isNull()) {
220 break;
221 }
222
223 // exit if date is out of interval
224 if (date.toDateTime() < m_startInterval) {
225 break;
226 }
227
228 QVariant data = getSourceData(row, participantsRole);
229 if (data.isValid()) {
230 const QVariantList participants = data.toList();
231 Q_FOREACH(const QVariant &map, participants) {
232 const QString phone = map.toMap().value("identifier").toString();
233 if (!phone.isEmpty())
234 m_phones << phone;
235 }
236 }
237
238 // next row
239 row++;
240 }
241
242 // query for all phones
243 nextContact();
244}
245
246void MostCalledContactsModel::nextContact()
247{
248 if (m_phones.isEmpty()) {
249 parseResult();
250 return;
251 }
252
253 QString nextPhone = m_phones.takeFirst();
254
255 if (m_phoneToContactCache.contains(nextPhone)) {
256 registerCall(nextPhone, m_phoneToContactCache.value(nextPhone));
257 nextContact();
258 return;
259 } else {
260 QContactFilter filter(QContactPhoneNumber::match(nextPhone));
261 QContactFetchHint hint;
262 hint.setDetailTypesHint(QList<QContactDetail::DetailType>() << QContactDetail::TypeGuid);
263
264 m_currentFetch = new QContactFetchRequest;
265 m_currentFetch->setProperty("PHONE", nextPhone);
266 m_currentFetch->setFilter(filter);
267 m_currentFetch->setFetchHint(hint);
268 m_currentFetch->setManager(m_manager.data());
269
270 connect(m_currentFetch,
271 SIGNAL(stateChanged(QContactAbstractRequest::State)),
272 SLOT(fetchContactIdDone()));
273
274 m_currentFetch->start();
275 }
276}
277
278void MostCalledContactsModel::fetchContactIdDone()
279{
280 Q_ASSERT(m_currentFetch);
281
282 if (m_aboutToQuit) {
283 m_currentFetch->deleteLater();
284 m_currentFetch = 0;
285 return;
286 }
287
288 if (m_currentFetch->state() == QContactAbstractRequest::ActiveState) {
289 return;
290 }
291
292 if (!m_currentFetch->contacts().isEmpty()) {
293 QString id = m_currentFetch->contacts().at(0).id().toString();
294 registerCall(m_currentFetch->property("PHONE").toString(), id);
295 }
296 m_currentFetch->deleteLater();
297 m_currentFetch = 0;
298 nextContact();
299}
300
301void MostCalledContactsModel::registerCall(const QString &phone, const QString &contactId)
302{
303 // update cache
304 m_phoneToContactCache.insert(phone, contactId);
305
306 if (m_contactsData.contains(contactId)) {
307 MostCalledContactsModelData &data = m_contactsData[contactId];
308 data.callCount++;
309 } else {
310 MostCalledContactsModelData data;
311 data.contactId = contactId;
312 data.phoneNumber = phone;
313 data.callCount = 1;
314 m_contactsData.insert(contactId, data);
315 }
316 m_totalCalls++;
317}
318
319void MostCalledContactsModel::parseResult()
320{
321 if (m_aboutToQuit) {
322 return;
323 }
324
325 Q_EMIT beginResetModel();
326
327 m_reloadingModel = true;
328 m_outdated = false;
329 m_data.clear();
330 m_average = 0;
331
332 if (!m_contactsData.isEmpty()) {
333 // sort by callCount
334 QList<MostCalledContactsModelData> data = m_contactsData.values();
335 qSort(data.begin(), data.end(), mostCalledContactsModelDataGreaterThan);
336
337 // average
338 m_average = qRound(((qreal) (m_totalCalls)) / m_contactsData.size());
339 Q_FOREACH(const MostCalledContactsModelData &d, data) {
340 if (d.callCount >= m_average) {
341 m_data << d;
342 }
343 if ((uint) m_data.size() >= m_maxCount) {
344 break;
345 }
346 }
347 }
348
349 m_totalCalls = 0;
350 m_phones.clear();
351 m_phoneToContactCache.clear();
352 m_contactsData.clear();
353
354 Q_EMIT endResetModel();
355 m_reloadingModel = false;
356 Q_EMIT callAverageChanged(m_average);
357 Q_EMIT loaded();
358}
359
360
361void MostCalledContactsModel::markAsOutdated()
362{
363 // skip if model is being reloaded
364 if (m_reloadingModel) {
365 return;
366 }
367
368 if (!m_outdated) {
369 m_outdated = true;
370 Q_EMIT outdatedChange(m_outdated);
371 }
372}
373
374
3750
=== removed file 'src/imports/Ubuntu/Contacts/mostcalledproxymodel.h'
--- src/imports/Ubuntu/Contacts/mostcalledproxymodel.h 2015-05-07 17:27:16 +0000
+++ src/imports/Ubuntu/Contacts/mostcalledproxymodel.h 1970-01-01 00:00:00 +0000
@@ -1,112 +0,0 @@
1/*
2 * Copyright (C) 2012-2015 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
21#include <QtCore/QAbstractListModel>
22#include <QtCore/QScopedPointer>
23#include <QtCore/QDateTime>
24#include <QtCore/QMap>
25
26#include <QtContacts/QContactManager>
27#include <QtContacts/QContactFetchRequest>
28
29struct MostCalledContactsModelData
30{
31 QString contactId;
32 QString phoneNumber;
33 int callCount;
34};
35
36class MostCalledContactsModel : public QAbstractListModel
37{
38 Q_OBJECT
39 Q_PROPERTY(QAbstractItemModel* sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
40 Q_PROPERTY(uint maxCount READ maxCount WRITE setMaxCount NOTIFY maxCountChanged)
41 Q_PROPERTY(int callAverage READ callAverage NOTIFY callAverageChanged)
42 Q_PROPERTY(QDateTime startInterval READ startInterval WRITE setStartInterval NOTIFY startIntervalChanged)
43 Q_PROPERTY(bool outdated READ outdated NOTIFY outdatedChange)
44
45public:
46 enum Role {
47 ContactIdRole = 0,
48 PhoneNumberRole,
49 CallCountRole
50 };
51
52 MostCalledContactsModel(QObject *parent=0);
53 ~MostCalledContactsModel();
54
55 QVariant data(const QModelIndex &index, int role) const;
56 QHash<int, QByteArray> roleNames() const;
57 int rowCount(const QModelIndex&) const;
58
59 QAbstractItemModel *sourceModel() const;
60 void setSourceModel(QAbstractItemModel *model);
61
62 uint maxCount() const;
63 void setMaxCount(uint value);
64
65 int callAverage() const;
66 bool outdated() const;
67
68 QDateTime startInterval() const;
69 void setStartInterval(const QDateTime &value);
70
71 Q_INVOKABLE void update();
72
73Q_SIGNALS:
74 void maxCountChanged(uint value);
75 void callAverageChanged(int value);
76 void startIntervalChanged(const QDateTime &value);
77 void sourceModelChanged(QAbstractItemModel *value);
78 void outdatedChange(bool value);
79 void loaded();
80
81private Q_SLOTS:
82 void markAsOutdated();
83 void fetchContactIdDone();
84
85private:
86 QAbstractItemModel *m_sourceModel;
87 QtContacts::QContactFetchRequest *m_currentFetch;
88
89 QScopedPointer<QtContacts::QContactManager> m_manager;
90 QList<MostCalledContactsModelData> m_data;
91 uint m_maxCount;
92 int m_average;
93 QDateTime m_startInterval;
94 bool m_outdated;
95 bool m_reloadingModel;
96 bool m_aboutToQuit;
97
98 QStringList m_phones;
99 QMap<QString, QString> m_phoneToContactCache;
100 QMap<QString, MostCalledContactsModelData > m_contactsData;
101 int m_totalCalls;
102
103 void fetchContactId(const QString &phoneNumber);
104 QVariant getSourceData(int row, int role);
105 void queryContacts();
106 void nextContact();
107 void registerCall(const QString &phone, const QString &contactId);
108 void parseResult();
109};
110
111
112#endif
1130
=== modified file 'src/imports/Ubuntu/Contacts/plugin.cpp'
--- src/imports/Ubuntu/Contacts/plugin.cpp 2015-05-07 17:27:16 +0000
+++ src/imports/Ubuntu/Contacts/plugin.cpp 2016-12-14 13:04:55 +0000
@@ -15,7 +15,6 @@
15 */15 */
1616
17#include "plugin.h"17#include "plugin.h"
18#include "mostcalledproxymodel.h"
19#include "contacts.h"18#include "contacts.h"
20#include "simcardcontacts.h"19#include "simcardcontacts.h"
2120
@@ -39,6 +38,5 @@
39{38{
40 // @uri Ubuntu.Contacts39 // @uri Ubuntu.Contacts
41 qmlRegisterSingletonType<UbuntuContacts>(uri, 0, 1, "Contacts", contactsProvider);40 qmlRegisterSingletonType<UbuntuContacts>(uri, 0, 1, "Contacts", contactsProvider);
42 qmlRegisterType<MostCalledContactsModel>(uri, 0, 1, "MostCalledContactsModel");
43 qmlRegisterType<SimCardContacts>(uri, 0, 1, "SimCardContacts");41 qmlRegisterType<SimCardContacts>(uri, 0, 1, "SimCardContacts");
44}42}
4543
=== modified file 'src/imports/Ubuntu/Contacts/qmldir'
--- src/imports/Ubuntu/Contacts/qmldir 2015-10-23 11:03:31 +0000
+++ src/imports/Ubuntu/Contacts/qmldir 2016-12-14 13:04:55 +0000
@@ -28,8 +28,6 @@
28internal FastScrollJs FastScroll.js28internal FastScrollJs FastScroll.js
29internal FastScroll FastScroll.qml29internal FastScroll FastScroll.qml
30internal ListItemWithActionsCheckBox ListItemWithActionsCheckBox.qml30internal ListItemWithActionsCheckBox ListItemWithActionsCheckBox.qml
31internal MostCalledList MostCalledList.qml
32internal MostCalledModel MostCalledModel.qml
33internal Ofono Ofono.qml31internal Ofono Ofono.qml
34internal SectionDelegate SectionDelegate.qml32internal SectionDelegate SectionDelegate.qml
35internal SubtitledWithColors SubtitledWithColors.qml33internal SubtitledWithColors SubtitledWithColors.qml

Subscribers

People subscribed via source and target branches