Merge lp:~mzanetti/reminders-app/add-reminders into lp:reminders-app
- add-reminders
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Michael Zanetti |
Approved revision: | 19 |
Merged at revision: | 17 |
Proposed branch: | lp:~mzanetti/reminders-app/add-reminders |
Merge into: | lp:reminders-app |
Prerequisite: | lp:~mzanetti/reminders-app/get-username |
Diff against target: |
952 lines (+375/-195) 13 files modified
src/app/qml/ui/NotesPage.qml (+2/-3) src/app/qml/ui/RemindersPage.qml (+9/-10) src/plugin/Evernote/jobs/evernotejob.cpp (+1/-1) src/plugin/Evernote/jobs/fetchnotesjob.cpp (+13/-3) src/plugin/Evernote/jobs/savenotejob.cpp (+22/-13) src/plugin/Evernote/jobs/savenotejob.h (+2/-6) src/plugin/Evernote/note.cpp (+90/-10) src/plugin/Evernote/note.h (+44/-4) src/plugin/Evernote/notebooks.cpp (+0/-1) src/plugin/Evernote/notes.cpp (+38/-80) src/plugin/Evernote/notes.h (+11/-24) src/plugin/Evernote/notesstore.cpp (+116/-31) src/plugin/Evernote/notesstore.h (+27/-9) |
To merge this branch: | bzr merge lp:~mzanetti/reminders-app/add-reminders |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Jordan Keyes | Approve | ||
Review via email: mp+197261@code.launchpad.net |
Commit message
Add support for reminders
Description of the change
This adds support for reminders.
Also moves the QAbstractListModel logic into notesstore, so that Notes is just a stupid QSortFilterProx
- 17. By Michael Zanetti
-
fix savenotejob to also store reminder stuff
- 18. By Michael Zanetti
-
delete note clone after savejob is done
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:18
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Jordan Keyes (jkeyes0) wrote : | # |
Maybe this is by design, but when you select a note from the Notes tab, then click the "Save" button (or make a change to the text and click "Save"), it adds a reminder to the note. I haven't noticed this behavior from other Evernote clients.
It appears this was added in src/plugin/
Is this something that will need to be pulled out and put into a separate job for when a new reminder is created?
Michael Zanetti (mzanetti) wrote : | # |
> Maybe this is by design, but when you select a note from the Notes tab, then
> click the "Save" button (or make a change to the text and click "Save"), it
> adds a reminder to the note. I haven't noticed this behavior from other
> Evernote clients.
No, this is a bug in my code. Thanks for finding!
> It appears this was added in src/plugin/
> SaveNoteJob:
>
> Is this something that will need to be pulled out and put into a separate job
> for when a new reminder is created?
Not really no, we just need initialize it with some sane defaults... I'll fix tonight.
Btw. feel free to put "Needs fixing" on my merges. If really unsure, mark it as "Needs information". I'm thankful for every found issue. After all that's what those merge requests are for.
- 19. By Michael Zanetti
-
fix reminder flag when saving notes
Michael Zanetti (mzanetti) wrote : | # |
> Maybe this is by design, but when you select a note from the Notes tab, then
> click the "Save" button (or make a change to the text and click "Save"), it
> adds a reminder to the note. I haven't noticed this behavior from other
> Evernote clients.
fixed
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:19
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'src/app/qml/ui/NotesPage.qml' | |||
2 | --- src/app/qml/ui/NotesPage.qml 2013-11-26 17:18:33 +0000 | |||
3 | +++ src/app/qml/ui/NotesPage.qml 2013-12-12 21:36:37 +0000 | |||
4 | @@ -28,8 +28,7 @@ | |||
5 | 28 | 28 | ||
6 | 29 | onActiveChanged: { | 29 | onActiveChanged: { |
7 | 30 | if (active) { | 30 | if (active) { |
10 | 31 | print("refreshing notes") | 31 | NotesStore.refreshNotes(); |
9 | 32 | notes.refresh(); | ||
11 | 33 | } | 32 | } |
12 | 34 | } | 33 | } |
13 | 35 | 34 | ||
14 | @@ -59,7 +58,7 @@ | |||
15 | 59 | text: title | 58 | text: title |
16 | 60 | 59 | ||
17 | 61 | onClicked: { | 60 | onClicked: { |
19 | 62 | pageStack.push(Qt.resolvedUrl("NotePage.qml"), {note: notes.note(guid)}) | 61 | pageStack.push(Qt.resolvedUrl("NotePage.qml"), {note: NotesStore.note(guid)}) |
20 | 63 | } | 62 | } |
21 | 64 | 63 | ||
22 | 65 | onPressAndHold: { | 64 | onPressAndHold: { |
23 | 66 | 65 | ||
24 | === modified file 'src/app/qml/ui/RemindersPage.qml' | |||
25 | --- src/app/qml/ui/RemindersPage.qml 2013-11-26 17:18:33 +0000 | |||
26 | +++ src/app/qml/ui/RemindersPage.qml 2013-12-12 21:36:37 +0000 | |||
27 | @@ -19,28 +19,27 @@ | |||
28 | 19 | import QtQuick 2.0 | 19 | import QtQuick 2.0 |
29 | 20 | import Ubuntu.Components 0.1 | 20 | import Ubuntu.Components 0.1 |
30 | 21 | import Ubuntu.Components.ListItems 0.1 | 21 | import Ubuntu.Components.ListItems 0.1 |
32 | 22 | //import "../components" | 22 | import Evernote 0.1 |
33 | 23 | 23 | ||
34 | 24 | Page { | 24 | Page { |
35 | 25 | id: remindersPage | 25 | id: remindersPage |
36 | 26 | 26 | ||
41 | 27 | Label { | 27 | Notes { |
42 | 28 | id: developmentWarning | 28 | id: notes |
43 | 29 | anchors.centerIn: parent | 29 | onlyReminders: true |
40 | 30 | text: i18n.tr("This page is still in development") | ||
44 | 31 | } | 30 | } |
45 | 32 | 31 | ||
46 | 33 | ListView { | 32 | ListView { |
47 | 34 | 33 | ||
49 | 35 | width: parent.width; height: parent.height | 34 | anchors.fill: parent |
50 | 36 | 35 | ||
51 | 37 | delegate: Subtitled { | 36 | delegate: Subtitled { |
54 | 38 | text: '<b>Name:</b> ' + model.name | 37 | text: '<b>Name:</b> ' + model.title |
55 | 39 | subText: '<b>Date:</b> ' + model.date | 38 | subText: '<b>Date:</b> ' + Qt.formatDateTime(model.created) + |
56 | 39 | (model.reminderDone ? " - <b>Done:</b> " + Qt.formatDate(model.reminderDoneTime) : "") | ||
57 | 40 | } | 40 | } |
58 | 41 | 41 | ||
61 | 42 | // model: RemindersModel {} | 42 | model: notes |
60 | 43 | |||
62 | 44 | } | 43 | } |
63 | 45 | 44 | ||
64 | 46 | } | 45 | } |
65 | 47 | 46 | ||
66 | === modified file 'src/plugin/Evernote/jobs/evernotejob.cpp' | |||
67 | --- src/plugin/Evernote/jobs/evernotejob.cpp 2013-12-12 21:36:37 +0000 | |||
68 | +++ src/plugin/Evernote/jobs/evernotejob.cpp 2013-12-12 21:36:37 +0000 | |||
69 | @@ -48,7 +48,7 @@ | |||
70 | 48 | void EvernoteJob::run() | 48 | void EvernoteJob::run() |
71 | 49 | { | 49 | { |
72 | 50 | if (m_token.isEmpty()) { | 50 | if (m_token.isEmpty()) { |
74 | 51 | qWarning() << "No token set. Cannot execute job."; | 51 | qWarning() << "No token set. Cannot execute job. (" << this->metaObject()->className() << ")"; |
75 | 52 | emitJobDone(EvernoteConnection::ErrorCodeUserException, QStringLiteral("No token set.")); | 52 | emitJobDone(EvernoteConnection::ErrorCodeUserException, QStringLiteral("No token set.")); |
76 | 53 | return; | 53 | return; |
77 | 54 | } | 54 | } |
78 | 55 | 55 | ||
79 | === modified file 'src/plugin/Evernote/jobs/fetchnotesjob.cpp' | |||
80 | --- src/plugin/Evernote/jobs/fetchnotesjob.cpp 2013-12-12 21:36:37 +0000 | |||
81 | +++ src/plugin/Evernote/jobs/fetchnotesjob.cpp 2013-12-12 21:36:37 +0000 | |||
82 | @@ -22,6 +22,9 @@ | |||
83 | 22 | 22 | ||
84 | 23 | #include "notesstore.h" | 23 | #include "notesstore.h" |
85 | 24 | 24 | ||
86 | 25 | // evernote sdk | ||
87 | 26 | #include "Limits_constants.h" | ||
88 | 27 | |||
89 | 25 | #include <QDebug> | 28 | #include <QDebug> |
90 | 26 | 29 | ||
91 | 27 | FetchNotesJob::FetchNotesJob( const QString &filterNotebookGuid, QObject *parent) : | 30 | FetchNotesJob::FetchNotesJob( const QString &filterNotebookGuid, QObject *parent) : |
92 | @@ -32,10 +35,10 @@ | |||
93 | 32 | 35 | ||
94 | 33 | void FetchNotesJob::startJob() | 36 | void FetchNotesJob::startJob() |
95 | 34 | { | 37 | { |
96 | 35 | qDebug() << "starting fetch notes job"; | ||
97 | 36 | // TODO: fix start/end (use smaller chunks and continue fetching if there are more notes available) | 38 | // TODO: fix start/end (use smaller chunks and continue fetching if there are more notes available) |
98 | 37 | int32_t start = 0; | 39 | int32_t start = 0; |
100 | 38 | int32_t end = 10000; | 40 | evernote::limits::LimitsConstants limits; |
101 | 41 | int32_t end = limits.EDAM_USER_NOTES_MAX; | ||
102 | 39 | 42 | ||
103 | 40 | // Prepare filter | 43 | // Prepare filter |
104 | 41 | evernote::edam::NoteFilter filter; | 44 | evernote::edam::NoteFilter filter; |
105 | @@ -44,13 +47,20 @@ | |||
106 | 44 | 47 | ||
107 | 45 | // Prepare ResultSpec | 48 | // Prepare ResultSpec |
108 | 46 | evernote::edam::NotesMetadataResultSpec resultSpec; | 49 | evernote::edam::NotesMetadataResultSpec resultSpec; |
109 | 50 | |||
110 | 47 | resultSpec.includeNotebookGuid = true; | 51 | resultSpec.includeNotebookGuid = true; |
111 | 48 | resultSpec.__isset.includeNotebookGuid = true; | 52 | resultSpec.__isset.includeNotebookGuid = true; |
112 | 53 | |||
113 | 54 | resultSpec.includeCreated = true; | ||
114 | 55 | resultSpec.__isset.includeCreated = true; | ||
115 | 56 | |||
116 | 49 | resultSpec.includeTitle = true; | 57 | resultSpec.includeTitle = true; |
117 | 50 | resultSpec.__isset.includeTitle = true; | 58 | resultSpec.__isset.includeTitle = true; |
118 | 51 | 59 | ||
119 | 60 | resultSpec.includeAttributes = true; | ||
120 | 61 | resultSpec.__isset.includeAttributes = true; | ||
121 | 62 | |||
122 | 52 | client()->findNotesMetadata(m_results, token().toStdString(), filter, start, end, resultSpec); | 63 | client()->findNotesMetadata(m_results, token().toStdString(), filter, start, end, resultSpec); |
123 | 53 | qDebug() << "ending fetch notes job"; | ||
124 | 54 | } | 64 | } |
125 | 55 | 65 | ||
126 | 56 | void FetchNotesJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) | 66 | void FetchNotesJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) |
127 | 57 | 67 | ||
128 | === modified file 'src/plugin/Evernote/jobs/savenotejob.cpp' | |||
129 | --- src/plugin/Evernote/jobs/savenotejob.cpp 2013-12-12 21:36:37 +0000 | |||
130 | +++ src/plugin/Evernote/jobs/savenotejob.cpp 2013-12-12 21:36:37 +0000 | |||
131 | @@ -24,31 +24,40 @@ | |||
132 | 24 | #include <QDebug> | 24 | #include <QDebug> |
133 | 25 | 25 | ||
134 | 26 | SaveNoteJob::SaveNoteJob(Note *note, QObject *parent) : | 26 | SaveNoteJob::SaveNoteJob(Note *note, QObject *parent) : |
140 | 27 | NotesStoreJob(parent), | 27 | NotesStoreJob(parent) |
136 | 28 | m_guid(note->guid()), | ||
137 | 29 | m_title(note->title()), | ||
138 | 30 | m_notebookGuid(note->notebookGuid()), | ||
139 | 31 | m_content(note->content()) | ||
141 | 32 | { | 28 | { |
142 | 29 | // Need to clone it. As startJob() will run in another thread we can't access the real note from there. | ||
143 | 30 | m_note = note->clone(); | ||
144 | 31 | |||
145 | 32 | // Make sure we delete the clone when done | ||
146 | 33 | m_note->setParent(this); | ||
147 | 33 | } | 34 | } |
148 | 34 | 35 | ||
149 | 35 | void SaveNoteJob::startJob() | 36 | void SaveNoteJob::startJob() |
150 | 36 | { | 37 | { |
151 | 37 | evernote::edam::Note note; | 38 | evernote::edam::Note note; |
153 | 38 | note.guid = m_guid.toStdString(); | 39 | note.guid = m_note->guid().toStdString(); |
154 | 39 | note.__isset.guid = true; | 40 | note.__isset.guid = true; |
156 | 40 | note.title = m_title.toStdString(); | 41 | note.title = m_note->title().toStdString(); |
157 | 41 | note.__isset.title = true; | 42 | note.__isset.title = true; |
159 | 42 | note.notebookGuid = m_notebookGuid.toStdString(); | 43 | note.notebookGuid = m_note->notebookGuid().toStdString(); |
160 | 43 | note.__isset.notebookGuid = true; | 44 | note.__isset.notebookGuid = true; |
162 | 44 | note.content = m_content.toStdString(); | 45 | note.content = m_note->content().toStdString(); |
163 | 45 | note.__isset.content = true; | 46 | note.__isset.content = true; |
167 | 46 | note.contentLength = m_content.length(); | 47 | note.contentLength = m_note->content().length(); |
168 | 47 | 48 | ||
169 | 48 | client()->updateNote(m_note, token().toStdString(), note); | 49 | note.__isset.attributes = true; |
170 | 50 | note.attributes.reminderOrder = m_note->reminderOrder(); | ||
171 | 51 | note.attributes.__isset.reminderOrder = true; | ||
172 | 52 | note.attributes.reminderTime = m_note->reminderTime().toMSecsSinceEpoch(); | ||
173 | 53 | note.attributes.__isset.reminderTime = true; | ||
174 | 54 | note.attributes.reminderDoneTime = m_note->reminderDoneTime().toMSecsSinceEpoch(); | ||
175 | 55 | note.attributes.__isset.reminderDoneTime = true; | ||
176 | 56 | |||
177 | 57 | client()->updateNote(m_resultNote, token().toStdString(), note); | ||
178 | 49 | } | 58 | } |
179 | 50 | 59 | ||
180 | 51 | void SaveNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) | 60 | void SaveNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) |
181 | 52 | { | 61 | { |
183 | 53 | emit jobDone(errorCode, errorMessage, m_note); | 62 | emit jobDone(errorCode, errorMessage, m_resultNote); |
184 | 54 | } | 63 | } |
185 | 55 | 64 | ||
186 | === modified file 'src/plugin/Evernote/jobs/savenotejob.h' | |||
187 | --- src/plugin/Evernote/jobs/savenotejob.h 2013-12-12 21:36:37 +0000 | |||
188 | +++ src/plugin/Evernote/jobs/savenotejob.h 2013-12-12 21:36:37 +0000 | |||
189 | @@ -17,12 +17,8 @@ | |||
190 | 17 | void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage); | 17 | void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage); |
191 | 18 | 18 | ||
192 | 19 | private: | 19 | private: |
199 | 20 | QString m_guid; | 20 | Note* m_note; |
200 | 21 | QString m_title; | 21 | evernote::edam::Note m_resultNote; |
195 | 22 | QString m_notebookGuid; | ||
196 | 23 | QString m_content; | ||
197 | 24 | |||
198 | 25 | evernote::edam::Note m_note; | ||
201 | 26 | }; | 22 | }; |
202 | 27 | 23 | ||
203 | 28 | #endif // SAVENOTEJOB_H | 24 | #endif // SAVENOTEJOB_H |
204 | 29 | 25 | ||
205 | === modified file 'src/plugin/Evernote/note.cpp' | |||
206 | --- src/plugin/Evernote/note.cpp 2013-12-12 21:36:37 +0000 | |||
207 | +++ src/plugin/Evernote/note.cpp 2013-12-12 21:36:37 +0000 | |||
208 | @@ -22,9 +22,12 @@ | |||
209 | 22 | 22 | ||
210 | 23 | #include "notesstore.h" | 23 | #include "notesstore.h" |
211 | 24 | 24 | ||
213 | 25 | Note::Note(const QString &guid, QObject *parent) : | 25 | #include <QDateTime> |
214 | 26 | |||
215 | 27 | Note::Note(const QString &guid, const QDateTime &created, QObject *parent) : | ||
216 | 26 | QObject(parent), | 28 | QObject(parent), |
218 | 27 | m_guid(guid) | 29 | m_guid(guid), |
219 | 30 | m_created(created) | ||
220 | 28 | { | 31 | { |
221 | 29 | } | 32 | } |
222 | 30 | 33 | ||
223 | @@ -33,14 +36,6 @@ | |||
224 | 33 | return m_guid; | 36 | return m_guid; |
225 | 34 | } | 37 | } |
226 | 35 | 38 | ||
227 | 36 | void Note::setGuid(const QString &guid) | ||
228 | 37 | { | ||
229 | 38 | if (m_guid != guid) { | ||
230 | 39 | m_guid = guid; | ||
231 | 40 | emit guidChanged(); | ||
232 | 41 | } | ||
233 | 42 | } | ||
234 | 43 | |||
235 | 44 | QString Note::notebookGuid() const | 39 | QString Note::notebookGuid() const |
236 | 45 | { | 40 | { |
237 | 46 | return m_notebookGuid; | 41 | return m_notebookGuid; |
238 | @@ -54,6 +49,11 @@ | |||
239 | 54 | } | 49 | } |
240 | 55 | } | 50 | } |
241 | 56 | 51 | ||
242 | 52 | QDateTime Note::created() const | ||
243 | 53 | { | ||
244 | 54 | return m_created; | ||
245 | 55 | } | ||
246 | 56 | |||
247 | 57 | QString Note::title() const | 57 | QString Note::title() const |
248 | 58 | { | 58 | { |
249 | 59 | return m_title; | 59 | return m_title; |
250 | @@ -80,6 +80,86 @@ | |||
251 | 80 | } | 80 | } |
252 | 81 | } | 81 | } |
253 | 82 | 82 | ||
254 | 83 | bool Note::reminder() const | ||
255 | 84 | { | ||
256 | 85 | return m_reminderOrder > 0; | ||
257 | 86 | } | ||
258 | 87 | |||
259 | 88 | void Note::setReminder(bool reminder) | ||
260 | 89 | { | ||
261 | 90 | if (reminder && m_reminderOrder == 0) { | ||
262 | 91 | m_reminderOrder = QDateTime::currentMSecsSinceEpoch(); | ||
263 | 92 | emit reminderChanged(); | ||
264 | 93 | } else if (!reminder && m_reminderOrder > 0) { | ||
265 | 94 | m_reminderOrder = 0; | ||
266 | 95 | emit reminderChanged(); | ||
267 | 96 | } | ||
268 | 97 | } | ||
269 | 98 | |||
270 | 99 | qint64 Note::reminderOrder() const | ||
271 | 100 | { | ||
272 | 101 | return m_reminderOrder; | ||
273 | 102 | } | ||
274 | 103 | |||
275 | 104 | void Note::setReminderOrder(qint64 reminderOrder) | ||
276 | 105 | { | ||
277 | 106 | if (m_reminderOrder != reminderOrder) { | ||
278 | 107 | m_reminderOrder = reminderOrder; | ||
279 | 108 | emit reminderChanged(); | ||
280 | 109 | } | ||
281 | 110 | } | ||
282 | 111 | |||
283 | 112 | QDateTime Note::reminderTime() const | ||
284 | 113 | { | ||
285 | 114 | return m_reminderTime; | ||
286 | 115 | } | ||
287 | 116 | |||
288 | 117 | void Note::setReminderTime(const QDateTime &reminderTime) | ||
289 | 118 | { | ||
290 | 119 | if (m_reminderTime != reminderTime) { | ||
291 | 120 | m_reminderTime = reminderTime; | ||
292 | 121 | emit reminderTimeChanged(); | ||
293 | 122 | } | ||
294 | 123 | } | ||
295 | 124 | |||
296 | 125 | bool Note::reminderDone() const | ||
297 | 126 | { | ||
298 | 127 | return !m_reminderDoneTime.isNull(); | ||
299 | 128 | } | ||
300 | 129 | |||
301 | 130 | void Note::setReminderDone(bool reminderDone) | ||
302 | 131 | { | ||
303 | 132 | if (reminderDone && m_reminderDoneTime.isNull()) { | ||
304 | 133 | m_reminderDoneTime = QDateTime::currentDateTime(); | ||
305 | 134 | emit reminderDoneChanged(); | ||
306 | 135 | } | ||
307 | 136 | } | ||
308 | 137 | |||
309 | 138 | QDateTime Note::reminderDoneTime() const | ||
310 | 139 | { | ||
311 | 140 | return m_reminderDoneTime; | ||
312 | 141 | } | ||
313 | 142 | |||
314 | 143 | void Note::setReminderDoneTime(const QDateTime &reminderDoneTime) | ||
315 | 144 | { | ||
316 | 145 | if (m_reminderDoneTime != reminderDoneTime) { | ||
317 | 146 | m_reminderDoneTime = reminderDoneTime; | ||
318 | 147 | emit reminderDoneChanged(); | ||
319 | 148 | } | ||
320 | 149 | } | ||
321 | 150 | |||
322 | 151 | Note *Note::clone() | ||
323 | 152 | { | ||
324 | 153 | Note *note = new Note(m_guid, m_created); | ||
325 | 154 | note->setNotebookGuid(m_notebookGuid); | ||
326 | 155 | note->setTitle(m_title); | ||
327 | 156 | note->setContent(m_content); | ||
328 | 157 | note->setReminderOrder(m_reminderOrder); | ||
329 | 158 | note->setReminderTime(m_reminderTime); | ||
330 | 159 | note->setReminderDoneTime(m_reminderDoneTime); | ||
331 | 160 | return note; | ||
332 | 161 | } | ||
333 | 162 | |||
334 | 83 | void Note::save() | 163 | void Note::save() |
335 | 84 | { | 164 | { |
336 | 85 | NotesStore::instance()->saveNote(m_guid); | 165 | NotesStore::instance()->saveNote(m_guid); |
337 | 86 | 166 | ||
338 | === modified file 'src/plugin/Evernote/note.h' | |||
339 | --- src/plugin/Evernote/note.h 2013-11-25 00:49:48 +0000 | |||
340 | +++ src/plugin/Evernote/note.h 2013-12-12 21:36:37 +0000 | |||
341 | @@ -2,45 +2,85 @@ | |||
342 | 2 | #define NOTE_H | 2 | #define NOTE_H |
343 | 3 | 3 | ||
344 | 4 | #include <QObject> | 4 | #include <QObject> |
345 | 5 | #include <QDateTime> | ||
346 | 6 | #include <QStringList> | ||
347 | 5 | 7 | ||
348 | 6 | class Note : public QObject | 8 | class Note : public QObject |
349 | 7 | { | 9 | { |
350 | 8 | Q_OBJECT | 10 | Q_OBJECT |
351 | 9 | 11 | ||
353 | 10 | Q_PROPERTY(QString guid READ guid NOTIFY guidChanged) | 12 | // Don't forget to update clone() if you add properties! |
354 | 13 | Q_PROPERTY(QString guid READ guid CONSTANT) | ||
355 | 11 | Q_PROPERTY(QString notebookGuid READ notebookGuid WRITE setNotebookGuid NOTIFY notebookGuidChanged) | 14 | Q_PROPERTY(QString notebookGuid READ notebookGuid WRITE setNotebookGuid NOTIFY notebookGuidChanged) |
356 | 15 | Q_PROPERTY(QDateTime created READ created CONSTANT) | ||
357 | 12 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) | 16 | Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) |
358 | 13 | Q_PROPERTY(QString content READ content WRITE setContent NOTIFY contentChanged) | 17 | Q_PROPERTY(QString content READ content WRITE setContent NOTIFY contentChanged) |
359 | 18 | Q_PROPERTY(bool reminder READ reminder WRITE setReminder NOTIFY reminderChanged) | ||
360 | 19 | Q_PROPERTY(QDateTime reminderTime READ reminderTime WRITE setReminderTime NOTIFY reminderTimeChanged) | ||
361 | 20 | Q_PROPERTY(bool reminderDone READ reminderDone WRITE setReminderDone NOTIFY reminderDoneChanged) | ||
362 | 21 | Q_PROPERTY(QDateTime reminderDoneTime READ reminderDoneTime WRITE setReminderDoneTime NOTIFY reminderDoneChanged) | ||
363 | 22 | // Don't forget to update clone() if you add properties! | ||
364 | 23 | |||
365 | 14 | public: | 24 | public: |
367 | 15 | explicit Note(const QString &guid = QString(), QObject *parent = 0); | 25 | explicit Note(const QString &guid, const QDateTime &created, QObject *parent = 0); |
368 | 16 | 26 | ||
369 | 17 | QString guid() const; | 27 | QString guid() const; |
370 | 18 | void setGuid(const QString &guid); | ||
371 | 19 | 28 | ||
372 | 20 | QString notebookGuid() const; | 29 | QString notebookGuid() const; |
373 | 21 | void setNotebookGuid(const QString ¬ebookGuid); | 30 | void setNotebookGuid(const QString ¬ebookGuid); |
374 | 22 | 31 | ||
375 | 32 | QDateTime created() const; | ||
376 | 33 | |||
377 | 23 | QString title() const; | 34 | QString title() const; |
378 | 24 | void setTitle(const QString &title); | 35 | void setTitle(const QString &title); |
379 | 25 | 36 | ||
380 | 26 | QString content() const; | 37 | QString content() const; |
381 | 27 | void setContent(const QString &content); | 38 | void setContent(const QString &content); |
382 | 28 | 39 | ||
383 | 40 | // This is the QML representation as we don't want to deal with timestamps there. | ||
384 | 41 | // setting it to false will reset the reminderOrder to 0, setting it to true will | ||
385 | 42 | // create a new timestamp for it. | ||
386 | 43 | bool reminder() const; | ||
387 | 44 | void setReminder(bool reminder); | ||
388 | 45 | |||
389 | 46 | qint64 reminderOrder() const; | ||
390 | 47 | void setReminderOrder(qint64 reminderOrder); | ||
391 | 48 | |||
392 | 49 | QDateTime reminderTime() const; | ||
393 | 50 | void setReminderTime(const QDateTime &reminderTime); | ||
394 | 51 | |||
395 | 52 | // This is the QML representation as we don't want to deal with timestamps there. | ||
396 | 53 | // setting it to false will reset reminderDoneTime to 0, setting it to true will | ||
397 | 54 | // create a new timestamp for it. | ||
398 | 55 | bool reminderDone() const; | ||
399 | 56 | void setReminderDone(bool reminderDone); | ||
400 | 57 | |||
401 | 58 | QDateTime reminderDoneTime() const; | ||
402 | 59 | void setReminderDoneTime(const QDateTime &reminderDoneTime); | ||
403 | 60 | |||
404 | 61 | Note* clone(); | ||
405 | 62 | |||
406 | 29 | public slots: | 63 | public slots: |
407 | 30 | void save(); | 64 | void save(); |
408 | 31 | void remove(); | 65 | void remove(); |
409 | 32 | 66 | ||
410 | 33 | signals: | 67 | signals: |
411 | 34 | void guidChanged(); | ||
412 | 35 | void titleChanged(); | 68 | void titleChanged(); |
413 | 36 | void notebookGuidChanged(); | 69 | void notebookGuidChanged(); |
414 | 37 | void contentChanged(); | 70 | void contentChanged(); |
415 | 71 | void reminderChanged(); | ||
416 | 72 | void reminderTimeChanged(); | ||
417 | 73 | void reminderDoneChanged(); | ||
418 | 38 | 74 | ||
419 | 39 | private: | 75 | private: |
420 | 40 | QString m_guid; | 76 | QString m_guid; |
421 | 41 | QString m_notebookGuid; | 77 | QString m_notebookGuid; |
422 | 78 | QDateTime m_created; | ||
423 | 42 | QString m_title; | 79 | QString m_title; |
424 | 43 | QString m_content; | 80 | QString m_content; |
425 | 81 | qint64 m_reminderOrder; | ||
426 | 82 | QDateTime m_reminderTime; | ||
427 | 83 | QDateTime m_reminderDoneTime; | ||
428 | 44 | }; | 84 | }; |
429 | 45 | 85 | ||
430 | 46 | #endif // NOTE_H | 86 | #endif // NOTE_H |
431 | 47 | 87 | ||
432 | === modified file 'src/plugin/Evernote/notebooks.cpp' | |||
433 | --- src/plugin/Evernote/notebooks.cpp 2013-11-26 17:18:33 +0000 | |||
434 | +++ src/plugin/Evernote/notebooks.cpp 2013-12-12 21:36:37 +0000 | |||
435 | @@ -35,7 +35,6 @@ | |||
436 | 35 | 35 | ||
437 | 36 | QVariant Notebooks::data(const QModelIndex &index, int role) const | 36 | QVariant Notebooks::data(const QModelIndex &index, int role) const |
438 | 37 | { | 37 | { |
439 | 38 | |||
440 | 39 | Notebook *notebook = NotesStore::instance()->notebook(m_list.at(index.row())); | 38 | Notebook *notebook = NotesStore::instance()->notebook(m_list.at(index.row())); |
441 | 40 | switch(role) { | 39 | switch(role) { |
442 | 41 | case RoleGuid: | 40 | case RoleGuid: |
443 | 42 | 41 | ||
444 | === modified file 'src/plugin/Evernote/notes.cpp' | |||
445 | --- src/plugin/Evernote/notes.cpp 2013-11-26 17:18:33 +0000 | |||
446 | +++ src/plugin/Evernote/notes.cpp 2013-12-12 21:36:37 +0000 | |||
447 | @@ -24,37 +24,12 @@ | |||
448 | 24 | #include <QDebug> | 24 | #include <QDebug> |
449 | 25 | 25 | ||
450 | 26 | Notes::Notes(QObject *parent) : | 26 | Notes::Notes(QObject *parent) : |
482 | 27 | QAbstractListModel(parent) | 27 | QSortFilterProxyModel(parent), |
483 | 28 | { | 28 | m_onlyReminders(false) |
484 | 29 | connect(NotesStore::instance(), &NotesStore::noteAdded, this, &Notes::noteAdded); | 29 | { |
485 | 30 | connect(NotesStore::instance(), &NotesStore::noteRemoved, this, &Notes::noteRemoved); | 30 | setSourceModel(NotesStore::instance()); |
486 | 31 | connect(NotesStore::instance(), &NotesStore::noteChanged, this, &Notes::noteChanged); | 31 | setSortRole(NotesStore::RoleCreated); |
487 | 32 | } | 32 | sort(0, Qt::DescendingOrder); |
457 | 33 | |||
458 | 34 | QVariant Notes::data(const QModelIndex &index, int role) const | ||
459 | 35 | { | ||
460 | 36 | Note *note = NotesStore::instance()->note(m_list.at(index.row())); | ||
461 | 37 | switch(role) { | ||
462 | 38 | case RoleGuid: | ||
463 | 39 | return note->guid(); | ||
464 | 40 | case RoleTitle: | ||
465 | 41 | return note->title(); | ||
466 | 42 | } | ||
467 | 43 | |||
468 | 44 | return QVariant(); | ||
469 | 45 | } | ||
470 | 46 | |||
471 | 47 | int Notes::rowCount(const QModelIndex &parent) const | ||
472 | 48 | { | ||
473 | 49 | return m_list.count(); | ||
474 | 50 | } | ||
475 | 51 | |||
476 | 52 | QHash<int, QByteArray> Notes::roleNames() const | ||
477 | 53 | { | ||
478 | 54 | QHash<int, QByteArray> roles; | ||
479 | 55 | roles.insert(RoleGuid, "guid"); | ||
480 | 56 | roles.insert(RoleTitle, "title"); | ||
481 | 57 | return roles; | ||
488 | 58 | } | 33 | } |
489 | 59 | 34 | ||
490 | 60 | QString Notes::filterNotebookGuid() const | 35 | QString Notes::filterNotebookGuid() const |
491 | @@ -67,53 +42,36 @@ | |||
492 | 67 | if (m_filterNotebookGuid != notebookGuid) { | 42 | if (m_filterNotebookGuid != notebookGuid) { |
493 | 68 | m_filterNotebookGuid = notebookGuid; | 43 | m_filterNotebookGuid = notebookGuid; |
494 | 69 | emit filterNotebookGuidChanged(); | 44 | emit filterNotebookGuidChanged(); |
544 | 70 | } | 45 | invalidateFilter(); |
545 | 71 | } | 46 | } |
546 | 72 | 47 | } | |
547 | 73 | Note* Notes::note(const QString &guid) | 48 | |
548 | 74 | { | 49 | bool Notes::onlyReminders() const |
549 | 75 | NotesStore::instance()->refreshNoteContent(guid); | 50 | { |
550 | 76 | return NotesStore::instance()->note(guid); | 51 | return m_onlyReminders; |
551 | 77 | } | 52 | } |
552 | 78 | 53 | ||
553 | 79 | void Notes::componentComplete() | 54 | void Notes::setOnlyReminders(bool onlyReminders) |
554 | 80 | { | 55 | { |
555 | 81 | foreach (Note *note, NotesStore::instance()->notes()) { | 56 | if (m_onlyReminders != onlyReminders) { |
556 | 82 | if (m_filterNotebookGuid.isEmpty() || note->notebookGuid() == m_filterNotebookGuid) { | 57 | m_onlyReminders = onlyReminders; |
557 | 83 | m_list.append(note->guid()); | 58 | emit onlyRemindersChanged(); |
558 | 84 | } | 59 | invalidateFilter(); |
559 | 85 | } | 60 | } |
560 | 86 | beginInsertRows(QModelIndex(), 0, m_list.count() - 1); | 61 | } |
561 | 87 | endInsertRows(); | 62 | |
562 | 88 | refresh(); | 63 | bool Notes::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const |
563 | 89 | } | 64 | { |
564 | 90 | 65 | QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent); | |
565 | 91 | void Notes::refresh() | 66 | if (!m_filterNotebookGuid.isEmpty()) { |
566 | 92 | { | 67 | if (sourceModel()->data(sourceIndex, NotesStore::RoleNotebookGuid).toString() != m_filterNotebookGuid) { |
567 | 93 | NotesStore::instance()->refreshNotes(m_filterNotebookGuid); | 68 | return false; |
568 | 94 | } | 69 | } |
569 | 95 | 70 | } | |
570 | 96 | void Notes::noteAdded(const QString &guid) | 71 | if (m_onlyReminders) { |
571 | 97 | { | 72 | if (!sourceModel()->data(sourceIndex, NotesStore::RoleReminder).toBool()) { |
572 | 98 | beginInsertRows(QModelIndex(), m_list.count(), m_list.count()); | 73 | return false; |
573 | 99 | m_list.append(guid); | 74 | } |
574 | 100 | endInsertRows(); | 75 | } |
575 | 101 | } | 76 | return true; |
527 | 102 | |||
528 | 103 | void Notes::noteChanged(const QString &guid) | ||
529 | 104 | { | ||
530 | 105 | int row = m_list.indexOf(guid); | ||
531 | 106 | if (row >= 0) { | ||
532 | 107 | emit dataChanged(index(row), index(row)); | ||
533 | 108 | } | ||
534 | 109 | } | ||
535 | 110 | |||
536 | 111 | void Notes::noteRemoved(const QString &guid) | ||
537 | 112 | { | ||
538 | 113 | int index = m_list.indexOf(guid); | ||
539 | 114 | if (index >= 0) { | ||
540 | 115 | beginRemoveRows(QModelIndex(), index, index); | ||
541 | 116 | m_list.removeAt(index); | ||
542 | 117 | endRemoveRows(); | ||
543 | 118 | } | ||
576 | 119 | } | 77 | } |
577 | 120 | 78 | ||
578 | === modified file 'src/plugin/Evernote/notes.h' | |||
579 | --- src/plugin/Evernote/notes.h 2013-11-25 00:49:48 +0000 | |||
580 | +++ src/plugin/Evernote/notes.h 2013-12-12 21:36:37 +0000 | |||
581 | @@ -3,46 +3,33 @@ | |||
582 | 3 | 3 | ||
583 | 4 | #include "notesstore.h" | 4 | #include "notesstore.h" |
584 | 5 | 5 | ||
587 | 6 | #include <QAbstractListModel> | 6 | #include <QSortFilterProxyModel> |
586 | 7 | #include <QQmlParserStatus> | ||
588 | 8 | 7 | ||
590 | 9 | class Notes : public QAbstractListModel, public QQmlParserStatus | 8 | class Notes : public QSortFilterProxyModel |
591 | 10 | { | 9 | { |
592 | 11 | Q_OBJECT | 10 | Q_OBJECT |
593 | 12 | Q_PROPERTY(QString filterNotebookGuid READ filterNotebookGuid WRITE setFilterNotebookGuid NOTIFY filterNotebookGuidChanged) | 11 | Q_PROPERTY(QString filterNotebookGuid READ filterNotebookGuid WRITE setFilterNotebookGuid NOTIFY filterNotebookGuidChanged) |
594 | 12 | Q_PROPERTY(bool onlyReminders READ onlyReminders WRITE setOnlyReminders NOTIFY onlyRemindersChanged) | ||
595 | 13 | |||
596 | 13 | public: | 14 | public: |
597 | 14 | enum Roles { | ||
598 | 15 | RoleGuid, | ||
599 | 16 | RoleTitle | ||
600 | 17 | }; | ||
601 | 18 | explicit Notes(QObject *parent = 0); | 15 | explicit Notes(QObject *parent = 0); |
602 | 19 | 16 | ||
603 | 20 | QVariant data(const QModelIndex &index, int role) const; | ||
604 | 21 | int rowCount(const QModelIndex &parent) const; | ||
605 | 22 | QHash<int, QByteArray> roleNames() const; | ||
606 | 23 | |||
607 | 24 | QString filterNotebookGuid() const; | 17 | QString filterNotebookGuid() const; |
608 | 25 | void setFilterNotebookGuid(const QString ¬ebookGuid); | 18 | void setFilterNotebookGuid(const QString ¬ebookGuid); |
609 | 26 | 19 | ||
622 | 27 | Q_INVOKABLE Note* note(const QString &guid); | 20 | bool onlyReminders() const; |
623 | 28 | 21 | void setOnlyReminders(bool onlyReminders); | |
624 | 29 | void classBegin() {} | 22 | |
625 | 30 | void componentComplete(); | 23 | protected: |
626 | 31 | 24 | bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; | |
615 | 32 | public slots: | ||
616 | 33 | void refresh(); | ||
617 | 34 | |||
618 | 35 | private slots: | ||
619 | 36 | void noteAdded(const QString &guid); | ||
620 | 37 | void noteChanged(const QString &guid); | ||
621 | 38 | void noteRemoved(const QString &guid); | ||
627 | 39 | 25 | ||
628 | 40 | signals: | 26 | signals: |
629 | 41 | void filterNotebookGuidChanged(); | 27 | void filterNotebookGuidChanged(); |
630 | 28 | void onlyRemindersChanged(); | ||
631 | 42 | 29 | ||
632 | 43 | private: | 30 | private: |
633 | 44 | QList<QString> m_list; | ||
634 | 45 | QString m_filterNotebookGuid; | 31 | QString m_filterNotebookGuid; |
635 | 32 | bool m_onlyReminders; | ||
636 | 46 | 33 | ||
637 | 47 | }; | 34 | }; |
638 | 48 | 35 | ||
639 | 49 | 36 | ||
640 | === modified file 'src/plugin/Evernote/notesstore.cpp' | |||
641 | --- src/plugin/Evernote/notesstore.cpp 2013-12-12 21:36:37 +0000 | |||
642 | +++ src/plugin/Evernote/notesstore.cpp 2013-12-12 21:36:37 +0000 | |||
643 | @@ -37,7 +37,7 @@ | |||
644 | 37 | NotesStore* NotesStore::s_instance = 0; | 37 | NotesStore* NotesStore::s_instance = 0; |
645 | 38 | 38 | ||
646 | 39 | NotesStore::NotesStore(QObject *parent) : | 39 | NotesStore::NotesStore(QObject *parent) : |
648 | 40 | QObject(parent) | 40 | QAbstractListModel(parent) |
649 | 41 | { | 41 | { |
650 | 42 | connect(EvernoteConnection::instance(), &EvernoteConnection::tokenChanged, this, &NotesStore::refreshNotebooks); | 42 | connect(EvernoteConnection::instance(), &EvernoteConnection::tokenChanged, this, &NotesStore::refreshNotebooks); |
651 | 43 | connect(EvernoteConnection::instance(), SIGNAL(tokenChanged()), this, SLOT(refreshNotes())); | 43 | connect(EvernoteConnection::instance(), SIGNAL(tokenChanged()), this, SLOT(refreshNotes())); |
652 | @@ -57,28 +57,71 @@ | |||
653 | 57 | return s_instance; | 57 | return s_instance; |
654 | 58 | } | 58 | } |
655 | 59 | 59 | ||
656 | 60 | int NotesStore::rowCount(const QModelIndex &parent) const | ||
657 | 61 | { | ||
658 | 62 | return m_notes.count(); | ||
659 | 63 | } | ||
660 | 64 | |||
661 | 65 | QVariant NotesStore::data(const QModelIndex &index, int role) const | ||
662 | 66 | { | ||
663 | 67 | switch (role) { | ||
664 | 68 | case RoleGuid: | ||
665 | 69 | return m_notes.at(index.row())->guid(); | ||
666 | 70 | case RoleNotebookGuid: | ||
667 | 71 | return m_notes.at(index.row())->notebookGuid(); | ||
668 | 72 | case RoleCreated: | ||
669 | 73 | return m_notes.at(index.row())->created(); | ||
670 | 74 | case RoleTitle: | ||
671 | 75 | return m_notes.at(index.row())->title(); | ||
672 | 76 | case RoleReminder: | ||
673 | 77 | return m_notes.at(index.row())->reminder(); | ||
674 | 78 | case RoleReminderTime: | ||
675 | 79 | return m_notes.at(index.row())->reminderTime(); | ||
676 | 80 | case RoleReminderDone: | ||
677 | 81 | return m_notes.at(index.row())->reminderDone(); | ||
678 | 82 | case RoleReminderDoneTime: | ||
679 | 83 | return m_notes.at(index.row())->reminderDoneTime(); | ||
680 | 84 | } | ||
681 | 85 | return QVariant(); | ||
682 | 86 | } | ||
683 | 87 | |||
684 | 88 | QHash<int, QByteArray> NotesStore::roleNames() const | ||
685 | 89 | { | ||
686 | 90 | QHash<int, QByteArray> roles; | ||
687 | 91 | roles.insert(RoleGuid, "guid"); | ||
688 | 92 | roles.insert(RoleNotebookGuid, "notebookGuid"); | ||
689 | 93 | roles.insert(RoleCreated, "created"); | ||
690 | 94 | roles.insert(RoleTitle, "title"); | ||
691 | 95 | roles.insert(RoleReminder, "reminder"); | ||
692 | 96 | roles.insert(RoleReminderTime, "reminderTime"); | ||
693 | 97 | roles.insert(RoleReminderDone, "reminderDone"); | ||
694 | 98 | roles.insert(RoleReminderDoneTime, "reminderDoneTime"); | ||
695 | 99 | return roles; | ||
696 | 100 | } | ||
697 | 101 | |||
698 | 60 | NotesStore::~NotesStore() | 102 | NotesStore::~NotesStore() |
699 | 61 | { | 103 | { |
700 | 62 | } | 104 | } |
701 | 63 | 105 | ||
702 | 64 | QList<Note*> NotesStore::notes() const | 106 | QList<Note*> NotesStore::notes() const |
703 | 65 | { | 107 | { |
705 | 66 | return m_notes.values(); | 108 | return m_notes; |
706 | 67 | } | 109 | } |
707 | 68 | 110 | ||
708 | 69 | Note *NotesStore::note(const QString &guid) | 111 | Note *NotesStore::note(const QString &guid) |
709 | 70 | { | 112 | { |
711 | 71 | return m_notes.value(guid); | 113 | refreshNoteContent(guid); |
712 | 114 | return m_notesHash.value(guid); | ||
713 | 72 | } | 115 | } |
714 | 73 | 116 | ||
715 | 74 | QList<Notebook *> NotesStore::notebooks() const | 117 | QList<Notebook *> NotesStore::notebooks() const |
716 | 75 | { | 118 | { |
718 | 76 | return m_notebooks.values(); | 119 | return m_notebooks; |
719 | 77 | } | 120 | } |
720 | 78 | 121 | ||
721 | 79 | Notebook *NotesStore::notebook(const QString &guid) | 122 | Notebook *NotesStore::notebook(const QString &guid) |
722 | 80 | { | 123 | { |
724 | 81 | return m_notebooks.value(guid); | 124 | return m_notebooksHash.value(guid); |
725 | 82 | } | 125 | } |
726 | 83 | 126 | ||
727 | 84 | void NotesStore::refreshNotes(const QString &filterNotebookGuid) | 127 | void NotesStore::refreshNotes(const QString &filterNotebookGuid) |
728 | @@ -97,17 +140,33 @@ | |||
729 | 97 | 140 | ||
730 | 98 | for (int i = 0; i < results.notes.size(); ++i) { | 141 | for (int i = 0; i < results.notes.size(); ++i) { |
731 | 99 | evernote::edam::NoteMetadata result = results.notes.at(i); | 142 | evernote::edam::NoteMetadata result = results.notes.at(i); |
736 | 100 | Note *note = m_notes.value(QString::fromStdString(result.guid)); | 143 | Note *note = m_notesHash.value(QString::fromStdString(result.guid)); |
737 | 101 | if (note) { | 144 | bool newNote = note == 0; |
738 | 102 | note->setTitle(QString::fromStdString(result.title)); | 145 | if (newNote) { |
739 | 103 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); | 146 | QString guid = QString::fromStdString(result.guid); |
740 | 147 | QDateTime created = QDateTime::fromMSecsSinceEpoch(result.created); | ||
741 | 148 | note = new Note(guid, created, this); | ||
742 | 149 | } | ||
743 | 150 | |||
744 | 151 | note->setTitle(QString::fromStdString(result.title)); | ||
745 | 152 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); | ||
746 | 153 | note->setReminderOrder(result.attributes.reminderOrder); | ||
747 | 154 | QDateTime reminderDoneTime; | ||
748 | 155 | if (result.attributes.reminderDoneTime > 0) { | ||
749 | 156 | reminderDoneTime = QDateTime::fromMSecsSinceEpoch(result.attributes.reminderDoneTime); | ||
750 | 157 | } | ||
751 | 158 | note->setReminderDoneTime(reminderDoneTime); | ||
752 | 159 | |||
753 | 160 | if (newNote) { | ||
754 | 161 | beginInsertRows(QModelIndex(), m_notes.count(), m_notes.count()); | ||
755 | 162 | m_notesHash.insert(note->guid(), note); | ||
756 | 163 | m_notes.append(note); | ||
757 | 164 | endInsertRows(); | ||
758 | 165 | emit noteAdded(note->guid()); | ||
759 | 166 | } else { | ||
760 | 167 | QModelIndex noteIndex = index(m_notes.indexOf(note)); | ||
761 | 168 | emit dataChanged(noteIndex, noteIndex); | ||
762 | 104 | emit noteChanged(note->guid()); | 169 | emit noteChanged(note->guid()); |
763 | 105 | } else { | ||
764 | 106 | note = new Note(QString::fromStdString(result.guid), this); | ||
765 | 107 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); | ||
766 | 108 | note->setTitle(QString::fromStdString(result.title)); | ||
767 | 109 | m_notes.insert(note->guid(), note); | ||
768 | 110 | emit noteAdded(note->guid()); | ||
769 | 111 | } | 170 | } |
770 | 112 | } | 171 | } |
771 | 113 | } | 172 | } |
772 | @@ -126,11 +185,20 @@ | |||
773 | 126 | return; | 185 | return; |
774 | 127 | } | 186 | } |
775 | 128 | 187 | ||
777 | 129 | Note *note = m_notes.value(QString::fromStdString(result.guid)); | 188 | Note *note = m_notesHash.value(QString::fromStdString(result.guid)); |
778 | 130 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); | 189 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); |
779 | 131 | note->setTitle(QString::fromStdString(result.title)); | 190 | note->setTitle(QString::fromStdString(result.title)); |
780 | 132 | note->setContent(QString::fromStdString(result.content)); | 191 | note->setContent(QString::fromStdString(result.content)); |
781 | 192 | note->setReminderOrder(result.attributes.reminderOrder); | ||
782 | 193 | QDateTime reminderDoneTime; | ||
783 | 194 | if (result.attributes.reminderDoneTime > 0) { | ||
784 | 195 | reminderDoneTime = QDateTime::fromMSecsSinceEpoch(result.attributes.reminderDoneTime); | ||
785 | 196 | } | ||
786 | 197 | note->setReminderDoneTime(reminderDoneTime); | ||
787 | 133 | emit noteChanged(note->guid()); | 198 | emit noteChanged(note->guid()); |
788 | 199 | |||
789 | 200 | QModelIndex noteIndex = index(m_notes.indexOf(note)); | ||
790 | 201 | emit dataChanged(noteIndex, noteIndex); | ||
791 | 134 | } | 202 | } |
792 | 135 | 203 | ||
793 | 136 | void NotesStore::refreshNotebooks() | 204 | void NotesStore::refreshNotebooks() |
794 | @@ -149,17 +217,19 @@ | |||
795 | 149 | 217 | ||
796 | 150 | for (int i = 0; i < results.size(); ++i) { | 218 | for (int i = 0; i < results.size(); ++i) { |
797 | 151 | evernote::edam::Notebook result = results.at(i); | 219 | evernote::edam::Notebook result = results.at(i); |
804 | 152 | Notebook *notebook = m_notebooks.value(QString::fromStdString(result.guid)); | 220 | Notebook *notebook = m_notebooksHash.value(QString::fromStdString(result.guid)); |
805 | 153 | if (notebook) { | 221 | bool newNoteNotebook = notebook == 0; |
806 | 154 | qDebug() << "got notebook update"; | 222 | if (newNoteNotebook) { |
801 | 155 | notebook->setName(QString::fromStdString(result.name)); | ||
802 | 156 | emit notebookChanged(notebook->guid()); | ||
803 | 157 | } else { | ||
807 | 158 | notebook = new Notebook(QString::fromStdString(result.guid), this); | 223 | notebook = new Notebook(QString::fromStdString(result.guid), this); |
810 | 159 | notebook->setName(QString::fromStdString(result.name)); | 224 | } |
811 | 160 | m_notebooks.insert(notebook->guid(), notebook); | 225 | notebook->setName(QString::fromStdString(result.name)); |
812 | 226 | |||
813 | 227 | if (newNoteNotebook) { | ||
814 | 228 | m_notebooksHash.insert(notebook->guid(), notebook); | ||
815 | 229 | m_notebooks.append(notebook); | ||
816 | 161 | emit notebookAdded(notebook->guid()); | 230 | emit notebookAdded(notebook->guid()); |
818 | 162 | qDebug() << "got new notebook" << notebook->guid(); | 231 | } else { |
819 | 232 | emit notebookChanged(notebook->guid()); | ||
820 | 163 | } | 233 | } |
821 | 164 | } | 234 | } |
822 | 165 | } | 235 | } |
823 | @@ -178,18 +248,24 @@ | |||
824 | 178 | return; | 248 | return; |
825 | 179 | } | 249 | } |
826 | 180 | 250 | ||
828 | 181 | Note *note = new Note(QString::fromStdString(result.guid)); | 251 | QString guid = QString::fromStdString(result.guid); |
829 | 252 | QDateTime created = QDateTime::fromMSecsSinceEpoch(result.created); | ||
830 | 253 | Note *note = new Note(guid, created, this); | ||
831 | 182 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); | 254 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); |
832 | 183 | note->setTitle(QString::fromStdString(result.title)); | 255 | note->setTitle(QString::fromStdString(result.title)); |
833 | 184 | note->setContent(QString::fromStdString(result.content)); | 256 | note->setContent(QString::fromStdString(result.content)); |
834 | 185 | 257 | ||
837 | 186 | m_notes.insert(note->guid(), note); | 258 | beginInsertRows(QModelIndex(), m_notes.count(), m_notes.count()); |
838 | 187 | noteAdded(note->guid()); | 259 | m_notesHash.insert(note->guid(), note); |
839 | 260 | m_notes.append(note); | ||
840 | 261 | endInsertRows(); | ||
841 | 262 | |||
842 | 263 | emit noteAdded(note->guid()); | ||
843 | 188 | } | 264 | } |
844 | 189 | 265 | ||
845 | 190 | void NotesStore::saveNote(const QString &guid) | 266 | void NotesStore::saveNote(const QString &guid) |
846 | 191 | { | 267 | { |
848 | 192 | Note *note = m_notes.value(guid); | 268 | Note *note = m_notesHash.value(guid); |
849 | 193 | 269 | ||
850 | 194 | QString enml = Html2EnmlConverter::html2enml(note->content()); | 270 | QString enml = Html2EnmlConverter::html2enml(note->content()); |
851 | 195 | note->setContent(enml); | 271 | note->setContent(enml); |
852 | @@ -206,12 +282,15 @@ | |||
853 | 206 | return; | 282 | return; |
854 | 207 | } | 283 | } |
855 | 208 | 284 | ||
857 | 209 | Note *note = m_notes.value(QString::fromStdString(result.guid)); | 285 | Note *note = m_notesHash.value(QString::fromStdString(result.guid)); |
858 | 210 | if (note) { | 286 | if (note) { |
859 | 211 | note->setTitle(QString::fromStdString(result.title)); | 287 | note->setTitle(QString::fromStdString(result.title)); |
860 | 212 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); | 288 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); |
861 | 213 | 289 | ||
862 | 214 | emit noteChanged(note->guid()); | 290 | emit noteChanged(note->guid()); |
863 | 291 | |||
864 | 292 | QModelIndex noteIndex = index(m_notes.indexOf(note)); | ||
865 | 293 | emit dataChanged(noteIndex, noteIndex); | ||
866 | 215 | } | 294 | } |
867 | 216 | } | 295 | } |
868 | 217 | 296 | ||
869 | @@ -229,5 +308,11 @@ | |||
870 | 229 | return; | 308 | return; |
871 | 230 | } | 309 | } |
872 | 231 | emit noteRemoved(guid); | 310 | emit noteRemoved(guid); |
874 | 232 | m_notes.take(guid)->deleteLater(); | 311 | |
875 | 312 | Note *note = m_notesHash.value(guid); | ||
876 | 313 | int noteIndex = m_notes.indexOf(note); | ||
877 | 314 | beginRemoveRows(QModelIndex(), noteIndex, noteIndex); | ||
878 | 315 | m_notes.takeAt(noteIndex); | ||
879 | 316 | m_notesHash.take(guid)->deleteLater(); | ||
880 | 317 | endRemoveRows(); | ||
881 | 233 | } | 318 | } |
882 | 234 | 319 | ||
883 | === modified file 'src/plugin/Evernote/notesstore.h' | |||
884 | --- src/plugin/Evernote/notesstore.h 2013-12-12 21:36:37 +0000 | |||
885 | +++ src/plugin/Evernote/notesstore.h 2013-12-12 21:36:37 +0000 | |||
886 | @@ -15,7 +15,7 @@ | |||
887 | 15 | #include <NoteStore_constants.h> | 15 | #include <NoteStore_constants.h> |
888 | 16 | #include <Errors_types.h> | 16 | #include <Errors_types.h> |
889 | 17 | 17 | ||
891 | 18 | #include <QObject> | 18 | #include <QAbstractListModel> |
892 | 19 | #include <QHash> | 19 | #include <QHash> |
893 | 20 | 20 | ||
894 | 21 | class Notebook; | 21 | class Notebook; |
895 | @@ -23,21 +23,36 @@ | |||
896 | 23 | 23 | ||
897 | 24 | using namespace apache::thrift::transport; | 24 | using namespace apache::thrift::transport; |
898 | 25 | 25 | ||
900 | 26 | class NotesStore : public QObject | 26 | class NotesStore : public QAbstractListModel |
901 | 27 | { | 27 | { |
902 | 28 | Q_OBJECT | 28 | Q_OBJECT |
903 | 29 | 29 | ||
904 | 30 | public: | 30 | public: |
906 | 31 | Q_INVOKABLE void createNote(const QString &title, const QString ¬ebookGuid, const QString &content); | 31 | enum Roles { |
907 | 32 | RoleGuid, | ||
908 | 33 | RoleNotebookGuid, | ||
909 | 34 | RoleCreated, | ||
910 | 35 | RoleTitle, | ||
911 | 36 | RoleReminder, | ||
912 | 37 | RoleReminderTime, | ||
913 | 38 | RoleReminderDone, | ||
914 | 39 | RoleReminderDoneTime | ||
915 | 40 | }; | ||
916 | 32 | 41 | ||
917 | 42 | ~NotesStore(); | ||
918 | 33 | static NotesStore *instance(); | 43 | static NotesStore *instance(); |
919 | 34 | 44 | ||
921 | 35 | ~NotesStore(); | 45 | // reimplemented from QAbstractListModel |
922 | 46 | int rowCount(const QModelIndex &parent) const; | ||
923 | 47 | QVariant data(const QModelIndex &index, int role) const; | ||
924 | 48 | QHash<int, QByteArray> roleNames() const; | ||
925 | 36 | 49 | ||
926 | 37 | QList<Note*> notes() const; | 50 | QList<Note*> notes() const; |
930 | 38 | Note* note(const QString &guid); | 51 | |
931 | 39 | void saveNote(const QString &guid); | 52 | Q_INVOKABLE Note* note(const QString &guid); |
932 | 40 | void deleteNote(const QString &guid); | 53 | Q_INVOKABLE void createNote(const QString &title, const QString ¬ebookGuid, const QString &content); |
933 | 54 | Q_INVOKABLE void saveNote(const QString &guid); | ||
934 | 55 | Q_INVOKABLE void deleteNote(const QString &guid); | ||
935 | 41 | 56 | ||
936 | 42 | QList<Notebook*> notebooks() const; | 57 | QList<Notebook*> notebooks() const; |
937 | 43 | Notebook* notebook(const QString &guid); | 58 | Notebook* notebook(const QString &guid); |
938 | @@ -69,9 +84,12 @@ | |||
939 | 69 | explicit NotesStore(QObject *parent = 0); | 84 | explicit NotesStore(QObject *parent = 0); |
940 | 70 | static NotesStore *s_instance; | 85 | static NotesStore *s_instance; |
941 | 71 | 86 | ||
944 | 72 | QHash<QString, Notebook*> m_notebooks; | 87 | QList<Note*> m_notes; |
945 | 73 | QHash<QString, Note*> m_notes; | 88 | QList<Notebook*> m_notebooks; |
946 | 74 | 89 | ||
947 | 90 | // Keep hashes for faster lookups as we always identify notes via guid | ||
948 | 91 | QHash<QString, Note*> m_notesHash; | ||
949 | 92 | QHash<QString, Notebook*> m_notebooksHash; | ||
950 | 75 | }; | 93 | }; |
951 | 76 | 94 | ||
952 | 77 | #endif // NOTESSTORE_H | 95 | #endif // NOTESSTORE_H |
PASSED: Continuous integration, rev:16 91.189. 93.70:8080/ job/reminders- app-ci/ 31/ 91.189. 93.70:8080/ job/generic- mediumtests- trusty/ 317 91.189. 93.70:8080/ job/reminders- app-saucy- amd64-ci/ 31 91.189. 93.70:8080/ job/reminders- app-trusty- amd64-ci/ 31
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: 91.189. 93.70:8080/ job/reminders- app-ci/ 31/rebuild
http://