Merge lp:~mzanetti/reminders-app/create-edit-delete-notes into lp:reminders-app
- create-edit-delete-notes
- Merge into trunk
Proposed by
Michael Zanetti
Status: | Superseded |
---|---|
Proposed branch: | lp:~mzanetti/reminders-app/create-edit-delete-notes |
Merge into: | lp:reminders-app |
Diff against target: |
1577 lines (+1029/-175) 30 files modified
src/app/qml/reminders-app.qml (+1/-1) src/app/qml/ui/NotePage.qml (+26/-6) src/app/qml/ui/NotesPage.qml (+20/-3) src/plugin/Evernote/Evernote.pro (+20/-2) src/plugin/Evernote/evernoteplugin.cpp (+2/-0) 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 (+23/-0) src/plugin/Evernote/jobs/fetchnotebooksjob.h (+18/-0) src/plugin/Evernote/jobs/fetchnotejob.cpp (+27/-0) src/plugin/Evernote/jobs/fetchnotejob.h (+22/-0) src/plugin/Evernote/jobs/fetchnotesjob.cpp (+44/-0) src/plugin/Evernote/jobs/fetchnotesjob.h (+21/-0) src/plugin/Evernote/jobs/savenotejob.cpp (+40/-0) src/plugin/Evernote/jobs/savenotejob.h (+20/-0) src/plugin/Evernote/note.cpp (+71/-0) src/plugin/Evernote/note.h (+46/-0) src/plugin/Evernote/notebook.cpp (+25/-0) src/plugin/Evernote/notebook.h (+30/-0) src/plugin/Evernote/notebooks.cpp (+19/-25) src/plugin/Evernote/notebooks.h (+4/-5) src/plugin/Evernote/notes.cpp (+49/-53) src/plugin/Evernote/notes.h (+13/-6) src/plugin/Evernote/notesstore.cpp (+255/-59) src/plugin/Evernote/notesstore.h (+56/-13) src/plugin/Evernote/userstore.h (+0/-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 | Needs Fixing | |
Ubuntu Notes app developers | Pending | ||
Review via email: mp+196456@code.launchpad.net |
This proposal has been superseded by 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.
To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
review:
Needs Fixing
(continuous-integration)
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/app/qml/reminders-app.qml' |
2 | --- src/app/qml/reminders-app.qml 2013-11-22 00:42:39 +0000 |
3 | +++ src/app/qml/reminders-app.qml 2013-11-25 00:51:38 +0000 |
4 | @@ -29,7 +29,7 @@ |
5 | |
6 | Component.onCompleted: { |
7 | pagestack.push(rootTabs) |
8 | - if (NotesStore.token.length == 0) { |
9 | + if (NotesStore.token.length === 0) { |
10 | pagestack.push(Qt.resolvedUrl("ui/AccountSelectorPage.qml")); |
11 | } |
12 | } |
13 | |
14 | === modified file 'src/app/qml/ui/NotePage.qml' |
15 | --- src/app/qml/ui/NotePage.qml 2013-11-21 23:30:15 +0000 |
16 | +++ src/app/qml/ui/NotePage.qml 2013-11-25 00:51:38 +0000 |
17 | @@ -3,13 +3,33 @@ |
18 | import Evernote 0.1 |
19 | |
20 | Page { |
21 | - |
22 | - property alias text: noteTextArea.text |
23 | - |
24 | - TextArea { |
25 | - id: noteTextArea |
26 | + title: note.title |
27 | + property var note |
28 | + |
29 | + Column { |
30 | anchors.fill: parent |
31 | - textFormat: TextEdit.RichText |
32 | + spacing: units.gu(1) |
33 | + Button { |
34 | + width: parent.width |
35 | + text: "save" |
36 | + onClicked: { |
37 | + print("timer triggered") |
38 | + 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\"/>" |
39 | + content = content + noteTextArea.getText(0, noteTextArea.length) |
40 | + content = content + "<br clear=\"none\"/></div><div><br clear=\"none\"/></div></en-note>" |
41 | + note.content = content |
42 | + note.save(); |
43 | + } |
44 | + } |
45 | + |
46 | + TextArea { |
47 | + id: noteTextArea |
48 | + anchors { left: parent.left; right: parent.right } |
49 | + height: parent.height - y |
50 | + |
51 | + textFormat: TextEdit.RichText |
52 | + text: note.content |
53 | + } |
54 | } |
55 | } |
56 | |
57 | |
58 | === modified file 'src/app/qml/ui/NotesPage.qml' |
59 | --- src/app/qml/ui/NotesPage.qml 2013-11-21 23:30:15 +0000 |
60 | +++ src/app/qml/ui/NotesPage.qml 2013-11-25 00:51:38 +0000 |
61 | @@ -10,14 +10,27 @@ |
62 | |
63 | onActiveChanged: { |
64 | if (active) { |
65 | + print("refreshing notes") |
66 | notes.refresh(); |
67 | } |
68 | } |
69 | |
70 | + // Just for testing |
71 | + tools: ToolbarItems { |
72 | + ToolbarButton { |
73 | + text: "add note" |
74 | + enabled: notes.filterNotebookGuid.length > 0 |
75 | + onTriggered: { |
76 | + 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\"/>" |
77 | + content = content + "fobar" |
78 | + content = content + "<br clear=\"none\"/></div><div><br clear=\"none\"/></div></en-note>" |
79 | + NotesStore.createNote("Untitled", notes.filterNotebookGuid, content); |
80 | + } |
81 | + } |
82 | + } |
83 | + |
84 | Notes { |
85 | id: notes |
86 | - |
87 | - onFilterNotebookGuidChanged: refresh(); |
88 | } |
89 | |
90 | ListView { |
91 | @@ -28,7 +41,11 @@ |
92 | text: title |
93 | |
94 | onClicked: { |
95 | - pageStack.push(Qt.resolvedUrl("NotePage.qml"), {title: title, text: notes.note(guid)}) |
96 | + pageStack.push(Qt.resolvedUrl("NotePage.qml"), {note: notes.note(guid)}) |
97 | + } |
98 | + |
99 | + onPressAndHold: { |
100 | + notes.note(guid).remove(); |
101 | } |
102 | } |
103 | } |
104 | |
105 | === modified file 'src/plugin/Evernote/Evernote.pro' |
106 | --- src/plugin/Evernote/Evernote.pro 2013-11-21 23:30:15 +0000 |
107 | +++ src/plugin/Evernote/Evernote.pro 2013-11-25 00:51:38 +0000 |
108 | @@ -13,13 +13,31 @@ |
109 | notesstore.cpp \ |
110 | userstore.cpp \ |
111 | notebooks.cpp \ |
112 | - notes.cpp |
113 | + notes.cpp \ |
114 | + note.cpp \ |
115 | + notebook.cpp \ |
116 | + jobs/fetchnotesjob.cpp \ |
117 | + jobs/fetchnotebooksjob.cpp \ |
118 | + jobs/fetchnotejob.cpp \ |
119 | + jobs/createnotejob.cpp \ |
120 | + jobs/evernotejob.cpp \ |
121 | + jobs/savenotejob.cpp \ |
122 | + jobs/deletenotejob.cpp |
123 | |
124 | HEADERS += evernoteplugin.h \ |
125 | notesstore.h \ |
126 | userstore.h \ |
127 | notebooks.h \ |
128 | - notes.h |
129 | + notes.h \ |
130 | + note.h \ |
131 | + notebook.h \ |
132 | + jobs/fetchnotesjob.h \ |
133 | + jobs/fetchnotebooksjob.h \ |
134 | + jobs/fetchnotejob.h \ |
135 | + jobs/createnotejob.h \ |
136 | + jobs/evernotejob.h \ |
137 | + jobs/savenotejob.h \ |
138 | + jobs/deletenotejob.h |
139 | |
140 | message(building in $$OUT_PWD) |
141 | LIBS += -L$$OUT_PWD/../../../3rdParty/evernote-sdk-cpp/ -L$$OUT_PWD/../../../3rdParty/libthrift/ -levernote-sdk-cpp -llibthrift |
142 | |
143 | === modified file 'src/plugin/Evernote/evernoteplugin.cpp' |
144 | --- src/plugin/Evernote/evernoteplugin.cpp 2013-11-21 23:30:15 +0000 |
145 | +++ src/plugin/Evernote/evernoteplugin.cpp 2013-11-25 00:51:38 +0000 |
146 | @@ -22,6 +22,7 @@ |
147 | #include "notesstore.h" |
148 | #include "notes.h" |
149 | #include "notebooks.h" |
150 | +#include "note.h" |
151 | |
152 | #include <QtQml> |
153 | |
154 | @@ -37,4 +38,5 @@ |
155 | qmlRegisterSingletonType<NotesStore>("Evernote", 0, 1, "NotesStore", notesStoreProvider); |
156 | qmlRegisterType<Notes>("Evernote", 0, 1, "Notes"); |
157 | qmlRegisterType<Notebooks>("Evernote", 0, 1, "Notebooks"); |
158 | + qmlRegisterUncreatableType<Note>("Evernote", 0, 1, "Note", "Cannot create Notes in QML. Use NotesStore.createNote() instead."); |
159 | } |
160 | |
161 | === added directory 'src/plugin/Evernote/jobs' |
162 | === added file 'src/plugin/Evernote/jobs/createnotejob.cpp' |
163 | --- src/plugin/Evernote/jobs/createnotejob.cpp 1970-01-01 00:00:00 +0000 |
164 | +++ src/plugin/Evernote/jobs/createnotejob.cpp 2013-11-25 00:51:38 +0000 |
165 | @@ -0,0 +1,37 @@ |
166 | +#include "createnotejob.h" |
167 | + |
168 | +#include <QDebug> |
169 | + |
170 | +CreateNoteJob::CreateNoteJob(Note *note, QObject *parent) : |
171 | + EvernoteJob(parent), |
172 | + m_note(note) |
173 | +{ |
174 | +} |
175 | + |
176 | +void CreateNoteJob::run() |
177 | +{ |
178 | + NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; |
179 | + |
180 | + try { |
181 | + evernote::edam::Note input; |
182 | + input.title = m_note->title().toStdString(); |
183 | + input.__isset.title = true; |
184 | + input.notebookGuid = m_note->notebookGuid().toStdString(); |
185 | + input.__isset.notebookGuid = true; |
186 | + input.content = m_note->content().toStdString(); |
187 | + input.__isset.content = true; |
188 | + input.contentLength = m_note->content().length(); |
189 | + input.__isset.contentLength = true; |
190 | + |
191 | + evernote::edam::Note result; |
192 | + client()->createNote(result, token().toStdString(), input); |
193 | + |
194 | + m_note->setGuid(QString::fromStdString(result.guid)); |
195 | + |
196 | + } catch(evernote::edam::EDAMUserException e) { |
197 | + errorCode = NotesStore::ErrorCodeUserException; |
198 | + } catch(evernote::edam::EDAMSystemException) { |
199 | + errorCode = NotesStore::ErrorCodeSystemException; |
200 | + } |
201 | + emit resultReady(errorCode, m_note); |
202 | +} |
203 | |
204 | === added file 'src/plugin/Evernote/jobs/createnotejob.h' |
205 | --- src/plugin/Evernote/jobs/createnotejob.h 1970-01-01 00:00:00 +0000 |
206 | +++ src/plugin/Evernote/jobs/createnotejob.h 2013-11-25 00:51:38 +0000 |
207 | @@ -0,0 +1,22 @@ |
208 | +#ifndef CREATENOTEJOB_H |
209 | +#define CREATENOTEJOB_H |
210 | + |
211 | +#include "evernotejob.h" |
212 | +#include "note.h" |
213 | + |
214 | +class CreateNoteJob : public EvernoteJob |
215 | +{ |
216 | + Q_OBJECT |
217 | +public: |
218 | + explicit CreateNoteJob(Note *note, QObject *parent = 0); |
219 | + |
220 | + void run(); |
221 | + |
222 | +signals: |
223 | + void resultReady(NotesStore::ErrorCode errorCode, Note *note); |
224 | + |
225 | +private: |
226 | + Note *m_note; |
227 | +}; |
228 | + |
229 | +#endif // CREATENOTEJOB_H |
230 | |
231 | === added file 'src/plugin/Evernote/jobs/deletenotejob.cpp' |
232 | --- src/plugin/Evernote/jobs/deletenotejob.cpp 1970-01-01 00:00:00 +0000 |
233 | +++ src/plugin/Evernote/jobs/deletenotejob.cpp 2013-11-25 00:51:38 +0000 |
234 | @@ -0,0 +1,18 @@ |
235 | +#include "deletenotejob.h" |
236 | + |
237 | +DeleteNoteJob::DeleteNoteJob(const QString &guid, QObject *parent): |
238 | + EvernoteJob(parent), |
239 | + m_guid(guid) |
240 | +{ |
241 | +} |
242 | + |
243 | +void DeleteNoteJob::run() |
244 | +{ |
245 | + NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; |
246 | + try { |
247 | + client()->deleteNote(token().toStdString(), m_guid.toStdString()); |
248 | + } catch(...) { |
249 | + catchTransportException(); |
250 | + } |
251 | + emit resultReady(errorCode, m_guid); |
252 | +} |
253 | |
254 | === added file 'src/plugin/Evernote/jobs/deletenotejob.h' |
255 | --- src/plugin/Evernote/jobs/deletenotejob.h 1970-01-01 00:00:00 +0000 |
256 | +++ src/plugin/Evernote/jobs/deletenotejob.h 2013-11-25 00:51:38 +0000 |
257 | @@ -0,0 +1,21 @@ |
258 | +#ifndef DELETENOTEJOB_H |
259 | +#define DELETENOTEJOB_H |
260 | + |
261 | +#include "evernotejob.h" |
262 | + |
263 | +class DeleteNoteJob : public EvernoteJob |
264 | +{ |
265 | + Q_OBJECT |
266 | +public: |
267 | + DeleteNoteJob(const QString &guid, QObject *parent = 0); |
268 | + |
269 | + void run(); |
270 | + |
271 | +signals: |
272 | + void resultReady(NotesStore::ErrorCode errorCode, const QString &guid); |
273 | + |
274 | +private: |
275 | + QString m_guid; |
276 | +}; |
277 | + |
278 | +#endif // DELETENOTEJOB_H |
279 | |
280 | === added file 'src/plugin/Evernote/jobs/evernotejob.cpp' |
281 | --- src/plugin/Evernote/jobs/evernotejob.cpp 1970-01-01 00:00:00 +0000 |
282 | +++ src/plugin/Evernote/jobs/evernotejob.cpp 2013-11-25 00:51:38 +0000 |
283 | @@ -0,0 +1,49 @@ |
284 | +#include "evernotejob.h" |
285 | + |
286 | +// Thrift |
287 | +#include <arpa/inet.h> // seems thrift forgot this one |
288 | +#include <protocol/TBinaryProtocol.h> |
289 | +#include <transport/THttpClient.h> |
290 | +#include <transport/TSSLSocket.h> |
291 | +#include <Thrift.h> |
292 | + |
293 | +#include <QDebug> |
294 | + |
295 | +using namespace apache::thrift; |
296 | +using namespace apache::thrift::protocol; |
297 | +using namespace apache::thrift::transport; |
298 | + |
299 | +EvernoteJob::EvernoteJob(QObject *parent) : |
300 | + QThread(parent), |
301 | + m_token(NotesStore::instance()->token()) |
302 | +{ |
303 | + connect(this, &EvernoteJob::finished, this, &EvernoteJob::deleteLater); |
304 | +} |
305 | + |
306 | +EvernoteJob::~EvernoteJob() |
307 | +{ |
308 | + |
309 | +} |
310 | + |
311 | +evernote::edam::NoteStoreClient *EvernoteJob::client() |
312 | +{ |
313 | + return NotesStore::instance()->m_client; |
314 | +} |
315 | + |
316 | +QString EvernoteJob::token() |
317 | +{ |
318 | + return m_token; |
319 | +} |
320 | + |
321 | +void EvernoteJob::catchTransportException() |
322 | +{ |
323 | + try { |
324 | + // this function is meant to be called from a catch block |
325 | + // rethrow the exception to catch it again |
326 | + throw; |
327 | + } catch (const TTransportException & e) { |
328 | + qDebug() << e.what(); |
329 | + } catch (const TException & e) { |
330 | + qDebug() << e.what(); |
331 | + } |
332 | +} |
333 | |
334 | === added file 'src/plugin/Evernote/jobs/evernotejob.h' |
335 | --- src/plugin/Evernote/jobs/evernotejob.h 1970-01-01 00:00:00 +0000 |
336 | +++ src/plugin/Evernote/jobs/evernotejob.h 2013-11-25 00:51:38 +0000 |
337 | @@ -0,0 +1,30 @@ |
338 | +#ifndef EVERNOTEJOB_H |
339 | +#define EVERNOTEJOB_H |
340 | + |
341 | +#include "notesstore.h" |
342 | + |
343 | +// Evernote SDK |
344 | +#include <NoteStore.h> |
345 | +#include <NoteStore_constants.h> |
346 | +#include <Errors_types.h> |
347 | + |
348 | +#include <QThread> |
349 | + |
350 | +class EvernoteJob : public QThread |
351 | +{ |
352 | + Q_OBJECT |
353 | +public: |
354 | + explicit EvernoteJob(QObject *parent = 0); |
355 | + virtual ~EvernoteJob(); |
356 | + |
357 | +protected: |
358 | + evernote::edam::NoteStoreClient* client(); |
359 | + QString token(); |
360 | + |
361 | + void catchTransportException(); |
362 | + |
363 | +private: |
364 | + QString m_token; |
365 | +}; |
366 | + |
367 | +#endif // EVERNOTEJOB_H |
368 | |
369 | === added file 'src/plugin/Evernote/jobs/fetchnotebooksjob.cpp' |
370 | --- src/plugin/Evernote/jobs/fetchnotebooksjob.cpp 1970-01-01 00:00:00 +0000 |
371 | +++ src/plugin/Evernote/jobs/fetchnotebooksjob.cpp 2013-11-25 00:51:38 +0000 |
372 | @@ -0,0 +1,23 @@ |
373 | +#include "fetchnotebooksjob.h" |
374 | + |
375 | +#include <QDebug> |
376 | + |
377 | +FetchNotebooksJob::FetchNotebooksJob(QObject *parent) : |
378 | + EvernoteJob(parent) |
379 | +{ |
380 | +} |
381 | + |
382 | + |
383 | +void FetchNotebooksJob::run() |
384 | +{ |
385 | + NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; |
386 | + std::vector<evernote::edam::Notebook> results; |
387 | + try { |
388 | + client()->listNotebooks(results, token().toStdString()); |
389 | + } catch(evernote::edam::EDAMUserException) { |
390 | + errorCode = NotesStore::ErrorCodeUserException; |
391 | + } catch(evernote::edam::EDAMSystemException) { |
392 | + errorCode = NotesStore::ErrorCodeSystemException; |
393 | + } |
394 | + emit resultReady(errorCode, results); |
395 | +} |
396 | |
397 | === added file 'src/plugin/Evernote/jobs/fetchnotebooksjob.h' |
398 | --- src/plugin/Evernote/jobs/fetchnotebooksjob.h 1970-01-01 00:00:00 +0000 |
399 | +++ src/plugin/Evernote/jobs/fetchnotebooksjob.h 2013-11-25 00:51:38 +0000 |
400 | @@ -0,0 +1,18 @@ |
401 | +#ifndef FETCHNOTEBOOKSJOB_H |
402 | +#define FETCHNOTEBOOKSJOB_H |
403 | + |
404 | +#include "evernotejob.h" |
405 | + |
406 | +class FetchNotebooksJob : public EvernoteJob |
407 | +{ |
408 | + Q_OBJECT |
409 | +public: |
410 | + explicit FetchNotebooksJob(QObject *parent = 0); |
411 | + |
412 | + void run(); |
413 | + |
414 | +signals: |
415 | + void resultReady(NotesStore::ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results); |
416 | +}; |
417 | + |
418 | +#endif // FETCHNOTEBOOKSJOB_H |
419 | |
420 | === added file 'src/plugin/Evernote/jobs/fetchnotejob.cpp' |
421 | --- src/plugin/Evernote/jobs/fetchnotejob.cpp 1970-01-01 00:00:00 +0000 |
422 | +++ src/plugin/Evernote/jobs/fetchnotejob.cpp 2013-11-25 00:51:38 +0000 |
423 | @@ -0,0 +1,27 @@ |
424 | +#include "fetchnotejob.h" |
425 | + |
426 | +FetchNoteJob::FetchNoteJob(const QString &guid, QObject *parent) : |
427 | + EvernoteJob(parent), |
428 | + m_guid(guid) |
429 | +{ |
430 | +} |
431 | + |
432 | +void FetchNoteJob::run() |
433 | +{ |
434 | + NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; |
435 | + evernote::edam::Note result; |
436 | + try { |
437 | + client()->getNote(result, token().toStdString(), m_guid.toStdString(), true, true, false, false); |
438 | + } catch (evernote::edam::EDAMUserException) { |
439 | + errorCode = NotesStore::ErrorCodeUserException; |
440 | + } catch (evernote::edam::EDAMSystemException) { |
441 | + errorCode = NotesStore::ErrorCodeSystemException; |
442 | + } catch (evernote::edam::EDAMNotFoundException) { |
443 | + errorCode = NotesStore::ErrorCodeNotFoundExcpetion; |
444 | + } catch (...) { |
445 | + catchTransportException(); |
446 | + errorCode = NotesStore::ErrorCodeConnectionLost; |
447 | + } |
448 | + |
449 | + emit resultReady(errorCode, result); |
450 | +} |
451 | |
452 | === added file 'src/plugin/Evernote/jobs/fetchnotejob.h' |
453 | --- src/plugin/Evernote/jobs/fetchnotejob.h 1970-01-01 00:00:00 +0000 |
454 | +++ src/plugin/Evernote/jobs/fetchnotejob.h 2013-11-25 00:51:38 +0000 |
455 | @@ -0,0 +1,22 @@ |
456 | +#ifndef FETCHNOTEJOB_H |
457 | +#define FETCHNOTEJOB_H |
458 | + |
459 | +#include "evernotejob.h" |
460 | + |
461 | +class FetchNoteJob : public EvernoteJob |
462 | +{ |
463 | + Q_OBJECT |
464 | +public: |
465 | + explicit FetchNoteJob(const QString &guid, QObject *parent = 0); |
466 | + |
467 | + void run(); |
468 | +signals: |
469 | + void resultReady(NotesStore::ErrorCode error, const evernote::edam::Note ¬e); |
470 | + |
471 | +private: |
472 | + evernote::edam::NoteStoreClient *m_client; |
473 | + QString m_token; |
474 | + QString m_guid; |
475 | +}; |
476 | + |
477 | +#endif // FETCHNOTEJOB_H |
478 | |
479 | === added file 'src/plugin/Evernote/jobs/fetchnotesjob.cpp' |
480 | --- src/plugin/Evernote/jobs/fetchnotesjob.cpp 1970-01-01 00:00:00 +0000 |
481 | +++ src/plugin/Evernote/jobs/fetchnotesjob.cpp 2013-11-25 00:51:38 +0000 |
482 | @@ -0,0 +1,44 @@ |
483 | +#include "fetchnotesjob.h" |
484 | + |
485 | +#include "notesstore.h" |
486 | + |
487 | +#include <QDebug> |
488 | + |
489 | +FetchNotesJob::FetchNotesJob( const QString &filterNotebookGuid, QObject *parent) : |
490 | + EvernoteJob(parent), |
491 | + m_filterNotebookGuid(filterNotebookGuid) |
492 | +{ |
493 | +} |
494 | + |
495 | +void FetchNotesJob::run() |
496 | +{ |
497 | + // TODO: fix start/end (use smaller chunks and continue fetching if there are more notes available) |
498 | + int32_t start = 0; |
499 | + int32_t end = 10000; |
500 | + |
501 | + // Prepare filter |
502 | + evernote::edam::NoteFilter filter; |
503 | + filter.notebookGuid = m_filterNotebookGuid.toStdString(); |
504 | + filter.__isset.notebookGuid = !m_filterNotebookGuid.isEmpty(); |
505 | + |
506 | + // Prepare ResultSpec |
507 | + evernote::edam::NotesMetadataResultSpec resultSpec; |
508 | + resultSpec.includeNotebookGuid = true; |
509 | + resultSpec.__isset.includeNotebookGuid = true; |
510 | + resultSpec.includeTitle = true; |
511 | + resultSpec.__isset.includeTitle = true; |
512 | + |
513 | + NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; |
514 | + evernote::edam::NotesMetadataList results; |
515 | + |
516 | + try { |
517 | + client()->findNotesMetadata(results, token().toStdString(), filter, start, end, resultSpec); |
518 | + } catch(evernote::edam::EDAMUserException) { |
519 | + errorCode = NotesStore::ErrorCodeUserException; |
520 | + } catch(evernote::edam::EDAMSystemException) { |
521 | + errorCode = NotesStore::ErrorCodeSystemException; |
522 | + } catch(evernote::edam::EDAMNotFoundException) { |
523 | + errorCode = NotesStore::ErrorCodeNotFoundExcpetion; |
524 | + } |
525 | + emit resultReady(errorCode, results); |
526 | +} |
527 | |
528 | === added file 'src/plugin/Evernote/jobs/fetchnotesjob.h' |
529 | --- src/plugin/Evernote/jobs/fetchnotesjob.h 1970-01-01 00:00:00 +0000 |
530 | +++ src/plugin/Evernote/jobs/fetchnotesjob.h 2013-11-25 00:51:38 +0000 |
531 | @@ -0,0 +1,21 @@ |
532 | +#ifndef FETCHNOTESJOB_H |
533 | +#define FETCHNOTESJOB_H |
534 | + |
535 | +#include "evernotejob.h" |
536 | + |
537 | +class FetchNotesJob : public EvernoteJob |
538 | +{ |
539 | + Q_OBJECT |
540 | +public: |
541 | + explicit FetchNotesJob(const QString &filterNotebookGuid, QObject *parent = 0); |
542 | + |
543 | + void run(); |
544 | + |
545 | +signals: |
546 | + void resultReady(NotesStore::ErrorCode errorCode, const evernote::edam::NotesMetadataList &results); |
547 | + |
548 | +private: |
549 | + QString m_filterNotebookGuid; |
550 | +}; |
551 | + |
552 | +#endif // FETCHNOTESJOB_H |
553 | |
554 | === added file 'src/plugin/Evernote/jobs/savenotejob.cpp' |
555 | --- src/plugin/Evernote/jobs/savenotejob.cpp 1970-01-01 00:00:00 +0000 |
556 | +++ src/plugin/Evernote/jobs/savenotejob.cpp 2013-11-25 00:51:38 +0000 |
557 | @@ -0,0 +1,40 @@ |
558 | +#include "savenotejob.h" |
559 | +#include "note.h" |
560 | + |
561 | +#include <QDebug> |
562 | + |
563 | +SaveNoteJob::SaveNoteJob(Note *note, QObject *parent) : |
564 | + EvernoteJob(parent), |
565 | + m_note(note) |
566 | +{ |
567 | +} |
568 | + |
569 | +void SaveNoteJob::run() |
570 | +{ |
571 | + NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; |
572 | + try { |
573 | + evernote::edam::Note note; |
574 | + note.guid = m_note->guid().toStdString(); |
575 | + note.__isset.guid = true; |
576 | + note.title = m_note->title().toStdString(); |
577 | + note.__isset.title = true; |
578 | + note.notebookGuid = m_note->notebookGuid().toStdString(); |
579 | + note.__isset.notebookGuid = true; |
580 | + note.content = m_note->content().toStdString(); |
581 | + note.__isset.content = true; |
582 | + note.contentLength = m_note->content().length(); |
583 | + |
584 | + client()->updateNote(note, token().toStdString(), note); |
585 | + |
586 | + } catch (evernote::edam::EDAMUserException e) { |
587 | + errorCode = NotesStore::ErrorCodeUserException; |
588 | + qDebug() << QString::fromStdString(e.parameter); |
589 | + } catch (evernote::edam::EDAMSystemException) { |
590 | + errorCode = NotesStore::ErrorCodeSystemException; |
591 | + } catch (...) { |
592 | + catchTransportException(); |
593 | + errorCode = NotesStore::ErrorCodeConnectionLost; |
594 | + } |
595 | + |
596 | + emit resultReady(errorCode, m_note); |
597 | +} |
598 | |
599 | === added file 'src/plugin/Evernote/jobs/savenotejob.h' |
600 | --- src/plugin/Evernote/jobs/savenotejob.h 1970-01-01 00:00:00 +0000 |
601 | +++ src/plugin/Evernote/jobs/savenotejob.h 2013-11-25 00:51:38 +0000 |
602 | @@ -0,0 +1,20 @@ |
603 | +#ifndef SAVENOTEJOB_H |
604 | +#define SAVENOTEJOB_H |
605 | + |
606 | +#include "evernotejob.h" |
607 | + |
608 | +class SaveNoteJob : public EvernoteJob |
609 | +{ |
610 | + Q_OBJECT |
611 | +public: |
612 | + explicit SaveNoteJob(Note *note, QObject *parent = 0); |
613 | + |
614 | + void run(); |
615 | +signals: |
616 | + void resultReady(NotesStore::ErrorCode errorCode, Note *note); |
617 | + |
618 | +private: |
619 | + Note *m_note; |
620 | +}; |
621 | + |
622 | +#endif // SAVENOTEJOB_H |
623 | |
624 | === added file 'src/plugin/Evernote/note.cpp' |
625 | --- src/plugin/Evernote/note.cpp 1970-01-01 00:00:00 +0000 |
626 | +++ src/plugin/Evernote/note.cpp 2013-11-25 00:51:38 +0000 |
627 | @@ -0,0 +1,71 @@ |
628 | +#include "note.h" |
629 | + |
630 | +#include "notesstore.h" |
631 | + |
632 | +Note::Note(const QString &guid, QObject *parent) : |
633 | + QObject(parent), |
634 | + m_guid(guid) |
635 | +{ |
636 | +} |
637 | + |
638 | +QString Note::guid() const |
639 | +{ |
640 | + return m_guid; |
641 | +} |
642 | + |
643 | +void Note::setGuid(const QString &guid) |
644 | +{ |
645 | + if (m_guid == guid) { |
646 | + m_guid = guid; |
647 | + emit guidChanged(); |
648 | + } |
649 | +} |
650 | + |
651 | +QString Note::notebookGuid() const |
652 | +{ |
653 | + return m_notebookGuid; |
654 | +} |
655 | + |
656 | +void Note::setNotebookGuid(const QString ¬ebookGuid) |
657 | +{ |
658 | + if (m_notebookGuid != notebookGuid) { |
659 | + m_notebookGuid = notebookGuid; |
660 | + emit notebookGuidChanged(); |
661 | + } |
662 | +} |
663 | + |
664 | +QString Note::title() const |
665 | +{ |
666 | + return m_title; |
667 | +} |
668 | + |
669 | +void Note::setTitle(const QString &title) |
670 | +{ |
671 | + if (m_title != title) { |
672 | + m_title = title; |
673 | + emit titleChanged(); |
674 | + } |
675 | +} |
676 | + |
677 | +QString Note::content() const |
678 | +{ |
679 | + return m_content; |
680 | +} |
681 | + |
682 | +void Note::setContent(const QString &content) |
683 | +{ |
684 | + if (m_content != content) { |
685 | + m_content = content; |
686 | + emit contentChanged(); |
687 | + } |
688 | +} |
689 | + |
690 | +void Note::save() |
691 | +{ |
692 | + NotesStore::instance()->saveNote(m_guid); |
693 | +} |
694 | + |
695 | +void Note::remove() |
696 | +{ |
697 | + NotesStore::instance()->deleteNote(m_guid); |
698 | +} |
699 | |
700 | === added file 'src/plugin/Evernote/note.h' |
701 | --- src/plugin/Evernote/note.h 1970-01-01 00:00:00 +0000 |
702 | +++ src/plugin/Evernote/note.h 2013-11-25 00:51:38 +0000 |
703 | @@ -0,0 +1,46 @@ |
704 | +#ifndef NOTE_H |
705 | +#define NOTE_H |
706 | + |
707 | +#include <QObject> |
708 | + |
709 | +class Note : public QObject |
710 | +{ |
711 | + Q_OBJECT |
712 | + |
713 | + Q_PROPERTY(QString guid READ guid NOTIFY guidChanged) |
714 | + Q_PROPERTY(QString notebookGuid READ notebookGuid WRITE setNotebookGuid NOTIFY notebookGuidChanged) |
715 | + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) |
716 | + Q_PROPERTY(QString content READ content WRITE setContent NOTIFY contentChanged) |
717 | +public: |
718 | + explicit Note(const QString &guid = QString(), QObject *parent = 0); |
719 | + |
720 | + QString guid() const; |
721 | + void setGuid(const QString &guid); |
722 | + |
723 | + QString notebookGuid() const; |
724 | + void setNotebookGuid(const QString ¬ebookGuid); |
725 | + |
726 | + QString title() const; |
727 | + void setTitle(const QString &title); |
728 | + |
729 | + QString content() const; |
730 | + void setContent(const QString &content); |
731 | + |
732 | +public slots: |
733 | + void save(); |
734 | + void remove(); |
735 | + |
736 | +signals: |
737 | + void guidChanged(); |
738 | + void titleChanged(); |
739 | + void notebookGuidChanged(); |
740 | + void contentChanged(); |
741 | + |
742 | +private: |
743 | + QString m_guid; |
744 | + QString m_notebookGuid; |
745 | + QString m_title; |
746 | + QString m_content; |
747 | +}; |
748 | + |
749 | +#endif // NOTE_H |
750 | |
751 | === added file 'src/plugin/Evernote/notebook.cpp' |
752 | --- src/plugin/Evernote/notebook.cpp 1970-01-01 00:00:00 +0000 |
753 | +++ src/plugin/Evernote/notebook.cpp 2013-11-25 00:51:38 +0000 |
754 | @@ -0,0 +1,25 @@ |
755 | +#include "notebook.h" |
756 | + |
757 | +Notebook::Notebook(QString guid, QObject *parent) : |
758 | + QObject(parent), |
759 | + m_guid(guid) |
760 | +{ |
761 | +} |
762 | + |
763 | +QString Notebook::guid() const |
764 | +{ |
765 | + return m_guid; |
766 | +} |
767 | + |
768 | +QString Notebook::name() const |
769 | +{ |
770 | + return m_name; |
771 | +} |
772 | + |
773 | +void Notebook::setName(const QString &name) |
774 | +{ |
775 | + if (m_name != name) { |
776 | + m_name = name; |
777 | + emit nameChanged(); |
778 | + } |
779 | +} |
780 | |
781 | === added file 'src/plugin/Evernote/notebook.h' |
782 | --- src/plugin/Evernote/notebook.h 1970-01-01 00:00:00 +0000 |
783 | +++ src/plugin/Evernote/notebook.h 2013-11-25 00:51:38 +0000 |
784 | @@ -0,0 +1,30 @@ |
785 | +#ifndef NOTEBOOK_H |
786 | +#define NOTEBOOK_H |
787 | + |
788 | +#include <QObject> |
789 | + |
790 | +class Notebook : public QObject |
791 | +{ |
792 | + Q_OBJECT |
793 | + |
794 | + Q_PROPERTY(QString guid READ guid CONSTANT) |
795 | + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
796 | +public: |
797 | + explicit Notebook(QString guid, QObject *parent = 0); |
798 | + |
799 | + QString guid() const; |
800 | + |
801 | + QString name() const; |
802 | + void setName(const QString &name); |
803 | + |
804 | +signals: |
805 | + void nameChanged(); |
806 | + |
807 | +public slots: |
808 | + |
809 | +private: |
810 | + QString m_guid; |
811 | + QString m_name; |
812 | +}; |
813 | + |
814 | +#endif // NOTEBOOK_H |
815 | |
816 | === modified file 'src/plugin/Evernote/notebooks.cpp' |
817 | --- src/plugin/Evernote/notebooks.cpp 2013-11-21 23:30:15 +0000 |
818 | +++ src/plugin/Evernote/notebooks.cpp 2013-11-25 00:51:38 +0000 |
819 | @@ -1,27 +1,34 @@ |
820 | #include "notebooks.h" |
821 | +#include "notebook.h" |
822 | |
823 | #include <QDebug> |
824 | |
825 | Notebooks::Notebooks(QObject *parent) : |
826 | QAbstractListModel(parent) |
827 | { |
828 | + foreach (Notebook *notebook, NotesStore::instance()->notebooks()) { |
829 | + m_list.append(notebook->guid()); |
830 | + } |
831 | + |
832 | + connect(NotesStore::instance(), SIGNAL(notebookAdded(const QString &)), SLOT(notebookAdded(const QString &))); |
833 | } |
834 | |
835 | QVariant Notebooks::data(const QModelIndex &index, int role) const |
836 | { |
837 | + |
838 | + Notebook *notebook = NotesStore::instance()->notebook(m_list.at(index.row())); |
839 | switch(role) { |
840 | case RoleGuid: |
841 | - return QString::fromStdString(m_list.at(index.row()).guid); |
842 | + return notebook->guid(); |
843 | case RoleName: |
844 | - return QString::fromStdString(m_list.at(index.row()).name); |
845 | + return notebook->name(); |
846 | } |
847 | - |
848 | return QVariant(); |
849 | } |
850 | |
851 | int Notebooks::rowCount(const QModelIndex &parent) const |
852 | { |
853 | - return m_list.size(); |
854 | + return m_list.count(); |
855 | } |
856 | |
857 | QHash<int, QByteArray> Notebooks::roleNames() const |
858 | @@ -34,25 +41,12 @@ |
859 | |
860 | void Notebooks::refresh() |
861 | { |
862 | - |
863 | - QString token = NotesStore::instance()->token(); |
864 | - if (token.isEmpty()) { |
865 | - qDebug() << "No token set. Cannot fetch notebooks."; |
866 | - return; |
867 | - } |
868 | - |
869 | - beginResetModel(); |
870 | - try { |
871 | - NotesStore::instance()->evernoteNotesStoreClient()->listNotebooks(m_list, token.toStdString()); |
872 | - } catch(...) { |
873 | - qDebug() << "Error fetching notebooks."; |
874 | -// displayException(); |
875 | - } |
876 | - |
877 | - endResetModel(); |
878 | - |
879 | -// for (int i = 0; i < notebooks.size(); ++i) { |
880 | -// qDebug() << "got notebooks" << QString::fromStdString(notebooks.at(i).name) << QString::fromStdString(notebooks.at(i).name) |
881 | -// << QString::fromStdString(notebooks.at(i).guid); |
882 | -// } |
883 | + NotesStore::instance()->refreshNotebooks(); |
884 | +} |
885 | + |
886 | +void Notebooks::notebookAdded(const QString &guid) |
887 | +{ |
888 | + beginInsertRows(QModelIndex(), m_list.count(), m_list.count()); |
889 | + m_list.append(guid); |
890 | + endInsertRows(); |
891 | } |
892 | |
893 | === modified file 'src/plugin/Evernote/notebooks.h' |
894 | --- src/plugin/Evernote/notebooks.h 2013-11-21 23:30:15 +0000 |
895 | +++ src/plugin/Evernote/notebooks.h 2013-11-25 00:51:38 +0000 |
896 | @@ -5,8 +5,6 @@ |
897 | |
898 | #include <QAbstractListModel> |
899 | |
900 | -using namespace evernote::edam; |
901 | - |
902 | class Notebooks : public QAbstractListModel |
903 | { |
904 | Q_OBJECT |
905 | @@ -24,10 +22,11 @@ |
906 | public slots: |
907 | void refresh(); |
908 | |
909 | +private slots: |
910 | + void notebookAdded(const QString &guid); |
911 | + |
912 | private: |
913 | - std::vector<Notebook> m_list; |
914 | - |
915 | - |
916 | + QList<QString> m_list; |
917 | }; |
918 | |
919 | #endif // NOTEBOOKS_H |
920 | |
921 | === modified file 'src/plugin/Evernote/notes.cpp' |
922 | --- src/plugin/Evernote/notes.cpp 2013-11-21 23:30:15 +0000 |
923 | +++ src/plugin/Evernote/notes.cpp 2013-11-25 00:51:38 +0000 |
924 | @@ -1,19 +1,24 @@ |
925 | #include "notes.h" |
926 | +#include "note.h" |
927 | |
928 | #include <QDebug> |
929 | |
930 | Notes::Notes(QObject *parent) : |
931 | QAbstractListModel(parent) |
932 | { |
933 | + connect(NotesStore::instance(), &NotesStore::noteAdded, this, &Notes::noteAdded); |
934 | + connect(NotesStore::instance(), &NotesStore::noteRemoved, this, &Notes::noteRemoved); |
935 | + connect(NotesStore::instance(), &NotesStore::noteChanged, this, &Notes::noteChanged); |
936 | } |
937 | |
938 | QVariant Notes::data(const QModelIndex &index, int role) const |
939 | { |
940 | + Note *note = NotesStore::instance()->note(m_list.at(index.row())); |
941 | switch(role) { |
942 | case RoleGuid: |
943 | - return QString::fromStdString(m_list.at(index.row()).guid); |
944 | + return note->guid(); |
945 | case RoleTitle: |
946 | - return QString::fromStdString(m_list.at(index.row()).title); |
947 | + return note->title(); |
948 | } |
949 | |
950 | return QVariant(); |
951 | @@ -45,59 +50,50 @@ |
952 | } |
953 | } |
954 | |
955 | -QString Notes::note(const QString ¬eGuid) |
956 | -{ |
957 | - QString token = NotesStore::instance()->token(); |
958 | - if (token.isEmpty()) { |
959 | - qDebug() << "No token set. Cannot fetch note."; |
960 | - return QString(); |
961 | - } |
962 | - |
963 | - Note note; |
964 | - try { |
965 | - NotesStore::instance()->evernoteNotesStoreClient()->getNote(note, token.toStdString(), noteGuid.toStdString(), true, true, false, false); |
966 | - } catch(...) { |
967 | - qDebug() << "error fetching note"; |
968 | - return QString(); |
969 | - } |
970 | - |
971 | - return QString::fromStdString(note.content); |
972 | +Note* Notes::note(const QString &guid) |
973 | +{ |
974 | + NotesStore::instance()->refreshNoteContent(guid); |
975 | + return NotesStore::instance()->note(guid); |
976 | +} |
977 | + |
978 | +void Notes::componentComplete() |
979 | +{ |
980 | + foreach (Note *note, NotesStore::instance()->notes()) { |
981 | + if (m_filterNotebookGuid.isEmpty() || note->notebookGuid() == m_filterNotebookGuid) { |
982 | + m_list.append(note->guid()); |
983 | + } |
984 | + } |
985 | + beginInsertRows(QModelIndex(), 0, m_list.count() - 1); |
986 | + endInsertRows(); |
987 | + refresh(); |
988 | } |
989 | |
990 | void Notes::refresh() |
991 | { |
992 | - QString token = NotesStore::instance()->token(); |
993 | - if (token.isEmpty()) { |
994 | - qDebug() << "No token set. Cannot fetch notes."; |
995 | - return; |
996 | - } |
997 | - |
998 | - int32_t start = 0; |
999 | - int32_t end = 10000; |
1000 | - |
1001 | - // Prepare filter |
1002 | - NoteFilter filter; |
1003 | - filter.notebookGuid = m_filterNotebookGuid.toStdString(); |
1004 | - filter.__isset.notebookGuid = !m_filterNotebookGuid.isEmpty(); |
1005 | - |
1006 | - // Prepare ResultSpec |
1007 | - NotesMetadataResultSpec resultSpec; |
1008 | - resultSpec.includeTitle = true; |
1009 | - resultSpec.__isset.includeTitle = true; |
1010 | - |
1011 | - NotesMetadataList notes; |
1012 | - try { |
1013 | - NotesStore::instance()->evernoteNotesStoreClient()->findNotesMetadata(notes, token.toStdString(), filter, start, end, resultSpec); |
1014 | - } catch(...) { |
1015 | - qDebug() << "error fetching notes"; |
1016 | - return; |
1017 | - } |
1018 | - |
1019 | - beginResetModel(); |
1020 | - m_list.clear(); |
1021 | - foreach (NoteMetadata note, notes.notes) { |
1022 | - m_list.append(note); |
1023 | - qDebug() << QString::fromStdString(note.guid) << QString::fromStdString(note.title); |
1024 | - } |
1025 | - endResetModel(); |
1026 | + NotesStore::instance()->refreshNotes(m_filterNotebookGuid); |
1027 | +} |
1028 | + |
1029 | +void Notes::noteAdded(const QString &guid) |
1030 | +{ |
1031 | + beginInsertRows(QModelIndex(), m_list.count(), m_list.count()); |
1032 | + m_list.append(guid); |
1033 | + endInsertRows(); |
1034 | +} |
1035 | + |
1036 | +void Notes::noteChanged(const QString &guid) |
1037 | +{ |
1038 | + int row = m_list.indexOf(guid); |
1039 | + if (row >= 0) { |
1040 | + emit dataChanged(index(row), index(row)); |
1041 | + } |
1042 | +} |
1043 | + |
1044 | +void Notes::noteRemoved(const QString &guid) |
1045 | +{ |
1046 | + int index = m_list.indexOf(guid); |
1047 | + if (index >= 0) { |
1048 | + beginRemoveRows(QModelIndex(), index, index); |
1049 | + m_list.removeAt(index); |
1050 | + endRemoveRows(); |
1051 | + } |
1052 | } |
1053 | |
1054 | === modified file 'src/plugin/Evernote/notes.h' |
1055 | --- src/plugin/Evernote/notes.h 2013-11-21 23:30:15 +0000 |
1056 | +++ src/plugin/Evernote/notes.h 2013-11-25 00:51:38 +0000 |
1057 | @@ -4,10 +4,9 @@ |
1058 | #include "notesstore.h" |
1059 | |
1060 | #include <QAbstractListModel> |
1061 | - |
1062 | -using namespace evernote::edam; |
1063 | - |
1064 | -class Notes : public QAbstractListModel |
1065 | +#include <QQmlParserStatus> |
1066 | + |
1067 | +class Notes : public QAbstractListModel, public QQmlParserStatus |
1068 | { |
1069 | Q_OBJECT |
1070 | Q_PROPERTY(QString filterNotebookGuid READ filterNotebookGuid WRITE setFilterNotebookGuid NOTIFY filterNotebookGuidChanged) |
1071 | @@ -25,16 +24,24 @@ |
1072 | QString filterNotebookGuid() const; |
1073 | void setFilterNotebookGuid(const QString ¬ebookGuid); |
1074 | |
1075 | - Q_INVOKABLE QString note(const QString ¬eGuid); |
1076 | + Q_INVOKABLE Note* note(const QString &guid); |
1077 | + |
1078 | + void classBegin() {} |
1079 | + void componentComplete(); |
1080 | |
1081 | public slots: |
1082 | void refresh(); |
1083 | |
1084 | +private slots: |
1085 | + void noteAdded(const QString &guid); |
1086 | + void noteChanged(const QString &guid); |
1087 | + void noteRemoved(const QString &guid); |
1088 | + |
1089 | signals: |
1090 | void filterNotebookGuidChanged(); |
1091 | |
1092 | private: |
1093 | - QList<NoteMetadata> m_list; |
1094 | + QList<QString> m_list; |
1095 | QString m_filterNotebookGuid; |
1096 | |
1097 | }; |
1098 | |
1099 | === modified file 'src/plugin/Evernote/notesstore.cpp' |
1100 | --- src/plugin/Evernote/notesstore.cpp 2013-11-21 23:30:15 +0000 |
1101 | +++ src/plugin/Evernote/notesstore.cpp 2013-11-25 00:51:38 +0000 |
1102 | @@ -1,6 +1,14 @@ |
1103 | #include "notesstore.h" |
1104 | - |
1105 | #include "notebooks.h" |
1106 | +#include "notebook.h" |
1107 | +#include "note.h" |
1108 | + |
1109 | +#include "jobs/fetchnotesjob.h" |
1110 | +#include "jobs/fetchnotebooksjob.h" |
1111 | +#include "jobs/fetchnotejob.h" |
1112 | +#include "jobs/createnotejob.h" |
1113 | +#include "jobs/savenotejob.h" |
1114 | +#include "jobs/deletenotejob.h" |
1115 | |
1116 | // Thrift |
1117 | #include <arpa/inet.h> // seems thrift forgot this one |
1118 | @@ -11,7 +19,6 @@ |
1119 | |
1120 | #include <QDebug> |
1121 | |
1122 | -using namespace evernote::edam; |
1123 | using namespace apache::thrift; |
1124 | using namespace apache::thrift::protocol; |
1125 | using namespace apache::thrift::transport; |
1126 | @@ -19,11 +26,10 @@ |
1127 | NotesStore* NotesStore::s_instance = 0; |
1128 | |
1129 | NotesStore::NotesStore(QObject *parent) : |
1130 | - QObject(parent) |
1131 | + QObject(parent), |
1132 | + m_currentJob(0) |
1133 | { |
1134 | try { |
1135 | - // TODO: Move this to a common place instead of keeping a copy here and in UserStore |
1136 | - |
1137 | // FIXME: need to populate this string from the system |
1138 | // The structure should be: |
1139 | // application/version; platform/version; [ device/version ] |
1140 | @@ -54,13 +60,21 @@ |
1141 | userStoreHttpClient->open(); |
1142 | |
1143 | boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(userStoreHttpClient)); |
1144 | - m_client = new NoteStoreClient(iprot); |
1145 | + m_client = new evernote::edam::NoteStoreClient(iprot); |
1146 | |
1147 | qDebug() << "NoteStore client created."; |
1148 | - } catch(...) { |
1149 | - displayException(); |
1150 | + |
1151 | + } catch (const TTransportException & e) { |
1152 | + qWarning() << "Failed to create Transport:" << e.what(); |
1153 | + } catch (const TException & e) { |
1154 | + qWarning() << "Generic Thrift exception:" << e.what(); |
1155 | } |
1156 | |
1157 | + qRegisterMetaType<NotesStore::ErrorCode>("NotesStore::ErrorCode"); |
1158 | + qRegisterMetaType<evernote::edam::NotesMetadataList>("evernote::edam::NotesMetadataList"); |
1159 | + qRegisterMetaType<evernote::edam::Note>("evernote::edam::Note"); |
1160 | + qRegisterMetaType<std::vector<evernote::edam::Notebook> >("std::vector<evernote::edam::Notebook>"); |
1161 | + |
1162 | } |
1163 | |
1164 | NotesStore *NotesStore::instance() |
1165 | @@ -71,6 +85,21 @@ |
1166 | return s_instance; |
1167 | } |
1168 | |
1169 | +QString NotesStore::errorCodeToString(NotesStore::ErrorCode errorCode) |
1170 | +{ |
1171 | + switch(errorCode) { |
1172 | + case ErrorCodeNoError: |
1173 | + return QStringLiteral("No error"); |
1174 | + case ErrorCodeUserException: |
1175 | + return QStringLiteral("User exception"); |
1176 | + case ErrorCodeSystemException: |
1177 | + return QStringLiteral("System exception"); |
1178 | + case ErrorCodeNotFoundExcpetion: |
1179 | + return QStringLiteral("Not found"); |
1180 | + } |
1181 | + return QString(); |
1182 | +} |
1183 | + |
1184 | NotesStore::~NotesStore() |
1185 | { |
1186 | delete m_client; |
1187 | @@ -84,56 +113,223 @@ |
1188 | void NotesStore::setToken(const QString &token) |
1189 | { |
1190 | if (token != m_token) { |
1191 | - qDebug() << "NotesStore: setting token:" << token; |
1192 | m_token = token; |
1193 | emit tokenChanged(); |
1194 | - } |
1195 | -} |
1196 | - |
1197 | -NoteStoreClient *NotesStore::evernoteNotesStoreClient() |
1198 | -{ |
1199 | - return m_client; |
1200 | -} |
1201 | - |
1202 | -// TODO: move to a common place instead of copying it through *store.cpps |
1203 | -void NotesStore::displayException() |
1204 | -{ |
1205 | - QString error_message = "Unknown Exception"; |
1206 | - try |
1207 | - { |
1208 | - // this function is meant to be called from a catch block |
1209 | - // rethrow the exception to catch it again |
1210 | - throw; |
1211 | - } |
1212 | - catch (const EDAMNotFoundException & e) |
1213 | - { |
1214 | - qDebug() << e.what(); |
1215 | - } |
1216 | - catch (const EDAMSystemException & e) |
1217 | - { |
1218 | - qDebug() << e.what(); |
1219 | - } |
1220 | - catch (const EDAMUserException & e) |
1221 | - { |
1222 | - qDebug() << e.what(); |
1223 | - } |
1224 | - catch (const TTransportException & e) |
1225 | - { |
1226 | - qDebug() << e.what(); |
1227 | - } |
1228 | - catch (const TException & e) |
1229 | - { |
1230 | - qDebug() << e.what(); |
1231 | - } |
1232 | - catch (const std::exception & e) |
1233 | - { |
1234 | - qDebug() << e.what(); |
1235 | - } |
1236 | - catch (...) |
1237 | - { |
1238 | - error_message = "Tried to sync, but something went wrong.\n Unknown exception."; |
1239 | - } |
1240 | - |
1241 | - qDebug() << error_message; |
1242 | - disconnect(); |
1243 | -} |
1244 | + refreshNotebooks(); |
1245 | + refreshNotes(); |
1246 | + } |
1247 | +} |
1248 | + |
1249 | +QList<Note*> NotesStore::notes() const |
1250 | +{ |
1251 | + return m_notes.values(); |
1252 | +} |
1253 | + |
1254 | +Note *NotesStore::note(const QString &guid) |
1255 | +{ |
1256 | + return m_notes.value(guid); |
1257 | +} |
1258 | + |
1259 | +void NotesStore::saveNote(const QString &guid) |
1260 | +{ |
1261 | + Note *note = m_notes.value(guid); |
1262 | + SaveNoteJob *job = new SaveNoteJob(note, this); |
1263 | + connect(job, &SaveNoteJob::resultReady, this, &NotesStore::saveNoteJobDone); |
1264 | + m_jobQueue.append(job); |
1265 | + startJobQueue(); |
1266 | +} |
1267 | + |
1268 | +void NotesStore::deleteNote(const QString &guid) |
1269 | +{ |
1270 | + DeleteNoteJob *job = new DeleteNoteJob(guid, this); |
1271 | + connect(job, &DeleteNoteJob::resultReady, this, &NotesStore::deleteNoteJobDone); |
1272 | + m_jobQueue.append(job); |
1273 | + startJobQueue(); |
1274 | +} |
1275 | + |
1276 | +QList<Notebook *> NotesStore::notebooks() const |
1277 | +{ |
1278 | + return m_notebooks.values(); |
1279 | +} |
1280 | + |
1281 | +Notebook *NotesStore::notebook(const QString &guid) |
1282 | +{ |
1283 | + return m_notebooks.value(guid); |
1284 | +} |
1285 | + |
1286 | +void NotesStore::startJobQueue() |
1287 | +{ |
1288 | + if (m_jobQueue.isEmpty()) { |
1289 | + return; |
1290 | + } |
1291 | + |
1292 | + if (m_currentJob) { |
1293 | + return; |
1294 | + } |
1295 | + m_currentJob = m_jobQueue.takeFirst(); |
1296 | + m_currentJob->start(); |
1297 | +} |
1298 | + |
1299 | +void NotesStore::startNextJob() |
1300 | +{ |
1301 | + m_currentJob = 0; |
1302 | + startJobQueue(); |
1303 | +} |
1304 | + |
1305 | +void NotesStore::refreshNotes(const QString &filterNotebookGuid) |
1306 | +{ |
1307 | + if (m_token.isEmpty()) { |
1308 | + qWarning() << "No token set. Cannot fetch notes."; |
1309 | + return; |
1310 | + } |
1311 | + |
1312 | + FetchNotesJob *job = new FetchNotesJob(filterNotebookGuid); |
1313 | + connect(job, &FetchNotesJob::resultReady, this, &NotesStore::fetchNotesJobDone); |
1314 | + |
1315 | + m_jobQueue.append(job); |
1316 | + startJobQueue(); |
1317 | +} |
1318 | + |
1319 | +void NotesStore::fetchNotesJobDone(ErrorCode errorCode, const evernote::edam::NotesMetadataList &results) |
1320 | +{ |
1321 | + if (errorCode != ErrorCodeNoError) { |
1322 | + qWarning() << "Failed to fetch notes list:" << errorCodeToString(errorCode); |
1323 | + startNextJob(); |
1324 | + return; |
1325 | + } |
1326 | + |
1327 | + for (int i = 0; i < results.notes.size(); ++i) { |
1328 | + evernote::edam::NoteMetadata result = results.notes.at(i); |
1329 | + Note *note = m_notes.value(QString::fromStdString(result.guid)); |
1330 | + if (note) { |
1331 | + note->setTitle(QString::fromStdString(result.title)); |
1332 | + note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); |
1333 | + emit noteChanged(note->guid()); |
1334 | + } else { |
1335 | + note = new Note(QString::fromStdString(result.guid), this); |
1336 | + note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); |
1337 | + note->setTitle(QString::fromStdString(result.title)); |
1338 | + m_notes.insert(note->guid(), note); |
1339 | + emit noteAdded(note->guid()); |
1340 | + } |
1341 | + } |
1342 | + |
1343 | + startNextJob(); |
1344 | +} |
1345 | + |
1346 | +void NotesStore::refreshNoteContent(const QString &guid) |
1347 | +{ |
1348 | + if (m_token.isEmpty()) { |
1349 | + qWarning() << "No token set. Cannot fetch note."; |
1350 | + return; |
1351 | + } |
1352 | + |
1353 | + FetchNoteJob *job = new FetchNoteJob(guid, this); |
1354 | + connect(job, &FetchNoteJob::resultReady, this, &NotesStore::fetchNoteJobDone); |
1355 | + m_jobQueue.append(job); |
1356 | + |
1357 | + startJobQueue(); |
1358 | +} |
1359 | + |
1360 | +void NotesStore::fetchNoteJobDone(ErrorCode errorCode, const evernote::edam::Note &result) |
1361 | +{ |
1362 | + if (errorCode != ErrorCodeNoError) { |
1363 | + qWarning() << "Error fetching note:" << errorCode; |
1364 | + startNextJob(); |
1365 | + return; |
1366 | + } |
1367 | + |
1368 | + Note *note = m_notes.value(QString::fromStdString(result.guid)); |
1369 | + note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); |
1370 | + note->setTitle(QString::fromStdString(result.title)); |
1371 | + note->setContent(QString::fromStdString(result.content)); |
1372 | + emit noteChanged(note->guid()); |
1373 | + |
1374 | + startNextJob(); |
1375 | +} |
1376 | + |
1377 | +void NotesStore::refreshNotebooks() |
1378 | +{ |
1379 | + if (m_token.isEmpty()) { |
1380 | + qWarning() << "No token set. Cannot refresh notebooks."; |
1381 | + return; |
1382 | + } |
1383 | + |
1384 | + FetchNotebooksJob *job = new FetchNotebooksJob(); |
1385 | + connect(job, &FetchNotebooksJob::resultReady, this, &NotesStore::fetchNotebooksJobDone); |
1386 | + |
1387 | + m_jobQueue.append(job); |
1388 | + startJobQueue(); |
1389 | +} |
1390 | + |
1391 | +void NotesStore::fetchNotebooksJobDone(ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results) |
1392 | +{ |
1393 | + if (errorCode != ErrorCodeNoError) { |
1394 | + qWarning() << "Error fetching notebooks:" << errorCodeToString(errorCode); |
1395 | + startNextJob(); |
1396 | + return; |
1397 | + } |
1398 | + |
1399 | + for (int i = 0; i < results.size(); ++i) { |
1400 | + evernote::edam::Notebook result = results.at(i); |
1401 | + Notebook *notebook = m_notebooks.value(QString::fromStdString(result.guid)); |
1402 | + if (notebook) { |
1403 | + qDebug() << "got notebook update"; |
1404 | + notebook->setName(QString::fromStdString(result.name)); |
1405 | + emit notebookChanged(notebook->guid()); |
1406 | + } else { |
1407 | + notebook = new Notebook(QString::fromStdString(result.guid), this); |
1408 | + notebook->setName(QString::fromStdString(result.name)); |
1409 | + m_notebooks.insert(notebook->guid(), notebook); |
1410 | + emit notebookAdded(notebook->guid()); |
1411 | + qDebug() << "got new notebook" << notebook->guid(); |
1412 | + } |
1413 | + } |
1414 | + |
1415 | + startNextJob(); |
1416 | +} |
1417 | + |
1418 | +void NotesStore::createNote(const QString &title, const QString ¬ebookGuid, const QString &content) |
1419 | +{ |
1420 | + Note *note = new Note(); |
1421 | + note->setTitle(title); |
1422 | + note->setNotebookGuid(notebookGuid); |
1423 | + note->setContent(content); |
1424 | + CreateNoteJob *job = new CreateNoteJob(note); |
1425 | + connect(job, &CreateNoteJob::resultReady, this, &NotesStore::createNoteJobDone); |
1426 | + |
1427 | + m_jobQueue.append(job); |
1428 | + startJobQueue(); |
1429 | +} |
1430 | + |
1431 | +void NotesStore::createNoteJobDone(NotesStore::ErrorCode errorCode, Note *note) |
1432 | +{ |
1433 | + if (errorCode != ErrorCodeNoError) { |
1434 | + qWarning() << "Error creating note:" << errorCodeToString(errorCode); |
1435 | + delete note; |
1436 | + startNextJob(); |
1437 | + return; |
1438 | + } |
1439 | + |
1440 | + m_notes.insert(note->guid(), note); |
1441 | + noteAdded(note->guid()); |
1442 | + startNextJob(); |
1443 | +} |
1444 | + |
1445 | +void NotesStore::saveNoteJobDone(NotesStore::ErrorCode errorCode, Note *note) |
1446 | +{ |
1447 | + startNextJob(); |
1448 | +} |
1449 | + |
1450 | +void NotesStore::deleteNoteJobDone(NotesStore::ErrorCode errorCode, const QString &guid) |
1451 | +{ |
1452 | + if (errorCode != ErrorCodeNoError) { |
1453 | + qWarning() << "Cannot delete note:" << errorCodeToString(errorCode); |
1454 | + startNextJob(); |
1455 | + return; |
1456 | + } |
1457 | + emit noteRemoved(guid); |
1458 | + m_notes.take(guid)->deleteLater(); |
1459 | + startNextJob(); |
1460 | +} |
1461 | + |
1462 | |
1463 | === modified file 'src/plugin/Evernote/notesstore.h' |
1464 | --- src/plugin/Evernote/notesstore.h 2013-11-21 23:30:15 +0000 |
1465 | +++ src/plugin/Evernote/notesstore.h 2013-11-25 00:51:38 +0000 |
1466 | @@ -6,42 +6,85 @@ |
1467 | #include <NoteStore_constants.h> |
1468 | #include <Errors_types.h> |
1469 | |
1470 | -// Qt |
1471 | #include <QObject> |
1472 | - |
1473 | -using namespace evernote::edam; |
1474 | - |
1475 | -class Notebooks; |
1476 | +#include <QHash> |
1477 | + |
1478 | +class EvernoteJob; |
1479 | + |
1480 | +class Notebook; |
1481 | +class Note; |
1482 | |
1483 | class NotesStore : public QObject |
1484 | { |
1485 | Q_OBJECT |
1486 | Q_PROPERTY(QString token READ token WRITE setToken NOTIFY tokenChanged) |
1487 | |
1488 | + friend class EvernoteJob; |
1489 | + |
1490 | public: |
1491 | + enum ErrorCode { |
1492 | + ErrorCodeNoError, |
1493 | + ErrorCodeUserException, |
1494 | + ErrorCodeSystemException, |
1495 | + ErrorCodeNotFoundExcpetion, |
1496 | + ErrorCodeConnectionLost |
1497 | + }; |
1498 | + |
1499 | + Q_INVOKABLE void createNote(const QString &title, const QString ¬ebookGuid, const QString &content); |
1500 | + |
1501 | static NotesStore *instance(); |
1502 | + static QString errorCodeToString(ErrorCode errorCode); |
1503 | |
1504 | ~NotesStore(); |
1505 | |
1506 | QString token() const; |
1507 | void setToken(const QString &token); |
1508 | |
1509 | - NoteStoreClient *evernoteNotesStoreClient(); |
1510 | - |
1511 | -private: |
1512 | - explicit NotesStore(QObject *parent = 0); |
1513 | + QList<Note*> notes() const; |
1514 | + Note* note(const QString &guid); |
1515 | + void saveNote(const QString &guid); |
1516 | + void deleteNote(const QString &guid); |
1517 | + |
1518 | + QList<Notebook*> notebooks() const; |
1519 | + Notebook* notebook(const QString &guid); |
1520 | + |
1521 | + void refreshNotes(const QString &filterNotebookGuid = QString()); |
1522 | + void refreshNoteContent(const QString &guid); |
1523 | + void refreshNotebooks(); |
1524 | |
1525 | signals: |
1526 | void tokenChanged(); |
1527 | |
1528 | + void noteAdded(const QString &guid); |
1529 | + void noteChanged(const QString &guid); |
1530 | + void noteRemoved(const QString &guid); |
1531 | + |
1532 | + void notebookAdded(const QString &guid); |
1533 | + void notebookChanged(const QString &guid); |
1534 | + |
1535 | +private slots: |
1536 | + void fetchNotesJobDone(ErrorCode errorCode, const evernote::edam::NotesMetadataList &results); |
1537 | + void fetchNotebooksJobDone(ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results); |
1538 | + void fetchNoteJobDone(ErrorCode errorCode, const evernote::edam::Note &result); |
1539 | + void createNoteJobDone(ErrorCode errorCode, Note *note); |
1540 | + void saveNoteJobDone(ErrorCode errorCode, Note *note); |
1541 | + void deleteNoteJobDone(ErrorCode errorCode, const QString &guid); |
1542 | + |
1543 | + void startJobQueue(); |
1544 | + void startNextJob(); |
1545 | + |
1546 | private: |
1547 | + explicit NotesStore(QObject *parent = 0); |
1548 | static NotesStore *s_instance; |
1549 | |
1550 | - void displayException(); |
1551 | - |
1552 | QString m_token; |
1553 | - NoteStoreClient *m_client; |
1554 | - |
1555 | + evernote::edam::NoteStoreClient *m_client; |
1556 | + |
1557 | + QHash<QString, Notebook*> m_notebooks; |
1558 | + QHash<QString, Note*> m_notes; |
1559 | + |
1560 | + QList<EvernoteJob*> m_jobQueue; |
1561 | + QThread *m_currentJob; |
1562 | }; |
1563 | |
1564 | #endif // NOTESSTORE_H |
1565 | |
1566 | === modified file 'src/plugin/Evernote/userstore.h' |
1567 | --- src/plugin/Evernote/userstore.h 2013-11-21 23:30:15 +0000 |
1568 | +++ src/plugin/Evernote/userstore.h 2013-11-25 00:51:38 +0000 |
1569 | @@ -5,8 +5,6 @@ |
1570 | |
1571 | #include <QObject> |
1572 | |
1573 | -using namespace evernote::edam; |
1574 | - |
1575 | class UserStore : public QObject |
1576 | { |
1577 | Q_OBJECT |
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://