|
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 Qt Mobility Components. |
|
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 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 |
|
43 #include <QtTracker/ontologies/nco.h> |
|
44 |
|
45 #include "trackerchangelistener.h" |
|
46 #include "qcontact.h" |
|
47 |
|
48 using namespace SopranoLive; |
|
49 |
|
50 TrackerChangeListener::TrackerChangeListener(QObject* parent) |
|
51 :QObject(parent) |
|
52 { |
|
53 signaler_contact = SopranoLive::BackEnds::Tracker::ClassUpdateSignaler::get( |
|
54 nco::Contact::iri()); |
|
55 connectSignals(signaler_contact); |
|
56 |
|
57 signaler_imaccount = SopranoLive::BackEnds::Tracker::ClassUpdateSignaler::get( |
|
58 nco::IMAccount::iri()); |
|
59 connectSignals(signaler_imaccount); |
|
60 } |
|
61 |
|
62 TrackerChangeListener::~TrackerChangeListener() |
|
63 { |
|
64 } |
|
65 // TEMPORARY here we'll for now extract ids from tracker contact URI. |
|
66 // In future need nonblocking async way to get contact ids from tracker contact urls |
|
67 // let's see which signals will be used from libqttracker |
|
68 QContactLocalId url2UniqueId(const QString &contactUrl) |
|
69 { |
|
70 |
|
71 /* Telepathy URI would look like telepathy:///org/freedesktop... |
|
72 convert the URI component which contains the |
|
73 account + contat id to uint32 expected by |
|
74 qcontactlocalid |
|
75 */ |
|
76 if (contactUrl.contains("telepathy")) { |
|
77 QContactLocalId id = 0; |
|
78 QStringList decoded = contactUrl.split(":"); |
|
79 id = qHash(decoded.value(1).remove(0,1)); |
|
80 return id; |
|
81 } |
|
82 |
|
83 /* handle conatact:interger URL types comming from |
|
84 which are non telepathy url's |
|
85 */ |
|
86 QRegExp rx("(\\d+)"); |
|
87 bool conversion = false; |
|
88 QContactLocalId id = 0; |
|
89 if( rx.indexIn(contactUrl) != -1 ) |
|
90 { |
|
91 id = rx.cap(1).toUInt(&conversion, 10); |
|
92 } |
|
93 if( !conversion ) |
|
94 qWarning() << Q_FUNC_INFO << "unparsed uri to uniqueI:" << contactUrl; |
|
95 return id; |
|
96 |
|
97 } |
|
98 |
|
99 void TrackerChangeListener::subjectsAdded(const QStringList &subjects) |
|
100 { |
|
101 QList<QContactLocalId> added; |
|
102 foreach(const QString &uri, subjects) |
|
103 { |
|
104 added << url2UniqueId(uri); |
|
105 } |
|
106 emit contactsAdded(added); |
|
107 } |
|
108 |
|
109 void TrackerChangeListener::subjectsRemoved(const QStringList &subjects) |
|
110 { |
|
111 QList<QContactLocalId> added; |
|
112 foreach(const QString &uri, subjects) |
|
113 { |
|
114 added << url2UniqueId(uri); |
|
115 } |
|
116 emit contactsRemoved(added); |
|
117 } |
|
118 |
|
119 // TODO data changed for full query |
|
120 void TrackerChangeListener::subjectsChanged(const QStringList &subjects) |
|
121 { |
|
122 QList<QContactLocalId> changed; |
|
123 foreach(const QString &uri, subjects) { |
|
124 QContactLocalId id = url2UniqueId(uri); |
|
125 if (changed.contains(id) == false) { |
|
126 changed << id; |
|
127 } |
|
128 } |
|
129 emit contactsChanged(changed); |
|
130 } |
|
131 |
|
132 |
|
133 AsyncQuery::AsyncQuery(RDFSelect selectQuery) |
|
134 { |
|
135 nodes = ::tracker()->modelQuery(selectQuery); |
|
136 QObject::connect(nodes.model(), SIGNAL(modelUpdated()), this, |
|
137 SLOT(queryReady())); |
|
138 } |
|
139 |
|
140 void AsyncQuery::queryReady() |
|
141 { |
|
142 emit queryReady(this); |
|
143 } |
|
144 |
|
145 void TrackerChangeListener::connectSignals(SopranoLive::BackEnds::Tracker::ClassUpdateSignaler *signaler) { |
|
146 // Note here that we are not using |
|
147 // QAbstractItemModel signals from LiveNodes::model() because |
|
148 // node list for which notification comes is fixed. Those are used for |
|
149 // async implementation |
|
150 if (signaler) |
|
151 { |
|
152 connect(signaler, SIGNAL(subjectsAdded(const QStringList &)), |
|
153 SLOT(subjectsAdded(const QStringList &))); |
|
154 connect(signaler, |
|
155 SIGNAL(baseRemoveSubjectsd(const QStringList &)), |
|
156 SLOT(subjectsRemoved(const QStringList &))); |
|
157 connect(signaler, |
|
158 SIGNAL(subjectsChanged(const QStringList &)), |
|
159 SLOT(subjectsChanged(const QStringList &))); |
|
160 } |
|
161 } |