Merge lp:~mzanetti/reminders-app/create-edit-delete-notes into lp:reminders-app
- create-edit-delete-notes
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | David Planella |
Approved revision: | 12 |
Merged at revision: | 10 |
Proposed branch: | lp:~mzanetti/reminders-app/create-edit-delete-notes |
Merge into: | lp:reminders-app |
Prerequisite: | lp:~mzanetti/reminders-app/notes-refactor |
Diff against target: |
967 lines (+466/-90) 24 files modified
src/app/qml/ui/NotePage.qml (+23/-4) src/app/qml/ui/NotesPage.qml (+25/-0) src/plugin/Evernote/Evernote.pro (+14/-6) src/plugin/Evernote/jobs/createnotejob.cpp (+37/-0) src/plugin/Evernote/jobs/createnotejob.h (+22/-0) src/plugin/Evernote/jobs/deletenotejob.cpp (+18/-0) src/plugin/Evernote/jobs/deletenotejob.h (+21/-0) src/plugin/Evernote/jobs/evernotejob.cpp (+49/-0) src/plugin/Evernote/jobs/evernotejob.h (+30/-0) src/plugin/Evernote/jobs/fetchnotebooksjob.cpp (+3/-5) src/plugin/Evernote/jobs/fetchnotebooksjob.h (+4/-15) src/plugin/Evernote/jobs/fetchnotejob.cpp (+9/-8) src/plugin/Evernote/jobs/fetchnotejob.h (+4/-11) src/plugin/Evernote/jobs/fetchnotesjob.cpp (+3/-7) src/plugin/Evernote/jobs/fetchnotesjob.h (+4/-13) src/plugin/Evernote/jobs/savenotejob.cpp (+40/-0) src/plugin/Evernote/jobs/savenotejob.h (+20/-0) src/plugin/Evernote/note.cpp (+20/-0) src/plugin/Evernote/note.h (+8/-2) src/plugin/Evernote/notebooks.cpp (+0/-1) src/plugin/Evernote/notes.cpp (+13/-1) src/plugin/Evernote/notes.h (+1/-0) src/plugin/Evernote/notesstore.cpp (+82/-15) src/plugin/Evernote/notesstore.h (+16/-2) |
To merge this branch: | bzr merge lp:~mzanetti/reminders-app/create-edit-delete-notes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
David Planella | Approve | ||
Review via email: mp+196500@code.launchpad.net |
This proposal supersedes a proposal from 2013-11-25.
Commit message
Adds support creating, editing and deleting notes.
Description of the change
Adds support creating, editing and deleting notes. Still a bit experimental. Need to figure a way to deal with the doctype.
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Continuous integration, rev:12
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
http://
Executed test runs:
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:12
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) : | # |
Preview Diff
1 | === modified file 'src/app/qml/ui/NotePage.qml' |
2 | --- src/app/qml/ui/NotePage.qml 2013-11-25 09:14:33 +0000 |
3 | +++ src/app/qml/ui/NotePage.qml 2013-11-25 09:14:33 +0000 |
4 | @@ -6,11 +6,30 @@ |
5 | title: note.title |
6 | property var note |
7 | |
8 | - TextArea { |
9 | - id: noteTextArea |
10 | + Column { |
11 | anchors.fill: parent |
12 | - textFormat: TextEdit.RichText |
13 | - text: note.content |
14 | + spacing: units.gu(1) |
15 | + Button { |
16 | + width: parent.width |
17 | + text: "save" |
18 | + onClicked: { |
19 | + print("timer triggered") |
20 | + var content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\"><en-note><div><br clear=\"none\"/>" |
21 | + content = content + noteTextArea.getText(0, noteTextArea.length) |
22 | + content = content + "<br clear=\"none\"/></div><div><br clear=\"none\"/></div></en-note>" |
23 | + note.content = content |
24 | + note.save(); |
25 | + } |
26 | + } |
27 | + |
28 | + TextArea { |
29 | + id: noteTextArea |
30 | + anchors { left: parent.left; right: parent.right } |
31 | + height: parent.height - y |
32 | + |
33 | + textFormat: TextEdit.RichText |
34 | + text: note.content |
35 | + } |
36 | } |
37 | } |
38 | |
39 | |
40 | === modified file 'src/app/qml/ui/NotesPage.qml' |
41 | --- src/app/qml/ui/NotesPage.qml 2013-11-25 09:14:33 +0000 |
42 | +++ src/app/qml/ui/NotesPage.qml 2013-11-25 09:14:33 +0000 |
43 | @@ -8,6 +8,27 @@ |
44 | |
45 | property alias filter: notes.filterNotebookGuid |
46 | |
47 | + onActiveChanged: { |
48 | + if (active) { |
49 | + print("refreshing notes") |
50 | + notes.refresh(); |
51 | + } |
52 | + } |
53 | + |
54 | + // Just for testing |
55 | + tools: ToolbarItems { |
56 | + ToolbarButton { |
57 | + text: "add note" |
58 | + enabled: notes.filterNotebookGuid.length > 0 |
59 | + onTriggered: { |
60 | + var content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\"><en-note><div><br clear=\"none\"/>" |
61 | + content = content + "fobar" |
62 | + content = content + "<br clear=\"none\"/></div><div><br clear=\"none\"/></div></en-note>" |
63 | + NotesStore.createNote("Untitled", notes.filterNotebookGuid, content); |
64 | + } |
65 | + } |
66 | + } |
67 | + |
68 | Notes { |
69 | id: notes |
70 | } |
71 | @@ -22,6 +43,10 @@ |
72 | onClicked: { |
73 | pageStack.push(Qt.resolvedUrl("NotePage.qml"), {note: notes.note(guid)}) |
74 | } |
75 | + |
76 | + onPressAndHold: { |
77 | + notes.note(guid).remove(); |
78 | + } |
79 | } |
80 | } |
81 | } |
82 | |
83 | === modified file 'src/plugin/Evernote/Evernote.pro' |
84 | --- src/plugin/Evernote/Evernote.pro 2013-11-25 09:14:33 +0000 |
85 | +++ src/plugin/Evernote/Evernote.pro 2013-11-25 09:14:33 +0000 |
86 | @@ -16,9 +16,13 @@ |
87 | notes.cpp \ |
88 | note.cpp \ |
89 | notebook.cpp \ |
90 | - fetchnotesjob.cpp \ |
91 | - fetchnotebooksjob.cpp \ |
92 | - fetchnotejob.cpp |
93 | + jobs/fetchnotesjob.cpp \ |
94 | + jobs/fetchnotebooksjob.cpp \ |
95 | + jobs/fetchnotejob.cpp \ |
96 | + jobs/createnotejob.cpp \ |
97 | + jobs/evernotejob.cpp \ |
98 | + jobs/savenotejob.cpp \ |
99 | + jobs/deletenotejob.cpp |
100 | |
101 | HEADERS += evernoteplugin.h \ |
102 | notesstore.h \ |
103 | @@ -27,9 +31,13 @@ |
104 | notes.h \ |
105 | note.h \ |
106 | notebook.h \ |
107 | - fetchnotesjob.h \ |
108 | - fetchnotebooksjob.h \ |
109 | - fetchnotejob.h |
110 | + jobs/fetchnotesjob.h \ |
111 | + jobs/fetchnotebooksjob.h \ |
112 | + jobs/fetchnotejob.h \ |
113 | + jobs/createnotejob.h \ |
114 | + jobs/evernotejob.h \ |
115 | + jobs/savenotejob.h \ |
116 | + jobs/deletenotejob.h |
117 | |
118 | message(building in $$OUT_PWD) |
119 | LIBS += -L$$OUT_PWD/../../../3rdParty/evernote-sdk-cpp/ -L$$OUT_PWD/../../../3rdParty/libthrift/ -levernote-sdk-cpp -llibthrift |
120 | |
121 | === added directory 'src/plugin/Evernote/jobs' |
122 | === added file 'src/plugin/Evernote/jobs/createnotejob.cpp' |
123 | --- src/plugin/Evernote/jobs/createnotejob.cpp 1970-01-01 00:00:00 +0000 |
124 | +++ src/plugin/Evernote/jobs/createnotejob.cpp 2013-11-25 09:14:33 +0000 |
125 | @@ -0,0 +1,37 @@ |
126 | +#include "createnotejob.h" |
127 | + |
128 | +#include <QDebug> |
129 | + |
130 | +CreateNoteJob::CreateNoteJob(Note *note, QObject *parent) : |
131 | + EvernoteJob(parent), |
132 | + m_note(note) |
133 | +{ |
134 | +} |
135 | + |
136 | +void CreateNoteJob::run() |
137 | +{ |
138 | + NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; |
139 | + |
140 | + try { |
141 | + evernote::edam::Note input; |
142 | + input.title = m_note->title().toStdString(); |
143 | + input.__isset.title = true; |
144 | + input.notebookGuid = m_note->notebookGuid().toStdString(); |
145 | + input.__isset.notebookGuid = true; |
146 | + input.content = m_note->content().toStdString(); |
147 | + input.__isset.content = true; |
148 | + input.contentLength = m_note->content().length(); |
149 | + input.__isset.contentLength = true; |
150 | + |
151 | + evernote::edam::Note result; |
152 | + client()->createNote(result, token().toStdString(), input); |
153 | + |
154 | + m_note->setGuid(QString::fromStdString(result.guid)); |
155 | + |
156 | + } catch(evernote::edam::EDAMUserException e) { |
157 | + errorCode = NotesStore::ErrorCodeUserException; |
158 | + } catch(evernote::edam::EDAMSystemException) { |
159 | + errorCode = NotesStore::ErrorCodeSystemException; |
160 | + } |
161 | + emit resultReady(errorCode, m_note); |
162 | +} |
163 | |
164 | === added file 'src/plugin/Evernote/jobs/createnotejob.h' |
165 | --- src/plugin/Evernote/jobs/createnotejob.h 1970-01-01 00:00:00 +0000 |
166 | +++ src/plugin/Evernote/jobs/createnotejob.h 2013-11-25 09:14:33 +0000 |
167 | @@ -0,0 +1,22 @@ |
168 | +#ifndef CREATENOTEJOB_H |
169 | +#define CREATENOTEJOB_H |
170 | + |
171 | +#include "evernotejob.h" |
172 | +#include "note.h" |
173 | + |
174 | +class CreateNoteJob : public EvernoteJob |
175 | +{ |
176 | + Q_OBJECT |
177 | +public: |
178 | + explicit CreateNoteJob(Note *note, QObject *parent = 0); |
179 | + |
180 | + void run(); |
181 | + |
182 | +signals: |
183 | + void resultReady(NotesStore::ErrorCode errorCode, Note *note); |
184 | + |
185 | +private: |
186 | + Note *m_note; |
187 | +}; |
188 | + |
189 | +#endif // CREATENOTEJOB_H |
190 | |
191 | === added file 'src/plugin/Evernote/jobs/deletenotejob.cpp' |
192 | --- src/plugin/Evernote/jobs/deletenotejob.cpp 1970-01-01 00:00:00 +0000 |
193 | +++ src/plugin/Evernote/jobs/deletenotejob.cpp 2013-11-25 09:14:33 +0000 |
194 | @@ -0,0 +1,18 @@ |
195 | +#include "deletenotejob.h" |
196 | + |
197 | +DeleteNoteJob::DeleteNoteJob(const QString &guid, QObject *parent): |
198 | + EvernoteJob(parent), |
199 | + m_guid(guid) |
200 | +{ |
201 | +} |
202 | + |
203 | +void DeleteNoteJob::run() |
204 | +{ |
205 | + NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; |
206 | + try { |
207 | + client()->deleteNote(token().toStdString(), m_guid.toStdString()); |
208 | + } catch(...) { |
209 | + catchTransportException(); |
210 | + } |
211 | + emit resultReady(errorCode, m_guid); |
212 | +} |
213 | |
214 | === added file 'src/plugin/Evernote/jobs/deletenotejob.h' |
215 | --- src/plugin/Evernote/jobs/deletenotejob.h 1970-01-01 00:00:00 +0000 |
216 | +++ src/plugin/Evernote/jobs/deletenotejob.h 2013-11-25 09:14:33 +0000 |
217 | @@ -0,0 +1,21 @@ |
218 | +#ifndef DELETENOTEJOB_H |
219 | +#define DELETENOTEJOB_H |
220 | + |
221 | +#include "evernotejob.h" |
222 | + |
223 | +class DeleteNoteJob : public EvernoteJob |
224 | +{ |
225 | + Q_OBJECT |
226 | +public: |
227 | + DeleteNoteJob(const QString &guid, QObject *parent = 0); |
228 | + |
229 | + void run(); |
230 | + |
231 | +signals: |
232 | + void resultReady(NotesStore::ErrorCode errorCode, const QString &guid); |
233 | + |
234 | +private: |
235 | + QString m_guid; |
236 | +}; |
237 | + |
238 | +#endif // DELETENOTEJOB_H |
239 | |
240 | === added file 'src/plugin/Evernote/jobs/evernotejob.cpp' |
241 | --- src/plugin/Evernote/jobs/evernotejob.cpp 1970-01-01 00:00:00 +0000 |
242 | +++ src/plugin/Evernote/jobs/evernotejob.cpp 2013-11-25 09:14:33 +0000 |
243 | @@ -0,0 +1,49 @@ |
244 | +#include "evernotejob.h" |
245 | + |
246 | +// Thrift |
247 | +#include <arpa/inet.h> // seems thrift forgot this one |
248 | +#include <protocol/TBinaryProtocol.h> |
249 | +#include <transport/THttpClient.h> |
250 | +#include <transport/TSSLSocket.h> |
251 | +#include <Thrift.h> |
252 | + |
253 | +#include <QDebug> |
254 | + |
255 | +using namespace apache::thrift; |
256 | +using namespace apache::thrift::protocol; |
257 | +using namespace apache::thrift::transport; |
258 | + |
259 | +EvernoteJob::EvernoteJob(QObject *parent) : |
260 | + QThread(parent), |
261 | + m_token(NotesStore::instance()->token()) |
262 | +{ |
263 | + connect(this, &EvernoteJob::finished, this, &EvernoteJob::deleteLater); |
264 | +} |
265 | + |
266 | +EvernoteJob::~EvernoteJob() |
267 | +{ |
268 | + |
269 | +} |
270 | + |
271 | +evernote::edam::NoteStoreClient *EvernoteJob::client() |
272 | +{ |
273 | + return NotesStore::instance()->m_client; |
274 | +} |
275 | + |
276 | +QString EvernoteJob::token() |
277 | +{ |
278 | + return m_token; |
279 | +} |
280 | + |
281 | +void EvernoteJob::catchTransportException() |
282 | +{ |
283 | + try { |
284 | + // this function is meant to be called from a catch block |
285 | + // rethrow the exception to catch it again |
286 | + throw; |
287 | + } catch (const TTransportException & e) { |
288 | + qDebug() << e.what(); |
289 | + } catch (const TException & e) { |
290 | + qDebug() << e.what(); |
291 | + } |
292 | +} |
293 | |
294 | === added file 'src/plugin/Evernote/jobs/evernotejob.h' |
295 | --- src/plugin/Evernote/jobs/evernotejob.h 1970-01-01 00:00:00 +0000 |
296 | +++ src/plugin/Evernote/jobs/evernotejob.h 2013-11-25 09:14:33 +0000 |
297 | @@ -0,0 +1,30 @@ |
298 | +#ifndef EVERNOTEJOB_H |
299 | +#define EVERNOTEJOB_H |
300 | + |
301 | +#include "notesstore.h" |
302 | + |
303 | +// Evernote SDK |
304 | +#include <NoteStore.h> |
305 | +#include <NoteStore_constants.h> |
306 | +#include <Errors_types.h> |
307 | + |
308 | +#include <QThread> |
309 | + |
310 | +class EvernoteJob : public QThread |
311 | +{ |
312 | + Q_OBJECT |
313 | +public: |
314 | + explicit EvernoteJob(QObject *parent = 0); |
315 | + virtual ~EvernoteJob(); |
316 | + |
317 | +protected: |
318 | + evernote::edam::NoteStoreClient* client(); |
319 | + QString token(); |
320 | + |
321 | + void catchTransportException(); |
322 | + |
323 | +private: |
324 | + QString m_token; |
325 | +}; |
326 | + |
327 | +#endif // EVERNOTEJOB_H |
328 | |
329 | === renamed file 'src/plugin/Evernote/fetchnotebooksjob.cpp' => 'src/plugin/Evernote/jobs/fetchnotebooksjob.cpp' |
330 | --- src/plugin/Evernote/fetchnotebooksjob.cpp 2013-11-25 09:14:33 +0000 |
331 | +++ src/plugin/Evernote/jobs/fetchnotebooksjob.cpp 2013-11-25 09:14:33 +0000 |
332 | @@ -2,10 +2,8 @@ |
333 | |
334 | #include <QDebug> |
335 | |
336 | -FetchNotebooksJob::FetchNotebooksJob(evernote::edam::NoteStoreClient *client, const QString &token, QObject *parent) : |
337 | - QThread(parent), |
338 | - m_client(client), |
339 | - m_token(token) |
340 | +FetchNotebooksJob::FetchNotebooksJob(QObject *parent) : |
341 | + EvernoteJob(parent) |
342 | { |
343 | } |
344 | |
345 | @@ -15,7 +13,7 @@ |
346 | NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; |
347 | std::vector<evernote::edam::Notebook> results; |
348 | try { |
349 | - m_client->listNotebooks(results, m_token.toStdString()); |
350 | + client()->listNotebooks(results, token().toStdString()); |
351 | } catch(evernote::edam::EDAMUserException) { |
352 | errorCode = NotesStore::ErrorCodeUserException; |
353 | } catch(evernote::edam::EDAMSystemException) { |
354 | |
355 | === renamed file 'src/plugin/Evernote/fetchnotebooksjob.h' => 'src/plugin/Evernote/jobs/fetchnotebooksjob.h' |
356 | --- src/plugin/Evernote/fetchnotebooksjob.h 2013-11-25 09:14:33 +0000 |
357 | +++ src/plugin/Evernote/jobs/fetchnotebooksjob.h 2013-11-25 09:14:33 +0000 |
358 | @@ -1,29 +1,18 @@ |
359 | #ifndef FETCHNOTEBOOKSJOB_H |
360 | #define FETCHNOTEBOOKSJOB_H |
361 | |
362 | -#include "notesstore.h" |
363 | - |
364 | -// Evernote SDK |
365 | -#include <NoteStore.h> |
366 | -#include <NoteStore_constants.h> |
367 | -#include <Errors_types.h> |
368 | - |
369 | -#include <QThread> |
370 | - |
371 | -class FetchNotebooksJob : public QThread |
372 | +#include "evernotejob.h" |
373 | + |
374 | +class FetchNotebooksJob : public EvernoteJob |
375 | { |
376 | Q_OBJECT |
377 | public: |
378 | - explicit FetchNotebooksJob(evernote::edam::NoteStoreClient *client, const QString &token, QObject *parent = 0); |
379 | + explicit FetchNotebooksJob(QObject *parent = 0); |
380 | |
381 | void run(); |
382 | |
383 | signals: |
384 | void resultReady(NotesStore::ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results); |
385 | - |
386 | -private: |
387 | - evernote::edam::NoteStoreClient *m_client; |
388 | - QString m_token; |
389 | }; |
390 | |
391 | #endif // FETCHNOTEBOOKSJOB_H |
392 | |
393 | === renamed file 'src/plugin/Evernote/fetchnotejob.cpp' => 'src/plugin/Evernote/jobs/fetchnotejob.cpp' |
394 | --- src/plugin/Evernote/fetchnotejob.cpp 2013-11-25 09:14:33 +0000 |
395 | +++ src/plugin/Evernote/jobs/fetchnotejob.cpp 2013-11-25 09:14:33 +0000 |
396 | @@ -1,9 +1,7 @@ |
397 | #include "fetchnotejob.h" |
398 | |
399 | -FetchNoteJob::FetchNoteJob(evernote::edam::NoteStoreClient *client, const QString &token, const QString &guid, QObject *parent) : |
400 | - QThread(parent), |
401 | - m_client(client), |
402 | - m_token(token), |
403 | +FetchNoteJob::FetchNoteJob(const QString &guid, QObject *parent) : |
404 | + EvernoteJob(parent), |
405 | m_guid(guid) |
406 | { |
407 | } |
408 | @@ -13,13 +11,16 @@ |
409 | NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; |
410 | evernote::edam::Note result; |
411 | try { |
412 | - m_client->getNote(result, m_token.toStdString(), m_guid.toStdString(), true, true, false, false); |
413 | - } catch(evernote::edam::EDAMUserException) { |
414 | + client()->getNote(result, token().toStdString(), m_guid.toStdString(), true, true, false, false); |
415 | + } catch (evernote::edam::EDAMUserException) { |
416 | errorCode = NotesStore::ErrorCodeUserException; |
417 | - } catch(evernote::edam::EDAMSystemException) { |
418 | + } catch (evernote::edam::EDAMSystemException) { |
419 | errorCode = NotesStore::ErrorCodeSystemException; |
420 | - } catch(evernote::edam::EDAMNotFoundException) { |
421 | + } catch (evernote::edam::EDAMNotFoundException) { |
422 | errorCode = NotesStore::ErrorCodeNotFoundExcpetion; |
423 | + } catch (...) { |
424 | + catchTransportException(); |
425 | + errorCode = NotesStore::ErrorCodeConnectionLost; |
426 | } |
427 | |
428 | emit resultReady(errorCode, result); |
429 | |
430 | === renamed file 'src/plugin/Evernote/fetchnotejob.h' => 'src/plugin/Evernote/jobs/fetchnotejob.h' |
431 | --- src/plugin/Evernote/fetchnotejob.h 2013-11-25 09:14:33 +0000 |
432 | +++ src/plugin/Evernote/jobs/fetchnotejob.h 2013-11-25 09:14:33 +0000 |
433 | @@ -1,20 +1,13 @@ |
434 | #ifndef FETCHNOTEJOB_H |
435 | #define FETCHNOTEJOB_H |
436 | |
437 | -#include "notesstore.h" |
438 | - |
439 | -// Evernote SDK |
440 | -#include <NoteStore.h> |
441 | -#include <NoteStore_constants.h> |
442 | -#include <Errors_types.h> |
443 | - |
444 | -#include <QThread> |
445 | - |
446 | -class FetchNoteJob : public QThread |
447 | +#include "evernotejob.h" |
448 | + |
449 | +class FetchNoteJob : public EvernoteJob |
450 | { |
451 | Q_OBJECT |
452 | public: |
453 | - explicit FetchNoteJob(evernote::edam::NoteStoreClient *client, const QString &token, const QString &guid, QObject *parent = 0); |
454 | + explicit FetchNoteJob(const QString &guid, QObject *parent = 0); |
455 | |
456 | void run(); |
457 | signals: |
458 | |
459 | === renamed file 'src/plugin/Evernote/fetchnotesjob.cpp' => 'src/plugin/Evernote/jobs/fetchnotesjob.cpp' |
460 | --- src/plugin/Evernote/fetchnotesjob.cpp 2013-11-25 09:14:33 +0000 |
461 | +++ src/plugin/Evernote/jobs/fetchnotesjob.cpp 2013-11-25 09:14:33 +0000 |
462 | @@ -4,12 +4,8 @@ |
463 | |
464 | #include <QDebug> |
465 | |
466 | -FetchNotesJob::FetchNotesJob(evernote::edam::NoteStoreClient *client, |
467 | - const QString &token, |
468 | - const QString &filterNotebookGuid, QObject *parent) : |
469 | - QThread(parent), |
470 | - m_client(client), |
471 | - m_token(token), |
472 | +FetchNotesJob::FetchNotesJob( const QString &filterNotebookGuid, QObject *parent) : |
473 | + EvernoteJob(parent), |
474 | m_filterNotebookGuid(filterNotebookGuid) |
475 | { |
476 | } |
477 | @@ -36,7 +32,7 @@ |
478 | evernote::edam::NotesMetadataList results; |
479 | |
480 | try { |
481 | - m_client->findNotesMetadata(results, m_token.toStdString(), filter, start, end, resultSpec); |
482 | + client()->findNotesMetadata(results, token().toStdString(), filter, start, end, resultSpec); |
483 | } catch(evernote::edam::EDAMUserException) { |
484 | errorCode = NotesStore::ErrorCodeUserException; |
485 | } catch(evernote::edam::EDAMSystemException) { |
486 | |
487 | === renamed file 'src/plugin/Evernote/fetchnotesjob.h' => 'src/plugin/Evernote/jobs/fetchnotesjob.h' |
488 | --- src/plugin/Evernote/fetchnotesjob.h 2013-11-25 09:14:33 +0000 |
489 | +++ src/plugin/Evernote/jobs/fetchnotesjob.h 2013-11-25 09:14:33 +0000 |
490 | @@ -1,20 +1,13 @@ |
491 | #ifndef FETCHNOTESJOB_H |
492 | #define FETCHNOTESJOB_H |
493 | |
494 | -#include "notesstore.h" |
495 | - |
496 | -// Evernote SDK |
497 | -#include <NoteStore.h> |
498 | -#include <NoteStore_constants.h> |
499 | -#include <Errors_types.h> |
500 | - |
501 | -#include <QThread> |
502 | - |
503 | -class FetchNotesJob : public QThread |
504 | +#include "evernotejob.h" |
505 | + |
506 | +class FetchNotesJob : public EvernoteJob |
507 | { |
508 | Q_OBJECT |
509 | public: |
510 | - explicit FetchNotesJob(evernote::edam::NoteStoreClient *client, const QString &token, const QString &filterNotebookGuid, QObject *parent = 0); |
511 | + explicit FetchNotesJob(const QString &filterNotebookGuid, QObject *parent = 0); |
512 | |
513 | void run(); |
514 | |
515 | @@ -22,8 +15,6 @@ |
516 | void resultReady(NotesStore::ErrorCode errorCode, const evernote::edam::NotesMetadataList &results); |
517 | |
518 | private: |
519 | - evernote::edam::NoteStoreClient *m_client; |
520 | - QString m_token; |
521 | QString m_filterNotebookGuid; |
522 | }; |
523 | |
524 | |
525 | === added file 'src/plugin/Evernote/jobs/savenotejob.cpp' |
526 | --- src/plugin/Evernote/jobs/savenotejob.cpp 1970-01-01 00:00:00 +0000 |
527 | +++ src/plugin/Evernote/jobs/savenotejob.cpp 2013-11-25 09:14:33 +0000 |
528 | @@ -0,0 +1,40 @@ |
529 | +#include "savenotejob.h" |
530 | +#include "note.h" |
531 | + |
532 | +#include <QDebug> |
533 | + |
534 | +SaveNoteJob::SaveNoteJob(Note *note, QObject *parent) : |
535 | + EvernoteJob(parent), |
536 | + m_note(note) |
537 | +{ |
538 | +} |
539 | + |
540 | +void SaveNoteJob::run() |
541 | +{ |
542 | + NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; |
543 | + try { |
544 | + evernote::edam::Note note; |
545 | + note.guid = m_note->guid().toStdString(); |
546 | + note.__isset.guid = true; |
547 | + note.title = m_note->title().toStdString(); |
548 | + note.__isset.title = true; |
549 | + note.notebookGuid = m_note->notebookGuid().toStdString(); |
550 | + note.__isset.notebookGuid = true; |
551 | + note.content = m_note->content().toStdString(); |
552 | + note.__isset.content = true; |
553 | + note.contentLength = m_note->content().length(); |
554 | + |
555 | + client()->updateNote(note, token().toStdString(), note); |
556 | + |
557 | + } catch (evernote::edam::EDAMUserException e) { |
558 | + errorCode = NotesStore::ErrorCodeUserException; |
559 | + qDebug() << QString::fromStdString(e.parameter); |
560 | + } catch (evernote::edam::EDAMSystemException) { |
561 | + errorCode = NotesStore::ErrorCodeSystemException; |
562 | + } catch (...) { |
563 | + catchTransportException(); |
564 | + errorCode = NotesStore::ErrorCodeConnectionLost; |
565 | + } |
566 | + |
567 | + emit resultReady(errorCode, m_note); |
568 | +} |
569 | |
570 | === added file 'src/plugin/Evernote/jobs/savenotejob.h' |
571 | --- src/plugin/Evernote/jobs/savenotejob.h 1970-01-01 00:00:00 +0000 |
572 | +++ src/plugin/Evernote/jobs/savenotejob.h 2013-11-25 09:14:33 +0000 |
573 | @@ -0,0 +1,20 @@ |
574 | +#ifndef SAVENOTEJOB_H |
575 | +#define SAVENOTEJOB_H |
576 | + |
577 | +#include "evernotejob.h" |
578 | + |
579 | +class SaveNoteJob : public EvernoteJob |
580 | +{ |
581 | + Q_OBJECT |
582 | +public: |
583 | + explicit SaveNoteJob(Note *note, QObject *parent = 0); |
584 | + |
585 | + void run(); |
586 | +signals: |
587 | + void resultReady(NotesStore::ErrorCode errorCode, Note *note); |
588 | + |
589 | +private: |
590 | + Note *m_note; |
591 | +}; |
592 | + |
593 | +#endif // SAVENOTEJOB_H |
594 | |
595 | === modified file 'src/plugin/Evernote/note.cpp' |
596 | --- src/plugin/Evernote/note.cpp 2013-11-25 09:14:33 +0000 |
597 | +++ src/plugin/Evernote/note.cpp 2013-11-25 09:14:33 +0000 |
598 | @@ -1,5 +1,7 @@ |
599 | #include "note.h" |
600 | |
601 | +#include "notesstore.h" |
602 | + |
603 | Note::Note(const QString &guid, QObject *parent) : |
604 | QObject(parent), |
605 | m_guid(guid) |
606 | @@ -11,6 +13,14 @@ |
607 | return m_guid; |
608 | } |
609 | |
610 | +void Note::setGuid(const QString &guid) |
611 | +{ |
612 | + if (m_guid == guid) { |
613 | + m_guid = guid; |
614 | + emit guidChanged(); |
615 | + } |
616 | +} |
617 | + |
618 | QString Note::notebookGuid() const |
619 | { |
620 | return m_notebookGuid; |
621 | @@ -49,3 +59,13 @@ |
622 | emit contentChanged(); |
623 | } |
624 | } |
625 | + |
626 | +void Note::save() |
627 | +{ |
628 | + NotesStore::instance()->saveNote(m_guid); |
629 | +} |
630 | + |
631 | +void Note::remove() |
632 | +{ |
633 | + NotesStore::instance()->deleteNote(m_guid); |
634 | +} |
635 | |
636 | === modified file 'src/plugin/Evernote/note.h' |
637 | --- src/plugin/Evernote/note.h 2013-11-25 09:14:33 +0000 |
638 | +++ src/plugin/Evernote/note.h 2013-11-25 09:14:33 +0000 |
639 | @@ -7,14 +7,15 @@ |
640 | { |
641 | Q_OBJECT |
642 | |
643 | - Q_PROPERTY(QString guid READ guid CONSTANT) |
644 | + Q_PROPERTY(QString guid READ guid NOTIFY guidChanged) |
645 | Q_PROPERTY(QString notebookGuid READ notebookGuid WRITE setNotebookGuid NOTIFY notebookGuidChanged) |
646 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) |
647 | Q_PROPERTY(QString content READ content WRITE setContent NOTIFY contentChanged) |
648 | public: |
649 | - explicit Note(const QString &guid, QObject *parent = 0); |
650 | + explicit Note(const QString &guid = QString(), QObject *parent = 0); |
651 | |
652 | QString guid() const; |
653 | + void setGuid(const QString &guid); |
654 | |
655 | QString notebookGuid() const; |
656 | void setNotebookGuid(const QString ¬ebookGuid); |
657 | @@ -25,7 +26,12 @@ |
658 | QString content() const; |
659 | void setContent(const QString &content); |
660 | |
661 | +public slots: |
662 | + void save(); |
663 | + void remove(); |
664 | + |
665 | signals: |
666 | + void guidChanged(); |
667 | void titleChanged(); |
668 | void notebookGuidChanged(); |
669 | void contentChanged(); |
670 | |
671 | === modified file 'src/plugin/Evernote/notebooks.cpp' |
672 | --- src/plugin/Evernote/notebooks.cpp 2013-11-25 09:14:33 +0000 |
673 | +++ src/plugin/Evernote/notebooks.cpp 2013-11-25 09:14:33 +0000 |
674 | @@ -41,7 +41,6 @@ |
675 | |
676 | void Notebooks::refresh() |
677 | { |
678 | - qDebug() << "refreshing notebooks"; |
679 | NotesStore::instance()->refreshNotebooks(); |
680 | } |
681 | |
682 | |
683 | === modified file 'src/plugin/Evernote/notes.cpp' |
684 | --- src/plugin/Evernote/notes.cpp 2013-11-25 09:14:33 +0000 |
685 | +++ src/plugin/Evernote/notes.cpp 2013-11-25 09:14:33 +0000 |
686 | @@ -6,7 +6,9 @@ |
687 | Notes::Notes(QObject *parent) : |
688 | QAbstractListModel(parent) |
689 | { |
690 | - connect(NotesStore::instance(), SIGNAL(noteAdded(const QString &)), SLOT(noteAdded(const QString &))); |
691 | + connect(NotesStore::instance(), &NotesStore::noteAdded, this, &Notes::noteAdded); |
692 | + connect(NotesStore::instance(), &NotesStore::noteRemoved, this, &Notes::noteRemoved); |
693 | + connect(NotesStore::instance(), &NotesStore::noteChanged, this, &Notes::noteChanged); |
694 | } |
695 | |
696 | QVariant Notes::data(const QModelIndex &index, int role) const |
697 | @@ -85,3 +87,13 @@ |
698 | emit dataChanged(index(row), index(row)); |
699 | } |
700 | } |
701 | + |
702 | +void Notes::noteRemoved(const QString &guid) |
703 | +{ |
704 | + int index = m_list.indexOf(guid); |
705 | + if (index >= 0) { |
706 | + beginRemoveRows(QModelIndex(), index, index); |
707 | + m_list.removeAt(index); |
708 | + endRemoveRows(); |
709 | + } |
710 | +} |
711 | |
712 | === modified file 'src/plugin/Evernote/notes.h' |
713 | --- src/plugin/Evernote/notes.h 2013-11-25 09:14:33 +0000 |
714 | +++ src/plugin/Evernote/notes.h 2013-11-25 09:14:33 +0000 |
715 | @@ -35,6 +35,7 @@ |
716 | private slots: |
717 | void noteAdded(const QString &guid); |
718 | void noteChanged(const QString &guid); |
719 | + void noteRemoved(const QString &guid); |
720 | |
721 | signals: |
722 | void filterNotebookGuidChanged(); |
723 | |
724 | === modified file 'src/plugin/Evernote/notesstore.cpp' |
725 | --- src/plugin/Evernote/notesstore.cpp 2013-11-25 09:14:33 +0000 |
726 | +++ src/plugin/Evernote/notesstore.cpp 2013-11-25 09:14:33 +0000 |
727 | @@ -3,9 +3,12 @@ |
728 | #include "notebook.h" |
729 | #include "note.h" |
730 | |
731 | -#include "fetchnotesjob.h" |
732 | -#include "fetchnotebooksjob.h" |
733 | -#include "fetchnotejob.h" |
734 | +#include "jobs/fetchnotesjob.h" |
735 | +#include "jobs/fetchnotebooksjob.h" |
736 | +#include "jobs/fetchnotejob.h" |
737 | +#include "jobs/createnotejob.h" |
738 | +#include "jobs/savenotejob.h" |
739 | +#include "jobs/deletenotejob.h" |
740 | |
741 | // Thrift |
742 | #include <arpa/inet.h> // seems thrift forgot this one |
743 | @@ -127,6 +130,23 @@ |
744 | return m_notes.value(guid); |
745 | } |
746 | |
747 | +void NotesStore::saveNote(const QString &guid) |
748 | +{ |
749 | + Note *note = m_notes.value(guid); |
750 | + SaveNoteJob *job = new SaveNoteJob(note, this); |
751 | + connect(job, &SaveNoteJob::resultReady, this, &NotesStore::saveNoteJobDone); |
752 | + m_jobQueue.append(job); |
753 | + startJobQueue(); |
754 | +} |
755 | + |
756 | +void NotesStore::deleteNote(const QString &guid) |
757 | +{ |
758 | + DeleteNoteJob *job = new DeleteNoteJob(guid, this); |
759 | + connect(job, &DeleteNoteJob::resultReady, this, &NotesStore::deleteNoteJobDone); |
760 | + m_jobQueue.append(job); |
761 | + startJobQueue(); |
762 | +} |
763 | + |
764 | QList<Notebook *> NotesStore::notebooks() const |
765 | { |
766 | return m_notebooks.values(); |
767 | @@ -139,14 +159,14 @@ |
768 | |
769 | void NotesStore::startJobQueue() |
770 | { |
771 | - if (m_requestQueue.isEmpty()) { |
772 | + if (m_jobQueue.isEmpty()) { |
773 | return; |
774 | } |
775 | |
776 | if (m_currentJob) { |
777 | return; |
778 | } |
779 | - m_currentJob = m_requestQueue.takeFirst(); |
780 | + m_currentJob = m_jobQueue.takeFirst(); |
781 | m_currentJob->start(); |
782 | } |
783 | |
784 | @@ -163,11 +183,10 @@ |
785 | return; |
786 | } |
787 | |
788 | - FetchNotesJob *job = new FetchNotesJob(m_client, m_token, filterNotebookGuid); |
789 | + FetchNotesJob *job = new FetchNotesJob(filterNotebookGuid); |
790 | connect(job, &FetchNotesJob::resultReady, this, &NotesStore::fetchNotesJobDone); |
791 | - connect(job, &FetchNoteJob::finished, job, &FetchNotesJob::deleteLater); |
792 | |
793 | - m_requestQueue.append(job); |
794 | + m_jobQueue.append(job); |
795 | startJobQueue(); |
796 | } |
797 | |
798 | @@ -183,7 +202,9 @@ |
799 | evernote::edam::NoteMetadata result = results.notes.at(i); |
800 | Note *note = m_notes.value(QString::fromStdString(result.guid)); |
801 | if (note) { |
802 | - qDebug() << "Received update for existing note"; |
803 | + note->setTitle(QString::fromStdString(result.title)); |
804 | + note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); |
805 | + emit noteChanged(note->guid()); |
806 | } else { |
807 | note = new Note(QString::fromStdString(result.guid), this); |
808 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); |
809 | @@ -203,10 +224,9 @@ |
810 | return; |
811 | } |
812 | |
813 | - FetchNoteJob *job = new FetchNoteJob(m_client, m_token, guid, this); |
814 | + FetchNoteJob *job = new FetchNoteJob(guid, this); |
815 | connect(job, &FetchNoteJob::resultReady, this, &NotesStore::fetchNoteJobDone); |
816 | - connect(job, &FetchNoteJob::finished, job, &FetchNoteJob::deleteLater); |
817 | - m_requestQueue.append(job); |
818 | + m_jobQueue.append(job); |
819 | |
820 | startJobQueue(); |
821 | } |
822 | @@ -235,11 +255,10 @@ |
823 | return; |
824 | } |
825 | |
826 | - FetchNotebooksJob *job = new FetchNotebooksJob(m_client, m_token); |
827 | + FetchNotebooksJob *job = new FetchNotebooksJob(); |
828 | connect(job, &FetchNotebooksJob::resultReady, this, &NotesStore::fetchNotebooksJobDone); |
829 | - connect(job, &FetchNotebooksJob::finished, job, &FetchNotebooksJob::deleteLater); |
830 | |
831 | - m_requestQueue.append(job); |
832 | + m_jobQueue.append(job); |
833 | startJobQueue(); |
834 | } |
835 | |
836 | @@ -256,13 +275,61 @@ |
837 | Notebook *notebook = m_notebooks.value(QString::fromStdString(result.guid)); |
838 | if (notebook) { |
839 | qDebug() << "got notebook update"; |
840 | + notebook->setName(QString::fromStdString(result.name)); |
841 | + emit notebookChanged(notebook->guid()); |
842 | } else { |
843 | notebook = new Notebook(QString::fromStdString(result.guid), this); |
844 | notebook->setName(QString::fromStdString(result.name)); |
845 | m_notebooks.insert(notebook->guid(), notebook); |
846 | emit notebookAdded(notebook->guid()); |
847 | + qDebug() << "got new notebook" << notebook->guid(); |
848 | } |
849 | } |
850 | |
851 | startNextJob(); |
852 | } |
853 | + |
854 | +void NotesStore::createNote(const QString &title, const QString ¬ebookGuid, const QString &content) |
855 | +{ |
856 | + Note *note = new Note(); |
857 | + note->setTitle(title); |
858 | + note->setNotebookGuid(notebookGuid); |
859 | + note->setContent(content); |
860 | + CreateNoteJob *job = new CreateNoteJob(note); |
861 | + connect(job, &CreateNoteJob::resultReady, this, &NotesStore::createNoteJobDone); |
862 | + |
863 | + m_jobQueue.append(job); |
864 | + startJobQueue(); |
865 | +} |
866 | + |
867 | +void NotesStore::createNoteJobDone(NotesStore::ErrorCode errorCode, Note *note) |
868 | +{ |
869 | + if (errorCode != ErrorCodeNoError) { |
870 | + qWarning() << "Error creating note:" << errorCodeToString(errorCode); |
871 | + delete note; |
872 | + startNextJob(); |
873 | + return; |
874 | + } |
875 | + |
876 | + m_notes.insert(note->guid(), note); |
877 | + noteAdded(note->guid()); |
878 | + startNextJob(); |
879 | +} |
880 | + |
881 | +void NotesStore::saveNoteJobDone(NotesStore::ErrorCode errorCode, Note *note) |
882 | +{ |
883 | + startNextJob(); |
884 | +} |
885 | + |
886 | +void NotesStore::deleteNoteJobDone(NotesStore::ErrorCode errorCode, const QString &guid) |
887 | +{ |
888 | + if (errorCode != ErrorCodeNoError) { |
889 | + qWarning() << "Cannot delete note:" << errorCodeToString(errorCode); |
890 | + startNextJob(); |
891 | + return; |
892 | + } |
893 | + emit noteRemoved(guid); |
894 | + m_notes.take(guid)->deleteLater(); |
895 | + startNextJob(); |
896 | +} |
897 | + |
898 | |
899 | === modified file 'src/plugin/Evernote/notesstore.h' |
900 | --- src/plugin/Evernote/notesstore.h 2013-11-25 09:14:33 +0000 |
901 | +++ src/plugin/Evernote/notesstore.h 2013-11-25 09:14:33 +0000 |
902 | @@ -9,6 +9,8 @@ |
903 | #include <QObject> |
904 | #include <QHash> |
905 | |
906 | +class EvernoteJob; |
907 | + |
908 | class Notebook; |
909 | class Note; |
910 | |
911 | @@ -17,14 +19,19 @@ |
912 | Q_OBJECT |
913 | Q_PROPERTY(QString token READ token WRITE setToken NOTIFY tokenChanged) |
914 | |
915 | + friend class EvernoteJob; |
916 | + |
917 | public: |
918 | enum ErrorCode { |
919 | ErrorCodeNoError, |
920 | ErrorCodeUserException, |
921 | ErrorCodeSystemException, |
922 | - ErrorCodeNotFoundExcpetion |
923 | + ErrorCodeNotFoundExcpetion, |
924 | + ErrorCodeConnectionLost |
925 | }; |
926 | |
927 | + Q_INVOKABLE void createNote(const QString &title, const QString ¬ebookGuid, const QString &content); |
928 | + |
929 | static NotesStore *instance(); |
930 | static QString errorCodeToString(ErrorCode errorCode); |
931 | |
932 | @@ -35,6 +42,8 @@ |
933 | |
934 | QList<Note*> notes() const; |
935 | Note* note(const QString &guid); |
936 | + void saveNote(const QString &guid); |
937 | + void deleteNote(const QString &guid); |
938 | |
939 | QList<Notebook*> notebooks() const; |
940 | Notebook* notebook(const QString &guid); |
941 | @@ -48,13 +57,18 @@ |
942 | |
943 | void noteAdded(const QString &guid); |
944 | void noteChanged(const QString &guid); |
945 | + void noteRemoved(const QString &guid); |
946 | |
947 | void notebookAdded(const QString &guid); |
948 | + void notebookChanged(const QString &guid); |
949 | |
950 | private slots: |
951 | void fetchNotesJobDone(ErrorCode errorCode, const evernote::edam::NotesMetadataList &results); |
952 | void fetchNotebooksJobDone(ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results); |
953 | void fetchNoteJobDone(ErrorCode errorCode, const evernote::edam::Note &result); |
954 | + void createNoteJobDone(ErrorCode errorCode, Note *note); |
955 | + void saveNoteJobDone(ErrorCode errorCode, Note *note); |
956 | + void deleteNoteJobDone(ErrorCode errorCode, const QString &guid); |
957 | |
958 | void startJobQueue(); |
959 | void startNextJob(); |
960 | @@ -69,7 +83,7 @@ |
961 | QHash<QString, Notebook*> m_notebooks; |
962 | QHash<QString, Note*> m_notes; |
963 | |
964 | - QList<QThread*> m_requestQueue; |
965 | + QList<EvernoteJob*> m_jobQueue; |
966 | QThread *m_currentJob; |
967 | }; |
968 |
FAILED: Continuous integration, rev:12 91.189. 93.70:8080/ job/reminders- app-ci/ 13/ 91.189. 93.70:8080/ job/generic- mediumtests- trusty/ 235/console 91.189. 93.70:8080/ job/reminders- app-raring- amd64-ci/ 13 91.189. 93.70:8080/ job/reminders- app-saucy- amd64-ci/ 13 91.189. 93.70:8080/ job/reminders- app-trusty- amd64-ci/ 13
http://
Executed test runs:
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: 91.189. 93.70:8080/ job/reminders- app-ci/ 13/rebuild
http://