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