Merge lp:~mzanetti/reminders-app/create-notebook into lp:reminders-app

Proposed by Michael Zanetti
Status: Merged
Approved by: Michael Zanetti
Approved revision: 21
Merged at revision: 18
Proposed branch: lp:~mzanetti/reminders-app/create-notebook
Merge into: lp:reminders-app
Prerequisite: lp:~mzanetti/reminders-app/add-reminders
Diff against target: 391 lines (+243/-4)
10 files modified
src/app/qml/ui/NotebooksPage.qml (+10/-0)
src/app/qml/ui/NotesPage.qml (+1/-1)
src/plugin/Evernote/Evernote.pro (+6/-2)
src/plugin/Evernote/jobs/createnotebookjob.cpp (+41/-0)
src/plugin/Evernote/jobs/createnotebookjob.h (+46/-0)
src/plugin/Evernote/jobs/evernotejob.cpp (+10/-1)
src/plugin/Evernote/jobs/expungenotebookjob.cpp (+39/-0)
src/plugin/Evernote/jobs/expungenotebookjob.h (+43/-0)
src/plugin/Evernote/notesstore.cpp (+42/-0)
src/plugin/Evernote/notesstore.h (+5/-0)
To merge this branch: bzr merge lp:~mzanetti/reminders-app/create-notebook
Reviewer Review Type Date Requested Status
Jordan Keyes Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+198841@code.launchpad.net

Commit message

Added createNotebook to plugin API.

Description of the change

Added createNotebook to plugin API.

I've also added expungeNote, however, with the current API key we aren't allowed to call that.

To post a comment you must log in.
21. By Michael Zanetti

add copyright headers

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Jordan Keyes (jkeyes0) wrote :

