Merge lp:~mzanetti/reminders-app/notesdelegate into lp:reminders-app
- notesdelegate
- Merge into trunk
Proposed by
Michael Zanetti
Status: | Superseded |
---|---|
Proposed branch: | lp:~mzanetti/reminders-app/notesdelegate |
Merge into: | lp:reminders-app |
Diff against target: |
3403 lines (+1845/-702) 49 files modified
src/app/app.pro (+4/-1) src/app/qml/components/NotesDelegate.qml (+56/-0) src/app/qml/components/ToolbarSpacer.qml (+45/-0) src/app/qml/reminders-app.qml (+8/-1) src/app/qml/ui/AccountSelectorPage.qml (+1/-1) src/app/qml/ui/NotePage.qml (+2/-0) src/app/qml/ui/NotebooksPage.qml (+9/-0) src/app/qml/ui/NotesPage.qml (+21/-7) src/app/qml/ui/RemindersPage.qml (+9/-10) src/app/qml/ui/SearchNotesPage.qml (+80/-0) src/plugin/Evernote/Evernote.pro (+14/-2) src/plugin/Evernote/evernoteconnection.cpp (+190/-0) src/plugin/Evernote/evernoteconnection.h (+101/-0) src/plugin/Evernote/evernoteplugin.cpp (+14/-2) src/plugin/Evernote/jobs/createnotebookjob.cpp (+41/-0) src/plugin/Evernote/jobs/createnotebookjob.h (+46/-0) src/plugin/Evernote/jobs/createnotejob.cpp (+26/-32) src/plugin/Evernote/jobs/createnotejob.h (+13/-8) src/plugin/Evernote/jobs/deletenotejob.cpp (+9/-10) src/plugin/Evernote/jobs/deletenotejob.h (+7/-5) src/plugin/Evernote/jobs/evernotejob.cpp (+50/-17) src/plugin/Evernote/jobs/evernotejob.h (+22/-8) src/plugin/Evernote/jobs/expungenotebookjob.cpp (+39/-0) src/plugin/Evernote/jobs/expungenotebookjob.h (+43/-0) src/plugin/Evernote/jobs/fetchnotebooksjob.cpp (+13/-17) src/plugin/Evernote/jobs/fetchnotebooksjob.h (+10/-5) src/plugin/Evernote/jobs/fetchnotejob.cpp (+7/-17) src/plugin/Evernote/jobs/fetchnotejob.h (+10/-4) src/plugin/Evernote/jobs/fetchnotesjob.cpp (+27/-18) src/plugin/Evernote/jobs/fetchnotesjob.h (+10/-6) src/plugin/Evernote/jobs/fetchusernamejob.cpp (+38/-0) src/plugin/Evernote/jobs/fetchusernamejob.h (+43/-0) src/plugin/Evernote/jobs/notesstorejob.cpp (+39/-0) src/plugin/Evernote/jobs/notesstorejob.h (+44/-0) src/plugin/Evernote/jobs/savenotejob.cpp (+36/-33) src/plugin/Evernote/jobs/savenotejob.h (+9/-5) src/plugin/Evernote/jobs/userstorejob.cpp (+39/-0) src/plugin/Evernote/jobs/userstorejob.h (+46/-0) src/plugin/Evernote/note.cpp (+115/-11) src/plugin/Evernote/note.h (+55/-4) src/plugin/Evernote/notebooks.cpp (+0/-1) src/plugin/Evernote/notes.cpp (+58/-80) src/plugin/Evernote/notes.h (+17/-25) src/plugin/Evernote/notesstore.cpp (+245/-231) src/plugin/Evernote/notesstore.h (+53/-41) src/plugin/Evernote/userstore.cpp (+38/-95) src/plugin/Evernote/userstore.h (+19/-5) src/plugin/Evernote/utils/html2enmlconverter.cpp (+22/-0) src/plugin/Evernote/utils/html2enmlconverter.h (+2/-0) |
To merge this branch: | bzr merge lp:~mzanetti/reminders-app/notesdelegate |
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+199011@code.launchpad.net |
This proposal has been superseded by a proposal from 2013-12-14.
Commit message
Added a NotesDelegate to roughly reflect design wireframe
Description of the change
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)
- 25. By Michael Zanetti
-
don't automatically fetch notes content to avoid hitting the rate limit
- 26. By Michael Zanetti
-
merge prerequisite branch
- 27. By Michael Zanetti
-
added missing file
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/app/app.pro' | |||
2 | --- src/app/app.pro 2013-11-22 21:35:34 +0000 | |||
3 | +++ src/app/app.pro 2013-12-14 00:07:45 +0000 | |||
4 | @@ -10,7 +10,10 @@ | |||
5 | 10 | qml/ui/RemindersPage.qml \ | 10 | qml/ui/RemindersPage.qml \ |
6 | 11 | qml/ui/NotesPage.qml \ | 11 | qml/ui/NotesPage.qml \ |
7 | 12 | qml/ui/AccountSelectorPage.qml \ | 12 | qml/ui/AccountSelectorPage.qml \ |
9 | 13 | qml/ui/NotePage.qml | 13 | qml/ui/NotePage.qml \ |
10 | 14 | qml/ui/SearchNotesPage.qml \ | ||
11 | 15 | qml/components/ToolbarSpacer.qml \ | ||
12 | 16 | qml/components/NotesDelegate.qml \ | ||
13 | 14 | 17 | ||
14 | 15 | # Copy qml to build dir for running with qtcreator | 18 | # Copy qml to build dir for running with qtcreator |
15 | 16 | qmlfolder.source = src/app/qml | 19 | qmlfolder.source = src/app/qml |
16 | 17 | 20 | ||
17 | === added directory 'src/app/qml/components' | |||
18 | === added file 'src/app/qml/components/NotesDelegate.qml' | |||
19 | --- src/app/qml/components/NotesDelegate.qml 1970-01-01 00:00:00 +0000 | |||
20 | +++ src/app/qml/components/NotesDelegate.qml 2013-12-14 00:07:45 +0000 | |||
21 | @@ -0,0 +1,56 @@ | |||
22 | 1 | /* | ||
23 | 2 | * Copyright: 2013 Canonical, Ltd | ||
24 | 3 | * | ||
25 | 4 | * This file is part of reminders-app | ||
26 | 5 | * | ||
27 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
28 | 7 | * it under the terms of the GNU General Public License as published by | ||
29 | 8 | * the Free Software Foundation; version 3. | ||
30 | 9 | * | ||
31 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
32 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
33 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
34 | 13 | * GNU General Public License for more details. | ||
35 | 14 | * | ||
36 | 15 | * You should have received a copy of the GNU General Public License | ||
37 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
38 | 17 | */ | ||
39 | 18 | |||
40 | 19 | import QtQuick 2.0 | ||
41 | 20 | import Ubuntu.Components 0.1 | ||
42 | 21 | import Ubuntu.Components.ListItems 0.1 | ||
43 | 22 | |||
44 | 23 | Empty { | ||
45 | 24 | id: root | ||
46 | 25 | height: units.gu(9) | ||
47 | 26 | |||
48 | 27 | property string title | ||
49 | 28 | property date creationDate | ||
50 | 29 | property string content | ||
51 | 30 | |||
52 | 31 | Column { | ||
53 | 32 | id: contentColumn | ||
54 | 33 | spacing: units.gu(1) | ||
55 | 34 | anchors { | ||
56 | 35 | top: parent.top | ||
57 | 36 | topMargin: units.gu(1) | ||
58 | 37 | left: parent.left | ||
59 | 38 | leftMargin: units.gu(2) | ||
60 | 39 | right: parent.right | ||
61 | 40 | rightMargin: units.gu(2) | ||
62 | 41 | } | ||
63 | 42 | Label { | ||
64 | 43 | anchors { left: parent.left; right: parent.right } | ||
65 | 44 | text: root.title | ||
66 | 45 | font.bold: true | ||
67 | 46 | elide: Text.ElideRight | ||
68 | 47 | } | ||
69 | 48 | Label { | ||
70 | 49 | anchors { left: parent.left; right: parent.right } | ||
71 | 50 | text: "<font color=\"#dd4814\">"+ Qt.formatDate(root.creationDate) + "</font> " + root.content | ||
72 | 51 | wrapMode: Text.WordWrap | ||
73 | 52 | textFormat: Text.StyledText | ||
74 | 53 | maximumLineCount: 2 | ||
75 | 54 | } | ||
76 | 55 | } | ||
77 | 56 | } | ||
78 | 0 | 57 | ||
79 | === added file 'src/app/qml/components/ToolbarSpacer.qml' | |||
80 | --- src/app/qml/components/ToolbarSpacer.qml 1970-01-01 00:00:00 +0000 | |||
81 | +++ src/app/qml/components/ToolbarSpacer.qml 2013-12-14 00:07:45 +0000 | |||
82 | @@ -0,0 +1,45 @@ | |||
83 | 1 | /* | ||
84 | 2 | * Copyright: 2013 Canonical, Ltd | ||
85 | 3 | * | ||
86 | 4 | * This file is part of reminders-app | ||
87 | 5 | * | ||
88 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
89 | 7 | * it under the terms of the GNU General Public License as published by | ||
90 | 8 | * the Free Software Foundation; version 3. | ||
91 | 9 | * | ||
92 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
93 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
94 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
95 | 13 | * GNU General Public License for more details. | ||
96 | 14 | * | ||
97 | 15 | * You should have received a copy of the GNU General Public License | ||
98 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
99 | 17 | */ | ||
100 | 18 | |||
101 | 19 | import QtQuick 2.0 | ||
102 | 20 | import Ubuntu.Components 0.1 | ||
103 | 21 | import Ubuntu.Components.Popups 0.1 | ||
104 | 22 | |||
105 | 23 | Item { | ||
106 | 24 | id: spacerItem | ||
107 | 25 | objectName: "__ToolBarItems.SpacerItem" | ||
108 | 26 | height: parent.height | ||
109 | 27 | width: { | ||
110 | 28 | var othersWidth = 0; | ||
111 | 29 | |||
112 | 30 | // Hack: the autogenerated back button | ||
113 | 31 | if (pageStack != null && pageStack.depth > 1) { | ||
114 | 32 | othersWidth = units.gu(6) | ||
115 | 33 | } | ||
116 | 34 | |||
117 | 35 | for (var i = 0; i < parent.children.length; ++i) { | ||
118 | 36 | var otherItem = parent.children[i]; | ||
119 | 37 | if (otherItem.objectName !== "__ToolBarItems.SpacerItem") { | ||
120 | 38 | if (otherItem.visible) { | ||
121 | 39 | othersWidth += otherItem.width + parent.spacing; | ||
122 | 40 | } | ||
123 | 41 | } | ||
124 | 42 | } | ||
125 | 43 | return parent.parent.width - othersWidth - units.gu(4); | ||
126 | 44 | } | ||
127 | 45 | } | ||
128 | 0 | 46 | ||
129 | === modified file 'src/app/qml/reminders-app.qml' | |||
130 | --- src/app/qml/reminders-app.qml 2013-11-26 17:18:33 +0000 | |||
131 | +++ src/app/qml/reminders-app.qml 2013-12-14 00:07:45 +0000 | |||
132 | @@ -47,11 +47,18 @@ | |||
133 | 47 | 47 | ||
134 | 48 | Component.onCompleted: { | 48 | Component.onCompleted: { |
135 | 49 | pagestack.push(rootTabs) | 49 | pagestack.push(rootTabs) |
137 | 50 | if (NotesStore.token.length === 0) { | 50 | if (EvernoteConnection.token.length === 0) { |
138 | 51 | pagestack.push(Qt.resolvedUrl("ui/AccountSelectorPage.qml")); | 51 | pagestack.push(Qt.resolvedUrl("ui/AccountSelectorPage.qml")); |
139 | 52 | } | 52 | } |
140 | 53 | } | 53 | } |
141 | 54 | 54 | ||
142 | 55 | Connections { | ||
143 | 56 | target: UserStore | ||
144 | 57 | onUsernameChanged: { | ||
145 | 58 | print("Logged in as user:", UserStore.username) | ||
146 | 59 | } | ||
147 | 60 | } | ||
148 | 61 | |||
149 | 55 | PageStack { | 62 | PageStack { |
150 | 56 | id: pagestack | 63 | id: pagestack |
151 | 57 | 64 | ||
152 | 58 | 65 | ||
153 | === modified file 'src/app/qml/ui/AccountSelectorPage.qml' | |||
154 | --- src/app/qml/ui/AccountSelectorPage.qml 2013-11-26 17:18:33 +0000 | |||
155 | +++ src/app/qml/ui/AccountSelectorPage.qml 2013-12-14 00:07:45 +0000 | |||
156 | @@ -51,7 +51,7 @@ | |||
157 | 51 | // Print the access token on the console | 51 | // Print the access token on the console |
158 | 52 | onAuthenticated: { | 52 | onAuthenticated: { |
159 | 53 | console.log("Access token is " + reply.AccessToken) | 53 | console.log("Access token is " + reply.AccessToken) |
161 | 54 | NotesStore.token = reply.AccessToken; | 54 | EvernoteConnection.token = reply.AccessToken; |
162 | 55 | pagestack.pop(); | 55 | pagestack.pop(); |
163 | 56 | } | 56 | } |
164 | 57 | onAuthenticationError: { console.log("Authentication failed, code " + error.code) } | 57 | onAuthenticationError: { console.log("Authentication failed, code " + error.code) } |
165 | 58 | 58 | ||
166 | === modified file 'src/app/qml/ui/NotePage.qml' | |||
167 | --- src/app/qml/ui/NotePage.qml 2013-11-26 17:18:33 +0000 | |||
168 | +++ src/app/qml/ui/NotePage.qml 2013-12-14 00:07:45 +0000 | |||
169 | @@ -24,6 +24,8 @@ | |||
170 | 24 | title: note.title | 24 | title: note.title |
171 | 25 | property var note | 25 | property var note |
172 | 26 | 26 | ||
173 | 27 | Component.onCompleted: NotesStore.refreshNoteContent(note.guid) | ||
174 | 28 | |||
175 | 27 | Column { | 29 | Column { |
176 | 28 | anchors.fill: parent | 30 | anchors.fill: parent |
177 | 29 | spacing: units.gu(1) | 31 | spacing: units.gu(1) |
178 | 30 | 32 | ||
179 | === modified file 'src/app/qml/ui/NotebooksPage.qml' | |||
180 | --- src/app/qml/ui/NotebooksPage.qml 2013-11-26 17:18:33 +0000 | |||
181 | +++ src/app/qml/ui/NotebooksPage.qml 2013-12-14 00:07:45 +0000 | |||
182 | @@ -30,6 +30,15 @@ | |||
183 | 30 | } | 30 | } |
184 | 31 | } | 31 | } |
185 | 32 | 32 | ||
186 | 33 | tools: ToolbarItems { | ||
187 | 34 | ToolbarButton { | ||
188 | 35 | text: "add notebook" | ||
189 | 36 | onTriggered: { | ||
190 | 37 | NotesStore.createNotebook("new notebook"); | ||
191 | 38 | } | ||
192 | 39 | } | ||
193 | 40 | } | ||
194 | 41 | |||
195 | 33 | Notebooks { | 42 | Notebooks { |
196 | 34 | id: notebooks | 43 | id: notebooks |
197 | 35 | } | 44 | } |
198 | 36 | 45 | ||
199 | === modified file 'src/app/qml/ui/NotesPage.qml' | |||
200 | --- src/app/qml/ui/NotesPage.qml 2013-11-26 17:18:33 +0000 | |||
201 | +++ src/app/qml/ui/NotesPage.qml 2013-12-14 00:07:45 +0000 | |||
202 | @@ -20,6 +20,7 @@ | |||
203 | 20 | import Ubuntu.Components 0.1 | 20 | import Ubuntu.Components 0.1 |
204 | 21 | import Ubuntu.Components.ListItems 0.1 | 21 | import Ubuntu.Components.ListItems 0.1 |
205 | 22 | import Evernote 0.1 | 22 | import Evernote 0.1 |
206 | 23 | import "../components" | ||
207 | 23 | 24 | ||
208 | 24 | Page { | 25 | Page { |
209 | 25 | id: notesPage | 26 | id: notesPage |
210 | @@ -28,14 +29,23 @@ | |||
211 | 28 | 29 | ||
212 | 29 | onActiveChanged: { | 30 | onActiveChanged: { |
213 | 30 | if (active) { | 31 | if (active) { |
216 | 31 | print("refreshing notes") | 32 | NotesStore.refreshNotes(); |
215 | 32 | notes.refresh(); | ||
217 | 33 | } | 33 | } |
218 | 34 | } | 34 | } |
219 | 35 | 35 | ||
220 | 36 | // Just for testing | 36 | // Just for testing |
221 | 37 | tools: ToolbarItems { | 37 | tools: ToolbarItems { |
222 | 38 | ToolbarButton { | 38 | ToolbarButton { |
223 | 39 | text: "search" | ||
224 | 40 | iconName: "search" | ||
225 | 41 | onTriggered: { | ||
226 | 42 | pagestack.push(Qt.resolvedUrl("SearchNotesPage.qml")) | ||
227 | 43 | } | ||
228 | 44 | } | ||
229 | 45 | |||
230 | 46 | ToolbarSpacer { } | ||
231 | 47 | |||
232 | 48 | ToolbarButton { | ||
233 | 39 | text: "add note" | 49 | text: "add note" |
234 | 40 | enabled: notes.filterNotebookGuid.length > 0 | 50 | enabled: notes.filterNotebookGuid.length > 0 |
235 | 41 | onTriggered: { | 51 | onTriggered: { |
236 | @@ -52,18 +62,22 @@ | |||
237 | 52 | } | 62 | } |
238 | 53 | 63 | ||
239 | 54 | ListView { | 64 | ListView { |
241 | 55 | anchors.fill: parent | 65 | anchors { left: parent.left; right: parent.right } |
242 | 66 | height: parent.height - y | ||
243 | 56 | model: notes | 67 | model: notes |
244 | 68 | clip: true | ||
245 | 57 | 69 | ||
248 | 58 | delegate: Standard { | 70 | delegate: NotesDelegate { |
249 | 59 | text: title | 71 | title: model.title |
250 | 72 | creationDate: model.created | ||
251 | 73 | content: NotesStore.note(model.guid).plaintextContent | ||
252 | 60 | 74 | ||
253 | 61 | onClicked: { | 75 | onClicked: { |
255 | 62 | pageStack.push(Qt.resolvedUrl("NotePage.qml"), {note: notes.note(guid)}) | 76 | pageStack.push(Qt.resolvedUrl("NotePage.qml"), {note: NotesStore.note(guid)}) |
256 | 63 | } | 77 | } |
257 | 64 | 78 | ||
258 | 65 | onPressAndHold: { | 79 | onPressAndHold: { |
260 | 66 | notes.note(guid).remove(); | 80 | NotesStore.deleteNote(guid); |
261 | 67 | } | 81 | } |
262 | 68 | } | 82 | } |
263 | 69 | } | 83 | } |
264 | 70 | 84 | ||
265 | === modified file 'src/app/qml/ui/RemindersPage.qml' | |||
266 | --- src/app/qml/ui/RemindersPage.qml 2013-11-26 17:18:33 +0000 | |||
267 | +++ src/app/qml/ui/RemindersPage.qml 2013-12-14 00:07:45 +0000 | |||
268 | @@ -19,28 +19,27 @@ | |||
269 | 19 | import QtQuick 2.0 | 19 | import QtQuick 2.0 |
270 | 20 | import Ubuntu.Components 0.1 | 20 | import Ubuntu.Components 0.1 |
271 | 21 | import Ubuntu.Components.ListItems 0.1 | 21 | import Ubuntu.Components.ListItems 0.1 |
273 | 22 | //import "../components" | 22 | import Evernote 0.1 |
274 | 23 | 23 | ||
275 | 24 | Page { | 24 | Page { |
276 | 25 | id: remindersPage | 25 | id: remindersPage |
277 | 26 | 26 | ||
282 | 27 | Label { | 27 | Notes { |
283 | 28 | id: developmentWarning | 28 | id: notes |
284 | 29 | anchors.centerIn: parent | 29 | onlyReminders: true |
281 | 30 | text: i18n.tr("This page is still in development") | ||
285 | 31 | } | 30 | } |
286 | 32 | 31 | ||
287 | 33 | ListView { | 32 | ListView { |
288 | 34 | 33 | ||
290 | 35 | width: parent.width; height: parent.height | 34 | anchors.fill: parent |
291 | 36 | 35 | ||
292 | 37 | delegate: Subtitled { | 36 | delegate: Subtitled { |
295 | 38 | text: '<b>Name:</b> ' + model.name | 37 | text: '<b>Name:</b> ' + model.title |
296 | 39 | subText: '<b>Date:</b> ' + model.date | 38 | subText: '<b>Date:</b> ' + Qt.formatDateTime(model.created) + |
297 | 39 | (model.reminderDone ? " - <b>Done:</b> " + Qt.formatDate(model.reminderDoneTime) : "") | ||
298 | 40 | } | 40 | } |
299 | 41 | 41 | ||
302 | 42 | // model: RemindersModel {} | 42 | model: notes |
301 | 43 | |||
303 | 44 | } | 43 | } |
304 | 45 | 44 | ||
305 | 46 | } | 45 | } |
306 | 47 | 46 | ||
307 | === added file 'src/app/qml/ui/SearchNotesPage.qml' | |||
308 | --- src/app/qml/ui/SearchNotesPage.qml 1970-01-01 00:00:00 +0000 | |||
309 | +++ src/app/qml/ui/SearchNotesPage.qml 2013-12-14 00:07:45 +0000 | |||
310 | @@ -0,0 +1,80 @@ | |||
311 | 1 | /* | ||
312 | 2 | * Copyright: 2013 Canonical, Ltd | ||
313 | 3 | * | ||
314 | 4 | * This file is part of reminders-app | ||
315 | 5 | * | ||
316 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
317 | 7 | * it under the terms of the GNU General Public License as published by | ||
318 | 8 | * the Free Software Foundation; version 3. | ||
319 | 9 | * | ||
320 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
321 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
322 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
323 | 13 | * GNU General Public License for more details. | ||
324 | 14 | * | ||
325 | 15 | * You should have received a copy of the GNU General Public License | ||
326 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
327 | 17 | */ | ||
328 | 18 | |||
329 | 19 | import QtQuick 2.0 | ||
330 | 20 | import Ubuntu.Components 0.1 | ||
331 | 21 | import Ubuntu.Components.ListItems 0.1 | ||
332 | 22 | import Evernote 0.1 | ||
333 | 23 | import "../components" | ||
334 | 24 | |||
335 | 25 | Page { | ||
336 | 26 | Column { | ||
337 | 27 | anchors { fill: parent; topMargin: units.gu(2); bottomMargin: units.gu(2) } | ||
338 | 28 | spacing: units.gu(2) | ||
339 | 29 | |||
340 | 30 | Row { | ||
341 | 31 | anchors { left: parent.left; right: parent.right; margins: units.gu(2) } | ||
342 | 32 | spacing: units.gu(1) | ||
343 | 33 | |||
344 | 34 | TextField { | ||
345 | 35 | id: searchField | ||
346 | 36 | width: parent.width - searchButton.width - parent.spacing | ||
347 | 37 | anchors.verticalCenter: parent.verticalCenter | ||
348 | 38 | |||
349 | 39 | primaryItem: Icon { | ||
350 | 40 | height: searchField.height - units.gu(1) | ||
351 | 41 | width: height | ||
352 | 42 | name: "search" | ||
353 | 43 | } | ||
354 | 44 | |||
355 | 45 | onAccepted: { | ||
356 | 46 | NotesStore.findNotes(searchField.text + "*") | ||
357 | 47 | } | ||
358 | 48 | } | ||
359 | 49 | Button { | ||
360 | 50 | id: searchButton | ||
361 | 51 | height: searchField.height | ||
362 | 52 | text: "search" | ||
363 | 53 | onClicked: { | ||
364 | 54 | NotesStore.findNotes(searchField.text + "*") | ||
365 | 55 | } | ||
366 | 56 | } | ||
367 | 57 | } | ||
368 | 58 | |||
369 | 59 | ListView { | ||
370 | 60 | anchors { left: parent.left; right: parent.right } | ||
371 | 61 | height: parent.height - y | ||
372 | 62 | clip: true | ||
373 | 63 | |||
374 | 64 | model: Notes { | ||
375 | 65 | onlySearchResults: true | ||
376 | 66 | } | ||
377 | 67 | |||
378 | 68 | delegate: NotesDelegate { | ||
379 | 69 | title: model.title | ||
380 | 70 | creationDate: model.created | ||
381 | 71 | content: NotesStore.note(model.guid).plaintextContent | ||
382 | 72 | |||
383 | 73 | onClicked: { | ||
384 | 74 | pageStack.push(Qt.resolvedUrl("NotePage.qml"), {note: NotesStore.note(guid)}) | ||
385 | 75 | } | ||
386 | 76 | } | ||
387 | 77 | } | ||
388 | 78 | |||
389 | 79 | } | ||
390 | 80 | } | ||
391 | 0 | 81 | ||
392 | === modified file 'src/plugin/Evernote/Evernote.pro' | |||
393 | --- src/plugin/Evernote/Evernote.pro 2013-11-27 17:33:36 +0000 | |||
394 | +++ src/plugin/Evernote/Evernote.pro 2013-12-14 00:07:45 +0000 | |||
395 | @@ -23,7 +23,13 @@ | |||
396 | 23 | jobs/evernotejob.cpp \ | 23 | jobs/evernotejob.cpp \ |
397 | 24 | jobs/savenotejob.cpp \ | 24 | jobs/savenotejob.cpp \ |
398 | 25 | jobs/deletenotejob.cpp \ | 25 | jobs/deletenotejob.cpp \ |
400 | 26 | utils/html2enmlconverter.cpp | 26 | utils/html2enmlconverter.cpp \ |
401 | 27 | evernoteconnection.cpp \ | ||
402 | 28 | jobs/userstorejob.cpp \ | ||
403 | 29 | jobs/notesstorejob.cpp \ | ||
404 | 30 | jobs/fetchusernamejob.cpp \ | ||
405 | 31 | jobs/createnotebookjob.cpp \ | ||
406 | 32 | jobs/expungenotebookjob.cpp | ||
407 | 27 | 33 | ||
408 | 28 | HEADERS += evernoteplugin.h \ | 34 | HEADERS += evernoteplugin.h \ |
409 | 29 | notesstore.h \ | 35 | notesstore.h \ |
410 | @@ -39,7 +45,13 @@ | |||
411 | 39 | jobs/evernotejob.h \ | 45 | jobs/evernotejob.h \ |
412 | 40 | jobs/savenotejob.h \ | 46 | jobs/savenotejob.h \ |
413 | 41 | jobs/deletenotejob.h \ | 47 | jobs/deletenotejob.h \ |
415 | 42 | utils/html2enmlconverter.h | 48 | utils/html2enmlconverter.h \ |
416 | 49 | evernoteconnection.h \ | ||
417 | 50 | jobs/userstorejob.h \ | ||
418 | 51 | jobs/notesstorejob.h \ | ||
419 | 52 | jobs/fetchusernamejob.h \ | ||
420 | 53 | jobs/createnotebookjob.h \ | ||
421 | 54 | jobs/expungenotebookjob.h | ||
422 | 43 | 55 | ||
423 | 44 | message(building in $$OUT_PWD) | 56 | message(building in $$OUT_PWD) |
424 | 45 | LIBS += -L$$OUT_PWD/../../../3rdParty/evernote-sdk-cpp/ -L$$OUT_PWD/../../../3rdParty/libthrift/ -levernote-sdk-cpp -llibthrift -lssl -lcrypto | 57 | LIBS += -L$$OUT_PWD/../../../3rdParty/evernote-sdk-cpp/ -L$$OUT_PWD/../../../3rdParty/libthrift/ -levernote-sdk-cpp -llibthrift -lssl -lcrypto |
425 | 46 | 58 | ||
426 | === added file 'src/plugin/Evernote/evernoteconnection.cpp' | |||
427 | --- src/plugin/Evernote/evernoteconnection.cpp 1970-01-01 00:00:00 +0000 | |||
428 | +++ src/plugin/Evernote/evernoteconnection.cpp 2013-12-14 00:07:45 +0000 | |||
429 | @@ -0,0 +1,190 @@ | |||
430 | 1 | /* | ||
431 | 2 | * Copyright: 2013 Canonical, Ltd | ||
432 | 3 | * | ||
433 | 4 | * This file is part of reminders-app | ||
434 | 5 | * | ||
435 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
436 | 7 | * it under the terms of the GNU General Public License as published by | ||
437 | 8 | * the Free Software Foundation; version 3. | ||
438 | 9 | * | ||
439 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
440 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
441 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
442 | 13 | * GNU General Public License for more details. | ||
443 | 14 | * | ||
444 | 15 | * You should have received a copy of the GNU General Public License | ||
445 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
446 | 17 | * | ||
447 | 18 | * Authors: Michael Zanetti <michael.zanetti@canonical.com> | ||
448 | 19 | */ | ||
449 | 20 | |||
450 | 21 | #include "evernoteconnection.h" | ||
451 | 22 | #include "jobs/evernotejob.h" | ||
452 | 23 | |||
453 | 24 | // Thrift | ||
454 | 25 | #include <arpa/inet.h> // seems thrift forgot this one | ||
455 | 26 | #include <protocol/TBinaryProtocol.h> | ||
456 | 27 | #include <transport/THttpClient.h> | ||
457 | 28 | #include <transport/TSSLSocket.h> | ||
458 | 29 | #include <Thrift.h> | ||
459 | 30 | |||
460 | 31 | // Evernote SDK | ||
461 | 32 | #include <NoteStore.h> | ||
462 | 33 | #include <NoteStore_constants.h> | ||
463 | 34 | #include <UserStore.h> | ||
464 | 35 | #include <UserStore_constants.h> | ||
465 | 36 | #include <Errors_types.h> | ||
466 | 37 | |||
467 | 38 | #include <QDebug> | ||
468 | 39 | |||
469 | 40 | using namespace apache::thrift; | ||
470 | 41 | using namespace apache::thrift::protocol; | ||
471 | 42 | using namespace apache::thrift::transport; | ||
472 | 43 | |||
473 | 44 | EvernoteConnection* EvernoteConnection::s_instance = 0; | ||
474 | 45 | |||
475 | 46 | // FIXME: need to populate this string from the system | ||
476 | 47 | // The structure should be: | ||
477 | 48 | // application/version; platform/version; [ device/version ] | ||
478 | 49 | // E.g. "Evernote Windows/3.0.1; Windows/XP SP3" | ||
479 | 50 | QString EDAM_CLIENT_NAME = QStringLiteral("Reminders/0.1; Ubuntu/13.10"); | ||
480 | 51 | QString EVERNOTE_HOST = QStringLiteral("sandbox.evernote.com"); | ||
481 | 52 | QString EDAM_USER_STORE_PATH = QStringLiteral("/edam/user"); | ||
482 | 53 | QString EDAM_NOTE_STORE_PATH = QStringLiteral("/edam/note"); | ||
483 | 54 | |||
484 | 55 | EvernoteConnection::EvernoteConnection(QObject *parent) : | ||
485 | 56 | QObject(parent), | ||
486 | 57 | m_currentJob(0), | ||
487 | 58 | m_useSSL(true) | ||
488 | 59 | { | ||
489 | 60 | setupUserStore(); | ||
490 | 61 | setupNotesStore(); | ||
491 | 62 | } | ||
492 | 63 | |||
493 | 64 | bool EvernoteConnection::setupUserStore() | ||
494 | 65 | { | ||
495 | 66 | bool versionOK = false; | ||
496 | 67 | try { | ||
497 | 68 | boost::shared_ptr<TSocket> socket; | ||
498 | 69 | |||
499 | 70 | if (m_useSSL) { | ||
500 | 71 | boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory()); | ||
501 | 72 | socket = sslSocketFactory->createSocket(EVERNOTE_HOST.toStdString(), 443); | ||
502 | 73 | qDebug() << "created UserStore SSL socket"; | ||
503 | 74 | } else { | ||
504 | 75 | // Create a non-secure socket | ||
505 | 76 | socket = boost::shared_ptr<TSocket> (new TSocket(EVERNOTE_HOST.toStdString(), 80)); | ||
506 | 77 | qDebug() << "created insecure UserStore socket"; | ||
507 | 78 | } | ||
508 | 79 | |||
509 | 80 | boost::shared_ptr<TBufferedTransport> bufferedTransport(new TBufferedTransport(socket)); | ||
510 | 81 | m_userStoreHttpClient = boost::shared_ptr<THttpClient>(new THttpClient(bufferedTransport, | ||
511 | 82 | EVERNOTE_HOST.toStdString(), | ||
512 | 83 | EDAM_USER_STORE_PATH.toStdString())); | ||
513 | 84 | m_userStoreHttpClient->open(); | ||
514 | 85 | boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(m_userStoreHttpClient)); | ||
515 | 86 | m_userstoreClient = new evernote::edam::UserStoreClient(iprot); | ||
516 | 87 | evernote::edam::UserStoreConstants constants; | ||
517 | 88 | versionOK = m_userstoreClient->checkVersion(EDAM_CLIENT_NAME.toStdString(), | ||
518 | 89 | constants.EDAM_VERSION_MAJOR, | ||
519 | 90 | constants.EDAM_VERSION_MINOR); | ||
520 | 91 | qDebug() << "UserStoreClient created. Version check:" << versionOK; | ||
521 | 92 | |||
522 | 93 | } catch (const TTransportException & e) { | ||
523 | 94 | qWarning() << "Failed to create Transport for UserStore:" << e.what(); | ||
524 | 95 | } catch (const TException & e) { | ||
525 | 96 | qWarning() << "Generic Thrift exception in UserStore setup:" << e.what(); | ||
526 | 97 | } | ||
527 | 98 | return versionOK; | ||
528 | 99 | } | ||
529 | 100 | |||
530 | 101 | bool EvernoteConnection::setupNotesStore() | ||
531 | 102 | { | ||
532 | 103 | try { | ||
533 | 104 | boost::shared_ptr<TSocket> socket; | ||
534 | 105 | |||
535 | 106 | if (m_useSSL) { | ||
536 | 107 | boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory()); | ||
537 | 108 | socket = sslSocketFactory->createSocket(EVERNOTE_HOST.toStdString(), 443); | ||
538 | 109 | qDebug() << "created NotesStore SSL socket"; | ||
539 | 110 | } else { | ||
540 | 111 | // Create a non-secure socket | ||
541 | 112 | socket = boost::shared_ptr<TSocket> (new TSocket(EVERNOTE_HOST.toStdString(), 80)); | ||
542 | 113 | qDebug() << "created insecure NotesStore socket"; | ||
543 | 114 | } | ||
544 | 115 | |||
545 | 116 | // setup UserStore | ||
546 | 117 | boost::shared_ptr<TBufferedTransport> bufferedTransport(new TBufferedTransport(socket)); | ||
547 | 118 | m_notesStoreHttpClient = boost::shared_ptr<THttpClient>(new THttpClient(bufferedTransport, | ||
548 | 119 | EVERNOTE_HOST.toStdString(), | ||
549 | 120 | EDAM_NOTE_STORE_PATH.toStdString())); | ||
550 | 121 | m_notesStoreHttpClient->open(); | ||
551 | 122 | boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(m_notesStoreHttpClient)); | ||
552 | 123 | |||
553 | 124 | // setup notesstore | ||
554 | 125 | m_notesStoreClient = new evernote::edam::NoteStoreClient(iprot); | ||
555 | 126 | |||
556 | 127 | qDebug() << "NoteStore client created."; | ||
557 | 128 | |||
558 | 129 | } catch (const TTransportException & e) { | ||
559 | 130 | qWarning() << "Failed to create Transport for NotesStore:" << e.what(); | ||
560 | 131 | return false; | ||
561 | 132 | } catch (const TException & e) { | ||
562 | 133 | qWarning() << "Generic Thrift exception in NotesStore setup:" << e.what(); | ||
563 | 134 | return false; | ||
564 | 135 | } | ||
565 | 136 | return true; | ||
566 | 137 | } | ||
567 | 138 | |||
568 | 139 | EvernoteConnection *EvernoteConnection::instance() | ||
569 | 140 | { | ||
570 | 141 | if (!s_instance) { | ||
571 | 142 | s_instance = new EvernoteConnection(); | ||
572 | 143 | } | ||
573 | 144 | return s_instance; | ||
574 | 145 | } | ||
575 | 146 | |||
576 | 147 | EvernoteConnection::~EvernoteConnection() | ||
577 | 148 | { | ||
578 | 149 | delete m_notesStoreClient; | ||
579 | 150 | } | ||
580 | 151 | |||
581 | 152 | QString EvernoteConnection::token() const | ||
582 | 153 | { | ||
583 | 154 | return m_token; | ||
584 | 155 | } | ||
585 | 156 | |||
586 | 157 | void EvernoteConnection::setToken(const QString &token) | ||
587 | 158 | { | ||
588 | 159 | if (token != m_token) { | ||
589 | 160 | m_token = token; | ||
590 | 161 | emit tokenChanged(); | ||
591 | 162 | } | ||
592 | 163 | } | ||
593 | 164 | |||
594 | 165 | void EvernoteConnection::enqueue(EvernoteJob *job) | ||
595 | 166 | { | ||
596 | 167 | connect(job, &EvernoteJob::finished, this, &EvernoteConnection::startNextJob); | ||
597 | 168 | |||
598 | 169 | m_jobQueue.append(job); | ||
599 | 170 | startJobQueue(); | ||
600 | 171 | } | ||
601 | 172 | |||
602 | 173 | void EvernoteConnection::startJobQueue() | ||
603 | 174 | { | ||
604 | 175 | if (m_jobQueue.isEmpty()) { | ||
605 | 176 | return; | ||
606 | 177 | } | ||
607 | 178 | |||
608 | 179 | if (m_currentJob) { | ||
609 | 180 | return; | ||
610 | 181 | } | ||
611 | 182 | m_currentJob = m_jobQueue.takeFirst(); | ||
612 | 183 | m_currentJob->start(); | ||
613 | 184 | } | ||
614 | 185 | |||
615 | 186 | void EvernoteConnection::startNextJob() | ||
616 | 187 | { | ||
617 | 188 | m_currentJob = 0; | ||
618 | 189 | startJobQueue(); | ||
619 | 190 | } | ||
620 | 0 | 191 | ||
621 | === added file 'src/plugin/Evernote/evernoteconnection.h' | |||
622 | --- src/plugin/Evernote/evernoteconnection.h 1970-01-01 00:00:00 +0000 | |||
623 | +++ src/plugin/Evernote/evernoteconnection.h 2013-12-14 00:07:45 +0000 | |||
624 | @@ -0,0 +1,101 @@ | |||
625 | 1 | /* | ||
626 | 2 | * Copyright: 2013 Canonical, Ltd | ||
627 | 3 | * | ||
628 | 4 | * This file is part of reminders-app | ||
629 | 5 | * | ||
630 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
631 | 7 | * it under the terms of the GNU General Public License as published by | ||
632 | 8 | * the Free Software Foundation; version 3. | ||
633 | 9 | * | ||
634 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
635 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
636 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
637 | 13 | * GNU General Public License for more details. | ||
638 | 14 | * | ||
639 | 15 | * You should have received a copy of the GNU General Public License | ||
640 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
641 | 17 | * | ||
642 | 18 | * Authors: Michael Zanetti <michael.zanetti@canonical.com> | ||
643 | 19 | */ | ||
644 | 20 | |||
645 | 21 | #ifndef EVERNOTECONNECTION_H | ||
646 | 22 | #define EVERNOTECONNECTION_H | ||
647 | 23 | |||
648 | 24 | #include <boost/shared_ptr.hpp> | ||
649 | 25 | |||
650 | 26 | // Thrift | ||
651 | 27 | #include <transport/THttpClient.h> | ||
652 | 28 | |||
653 | 29 | #include <QObject> | ||
654 | 30 | |||
655 | 31 | namespace evernote { | ||
656 | 32 | namespace edam { | ||
657 | 33 | class NoteStoreClient; | ||
658 | 34 | class UserStoreClient; | ||
659 | 35 | } | ||
660 | 36 | } | ||
661 | 37 | |||
662 | 38 | using namespace apache::thrift::transport; | ||
663 | 39 | |||
664 | 40 | class EvernoteJob; | ||
665 | 41 | |||
666 | 42 | class EvernoteConnection : public QObject | ||
667 | 43 | { | ||
668 | 44 | Q_OBJECT | ||
669 | 45 | Q_PROPERTY(QString token READ token WRITE setToken NOTIFY tokenChanged) | ||
670 | 46 | |||
671 | 47 | friend class NotesStoreJob; | ||
672 | 48 | friend class UserStoreJob; | ||
673 | 49 | |||
674 | 50 | public: | ||
675 | 51 | enum ErrorCode { | ||
676 | 52 | ErrorCodeNoError, | ||
677 | 53 | ErrorCodeUserException, | ||
678 | 54 | ErrorCodeSystemException, | ||
679 | 55 | ErrorCodeNotFoundExcpetion, | ||
680 | 56 | ErrorCodeConnectionLost | ||
681 | 57 | }; | ||
682 | 58 | |||
683 | 59 | static EvernoteConnection* instance(); | ||
684 | 60 | ~EvernoteConnection(); | ||
685 | 61 | |||
686 | 62 | QString token() const; | ||
687 | 63 | void setToken(const QString &token); | ||
688 | 64 | |||
689 | 65 | void enqueue(EvernoteJob *job); | ||
690 | 66 | |||
691 | 67 | signals: | ||
692 | 68 | void tokenChanged(); | ||
693 | 69 | |||
694 | 70 | private slots: | ||
695 | 71 | void startJobQueue(); | ||
696 | 72 | void startNextJob(); | ||
697 | 73 | |||
698 | 74 | private: | ||
699 | 75 | explicit EvernoteConnection(QObject *parent = 0); | ||
700 | 76 | static EvernoteConnection *s_instance; | ||
701 | 77 | |||
702 | 78 | bool setupUserStore(); | ||
703 | 79 | bool setupNotesStore(); | ||
704 | 80 | |||
705 | 81 | bool m_useSSL; | ||
706 | 82 | |||
707 | 83 | QString m_token; | ||
708 | 84 | |||
709 | 85 | // There must be only one job running at a time | ||
710 | 86 | // Do not start jobs other than with startJobQueue() | ||
711 | 87 | QList<EvernoteJob*> m_jobQueue; | ||
712 | 88 | EvernoteJob *m_currentJob; | ||
713 | 89 | |||
714 | 90 | // Those 4 are accessed from the job thread. | ||
715 | 91 | // Make sure to not access them while any jobs are running | ||
716 | 92 | // or we need to mutex them. | ||
717 | 93 | evernote::edam::NoteStoreClient *m_notesStoreClient; | ||
718 | 94 | boost::shared_ptr<THttpClient> m_notesStoreHttpClient; | ||
719 | 95 | |||
720 | 96 | evernote::edam::UserStoreClient *m_userstoreClient; | ||
721 | 97 | boost::shared_ptr<THttpClient> m_userStoreHttpClient; | ||
722 | 98 | |||
723 | 99 | }; | ||
724 | 100 | |||
725 | 101 | #endif // EVERNOTECONNECTION_H | ||
726 | 0 | 102 | ||
727 | === modified file 'src/plugin/Evernote/evernoteplugin.cpp' | |||
728 | --- src/plugin/Evernote/evernoteplugin.cpp 2013-11-26 17:18:33 +0000 | |||
729 | +++ src/plugin/Evernote/evernoteplugin.cpp 2013-12-14 00:07:45 +0000 | |||
730 | @@ -20,6 +20,7 @@ | |||
731 | 20 | 20 | ||
732 | 21 | #include "evernoteplugin.h" | 21 | #include "evernoteplugin.h" |
733 | 22 | 22 | ||
734 | 23 | #include "evernoteconnection.h" | ||
735 | 23 | #include "userstore.h" | 24 | #include "userstore.h" |
736 | 24 | #include "notesstore.h" | 25 | #include "notesstore.h" |
737 | 25 | #include "notes.h" | 26 | #include "notes.h" |
738 | @@ -28,16 +29,27 @@ | |||
739 | 28 | 29 | ||
740 | 29 | #include <QtQml> | 30 | #include <QtQml> |
741 | 30 | 31 | ||
742 | 32 | static QObject* userStoreProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */) | ||
743 | 33 | { | ||
744 | 34 | return UserStore::instance(); | ||
745 | 35 | } | ||
746 | 36 | |||
747 | 31 | static QObject* notesStoreProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */) | 37 | static QObject* notesStoreProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */) |
748 | 32 | { | 38 | { |
749 | 33 | return NotesStore::instance(); | 39 | return NotesStore::instance(); |
750 | 34 | } | 40 | } |
751 | 35 | 41 | ||
752 | 42 | static QObject* connectionProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */) | ||
753 | 43 | { | ||
754 | 44 | return EvernoteConnection::instance(); | ||
755 | 45 | } | ||
756 | 46 | |||
757 | 36 | void FitBitPlugin::registerTypes(const char *uri) | 47 | void FitBitPlugin::registerTypes(const char *uri) |
758 | 37 | { | 48 | { |
761 | 38 | qmlRegisterType<UserStore>("Evernote", 0, 1, "UserStore"); | 49 | qmlRegisterSingletonType<UserStore>("Evernote", 0, 1, "UserStore", userStoreProvider); |
760 | 39 | |||
762 | 40 | qmlRegisterSingletonType<NotesStore>("Evernote", 0, 1, "NotesStore", notesStoreProvider); | 50 | qmlRegisterSingletonType<NotesStore>("Evernote", 0, 1, "NotesStore", notesStoreProvider); |
763 | 51 | qmlRegisterSingletonType<EvernoteConnection>("Evernote", 0, 1, "EvernoteConnection", connectionProvider); | ||
764 | 52 | |||
765 | 41 | qmlRegisterType<Notes>("Evernote", 0, 1, "Notes"); | 53 | qmlRegisterType<Notes>("Evernote", 0, 1, "Notes"); |
766 | 42 | qmlRegisterType<Notebooks>("Evernote", 0, 1, "Notebooks"); | 54 | qmlRegisterType<Notebooks>("Evernote", 0, 1, "Notebooks"); |
767 | 43 | qmlRegisterUncreatableType<Note>("Evernote", 0, 1, "Note", "Cannot create Notes in QML. Use NotesStore.createNote() instead."); | 55 | qmlRegisterUncreatableType<Note>("Evernote", 0, 1, "Note", "Cannot create Notes in QML. Use NotesStore.createNote() instead."); |
768 | 44 | 56 | ||
769 | === added file 'src/plugin/Evernote/jobs/createnotebookjob.cpp' | |||
770 | --- src/plugin/Evernote/jobs/createnotebookjob.cpp 1970-01-01 00:00:00 +0000 | |||
771 | +++ src/plugin/Evernote/jobs/createnotebookjob.cpp 2013-12-14 00:07:45 +0000 | |||
772 | @@ -0,0 +1,41 @@ | |||
773 | 1 | /* | ||
774 | 2 | * Copyright: 2013 Canonical, Ltd | ||
775 | 3 | * | ||
776 | 4 | * This file is part of reminders-app | ||
777 | 5 | * | ||
778 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
779 | 7 | * it under the terms of the GNU General Public License as published by | ||
780 | 8 | * the Free Software Foundation; version 3. | ||
781 | 9 | * | ||
782 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
783 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
784 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
785 | 13 | * GNU General Public License for more details. | ||
786 | 14 | * | ||
787 | 15 | * You should have received a copy of the GNU General Public License | ||
788 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
789 | 17 | * | ||
790 | 18 | * Authors: Michael Zanetti <michael.zanetti@canonical.com> | ||
791 | 19 | */ | ||
792 | 20 | |||
793 | 21 | #include "createnotebookjob.h" | ||
794 | 22 | |||
795 | 23 | #include <QDebug> | ||
796 | 24 | |||
797 | 25 | CreateNotebookJob::CreateNotebookJob(const QString &name, QObject *parent) : | ||
798 | 26 | NotesStoreJob(parent), | ||
799 | 27 | m_name(name) | ||
800 | 28 | { | ||
801 | 29 | } | ||
802 | 30 | |||
803 | 31 | void CreateNotebookJob::startJob() | ||
804 | 32 | { | ||
805 | 33 | m_result.name = m_name.toStdString(); | ||
806 | 34 | m_result.__isset.name = true; | ||
807 | 35 | client()->createNotebook(m_result, token().toStdString(), m_result); | ||
808 | 36 | } | ||
809 | 37 | |||
810 | 38 | void CreateNotebookJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) | ||
811 | 39 | { | ||
812 | 40 | emit jobDone(errorCode, errorMessage, m_result); | ||
813 | 41 | } | ||
814 | 0 | 42 | ||
815 | === added file 'src/plugin/Evernote/jobs/createnotebookjob.h' | |||
816 | --- src/plugin/Evernote/jobs/createnotebookjob.h 1970-01-01 00:00:00 +0000 | |||
817 | +++ src/plugin/Evernote/jobs/createnotebookjob.h 2013-12-14 00:07:45 +0000 | |||
818 | @@ -0,0 +1,46 @@ | |||
819 | 1 | /* | ||
820 | 2 | * Copyright: 2013 Canonical, Ltd | ||
821 | 3 | * | ||
822 | 4 | * This file is part of reminders-app | ||
823 | 5 | * | ||
824 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
825 | 7 | * it under the terms of the GNU General Public License as published by | ||
826 | 8 | * the Free Software Foundation; version 3. | ||
827 | 9 | * | ||
828 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
829 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
830 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
831 | 13 | * GNU General Public License for more details. | ||
832 | 14 | * | ||
833 | 15 | * You should have received a copy of the GNU General Public License | ||
834 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
835 | 17 | * | ||
836 | 18 | * Authors: Michael Zanetti <michael.zanetti@canonical.com> | ||
837 | 19 | */ | ||
838 | 20 | |||
839 | 21 | #ifndef CREATENOTEBOOKJOB_H | ||
840 | 22 | #define CREATENOTEBOOKJOB_H | ||
841 | 23 | |||
842 | 24 | #include "notesstorejob.h" | ||
843 | 25 | |||
844 | 26 | class CreateNotebookJob : public NotesStoreJob | ||
845 | 27 | { | ||
846 | 28 | Q_OBJECT | ||
847 | 29 | public: | ||
848 | 30 | explicit CreateNotebookJob(const QString &name, QObject *parent = 0); | ||
849 | 31 | |||
850 | 32 | virtual void startJob() override; | ||
851 | 33 | |||
852 | 34 | signals: | ||
853 | 35 | void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Notebook &result); | ||
854 | 36 | |||
855 | 37 | private slots: | ||
856 | 38 | void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage); | ||
857 | 39 | |||
858 | 40 | private: | ||
859 | 41 | QString m_name; | ||
860 | 42 | |||
861 | 43 | evernote::edam::Notebook m_result; | ||
862 | 44 | }; | ||
863 | 45 | |||
864 | 46 | #endif // CREATENOTEBOOKJOB_H | ||
865 | 0 | 47 | ||
866 | === modified file 'src/plugin/Evernote/jobs/createnotejob.cpp' | |||
867 | --- src/plugin/Evernote/jobs/createnotejob.cpp 2013-11-26 17:18:33 +0000 | |||
868 | +++ src/plugin/Evernote/jobs/createnotejob.cpp 2013-12-14 00:07:45 +0000 | |||
869 | @@ -22,36 +22,30 @@ | |||
870 | 22 | 22 | ||
871 | 23 | #include <QDebug> | 23 | #include <QDebug> |
872 | 24 | 24 | ||
905 | 25 | CreateNoteJob::CreateNoteJob(Note *note, QObject *parent) : | 25 | CreateNoteJob::CreateNoteJob(const QString &title, const QString ¬ebookGuid, const QString &content, QObject *parent) : |
906 | 26 | EvernoteJob(parent), | 26 | NotesStoreJob(parent), |
907 | 27 | m_note(note) | 27 | m_title(title), |
908 | 28 | { | 28 | m_notebookGuid(notebookGuid), |
909 | 29 | } | 29 | m_content(content) |
910 | 30 | 30 | { | |
911 | 31 | void CreateNoteJob::run() | 31 | } |
912 | 32 | { | 32 | |
913 | 33 | NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; | 33 | void CreateNoteJob::startJob() |
914 | 34 | 34 | { | |
915 | 35 | try { | 35 | evernote::edam::Note input; |
916 | 36 | evernote::edam::Note input; | 36 | input.title = m_title.toStdString(); |
917 | 37 | input.title = m_note->title().toStdString(); | 37 | input.__isset.title = true; |
918 | 38 | input.__isset.title = true; | 38 | input.notebookGuid = m_notebookGuid.toStdString(); |
919 | 39 | input.notebookGuid = m_note->notebookGuid().toStdString(); | 39 | input.__isset.notebookGuid = true; |
920 | 40 | input.__isset.notebookGuid = true; | 40 | input.content = m_content.toStdString(); |
921 | 41 | input.content = m_note->content().toStdString(); | 41 | input.__isset.content = true; |
922 | 42 | input.__isset.content = true; | 42 | input.contentLength = m_content.length(); |
923 | 43 | input.contentLength = m_note->content().length(); | 43 | input.__isset.contentLength = true; |
924 | 44 | input.__isset.contentLength = true; | 44 | |
925 | 45 | 45 | client()->createNote(m_resultNote, token().toStdString(), input); | |
926 | 46 | evernote::edam::Note result; | 46 | } |
927 | 47 | client()->createNote(result, token().toStdString(), input); | 47 | |
928 | 48 | 48 | void CreateNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) | |
929 | 49 | m_note->setGuid(QString::fromStdString(result.guid)); | 49 | { |
930 | 50 | 50 | emit jobDone(errorCode, errorMessage, m_resultNote); | |
899 | 51 | } catch(evernote::edam::EDAMUserException e) { | ||
900 | 52 | errorCode = NotesStore::ErrorCodeUserException; | ||
901 | 53 | } catch(evernote::edam::EDAMSystemException) { | ||
902 | 54 | errorCode = NotesStore::ErrorCodeSystemException; | ||
903 | 55 | } | ||
904 | 56 | emit resultReady(errorCode, m_note); | ||
931 | 57 | } | 51 | } |
932 | 58 | 52 | ||
933 | === modified file 'src/plugin/Evernote/jobs/createnotejob.h' | |||
934 | --- src/plugin/Evernote/jobs/createnotejob.h 2013-11-25 00:49:48 +0000 | |||
935 | +++ src/plugin/Evernote/jobs/createnotejob.h 2013-12-14 00:07:45 +0000 | |||
936 | @@ -1,22 +1,27 @@ | |||
937 | 1 | #ifndef CREATENOTEJOB_H | 1 | #ifndef CREATENOTEJOB_H |
938 | 2 | #define CREATENOTEJOB_H | 2 | #define CREATENOTEJOB_H |
939 | 3 | 3 | ||
942 | 4 | #include "evernotejob.h" | 4 | #include "notesstorejob.h" |
941 | 5 | #include "note.h" | ||
943 | 6 | 5 | ||
945 | 7 | class CreateNoteJob : public EvernoteJob | 6 | class CreateNoteJob : public NotesStoreJob |
946 | 8 | { | 7 | { |
947 | 9 | Q_OBJECT | 8 | Q_OBJECT |
948 | 10 | public: | 9 | public: |
952 | 11 | explicit CreateNoteJob(Note *note, QObject *parent = 0); | 10 | explicit CreateNoteJob(const QString &title, const QString ¬ebookGuid, const QString &content, QObject *parent = 0); |
950 | 12 | |||
951 | 13 | void run(); | ||
953 | 14 | 11 | ||
954 | 15 | signals: | 12 | signals: |
956 | 16 | void resultReady(NotesStore::ErrorCode errorCode, Note *note); | 13 | void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, evernote::edam::Note note); |
957 | 14 | |||
958 | 15 | protected: | ||
959 | 16 | void startJob(); | ||
960 | 17 | void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage); | ||
961 | 17 | 18 | ||
962 | 18 | private: | 19 | private: |
964 | 19 | Note *m_note; | 20 | QString m_title; |
965 | 21 | QString m_notebookGuid; | ||
966 | 22 | QString m_content; | ||
967 | 23 | |||
968 | 24 | evernote::edam::Note m_resultNote; | ||
969 | 20 | }; | 25 | }; |
970 | 21 | 26 | ||
971 | 22 | #endif // CREATENOTEJOB_H | 27 | #endif // CREATENOTEJOB_H |
972 | 23 | 28 | ||
973 | === modified file 'src/plugin/Evernote/jobs/deletenotejob.cpp' | |||
974 | --- src/plugin/Evernote/jobs/deletenotejob.cpp 2013-11-26 17:18:33 +0000 | |||
975 | +++ src/plugin/Evernote/jobs/deletenotejob.cpp 2013-12-14 00:07:45 +0000 | |||
976 | @@ -21,18 +21,17 @@ | |||
977 | 21 | #include "deletenotejob.h" | 21 | #include "deletenotejob.h" |
978 | 22 | 22 | ||
979 | 23 | DeleteNoteJob::DeleteNoteJob(const QString &guid, QObject *parent): | 23 | DeleteNoteJob::DeleteNoteJob(const QString &guid, QObject *parent): |
981 | 24 | EvernoteJob(parent), | 24 | NotesStoreJob(parent), |
982 | 25 | m_guid(guid) | 25 | m_guid(guid) |
983 | 26 | { | 26 | { |
984 | 27 | } | 27 | } |
985 | 28 | 28 | ||
995 | 29 | void DeleteNoteJob::run() | 29 | void DeleteNoteJob::startJob() |
996 | 30 | { | 30 | { |
997 | 31 | NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; | 31 | client()->deleteNote(token().toStdString(), m_guid.toStdString()); |
998 | 32 | try { | 32 | } |
999 | 33 | client()->deleteNote(token().toStdString(), m_guid.toStdString()); | 33 | |
1000 | 34 | } catch(...) { | 34 | void DeleteNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) |
1001 | 35 | catchTransportException(); | 35 | { |
1002 | 36 | } | 36 | emit jobDone(errorCode, errorMessage, m_guid); |
994 | 37 | emit resultReady(errorCode, m_guid); | ||
1003 | 38 | } | 37 | } |
1004 | 39 | 38 | ||
1005 | === modified file 'src/plugin/Evernote/jobs/deletenotejob.h' | |||
1006 | --- src/plugin/Evernote/jobs/deletenotejob.h 2013-11-25 00:49:48 +0000 | |||
1007 | +++ src/plugin/Evernote/jobs/deletenotejob.h 2013-12-14 00:07:45 +0000 | |||
1008 | @@ -1,18 +1,20 @@ | |||
1009 | 1 | #ifndef DELETENOTEJOB_H | 1 | #ifndef DELETENOTEJOB_H |
1010 | 2 | #define DELETENOTEJOB_H | 2 | #define DELETENOTEJOB_H |
1011 | 3 | 3 | ||
1013 | 4 | #include "evernotejob.h" | 4 | #include "notesstorejob.h" |
1014 | 5 | 5 | ||
1016 | 6 | class DeleteNoteJob : public EvernoteJob | 6 | class DeleteNoteJob : public NotesStoreJob |
1017 | 7 | { | 7 | { |
1018 | 8 | Q_OBJECT | 8 | Q_OBJECT |
1019 | 9 | public: | 9 | public: |
1020 | 10 | DeleteNoteJob(const QString &guid, QObject *parent = 0); | 10 | DeleteNoteJob(const QString &guid, QObject *parent = 0); |
1021 | 11 | 11 | ||
1022 | 12 | void run(); | ||
1023 | 13 | |||
1024 | 14 | signals: | 12 | signals: |
1026 | 15 | void resultReady(NotesStore::ErrorCode errorCode, const QString &guid); | 13 | void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid); |
1027 | 14 | |||
1028 | 15 | protected: | ||
1029 | 16 | void startJob(); | ||
1030 | 17 | void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage); | ||
1031 | 16 | 18 | ||
1032 | 17 | private: | 19 | private: |
1033 | 18 | QString m_guid; | 20 | QString m_guid; |
1034 | 19 | 21 | ||
1035 | === modified file 'src/plugin/Evernote/jobs/evernotejob.cpp' | |||
1036 | --- src/plugin/Evernote/jobs/evernotejob.cpp 2013-11-26 17:18:33 +0000 | |||
1037 | +++ src/plugin/Evernote/jobs/evernotejob.cpp 2013-12-14 00:07:45 +0000 | |||
1038 | @@ -19,6 +19,7 @@ | |||
1039 | 19 | */ | 19 | */ |
1040 | 20 | 20 | ||
1041 | 21 | #include "evernotejob.h" | 21 | #include "evernotejob.h" |
1042 | 22 | #include "evernoteconnection.h" | ||
1043 | 22 | 23 | ||
1044 | 23 | // Thrift | 24 | // Thrift |
1045 | 24 | #include <arpa/inet.h> // seems thrift forgot this one | 25 | #include <arpa/inet.h> // seems thrift forgot this one |
1046 | @@ -35,35 +36,67 @@ | |||
1047 | 35 | 36 | ||
1048 | 36 | EvernoteJob::EvernoteJob(QObject *parent) : | 37 | EvernoteJob::EvernoteJob(QObject *parent) : |
1049 | 37 | QThread(parent), | 38 | QThread(parent), |
1051 | 38 | m_token(NotesStore::instance()->token()) | 39 | m_token(EvernoteConnection::instance()->token()) |
1052 | 39 | { | 40 | { |
1053 | 40 | connect(this, &EvernoteJob::finished, this, &EvernoteJob::deleteLater); | 41 | connect(this, &EvernoteJob::finished, this, &EvernoteJob::deleteLater); |
1054 | 41 | } | 42 | } |
1055 | 42 | 43 | ||
1056 | 43 | EvernoteJob::~EvernoteJob() | 44 | EvernoteJob::~EvernoteJob() |
1057 | 44 | { | 45 | { |
1058 | 45 | |||
1059 | 46 | } | 46 | } |
1060 | 47 | 47 | ||
1062 | 48 | evernote::edam::NoteStoreClient *EvernoteJob::client() | 48 | void EvernoteJob::run() |
1063 | 49 | { | 49 | { |
1065 | 50 | return NotesStore::instance()->m_client; | 50 | if (m_token.isEmpty()) { |
1066 | 51 | qWarning() << "No token set. Cannot execute job. (" << this->metaObject()->className() << ")"; | ||
1067 | 52 | emitJobDone(EvernoteConnection::ErrorCodeUserException, QStringLiteral("No token set.")); | ||
1068 | 53 | return; | ||
1069 | 54 | } | ||
1070 | 55 | |||
1071 | 56 | try { | ||
1072 | 57 | startJob(); | ||
1073 | 58 | } catch (const TTransportException & e) { | ||
1074 | 59 | |||
1075 | 60 | // The connection broke down. libthrift + evernote servers seem to be quite flaky | ||
1076 | 61 | // so lets try to start the job once more. | ||
1077 | 62 | qWarning() << "Got a transport exception:" << e.what() << ". Trying to reestablish connection..."; | ||
1078 | 63 | try { | ||
1079 | 64 | resetConnection(); | ||
1080 | 65 | startJob(); | ||
1081 | 66 | } catch (const TTransportException &e) { | ||
1082 | 67 | // Giving up... the connection seems to be down for real. | ||
1083 | 68 | qWarning() << "Cannot reestablish connection:" << e.what(); | ||
1084 | 69 | emitJobDone(EvernoteConnection::ErrorCodeConnectionLost, e.what()); | ||
1085 | 70 | } catch (const TApplicationException &e) { | ||
1086 | 71 | qWarning() << "Cannot reestablish connection:" << e.what(); | ||
1087 | 72 | emitJobDone(EvernoteConnection::ErrorCodeConnectionLost, e.what()); | ||
1088 | 73 | } catch (const evernote::edam::EDAMUserException &e) { | ||
1089 | 74 | qWarning() << "EDAMUserException" << e.what(); | ||
1090 | 75 | emitJobDone(EvernoteConnection::ErrorCodeUserException, e.what()); | ||
1091 | 76 | } catch (const evernote::edam::EDAMSystemException &e) { | ||
1092 | 77 | qWarning() << "EDAMSystemException" << e.what(); | ||
1093 | 78 | emitJobDone(EvernoteConnection::ErrorCodeSystemException, e.what()); | ||
1094 | 79 | } catch (const evernote::edam::EDAMNotFoundException &e) { | ||
1095 | 80 | qWarning() << "EDAMNotFoundException" << e.what(); | ||
1096 | 81 | emitJobDone(EvernoteConnection::ErrorCodeNotFoundExcpetion, e.what()); | ||
1097 | 82 | } | ||
1098 | 83 | |||
1099 | 84 | |||
1100 | 85 | } catch (const evernote::edam::EDAMUserException &e) { | ||
1101 | 86 | qWarning() << "EDAMUserException" << e.what(); | ||
1102 | 87 | emitJobDone(EvernoteConnection::ErrorCodeUserException, e.what()); | ||
1103 | 88 | } catch (const evernote::edam::EDAMSystemException &e) { | ||
1104 | 89 | qWarning() << "EDAMSystemException" << e.what(); | ||
1105 | 90 | emitJobDone(EvernoteConnection::ErrorCodeSystemException, e.what()); | ||
1106 | 91 | } catch (const evernote::edam::EDAMNotFoundException &e) { | ||
1107 | 92 | qWarning() << "EDAMNotFoundException" << e.what(); | ||
1108 | 93 | emitJobDone(EvernoteConnection::ErrorCodeNotFoundExcpetion, e.what()); | ||
1109 | 94 | } | ||
1110 | 95 | |||
1111 | 96 | emitJobDone(EvernoteConnection::ErrorCodeNoError, QString()); | ||
1112 | 51 | } | 97 | } |
1113 | 52 | 98 | ||
1114 | 53 | QString EvernoteJob::token() | 99 | QString EvernoteJob::token() |
1115 | 54 | { | 100 | { |
1116 | 55 | return m_token; | 101 | return m_token; |
1117 | 56 | } | 102 | } |
1118 | 57 | |||
1119 | 58 | void EvernoteJob::catchTransportException() | ||
1120 | 59 | { | ||
1121 | 60 | try { | ||
1122 | 61 | // this function is meant to be called from a catch block | ||
1123 | 62 | // rethrow the exception to catch it again | ||
1124 | 63 | throw; | ||
1125 | 64 | } catch (const TTransportException & e) { | ||
1126 | 65 | qDebug() << e.what(); | ||
1127 | 66 | } catch (const TException & e) { | ||
1128 | 67 | qDebug() << e.what(); | ||
1129 | 68 | } | ||
1130 | 69 | } | ||
1131 | 70 | 103 | ||
1132 | === modified file 'src/plugin/Evernote/jobs/evernotejob.h' | |||
1133 | --- src/plugin/Evernote/jobs/evernotejob.h 2013-11-25 00:49:48 +0000 | |||
1134 | +++ src/plugin/Evernote/jobs/evernotejob.h 2013-12-14 00:07:45 +0000 | |||
1135 | @@ -3,13 +3,21 @@ | |||
1136 | 3 | 3 | ||
1137 | 4 | #include "notesstore.h" | 4 | #include "notesstore.h" |
1138 | 5 | 5 | ||
1139 | 6 | // Evernote SDK | ||
1140 | 7 | #include <NoteStore.h> | ||
1141 | 8 | #include <NoteStore_constants.h> | ||
1142 | 9 | #include <Errors_types.h> | ||
1143 | 10 | |||
1144 | 11 | #include <QThread> | 6 | #include <QThread> |
1145 | 12 | 7 | ||
1146 | 8 | /* How to create a new Job type: | ||
1147 | 9 | * - Subclass EvernoteJob | ||
1148 | 10 | * - Implement startJob() in which you do the call to evernote. | ||
1149 | 11 | * - No need to catch exceptions, EvernoteJob will deal with those. | ||
1150 | 12 | * - Define a jobDone() signal with the result parameters you need. | ||
1151 | 13 | * - Keep the convention of jobDone(EvernoteConnection::ErrorCode errorCode, const QString &message [, ...]) | ||
1152 | 14 | * - Emit jobDone() in your implementation of emitJobDone(). | ||
1153 | 15 | * - NOTE: emitJobDone() might be called with an error even before startJob() is triggered. | ||
1154 | 16 | * | ||
1155 | 17 | * Jobs can be enqueue()d in NotesStore. | ||
1156 | 18 | * They will destroy themselves when finished. | ||
1157 | 19 | * The jobqueue will take care about starting them. | ||
1158 | 20 | */ | ||
1159 | 13 | class EvernoteJob : public QThread | 21 | class EvernoteJob : public QThread |
1160 | 14 | { | 22 | { |
1161 | 15 | Q_OBJECT | 23 | Q_OBJECT |
1162 | @@ -17,12 +25,18 @@ | |||
1163 | 17 | explicit EvernoteJob(QObject *parent = 0); | 25 | explicit EvernoteJob(QObject *parent = 0); |
1164 | 18 | virtual ~EvernoteJob(); | 26 | virtual ~EvernoteJob(); |
1165 | 19 | 27 | ||
1166 | 28 | void run() final; | ||
1167 | 29 | |||
1168 | 30 | signals: | ||
1169 | 31 | void connectionLost(const QString &errorMessage); | ||
1170 | 32 | |||
1171 | 20 | protected: | 33 | protected: |
1173 | 21 | evernote::edam::NoteStoreClient* client(); | 34 | virtual void resetConnection() = 0; |
1174 | 35 | virtual void startJob() = 0; | ||
1175 | 36 | virtual void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) = 0; | ||
1176 | 37 | |||
1177 | 22 | QString token(); | 38 | QString token(); |
1178 | 23 | 39 | ||
1179 | 24 | void catchTransportException(); | ||
1180 | 25 | |||
1181 | 26 | private: | 40 | private: |
1182 | 27 | QString m_token; | 41 | QString m_token; |
1183 | 28 | }; | 42 | }; |
1184 | 29 | 43 | ||
1185 | === added file 'src/plugin/Evernote/jobs/expungenotebookjob.cpp' | |||
1186 | --- src/plugin/Evernote/jobs/expungenotebookjob.cpp 1970-01-01 00:00:00 +0000 | |||
1187 | +++ src/plugin/Evernote/jobs/expungenotebookjob.cpp 2013-12-14 00:07:45 +0000 | |||
1188 | @@ -0,0 +1,39 @@ | |||
1189 | 1 | /* | ||
1190 | 2 | * Copyright: 2013 Canonical, Ltd | ||
1191 | 3 | * | ||
1192 | 4 | * This file is part of reminders-app | ||
1193 | 5 | * | ||
1194 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
1195 | 7 | * it under the terms of the GNU General Public License as published by | ||
1196 | 8 | * the Free Software Foundation; version 3. | ||
1197 | 9 | * | ||
1198 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
1199 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1200 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1201 | 13 | * GNU General Public License for more details. | ||
1202 | 14 | * | ||
1203 | 15 | * You should have received a copy of the GNU General Public License | ||
1204 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1205 | 17 | * | ||
1206 | 18 | * Authors: Michael Zanetti <michael.zanetti@canonical.com> | ||
1207 | 19 | */ | ||
1208 | 20 | |||
1209 | 21 | #include "expungenotebookjob.h" | ||
1210 | 22 | |||
1211 | 23 | #include <QDebug> | ||
1212 | 24 | |||
1213 | 25 | ExpungeNotebookJob::ExpungeNotebookJob(const QString &guid, QObject *parent) : | ||
1214 | 26 | NotesStoreJob(parent), | ||
1215 | 27 | m_guid(guid) | ||
1216 | 28 | { | ||
1217 | 29 | } | ||
1218 | 30 | |||
1219 | 31 | void ExpungeNotebookJob::startJob() | ||
1220 | 32 | { | ||
1221 | 33 | client()->expungeNotebook(token().toStdString(), m_guid.toStdString()); | ||
1222 | 34 | } | ||
1223 | 35 | |||
1224 | 36 | void ExpungeNotebookJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) | ||
1225 | 37 | { | ||
1226 | 38 | emit jobDone(errorCode, errorMessage, m_guid); | ||
1227 | 39 | } | ||
1228 | 0 | 40 | ||
1229 | === added file 'src/plugin/Evernote/jobs/expungenotebookjob.h' | |||
1230 | --- src/plugin/Evernote/jobs/expungenotebookjob.h 1970-01-01 00:00:00 +0000 | |||
1231 | +++ src/plugin/Evernote/jobs/expungenotebookjob.h 2013-12-14 00:07:45 +0000 | |||
1232 | @@ -0,0 +1,43 @@ | |||
1233 | 1 | /* | ||
1234 | 2 | * Copyright: 2013 Canonical, Ltd | ||
1235 | 3 | * | ||
1236 | 4 | * This file is part of reminders-app | ||
1237 | 5 | * | ||
1238 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
1239 | 7 | * it under the terms of the GNU General Public License as published by | ||
1240 | 8 | * the Free Software Foundation; version 3. | ||
1241 | 9 | * | ||
1242 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
1243 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1244 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1245 | 13 | * GNU General Public License for more details. | ||
1246 | 14 | * | ||
1247 | 15 | * You should have received a copy of the GNU General Public License | ||
1248 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1249 | 17 | * | ||
1250 | 18 | * Authors: Michael Zanetti <michael.zanetti@canonical.com> | ||
1251 | 19 | */ | ||
1252 | 20 | |||
1253 | 21 | #ifndef DELETENOTEBOOKJOB_H | ||
1254 | 22 | #define DELETENOTEBOOKJOB_H | ||
1255 | 23 | |||
1256 | 24 | #include "notesstorejob.h" | ||
1257 | 25 | |||
1258 | 26 | class ExpungeNotebookJob : public NotesStoreJob | ||
1259 | 27 | { | ||
1260 | 28 | Q_OBJECT | ||
1261 | 29 | public: | ||
1262 | 30 | explicit ExpungeNotebookJob(const QString &guid, QObject *parent = 0); | ||
1263 | 31 | |||
1264 | 32 | signals: | ||
1265 | 33 | void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid); | ||
1266 | 34 | |||
1267 | 35 | private slots: | ||
1268 | 36 | void startJob(); | ||
1269 | 37 | void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage); | ||
1270 | 38 | |||
1271 | 39 | private: | ||
1272 | 40 | QString m_guid; | ||
1273 | 41 | }; | ||
1274 | 42 | |||
1275 | 43 | #endif // DELETENOTEBOOKJOB_H | ||
1276 | 0 | 44 | ||
1277 | === modified file 'src/plugin/Evernote/jobs/fetchnotebooksjob.cpp' | |||
1278 | --- src/plugin/Evernote/jobs/fetchnotebooksjob.cpp 2013-11-26 17:18:33 +0000 | |||
1279 | +++ src/plugin/Evernote/jobs/fetchnotebooksjob.cpp 2013-12-14 00:07:45 +0000 | |||
1280 | @@ -23,21 +23,17 @@ | |||
1281 | 23 | #include <QDebug> | 23 | #include <QDebug> |
1282 | 24 | 24 | ||
1283 | 25 | FetchNotebooksJob::FetchNotebooksJob(QObject *parent) : | 25 | FetchNotebooksJob::FetchNotebooksJob(QObject *parent) : |
1301 | 26 | EvernoteJob(parent) | 26 | NotesStoreJob(parent) |
1302 | 27 | { | 27 | { |
1303 | 28 | } | 28 | } |
1304 | 29 | 29 | ||
1305 | 30 | 30 | ||
1306 | 31 | void FetchNotebooksJob::run() | 31 | void FetchNotebooksJob::startJob() |
1307 | 32 | { | 32 | { |
1308 | 33 | NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; | 33 | client()->listNotebooks(m_results, token().toStdString()); |
1309 | 34 | std::vector<evernote::edam::Notebook> results; | 34 | } |
1310 | 35 | try { | 35 | |
1311 | 36 | client()->listNotebooks(results, token().toStdString()); | 36 | void FetchNotebooksJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) |
1312 | 37 | } catch(evernote::edam::EDAMUserException) { | 37 | { |
1313 | 38 | errorCode = NotesStore::ErrorCodeUserException; | 38 | emit jobDone(errorCode, errorMessage, m_results); |
1297 | 39 | } catch(evernote::edam::EDAMSystemException) { | ||
1298 | 40 | errorCode = NotesStore::ErrorCodeSystemException; | ||
1299 | 41 | } | ||
1300 | 42 | emit resultReady(errorCode, results); | ||
1314 | 43 | } | 39 | } |
1315 | 44 | 40 | ||
1316 | === modified file 'src/plugin/Evernote/jobs/fetchnotebooksjob.h' | |||
1317 | --- src/plugin/Evernote/jobs/fetchnotebooksjob.h 2013-11-25 00:49:48 +0000 | |||
1318 | +++ src/plugin/Evernote/jobs/fetchnotebooksjob.h 2013-12-14 00:07:45 +0000 | |||
1319 | @@ -1,18 +1,23 @@ | |||
1320 | 1 | #ifndef FETCHNOTEBOOKSJOB_H | 1 | #ifndef FETCHNOTEBOOKSJOB_H |
1321 | 2 | #define FETCHNOTEBOOKSJOB_H | 2 | #define FETCHNOTEBOOKSJOB_H |
1322 | 3 | 3 | ||
1324 | 4 | #include "evernotejob.h" | 4 | #include "notesstorejob.h" |
1325 | 5 | 5 | ||
1327 | 6 | class FetchNotebooksJob : public EvernoteJob | 6 | class FetchNotebooksJob : public NotesStoreJob |
1328 | 7 | { | 7 | { |
1329 | 8 | Q_OBJECT | 8 | Q_OBJECT |
1330 | 9 | public: | 9 | public: |
1331 | 10 | explicit FetchNotebooksJob(QObject *parent = 0); | 10 | explicit FetchNotebooksJob(QObject *parent = 0); |
1332 | 11 | 11 | ||
1333 | 12 | void run(); | ||
1334 | 13 | |||
1335 | 14 | signals: | 12 | signals: |
1337 | 15 | void resultReady(NotesStore::ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results); | 13 | void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results); |
1338 | 14 | |||
1339 | 15 | protected: | ||
1340 | 16 | void startJob(); | ||
1341 | 17 | void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage); | ||
1342 | 18 | |||
1343 | 19 | private: | ||
1344 | 20 | std::vector<evernote::edam::Notebook> m_results; | ||
1345 | 16 | }; | 21 | }; |
1346 | 17 | 22 | ||
1347 | 18 | #endif // FETCHNOTEBOOKSJOB_H | 23 | #endif // FETCHNOTEBOOKSJOB_H |
1348 | 19 | 24 | ||
1349 | === modified file 'src/plugin/Evernote/jobs/fetchnotejob.cpp' | |||
1350 | --- src/plugin/Evernote/jobs/fetchnotejob.cpp 2013-11-26 17:18:33 +0000 | |||
1351 | +++ src/plugin/Evernote/jobs/fetchnotejob.cpp 2013-12-14 00:07:45 +0000 | |||
1352 | @@ -21,27 +21,17 @@ | |||
1353 | 21 | #include "fetchnotejob.h" | 21 | #include "fetchnotejob.h" |
1354 | 22 | 22 | ||
1355 | 23 | FetchNoteJob::FetchNoteJob(const QString &guid, QObject *parent) : | 23 | FetchNoteJob::FetchNoteJob(const QString &guid, QObject *parent) : |
1357 | 24 | EvernoteJob(parent), | 24 | NotesStoreJob(parent), |
1358 | 25 | m_guid(guid) | 25 | m_guid(guid) |
1359 | 26 | { | 26 | { |
1360 | 27 | } | 27 | } |
1361 | 28 | 28 | ||
1363 | 29 | void FetchNoteJob::run() | 29 | void FetchNoteJob::startJob() |
1364 | 30 | { | 30 | { |
1379 | 31 | NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; | 31 | client()->getNote(m_result, token().toStdString(), m_guid.toStdString(), true, false, false, false); |
1380 | 32 | evernote::edam::Note result; | 32 | } |
1367 | 33 | try { | ||
1368 | 34 | client()->getNote(result, token().toStdString(), m_guid.toStdString(), true, true, false, false); | ||
1369 | 35 | } catch (evernote::edam::EDAMUserException) { | ||
1370 | 36 | errorCode = NotesStore::ErrorCodeUserException; | ||
1371 | 37 | } catch (evernote::edam::EDAMSystemException) { | ||
1372 | 38 | errorCode = NotesStore::ErrorCodeSystemException; | ||
1373 | 39 | } catch (evernote::edam::EDAMNotFoundException) { | ||
1374 | 40 | errorCode = NotesStore::ErrorCodeNotFoundExcpetion; | ||
1375 | 41 | } catch (...) { | ||
1376 | 42 | catchTransportException(); | ||
1377 | 43 | errorCode = NotesStore::ErrorCodeConnectionLost; | ||
1378 | 44 | } | ||
1381 | 45 | 33 | ||
1383 | 46 | emit resultReady(errorCode, result); | 34 | void FetchNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) |
1384 | 35 | { | ||
1385 | 36 | emit resultReady(errorCode, errorMessage, m_result); | ||
1386 | 47 | } | 37 | } |
1387 | 48 | 38 | ||
1388 | === modified file 'src/plugin/Evernote/jobs/fetchnotejob.h' | |||
1389 | --- src/plugin/Evernote/jobs/fetchnotejob.h 2013-11-25 00:49:48 +0000 | |||
1390 | +++ src/plugin/Evernote/jobs/fetchnotejob.h 2013-12-14 00:07:45 +0000 | |||
1391 | @@ -1,22 +1,28 @@ | |||
1392 | 1 | #ifndef FETCHNOTEJOB_H | 1 | #ifndef FETCHNOTEJOB_H |
1393 | 2 | #define FETCHNOTEJOB_H | 2 | #define FETCHNOTEJOB_H |
1394 | 3 | 3 | ||
1396 | 4 | #include "evernotejob.h" | 4 | #include "notesstorejob.h" |
1397 | 5 | 5 | ||
1399 | 6 | class FetchNoteJob : public EvernoteJob | 6 | class FetchNoteJob : public NotesStoreJob |
1400 | 7 | { | 7 | { |
1401 | 8 | Q_OBJECT | 8 | Q_OBJECT |
1402 | 9 | public: | 9 | public: |
1403 | 10 | explicit FetchNoteJob(const QString &guid, QObject *parent = 0); | 10 | explicit FetchNoteJob(const QString &guid, QObject *parent = 0); |
1404 | 11 | 11 | ||
1405 | 12 | void run(); | ||
1406 | 13 | signals: | 12 | signals: |
1408 | 14 | void resultReady(NotesStore::ErrorCode error, const evernote::edam::Note ¬e); | 13 | void resultReady(EvernoteConnection::ErrorCode error, const QString &errorMessage, const evernote::edam::Note ¬e); |
1409 | 14 | |||
1410 | 15 | protected: | ||
1411 | 16 | void startJob(); | ||
1412 | 17 | void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage); | ||
1413 | 15 | 18 | ||
1414 | 16 | private: | 19 | private: |
1415 | 17 | evernote::edam::NoteStoreClient *m_client; | 20 | evernote::edam::NoteStoreClient *m_client; |
1416 | 18 | QString m_token; | 21 | QString m_token; |
1417 | 19 | QString m_guid; | 22 | QString m_guid; |
1418 | 23 | |||
1419 | 24 | evernote::edam::Note m_result; | ||
1420 | 25 | |||
1421 | 20 | }; | 26 | }; |
1422 | 21 | 27 | ||
1423 | 22 | #endif // FETCHNOTEJOB_H | 28 | #endif // FETCHNOTEJOB_H |
1424 | 23 | 29 | ||
1425 | === modified file 'src/plugin/Evernote/jobs/fetchnotesjob.cpp' | |||
1426 | --- src/plugin/Evernote/jobs/fetchnotesjob.cpp 2013-11-26 17:18:33 +0000 | |||
1427 | +++ src/plugin/Evernote/jobs/fetchnotesjob.cpp 2013-12-14 00:07:45 +0000 | |||
1428 | @@ -22,43 +22,52 @@ | |||
1429 | 22 | 22 | ||
1430 | 23 | #include "notesstore.h" | 23 | #include "notesstore.h" |
1431 | 24 | 24 | ||
1432 | 25 | // evernote sdk | ||
1433 | 26 | #include "Limits_constants.h" | ||
1434 | 27 | |||
1435 | 25 | #include <QDebug> | 28 | #include <QDebug> |
1436 | 26 | 29 | ||
1440 | 27 | FetchNotesJob::FetchNotesJob( const QString &filterNotebookGuid, QObject *parent) : | 30 | FetchNotesJob::FetchNotesJob(const QString &filterNotebookGuid, const QString &searchWords, QObject *parent) : |
1441 | 28 | EvernoteJob(parent), | 31 | NotesStoreJob(parent), |
1442 | 29 | m_filterNotebookGuid(filterNotebookGuid) | 32 | m_filterNotebookGuid(filterNotebookGuid), |
1443 | 33 | m_searchWords(searchWords) | ||
1444 | 30 | { | 34 | { |
1445 | 31 | } | 35 | } |
1446 | 32 | 36 | ||
1448 | 33 | void FetchNotesJob::run() | 37 | void FetchNotesJob::startJob() |
1449 | 34 | { | 38 | { |
1450 | 35 | // TODO: fix start/end (use smaller chunks and continue fetching if there are more notes available) | 39 | // TODO: fix start/end (use smaller chunks and continue fetching if there are more notes available) |
1451 | 36 | int32_t start = 0; | 40 | int32_t start = 0; |
1453 | 37 | int32_t end = 10000; | 41 | evernote::limits::LimitsConstants limits; |
1454 | 42 | int32_t end = limits.EDAM_USER_NOTES_MAX; | ||
1455 | 38 | 43 | ||
1456 | 39 | // Prepare filter | 44 | // Prepare filter |
1457 | 40 | evernote::edam::NoteFilter filter; | 45 | evernote::edam::NoteFilter filter; |
1458 | 41 | filter.notebookGuid = m_filterNotebookGuid.toStdString(); | 46 | filter.notebookGuid = m_filterNotebookGuid.toStdString(); |
1459 | 42 | filter.__isset.notebookGuid = !m_filterNotebookGuid.isEmpty(); | 47 | filter.__isset.notebookGuid = !m_filterNotebookGuid.isEmpty(); |
1460 | 43 | 48 | ||
1461 | 49 | filter.words = m_searchWords.toStdString(); | ||
1462 | 50 | filter.__isset.words = !m_searchWords.isEmpty(); | ||
1463 | 51 | |||
1464 | 44 | // Prepare ResultSpec | 52 | // Prepare ResultSpec |
1465 | 45 | evernote::edam::NotesMetadataResultSpec resultSpec; | 53 | evernote::edam::NotesMetadataResultSpec resultSpec; |
1466 | 54 | |||
1467 | 46 | resultSpec.includeNotebookGuid = true; | 55 | resultSpec.includeNotebookGuid = true; |
1468 | 47 | resultSpec.__isset.includeNotebookGuid = true; | 56 | resultSpec.__isset.includeNotebookGuid = true; |
1469 | 57 | |||
1470 | 58 | resultSpec.includeCreated = true; | ||
1471 | 59 | resultSpec.__isset.includeCreated = true; | ||
1472 | 60 | |||
1473 | 48 | resultSpec.includeTitle = true; | 61 | resultSpec.includeTitle = true; |
1474 | 49 | resultSpec.__isset.includeTitle = true; | 62 | resultSpec.__isset.includeTitle = true; |
1475 | 50 | 63 | ||
1489 | 51 | NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; | 64 | resultSpec.includeAttributes = true; |
1490 | 52 | evernote::edam::NotesMetadataList results; | 65 | resultSpec.__isset.includeAttributes = true; |
1491 | 53 | 66 | ||
1492 | 54 | try { | 67 | client()->findNotesMetadata(m_results, token().toStdString(), filter, start, end, resultSpec); |
1493 | 55 | client()->findNotesMetadata(results, token().toStdString(), filter, start, end, resultSpec); | 68 | } |
1494 | 56 | } catch(evernote::edam::EDAMUserException) { | 69 | |
1495 | 57 | errorCode = NotesStore::ErrorCodeUserException; | 70 | void FetchNotesJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) |
1496 | 58 | } catch(evernote::edam::EDAMSystemException) { | 71 | { |
1497 | 59 | errorCode = NotesStore::ErrorCodeSystemException; | 72 | emit jobDone(errorCode, errorMessage, m_results); |
1485 | 60 | } catch(evernote::edam::EDAMNotFoundException) { | ||
1486 | 61 | errorCode = NotesStore::ErrorCodeNotFoundExcpetion; | ||
1487 | 62 | } | ||
1488 | 63 | emit resultReady(errorCode, results); | ||
1498 | 64 | } | 73 | } |
1499 | 65 | 74 | ||
1500 | === modified file 'src/plugin/Evernote/jobs/fetchnotesjob.h' | |||
1501 | --- src/plugin/Evernote/jobs/fetchnotesjob.h 2013-11-25 00:49:48 +0000 | |||
1502 | +++ src/plugin/Evernote/jobs/fetchnotesjob.h 2013-12-14 00:07:45 +0000 | |||
1503 | @@ -1,21 +1,25 @@ | |||
1504 | 1 | #ifndef FETCHNOTESJOB_H | 1 | #ifndef FETCHNOTESJOB_H |
1505 | 2 | #define FETCHNOTESJOB_H | 2 | #define FETCHNOTESJOB_H |
1506 | 3 | 3 | ||
1508 | 4 | #include "evernotejob.h" | 4 | #include "notesstorejob.h" |
1509 | 5 | 5 | ||
1511 | 6 | class FetchNotesJob : public EvernoteJob | 6 | class FetchNotesJob : public NotesStoreJob |
1512 | 7 | { | 7 | { |
1513 | 8 | Q_OBJECT | 8 | Q_OBJECT |
1514 | 9 | public: | 9 | public: |
1518 | 10 | explicit FetchNotesJob(const QString &filterNotebookGuid, QObject *parent = 0); | 10 | explicit FetchNotesJob(const QString &filterNotebookGuid = QString(), const QString &searchWords = QString(), QObject *parent = 0); |
1516 | 11 | |||
1517 | 12 | void run(); | ||
1519 | 13 | 11 | ||
1520 | 14 | signals: | 12 | signals: |
1522 | 15 | void resultReady(NotesStore::ErrorCode errorCode, const evernote::edam::NotesMetadataList &results); | 13 | void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results); |
1523 | 14 | |||
1524 | 15 | protected: | ||
1525 | 16 | void startJob(); | ||
1526 | 17 | void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage); | ||
1527 | 16 | 18 | ||
1528 | 17 | private: | 19 | private: |
1529 | 18 | QString m_filterNotebookGuid; | 20 | QString m_filterNotebookGuid; |
1530 | 21 | QString m_searchWords; | ||
1531 | 22 | evernote::edam::NotesMetadataList m_results; | ||
1532 | 19 | }; | 23 | }; |
1533 | 20 | 24 | ||
1534 | 21 | #endif // FETCHNOTESJOB_H | 25 | #endif // FETCHNOTESJOB_H |
1535 | 22 | 26 | ||
1536 | === added file 'src/plugin/Evernote/jobs/fetchusernamejob.cpp' | |||
1537 | --- src/plugin/Evernote/jobs/fetchusernamejob.cpp 1970-01-01 00:00:00 +0000 | |||
1538 | +++ src/plugin/Evernote/jobs/fetchusernamejob.cpp 2013-12-14 00:07:45 +0000 | |||
1539 | @@ -0,0 +1,38 @@ | |||
1540 | 1 | /* | ||
1541 | 2 | * Copyright: 2013 Canonical, Ltd | ||
1542 | 3 | * | ||
1543 | 4 | * This file is part of reminders-app | ||
1544 | 5 | * | ||
1545 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
1546 | 7 | * it under the terms of the GNU General Public License as published by | ||
1547 | 8 | * the Free Software Foundation; version 3. | ||
1548 | 9 | * | ||
1549 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
1550 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1551 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1552 | 13 | * GNU General Public License for more details. | ||
1553 | 14 | * | ||
1554 | 15 | * You should have received a copy of the GNU General Public License | ||
1555 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1556 | 17 | * | ||
1557 | 18 | * Authors: Michael Zanetti <michael.zanetti@canonical.com> | ||
1558 | 19 | */ | ||
1559 | 20 | |||
1560 | 21 | #include "fetchusernamejob.h" | ||
1561 | 22 | |||
1562 | 23 | FetchUsernameJob::FetchUsernameJob(QObject *parent) : | ||
1563 | 24 | UserStoreJob(parent) | ||
1564 | 25 | { | ||
1565 | 26 | } | ||
1566 | 27 | |||
1567 | 28 | void FetchUsernameJob::startJob() | ||
1568 | 29 | { | ||
1569 | 30 | evernote::edam::User user; | ||
1570 | 31 | client()->getUser(user, token().toStdString()); | ||
1571 | 32 | m_result = QString::fromStdString(user.username); | ||
1572 | 33 | } | ||
1573 | 34 | |||
1574 | 35 | void FetchUsernameJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) | ||
1575 | 36 | { | ||
1576 | 37 | emit jobDone(errorCode, errorMessage, m_result); | ||
1577 | 38 | } | ||
1578 | 0 | 39 | ||
1579 | === added file 'src/plugin/Evernote/jobs/fetchusernamejob.h' | |||
1580 | --- src/plugin/Evernote/jobs/fetchusernamejob.h 1970-01-01 00:00:00 +0000 | |||
1581 | +++ src/plugin/Evernote/jobs/fetchusernamejob.h 2013-12-14 00:07:45 +0000 | |||
1582 | @@ -0,0 +1,43 @@ | |||
1583 | 1 | /* | ||
1584 | 2 | * Copyright: 2013 Canonical, Ltd | ||
1585 | 3 | * | ||
1586 | 4 | * This file is part of reminders-app | ||
1587 | 5 | * | ||
1588 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
1589 | 7 | * it under the terms of the GNU General Public License as published by | ||
1590 | 8 | * the Free Software Foundation; version 3. | ||
1591 | 9 | * | ||
1592 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
1593 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1594 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1595 | 13 | * GNU General Public License for more details. | ||
1596 | 14 | * | ||
1597 | 15 | * You should have received a copy of the GNU General Public License | ||
1598 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1599 | 17 | * | ||
1600 | 18 | * Authors: Michael Zanetti <michael.zanetti@canonical.com> | ||
1601 | 19 | */ | ||
1602 | 20 | |||
1603 | 21 | #ifndef FETCHUSERNAMEJOB_H | ||
1604 | 22 | #define FETCHUSERNAMEJOB_H | ||
1605 | 23 | |||
1606 | 24 | #include "userstorejob.h" | ||
1607 | 25 | |||
1608 | 26 | class FetchUsernameJob : public UserStoreJob | ||
1609 | 27 | { | ||
1610 | 28 | Q_OBJECT | ||
1611 | 29 | public: | ||
1612 | 30 | explicit FetchUsernameJob(QObject *parent = 0); | ||
1613 | 31 | |||
1614 | 32 | signals: | ||
1615 | 33 | void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result); | ||
1616 | 34 | |||
1617 | 35 | protected: | ||
1618 | 36 | void startJob(); | ||
1619 | 37 | void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage); | ||
1620 | 38 | |||
1621 | 39 | private: | ||
1622 | 40 | QString m_result; | ||
1623 | 41 | }; | ||
1624 | 42 | |||
1625 | 43 | #endif // FETCHUSERNAMEJOB_H | ||
1626 | 0 | 44 | ||
1627 | === added file 'src/plugin/Evernote/jobs/notesstorejob.cpp' | |||
1628 | --- src/plugin/Evernote/jobs/notesstorejob.cpp 1970-01-01 00:00:00 +0000 | |||
1629 | +++ src/plugin/Evernote/jobs/notesstorejob.cpp 2013-12-14 00:07:45 +0000 | |||
1630 | @@ -0,0 +1,39 @@ | |||
1631 | 1 | /* | ||
1632 | 2 | * Copyright: 2013 Canonical, Ltd | ||
1633 | 3 | * | ||
1634 | 4 | * This file is part of reminders-app | ||
1635 | 5 | * | ||
1636 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
1637 | 7 | * it under the terms of the GNU General Public License as published by | ||
1638 | 8 | * the Free Software Foundation; version 3. | ||
1639 | 9 | * | ||
1640 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
1641 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1642 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1643 | 13 | * GNU General Public License for more details. | ||
1644 | 14 | * | ||
1645 | 15 | * You should have received a copy of the GNU General Public License | ||
1646 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1647 | 17 | * | ||
1648 | 18 | * Authors: Michael Zanetti <michael.zanetti@canonical.com> | ||
1649 | 19 | */ | ||
1650 | 20 | |||
1651 | 21 | #include "notesstorejob.h" | ||
1652 | 22 | |||
1653 | 23 | #include "evernoteconnection.h" | ||
1654 | 24 | |||
1655 | 25 | NotesStoreJob::NotesStoreJob(QObject *parent) : | ||
1656 | 26 | EvernoteJob(parent) | ||
1657 | 27 | { | ||
1658 | 28 | } | ||
1659 | 29 | |||
1660 | 30 | void NotesStoreJob::resetConnection() | ||
1661 | 31 | { | ||
1662 | 32 | EvernoteConnection::instance()->m_notesStoreHttpClient->close(); | ||
1663 | 33 | EvernoteConnection::instance()->m_notesStoreHttpClient->open(); | ||
1664 | 34 | } | ||
1665 | 35 | |||
1666 | 36 | evernote::edam::NoteStoreClient *NotesStoreJob::client() const | ||
1667 | 37 | { | ||
1668 | 38 | return EvernoteConnection::instance()->m_notesStoreClient; | ||
1669 | 39 | } | ||
1670 | 0 | 40 | ||
1671 | === added file 'src/plugin/Evernote/jobs/notesstorejob.h' | |||
1672 | --- src/plugin/Evernote/jobs/notesstorejob.h 1970-01-01 00:00:00 +0000 | |||
1673 | +++ src/plugin/Evernote/jobs/notesstorejob.h 2013-12-14 00:07:45 +0000 | |||
1674 | @@ -0,0 +1,44 @@ | |||
1675 | 1 | /* | ||
1676 | 2 | * Copyright: 2013 Canonical, Ltd | ||
1677 | 3 | * | ||
1678 | 4 | * This file is part of reminders-app | ||
1679 | 5 | * | ||
1680 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
1681 | 7 | * it under the terms of the GNU General Public License as published by | ||
1682 | 8 | * the Free Software Foundation; version 3. | ||
1683 | 9 | * | ||
1684 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
1685 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1686 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1687 | 13 | * GNU General Public License for more details. | ||
1688 | 14 | * | ||
1689 | 15 | * You should have received a copy of the GNU General Public License | ||
1690 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1691 | 17 | * | ||
1692 | 18 | * Authors: Michael Zanetti <michael.zanetti@canonical.com> | ||
1693 | 19 | */ | ||
1694 | 20 | |||
1695 | 21 | #ifndef NOTESSTOREJOB_H | ||
1696 | 22 | #define NOTESSTOREJOB_H | ||
1697 | 23 | |||
1698 | 24 | #include "evernotejob.h" | ||
1699 | 25 | |||
1700 | 26 | // Evernote SDK | ||
1701 | 27 | #include <NoteStore.h> | ||
1702 | 28 | #include <NoteStore_constants.h> | ||
1703 | 29 | #include <Errors_types.h> | ||
1704 | 30 | |||
1705 | 31 | class NotesStoreJob : public EvernoteJob | ||
1706 | 32 | { | ||
1707 | 33 | Q_OBJECT | ||
1708 | 34 | public: | ||
1709 | 35 | explicit NotesStoreJob(QObject *parent = 0); | ||
1710 | 36 | |||
1711 | 37 | protected: | ||
1712 | 38 | void resetConnection() final; | ||
1713 | 39 | |||
1714 | 40 | evernote::edam::NoteStoreClient *client() const; | ||
1715 | 41 | |||
1716 | 42 | }; | ||
1717 | 43 | |||
1718 | 44 | #endif // NOTESSTOREJOB_H | ||
1719 | 0 | 45 | ||
1720 | === modified file 'src/plugin/Evernote/jobs/savenotejob.cpp' | |||
1721 | --- src/plugin/Evernote/jobs/savenotejob.cpp 2013-11-26 17:18:33 +0000 | |||
1722 | +++ src/plugin/Evernote/jobs/savenotejob.cpp 2013-12-14 00:07:45 +0000 | |||
1723 | @@ -24,37 +24,40 @@ | |||
1724 | 24 | #include <QDebug> | 24 | #include <QDebug> |
1725 | 25 | 25 | ||
1726 | 26 | SaveNoteJob::SaveNoteJob(Note *note, QObject *parent) : | 26 | SaveNoteJob::SaveNoteJob(Note *note, QObject *parent) : |
1760 | 27 | EvernoteJob(parent), | 27 | NotesStoreJob(parent) |
1761 | 28 | m_note(note) | 28 | { |
1762 | 29 | { | 29 | // Need to clone it. As startJob() will run in another thread we can't access the real note from there. |
1763 | 30 | } | 30 | m_note = note->clone(); |
1764 | 31 | 31 | ||
1765 | 32 | void SaveNoteJob::run() | 32 | // Make sure we delete the clone when done |
1766 | 33 | { | 33 | m_note->setParent(this); |
1767 | 34 | NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError; | 34 | } |
1768 | 35 | try { | 35 | |
1769 | 36 | evernote::edam::Note note; | 36 | void SaveNoteJob::startJob() |
1770 | 37 | note.guid = m_note->guid().toStdString(); | 37 | { |
1771 | 38 | note.__isset.guid = true; | 38 | evernote::edam::Note note; |
1772 | 39 | note.title = m_note->title().toStdString(); | 39 | note.guid = m_note->guid().toStdString(); |
1773 | 40 | note.__isset.title = true; | 40 | note.__isset.guid = true; |
1774 | 41 | note.notebookGuid = m_note->notebookGuid().toStdString(); | 41 | note.title = m_note->title().toStdString(); |
1775 | 42 | note.__isset.notebookGuid = true; | 42 | note.__isset.title = true; |
1776 | 43 | note.content = m_note->content().toStdString(); | 43 | note.notebookGuid = m_note->notebookGuid().toStdString(); |
1777 | 44 | note.__isset.content = true; | 44 | note.__isset.notebookGuid = true; |
1778 | 45 | note.contentLength = m_note->content().length(); | 45 | note.content = m_note->content().toStdString(); |
1779 | 46 | 46 | note.__isset.content = true; | |
1780 | 47 | client()->updateNote(note, token().toStdString(), note); | 47 | note.contentLength = m_note->content().length(); |
1781 | 48 | 48 | ||
1782 | 49 | } catch (evernote::edam::EDAMUserException e) { | 49 | note.__isset.attributes = true; |
1783 | 50 | errorCode = NotesStore::ErrorCodeUserException; | 50 | note.attributes.reminderOrder = m_note->reminderOrder(); |
1784 | 51 | qDebug() << QString::fromStdString(e.parameter); | 51 | note.attributes.__isset.reminderOrder = true; |
1785 | 52 | } catch (evernote::edam::EDAMSystemException) { | 52 | note.attributes.reminderTime = m_note->reminderTime().toMSecsSinceEpoch(); |
1786 | 53 | errorCode = NotesStore::ErrorCodeSystemException; | 53 | note.attributes.__isset.reminderTime = true; |
1787 | 54 | } catch (...) { | 54 | note.attributes.reminderDoneTime = m_note->reminderDoneTime().toMSecsSinceEpoch(); |
1788 | 55 | catchTransportException(); | 55 | note.attributes.__isset.reminderDoneTime = true; |
1789 | 56 | errorCode = NotesStore::ErrorCodeConnectionLost; | 56 | |
1790 | 57 | } | 57 | client()->updateNote(m_resultNote, token().toStdString(), note); |
1791 | 58 | 58 | } | |
1792 | 59 | emit resultReady(errorCode, m_note); | 59 | |
1793 | 60 | void SaveNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) | ||
1794 | 61 | { | ||
1795 | 62 | emit jobDone(errorCode, errorMessage, m_resultNote); | ||
1796 | 60 | } | 63 | } |
1797 | 61 | 64 | ||
1798 | === modified file 'src/plugin/Evernote/jobs/savenotejob.h' | |||
1799 | --- src/plugin/Evernote/jobs/savenotejob.h 2013-11-25 00:49:48 +0000 | |||
1800 | +++ src/plugin/Evernote/jobs/savenotejob.h 2013-12-14 00:07:45 +0000 | |||
1801 | @@ -1,20 +1,24 @@ | |||
1802 | 1 | #ifndef SAVENOTEJOB_H | 1 | #ifndef SAVENOTEJOB_H |
1803 | 2 | #define SAVENOTEJOB_H | 2 | #define SAVENOTEJOB_H |
1804 | 3 | 3 | ||
1806 | 4 | #include "evernotejob.h" | 4 | #include "notesstorejob.h" |
1807 | 5 | 5 | ||
1809 | 6 | class SaveNoteJob : public EvernoteJob | 6 | class SaveNoteJob : public NotesStoreJob |
1810 | 7 | { | 7 | { |
1811 | 8 | Q_OBJECT | 8 | Q_OBJECT |
1812 | 9 | public: | 9 | public: |
1813 | 10 | explicit SaveNoteJob(Note *note, QObject *parent = 0); | 10 | explicit SaveNoteJob(Note *note, QObject *parent = 0); |
1814 | 11 | 11 | ||
1815 | 12 | void run(); | ||
1816 | 13 | signals: | 12 | signals: |
1818 | 14 | void resultReady(NotesStore::ErrorCode errorCode, Note *note); | 13 | void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note ¬e); |
1819 | 14 | |||
1820 | 15 | protected: | ||
1821 | 16 | void startJob(); | ||
1822 | 17 | void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage); | ||
1823 | 15 | 18 | ||
1824 | 16 | private: | 19 | private: |
1826 | 17 | Note *m_note; | 20 | Note* m_note; |
1827 | 21 | evernote::edam::Note m_resultNote; | ||
1828 | 18 | }; | 22 | }; |
1829 | 19 | 23 | ||
1830 | 20 | #endif // SAVENOTEJOB_H | 24 | #endif // SAVENOTEJOB_H |
1831 | 21 | 25 | ||
1832 | === added file 'src/plugin/Evernote/jobs/userstorejob.cpp' | |||
1833 | --- src/plugin/Evernote/jobs/userstorejob.cpp 1970-01-01 00:00:00 +0000 | |||
1834 | +++ src/plugin/Evernote/jobs/userstorejob.cpp 2013-12-14 00:07:45 +0000 | |||
1835 | @@ -0,0 +1,39 @@ | |||
1836 | 1 | /* | ||
1837 | 2 | * Copyright: 2013 Canonical, Ltd | ||
1838 | 3 | * | ||
1839 | 4 | * This file is part of reminders-app | ||
1840 | 5 | * | ||
1841 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
1842 | 7 | * it under the terms of the GNU General Public License as published by | ||
1843 | 8 | * the Free Software Foundation; version 3. | ||
1844 | 9 | * | ||
1845 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
1846 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1847 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1848 | 13 | * GNU General Public License for more details. | ||
1849 | 14 | * | ||
1850 | 15 | * You should have received a copy of the GNU General Public License | ||
1851 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1852 | 17 | * | ||
1853 | 18 | * Authors: Michael Zanetti <michael.zanetti@canonical.com> | ||
1854 | 19 | */ | ||
1855 | 20 | |||
1856 | 21 | #include "userstorejob.h" | ||
1857 | 22 | |||
1858 | 23 | #include "evernoteconnection.h" | ||
1859 | 24 | |||
1860 | 25 | UserStoreJob::UserStoreJob(QObject *parent) : | ||
1861 | 26 | EvernoteJob(parent) | ||
1862 | 27 | { | ||
1863 | 28 | } | ||
1864 | 29 | |||
1865 | 30 | void UserStoreJob::resetConnection() | ||
1866 | 31 | { | ||
1867 | 32 | EvernoteConnection::instance()->m_userStoreHttpClient->close(); | ||
1868 | 33 | EvernoteConnection::instance()->m_userStoreHttpClient->open(); | ||
1869 | 34 | } | ||
1870 | 35 | |||
1871 | 36 | evernote::edam::UserStoreClient *UserStoreJob::client() const | ||
1872 | 37 | { | ||
1873 | 38 | return EvernoteConnection::instance()->m_userstoreClient; | ||
1874 | 39 | } | ||
1875 | 0 | 40 | ||
1876 | === added file 'src/plugin/Evernote/jobs/userstorejob.h' | |||
1877 | --- src/plugin/Evernote/jobs/userstorejob.h 1970-01-01 00:00:00 +0000 | |||
1878 | +++ src/plugin/Evernote/jobs/userstorejob.h 2013-12-14 00:07:45 +0000 | |||
1879 | @@ -0,0 +1,46 @@ | |||
1880 | 1 | /* | ||
1881 | 2 | * Copyright: 2013 Canonical, Ltd | ||
1882 | 3 | * | ||
1883 | 4 | * This file is part of reminders-app | ||
1884 | 5 | * | ||
1885 | 6 | * reminders-app is free software: you can redistribute it and/or modify | ||
1886 | 7 | * it under the terms of the GNU General Public License as published by | ||
1887 | 8 | * the Free Software Foundation; version 3. | ||
1888 | 9 | * | ||
1889 | 10 | * reminders-app is distributed in the hope that it will be useful, | ||
1890 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1891 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1892 | 13 | * GNU General Public License for more details. | ||
1893 | 14 | * | ||
1894 | 15 | * You should have received a copy of the GNU General Public License | ||
1895 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1896 | 17 | * | ||
1897 | 18 | * Authors: Michael Zanetti <michael.zanetti@canonical.com> | ||
1898 | 19 | */ | ||
1899 | 20 | |||
1900 | 21 | #ifndef USERSTOREJOB_H | ||
1901 | 22 | #define USERSTOREJOB_H | ||
1902 | 23 | |||
1903 | 24 | #include "evernotejob.h" | ||
1904 | 25 | |||
1905 | 26 | // Evernote SDK | ||
1906 | 27 | #include <UserStore.h> | ||
1907 | 28 | #include <UserStore_constants.h> | ||
1908 | 29 | #include <Errors_types.h> | ||
1909 | 30 | |||
1910 | 31 | class UserStoreJob : public EvernoteJob | ||
1911 | 32 | { | ||
1912 | 33 | Q_OBJECT | ||
1913 | 34 | public: | ||
1914 | 35 | explicit UserStoreJob(QObject *parent = 0); | ||
1915 | 36 | |||
1916 | 37 | protected: | ||
1917 | 38 | void resetConnection() final; | ||
1918 | 39 | |||
1919 | 40 | evernote::edam::UserStoreClient* client() const; | ||
1920 | 41 | |||
1921 | 42 | public slots: | ||
1922 | 43 | |||
1923 | 44 | }; | ||
1924 | 45 | |||
1925 | 46 | #endif // USERSTOREJOB_H | ||
1926 | 0 | 47 | ||
1927 | === modified file 'src/plugin/Evernote/note.cpp' | |||
1928 | --- src/plugin/Evernote/note.cpp 2013-11-26 17:18:33 +0000 | |||
1929 | +++ src/plugin/Evernote/note.cpp 2013-12-14 00:07:45 +0000 | |||
1930 | @@ -21,10 +21,16 @@ | |||
1931 | 21 | #include "note.h" | 21 | #include "note.h" |
1932 | 22 | 22 | ||
1933 | 23 | #include "notesstore.h" | 23 | #include "notesstore.h" |
1936 | 24 | 24 | #include "utils/html2enmlconverter.h" | |
1937 | 25 | Note::Note(const QString &guid, QObject *parent) : | 25 | |
1938 | 26 | #include <QDateTime> | ||
1939 | 27 | #include <QDebug> | ||
1940 | 28 | |||
1941 | 29 | Note::Note(const QString &guid, const QDateTime &created, QObject *parent) : | ||
1942 | 26 | QObject(parent), | 30 | QObject(parent), |
1944 | 27 | m_guid(guid) | 31 | m_guid(guid), |
1945 | 32 | m_created(created), | ||
1946 | 33 | m_isSearchResult(false) | ||
1947 | 28 | { | 34 | { |
1948 | 29 | } | 35 | } |
1949 | 30 | 36 | ||
1950 | @@ -33,14 +39,6 @@ | |||
1951 | 33 | return m_guid; | 39 | return m_guid; |
1952 | 34 | } | 40 | } |
1953 | 35 | 41 | ||
1954 | 36 | void Note::setGuid(const QString &guid) | ||
1955 | 37 | { | ||
1956 | 38 | if (m_guid == guid) { | ||
1957 | 39 | m_guid = guid; | ||
1958 | 40 | emit guidChanged(); | ||
1959 | 41 | } | ||
1960 | 42 | } | ||
1961 | 43 | |||
1962 | 44 | QString Note::notebookGuid() const | 42 | QString Note::notebookGuid() const |
1963 | 45 | { | 43 | { |
1964 | 46 | return m_notebookGuid; | 44 | return m_notebookGuid; |
1965 | @@ -54,6 +52,11 @@ | |||
1966 | 54 | } | 52 | } |
1967 | 55 | } | 53 | } |
1968 | 56 | 54 | ||
1969 | 55 | QDateTime Note::created() const | ||
1970 | 56 | { | ||
1971 | 57 | return m_created; | ||
1972 | 58 | } | ||
1973 | 59 | |||
1974 | 57 | QString Note::title() const | 60 | QString Note::title() const |
1975 | 58 | { | 61 | { |
1976 | 59 | return m_title; | 62 | return m_title; |
1977 | @@ -76,10 +79,111 @@ | |||
1978 | 76 | { | 79 | { |
1979 | 77 | if (m_content != content) { | 80 | if (m_content != content) { |
1980 | 78 | m_content = content; | 81 | m_content = content; |
1981 | 82 | m_plaintextContent = Html2EnmlConverter::enml2plaintext(content); | ||
1982 | 83 | qDebug() << "plaintext content is" << m_plaintextContent; | ||
1983 | 79 | emit contentChanged(); | 84 | emit contentChanged(); |
1984 | 80 | } | 85 | } |
1985 | 81 | } | 86 | } |
1986 | 82 | 87 | ||
1987 | 88 | QString Note::plaintextContent() const | ||
1988 | 89 | { | ||
1989 | 90 | return m_plaintextContent; | ||
1990 | 91 | } | ||
1991 | 92 | |||
1992 | 93 | bool Note::reminder() const | ||
1993 | 94 | { | ||
1994 | 95 | return m_reminderOrder > 0; | ||
1995 | 96 | } | ||
1996 | 97 | |||
1997 | 98 | void Note::setReminder(bool reminder) | ||
1998 | 99 | { | ||
1999 | 100 | if (reminder && m_reminderOrder == 0) { | ||
2000 | 101 | m_reminderOrder = QDateTime::currentMSecsSinceEpoch(); | ||
2001 | 102 | emit reminderChanged(); | ||
2002 | 103 | } else if (!reminder && m_reminderOrder > 0) { | ||
2003 | 104 | m_reminderOrder = 0; | ||
2004 | 105 | emit reminderChanged(); | ||
2005 | 106 | } | ||
2006 | 107 | } | ||
2007 | 108 | |||
2008 | 109 | qint64 Note::reminderOrder() const | ||
2009 | 110 | { | ||
2010 | 111 | return m_reminderOrder; | ||
2011 | 112 | } | ||
2012 | 113 | |||
2013 | 114 | void Note::setReminderOrder(qint64 reminderOrder) | ||
2014 | 115 | { | ||
2015 | 116 | if (m_reminderOrder != reminderOrder) { | ||
2016 | 117 | m_reminderOrder = reminderOrder; | ||
2017 | 118 | emit reminderChanged(); | ||
2018 | 119 | } | ||
2019 | 120 | } | ||
2020 | 121 | |||
2021 | 122 | QDateTime Note::reminderTime() const | ||
2022 | 123 | { | ||
2023 | 124 | return m_reminderTime; | ||
2024 | 125 | } | ||
2025 | 126 | |||
2026 | 127 | void Note::setReminderTime(const QDateTime &reminderTime) | ||
2027 | 128 | { | ||
2028 | 129 | if (m_reminderTime != reminderTime) { | ||
2029 | 130 | m_reminderTime = reminderTime; | ||
2030 | 131 | emit reminderTimeChanged(); | ||
2031 | 132 | } | ||
2032 | 133 | } | ||
2033 | 134 | |||
2034 | 135 | bool Note::reminderDone() const | ||
2035 | 136 | { | ||
2036 | 137 | return !m_reminderDoneTime.isNull(); | ||
2037 | 138 | } | ||
2038 | 139 | |||
2039 | 140 | void Note::setReminderDone(bool reminderDone) | ||
2040 | 141 | { | ||
2041 | 142 | if (reminderDone && m_reminderDoneTime.isNull()) { | ||
2042 | 143 | m_reminderDoneTime = QDateTime::currentDateTime(); | ||
2043 | 144 | emit reminderDoneChanged(); | ||
2044 | 145 | } | ||
2045 | 146 | } | ||
2046 | 147 | |||
2047 | 148 | QDateTime Note::reminderDoneTime() const | ||
2048 | 149 | { | ||
2049 | 150 | return m_reminderDoneTime; | ||
2050 | 151 | } | ||
2051 | 152 | |||
2052 | 153 | void Note::setReminderDoneTime(const QDateTime &reminderDoneTime) | ||
2053 | 154 | { | ||
2054 | 155 | if (m_reminderDoneTime != reminderDoneTime) { | ||
2055 | 156 | m_reminderDoneTime = reminderDoneTime; | ||
2056 | 157 | emit reminderDoneChanged(); | ||
2057 | 158 | } | ||
2058 | 159 | } | ||
2059 | 160 | |||
2060 | 161 | bool Note::isSearchResult() const | ||
2061 | 162 | { | ||
2062 | 163 | return m_isSearchResult; | ||
2063 | 164 | } | ||
2064 | 165 | |||
2065 | 166 | void Note::setIsSearchResult(bool isSearchResult) | ||
2066 | 167 | { | ||
2067 | 168 | if (m_isSearchResult != isSearchResult) { | ||
2068 | 169 | m_isSearchResult = isSearchResult; | ||
2069 | 170 | emit isSearchResultChanged(); | ||
2070 | 171 | } | ||
2071 | 172 | } | ||
2072 | 173 | |||
2073 | 174 | Note *Note::clone() | ||
2074 | 175 | { | ||
2075 | 176 | Note *note = new Note(m_guid, m_created); | ||
2076 | 177 | note->setNotebookGuid(m_notebookGuid); | ||
2077 | 178 | note->setTitle(m_title); | ||
2078 | 179 | note->setContent(m_content); | ||
2079 | 180 | note->setReminderOrder(m_reminderOrder); | ||
2080 | 181 | note->setReminderTime(m_reminderTime); | ||
2081 | 182 | note->setReminderDoneTime(m_reminderDoneTime); | ||
2082 | 183 | note->setIsSearchResult(m_isSearchResult); | ||
2083 | 184 | return note; | ||
2084 | 185 | } | ||
2085 | 186 | |||
2086 | 83 | void Note::save() | 187 | void Note::save() |
2087 | 84 | { | 188 | { |
2088 | 85 | NotesStore::instance()->saveNote(m_guid); | 189 | NotesStore::instance()->saveNote(m_guid); |
2089 | 86 | 190 | ||
2090 | === modified file 'src/plugin/Evernote/note.h' | |||
2091 | --- src/plugin/Evernote/note.h 2013-11-25 00:49:48 +0000 | |||
2092 | +++ src/plugin/Evernote/note.h 2013-12-14 00:07:45 +0000 | |||
2093 | @@ -2,45 +2,96 @@ | |||
2094 | 2 | #define NOTE_H | 2 | #define NOTE_H |
2095 | 3 | 3 | ||
2096 | 4 | #include <QObject> | 4 | #include <QObject> |
2097 | 5 | #include <QDateTime> | ||
2098 | 6 | #include <QStringList> | ||
2099 | 5 | 7 | ||
2100 | 6 | class Note : public QObject | 8 | class Note : public QObject |
2101 | 7 | { | 9 | { |
2102 | 8 | Q_OBJECT | 10 | Q_OBJECT |
2103 | 9 | 11 | ||
2105 | 10 | Q_PROPERTY(QString guid READ guid NOTIFY guidChanged) | 12 | // Don't forget to update clone() if you add properties! |
2106 | 13 | Q_PROPERTY(QString guid READ guid CONSTANT) | ||
2107 | 11 | Q_PROPERTY(QString notebookGuid READ notebookGuid WRITE setNotebookGuid NOTIFY notebookGuidChanged) | 14 | Q_PROPERTY(QString notebookGuid READ notebookGuid WRITE setNotebookGuid NOTIFY notebookGuidChanged) |
2108 | 15 | Q_PROPERTY(QDateTime created READ created CONSTANT) | ||
2109 | 12 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) | 16 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) |
2110 | 13 | Q_PROPERTY(QString content READ content WRITE setContent NOTIFY contentChanged) | 17 | Q_PROPERTY(QString content READ content WRITE setContent NOTIFY contentChanged) |
2111 | 18 | Q_PROPERTY(QString plaintextContent READ plaintextContent NOTIFY contentChanged) | ||
2112 | 19 | Q_PROPERTY(bool reminder READ reminder WRITE setReminder NOTIFY reminderChanged) | ||
2113 | 20 | Q_PROPERTY(QDateTime reminderTime READ reminderTime WRITE setReminderTime NOTIFY reminderTimeChanged) | ||
2114 | 21 | Q_PROPERTY(bool reminderDone READ reminderDone WRITE setReminderDone NOTIFY reminderDoneChanged) | ||
2115 | 22 | Q_PROPERTY(QDateTime reminderDoneTime READ reminderDoneTime WRITE setReminderDoneTime NOTIFY reminderDoneChanged) | ||
2116 | 23 | Q_PROPERTY(bool isSearchResult READ isSearchResult NOTIFY isSearchResultChanged) | ||
2117 | 24 | // Don't forget to update clone() if you add properties! | ||
2118 | 25 | |||
2119 | 14 | public: | 26 | public: |
2121 | 15 | explicit Note(const QString &guid = QString(), QObject *parent = 0); | 27 | explicit Note(const QString &guid, const QDateTime &created, QObject *parent = 0); |
2122 | 16 | 28 | ||
2123 | 17 | QString guid() const; | 29 | QString guid() const; |
2124 | 18 | void setGuid(const QString &guid); | ||
2125 | 19 | 30 | ||
2126 | 20 | QString notebookGuid() const; | 31 | QString notebookGuid() const; |
2127 | 21 | void setNotebookGuid(const QString ¬ebookGuid); | 32 | void setNotebookGuid(const QString ¬ebookGuid); |
2128 | 22 | 33 | ||
2129 | 34 | QDateTime created() const; | ||
2130 | 35 | |||
2131 | 23 | QString title() const; | 36 | QString title() const; |
2132 | 24 | void setTitle(const QString &title); | 37 | void setTitle(const QString &title); |
2133 | 25 | 38 | ||
2134 | 26 | QString content() const; | 39 | QString content() const; |
2135 | 27 | void setContent(const QString &content); | 40 | void setContent(const QString &content); |
2136 | 28 | 41 | ||
2137 | 42 | QString plaintextContent() const; | ||
2138 | 43 | void setPlaintextContent(const QString &plaintextContent); | ||
2139 | 44 | |||
2140 | 45 | // This is the QML representation as we don't want to deal with timestamps there. | ||
2141 | 46 | // setting it to false will reset the reminderOrder to 0, setting it to true will | ||
2142 | 47 | // create a new timestamp for it. | ||
2143 | 48 | bool reminder() const; | ||
2144 | 49 | void setReminder(bool reminder); | ||
2145 | 50 | |||
2146 | 51 | qint64 reminderOrder() const; | ||
2147 | 52 | void setReminderOrder(qint64 reminderOrder); | ||
2148 | 53 | |||
2149 | 54 | QDateTime reminderTime() const; | ||
2150 | 55 | void setReminderTime(const QDateTime &reminderTime); | ||
2151 | 56 | |||
2152 | 57 | // This is the QML representation as we don't want to deal with timestamps there. | ||
2153 | 58 | // setting it to false will reset reminderDoneTime to 0, setting it to true will | ||
2154 | 59 | // create a new timestamp for it. | ||
2155 | 60 | bool reminderDone() const; | ||
2156 | 61 | void setReminderDone(bool reminderDone); | ||
2157 | 62 | |||
2158 | 63 | QDateTime reminderDoneTime() const; | ||
2159 | 64 | void setReminderDoneTime(const QDateTime &reminderDoneTime); | ||
2160 | 65 | |||
2161 | 66 | bool isSearchResult() const; | ||
2162 | 67 | void setIsSearchResult(bool isSearchResult); | ||
2163 | 68 | |||
2164 | 69 | Note* clone(); | ||
2165 | 70 | |||
2166 | 29 | public slots: | 71 | public slots: |
2167 | 30 | void save(); | 72 | void save(); |
2168 | 31 | void remove(); | 73 | void remove(); |
2169 | 32 | 74 | ||
2170 | 33 | signals: | 75 | signals: |
2171 | 34 | void guidChanged(); | ||
2172 | 35 | void titleChanged(); | 76 | void titleChanged(); |
2173 | 36 | void notebookGuidChanged(); | 77 | void notebookGuidChanged(); |
2174 | 37 | void contentChanged(); | 78 | void contentChanged(); |
2175 | 79 | void reminderChanged(); | ||
2176 | 80 | void reminderTimeChanged(); | ||
2177 | 81 | void reminderDoneChanged(); | ||
2178 | 82 | void isSearchResultChanged(); | ||
2179 | 38 | 83 | ||
2180 | 39 | private: | 84 | private: |
2181 | 40 | QString m_guid; | 85 | QString m_guid; |
2182 | 41 | QString m_notebookGuid; | 86 | QString m_notebookGuid; |
2183 | 87 | QDateTime m_created; | ||
2184 | 42 | QString m_title; | 88 | QString m_title; |
2185 | 43 | QString m_content; | 89 | QString m_content; |
2186 | 90 | QString m_plaintextContent; | ||
2187 | 91 | qint64 m_reminderOrder; | ||
2188 | 92 | QDateTime m_reminderTime; | ||
2189 | 93 | QDateTime m_reminderDoneTime; | ||
2190 | 94 | bool m_isSearchResult; | ||
2191 | 44 | }; | 95 | }; |
2192 | 45 | 96 | ||
2193 | 46 | #endif // NOTE_H | 97 | #endif // NOTE_H |
2194 | 47 | 98 | ||
2195 | === modified file 'src/plugin/Evernote/notebooks.cpp' | |||
2196 | --- src/plugin/Evernote/notebooks.cpp 2013-11-26 17:18:33 +0000 | |||
2197 | +++ src/plugin/Evernote/notebooks.cpp 2013-12-14 00:07:45 +0000 | |||
2198 | @@ -35,7 +35,6 @@ | |||
2199 | 35 | 35 | ||
2200 | 36 | QVariant Notebooks::data(const QModelIndex &index, int role) const | 36 | QVariant Notebooks::data(const QModelIndex &index, int role) const |
2201 | 37 | { | 37 | { |
2202 | 38 | |||
2203 | 39 | Notebook *notebook = NotesStore::instance()->notebook(m_list.at(index.row())); | 38 | Notebook *notebook = NotesStore::instance()->notebook(m_list.at(index.row())); |
2204 | 40 | switch(role) { | 39 | switch(role) { |
2205 | 41 | case RoleGuid: | 40 | case RoleGuid: |
2206 | 42 | 41 | ||
2207 | === modified file 'src/plugin/Evernote/notes.cpp' | |||
2208 | --- src/plugin/Evernote/notes.cpp 2013-11-26 17:18:33 +0000 | |||
2209 | +++ src/plugin/Evernote/notes.cpp 2013-12-14 00:07:45 +0000 | |||
2210 | @@ -24,37 +24,12 @@ | |||
2211 | 24 | #include <QDebug> | 24 | #include <QDebug> |
2212 | 25 | 25 | ||
2213 | 26 | Notes::Notes(QObject *parent) : | 26 | Notes::Notes(QObject *parent) : |
2245 | 27 | QAbstractListModel(parent) | 27 | QSortFilterProxyModel(parent), |
2246 | 28 | { | 28 | m_onlyReminders(false) |
2247 | 29 | connect(NotesStore::instance(), &NotesStore::noteAdded, this, &Notes::noteAdded); | 29 | { |
2248 | 30 | connect(NotesStore::instance(), &NotesStore::noteRemoved, this, &Notes::noteRemoved); | 30 | setSourceModel(NotesStore::instance()); |
2249 | 31 | connect(NotesStore::instance(), &NotesStore::noteChanged, this, &Notes::noteChanged); | 31 | setSortRole(NotesStore::RoleCreated); |
2250 | 32 | } | 32 | sort(0, Qt::DescendingOrder); |
2220 | 33 | |||
2221 | 34 | QVariant Notes::data(const QModelIndex &index, int role) const | ||
2222 | 35 | { | ||
2223 | 36 | Note *note = NotesStore::instance()->note(m_list.at(index.row())); | ||
2224 | 37 | switch(role) { | ||
2225 | 38 | case RoleGuid: | ||
2226 | 39 | return note->guid(); | ||
2227 | 40 | case RoleTitle: | ||
2228 | 41 | return note->title(); | ||
2229 | 42 | } | ||
2230 | 43 | |||
2231 | 44 | return QVariant(); | ||
2232 | 45 | } | ||
2233 | 46 | |||
2234 | 47 | int Notes::rowCount(const QModelIndex &parent) const | ||
2235 | 48 | { | ||
2236 | 49 | return m_list.count(); | ||
2237 | 50 | } | ||
2238 | 51 | |||
2239 | 52 | QHash<int, QByteArray> Notes::roleNames() const | ||
2240 | 53 | { | ||
2241 | 54 | QHash<int, QByteArray> roles; | ||
2242 | 55 | roles.insert(RoleGuid, "guid"); | ||
2243 | 56 | roles.insert(RoleTitle, "title"); | ||
2244 | 57 | return roles; | ||
2251 | 58 | } | 33 | } |
2252 | 59 | 34 | ||
2253 | 60 | QString Notes::filterNotebookGuid() const | 35 | QString Notes::filterNotebookGuid() const |
2254 | @@ -67,53 +42,56 @@ | |||
2255 | 67 | if (m_filterNotebookGuid != notebookGuid) { | 42 | if (m_filterNotebookGuid != notebookGuid) { |
2256 | 68 | m_filterNotebookGuid = notebookGuid; | 43 | m_filterNotebookGuid = notebookGuid; |
2257 | 69 | emit filterNotebookGuidChanged(); | 44 | emit filterNotebookGuidChanged(); |
2307 | 70 | } | 45 | invalidateFilter(); |
2308 | 71 | } | 46 | } |
2309 | 72 | 47 | } | |
2310 | 73 | Note* Notes::note(const QString &guid) | 48 | |
2311 | 74 | { | 49 | bool Notes::onlyReminders() const |
2312 | 75 | NotesStore::instance()->refreshNoteContent(guid); | 50 | { |
2313 | 76 | return NotesStore::instance()->note(guid); | 51 | return m_onlyReminders; |
2314 | 77 | } | 52 | } |
2315 | 78 | 53 | ||
2316 | 79 | void Notes::componentComplete() | 54 | void Notes::setOnlyReminders(bool onlyReminders) |
2317 | 80 | { | 55 | { |
2318 | 81 | foreach (Note *note, NotesStore::instance()->notes()) { | 56 | if (m_onlyReminders != onlyReminders) { |
2319 | 82 | if (m_filterNotebookGuid.isEmpty() || note->notebookGuid() == m_filterNotebookGuid) { | 57 | m_onlyReminders = onlyReminders; |
2320 | 83 | m_list.append(note->guid()); | 58 | emit onlyRemindersChanged(); |
2321 | 84 | } | 59 | invalidateFilter(); |
2322 | 85 | } | 60 | } |
2323 | 86 | beginInsertRows(QModelIndex(), 0, m_list.count() - 1); | 61 | } |
2324 | 87 | endInsertRows(); | 62 | |
2325 | 88 | refresh(); | 63 | bool Notes::onlySearchResults() const |
2326 | 89 | } | 64 | { |
2327 | 90 | 65 | return m_onlySearchResults; | |
2328 | 91 | void Notes::refresh() | 66 | } |
2329 | 92 | { | 67 | |
2330 | 93 | NotesStore::instance()->refreshNotes(m_filterNotebookGuid); | 68 | void Notes::setOnlySearchResults(bool onlySearchResults) |
2331 | 94 | } | 69 | { |
2332 | 95 | 70 | if (m_onlySearchResults != onlySearchResults) { | |
2333 | 96 | void Notes::noteAdded(const QString &guid) | 71 | m_onlySearchResults = onlySearchResults; |
2334 | 97 | { | 72 | emit onlySearchResultsChanged(); |
2335 | 98 | beginInsertRows(QModelIndex(), m_list.count(), m_list.count()); | 73 | invalidateFilter(); |
2336 | 99 | m_list.append(guid); | 74 | } |
2337 | 100 | endInsertRows(); | 75 | } |
2338 | 101 | } | 76 | |
2339 | 102 | 77 | bool Notes::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const | |
2340 | 103 | void Notes::noteChanged(const QString &guid) | 78 | { |
2341 | 104 | { | 79 | QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent); |
2342 | 105 | int row = m_list.indexOf(guid); | 80 | if (!m_filterNotebookGuid.isEmpty()) { |
2343 | 106 | if (row >= 0) { | 81 | if (sourceModel()->data(sourceIndex, NotesStore::RoleNotebookGuid).toString() != m_filterNotebookGuid) { |
2344 | 107 | emit dataChanged(index(row), index(row)); | 82 | return false; |
2345 | 108 | } | 83 | } |
2346 | 109 | } | 84 | } |
2347 | 110 | 85 | if (m_onlyReminders) { | |
2348 | 111 | void Notes::noteRemoved(const QString &guid) | 86 | if (!sourceModel()->data(sourceIndex, NotesStore::RoleReminder).toBool()) { |
2349 | 112 | { | 87 | return false; |
2350 | 113 | int index = m_list.indexOf(guid); | 88 | } |
2351 | 114 | if (index >= 0) { | 89 | } |
2352 | 115 | beginRemoveRows(QModelIndex(), index, index); | 90 | if (m_onlySearchResults) { |
2353 | 116 | m_list.removeAt(index); | 91 | Note *note = NotesStore::instance()->note(sourceModel()->data(sourceIndex, NotesStore::RoleGuid).toString()); |
2354 | 117 | endRemoveRows(); | 92 | if (!note->isSearchResult()) { |
2355 | 118 | } | 93 | return false; |
2356 | 94 | } | ||
2357 | 95 | } | ||
2358 | 96 | return true; | ||
2359 | 119 | } | 97 | } |
2360 | 120 | 98 | ||
2361 | === modified file 'src/plugin/Evernote/notes.h' | |||
2362 | --- src/plugin/Evernote/notes.h 2013-11-25 00:49:48 +0000 | |||
2363 | +++ src/plugin/Evernote/notes.h 2013-12-14 00:07:45 +0000 | |||
2364 | @@ -3,47 +3,39 @@ | |||
2365 | 3 | 3 | ||
2366 | 4 | #include "notesstore.h" | 4 | #include "notesstore.h" |
2367 | 5 | 5 | ||
2370 | 6 | #include <QAbstractListModel> | 6 | #include <QSortFilterProxyModel> |
2369 | 7 | #include <QQmlParserStatus> | ||
2371 | 8 | 7 | ||
2373 | 9 | class Notes : public QAbstractListModel, public QQmlParserStatus | 8 | class Notes : public QSortFilterProxyModel |
2374 | 10 | { | 9 | { |
2375 | 11 | Q_OBJECT | 10 | Q_OBJECT |
2376 | 12 | Q_PROPERTY(QString filterNotebookGuid READ filterNotebookGuid WRITE setFilterNotebookGuid NOTIFY filterNotebookGuidChanged) | 11 | Q_PROPERTY(QString filterNotebookGuid READ filterNotebookGuid WRITE setFilterNotebookGuid NOTIFY filterNotebookGuidChanged) |
2377 | 12 | Q_PROPERTY(bool onlyReminders READ onlyReminders WRITE setOnlyReminders NOTIFY onlyRemindersChanged) | ||
2378 | 13 | Q_PROPERTY(bool onlySearchResults READ onlySearchResults WRITE setOnlySearchResults NOTIFY onlySearchResultsChanged) | ||
2379 | 14 | |||
2380 | 13 | public: | 15 | public: |
2381 | 14 | enum Roles { | ||
2382 | 15 | RoleGuid, | ||
2383 | 16 | RoleTitle | ||
2384 | 17 | }; | ||
2385 | 18 | explicit Notes(QObject *parent = 0); | 16 | explicit Notes(QObject *parent = 0); |
2386 | 19 | 17 | ||
2387 | 20 | QVariant data(const QModelIndex &index, int role) const; | ||
2388 | 21 | int rowCount(const QModelIndex &parent) const; | ||
2389 | 22 | QHash<int, QByteArray> roleNames() const; | ||
2390 | 23 | |||
2391 | 24 | QString filterNotebookGuid() const; | 18 | QString filterNotebookGuid() const; |
2392 | 25 | void setFilterNotebookGuid(const QString ¬ebookGuid); | 19 | void setFilterNotebookGuid(const QString ¬ebookGuid); |
2393 | 26 | 20 | ||
2406 | 27 | Q_INVOKABLE Note* note(const QString &guid); | 21 | bool onlyReminders() const; |
2407 | 28 | 22 | void setOnlyReminders(bool onlyReminders); | |
2408 | 29 | void classBegin() {} | 23 | |
2409 | 30 | void componentComplete(); | 24 | bool onlySearchResults() const; |
2410 | 31 | 25 | void setOnlySearchResults(bool onlySearchResults); | |
2411 | 32 | public slots: | 26 | |
2412 | 33 | void refresh(); | 27 | protected: |
2413 | 34 | 28 | bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; | |
2402 | 35 | private slots: | ||
2403 | 36 | void noteAdded(const QString &guid); | ||
2404 | 37 | void noteChanged(const QString &guid); | ||
2405 | 38 | void noteRemoved(const QString &guid); | ||
2414 | 39 | 29 | ||
2415 | 40 | signals: | 30 | signals: |
2416 | 41 | void filterNotebookGuidChanged(); | 31 | void filterNotebookGuidChanged(); |
2417 | 32 | void onlyRemindersChanged(); | ||
2418 | 33 | void onlySearchResultsChanged(); | ||
2419 | 42 | 34 | ||
2420 | 43 | private: | 35 | private: |
2421 | 44 | QList<QString> m_list; | ||
2422 | 45 | QString m_filterNotebookGuid; | 36 | QString m_filterNotebookGuid; |
2424 | 46 | 37 | bool m_onlyReminders; | |
2425 | 38 | bool m_onlySearchResults; | ||
2426 | 47 | }; | 39 | }; |
2427 | 48 | 40 | ||
2428 | 49 | #endif // NOTES_H | 41 | #endif // NOTES_H |
2429 | 50 | 42 | ||
2430 | === modified file 'src/plugin/Evernote/notesstore.cpp' | |||
2431 | --- src/plugin/Evernote/notesstore.cpp 2013-11-27 17:33:36 +0000 | |||
2432 | +++ src/plugin/Evernote/notesstore.cpp 2013-12-14 00:07:45 +0000 | |||
2433 | @@ -19,6 +19,7 @@ | |||
2434 | 19 | */ | 19 | */ |
2435 | 20 | 20 | ||
2436 | 21 | #include "notesstore.h" | 21 | #include "notesstore.h" |
2437 | 22 | #include "evernoteconnection.h" | ||
2438 | 22 | #include "notebooks.h" | 23 | #include "notebooks.h" |
2439 | 23 | #include "notebook.h" | 24 | #include "notebook.h" |
2440 | 24 | #include "note.h" | 25 | #include "note.h" |
2441 | @@ -30,73 +31,24 @@ | |||
2442 | 30 | #include "jobs/createnotejob.h" | 31 | #include "jobs/createnotejob.h" |
2443 | 31 | #include "jobs/savenotejob.h" | 32 | #include "jobs/savenotejob.h" |
2444 | 32 | #include "jobs/deletenotejob.h" | 33 | #include "jobs/deletenotejob.h" |
2452 | 33 | 34 | #include "jobs/createnotebookjob.h" | |
2453 | 34 | // Thrift | 35 | #include "jobs/expungenotebookjob.h" |
2447 | 35 | #include <arpa/inet.h> // seems thrift forgot this one | ||
2448 | 36 | #include <protocol/TBinaryProtocol.h> | ||
2449 | 37 | #include <transport/THttpClient.h> | ||
2450 | 38 | #include <transport/TSSLSocket.h> | ||
2451 | 39 | #include <Thrift.h> | ||
2454 | 40 | 36 | ||
2455 | 41 | #include <QDebug> | 37 | #include <QDebug> |
2456 | 42 | 38 | ||
2457 | 43 | using namespace apache::thrift; | ||
2458 | 44 | using namespace apache::thrift::protocol; | ||
2459 | 45 | using namespace apache::thrift::transport; | ||
2460 | 46 | |||
2461 | 47 | NotesStore* NotesStore::s_instance = 0; | 39 | NotesStore* NotesStore::s_instance = 0; |
2462 | 48 | 40 | ||
2463 | 49 | NotesStore::NotesStore(QObject *parent) : | 41 | NotesStore::NotesStore(QObject *parent) : |
2466 | 50 | QObject(parent), | 42 | QAbstractListModel(parent) |
2465 | 51 | m_currentJob(0) | ||
2467 | 52 | { | 43 | { |
2512 | 53 | try { | 44 | connect(EvernoteConnection::instance(), &EvernoteConnection::tokenChanged, this, &NotesStore::refreshNotebooks); |
2513 | 54 | // FIXME: need to populate this string from the system | 45 | connect(EvernoteConnection::instance(), SIGNAL(tokenChanged()), this, SLOT(refreshNotes())); |
2514 | 55 | // The structure should be: | 46 | |
2515 | 56 | // application/version; platform/version; [ device/version ] | 47 | qRegisterMetaType<EvernoteConnection::ErrorCode>("EvernoteConnection::ErrorCode"); |
2472 | 57 | // E.g. "Evernote Windows/3.0.1; Windows/XP SP3" | ||
2473 | 58 | QString EDAM_CLIENT_NAME = QStringLiteral("Reminders/0.1; Ubuntu/13.10"); | ||
2474 | 59 | QString EVERNOTE_HOST = QStringLiteral("sandbox.evernote.com"); | ||
2475 | 60 | QString EDAM_USER_STORE_PATH = QStringLiteral("/edam/note"); | ||
2476 | 61 | boost::shared_ptr<TSocket> socket; | ||
2477 | 62 | bool use_SSL = true; | ||
2478 | 63 | |||
2479 | 64 | if (use_SSL) { | ||
2480 | 65 | // Create an SSL socket | ||
2481 | 66 | // FIXME: this fails with the following error: | ||
2482 | 67 | // Thrift: Fri Nov 15 12:47:31 2013 SSL_shutdown: error code: 0 | ||
2483 | 68 | // SSL_get_verify_result(), unable to get local issuer certificate | ||
2484 | 69 | // Additionally, the UI blocks and does not load for about 2 minutes | ||
2485 | 70 | boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory()); | ||
2486 | 71 | socket = sslSocketFactory->createSocket(EVERNOTE_HOST.toStdString(), 443); | ||
2487 | 72 | qDebug() << "created SSL socket"; | ||
2488 | 73 | } else { | ||
2489 | 74 | // Create a non-secure socket | ||
2490 | 75 | socket = boost::shared_ptr<TSocket> (new TSocket(EVERNOTE_HOST.toStdString(), 80)); | ||
2491 | 76 | qDebug() << "created insecure socket"; | ||
2492 | 77 | } | ||
2493 | 78 | |||
2494 | 79 | boost::shared_ptr<TBufferedTransport> bufferedTransport(new TBufferedTransport(socket)); | ||
2495 | 80 | boost::shared_ptr<THttpClient> userStoreHttpClient (new THttpClient(bufferedTransport, | ||
2496 | 81 | EVERNOTE_HOST.toStdString(), | ||
2497 | 82 | EDAM_USER_STORE_PATH.toStdString())); | ||
2498 | 83 | userStoreHttpClient->open(); | ||
2499 | 84 | |||
2500 | 85 | boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(userStoreHttpClient)); | ||
2501 | 86 | m_client = new evernote::edam::NoteStoreClient(iprot); | ||
2502 | 87 | |||
2503 | 88 | qDebug() << "NoteStore client created."; | ||
2504 | 89 | |||
2505 | 90 | } catch (const TTransportException & e) { | ||
2506 | 91 | qWarning() << "Failed to create Transport:" << e.what(); | ||
2507 | 92 | } catch (const TException & e) { | ||
2508 | 93 | qWarning() << "Generic Thrift exception:" << e.what(); | ||
2509 | 94 | } | ||
2510 | 95 | |||
2511 | 96 | qRegisterMetaType<NotesStore::ErrorCode>("NotesStore::ErrorCode"); | ||
2516 | 97 | qRegisterMetaType<evernote::edam::NotesMetadataList>("evernote::edam::NotesMetadataList"); | 48 | qRegisterMetaType<evernote::edam::NotesMetadataList>("evernote::edam::NotesMetadataList"); |
2517 | 98 | qRegisterMetaType<evernote::edam::Note>("evernote::edam::Note"); | 49 | qRegisterMetaType<evernote::edam::Note>("evernote::edam::Note"); |
2518 | 99 | qRegisterMetaType<std::vector<evernote::edam::Notebook> >("std::vector<evernote::edam::Notebook>"); | 50 | qRegisterMetaType<std::vector<evernote::edam::Notebook> >("std::vector<evernote::edam::Notebook>"); |
2519 | 51 | qRegisterMetaType<evernote::edam::Notebook>("evernote::edam::Notebook"); | ||
2520 | 100 | 52 | ||
2521 | 101 | } | 53 | } |
2522 | 102 | 54 | ||
2523 | @@ -108,255 +60,317 @@ | |||
2524 | 108 | return s_instance; | 60 | return s_instance; |
2525 | 109 | } | 61 | } |
2526 | 110 | 62 | ||
2538 | 111 | QString NotesStore::errorCodeToString(NotesStore::ErrorCode errorCode) | 63 | int NotesStore::rowCount(const QModelIndex &parent) const |
2539 | 112 | { | 64 | { |
2540 | 113 | switch(errorCode) { | 65 | return m_notes.count(); |
2541 | 114 | case ErrorCodeNoError: | 66 | } |
2542 | 115 | return QStringLiteral("No error"); | 67 | |
2543 | 116 | case ErrorCodeUserException: | 68 | QVariant NotesStore::data(const QModelIndex &index, int role) const |
2544 | 117 | return QStringLiteral("User exception"); | 69 | { |
2545 | 118 | case ErrorCodeSystemException: | 70 | switch (role) { |
2546 | 119 | return QStringLiteral("System exception"); | 71 | case RoleGuid: |
2547 | 120 | case ErrorCodeNotFoundExcpetion: | 72 | return m_notes.at(index.row())->guid(); |
2548 | 121 | return QStringLiteral("Not found"); | 73 | case RoleNotebookGuid: |
2549 | 74 | return m_notes.at(index.row())->notebookGuid(); | ||
2550 | 75 | case RoleCreated: | ||
2551 | 76 | return m_notes.at(index.row())->created(); | ||
2552 | 77 | case RoleTitle: | ||
2553 | 78 | return m_notes.at(index.row())->title(); | ||
2554 | 79 | case RoleReminder: | ||
2555 | 80 | return m_notes.at(index.row())->reminder(); | ||
2556 | 81 | case RoleReminderTime: | ||
2557 | 82 | return m_notes.at(index.row())->reminderTime(); | ||
2558 | 83 | case RoleReminderDone: | ||
2559 | 84 | return m_notes.at(index.row())->reminderDone(); | ||
2560 | 85 | case RoleReminderDoneTime: | ||
2561 | 86 | return m_notes.at(index.row())->reminderDoneTime(); | ||
2562 | 122 | } | 87 | } |
2564 | 123 | return QString(); | 88 | return QVariant(); |
2565 | 89 | } | ||
2566 | 90 | |||
2567 | 91 | QHash<int, QByteArray> NotesStore::roleNames() const | ||
2568 | 92 | { | ||
2569 | 93 | QHash<int, QByteArray> roles; | ||
2570 | 94 | roles.insert(RoleGuid, "guid"); | ||
2571 | 95 | roles.insert(RoleNotebookGuid, "notebookGuid"); | ||
2572 | 96 | roles.insert(RoleCreated, "created"); | ||
2573 | 97 | roles.insert(RoleTitle, "title"); | ||
2574 | 98 | roles.insert(RoleReminder, "reminder"); | ||
2575 | 99 | roles.insert(RoleReminderTime, "reminderTime"); | ||
2576 | 100 | roles.insert(RoleReminderDone, "reminderDone"); | ||
2577 | 101 | roles.insert(RoleReminderDoneTime, "reminderDoneTime"); | ||
2578 | 102 | return roles; | ||
2579 | 124 | } | 103 | } |
2580 | 125 | 104 | ||
2581 | 126 | NotesStore::~NotesStore() | 105 | NotesStore::~NotesStore() |
2582 | 127 | { | 106 | { |
2583 | 128 | delete m_client; | ||
2584 | 129 | } | ||
2585 | 130 | |||
2586 | 131 | QString NotesStore::token() const | ||
2587 | 132 | { | ||
2588 | 133 | return m_token; | ||
2589 | 134 | } | ||
2590 | 135 | |||
2591 | 136 | void NotesStore::setToken(const QString &token) | ||
2592 | 137 | { | ||
2593 | 138 | if (token != m_token) { | ||
2594 | 139 | m_token = token; | ||
2595 | 140 | emit tokenChanged(); | ||
2596 | 141 | refreshNotebooks(); | ||
2597 | 142 | refreshNotes(); | ||
2598 | 143 | } | ||
2599 | 144 | } | 107 | } |
2600 | 145 | 108 | ||
2601 | 146 | QList<Note*> NotesStore::notes() const | 109 | QList<Note*> NotesStore::notes() const |
2602 | 147 | { | 110 | { |
2604 | 148 | return m_notes.values(); | 111 | return m_notes; |
2605 | 149 | } | 112 | } |
2606 | 150 | 113 | ||
2607 | 151 | Note *NotesStore::note(const QString &guid) | 114 | Note *NotesStore::note(const QString &guid) |
2608 | 152 | { | 115 | { |
2631 | 153 | return m_notes.value(guid); | 116 | return m_notesHash.value(guid); |
2610 | 154 | } | ||
2611 | 155 | |||
2612 | 156 | void NotesStore::saveNote(const QString &guid) | ||
2613 | 157 | { | ||
2614 | 158 | Note *note = m_notes.value(guid); | ||
2615 | 159 | |||
2616 | 160 | QString enml = Html2EnmlConverter::html2enml(note->content()); | ||
2617 | 161 | note->setContent(enml); | ||
2618 | 162 | |||
2619 | 163 | SaveNoteJob *job = new SaveNoteJob(note, this); | ||
2620 | 164 | connect(job, &SaveNoteJob::resultReady, this, &NotesStore::saveNoteJobDone); | ||
2621 | 165 | m_jobQueue.append(job); | ||
2622 | 166 | startJobQueue(); | ||
2623 | 167 | } | ||
2624 | 168 | |||
2625 | 169 | void NotesStore::deleteNote(const QString &guid) | ||
2626 | 170 | { | ||
2627 | 171 | DeleteNoteJob *job = new DeleteNoteJob(guid, this); | ||
2628 | 172 | connect(job, &DeleteNoteJob::resultReady, this, &NotesStore::deleteNoteJobDone); | ||
2629 | 173 | m_jobQueue.append(job); | ||
2630 | 174 | startJobQueue(); | ||
2632 | 175 | } | 117 | } |
2633 | 176 | 118 | ||
2634 | 177 | QList<Notebook *> NotesStore::notebooks() const | 119 | QList<Notebook *> NotesStore::notebooks() const |
2635 | 178 | { | 120 | { |
2637 | 179 | return m_notebooks.values(); | 121 | return m_notebooks; |
2638 | 180 | } | 122 | } |
2639 | 181 | 123 | ||
2640 | 182 | Notebook *NotesStore::notebook(const QString &guid) | 124 | Notebook *NotesStore::notebook(const QString &guid) |
2641 | 183 | { | 125 | { |
2662 | 184 | return m_notebooks.value(guid); | 126 | return m_notebooksHash.value(guid); |
2663 | 185 | } | 127 | } |
2664 | 186 | 128 | ||
2665 | 187 | void NotesStore::startJobQueue() | 129 | void NotesStore::createNotebook(const QString &name) |
2666 | 188 | { | 130 | { |
2667 | 189 | if (m_jobQueue.isEmpty()) { | 131 | CreateNotebookJob *job = new CreateNotebookJob(name); |
2668 | 190 | return; | 132 | connect(job, &CreateNotebookJob::jobDone, this, &NotesStore::createNotebookJobDone); |
2669 | 191 | } | 133 | EvernoteConnection::instance()->enqueue(job); |
2670 | 192 | 134 | } | |
2671 | 193 | if (m_currentJob) { | 135 | |
2672 | 194 | return; | 136 | void NotesStore::expungeNotebook(const QString &guid) |
2673 | 195 | } | 137 | { |
2674 | 196 | m_currentJob = m_jobQueue.takeFirst(); | 138 | ExpungeNotebookJob *job = new ExpungeNotebookJob(guid); |
2675 | 197 | m_currentJob->start(); | 139 | connect(job, &ExpungeNotebookJob::jobDone, this, &NotesStore::expungeNotebookJobDone); |
2676 | 198 | } | 140 | EvernoteConnection::instance()->enqueue(job); |
2657 | 199 | |||
2658 | 200 | void NotesStore::startNextJob() | ||
2659 | 201 | { | ||
2660 | 202 | m_currentJob = 0; | ||
2661 | 203 | startJobQueue(); | ||
2677 | 204 | } | 141 | } |
2678 | 205 | 142 | ||
2679 | 206 | void NotesStore::refreshNotes(const QString &filterNotebookGuid) | 143 | void NotesStore::refreshNotes(const QString &filterNotebookGuid) |
2680 | 207 | { | 144 | { |
2681 | 208 | if (m_token.isEmpty()) { | ||
2682 | 209 | qWarning() << "No token set. Cannot fetch notes."; | ||
2683 | 210 | return; | ||
2684 | 211 | } | ||
2685 | 212 | |||
2686 | 213 | FetchNotesJob *job = new FetchNotesJob(filterNotebookGuid); | 145 | FetchNotesJob *job = new FetchNotesJob(filterNotebookGuid); |
2691 | 214 | connect(job, &FetchNotesJob::resultReady, this, &NotesStore::fetchNotesJobDone); | 146 | connect(job, &FetchNotesJob::jobDone, this, &NotesStore::fetchNotesJobDone); |
2692 | 215 | 147 | EvernoteConnection::instance()->enqueue(job); | |
2689 | 216 | m_jobQueue.append(job); | ||
2690 | 217 | startJobQueue(); | ||
2693 | 218 | } | 148 | } |
2694 | 219 | 149 | ||
2696 | 220 | void NotesStore::fetchNotesJobDone(ErrorCode errorCode, const evernote::edam::NotesMetadataList &results) | 150 | void NotesStore::fetchNotesJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results) |
2697 | 221 | { | 151 | { |
2701 | 222 | if (errorCode != ErrorCodeNoError) { | 152 | if (errorCode != EvernoteConnection::ErrorCodeNoError) { |
2702 | 223 | qWarning() << "Failed to fetch notes list:" << errorCodeToString(errorCode); | 153 | qWarning() << "Failed to fetch notes list:" << errorMessage; |
2700 | 224 | startNextJob(); | ||
2703 | 225 | return; | 154 | return; |
2704 | 226 | } | 155 | } |
2705 | 227 | 156 | ||
2706 | 228 | for (int i = 0; i < results.notes.size(); ++i) { | 157 | for (int i = 0; i < results.notes.size(); ++i) { |
2707 | 229 | evernote::edam::NoteMetadata result = results.notes.at(i); | 158 | evernote::edam::NoteMetadata result = results.notes.at(i); |
2712 | 230 | Note *note = m_notes.value(QString::fromStdString(result.guid)); | 159 | Note *note = m_notesHash.value(QString::fromStdString(result.guid)); |
2713 | 231 | if (note) { | 160 | bool newNote = note == 0; |
2714 | 232 | note->setTitle(QString::fromStdString(result.title)); | 161 | if (newNote) { |
2715 | 233 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); | 162 | QString guid = QString::fromStdString(result.guid); |
2716 | 163 | QDateTime created = QDateTime::fromMSecsSinceEpoch(result.created); | ||
2717 | 164 | note = new Note(guid, created, this); | ||
2718 | 165 | } | ||
2719 | 166 | |||
2720 | 167 | note->setTitle(QString::fromStdString(result.title)); | ||
2721 | 168 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); | ||
2722 | 169 | note->setReminderOrder(result.attributes.reminderOrder); | ||
2723 | 170 | |||
2724 | 171 | if (!results.searchedWords.empty()) { | ||
2725 | 172 | note->setIsSearchResult(true); | ||
2726 | 173 | } | ||
2727 | 174 | |||
2728 | 175 | QDateTime reminderDoneTime; | ||
2729 | 176 | if (result.attributes.reminderDoneTime > 0) { | ||
2730 | 177 | reminderDoneTime = QDateTime::fromMSecsSinceEpoch(result.attributes.reminderDoneTime); | ||
2731 | 178 | } | ||
2732 | 179 | note->setReminderDoneTime(reminderDoneTime); | ||
2733 | 180 | |||
2734 | 181 | if (newNote) { | ||
2735 | 182 | beginInsertRows(QModelIndex(), m_notes.count(), m_notes.count()); | ||
2736 | 183 | m_notesHash.insert(note->guid(), note); | ||
2737 | 184 | m_notes.append(note); | ||
2738 | 185 | endInsertRows(); | ||
2739 | 186 | emit noteAdded(note->guid()); | ||
2740 | 187 | } else { | ||
2741 | 188 | QModelIndex noteIndex = index(m_notes.indexOf(note)); | ||
2742 | 189 | emit dataChanged(noteIndex, noteIndex); | ||
2743 | 234 | emit noteChanged(note->guid()); | 190 | emit noteChanged(note->guid()); |
2744 | 235 | } else { | ||
2745 | 236 | note = new Note(QString::fromStdString(result.guid), this); | ||
2746 | 237 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); | ||
2747 | 238 | note->setTitle(QString::fromStdString(result.title)); | ||
2748 | 239 | m_notes.insert(note->guid(), note); | ||
2749 | 240 | emit noteAdded(note->guid()); | ||
2750 | 241 | } | 191 | } |
2751 | 242 | } | 192 | } |
2752 | 243 | |||
2753 | 244 | startNextJob(); | ||
2754 | 245 | } | 193 | } |
2755 | 246 | 194 | ||
2756 | 247 | void NotesStore::refreshNoteContent(const QString &guid) | 195 | void NotesStore::refreshNoteContent(const QString &guid) |
2757 | 248 | { | 196 | { |
2758 | 249 | if (m_token.isEmpty()) { | ||
2759 | 250 | qWarning() << "No token set. Cannot fetch note."; | ||
2760 | 251 | return; | ||
2761 | 252 | } | ||
2762 | 253 | |||
2763 | 254 | FetchNoteJob *job = new FetchNoteJob(guid, this); | 197 | FetchNoteJob *job = new FetchNoteJob(guid, this); |
2764 | 255 | connect(job, &FetchNoteJob::resultReady, this, &NotesStore::fetchNoteJobDone); | 198 | connect(job, &FetchNoteJob::resultReady, this, &NotesStore::fetchNoteJobDone); |
2768 | 256 | m_jobQueue.append(job); | 199 | EvernoteConnection::instance()->enqueue(job); |
2766 | 257 | |||
2767 | 258 | startJobQueue(); | ||
2769 | 259 | } | 200 | } |
2770 | 260 | 201 | ||
2772 | 261 | void NotesStore::fetchNoteJobDone(ErrorCode errorCode, const evernote::edam::Note &result) | 202 | void NotesStore::fetchNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result) |
2773 | 262 | { | 203 | { |
2777 | 263 | if (errorCode != ErrorCodeNoError) { | 204 | if (errorCode != EvernoteConnection::ErrorCodeNoError) { |
2778 | 264 | qWarning() << "Error fetching note:" << errorCode; | 205 | qWarning() << "Error fetching note:" << errorMessage; |
2776 | 265 | startNextJob(); | ||
2779 | 266 | return; | 206 | return; |
2780 | 267 | } | 207 | } |
2781 | 268 | 208 | ||
2783 | 269 | Note *note = m_notes.value(QString::fromStdString(result.guid)); | 209 | Note *note = m_notesHash.value(QString::fromStdString(result.guid)); |
2784 | 270 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); | 210 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); |
2785 | 271 | note->setTitle(QString::fromStdString(result.title)); | 211 | note->setTitle(QString::fromStdString(result.title)); |
2786 | 272 | note->setContent(QString::fromStdString(result.content)); | 212 | note->setContent(QString::fromStdString(result.content)); |
2787 | 213 | note->setReminderOrder(result.attributes.reminderOrder); | ||
2788 | 214 | QDateTime reminderDoneTime; | ||
2789 | 215 | if (result.attributes.reminderDoneTime > 0) { | ||
2790 | 216 | reminderDoneTime = QDateTime::fromMSecsSinceEpoch(result.attributes.reminderDoneTime); | ||
2791 | 217 | } | ||
2792 | 218 | note->setReminderDoneTime(reminderDoneTime); | ||
2793 | 273 | emit noteChanged(note->guid()); | 219 | emit noteChanged(note->guid()); |
2794 | 274 | 220 | ||
2796 | 275 | startNextJob(); | 221 | QModelIndex noteIndex = index(m_notes.indexOf(note)); |
2797 | 222 | emit dataChanged(noteIndex, noteIndex); | ||
2798 | 276 | } | 223 | } |
2799 | 277 | 224 | ||
2800 | 278 | void NotesStore::refreshNotebooks() | 225 | void NotesStore::refreshNotebooks() |
2801 | 279 | { | 226 | { |
2802 | 280 | if (m_token.isEmpty()) { | ||
2803 | 281 | qWarning() << "No token set. Cannot refresh notebooks."; | ||
2804 | 282 | return; | ||
2805 | 283 | } | ||
2806 | 284 | |||
2807 | 285 | FetchNotebooksJob *job = new FetchNotebooksJob(); | 227 | FetchNotebooksJob *job = new FetchNotebooksJob(); |
2812 | 286 | connect(job, &FetchNotebooksJob::resultReady, this, &NotesStore::fetchNotebooksJobDone); | 228 | connect(job, &FetchNotebooksJob::jobDone, this, &NotesStore::fetchNotebooksJobDone); |
2813 | 287 | 229 | EvernoteConnection::instance()->enqueue(job); | |
2810 | 288 | m_jobQueue.append(job); | ||
2811 | 289 | startJobQueue(); | ||
2814 | 290 | } | 230 | } |
2815 | 291 | 231 | ||
2817 | 292 | void NotesStore::fetchNotebooksJobDone(ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results) | 232 | void NotesStore::fetchNotebooksJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results) |
2818 | 293 | { | 233 | { |
2822 | 294 | if (errorCode != ErrorCodeNoError) { | 234 | if (errorCode != EvernoteConnection::ErrorCodeNoError) { |
2823 | 295 | qWarning() << "Error fetching notebooks:" << errorCodeToString(errorCode); | 235 | qWarning() << "Error fetching notebooks:" << errorMessage; |
2821 | 296 | startNextJob(); | ||
2824 | 297 | return; | 236 | return; |
2825 | 298 | } | 237 | } |
2826 | 299 | 238 | ||
2827 | 300 | for (int i = 0; i < results.size(); ++i) { | 239 | for (int i = 0; i < results.size(); ++i) { |
2828 | 301 | evernote::edam::Notebook result = results.at(i); | 240 | evernote::edam::Notebook result = results.at(i); |
2835 | 302 | Notebook *notebook = m_notebooks.value(QString::fromStdString(result.guid)); | 241 | Notebook *notebook = m_notebooksHash.value(QString::fromStdString(result.guid)); |
2836 | 303 | if (notebook) { | 242 | bool newNoteNotebook = notebook == 0; |
2837 | 304 | qDebug() << "got notebook update"; | 243 | if (newNoteNotebook) { |
2832 | 305 | notebook->setName(QString::fromStdString(result.name)); | ||
2833 | 306 | emit notebookChanged(notebook->guid()); | ||
2834 | 307 | } else { | ||
2838 | 308 | notebook = new Notebook(QString::fromStdString(result.guid), this); | 244 | notebook = new Notebook(QString::fromStdString(result.guid), this); |
2841 | 309 | notebook->setName(QString::fromStdString(result.name)); | 245 | } |
2842 | 310 | m_notebooks.insert(notebook->guid(), notebook); | 246 | notebook->setName(QString::fromStdString(result.name)); |
2843 | 247 | |||
2844 | 248 | if (newNoteNotebook) { | ||
2845 | 249 | m_notebooksHash.insert(notebook->guid(), notebook); | ||
2846 | 250 | m_notebooks.append(notebook); | ||
2847 | 311 | emit notebookAdded(notebook->guid()); | 251 | emit notebookAdded(notebook->guid()); |
2849 | 312 | qDebug() << "got new notebook" << notebook->guid(); | 252 | } else { |
2850 | 253 | emit notebookChanged(notebook->guid()); | ||
2851 | 313 | } | 254 | } |
2852 | 314 | } | 255 | } |
2853 | 315 | |||
2854 | 316 | startNextJob(); | ||
2855 | 317 | } | 256 | } |
2856 | 318 | 257 | ||
2857 | 319 | void NotesStore::createNote(const QString &title, const QString ¬ebookGuid, const QString &content) | 258 | void NotesStore::createNote(const QString &title, const QString ¬ebookGuid, const QString &content) |
2858 | 320 | { | 259 | { |
2894 | 321 | Note *note = new Note(); | 260 | CreateNoteJob *job = new CreateNoteJob(title, notebookGuid, content); |
2895 | 322 | note->setTitle(title); | 261 | connect(job, &CreateNoteJob::jobDone, this, &NotesStore::createNoteJobDone); |
2896 | 323 | note->setNotebookGuid(notebookGuid); | 262 | EvernoteConnection::instance()->enqueue(job); |
2897 | 324 | note->setContent(content); | 263 | } |
2898 | 325 | CreateNoteJob *job = new CreateNoteJob(note); | 264 | |
2899 | 326 | connect(job, &CreateNoteJob::resultReady, this, &NotesStore::createNoteJobDone); | 265 | void NotesStore::createNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result) |
2900 | 327 | 266 | { | |
2901 | 328 | m_jobQueue.append(job); | 267 | if (errorCode != EvernoteConnection::ErrorCodeNoError) { |
2902 | 329 | startJobQueue(); | 268 | qWarning() << "Error creating note:" << errorMessage; |
2903 | 330 | } | 269 | return; |
2904 | 331 | 270 | } | |
2905 | 332 | void NotesStore::createNoteJobDone(NotesStore::ErrorCode errorCode, Note *note) | 271 | |
2906 | 333 | { | 272 | QString guid = QString::fromStdString(result.guid); |
2907 | 334 | if (errorCode != ErrorCodeNoError) { | 273 | QDateTime created = QDateTime::fromMSecsSinceEpoch(result.created); |
2908 | 335 | qWarning() << "Error creating note:" << errorCodeToString(errorCode); | 274 | Note *note = new Note(guid, created, this); |
2909 | 336 | delete note; | 275 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); |
2910 | 337 | startNextJob(); | 276 | note->setTitle(QString::fromStdString(result.title)); |
2911 | 338 | return; | 277 | note->setContent(QString::fromStdString(result.content)); |
2912 | 339 | } | 278 | |
2913 | 340 | 279 | beginInsertRows(QModelIndex(), m_notes.count(), m_notes.count()); | |
2914 | 341 | m_notes.insert(note->guid(), note); | 280 | m_notesHash.insert(note->guid(), note); |
2915 | 342 | noteAdded(note->guid()); | 281 | m_notes.append(note); |
2916 | 343 | startNextJob(); | 282 | endInsertRows(); |
2917 | 344 | } | 283 | |
2918 | 345 | 284 | emit noteAdded(note->guid()); | |
2919 | 346 | void NotesStore::saveNoteJobDone(NotesStore::ErrorCode errorCode, Note *note) | 285 | } |
2920 | 347 | { | 286 | |
2921 | 348 | startNextJob(); | 287 | void NotesStore::saveNote(const QString &guid) |
2922 | 349 | } | 288 | { |
2923 | 350 | 289 | Note *note = m_notesHash.value(guid); | |
2924 | 351 | void NotesStore::deleteNoteJobDone(NotesStore::ErrorCode errorCode, const QString &guid) | 290 | |
2925 | 352 | { | 291 | QString enml = Html2EnmlConverter::html2enml(note->content()); |
2926 | 353 | if (errorCode != ErrorCodeNoError) { | 292 | note->setContent(enml); |
2927 | 354 | qWarning() << "Cannot delete note:" << errorCodeToString(errorCode); | 293 | |
2928 | 355 | startNextJob(); | 294 | SaveNoteJob *job = new SaveNoteJob(note, this); |
2929 | 295 | connect(job, &SaveNoteJob::jobDone, this, &NotesStore::saveNoteJobDone); | ||
2930 | 296 | EvernoteConnection::instance()->enqueue(job); | ||
2931 | 297 | } | ||
2932 | 298 | |||
2933 | 299 | void NotesStore::saveNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result) | ||
2934 | 300 | { | ||
2935 | 301 | if (errorCode != EvernoteConnection::ErrorCodeNoError) { | ||
2936 | 302 | qWarning() << "error saving note" << errorMessage; | ||
2937 | 303 | return; | ||
2938 | 304 | } | ||
2939 | 305 | |||
2940 | 306 | Note *note = m_notesHash.value(QString::fromStdString(result.guid)); | ||
2941 | 307 | if (note) { | ||
2942 | 308 | note->setTitle(QString::fromStdString(result.title)); | ||
2943 | 309 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); | ||
2944 | 310 | |||
2945 | 311 | emit noteChanged(note->guid()); | ||
2946 | 312 | |||
2947 | 313 | QModelIndex noteIndex = index(m_notes.indexOf(note)); | ||
2948 | 314 | emit dataChanged(noteIndex, noteIndex); | ||
2949 | 315 | } | ||
2950 | 316 | } | ||
2951 | 317 | |||
2952 | 318 | void NotesStore::deleteNote(const QString &guid) | ||
2953 | 319 | { | ||
2954 | 320 | DeleteNoteJob *job = new DeleteNoteJob(guid, this); | ||
2955 | 321 | connect(job, &DeleteNoteJob::jobDone, this, &NotesStore::deleteNoteJobDone); | ||
2956 | 322 | EvernoteConnection::instance()->enqueue(job); | ||
2957 | 323 | } | ||
2958 | 324 | |||
2959 | 325 | void NotesStore::findNotes(const QString &searchWords) | ||
2960 | 326 | { | ||
2961 | 327 | foreach (Note *note, m_notes) { | ||
2962 | 328 | note->setIsSearchResult(false); | ||
2963 | 329 | } | ||
2964 | 330 | emit dataChanged(index(0), index(m_notes.count()), QVector<int>() << RoleIsSearchResult); | ||
2965 | 331 | |||
2966 | 332 | FetchNotesJob *job = new FetchNotesJob(QString(), searchWords); | ||
2967 | 333 | connect(job, &FetchNotesJob::jobDone, this, &NotesStore::fetchNotesJobDone); | ||
2968 | 334 | EvernoteConnection::instance()->enqueue(job); | ||
2969 | 335 | } | ||
2970 | 336 | |||
2971 | 337 | void NotesStore::deleteNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid) | ||
2972 | 338 | { | ||
2973 | 339 | if (errorCode != EvernoteConnection::ErrorCodeNoError) { | ||
2974 | 340 | qWarning() << "Cannot delete note:" << errorMessage; | ||
2975 | 356 | return; | 341 | return; |
2976 | 357 | } | 342 | } |
2977 | 358 | emit noteRemoved(guid); | 343 | emit noteRemoved(guid); |
2982 | 359 | m_notes.take(guid)->deleteLater(); | 344 | |
2983 | 360 | startNextJob(); | 345 | Note *note = m_notesHash.value(guid); |
2984 | 361 | } | 346 | int noteIndex = m_notes.indexOf(note); |
2985 | 362 | 347 | beginRemoveRows(QModelIndex(), noteIndex, noteIndex); | |
2986 | 348 | m_notes.takeAt(noteIndex); | ||
2987 | 349 | m_notesHash.take(guid)->deleteLater(); | ||
2988 | 350 | endRemoveRows(); | ||
2989 | 351 | } | ||
2990 | 352 | |||
2991 | 353 | void NotesStore::createNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Notebook &result) | ||
2992 | 354 | { | ||
2993 | 355 | if (errorCode != EvernoteConnection::ErrorCodeNoError) { | ||
2994 | 356 | qWarning() << "Error creating notebook:" << errorMessage; | ||
2995 | 357 | return; | ||
2996 | 358 | } | ||
2997 | 359 | Notebook *notebook = new Notebook(QString::fromStdString(result.guid)); | ||
2998 | 360 | notebook->setName(QString::fromStdString(result.name)); | ||
2999 | 361 | m_notebooks.append(notebook); | ||
3000 | 362 | m_notebooksHash.insert(notebook->guid(), notebook); | ||
3001 | 363 | emit notebookAdded(notebook->guid()); | ||
3002 | 364 | } | ||
3003 | 365 | |||
3004 | 366 | void NotesStore::expungeNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid) | ||
3005 | 367 | { | ||
3006 | 368 | if (errorCode != EvernoteConnection::ErrorCodeNoError) { | ||
3007 | 369 | qWarning() << "Error expunging notebook:" << errorMessage; | ||
3008 | 370 | return; | ||
3009 | 371 | } | ||
3010 | 372 | emit notebookRemoved(guid); | ||
3011 | 373 | Notebook *notebook = m_notebooksHash.take(guid); | ||
3012 | 374 | m_notebooks.removeAll(notebook); | ||
3013 | 375 | notebook->deleteLater(); | ||
3014 | 376 | } | ||
3015 | 363 | 377 | ||
3016 | === modified file 'src/plugin/Evernote/notesstore.h' | |||
3017 | --- src/plugin/Evernote/notesstore.h 2013-11-25 00:49:48 +0000 | |||
3018 | +++ src/plugin/Evernote/notesstore.h 2013-12-14 00:07:45 +0000 | |||
3019 | @@ -1,53 +1,67 @@ | |||
3020 | 1 | #ifndef NOTESSTORE_H | 1 | #ifndef NOTESSTORE_H |
3021 | 2 | #define NOTESSTORE_H | 2 | #define NOTESSTORE_H |
3022 | 3 | 3 | ||
3023 | 4 | #include "evernoteconnection.h" | ||
3024 | 5 | |||
3025 | 6 | // Thrift | ||
3026 | 7 | #include <arpa/inet.h> // seems thrift forgot this one | ||
3027 | 8 | #include <protocol/TBinaryProtocol.h> | ||
3028 | 9 | #include <transport/THttpClient.h> | ||
3029 | 10 | #include <transport/TSSLSocket.h> | ||
3030 | 11 | #include <Thrift.h> | ||
3031 | 12 | |||
3032 | 4 | // Evernote SDK | 13 | // Evernote SDK |
3033 | 5 | #include <NoteStore.h> | 14 | #include <NoteStore.h> |
3034 | 6 | #include <NoteStore_constants.h> | 15 | #include <NoteStore_constants.h> |
3035 | 7 | #include <Errors_types.h> | 16 | #include <Errors_types.h> |
3036 | 8 | 17 | ||
3038 | 9 | #include <QObject> | 18 | #include <QAbstractListModel> |
3039 | 10 | #include <QHash> | 19 | #include <QHash> |
3040 | 11 | 20 | ||
3041 | 12 | class EvernoteJob; | ||
3042 | 13 | |||
3043 | 14 | class Notebook; | 21 | class Notebook; |
3044 | 15 | class Note; | 22 | class Note; |
3045 | 16 | 23 | ||
3047 | 17 | class NotesStore : public QObject | 24 | using namespace apache::thrift::transport; |
3048 | 25 | |||
3049 | 26 | class NotesStore : public QAbstractListModel | ||
3050 | 18 | { | 27 | { |
3051 | 19 | Q_OBJECT | 28 | Q_OBJECT |
3052 | 20 | Q_PROPERTY(QString token READ token WRITE setToken NOTIFY tokenChanged) | ||
3053 | 21 | |||
3054 | 22 | friend class EvernoteJob; | ||
3055 | 23 | 29 | ||
3056 | 24 | public: | 30 | public: |
3063 | 25 | enum ErrorCode { | 31 | enum Roles { |
3064 | 26 | ErrorCodeNoError, | 32 | RoleGuid, |
3065 | 27 | ErrorCodeUserException, | 33 | RoleNotebookGuid, |
3066 | 28 | ErrorCodeSystemException, | 34 | RoleCreated, |
3067 | 29 | ErrorCodeNotFoundExcpetion, | 35 | RoleTitle, |
3068 | 30 | ErrorCodeConnectionLost | 36 | RoleReminder, |
3069 | 37 | RoleReminderTime, | ||
3070 | 38 | RoleReminderDone, | ||
3071 | 39 | RoleReminderDoneTime, | ||
3072 | 40 | RoleIsSearchResult | ||
3073 | 31 | }; | 41 | }; |
3074 | 32 | 42 | ||
3077 | 33 | Q_INVOKABLE void createNote(const QString &title, const QString ¬ebookGuid, const QString &content); | 43 | ~NotesStore(); |
3076 | 34 | |||
3078 | 35 | static NotesStore *instance(); | 44 | static NotesStore *instance(); |
3085 | 36 | static QString errorCodeToString(ErrorCode errorCode); | 45 | |
3086 | 37 | 46 | // reimplemented from QAbstractListModel | |
3087 | 38 | ~NotesStore(); | 47 | int rowCount(const QModelIndex &parent) const; |
3088 | 39 | 48 | QVariant data(const QModelIndex &index, int role) const; | |
3089 | 40 | QString token() const; | 49 | QHash<int, QByteArray> roleNames() const; |
3084 | 41 | void setToken(const QString &token); | ||
3090 | 42 | 50 | ||
3091 | 43 | QList<Note*> notes() const; | 51 | QList<Note*> notes() const; |
3095 | 44 | Note* note(const QString &guid); | 52 | |
3096 | 45 | void saveNote(const QString &guid); | 53 | Q_INVOKABLE Note* note(const QString &guid); |
3097 | 46 | void deleteNote(const QString &guid); | 54 | Q_INVOKABLE void createNote(const QString &title, const QString ¬ebookGuid, const QString &content); |
3098 | 55 | Q_INVOKABLE void saveNote(const QString &guid); | ||
3099 | 56 | Q_INVOKABLE void deleteNote(const QString &guid); | ||
3100 | 57 | Q_INVOKABLE void findNotes(const QString &searchWords); | ||
3101 | 47 | 58 | ||
3102 | 48 | QList<Notebook*> notebooks() const; | 59 | QList<Notebook*> notebooks() const; |
3103 | 49 | Notebook* notebook(const QString &guid); | 60 | Notebook* notebook(const QString &guid); |
3104 | 61 | Q_INVOKABLE void createNotebook(const QString &name); | ||
3105 | 62 | Q_INVOKABLE void expungeNotebook(const QString &guid); | ||
3106 | 50 | 63 | ||
3107 | 64 | public slots: | ||
3108 | 51 | void refreshNotes(const QString &filterNotebookGuid = QString()); | 65 | void refreshNotes(const QString &filterNotebookGuid = QString()); |
3109 | 52 | void refreshNoteContent(const QString &guid); | 66 | void refreshNoteContent(const QString &guid); |
3110 | 53 | void refreshNotebooks(); | 67 | void refreshNotebooks(); |
3111 | @@ -61,30 +75,28 @@ | |||
3112 | 61 | 75 | ||
3113 | 62 | void notebookAdded(const QString &guid); | 76 | void notebookAdded(const QString &guid); |
3114 | 63 | void notebookChanged(const QString &guid); | 77 | void notebookChanged(const QString &guid); |
3115 | 78 | void notebookRemoved(const QString &guid); | ||
3116 | 64 | 79 | ||
3117 | 65 | private slots: | 80 | private slots: |
3127 | 66 | void fetchNotesJobDone(ErrorCode errorCode, const evernote::edam::NotesMetadataList &results); | 81 | void fetchNotesJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results); |
3128 | 67 | void fetchNotebooksJobDone(ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results); | 82 | void fetchNotebooksJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results); |
3129 | 68 | void fetchNoteJobDone(ErrorCode errorCode, const evernote::edam::Note &result); | 83 | void fetchNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result); |
3130 | 69 | void createNoteJobDone(ErrorCode errorCode, Note *note); | 84 | void createNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result); |
3131 | 70 | void saveNoteJobDone(ErrorCode errorCode, Note *note); | 85 | void saveNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result); |
3132 | 71 | void deleteNoteJobDone(ErrorCode errorCode, const QString &guid); | 86 | void deleteNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid); |
3133 | 72 | 87 | void createNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Notebook &result); | |
3134 | 73 | void startJobQueue(); | 88 | void expungeNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid); |
3126 | 74 | void startNextJob(); | ||
3135 | 75 | 89 | ||
3136 | 76 | private: | 90 | private: |
3137 | 77 | explicit NotesStore(QObject *parent = 0); | 91 | explicit NotesStore(QObject *parent = 0); |
3138 | 78 | static NotesStore *s_instance; | 92 | static NotesStore *s_instance; |
3139 | 79 | 93 | ||
3148 | 80 | QString m_token; | 94 | QList<Note*> m_notes; |
3149 | 81 | evernote::edam::NoteStoreClient *m_client; | 95 | QList<Notebook*> m_notebooks; |
3150 | 82 | 96 | ||
3151 | 83 | QHash<QString, Notebook*> m_notebooks; | 97 | // Keep hashes for faster lookups as we always identify notes via guid |
3152 | 84 | QHash<QString, Note*> m_notes; | 98 | QHash<QString, Note*> m_notesHash; |
3153 | 85 | 99 | QHash<QString, Notebook*> m_notebooksHash; | |
3146 | 86 | QList<EvernoteJob*> m_jobQueue; | ||
3147 | 87 | QThread *m_currentJob; | ||
3154 | 88 | }; | 100 | }; |
3155 | 89 | 101 | ||
3156 | 90 | #endif // NOTESSTORE_H | 102 | #endif // NOTESSTORE_H |
3157 | 91 | 103 | ||
3158 | === modified file 'src/plugin/Evernote/userstore.cpp' | |||
3159 | --- src/plugin/Evernote/userstore.cpp 2013-11-26 17:18:33 +0000 | |||
3160 | +++ src/plugin/Evernote/userstore.cpp 2013-12-14 00:07:45 +0000 | |||
3161 | @@ -19,6 +19,8 @@ | |||
3162 | 19 | */ | 19 | */ |
3163 | 20 | 20 | ||
3164 | 21 | #include "userstore.h" | 21 | #include "userstore.h" |
3165 | 22 | #include "evernoteconnection.h" | ||
3166 | 23 | #include "jobs/fetchusernamejob.h" | ||
3167 | 22 | 24 | ||
3168 | 23 | // Evernote sdk | 25 | // Evernote sdk |
3169 | 24 | #include <UserStore.h> | 26 | #include <UserStore.h> |
3170 | @@ -34,106 +36,47 @@ | |||
3171 | 34 | 36 | ||
3172 | 35 | #include <QDebug> | 37 | #include <QDebug> |
3173 | 36 | 38 | ||
3174 | 37 | using namespace evernote::edam; | ||
3175 | 38 | using namespace apache::thrift; | 39 | using namespace apache::thrift; |
3176 | 39 | using namespace apache::thrift::protocol; | 40 | using namespace apache::thrift::protocol; |
3177 | 40 | using namespace apache::thrift::transport; | 41 | using namespace apache::thrift::transport; |
3178 | 41 | 42 | ||
3179 | 43 | UserStore* UserStore::s_instance = 0; | ||
3180 | 44 | |||
3181 | 42 | UserStore::UserStore(QObject *parent) : | 45 | UserStore::UserStore(QObject *parent) : |
3182 | 43 | QObject(parent) | 46 | QObject(parent) |
3183 | 44 | { | 47 | { |
3278 | 45 | 48 | connect(EvernoteConnection::instance(), &EvernoteConnection::tokenChanged, this, &UserStore::fetchUsername); | |
3279 | 46 | try { | 49 | |
3280 | 47 | // FIXME: need to populate this string from the system | 50 | fetchUsername(); |
3281 | 48 | // The structure should be: | 51 | } |
3282 | 49 | // application/version; platform/version; [ device/version ] | 52 | |
3283 | 50 | // E.g. "Evernote Windows/3.0.1; Windows/XP SP3" | 53 | UserStore *UserStore::instance() |
3284 | 51 | QString EDAM_CLIENT_NAME = QStringLiteral("Reminders/0.1; Ubuntu/13.10"); | 54 | { |
3285 | 52 | QString EVERNOTE_HOST = QStringLiteral("sandbox.evernote.com"); | 55 | if (!s_instance) { |
3286 | 53 | QString EDAM_USER_STORE_PATH = QStringLiteral("/edam/user"); | 56 | s_instance = new UserStore(); |
3287 | 54 | boost::shared_ptr<TSocket> socket; | 57 | } |
3288 | 55 | bool use_SSL = false; | 58 | return s_instance; |
3289 | 56 | 59 | } | |
3290 | 57 | if (use_SSL) { | 60 | |
3291 | 58 | // Create an SSL socket | 61 | QString UserStore::username() const |
3292 | 59 | // FIXME: this fails with the following error: | 62 | { |
3293 | 60 | // Thrift: Fri Nov 15 12:47:31 2013 SSL_shutdown: error code: 0 | 63 | return m_username; |
3294 | 61 | // SSL_get_verify_result(), unable to get local issuer certificate | 64 | } |
3295 | 62 | // Additionally, the UI blocks and does not load for about 2 minutes | 65 | |
3296 | 63 | boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory()); | 66 | void UserStore::fetchUsername() |
3297 | 64 | socket = sslSocketFactory->createSocket(EVERNOTE_HOST.toStdString(), 443); | 67 | { |
3298 | 65 | } else { | 68 | FetchUsernameJob *job = new FetchUsernameJob(); |
3299 | 66 | // Create a non-secure socket | 69 | connect(job, &FetchUsernameJob::jobDone, this, &UserStore::fetchUsernameJobDone); |
3300 | 67 | socket = boost::shared_ptr<TSocket> (new TSocket(EVERNOTE_HOST.toStdString(), 80)); | 70 | EvernoteConnection::instance()->enqueue(job); |
3301 | 68 | } | 71 | } |
3302 | 69 | 72 | ||
3303 | 70 | boost::shared_ptr<TBufferedTransport> bufferedTransport(new TBufferedTransport(socket)); | 73 | void UserStore::fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result) |
3304 | 71 | boost::shared_ptr<THttpClient> userStoreHttpClient (new THttpClient(bufferedTransport, | 74 | { |
3305 | 72 | EVERNOTE_HOST.toStdString(), | 75 | if (errorCode != EvernoteConnection::ErrorCodeNoError) { |
3306 | 73 | EDAM_USER_STORE_PATH.toStdString())); | 76 | qWarning() << "Error fetching username:" << errorMessage; |
3307 | 74 | userStoreHttpClient->open(); | 77 | return; |
3308 | 75 | 78 | } | |
3309 | 76 | boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(userStoreHttpClient)); | 79 | |
3310 | 77 | UserStoreClient m_client(iprot); | 80 | m_username = result; |
3311 | 78 | UserStoreConstants constants; | 81 | emit usernameChanged(); |
3218 | 79 | |||
3219 | 80 | // checkVersion returns true if the client is capable of talking to the service, | ||
3220 | 81 | // false otherwise | ||
3221 | 82 | qDebug() << "version check:" << m_client.checkVersion(EDAM_CLIENT_NAME.toStdString(), | ||
3222 | 83 | constants.EDAM_VERSION_MAJOR, | ||
3223 | 84 | constants.EDAM_VERSION_MINOR); | ||
3224 | 85 | |||
3225 | 86 | } catch(...) { | ||
3226 | 87 | displayException(); | ||
3227 | 88 | } | ||
3228 | 89 | } | ||
3229 | 90 | |||
3230 | 91 | void UserStore::getPublicUserInfo(const QString &user) | ||
3231 | 92 | { | ||
3232 | 93 | qDebug() << "should get public user info for user" << user; | ||
3233 | 94 | // PublicUserInfo userInfo; | ||
3234 | 95 | |||
3235 | 96 | } | ||
3236 | 97 | |||
3237 | 98 | // TODO: move to a common place instead of copying it through *store.cpps | ||
3238 | 99 | void UserStore::displayException() | ||
3239 | 100 | { | ||
3240 | 101 | QString error_message = "Unknown Exception"; | ||
3241 | 102 | try | ||
3242 | 103 | { | ||
3243 | 104 | // this function is meant to be called from a catch block | ||
3244 | 105 | // rethrow the exception to catch it again | ||
3245 | 106 | throw; | ||
3246 | 107 | } | ||
3247 | 108 | catch (const EDAMNotFoundException & e) | ||
3248 | 109 | { | ||
3249 | 110 | qDebug() << e.what(); | ||
3250 | 111 | } | ||
3251 | 112 | catch (const EDAMSystemException & e) | ||
3252 | 113 | { | ||
3253 | 114 | qDebug() << e.what(); | ||
3254 | 115 | } | ||
3255 | 116 | catch (const EDAMUserException & e) | ||
3256 | 117 | { | ||
3257 | 118 | qDebug() << e.what(); | ||
3258 | 119 | } | ||
3259 | 120 | catch (const TTransportException & e) | ||
3260 | 121 | { | ||
3261 | 122 | qDebug() << e.what(); | ||
3262 | 123 | } | ||
3263 | 124 | catch (const TException & e) | ||
3264 | 125 | { | ||
3265 | 126 | qDebug() << e.what(); | ||
3266 | 127 | } | ||
3267 | 128 | catch (const std::exception & e) | ||
3268 | 129 | { | ||
3269 | 130 | qDebug() << e.what(); | ||
3270 | 131 | } | ||
3271 | 132 | catch (...) | ||
3272 | 133 | { | ||
3273 | 134 | error_message = "Tried to sync, but something went wrong.\n Unknown exception."; | ||
3274 | 135 | } | ||
3275 | 136 | |||
3276 | 137 | qDebug() << error_message; | ||
3277 | 138 | disconnect(); | ||
3312 | 139 | } | 82 | } |
3313 | 140 | 83 | ||
3314 | === modified file 'src/plugin/Evernote/userstore.h' | |||
3315 | --- src/plugin/Evernote/userstore.h 2013-11-24 17:03:28 +0000 | |||
3316 | +++ src/plugin/Evernote/userstore.h 2013-12-14 00:07:45 +0000 | |||
3317 | @@ -1,6 +1,9 @@ | |||
3318 | 1 | #ifndef USERSTORE_H | 1 | #ifndef USERSTORE_H |
3319 | 2 | #define USERSTORE_H | 2 | #define USERSTORE_H |
3320 | 3 | 3 | ||
3321 | 4 | #include "evernoteconnection.h" | ||
3322 | 5 | |||
3323 | 6 | //Evernote SDK | ||
3324 | 4 | #include "UserStore.h" | 7 | #include "UserStore.h" |
3325 | 5 | 8 | ||
3326 | 6 | #include <QObject> | 9 | #include <QObject> |
3327 | @@ -8,17 +11,28 @@ | |||
3328 | 8 | class UserStore : public QObject | 11 | class UserStore : public QObject |
3329 | 9 | { | 12 | { |
3330 | 10 | Q_OBJECT | 13 | Q_OBJECT |
3331 | 14 | |||
3332 | 15 | // TODO: Once we need more than just the username, turn this into a class User | ||
3333 | 16 | Q_PROPERTY(QString username READ username NOTIFY usernameChanged) | ||
3334 | 17 | |||
3335 | 11 | public: | 18 | public: |
3337 | 12 | explicit UserStore(QObject *parent = 0); | 19 | static UserStore* instance(); |
3338 | 20 | |||
3339 | 21 | QString username() const; | ||
3340 | 13 | 22 | ||
3341 | 14 | signals: | 23 | signals: |
3345 | 15 | 24 | void usernameChanged(); | |
3346 | 16 | public slots: | 25 | |
3347 | 17 | void getPublicUserInfo(const QString &user); | 26 | private slots: |
3348 | 27 | void fetchUsername(); | ||
3349 | 28 | |||
3350 | 29 | void fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result); | ||
3351 | 18 | 30 | ||
3352 | 19 | private: | 31 | private: |
3353 | 32 | static UserStore* s_instance; | ||
3354 | 33 | explicit UserStore(QObject *parent = 0); | ||
3355 | 20 | 34 | ||
3357 | 21 | void displayException(); | 35 | QString m_username; |
3358 | 22 | }; | 36 | }; |
3359 | 23 | 37 | ||
3360 | 24 | #endif // USERSTORE_H | 38 | #endif // USERSTORE_H |
3361 | 25 | 39 | ||
3362 | === modified file 'src/plugin/Evernote/utils/html2enmlconverter.cpp' | |||
3363 | --- src/plugin/Evernote/utils/html2enmlconverter.cpp 2013-11-25 19:06:38 +0000 | |||
3364 | +++ src/plugin/Evernote/utils/html2enmlconverter.cpp 2013-12-14 00:07:45 +0000 | |||
3365 | @@ -82,3 +82,25 @@ | |||
3366 | 82 | 82 | ||
3367 | 83 | return evml; | 83 | return evml; |
3368 | 84 | } | 84 | } |
3369 | 85 | |||
3370 | 86 | QString Html2EnmlConverter::enml2plaintext(const QString &enml) | ||
3371 | 87 | { | ||
3372 | 88 | // output | ||
3373 | 89 | QString plaintext; | ||
3374 | 90 | |||
3375 | 91 | // input | ||
3376 | 92 | QXmlStreamReader reader(enml); | ||
3377 | 93 | |||
3378 | 94 | while (!reader.atEnd() && !reader.hasError()) { | ||
3379 | 95 | QXmlStreamReader::TokenType token = reader.readNext(); | ||
3380 | 96 | |||
3381 | 97 | // Write all normal text inside <body> </body> to output | ||
3382 | 98 | if (token == QXmlStreamReader::Characters) { | ||
3383 | 99 | plaintext.append(reader.text().toString()); | ||
3384 | 100 | plaintext.append(' '); | ||
3385 | 101 | } | ||
3386 | 102 | } | ||
3387 | 103 | |||
3388 | 104 | plaintext.remove('\n'); | ||
3389 | 105 | return plaintext; | ||
3390 | 106 | } | ||
3391 | 85 | 107 | ||
3392 | === modified file 'src/plugin/Evernote/utils/html2enmlconverter.h' | |||
3393 | --- src/plugin/Evernote/utils/html2enmlconverter.h 2013-11-25 19:06:38 +0000 | |||
3394 | +++ src/plugin/Evernote/utils/html2enmlconverter.h 2013-12-14 00:07:45 +0000 | |||
3395 | @@ -9,6 +9,8 @@ | |||
3396 | 9 | Html2EnmlConverter(); | 9 | Html2EnmlConverter(); |
3397 | 10 | 10 | ||
3398 | 11 | static QString html2enml(const QString &html); | 11 | static QString html2enml(const QString &html); |
3399 | 12 | |||
3400 | 13 | static QString enml2plaintext(const QString &enml); | ||
3401 | 12 | }; | 14 | }; |
3402 | 13 | 15 | ||
3403 | 14 | #endif // HTML2ENMLCONVERTER_H | 16 | #endif // HTML2ENMLCONVERTER_H |
FAILED: Continuous integration, rev:24 91.189. 93.70:8080/ job/reminders- app-ci/ 38/ 91.189. 93.70:8080/ job/generic- mediumtests- trusty/ 441 91.189. 93.70:8080/ job/reminders- app-saucy- amd64-ci/ 38/console 91.189. 93.70:8080/ job/reminders- app-trusty- amd64-ci/ 38/console
http://
Executed test runs:
UNSTABLE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: 91.189. 93.70:8080/ job/reminders- app-ci/ 38/rebuild
http://