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

Proposed by Michael Zanetti
Status: Merged
Approved by: Riccardo Padovani
Approved revision: 223
Merged at revision: 221
Proposed branch: lp:~mzanetti/reminders-app/save-notebook
Merge into: lp:reminders-app
Diff against target: 240 lines (+142/-0)
7 files modified
src/plugin/Evernote/CMakeLists.txt (+1/-0)
src/plugin/Evernote/jobs/savenotebookjob.cpp (+50/-0)
src/plugin/Evernote/jobs/savenotebookjob.h (+43/-0)
src/plugin/Evernote/notebook.cpp (+15/-0)
src/plugin/Evernote/notebook.h (+7/-0)
src/plugin/Evernote/notesstore.cpp (+24/-0)
src/plugin/Evernote/notesstore.h (+2/-0)
To merge this branch: bzr merge lp:~mzanetti/reminders-app/save-notebook
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Riccardo Padovani Approve
Review via email: mp+231123@code.launchpad.net

Commit message

add API to save notebooks

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

fix typo

223. By Michael Zanetti

fix some comments and headers

Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Looks good to me and works fine, thanks

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/plugin/Evernote/CMakeLists.txt'
2--- src/plugin/Evernote/CMakeLists.txt 2014-02-15 17:04:45 +0000
3+++ src/plugin/Evernote/CMakeLists.txt 2014-08-17 14:31:11 +0000
4@@ -19,6 +19,7 @@
5 jobs/createnotejob.cpp
6 jobs/evernotejob.cpp
7 jobs/savenotejob.cpp
8+ jobs/savenotebookjob.cpp
9 jobs/deletenotejob.cpp
10 evernoteconnection.cpp
11 jobs/userstorejob.cpp
12
13=== added file 'src/plugin/Evernote/jobs/savenotebookjob.cpp'
14--- src/plugin/Evernote/jobs/savenotebookjob.cpp 1970-01-01 00:00:00 +0000
15+++ src/plugin/Evernote/jobs/savenotebookjob.cpp 2014-08-17 14:31:11 +0000
16@@ -0,0 +1,50 @@
17+/*
18+ * Copyright: 2014 Canonical, Ltd
19+ *
20+ * This file is part of reminders
21+ *
22+ * reminders is free software: you can redistribute it and/or modify
23+ * it under the terms of the GNU General Public License as published by
24+ * the Free Software Foundation; version 3.
25+ *
26+ * reminders is distributed in the hope that it will be useful,
27+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
28+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29+ * GNU General Public License for more details.
30+ *
31+ * You should have received a copy of the GNU General Public License
32+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
33+ *
34+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
35+ */
36+
37+#include "savenotebookjob.h"
38+#include "notebook.h"
39+
40+#include <QDebug>
41+
42+SaveNotebookJob::SaveNotebookJob(Notebook *notebook, QObject *parent) :
43+ NotesStoreJob(parent)
44+{
45+ // Need to clone it. As startJob() will run in another thread we can't access the real notebook from there.
46+ m_notebook = notebook->clone();
47+
48+ // Make sure we delete the clone when done
49+ m_notebook->setParent(this);
50+}
51+
52+void SaveNotebookJob::startJob()
53+{
54+ evernote::edam::Notebook notebook;
55+ notebook.guid = m_notebook->guid().toStdString();
56+ notebook.__isset.guid = true;
57+ notebook.name = m_notebook->name().toStdString();
58+ notebook.__isset.name = true;
59+
60+ client()->updateNotebook(token().toStdString(), notebook);
61+}
62+
63+void SaveNotebookJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
64+{
65+ emit jobDone(errorCode, errorMessage);
66+}
67
68=== added file 'src/plugin/Evernote/jobs/savenotebookjob.h'
69--- src/plugin/Evernote/jobs/savenotebookjob.h 1970-01-01 00:00:00 +0000
70+++ src/plugin/Evernote/jobs/savenotebookjob.h 2014-08-17 14:31:11 +0000
71@@ -0,0 +1,43 @@
72+/*
73+ * Copyright: 2014 Canonical, Ltd
74+ *
75+ * This file is part of reminders
76+ *
77+ * reminders is free software: you can redistribute it and/or modify
78+ * it under the terms of the GNU General Public License as published by
79+ * the Free Software Foundation; version 3.
80+ *
81+ * reminders is distributed in the hope that it will be useful,
82+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
83+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84+ * GNU General Public License for more details.
85+ *
86+ * You should have received a copy of the GNU General Public License
87+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
88+ *
89+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
90+ */
91+
92+#ifndef SAVENOTEBOOKJOB_H
93+#define SAVENOTEBOOKJOB_H
94+
95+#include "notesstorejob.h"
96+
97+class SaveNotebookJob : public NotesStoreJob
98+{
99+ Q_OBJECT
100+public:
101+ explicit SaveNotebookJob(Notebook *notebook, QObject *parent = 0);
102+
103+signals:
104+ void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
105+
106+protected:
107+ void startJob();
108+ void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
109+
110+private:
111+ Notebook* m_notebook;
112+};
113+
114+#endif // SAVENOTEBOOKJOB_H
115
116=== modified file 'src/plugin/Evernote/notebook.cpp'
117--- src/plugin/Evernote/notebook.cpp 2014-05-19 14:20:45 +0000
118+++ src/plugin/Evernote/notebook.cpp 2014-08-17 14:31:11 +0000
119@@ -116,6 +116,21 @@
120 return QString(gettext("on %1 %2")).arg(QLocale::system().standaloneMonthName(updateDate.month())).arg(updateDate.year());
121 }
122
123+Notebook *Notebook::clone()
124+{
125+ Notebook *notebook = new Notebook(m_guid);
126+ notebook->setName(m_name);
127+ notebook->setLastUpdated(m_lastUpdated);
128+ notebook->setPublished(m_published);
129+
130+ return notebook;
131+}
132+
133+void Notebook::save()
134+{
135+ NotesStore::instance()->saveNotebook(m_guid);
136+}
137+
138 void Notebook::noteAdded(const QString &noteGuid, const QString &notebookGuid)
139 {
140 Q_UNUSED(noteGuid)
141
142=== modified file 'src/plugin/Evernote/notebook.h'
143--- src/plugin/Evernote/notebook.h 2014-05-05 22:33:48 +0000
144+++ src/plugin/Evernote/notebook.h 2014-08-17 14:31:11 +0000
145@@ -28,12 +28,14 @@
146 {
147 Q_OBJECT
148
149+ // Don't forget to update clone() if you add new properties
150 Q_PROPERTY(QString guid READ guid CONSTANT)
151 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
152 Q_PROPERTY(int noteCount READ noteCount NOTIFY noteCountChanged)
153 Q_PROPERTY(bool published READ published NOTIFY publishedChanged)
154 Q_PROPERTY(QDateTime lastUpdated READ lastUpdated NOTIFY lastUpdatedChanged)
155 Q_PROPERTY(QString lastUpdatedString READ lastUpdatedString NOTIFY lastUpdatedChanged)
156+ // Don't forget to update clone() if you add new properties
157
158 public:
159 explicit Notebook(QString guid, QObject *parent = 0);
160@@ -53,6 +55,11 @@
161
162 QString lastUpdatedString() const;
163
164+ Notebook *clone();
165+
166+public slots:
167+ void save();
168+
169 signals:
170 void nameChanged();
171 void noteCountChanged();
172
173=== modified file 'src/plugin/Evernote/notesstore.cpp'
174--- src/plugin/Evernote/notesstore.cpp 2014-07-14 07:38:42 +0000
175+++ src/plugin/Evernote/notesstore.cpp 2014-08-17 14:31:11 +0000
176@@ -30,6 +30,7 @@
177 #include "jobs/fetchnotejob.h"
178 #include "jobs/createnotejob.h"
179 #include "jobs/savenotejob.h"
180+#include "jobs/savenotebookjob.h"
181 #include "jobs/deletenotejob.h"
182 #include "jobs/createnotebookjob.h"
183 #include "jobs/expungenotebookjob.h"
184@@ -186,6 +187,18 @@
185 EvernoteConnection::instance()->enqueue(job);
186 }
187
188+void NotesStore::saveNotebook(const QString &guid)
189+{
190+ Notebook *notebook = m_notebooksHash.value(guid);
191+ if (!notebook) {
192+ qWarning() << "Can't save notebook. Guid not found:" << guid;
193+ return;
194+ }
195+ SaveNotebookJob *job = new SaveNotebookJob(notebook, this);
196+ connect(job, &SaveNotebookJob::jobDone, this, &NotesStore::saveNotebookJobDone);
197+ EvernoteConnection::instance()->enqueue(job);
198+}
199+
200 void NotesStore::expungeNotebook(const QString &guid)
201 {
202 ExpungeNotebookJob *job = new ExpungeNotebookJob(guid);
203@@ -473,6 +486,17 @@
204 }
205 }
206
207+void NotesStore::saveNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
208+{
209+ if (errorCode != EvernoteConnection::ErrorCodeNoError) {
210+ qWarning() << "error saving notebook" << errorMessage;
211+
212+ // Lets fetch the notebook from the server again to reflect the non-saved state...
213+ refreshNotebooks();
214+ return;
215+ }
216+}
217+
218 void NotesStore::deleteNote(const QString &guid)
219 {
220 DeleteNoteJob *job = new DeleteNoteJob(guid, this);
221
222=== modified file 'src/plugin/Evernote/notesstore.h'
223--- src/plugin/Evernote/notesstore.h 2014-07-14 07:38:42 +0000
224+++ src/plugin/Evernote/notesstore.h 2014-08-17 14:31:11 +0000
225@@ -103,6 +103,7 @@
226 QList<Notebook*> notebooks() const;
227 Q_INVOKABLE Notebook* notebook(const QString &guid);
228 Q_INVOKABLE void createNotebook(const QString &name);
229+ Q_INVOKABLE void saveNotebook(const QString &guid);
230 Q_INVOKABLE void expungeNotebook(const QString &guid);
231
232 public slots:
233@@ -133,6 +134,7 @@
234 void fetchNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result, bool withResourceContent);
235 void createNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);
236 void saveNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);
237+ void saveNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
238 void deleteNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid);
239 void createNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Notebook &result);
240 void expungeNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid);

Subscribers

People subscribed via source and target branches