Create notebook option seems to work here, at least as far as creating a new notebook named "new notebook" :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app/qml/ui/NotebooksPage.qml'
2--- src/app/qml/ui/NotebooksPage.qml 2013-11-26 17:18:33 +0000
3+++ src/app/qml/ui/NotebooksPage.qml 2013-12-12 22:46:16 +0000
4@@ -30,6 +30,16 @@
5 }
6 }
7
8+ tools: ToolbarItems {
9+ ToolbarButton {
10+ text: "add notebook"
11+ enabled: notes.filterNotebookGuid.length > 0
12+ onTriggered: {
13+ NotesStore.createNotebook("new notebook");
14+ }
15+ }
16+ }
17+
18 Notebooks {
19 id: notebooks
20 }
21
22=== modified file 'src/app/qml/ui/NotesPage.qml'
23--- src/app/qml/ui/NotesPage.qml 2013-12-12 22:46:16 +0000
24+++ src/app/qml/ui/NotesPage.qml 2013-12-12 22:46:16 +0000
25@@ -62,7 +62,7 @@
26 }
27
28 onPressAndHold: {
29- notes.note(guid).remove();
30+ NotesStore.deleteNote(guid);
31 }
32 }
33 }
34
35=== modified file 'src/plugin/Evernote/Evernote.pro'
36--- src/plugin/Evernote/Evernote.pro 2013-12-12 22:46:16 +0000
37+++ src/plugin/Evernote/Evernote.pro 2013-12-12 22:46:16 +0000
38@@ -27,7 +27,9 @@
39 evernoteconnection.cpp \
40 jobs/userstorejob.cpp \
41 jobs/notesstorejob.cpp \
42- jobs/fetchusernamejob.cpp
43+ jobs/fetchusernamejob.cpp \
44+ jobs/createnotebookjob.cpp \
45+ jobs/expungenotebookjob.cpp
46
47 HEADERS += evernoteplugin.h \
48 notesstore.h \
49@@ -47,7 +49,9 @@
50 evernoteconnection.h \
51 jobs/userstorejob.h \
52 jobs/notesstorejob.h \
53- jobs/fetchusernamejob.h
54+ jobs/fetchusernamejob.h \
55+ jobs/createnotebookjob.h \
56+ jobs/expungenotebookjob.h
57
58 message(building in $$OUT_PWD)
59 LIBS += -L$$OUT_PWD/../../../3rdParty/evernote-sdk-cpp/ -L$$OUT_PWD/../../../3rdParty/libthrift/ -levernote-sdk-cpp -llibthrift -lssl -lcrypto
60
61=== added file 'src/plugin/Evernote/jobs/createnotebookjob.cpp'
62--- src/plugin/Evernote/jobs/createnotebookjob.cpp 1970-01-01 00:00:00 +0000
63+++ src/plugin/Evernote/jobs/createnotebookjob.cpp 2013-12-12 22:46:16 +0000
64@@ -0,0 +1,41 @@
65+/*
66+ * Copyright: 2013 Canonical, Ltd
67+ *
68+ * This file is part of reminders-app
69+ *
70+ * reminders-app is free software: you can redistribute it and/or modify
71+ * it under the terms of the GNU General Public License as published by
72+ * the Free Software Foundation; version 3.
73+ *
74+ * reminders-app is distributed in the hope that it will be useful,
75+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
76+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
77+ * GNU General Public License for more details.
78+ *
79+ * You should have received a copy of the GNU General Public License
80+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
81+ *
82+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
83+ */
84+
85+#include "createnotebookjob.h"
86+
87+#include <QDebug>
88+
89+CreateNotebookJob::CreateNotebookJob(const QString &name, QObject *parent) :
90+ NotesStoreJob(parent),
91+ m_name(name)
92+{
93+}
94+
95+void CreateNotebookJob::startJob()
96+{
97+ m_result.name = m_name.toStdString();
98+ m_result.__isset.name = true;
99+ client()->createNotebook(m_result, token().toStdString(), m_result);
100+}
101+
102+void CreateNotebookJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
103+{
104+ emit jobDone(errorCode, errorMessage, m_result);
105+}
106
107=== added file 'src/plugin/Evernote/jobs/createnotebookjob.h'
108--- src/plugin/Evernote/jobs/createnotebookjob.h 1970-01-01 00:00:00 +0000
109+++ src/plugin/Evernote/jobs/createnotebookjob.h 2013-12-12 22:46:16 +0000
110@@ -0,0 +1,46 @@
111+/*
112+ * Copyright: 2013 Canonical, Ltd
113+ *
114+ * This file is part of reminders-app
115+ *
116+ * reminders-app is free software: you can redistribute it and/or modify
117+ * it under the terms of the GNU General Public License as published by
118+ * the Free Software Foundation; version 3.
119+ *
120+ * reminders-app is distributed in the hope that it will be useful,
121+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
122+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
123+ * GNU General Public License for more details.
124+ *
125+ * You should have received a copy of the GNU General Public License
126+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
127+ *
128+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
129+ */
130+
131+#ifndef CREATENOTEBOOKJOB_H
132+#define CREATENOTEBOOKJOB_H
133+
134+#include "notesstorejob.h"
135+
136+class CreateNotebookJob : public NotesStoreJob
137+{
138+ Q_OBJECT
139+public:
140+ explicit CreateNotebookJob(const QString &name, QObject *parent = 0);
141+
142+ virtual void startJob() override;
143+
144+signals:
145+ void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Notebook &result);
146+
147+private slots:
148+ void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
149+
150+private:
151+ QString m_name;
152+
153+ evernote::edam::Notebook m_result;
154+};
155+
156+#endif // CREATENOTEBOOKJOB_H
157
158=== modified file 'src/plugin/Evernote/jobs/evernotejob.cpp'
159--- src/plugin/Evernote/jobs/evernotejob.cpp 2013-12-12 22:46:16 +0000
160+++ src/plugin/Evernote/jobs/evernotejob.cpp 2013-12-12 22:46:16 +0000
161@@ -55,7 +55,6 @@
162
163 try {
164 startJob();
165-
166 } catch (const TTransportException & e) {
167
168 // The connection broke down. libthrift + evernote servers seem to be quite flaky
169@@ -68,19 +67,29 @@
170 // Giving up... the connection seems to be down for real.
171 qWarning() << "Cannot reestablish connection:" << e.what();
172 emitJobDone(EvernoteConnection::ErrorCodeConnectionLost, e.what());
173+ } catch (const TApplicationException &e) {
174+ qWarning() << "Cannot reestablish connection:" << e.what();
175+ emitJobDone(EvernoteConnection::ErrorCodeConnectionLost, e.what());
176 } catch (const evernote::edam::EDAMUserException &e) {
177+ qWarning() << "EDAMUserException" << e.what();
178 emitJobDone(EvernoteConnection::ErrorCodeUserException, e.what());
179 } catch (const evernote::edam::EDAMSystemException &e) {
180+ qWarning() << "EDAMSystemException" << e.what();
181 emitJobDone(EvernoteConnection::ErrorCodeSystemException, e.what());
182 } catch (const evernote::edam::EDAMNotFoundException &e) {
183+ qWarning() << "EDAMNotFoundException" << e.what();
184 emitJobDone(EvernoteConnection::ErrorCodeNotFoundExcpetion, e.what());
185 }
186
187+
188 } catch (const evernote::edam::EDAMUserException &e) {
189+ qWarning() << "EDAMUserException" << e.what();
190 emitJobDone(EvernoteConnection::ErrorCodeUserException, e.what());
191 } catch (const evernote::edam::EDAMSystemException &e) {
192+ qWarning() << "EDAMSystemException" << e.what();
193 emitJobDone(EvernoteConnection::ErrorCodeSystemException, e.what());
194 } catch (const evernote::edam::EDAMNotFoundException &e) {
195+ qWarning() << "EDAMNotFoundException" << e.what();
196 emitJobDone(EvernoteConnection::ErrorCodeNotFoundExcpetion, e.what());
197 }
198
199
200=== added file 'src/plugin/Evernote/jobs/expungenotebookjob.cpp'
201--- src/plugin/Evernote/jobs/expungenotebookjob.cpp 1970-01-01 00:00:00 +0000
202+++ src/plugin/Evernote/jobs/expungenotebookjob.cpp 2013-12-12 22:46:16 +0000
203@@ -0,0 +1,39 @@
204+/*
205+ * Copyright: 2013 Canonical, Ltd
206+ *
207+ * This file is part of reminders-app
208+ *
209+ * reminders-app is free software: you can redistribute it and/or modify
210+ * it under the terms of the GNU General Public License as published by
211+ * the Free Software Foundation; version 3.
212+ *
213+ * reminders-app is distributed in the hope that it will be useful,
214+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
215+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
216+ * GNU General Public License for more details.
217+ *
218+ * You should have received a copy of the GNU General Public License
219+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
220+ *
221+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
222+ */
223+
224+#include "expungenotebookjob.h"
225+
226+#include <QDebug>
227+
228+ExpungeNotebookJob::ExpungeNotebookJob(const QString &guid, QObject *parent) :
229+ NotesStoreJob(parent),
230+ m_guid(guid)
231+{
232+}
233+
234+void ExpungeNotebookJob::startJob()
235+{
236+ client()->expungeNotebook(token().toStdString(), m_guid.toStdString());
237+}
238+
239+void ExpungeNotebookJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
240+{
241+ emit jobDone(errorCode, errorMessage, m_guid);
242+}
243
244=== added file 'src/plugin/Evernote/jobs/expungenotebookjob.h'
245--- src/plugin/Evernote/jobs/expungenotebookjob.h 1970-01-01 00:00:00 +0000
246+++ src/plugin/Evernote/jobs/expungenotebookjob.h 2013-12-12 22:46:16 +0000
247@@ -0,0 +1,43 @@
248+/*
249+ * Copyright: 2013 Canonical, Ltd
250+ *
251+ * This file is part of reminders-app
252+ *
253+ * reminders-app is free software: you can redistribute it and/or modify
254+ * it under the terms of the GNU General Public License as published by
255+ * the Free Software Foundation; version 3.
256+ *
257+ * reminders-app is distributed in the hope that it will be useful,
258+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
259+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
260+ * GNU General Public License for more details.
261+ *
262+ * You should have received a copy of the GNU General Public License
263+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
264+ *
265+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
266+ */
267+
268+#ifndef DELETENOTEBOOKJOB_H
269+#define DELETENOTEBOOKJOB_H
270+
271+#include "notesstorejob.h"
272+
273+class ExpungeNotebookJob : public NotesStoreJob
274+{
275+ Q_OBJECT
276+public:
277+ explicit ExpungeNotebookJob(const QString &guid, QObject *parent = 0);
278+
279+signals:
280+ void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid);
281+
282+private slots:
283+ void startJob();
284+ void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
285+
286+private:
287+ QString m_guid;
288+};
289+
290+#endif // DELETENOTEBOOKJOB_H
291
292=== modified file 'src/plugin/Evernote/notesstore.cpp'
293--- src/plugin/Evernote/notesstore.cpp 2013-12-12 22:46:16 +0000
294+++ src/plugin/Evernote/notesstore.cpp 2013-12-12 22:46:16 +0000
295@@ -31,6 +31,8 @@
296 #include "jobs/createnotejob.h"
297 #include "jobs/savenotejob.h"
298 #include "jobs/deletenotejob.h"
299+#include "jobs/createnotebookjob.h"
300+#include "jobs/expungenotebookjob.h"
301
302 #include <QDebug>
303
304@@ -46,6 +48,7 @@
305 qRegisterMetaType<evernote::edam::NotesMetadataList>("evernote::edam::NotesMetadataList");
306 qRegisterMetaType<evernote::edam::Note>("evernote::edam::Note");
307 qRegisterMetaType<std::vector<evernote::edam::Notebook> >("std::vector<evernote::edam::Notebook>");
308+ qRegisterMetaType<evernote::edam::Notebook>("evernote::edam::Notebook");
309
310 }
311
312@@ -124,6 +127,20 @@
313 return m_notebooksHash.value(guid);
314 }
315
316+void NotesStore::createNotebook(const QString &name)
317+{
318+ CreateNotebookJob *job = new CreateNotebookJob(name);
319+ connect(job, &CreateNotebookJob::jobDone, this, &NotesStore::createNotebookJobDone);
320+ EvernoteConnection::instance()->enqueue(job);
321+}
322+
323+void NotesStore::expungeNotebook(const QString &guid)
324+{
325+ ExpungeNotebookJob *job = new ExpungeNotebookJob(guid);
326+ connect(job, &ExpungeNotebookJob::jobDone, this, &NotesStore::expungeNotebookJobDone);
327+ EvernoteConnection::instance()->enqueue(job);
328+}
329+
330 void NotesStore::refreshNotes(const QString &filterNotebookGuid)
331 {
332 FetchNotesJob *job = new FetchNotesJob(filterNotebookGuid);
333@@ -316,3 +333,28 @@
334 m_notesHash.take(guid)->deleteLater();
335 endRemoveRows();
336 }
337+
338+void NotesStore::createNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Notebook &result)
339+{
340+ if (errorCode != EvernoteConnection::ErrorCodeNoError) {
341+ qWarning() << "Error creating notebook:" << errorMessage;
342+ return;
343+ }
344+ Notebook *notebook = new Notebook(QString::fromStdString(result.guid));
345+ notebook->setName(QString::fromStdString(result.name));
346+ m_notebooks.append(notebook);
347+ m_notebooksHash.insert(notebook->guid(), notebook);
348+ emit notebookAdded(notebook->guid());
349+}
350+
351+void NotesStore::expungeNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid)
352+{
353+ if (errorCode != EvernoteConnection::ErrorCodeNoError) {
354+ qWarning() << "Error expunging notebook:" << errorMessage;
355+ return;
356+ }
357+ emit notebookRemoved(guid);
358+ Notebook *notebook = m_notebooksHash.take(guid);
359+ m_notebooks.removeAll(notebook);
360+ notebook->deleteLater();
361+}
362
363=== modified file 'src/plugin/Evernote/notesstore.h'
364--- src/plugin/Evernote/notesstore.h 2013-12-12 22:46:16 +0000
365+++ src/plugin/Evernote/notesstore.h 2013-12-12 22:46:16 +0000
366@@ -56,6 +56,8 @@
367
368 QList<Notebook*> notebooks() const;
369 Notebook* notebook(const QString &guid);
370+ Q_INVOKABLE void createNotebook(const QString &name);
371+ Q_INVOKABLE void expungeNotebook(const QString &guid);
372
373 public slots:
374 void refreshNotes(const QString &filterNotebookGuid = QString());
375@@ -71,6 +73,7 @@
376
377 void notebookAdded(const QString &guid);
378 void notebookChanged(const QString &guid);
379+ void notebookRemoved(const QString &guid);
380
381 private slots:
382 void fetchNotesJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results);
383@@ -79,6 +82,8 @@
384 void createNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);
385 void saveNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);
386 void deleteNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid);
387+ void createNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Notebook &result);
388+ void expungeNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid);
389
390 private:
391 explicit NotesStore(QObject *parent = 0);

Subscribers

People subscribed via source and target branches