Merge lp:~renatofilho/qtorganizer5-eds/fix-1373945 into lp:qtorganizer5-eds
- fix-1373945
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Arthur Mello |
Approved revision: | 91 |
Merged at revision: | 97 |
Proposed branch: | lp:~renatofilho/qtorganizer5-eds/fix-1373945 |
Merge into: | lp:qtorganizer5-eds |
Diff against target: |
330 lines (+152/-11) 4 files modified
organizer/qorganizer-eds-savecollectionrequestdata.cpp (+20/-2) organizer/qorganizer-eds-source-registry.cpp (+68/-8) organizer/qorganizer-eds-source-registry.h (+10/-1) tests/unittest/collections-test.cpp (+54/-0) |
To merge this branch: | bzr merge lp:~renatofilho/qtorganizer5-eds/fix-1373945 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Arthur Mello (community) | Approve | ||
PS Jenkins bot | continuous-integration | Approve | |
Review via email: mp+288968@code.launchpad.net |
Commit message
Implemented support to change the default collection using 'collection-
Description of the change
PS Jenkins bot (ps-jenkins) wrote : | # |
- 90. By Renato Araujo Oliveira Filho
-
Trunk merged.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:90
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Arthur Mello (artmello) wrote : | # |
lgtm, just added a single diff inline comment.
- 91. By Renato Araujo Oliveira Filho
-
Re-use 'registry' variable instead of declare a new one.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:91
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'organizer/qorganizer-eds-savecollectionrequestdata.cpp' |
2 | --- organizer/qorganizer-eds-savecollectionrequestdata.cpp 2014-10-06 14:07:54 +0000 |
3 | +++ organizer/qorganizer-eds-savecollectionrequestdata.cpp 2016-03-15 13:05:25 +0000 |
4 | @@ -72,7 +72,13 @@ |
5 | |
6 | for(; i != 0; i = i->next) { |
7 | ESource *source = E_SOURCE(i->data); |
8 | - QOrganizerCollection collection = parent()->d->m_sourceRegistry->insert(source); |
9 | + SourceRegistry *registry = parent()->d->m_sourceRegistry; |
10 | + Q_ASSERT(registry); |
11 | + QOrganizerCollection collection = registry->insert(source); |
12 | + bool isDefault = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(source), "is-default")); |
13 | + if (isDefault) { |
14 | + registry->setDefaultCollection(collection); |
15 | + } |
16 | m_results.insert(m_sources.key(source), collection); |
17 | m_changeSet.insertAddedCollection(collection.id()); |
18 | } |
19 | @@ -86,8 +92,16 @@ |
20 | |
21 | if (error == QOrganizerManager::NoError) { |
22 | QOrganizerEDSCollectionEngineId *id; |
23 | - QOrganizerCollection collection = SourceRegistry::parseSource(source, &id); |
24 | + bool isDefault = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(source), "is-default")); |
25 | + QOrganizerCollection collection = SourceRegistry::parseSource(source, isDefault, &id); |
26 | m_results.insert(index, collection); |
27 | + |
28 | + if (isDefault) { |
29 | + SourceRegistry *registry = parent()->d->m_sourceRegistry; |
30 | + Q_ASSERT(registry); |
31 | + registry->setDefaultCollection(collection); |
32 | + } |
33 | + |
34 | m_changeSet.insertChangedCollection(collection.id()); |
35 | } else { |
36 | m_errorMap.insert(index, error); |
37 | @@ -195,6 +209,10 @@ |
38 | bool selected = collection.extendedMetaData(COLLECTION_SELECTED_METADATA).toBool(); |
39 | e_source_selectable_set_selected(E_SOURCE_SELECTABLE(extCalendar), selected); |
40 | |
41 | + // default collection |
42 | + bool isDefault = collection.extendedMetaData(COLLECTION_DEFAULT_METADATA).toBool(); |
43 | + g_object_set_data(G_OBJECT(source), "is-default", GINT_TO_POINTER(isDefault)); |
44 | + |
45 | m_sources.insert(index, source); |
46 | if (isNew) { |
47 | m_sourcesToCreate.insert(index, source); |
48 | |
49 | === modified file 'organizer/qorganizer-eds-source-registry.cpp' |
50 | --- organizer/qorganizer-eds-source-registry.cpp 2016-01-11 21:15:32 +0000 |
51 | +++ organizer/qorganizer-eds-source-registry.cpp 2016-03-15 13:05:25 +0000 |
52 | @@ -12,7 +12,8 @@ |
53 | m_sourceRemovedId(0), |
54 | m_sourceChangedId(0), |
55 | m_sourceEnabledId(0), |
56 | - m_sourceDisabledId(0) |
57 | + m_sourceDisabledId(0), |
58 | + m_defaultSourceChangedId(0) |
59 | { |
60 | } |
61 | |
62 | @@ -26,6 +27,7 @@ |
63 | g_signal_handler_disconnect(m_sourceRegistry, m_sourceChangedId); |
64 | g_signal_handler_disconnect(m_sourceRegistry, m_sourceEnabledId); |
65 | g_signal_handler_disconnect(m_sourceRegistry, m_sourceDisabledId); |
66 | + g_signal_handler_disconnect(m_sourceRegistry, m_defaultSourceChangedId); |
67 | |
68 | g_clear_object(&m_sourceRegistry); |
69 | |
70 | @@ -73,7 +75,10 @@ |
71 | "source-removed", |
72 | (GCallback) SourceRegistry::onSourceRemoved, |
73 | this); |
74 | - |
75 | + m_defaultSourceChangedId = g_signal_connect(m_sourceRegistry, |
76 | + "notify::default-calendar", |
77 | + G_CALLBACK(SourceRegistry::onDefaultCalendarChanged), |
78 | + this); |
79 | |
80 | // We use calendar as default source, if you are trying to use other source type |
81 | // you need to set the item source id manually |
82 | @@ -82,9 +87,10 @@ |
83 | GList *sources = e_source_registry_list_sources(m_sourceRegistry, 0); |
84 | for(int i = 0, iMax = g_list_length(sources); i < iMax; i++) { |
85 | ESource *source = E_SOURCE(g_list_nth_data(sources, i)); |
86 | + bool isDefault = e_source_equal(defaultCalendarSource, source); |
87 | |
88 | - QOrganizerCollection collection = registerSource(source); |
89 | - if (e_source_equal(defaultCalendarSource, source)) { |
90 | + QOrganizerCollection collection = registerSource(source, isDefault); |
91 | + if (isDefault) { |
92 | m_defaultCollection = collection; |
93 | } |
94 | } |
95 | @@ -102,6 +108,19 @@ |
96 | return m_defaultCollection; |
97 | } |
98 | |
99 | +void SourceRegistry::setDefaultCollection(QtOrganizer::QOrganizerCollection &collection) |
100 | +{ |
101 | + if (m_defaultCollection.id() == collection.id()) |
102 | + return; |
103 | + |
104 | + QOrganizerEDSCollectionEngineId *eid = m_collectionsMap.value(collection.id().toString(), 0); |
105 | + if (eid && eid->m_esource) { |
106 | + e_source_registry_set_default_calendar(m_sourceRegistry, eid->m_esource); |
107 | + } else { |
108 | + qWarning() << "Fail to set default collection" << collection.id(); |
109 | + } |
110 | +} |
111 | + |
112 | QOrganizerCollection SourceRegistry::collection(const QString &collectionId) const |
113 | { |
114 | return m_collections.value(collectionId); |
115 | @@ -228,7 +247,7 @@ |
116 | return QString(); |
117 | } |
118 | |
119 | -QOrganizerCollection SourceRegistry::registerSource(ESource *source) |
120 | +QOrganizerCollection SourceRegistry::registerSource(ESource *source, bool isDefault) |
121 | { |
122 | QString collectionId = findCollection(source); |
123 | if (collectionId.isEmpty()) { |
124 | @@ -240,7 +259,7 @@ |
125 | |
126 | if ( isEnabled && (isCalendar || isTaskList || isMemoList || isAlarms)) { |
127 | QOrganizerEDSCollectionEngineId *edsId = 0; |
128 | - QOrganizerCollection collection = parseSource(source, &edsId); |
129 | + QOrganizerCollection collection = parseSource(source, isDefault, &edsId); |
130 | QString collectionId = collection.id().toString(); |
131 | |
132 | if (!m_collectionsMap.contains(collectionId)) { |
133 | @@ -262,7 +281,23 @@ |
134 | |
135 | } |
136 | |
137 | +void SourceRegistry::updateDefaultCollection(QOrganizerCollection *collection) |
138 | +{ |
139 | + if (m_defaultCollection.id() != collection->id()) { |
140 | + QString oldDefaultCollectionId = m_defaultCollection.id().toString(); |
141 | + |
142 | + collection->setExtendedMetaData(COLLECTION_DEFAULT_METADATA, true); |
143 | + m_defaultCollection = *collection; |
144 | + Q_EMIT sourceUpdated(m_defaultCollection.id().toString()); |
145 | + |
146 | + QOrganizerCollection &old = m_collections[oldDefaultCollectionId]; |
147 | + old.setExtendedMetaData(COLLECTION_DEFAULT_METADATA, false); |
148 | + Q_EMIT sourceUpdated(oldDefaultCollectionId); |
149 | + } |
150 | +} |
151 | + |
152 | QOrganizerCollection SourceRegistry::parseSource(ESource *source, |
153 | + bool isDefault, |
154 | QOrganizerEDSCollectionEngineId **edsId) |
155 | { |
156 | *edsId = new QOrganizerEDSCollectionEngineId(source); |
157 | @@ -270,7 +305,7 @@ |
158 | QOrganizerCollection collection; |
159 | |
160 | collection.setId(id); |
161 | - updateCollection(&collection, source); |
162 | + updateCollection(&collection, isDefault, source); |
163 | return collection; |
164 | } |
165 | |
166 | @@ -290,7 +325,9 @@ |
167 | QString collectionId = self->findCollection(source); |
168 | if (!collectionId.isEmpty() && self->m_collections.contains(collectionId)) { |
169 | QOrganizerCollection &collection = self->m_collections[collectionId]; |
170 | - self->updateCollection(&collection, source, self->m_clients.value(collectionId)); |
171 | + self->updateCollection(&collection, |
172 | + self->m_defaultCollection.id() == collection.id(), |
173 | + source, self->m_clients.value(collectionId)); |
174 | Q_EMIT self->sourceUpdated(collectionId); |
175 | } else { |
176 | qWarning() << "Source changed not found"; |
177 | @@ -305,7 +342,27 @@ |
178 | self->remove(source); |
179 | } |
180 | |
181 | +void SourceRegistry::onDefaultCalendarChanged(ESourceRegistry *registry, |
182 | + GParamSpec *pspec, |
183 | + SourceRegistry *self) |
184 | +{ |
185 | + Q_UNUSED(registry); |
186 | + Q_UNUSED(pspec); |
187 | + |
188 | + ESource *defaultCalendar = e_source_registry_ref_default_calendar(self->m_sourceRegistry); |
189 | + if (!defaultCalendar) |
190 | + return; |
191 | + |
192 | + QString collectionId = self->findCollection(defaultCalendar); |
193 | + if (!collectionId.isEmpty()) { |
194 | + QOrganizerCollection &collection = self->m_collections[collectionId]; |
195 | + self->updateDefaultCollection(&collection); |
196 | + } |
197 | + g_object_unref(defaultCalendar); |
198 | +} |
199 | + |
200 | void SourceRegistry::updateCollection(QOrganizerCollection *collection, |
201 | + bool isDefault, |
202 | ESource *source, |
203 | EClient *client) |
204 | { |
205 | @@ -341,4 +398,7 @@ |
206 | writable = writable && !e_client_is_readonly(client); |
207 | } |
208 | collection->setExtendedMetaData(COLLECTION_READONLY_METADATA, !writable); |
209 | + |
210 | + // default |
211 | + collection->setExtendedMetaData(COLLECTION_DEFAULT_METADATA, isDefault); |
212 | } |
213 | |
214 | === modified file 'organizer/qorganizer-eds-source-registry.h' |
215 | --- organizer/qorganizer-eds-source-registry.h 2016-01-11 21:15:32 +0000 |
216 | +++ organizer/qorganizer-eds-source-registry.h 2016-03-15 13:05:25 +0000 |
217 | @@ -31,6 +31,7 @@ |
218 | #define COLLECTION_CALLENDAR_TYPE_METADATA "collection-type" |
219 | #define COLLECTION_SELECTED_METADATA "collection-selected" |
220 | #define COLLECTION_READONLY_METADATA "collection-readonly" |
221 | +#define COLLECTION_DEFAULT_METADATA "collection-default" |
222 | |
223 | class SourceRegistry : public QObject |
224 | { |
225 | @@ -42,6 +43,7 @@ |
226 | ESourceRegistry *object() const; |
227 | void load(); |
228 | QtOrganizer::QOrganizerCollection defaultCollection() const; |
229 | + void setDefaultCollection(QtOrganizer::QOrganizerCollection &collection); |
230 | QtOrganizer::QOrganizerCollection collection(const QString &collectionId) const; |
231 | QList<QtOrganizer::QOrganizerCollection> collections() const; |
232 | QStringList collectionsIds() const; |
233 | @@ -56,6 +58,7 @@ |
234 | void clear(); |
235 | |
236 | static QtOrganizer::QOrganizerCollection parseSource(ESource *source, |
237 | + bool isDefault, |
238 | QOrganizerEDSCollectionEngineId **edsId); |
239 | |
240 | Q_SIGNALS: |
241 | @@ -77,10 +80,13 @@ |
242 | int m_sourceChangedId; |
243 | int m_sourceEnabledId; |
244 | int m_sourceDisabledId; |
245 | + int m_defaultSourceChangedId; |
246 | |
247 | QString findCollection(ESource *source) const; |
248 | - QtOrganizer::QOrganizerCollection registerSource(ESource *source); |
249 | + QtOrganizer::QOrganizerCollection registerSource(ESource *source, bool isDefault = false); |
250 | + void updateDefaultCollection(QtOrganizer::QOrganizerCollection *collection); |
251 | static void updateCollection(QtOrganizer::QOrganizerCollection *collection, |
252 | + bool isDefault, |
253 | ESource *source, |
254 | EClient *client = 0); |
255 | |
256 | @@ -95,6 +101,9 @@ |
257 | static void onSourceRemoved(ESourceRegistry *registry, |
258 | ESource *source, |
259 | SourceRegistry *self); |
260 | + static void onDefaultCalendarChanged(ESourceRegistry *registry, |
261 | + GParamSpec *pspec, |
262 | + SourceRegistry *self); |
263 | }; |
264 | |
265 | #endif |
266 | |
267 | === modified file 'tests/unittest/collections-test.cpp' |
268 | --- tests/unittest/collections-test.cpp 2016-01-11 21:15:32 +0000 |
269 | +++ tests/unittest/collections-test.cpp 2016-03-15 13:05:25 +0000 |
270 | @@ -297,6 +297,60 @@ |
271 | } |
272 | } |
273 | } |
274 | + |
275 | + void testCreateNewDefaultCollection() |
276 | + { |
277 | + static QString newCollection = uniqueCollectionName(); |
278 | + |
279 | + // Create a new default collection |
280 | + QOrganizerCollection collection; |
281 | + QtOrganizer::QOrganizerManager::Error error; |
282 | + collection.setMetaData(QOrganizerCollection::KeyName, newCollection); |
283 | + collection.setMetaData(QOrganizerCollection::KeyColor, QStringLiteral("red")); |
284 | + collection.setExtendedMetaData(QStringLiteral("collection-selected"), true); |
285 | + collection.setExtendedMetaData(QStringLiteral("collection-default"), true); |
286 | + |
287 | + QSignalSpy createdCollection(m_engineRead, SIGNAL(collectionsAdded(QList<QOrganizerCollectionId>))); |
288 | + QVERIFY(m_engineWrite->saveCollection(&collection, &error)); |
289 | + // create collection |
290 | + QTRY_COMPARE(createdCollection.count(), 1); |
291 | + |
292 | + // wait collection to became the default one |
293 | + QTRY_COMPARE_WITH_TIMEOUT(m_engineRead->defaultCollection(0).id(), collection.id(), 5000); |
294 | + } |
295 | + |
296 | + void testUpdateDefaultCollection() |
297 | + { |
298 | + static QString newCollectionId = uniqueCollectionName(); |
299 | + |
300 | + // store current default collection |
301 | + QOrganizerCollection defaultCollection = m_engineRead->defaultCollection(0); |
302 | + |
303 | + // Create a collection |
304 | + QOrganizerCollection collection; |
305 | + QtOrganizer::QOrganizerManager::Error error; |
306 | + collection.setMetaData(QOrganizerCollection::KeyName, newCollectionId); |
307 | + QSignalSpy createCollection(m_engineRead, SIGNAL(collectionsAdded(QList<QOrganizerCollectionId>))); |
308 | + QVERIFY(m_engineWrite->saveCollection(&collection, &error)); |
309 | + QTRY_COMPARE(createCollection.count(), 1); |
310 | + // wait collection to became writable |
311 | + QTRY_VERIFY_WITH_TIMEOUT(!m_engineRead->collection(collection.id(), 0).extendedMetaData("collection-readonly").toBool(), 5000); |
312 | + |
313 | + // make sure that the new collection is not default |
314 | + QOrganizerCollection newCollection = m_engineRead->collection(collection.id(), 0); |
315 | + QCOMPARE(newCollection.extendedMetaData(QStringLiteral("collection-default")).toBool(), false); |
316 | + QVERIFY(newCollection.id() != defaultCollection.id()); |
317 | + |
318 | + // mark new collection as default |
319 | + QSignalSpy changedCollection(m_engineRead, SIGNAL(collectionsChanged(QList<QOrganizerCollectionId>))); |
320 | + newCollection.setExtendedMetaData(QStringLiteral("collection-default"), true); |
321 | + QVERIFY(m_engineWrite->saveCollection(&newCollection, &error)); |
322 | + // old default collection will change, and the new one |
323 | + QTRY_COMPARE(changedCollection.count() , 3); |
324 | + |
325 | + // wait collection to became the default one |
326 | + QTRY_COMPARE_WITH_TIMEOUT(m_engineRead->defaultCollection(0).id(), newCollection.id(), 5000); |
327 | + } |
328 | }; |
329 | |
330 | const QString CollectionTest::collectionTypePropertyName = QStringLiteral("collection-type"); |
PASSED: Continuous integration, rev:89 jenkins. qa.ubuntu. com/job/ qtorganizer5- eds-ci/ 248/ jenkins. qa.ubuntu. com/job/ qtorganizer5- eds-vivid- amd64-ci/ 55 jenkins. qa.ubuntu. com/job/ qtorganizer5- eds-vivid- armhf-ci/ 55 jenkins. qa.ubuntu. com/job/ qtorganizer5- eds-vivid- armhf-ci/ 55/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ qtorganizer5- eds-vivid- i386-ci/ 55
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/qtorganizer 5-eds-ci/ 248/rebuild
http://