|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the examples of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 |
|
37 [sbox-maemo6-i486: ~/w/QMLContacts] > xeyes |
|
38 ** |
|
39 ** |
|
40 ** $QT_END_LICENSE$ |
|
41 ** |
|
42 ****************************************************************************/ |
|
43 #include "qmlcontactsa.h" |
|
44 |
|
45 #include <QtDebug> |
|
46 #include <qcontactfetchrequest.h> |
|
47 #include <qcontactlocalidfilter.h> |
|
48 #include <qcontactdetails.h> |
|
49 |
|
50 QTM_USE_NAMESPACE |
|
51 |
|
52 QTM_BEGIN_NAMESPACE |
|
53 |
|
54 // ![0] |
|
55 QMLContactManagerAsync::QMLContactManagerAsync(QObject *parent) |
|
56 : QObject(parent) |
|
57 { |
|
58 qc = new QContactManager(); |
|
59 |
|
60 } |
|
61 |
|
62 QMLContactManagerAsync::~QMLContactManagerAsync() |
|
63 { |
|
64 delete qc; |
|
65 } |
|
66 |
|
67 QString QMLContactManagerAsync::availableManagers() const |
|
68 { |
|
69 return QContactManager::availableManagers().join(" "); |
|
70 } |
|
71 |
|
72 QString QMLContactManagerAsync::manager() |
|
73 { |
|
74 return qc->managerName(); |
|
75 } |
|
76 |
|
77 void QMLContactManagerAsync::setManager(QString manager) |
|
78 { |
|
79 delete qc; |
|
80 qc = new QContactManager(manager); |
|
81 if(!qc) |
|
82 qc = new QContactManager(); |
|
83 connect(qc, SIGNAL(contactsAdded(QList<QContactLocalId>)), this, SIGNAL(contactsAdded(QList<QContactLocalId>))); |
|
84 connect(qc, SIGNAL(contactsChanged(QList<QContactLocalId>)), this, SIGNAL(contactsChanged(QList<QContactLocalId>))); |
|
85 connect(qc, SIGNAL(contactsRemoved(QList<QContactLocalId>)), this, SIGNAL(contactsRemoved(QList<QContactLocalId>))); |
|
86 connect(qc, SIGNAL(relationshipsAdded(QList<QContactLocalId>)), this, SIGNAL(relationshipsAdded(QList<QContactLocalId>))); |
|
87 connect(qc, SIGNAL(relationshipsRemoved(QList<QContactLocalId>)), this, SIGNAL(relationshipsRemoved(QList<QContactLocalId>))); |
|
88 |
|
89 qWarning() << "Changed backend to: " << manager; |
|
90 } |
|
91 |
|
92 |
|
93 QString QMLContactManagerAsync::contactListToQString(const QList<QContactLocalId>& contactIds) const |
|
94 { |
|
95 QString list; |
|
96 int i; |
|
97 |
|
98 for (i = 0; i < contactIds.count(); i++) { |
|
99 list += QString::number(contactIds.at(i)) + " "; |
|
100 } |
|
101 |
|
102 return list; |
|
103 } |
|
104 |
|
105 QStringList QMLContactManagerAsync::contactListToQString(const QList<QContact>& contact) const |
|
106 { |
|
107 QStringList list; |
|
108 int i; |
|
109 |
|
110 for (i = 0; i < contact.count(); i++) { |
|
111 list += qc->synthesizeDisplayLabel(contact.at(i)); |
|
112 } |
|
113 |
|
114 return list; |
|
115 } |
|
116 |
|
117 int QMLContactManagerAsync::numContacts() |
|
118 { |
|
119 QList<QContactLocalId> qlid; |
|
120 |
|
121 qlid = qc->contacts(); |
|
122 |
|
123 return qlid.count(); |
|
124 } |
|
125 |
|
126 void QMLContactManagerAsync::contacts() |
|
127 { |
|
128 m_contactIds.clear(); |
|
129 QContactFetchRequest* req = new QContactFetchRequest; |
|
130 QContactLocalIdFilter idFil; |
|
131 idFil.setIds(qc->contacts()); |
|
132 req->setFilter(idFil); |
|
133 req->setManager(qc); |
|
134 connect(req, SIGNAL(progress(QContactFetchRequest*, bool)), this, SLOT(contactProgress(QContactFetchRequest*,bool))); |
|
135 req->start(); |
|
136 } |
|
137 |
|
138 void QMLContactManagerAsync::contactProgress(QContactFetchRequest *request, bool appendOnly) |
|
139 { |
|
140 Q_UNUSED(appendOnly); |
|
141 |
|
142 // first, check to make sure that the request is still valid. |
|
143 if (qc != request->manager() || |
|
144 request->status() == QContactAbstractRequest::Cancelled) { |
|
145 delete request; |
|
146 return; // ignore these results. |
|
147 } |
|
148 |
|
149 if(request->contacts().count() > 0) { |
|
150 QContact c; |
|
151 foreach(c, request->contacts()) { |
|
152 //qWarning() << "Local Id: " << c.localId() << " count: " << m_contactIds.count(); |
|
153 QmlContact qmlc(c); |
|
154 emit contactsLoaded(&qmlc); |
|
155 } |
|
156 } |
|
157 |
|
158 // check to see if the request status is "finished" - clean up. |
|
159 if (request->status() == QContactAbstractRequest::Finished) { |
|
160 delete request; |
|
161 emit contactsLoadedDone(); |
|
162 } |
|
163 |
|
164 } |
|
165 |
|
166 QString QMLContactManagerAsync::idToName(QString name) |
|
167 { |
|
168 QContact c = qc->contact(name.toInt()); |
|
169 return qc->synthesizeDisplayLabel(c); |
|
170 } |
|
171 |
|
172 // ![0] |
|
173 |
|
174 #include "moc_qmlcontactsa.cpp" |
|
175 |
|
176 QTM_END_NAMESPACE |
|
177 QML_DEFINE_TYPE(QMLContactManagerAsync, 1, 0, QMLContactManagerAsync, QMLContactManagerAsync); |