Merge lp:~mzanetti/reminders-app/get-username into lp:reminders-app

Proposed by Michael Zanetti
Status: Merged
Approved by: Michael Zanetti
Approved revision: 15
Merged at revision: 16
Proposed branch: lp:~mzanetti/reminders-app/get-username
Merge into: lp:reminders-app
Prerequisite: lp:~mzanetti/reminders-app/rework-error-handling
Diff against target: 1692 lines (+720/-345)
30 files modified
src/app/qml/reminders-app.qml (+8/-1)
src/app/qml/ui/AccountSelectorPage.qml (+1/-1)
src/plugin/Evernote/Evernote.pro (+10/-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/createnotejob.cpp (+2/-2)
src/plugin/Evernote/jobs/createnotejob.h (+4/-5)
src/plugin/Evernote/jobs/deletenotejob.cpp (+2/-2)
src/plugin/Evernote/jobs/deletenotejob.h (+4/-4)
src/plugin/Evernote/jobs/evernotejob.cpp (+12/-19)
src/plugin/Evernote/jobs/evernotejob.h (+3/-8)
src/plugin/Evernote/jobs/fetchnotebooksjob.cpp (+2/-2)
src/plugin/Evernote/jobs/fetchnotebooksjob.h (+4/-4)
src/plugin/Evernote/jobs/fetchnotejob.cpp (+2/-2)
src/plugin/Evernote/jobs/fetchnotejob.h (+4/-4)
src/plugin/Evernote/jobs/fetchnotesjob.cpp (+4/-2)
src/plugin/Evernote/jobs/fetchnotesjob.h (+4/-4)
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 (+2/-2)
src/plugin/Evernote/jobs/savenotejob.h (+4/-4)
src/plugin/Evernote/jobs/userstorejob.cpp (+39/-0)
src/plugin/Evernote/jobs/userstorejob.h (+46/-0)
src/plugin/Evernote/notesstore.cpp (+24/-131)
src/plugin/Evernote/notesstore.h (+13/-44)
src/plugin/Evernote/userstore.cpp (+38/-95)
src/plugin/Evernote/userstore.h (+19/-5)
To merge this branch: bzr merge lp:~mzanetti/reminders-app/get-username
Reviewer Review Type Date Requested Status
Alan Pope 🍺🐧🐱 πŸ¦„ (community) Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+196999@code.launchpad.net

Commit message

implement initial userstore. split connection handling into EvernoteConnection

Description of the change

This implements the beginning of the UserStore. So far it has only one property "username" which is what we will need in OnlineAccounts.

I have moved the connection setup into a new class "EvernoteConnection" so some stuff can be shared between NotesStore and UserStore. The EvernoteConnection class now does the connection setup and the job queue handling. The base class for Jobs is split into NotesStoreJob and UserStoreJob taking care about selecting the proper connection.

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: Approve (continuous-integration)
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) :
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/reminders-app.qml'
2--- src/app/qml/reminders-app.qml 2013-11-26 17:18:33 +0000
3+++ src/app/qml/reminders-app.qml 2013-11-28 00:46:50 +0000
4@@ -47,11 +47,18 @@
5
6 Component.onCompleted: {
7 pagestack.push(rootTabs)
8- if (NotesStore.token.length === 0) {
9+ if (EvernoteConnection.token.length === 0) {
10 pagestack.push(Qt.resolvedUrl("ui/AccountSelectorPage.qml"));
11 }
12 }
13
14+ Connections {
15+ target: UserStore
16+ onUsernameChanged: {
17+ print("Logged in as user:", UserStore.username)
18+ }
19+ }
20+
21 PageStack {
22 id: pagestack
23
24
25=== modified file 'src/app/qml/ui/AccountSelectorPage.qml'
26--- src/app/qml/ui/AccountSelectorPage.qml 2013-11-26 17:18:33 +0000
27+++ src/app/qml/ui/AccountSelectorPage.qml 2013-11-28 00:46:50 +0000
28@@ -51,7 +51,7 @@
29 // Print the access token on the console
30 onAuthenticated: {
31 console.log("Access token is " + reply.AccessToken)
32- NotesStore.token = reply.AccessToken;
33+ EvernoteConnection.token = reply.AccessToken;
34 pagestack.pop();
35 }
36 onAuthenticationError: { console.log("Authentication failed, code " + error.code) }
37
38=== modified file 'src/plugin/Evernote/Evernote.pro'
39--- src/plugin/Evernote/Evernote.pro 2013-11-28 00:46:50 +0000
40+++ src/plugin/Evernote/Evernote.pro 2013-11-28 00:46:50 +0000
41@@ -23,7 +23,11 @@
42 jobs/evernotejob.cpp \
43 jobs/savenotejob.cpp \
44 jobs/deletenotejob.cpp \
45- utils/html2enmlconverter.cpp
46+ utils/html2enmlconverter.cpp \
47+ evernoteconnection.cpp \
48+ jobs/userstorejob.cpp \
49+ jobs/notesstorejob.cpp \
50+ jobs/fetchusernamejob.cpp
51
52 HEADERS += evernoteplugin.h \
53 notesstore.h \
54@@ -39,7 +43,11 @@
55 jobs/evernotejob.h \
56 jobs/savenotejob.h \
57 jobs/deletenotejob.h \
58- utils/html2enmlconverter.h
59+ utils/html2enmlconverter.h \
60+ evernoteconnection.h \
61+ jobs/userstorejob.h \
62+ jobs/notesstorejob.h \
63+ jobs/fetchusernamejob.h
64
65 message(building in $$OUT_PWD)
66 LIBS += -L$$OUT_PWD/../../../3rdParty/evernote-sdk-cpp/ -L$$OUT_PWD/../../../3rdParty/libthrift/ -levernote-sdk-cpp -llibthrift -lssl -lcrypto
67
68=== added file 'src/plugin/Evernote/evernoteconnection.cpp'
69--- src/plugin/Evernote/evernoteconnection.cpp 1970-01-01 00:00:00 +0000
70+++ src/plugin/Evernote/evernoteconnection.cpp 2013-11-28 00:46:50 +0000
71@@ -0,0 +1,190 @@
72+/*
73+ * Copyright: 2013 Canonical, Ltd
74+ *
75+ * This file is part of reminders-app
76+ *
77+ * reminders-app 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-app 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+#include "evernoteconnection.h"
93+#include "jobs/evernotejob.h"
94+
95+// Thrift
96+#include <arpa/inet.h> // seems thrift forgot this one
97+#include <protocol/TBinaryProtocol.h>
98+#include <transport/THttpClient.h>
99+#include <transport/TSSLSocket.h>
100+#include <Thrift.h>
101+
102+// Evernote SDK
103+#include <NoteStore.h>
104+#include <NoteStore_constants.h>
105+#include <UserStore.h>
106+#include <UserStore_constants.h>
107+#include <Errors_types.h>
108+
109+#include <QDebug>
110+
111+using namespace apache::thrift;
112+using namespace apache::thrift::protocol;
113+using namespace apache::thrift::transport;
114+
115+EvernoteConnection* EvernoteConnection::s_instance = 0;
116+
117+// FIXME: need to populate this string from the system
118+// The structure should be:
119+// application/version; platform/version; [ device/version ]
120+// E.g. "Evernote Windows/3.0.1; Windows/XP SP3"
121+QString EDAM_CLIENT_NAME = QStringLiteral("Reminders/0.1; Ubuntu/13.10");
122+QString EVERNOTE_HOST = QStringLiteral("sandbox.evernote.com");
123+QString EDAM_USER_STORE_PATH = QStringLiteral("/edam/user");
124+QString EDAM_NOTE_STORE_PATH = QStringLiteral("/edam/note");
125+
126+EvernoteConnection::EvernoteConnection(QObject *parent) :
127+ QObject(parent),
128+ m_currentJob(0),
129+ m_useSSL(true)
130+{
131+ setupUserStore();
132+ setupNotesStore();
133+}
134+
135+bool EvernoteConnection::setupUserStore()
136+{
137+ bool versionOK = false;
138+ try {
139+ boost::shared_ptr<TSocket> socket;
140+
141+ if (m_useSSL) {
142+ boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory());
143+ socket = sslSocketFactory->createSocket(EVERNOTE_HOST.toStdString(), 443);
144+ qDebug() << "created UserStore SSL socket";
145+ } else {
146+ // Create a non-secure socket
147+ socket = boost::shared_ptr<TSocket> (new TSocket(EVERNOTE_HOST.toStdString(), 80));
148+ qDebug() << "created insecure UserStore socket";
149+ }
150+
151+ boost::shared_ptr<TBufferedTransport> bufferedTransport(new TBufferedTransport(socket));
152+ m_userStoreHttpClient = boost::shared_ptr<THttpClient>(new THttpClient(bufferedTransport,
153+ EVERNOTE_HOST.toStdString(),
154+ EDAM_USER_STORE_PATH.toStdString()));
155+ m_userStoreHttpClient->open();
156+ boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(m_userStoreHttpClient));
157+ m_userstoreClient = new evernote::edam::UserStoreClient(iprot);
158+ evernote::edam::UserStoreConstants constants;
159+ versionOK = m_userstoreClient->checkVersion(EDAM_CLIENT_NAME.toStdString(),
160+ constants.EDAM_VERSION_MAJOR,
161+ constants.EDAM_VERSION_MINOR);
162+ qDebug() << "UserStoreClient created. Version check:" << versionOK;
163+
164+ } catch (const TTransportException & e) {
165+ qWarning() << "Failed to create Transport for UserStore:" << e.what();
166+ } catch (const TException & e) {
167+ qWarning() << "Generic Thrift exception in UserStore setup:" << e.what();
168+ }
169+ return versionOK;
170+}
171+
172+bool EvernoteConnection::setupNotesStore()
173+{
174+ try {
175+ boost::shared_ptr<TSocket> socket;
176+
177+ if (m_useSSL) {
178+ boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory());
179+ socket = sslSocketFactory->createSocket(EVERNOTE_HOST.toStdString(), 443);
180+ qDebug() << "created NotesStore SSL socket";
181+ } else {
182+ // Create a non-secure socket
183+ socket = boost::shared_ptr<TSocket> (new TSocket(EVERNOTE_HOST.toStdString(), 80));
184+ qDebug() << "created insecure NotesStore socket";
185+ }
186+
187+ // setup UserStore
188+ boost::shared_ptr<TBufferedTransport> bufferedTransport(new TBufferedTransport(socket));
189+ m_notesStoreHttpClient = boost::shared_ptr<THttpClient>(new THttpClient(bufferedTransport,
190+ EVERNOTE_HOST.toStdString(),
191+ EDAM_NOTE_STORE_PATH.toStdString()));
192+ m_notesStoreHttpClient->open();
193+ boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(m_notesStoreHttpClient));
194+
195+ // setup notesstore
196+ m_notesStoreClient = new evernote::edam::NoteStoreClient(iprot);
197+
198+ qDebug() << "NoteStore client created.";
199+
200+ } catch (const TTransportException & e) {
201+ qWarning() << "Failed to create Transport for NotesStore:" << e.what();
202+ return false;
203+ } catch (const TException & e) {
204+ qWarning() << "Generic Thrift exception in NotesStore setup:" << e.what();
205+ return false;
206+ }
207+ return true;
208+}
209+
210+EvernoteConnection *EvernoteConnection::instance()
211+{
212+ if (!s_instance) {
213+ s_instance = new EvernoteConnection();
214+ }
215+ return s_instance;
216+}
217+
218+EvernoteConnection::~EvernoteConnection()
219+{
220+ delete m_notesStoreClient;
221+}
222+
223+QString EvernoteConnection::token() const
224+{
225+ return m_token;
226+}
227+
228+void EvernoteConnection::setToken(const QString &token)
229+{
230+ if (token != m_token) {
231+ m_token = token;
232+ emit tokenChanged();
233+ }
234+}
235+
236+void EvernoteConnection::enqueue(EvernoteJob *job)
237+{
238+ connect(job, &EvernoteJob::finished, this, &EvernoteConnection::startNextJob);
239+
240+ m_jobQueue.append(job);
241+ startJobQueue();
242+}
243+
244+void EvernoteConnection::startJobQueue()
245+{
246+ if (m_jobQueue.isEmpty()) {
247+ return;
248+ }
249+
250+ if (m_currentJob) {
251+ return;
252+ }
253+ m_currentJob = m_jobQueue.takeFirst();
254+ m_currentJob->start();
255+}
256+
257+void EvernoteConnection::startNextJob()
258+{
259+ m_currentJob = 0;
260+ startJobQueue();
261+}
262
263=== added file 'src/plugin/Evernote/evernoteconnection.h'
264--- src/plugin/Evernote/evernoteconnection.h 1970-01-01 00:00:00 +0000
265+++ src/plugin/Evernote/evernoteconnection.h 2013-11-28 00:46:50 +0000
266@@ -0,0 +1,101 @@
267+/*
268+ * Copyright: 2013 Canonical, Ltd
269+ *
270+ * This file is part of reminders-app
271+ *
272+ * reminders-app is free software: you can redistribute it and/or modify
273+ * it under the terms of the GNU General Public License as published by
274+ * the Free Software Foundation; version 3.
275+ *
276+ * reminders-app is distributed in the hope that it will be useful,
277+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
278+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
279+ * GNU General Public License for more details.
280+ *
281+ * You should have received a copy of the GNU General Public License
282+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
283+ *
284+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
285+ */
286+
287+#ifndef EVERNOTECONNECTION_H
288+#define EVERNOTECONNECTION_H
289+
290+#include <boost/shared_ptr.hpp>
291+
292+// Thrift
293+#include <transport/THttpClient.h>
294+
295+#include <QObject>
296+
297+namespace evernote {
298+namespace edam {
299+class NoteStoreClient;
300+class UserStoreClient;
301+}
302+}
303+
304+using namespace apache::thrift::transport;
305+
306+class EvernoteJob;
307+
308+class EvernoteConnection : public QObject
309+{
310+ Q_OBJECT
311+ Q_PROPERTY(QString token READ token WRITE setToken NOTIFY tokenChanged)
312+
313+ friend class NotesStoreJob;
314+ friend class UserStoreJob;
315+
316+public:
317+ enum ErrorCode {
318+ ErrorCodeNoError,
319+ ErrorCodeUserException,
320+ ErrorCodeSystemException,
321+ ErrorCodeNotFoundExcpetion,
322+ ErrorCodeConnectionLost
323+ };
324+
325+ static EvernoteConnection* instance();
326+ ~EvernoteConnection();
327+
328+ QString token() const;
329+ void setToken(const QString &token);
330+
331+ void enqueue(EvernoteJob *job);
332+
333+signals:
334+ void tokenChanged();
335+
336+private slots:
337+ void startJobQueue();
338+ void startNextJob();
339+
340+private:
341+ explicit EvernoteConnection(QObject *parent = 0);
342+ static EvernoteConnection *s_instance;
343+
344+ bool setupUserStore();
345+ bool setupNotesStore();
346+
347+ bool m_useSSL;
348+
349+ QString m_token;
350+
351+ // There must be only one job running at a time
352+ // Do not start jobs other than with startJobQueue()
353+ QList<EvernoteJob*> m_jobQueue;
354+ EvernoteJob *m_currentJob;
355+
356+ // Those 4 are accessed from the job thread.
357+ // Make sure to not access them while any jobs are running
358+ // or we need to mutex them.
359+ evernote::edam::NoteStoreClient *m_notesStoreClient;
360+ boost::shared_ptr<THttpClient> m_notesStoreHttpClient;
361+
362+ evernote::edam::UserStoreClient *m_userstoreClient;
363+ boost::shared_ptr<THttpClient> m_userStoreHttpClient;
364+
365+};
366+
367+#endif // EVERNOTECONNECTION_H
368
369=== modified file 'src/plugin/Evernote/evernoteplugin.cpp'
370--- src/plugin/Evernote/evernoteplugin.cpp 2013-11-26 17:18:33 +0000
371+++ src/plugin/Evernote/evernoteplugin.cpp 2013-11-28 00:46:50 +0000
372@@ -20,6 +20,7 @@
373
374 #include "evernoteplugin.h"
375
376+#include "evernoteconnection.h"
377 #include "userstore.h"
378 #include "notesstore.h"
379 #include "notes.h"
380@@ -28,16 +29,27 @@
381
382 #include <QtQml>
383
384+static QObject* userStoreProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
385+{
386+ return UserStore::instance();
387+}
388+
389 static QObject* notesStoreProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
390 {
391 return NotesStore::instance();
392 }
393
394+static QObject* connectionProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
395+{
396+ return EvernoteConnection::instance();
397+}
398+
399 void FitBitPlugin::registerTypes(const char *uri)
400 {
401- qmlRegisterType<UserStore>("Evernote", 0, 1, "UserStore");
402-
403+ qmlRegisterSingletonType<UserStore>("Evernote", 0, 1, "UserStore", userStoreProvider);
404 qmlRegisterSingletonType<NotesStore>("Evernote", 0, 1, "NotesStore", notesStoreProvider);
405+ qmlRegisterSingletonType<EvernoteConnection>("Evernote", 0, 1, "EvernoteConnection", connectionProvider);
406+
407 qmlRegisterType<Notes>("Evernote", 0, 1, "Notes");
408 qmlRegisterType<Notebooks>("Evernote", 0, 1, "Notebooks");
409 qmlRegisterUncreatableType<Note>("Evernote", 0, 1, "Note", "Cannot create Notes in QML. Use NotesStore.createNote() instead.");
410
411=== modified file 'src/plugin/Evernote/jobs/createnotejob.cpp'
412--- src/plugin/Evernote/jobs/createnotejob.cpp 2013-11-28 00:46:50 +0000
413+++ src/plugin/Evernote/jobs/createnotejob.cpp 2013-11-28 00:46:50 +0000
414@@ -23,7 +23,7 @@
415 #include <QDebug>
416
417 CreateNoteJob::CreateNoteJob(const QString &title, const QString &notebookGuid, const QString &content, QObject *parent) :
418- EvernoteJob(parent),
419+ NotesStoreJob(parent),
420 m_title(title),
421 m_notebookGuid(notebookGuid),
422 m_content(content)
423@@ -45,7 +45,7 @@
424 client()->createNote(m_resultNote, token().toStdString(), input);
425 }
426
427-void CreateNoteJob::emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage)
428+void CreateNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
429 {
430 emit jobDone(errorCode, errorMessage, m_resultNote);
431 }
432
433=== modified file 'src/plugin/Evernote/jobs/createnotejob.h'
434--- src/plugin/Evernote/jobs/createnotejob.h 2013-11-28 00:46:50 +0000
435+++ src/plugin/Evernote/jobs/createnotejob.h 2013-11-28 00:46:50 +0000
436@@ -1,21 +1,20 @@
437 #ifndef CREATENOTEJOB_H
438 #define CREATENOTEJOB_H
439
440-#include "evernotejob.h"
441-#include "note.h"
442+#include "notesstorejob.h"
443
444-class CreateNoteJob : public EvernoteJob
445+class CreateNoteJob : public NotesStoreJob
446 {
447 Q_OBJECT
448 public:
449 explicit CreateNoteJob(const QString &title, const QString &notebookGuid, const QString &content, QObject *parent = 0);
450
451 signals:
452- void jobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, evernote::edam::Note note);
453+ void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, evernote::edam::Note note);
454
455 protected:
456 void startJob();
457- void emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage);
458+ void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
459
460 private:
461 QString m_title;
462
463=== modified file 'src/plugin/Evernote/jobs/deletenotejob.cpp'
464--- src/plugin/Evernote/jobs/deletenotejob.cpp 2013-11-28 00:46:50 +0000
465+++ src/plugin/Evernote/jobs/deletenotejob.cpp 2013-11-28 00:46:50 +0000
466@@ -21,7 +21,7 @@
467 #include "deletenotejob.h"
468
469 DeleteNoteJob::DeleteNoteJob(const QString &guid, QObject *parent):
470- EvernoteJob(parent),
471+ NotesStoreJob(parent),
472 m_guid(guid)
473 {
474 }
475@@ -31,7 +31,7 @@
476 client()->deleteNote(token().toStdString(), m_guid.toStdString());
477 }
478
479-void DeleteNoteJob::emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage)
480+void DeleteNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
481 {
482 emit jobDone(errorCode, errorMessage, m_guid);
483 }
484
485=== modified file 'src/plugin/Evernote/jobs/deletenotejob.h'
486--- src/plugin/Evernote/jobs/deletenotejob.h 2013-11-28 00:46:50 +0000
487+++ src/plugin/Evernote/jobs/deletenotejob.h 2013-11-28 00:46:50 +0000
488@@ -1,20 +1,20 @@
489 #ifndef DELETENOTEJOB_H
490 #define DELETENOTEJOB_H
491
492-#include "evernotejob.h"
493+#include "notesstorejob.h"
494
495-class DeleteNoteJob : public EvernoteJob
496+class DeleteNoteJob : public NotesStoreJob
497 {
498 Q_OBJECT
499 public:
500 DeleteNoteJob(const QString &guid, QObject *parent = 0);
501
502 signals:
503- void jobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, const QString &guid);
504+ void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid);
505
506 protected:
507 void startJob();
508- void emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage);
509+ void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
510
511 private:
512 QString m_guid;
513
514=== modified file 'src/plugin/Evernote/jobs/evernotejob.cpp'
515--- src/plugin/Evernote/jobs/evernotejob.cpp 2013-11-28 00:46:50 +0000
516+++ src/plugin/Evernote/jobs/evernotejob.cpp 2013-11-28 00:46:50 +0000
517@@ -19,6 +19,7 @@
518 */
519
520 #include "evernotejob.h"
521+#include "evernoteconnection.h"
522
523 // Thrift
524 #include <arpa/inet.h> // seems thrift forgot this one
525@@ -35,10 +36,9 @@
526
527 EvernoteJob::EvernoteJob(QObject *parent) :
528 QThread(parent),
529- m_token(NotesStore::instance()->token())
530+ m_token(EvernoteConnection::instance()->token())
531 {
532 connect(this, &EvernoteJob::finished, this, &EvernoteJob::deleteLater);
533- connect(this, &EvernoteJob::finished, NotesStore::instance(), &NotesStore::startNextJob);
534 }
535
536 EvernoteJob::~EvernoteJob()
537@@ -49,7 +49,7 @@
538 {
539 if (m_token.isEmpty()) {
540 qWarning() << "No token set. Cannot execute job.";
541- emitJobDone(NotesStore::ErrorCodeUserException, QStringLiteral("No token set."));
542+ emitJobDone(EvernoteConnection::ErrorCodeUserException, QStringLiteral("No token set."));
543 return;
544 }
545
546@@ -62,36 +62,29 @@
547 // so lets try to start the job once more.
548 qWarning() << "Got a transport exception:" << e.what() << ". Trying to reestablish connection...";
549 try {
550- NotesStore::instance()->m_httpClient->close();
551- NotesStore::instance()->m_httpClient->open();
552-
553+ resetConnection();
554 startJob();
555 } catch (const TTransportException &e) {
556 // Giving up... the connection seems to be down for real.
557 qWarning() << "Cannot reestablish connection:" << e.what();
558- emitJobDone(NotesStore::ErrorCodeConnectionLost, e.what());
559+ emitJobDone(EvernoteConnection::ErrorCodeConnectionLost, e.what());
560 } catch (const evernote::edam::EDAMUserException &e) {
561- emitJobDone(NotesStore::ErrorCodeUserException, e.what());
562+ emitJobDone(EvernoteConnection::ErrorCodeUserException, e.what());
563 } catch (const evernote::edam::EDAMSystemException &e) {
564- emitJobDone(NotesStore::ErrorCodeSystemException, e.what());
565+ emitJobDone(EvernoteConnection::ErrorCodeSystemException, e.what());
566 } catch (const evernote::edam::EDAMNotFoundException &e) {
567- emitJobDone(NotesStore::ErrorCodeNotFoundExcpetion, e.what());
568+ emitJobDone(EvernoteConnection::ErrorCodeNotFoundExcpetion, e.what());
569 }
570
571 } catch (const evernote::edam::EDAMUserException &e) {
572- emitJobDone(NotesStore::ErrorCodeUserException, e.what());
573+ emitJobDone(EvernoteConnection::ErrorCodeUserException, e.what());
574 } catch (const evernote::edam::EDAMSystemException &e) {
575- emitJobDone(NotesStore::ErrorCodeSystemException, e.what());
576+ emitJobDone(EvernoteConnection::ErrorCodeSystemException, e.what());
577 } catch (const evernote::edam::EDAMNotFoundException &e) {
578- emitJobDone(NotesStore::ErrorCodeNotFoundExcpetion, e.what());
579+ emitJobDone(EvernoteConnection::ErrorCodeNotFoundExcpetion, e.what());
580 }
581
582- emitJobDone(NotesStore::ErrorCodeNoError, QString());
583-}
584-
585-evernote::edam::NoteStoreClient *EvernoteJob::client()
586-{
587- return NotesStore::instance()->m_client;
588+ emitJobDone(EvernoteConnection::ErrorCodeNoError, QString());
589 }
590
591 QString EvernoteJob::token()
592
593=== modified file 'src/plugin/Evernote/jobs/evernotejob.h'
594--- src/plugin/Evernote/jobs/evernotejob.h 2013-11-28 00:46:50 +0000
595+++ src/plugin/Evernote/jobs/evernotejob.h 2013-11-28 00:46:50 +0000
596@@ -3,11 +3,6 @@
597
598 #include "notesstore.h"
599
600-// Evernote SDK
601-#include <NoteStore.h>
602-#include <NoteStore_constants.h>
603-#include <Errors_types.h>
604-
605 #include <QThread>
606
607 /* How to create a new Job type:
608@@ -15,7 +10,7 @@
609 * - Implement startJob() in which you do the call to evernote.
610 * - No need to catch exceptions, EvernoteJob will deal with those.
611 * - Define a jobDone() signal with the result parameters you need.
612- * - Keep the convention of jobDone(NotesStore::ErrorCode errorCode, const QString &message [, ...])
613+ * - Keep the convention of jobDone(EvernoteConnection::ErrorCode errorCode, const QString &message [, ...])
614 * - Emit jobDone() in your implementation of emitJobDone().
615 * - NOTE: emitJobDone() might be called with an error even before startJob() is triggered.
616 *
617@@ -36,10 +31,10 @@
618 void connectionLost(const QString &errorMessage);
619
620 protected:
621+ virtual void resetConnection() = 0;
622 virtual void startJob() = 0;
623- virtual void emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage) = 0;
624+ virtual void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) = 0;
625
626- evernote::edam::NoteStoreClient* client();
627 QString token();
628
629 private:
630
631=== modified file 'src/plugin/Evernote/jobs/fetchnotebooksjob.cpp'
632--- src/plugin/Evernote/jobs/fetchnotebooksjob.cpp 2013-11-28 00:46:50 +0000
633+++ src/plugin/Evernote/jobs/fetchnotebooksjob.cpp 2013-11-28 00:46:50 +0000
634@@ -23,7 +23,7 @@
635 #include <QDebug>
636
637 FetchNotebooksJob::FetchNotebooksJob(QObject *parent) :
638- EvernoteJob(parent)
639+ NotesStoreJob(parent)
640 {
641 }
642
643@@ -33,7 +33,7 @@
644 client()->listNotebooks(m_results, token().toStdString());
645 }
646
647-void FetchNotebooksJob::emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage)
648+void FetchNotebooksJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
649 {
650 emit jobDone(errorCode, errorMessage, m_results);
651 }
652
653=== modified file 'src/plugin/Evernote/jobs/fetchnotebooksjob.h'
654--- src/plugin/Evernote/jobs/fetchnotebooksjob.h 2013-11-28 00:46:50 +0000
655+++ src/plugin/Evernote/jobs/fetchnotebooksjob.h 2013-11-28 00:46:50 +0000
656@@ -1,20 +1,20 @@
657 #ifndef FETCHNOTEBOOKSJOB_H
658 #define FETCHNOTEBOOKSJOB_H
659
660-#include "evernotejob.h"
661+#include "notesstorejob.h"
662
663-class FetchNotebooksJob : public EvernoteJob
664+class FetchNotebooksJob : public NotesStoreJob
665 {
666 Q_OBJECT
667 public:
668 explicit FetchNotebooksJob(QObject *parent = 0);
669
670 signals:
671- void jobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results);
672+ void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results);
673
674 protected:
675 void startJob();
676- void emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage);
677+ void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
678
679 private:
680 std::vector<evernote::edam::Notebook> m_results;
681
682=== modified file 'src/plugin/Evernote/jobs/fetchnotejob.cpp'
683--- src/plugin/Evernote/jobs/fetchnotejob.cpp 2013-11-28 00:46:50 +0000
684+++ src/plugin/Evernote/jobs/fetchnotejob.cpp 2013-11-28 00:46:50 +0000
685@@ -21,7 +21,7 @@
686 #include "fetchnotejob.h"
687
688 FetchNoteJob::FetchNoteJob(const QString &guid, QObject *parent) :
689- EvernoteJob(parent),
690+ NotesStoreJob(parent),
691 m_guid(guid)
692 {
693 }
694@@ -31,7 +31,7 @@
695 client()->getNote(m_result, token().toStdString(), m_guid.toStdString(), true, true, false, false);
696 }
697
698-void FetchNoteJob::emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage)
699+void FetchNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
700 {
701 emit resultReady(errorCode, errorMessage, m_result);
702 }
703
704=== modified file 'src/plugin/Evernote/jobs/fetchnotejob.h'
705--- src/plugin/Evernote/jobs/fetchnotejob.h 2013-11-28 00:46:50 +0000
706+++ src/plugin/Evernote/jobs/fetchnotejob.h 2013-11-28 00:46:50 +0000
707@@ -1,20 +1,20 @@
708 #ifndef FETCHNOTEJOB_H
709 #define FETCHNOTEJOB_H
710
711-#include "evernotejob.h"
712+#include "notesstorejob.h"
713
714-class FetchNoteJob : public EvernoteJob
715+class FetchNoteJob : public NotesStoreJob
716 {
717 Q_OBJECT
718 public:
719 explicit FetchNoteJob(const QString &guid, QObject *parent = 0);
720
721 signals:
722- void resultReady(NotesStore::ErrorCode error, const QString &errorMessage, const evernote::edam::Note &note);
723+ void resultReady(EvernoteConnection::ErrorCode error, const QString &errorMessage, const evernote::edam::Note &note);
724
725 protected:
726 void startJob();
727- void emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage);
728+ void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
729
730 private:
731 evernote::edam::NoteStoreClient *m_client;
732
733=== modified file 'src/plugin/Evernote/jobs/fetchnotesjob.cpp'
734--- src/plugin/Evernote/jobs/fetchnotesjob.cpp 2013-11-28 00:46:50 +0000
735+++ src/plugin/Evernote/jobs/fetchnotesjob.cpp 2013-11-28 00:46:50 +0000
736@@ -25,13 +25,14 @@
737 #include <QDebug>
738
739 FetchNotesJob::FetchNotesJob( const QString &filterNotebookGuid, QObject *parent) :
740- EvernoteJob(parent),
741+ NotesStoreJob(parent),
742 m_filterNotebookGuid(filterNotebookGuid)
743 {
744 }
745
746 void FetchNotesJob::startJob()
747 {
748+ qDebug() << "starting fetch notes job";
749 // TODO: fix start/end (use smaller chunks and continue fetching if there are more notes available)
750 int32_t start = 0;
751 int32_t end = 10000;
752@@ -49,9 +50,10 @@
753 resultSpec.__isset.includeTitle = true;
754
755 client()->findNotesMetadata(m_results, token().toStdString(), filter, start, end, resultSpec);
756+ qDebug() << "ending fetch notes job";
757 }
758
759-void FetchNotesJob::emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage)
760+void FetchNotesJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
761 {
762 emit jobDone(errorCode, errorMessage, m_results);
763 }
764
765=== modified file 'src/plugin/Evernote/jobs/fetchnotesjob.h'
766--- src/plugin/Evernote/jobs/fetchnotesjob.h 2013-11-28 00:46:50 +0000
767+++ src/plugin/Evernote/jobs/fetchnotesjob.h 2013-11-28 00:46:50 +0000
768@@ -1,20 +1,20 @@
769 #ifndef FETCHNOTESJOB_H
770 #define FETCHNOTESJOB_H
771
772-#include "evernotejob.h"
773+#include "notesstorejob.h"
774
775-class FetchNotesJob : public EvernoteJob
776+class FetchNotesJob : public NotesStoreJob
777 {
778 Q_OBJECT
779 public:
780 explicit FetchNotesJob(const QString &filterNotebookGuid, QObject *parent = 0);
781
782 signals:
783- void jobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results);
784+ void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results);
785
786 protected:
787 void startJob();
788- void emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage);
789+ void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
790
791 private:
792 QString m_filterNotebookGuid;
793
794=== added file 'src/plugin/Evernote/jobs/fetchusernamejob.cpp'
795--- src/plugin/Evernote/jobs/fetchusernamejob.cpp 1970-01-01 00:00:00 +0000
796+++ src/plugin/Evernote/jobs/fetchusernamejob.cpp 2013-11-28 00:46:50 +0000
797@@ -0,0 +1,38 @@
798+/*
799+ * Copyright: 2013 Canonical, Ltd
800+ *
801+ * This file is part of reminders-app
802+ *
803+ * reminders-app is free software: you can redistribute it and/or modify
804+ * it under the terms of the GNU General Public License as published by
805+ * the Free Software Foundation; version 3.
806+ *
807+ * reminders-app is distributed in the hope that it will be useful,
808+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
809+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
810+ * GNU General Public License for more details.
811+ *
812+ * You should have received a copy of the GNU General Public License
813+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
814+ *
815+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
816+ */
817+
818+#include "fetchusernamejob.h"
819+
820+FetchUsernameJob::FetchUsernameJob(QObject *parent) :
821+ UserStoreJob(parent)
822+{
823+}
824+
825+void FetchUsernameJob::startJob()
826+{
827+ evernote::edam::User user;
828+ client()->getUser(user, token().toStdString());
829+ m_result = QString::fromStdString(user.username);
830+}
831+
832+void FetchUsernameJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
833+{
834+ emit jobDone(errorCode, errorMessage, m_result);
835+}
836
837=== added file 'src/plugin/Evernote/jobs/fetchusernamejob.h'
838--- src/plugin/Evernote/jobs/fetchusernamejob.h 1970-01-01 00:00:00 +0000
839+++ src/plugin/Evernote/jobs/fetchusernamejob.h 2013-11-28 00:46:50 +0000
840@@ -0,0 +1,43 @@
841+/*
842+ * Copyright: 2013 Canonical, Ltd
843+ *
844+ * This file is part of reminders-app
845+ *
846+ * reminders-app is free software: you can redistribute it and/or modify
847+ * it under the terms of the GNU General Public License as published by
848+ * the Free Software Foundation; version 3.
849+ *
850+ * reminders-app is distributed in the hope that it will be useful,
851+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
852+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
853+ * GNU General Public License for more details.
854+ *
855+ * You should have received a copy of the GNU General Public License
856+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
857+ *
858+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
859+ */
860+
861+#ifndef FETCHUSERNAMEJOB_H
862+#define FETCHUSERNAMEJOB_H
863+
864+#include "userstorejob.h"
865+
866+class FetchUsernameJob : public UserStoreJob
867+{
868+ Q_OBJECT
869+public:
870+ explicit FetchUsernameJob(QObject *parent = 0);
871+
872+signals:
873+ void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result);
874+
875+protected:
876+ void startJob();
877+ void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
878+
879+private:
880+ QString m_result;
881+};
882+
883+#endif // FETCHUSERNAMEJOB_H
884
885=== added file 'src/plugin/Evernote/jobs/notesstorejob.cpp'
886--- src/plugin/Evernote/jobs/notesstorejob.cpp 1970-01-01 00:00:00 +0000
887+++ src/plugin/Evernote/jobs/notesstorejob.cpp 2013-11-28 00:46:50 +0000
888@@ -0,0 +1,39 @@
889+/*
890+ * Copyright: 2013 Canonical, Ltd
891+ *
892+ * This file is part of reminders-app
893+ *
894+ * reminders-app is free software: you can redistribute it and/or modify
895+ * it under the terms of the GNU General Public License as published by
896+ * the Free Software Foundation; version 3.
897+ *
898+ * reminders-app is distributed in the hope that it will be useful,
899+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
900+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
901+ * GNU General Public License for more details.
902+ *
903+ * You should have received a copy of the GNU General Public License
904+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
905+ *
906+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
907+ */
908+
909+#include "notesstorejob.h"
910+
911+#include "evernoteconnection.h"
912+
913+NotesStoreJob::NotesStoreJob(QObject *parent) :
914+ EvernoteJob(parent)
915+{
916+}
917+
918+void NotesStoreJob::resetConnection()
919+{
920+ EvernoteConnection::instance()->m_notesStoreHttpClient->close();
921+ EvernoteConnection::instance()->m_notesStoreHttpClient->open();
922+}
923+
924+evernote::edam::NoteStoreClient *NotesStoreJob::client() const
925+{
926+ return EvernoteConnection::instance()->m_notesStoreClient;
927+}
928
929=== added file 'src/plugin/Evernote/jobs/notesstorejob.h'
930--- src/plugin/Evernote/jobs/notesstorejob.h 1970-01-01 00:00:00 +0000
931+++ src/plugin/Evernote/jobs/notesstorejob.h 2013-11-28 00:46:50 +0000
932@@ -0,0 +1,44 @@
933+/*
934+ * Copyright: 2013 Canonical, Ltd
935+ *
936+ * This file is part of reminders-app
937+ *
938+ * reminders-app is free software: you can redistribute it and/or modify
939+ * it under the terms of the GNU General Public License as published by
940+ * the Free Software Foundation; version 3.
941+ *
942+ * reminders-app is distributed in the hope that it will be useful,
943+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
944+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
945+ * GNU General Public License for more details.
946+ *
947+ * You should have received a copy of the GNU General Public License
948+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
949+ *
950+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
951+ */
952+
953+#ifndef NOTESSTOREJOB_H
954+#define NOTESSTOREJOB_H
955+
956+#include "evernotejob.h"
957+
958+// Evernote SDK
959+#include <NoteStore.h>
960+#include <NoteStore_constants.h>
961+#include <Errors_types.h>
962+
963+class NotesStoreJob : public EvernoteJob
964+{
965+ Q_OBJECT
966+public:
967+ explicit NotesStoreJob(QObject *parent = 0);
968+
969+protected:
970+ void resetConnection() final;
971+
972+ evernote::edam::NoteStoreClient *client() const;
973+
974+};
975+
976+#endif // NOTESSTOREJOB_H
977
978=== modified file 'src/plugin/Evernote/jobs/savenotejob.cpp'
979--- src/plugin/Evernote/jobs/savenotejob.cpp 2013-11-28 00:46:50 +0000
980+++ src/plugin/Evernote/jobs/savenotejob.cpp 2013-11-28 00:46:50 +0000
981@@ -24,7 +24,7 @@
982 #include <QDebug>
983
984 SaveNoteJob::SaveNoteJob(Note *note, QObject *parent) :
985- EvernoteJob(parent),
986+ NotesStoreJob(parent),
987 m_guid(note->guid()),
988 m_title(note->title()),
989 m_notebookGuid(note->notebookGuid()),
990@@ -48,7 +48,7 @@
991 client()->updateNote(m_note, token().toStdString(), note);
992 }
993
994-void SaveNoteJob::emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage)
995+void SaveNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
996 {
997 emit jobDone(errorCode, errorMessage, m_note);
998 }
999
1000=== modified file 'src/plugin/Evernote/jobs/savenotejob.h'
1001--- src/plugin/Evernote/jobs/savenotejob.h 2013-11-28 00:46:50 +0000
1002+++ src/plugin/Evernote/jobs/savenotejob.h 2013-11-28 00:46:50 +0000
1003@@ -1,20 +1,20 @@
1004 #ifndef SAVENOTEJOB_H
1005 #define SAVENOTEJOB_H
1006
1007-#include "evernotejob.h"
1008+#include "notesstorejob.h"
1009
1010-class SaveNoteJob : public EvernoteJob
1011+class SaveNoteJob : public NotesStoreJob
1012 {
1013 Q_OBJECT
1014 public:
1015 explicit SaveNoteJob(Note *note, QObject *parent = 0);
1016
1017 signals:
1018- void jobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &note);
1019+ void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &note);
1020
1021 protected:
1022 void startJob();
1023- void emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage);
1024+ void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
1025
1026 private:
1027 QString m_guid;
1028
1029=== added file 'src/plugin/Evernote/jobs/userstorejob.cpp'
1030--- src/plugin/Evernote/jobs/userstorejob.cpp 1970-01-01 00:00:00 +0000
1031+++ src/plugin/Evernote/jobs/userstorejob.cpp 2013-11-28 00:46:50 +0000
1032@@ -0,0 +1,39 @@
1033+/*
1034+ * Copyright: 2013 Canonical, Ltd
1035+ *
1036+ * This file is part of reminders-app
1037+ *
1038+ * reminders-app is free software: you can redistribute it and/or modify
1039+ * it under the terms of the GNU General Public License as published by
1040+ * the Free Software Foundation; version 3.
1041+ *
1042+ * reminders-app is distributed in the hope that it will be useful,
1043+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1044+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1045+ * GNU General Public License for more details.
1046+ *
1047+ * You should have received a copy of the GNU General Public License
1048+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1049+ *
1050+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
1051+ */
1052+
1053+#include "userstorejob.h"
1054+
1055+#include "evernoteconnection.h"
1056+
1057+UserStoreJob::UserStoreJob(QObject *parent) :
1058+ EvernoteJob(parent)
1059+{
1060+}
1061+
1062+void UserStoreJob::resetConnection()
1063+{
1064+ EvernoteConnection::instance()->m_userStoreHttpClient->close();
1065+ EvernoteConnection::instance()->m_userStoreHttpClient->open();
1066+}
1067+
1068+evernote::edam::UserStoreClient *UserStoreJob::client() const
1069+{
1070+ return EvernoteConnection::instance()->m_userstoreClient;
1071+}
1072
1073=== added file 'src/plugin/Evernote/jobs/userstorejob.h'
1074--- src/plugin/Evernote/jobs/userstorejob.h 1970-01-01 00:00:00 +0000
1075+++ src/plugin/Evernote/jobs/userstorejob.h 2013-11-28 00:46:50 +0000
1076@@ -0,0 +1,46 @@
1077+/*
1078+ * Copyright: 2013 Canonical, Ltd
1079+ *
1080+ * This file is part of reminders-app
1081+ *
1082+ * reminders-app is free software: you can redistribute it and/or modify
1083+ * it under the terms of the GNU General Public License as published by
1084+ * the Free Software Foundation; version 3.
1085+ *
1086+ * reminders-app is distributed in the hope that it will be useful,
1087+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1088+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1089+ * GNU General Public License for more details.
1090+ *
1091+ * You should have received a copy of the GNU General Public License
1092+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1093+ *
1094+ * Authors: Michael Zanetti <michael.zanetti@canonical.com>
1095+ */
1096+
1097+#ifndef USERSTOREJOB_H
1098+#define USERSTOREJOB_H
1099+
1100+#include "evernotejob.h"
1101+
1102+// Evernote SDK
1103+#include <UserStore.h>
1104+#include <UserStore_constants.h>
1105+#include <Errors_types.h>
1106+
1107+class UserStoreJob : public EvernoteJob
1108+{
1109+ Q_OBJECT
1110+public:
1111+ explicit UserStoreJob(QObject *parent = 0);
1112+
1113+protected:
1114+ void resetConnection() final;
1115+
1116+ evernote::edam::UserStoreClient* client() const;
1117+
1118+public slots:
1119+
1120+};
1121+
1122+#endif // USERSTOREJOB_H
1123
1124=== modified file 'src/plugin/Evernote/notesstore.cpp'
1125--- src/plugin/Evernote/notesstore.cpp 2013-11-28 00:46:50 +0000
1126+++ src/plugin/Evernote/notesstore.cpp 2013-11-28 00:46:50 +0000
1127@@ -19,6 +19,7 @@
1128 */
1129
1130 #include "notesstore.h"
1131+#include "evernoteconnection.h"
1132 #include "notebooks.h"
1133 #include "notebook.h"
1134 #include "note.h"
1135@@ -31,69 +32,17 @@
1136 #include "jobs/savenotejob.h"
1137 #include "jobs/deletenotejob.h"
1138
1139-// Thrift
1140-#include <arpa/inet.h> // seems thrift forgot this one
1141-#include <protocol/TBinaryProtocol.h>
1142-#include <transport/THttpClient.h>
1143-#include <transport/TSSLSocket.h>
1144-#include <Thrift.h>
1145-
1146 #include <QDebug>
1147
1148-using namespace apache::thrift;
1149-using namespace apache::thrift::protocol;
1150-using namespace apache::thrift::transport;
1151-
1152 NotesStore* NotesStore::s_instance = 0;
1153
1154 NotesStore::NotesStore(QObject *parent) :
1155- QObject(parent),
1156- m_currentJob(0)
1157+ QObject(parent)
1158 {
1159- try {
1160- // FIXME: need to populate this string from the system
1161- // The structure should be:
1162- // application/version; platform/version; [ device/version ]
1163- // E.g. "Evernote Windows/3.0.1; Windows/XP SP3"
1164- QString EDAM_CLIENT_NAME = QStringLiteral("Reminders/0.1; Ubuntu/13.10");
1165- QString EVERNOTE_HOST = QStringLiteral("sandbox.evernote.com");
1166- QString EDAM_USER_STORE_PATH = QStringLiteral("/edam/note");
1167- boost::shared_ptr<TSocket> socket;
1168- bool use_SSL = true;
1169-
1170- if (use_SSL) {
1171- // Create an SSL socket
1172- // FIXME: this fails with the following error:
1173- // Thrift: Fri Nov 15 12:47:31 2013 SSL_shutdown: error code: 0
1174- // SSL_get_verify_result(), unable to get local issuer certificate
1175- // Additionally, the UI blocks and does not load for about 2 minutes
1176- boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory());
1177- socket = sslSocketFactory->createSocket(EVERNOTE_HOST.toStdString(), 443);
1178- qDebug() << "created SSL socket";
1179- } else {
1180- // Create a non-secure socket
1181- socket = boost::shared_ptr<TSocket> (new TSocket(EVERNOTE_HOST.toStdString(), 80));
1182- qDebug() << "created insecure socket";
1183- }
1184-
1185- boost::shared_ptr<TBufferedTransport> bufferedTransport(new TBufferedTransport(socket));
1186- m_httpClient = boost::shared_ptr<THttpClient>(new THttpClient(bufferedTransport,
1187- EVERNOTE_HOST.toStdString(),
1188- EDAM_USER_STORE_PATH.toStdString()));
1189- m_httpClient->open();
1190-
1191- boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(m_httpClient));
1192- m_client = new evernote::edam::NoteStoreClient(iprot);
1193-
1194- qDebug() << "NoteStore client created.";
1195-
1196- } catch (const TTransportException & e) {
1197- qWarning() << "Failed to create Transport:" << e.what();
1198- } catch (const TException & e) {
1199- qWarning() << "Generic Thrift exception:" << e.what();
1200- }
1201-
1202- qRegisterMetaType<NotesStore::ErrorCode>("NotesStore::ErrorCode");
1203+ connect(EvernoteConnection::instance(), &EvernoteConnection::tokenChanged, this, &NotesStore::refreshNotebooks);
1204+ connect(EvernoteConnection::instance(), SIGNAL(tokenChanged()), this, SLOT(refreshNotes()));
1205+
1206+ qRegisterMetaType<EvernoteConnection::ErrorCode>("EvernoteConnection::ErrorCode");
1207 qRegisterMetaType<evernote::edam::NotesMetadataList>("evernote::edam::NotesMetadataList");
1208 qRegisterMetaType<evernote::edam::Note>("evernote::edam::Note");
1209 qRegisterMetaType<std::vector<evernote::edam::Notebook> >("std::vector<evernote::edam::Notebook>");
1210@@ -108,39 +57,8 @@
1211 return s_instance;
1212 }
1213
1214-QString NotesStore::errorCodeToString(NotesStore::ErrorCode errorCode)
1215-{
1216- switch(errorCode) {
1217- case ErrorCodeNoError:
1218- return QStringLiteral("No error");
1219- case ErrorCodeUserException:
1220- return QStringLiteral("User exception");
1221- case ErrorCodeSystemException:
1222- return QStringLiteral("System exception");
1223- case ErrorCodeNotFoundExcpetion:
1224- return QStringLiteral("Not found");
1225- }
1226- return QString();
1227-}
1228-
1229 NotesStore::~NotesStore()
1230 {
1231- delete m_client;
1232-}
1233-
1234-QString NotesStore::token() const
1235-{
1236- return m_token;
1237-}
1238-
1239-void NotesStore::setToken(const QString &token)
1240-{
1241- if (token != m_token) {
1242- m_token = token;
1243- emit tokenChanged();
1244- refreshNotebooks();
1245- refreshNotes();
1246- }
1247 }
1248
1249 QList<Note*> NotesStore::notes() const
1250@@ -163,41 +81,16 @@
1251 return m_notebooks.value(guid);
1252 }
1253
1254-void NotesStore::enqueue(EvernoteJob *job)
1255-{
1256- m_jobQueue.append(job);
1257- startJobQueue();
1258-}
1259-
1260-void NotesStore::startJobQueue()
1261-{
1262- if (m_jobQueue.isEmpty()) {
1263- return;
1264- }
1265-
1266- if (m_currentJob) {
1267- return;
1268- }
1269- m_currentJob = m_jobQueue.takeFirst();
1270- m_currentJob->start();
1271-}
1272-
1273-void NotesStore::startNextJob()
1274-{
1275- m_currentJob = 0;
1276- startJobQueue();
1277-}
1278-
1279 void NotesStore::refreshNotes(const QString &filterNotebookGuid)
1280 {
1281 FetchNotesJob *job = new FetchNotesJob(filterNotebookGuid);
1282 connect(job, &FetchNotesJob::jobDone, this, &NotesStore::fetchNotesJobDone);
1283- enqueue(job);
1284+ EvernoteConnection::instance()->enqueue(job);
1285 }
1286
1287-void NotesStore::fetchNotesJobDone(ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results)
1288+void NotesStore::fetchNotesJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results)
1289 {
1290- if (errorCode != ErrorCodeNoError) {
1291+ if (errorCode != EvernoteConnection::ErrorCodeNoError) {
1292 qWarning() << "Failed to fetch notes list:" << errorMessage;
1293 return;
1294 }
1295@@ -223,12 +116,12 @@
1296 {
1297 FetchNoteJob *job = new FetchNoteJob(guid, this);
1298 connect(job, &FetchNoteJob::resultReady, this, &NotesStore::fetchNoteJobDone);
1299- enqueue(job);
1300+ EvernoteConnection::instance()->enqueue(job);
1301 }
1302
1303-void NotesStore::fetchNoteJobDone(ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result)
1304+void NotesStore::fetchNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result)
1305 {
1306- if (errorCode != ErrorCodeNoError) {
1307+ if (errorCode != EvernoteConnection::ErrorCodeNoError) {
1308 qWarning() << "Error fetching note:" << errorMessage;
1309 return;
1310 }
1311@@ -244,12 +137,12 @@
1312 {
1313 FetchNotebooksJob *job = new FetchNotebooksJob();
1314 connect(job, &FetchNotebooksJob::jobDone, this, &NotesStore::fetchNotebooksJobDone);
1315- enqueue(job);
1316+ EvernoteConnection::instance()->enqueue(job);
1317 }
1318
1319-void NotesStore::fetchNotebooksJobDone(ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results)
1320+void NotesStore::fetchNotebooksJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results)
1321 {
1322- if (errorCode != ErrorCodeNoError) {
1323+ if (errorCode != EvernoteConnection::ErrorCodeNoError) {
1324 qWarning() << "Error fetching notebooks:" << errorMessage;
1325 return;
1326 }
1327@@ -275,12 +168,12 @@
1328 {
1329 CreateNoteJob *job = new CreateNoteJob(title, notebookGuid, content);
1330 connect(job, &CreateNoteJob::jobDone, this, &NotesStore::createNoteJobDone);
1331- enqueue(job);
1332+ EvernoteConnection::instance()->enqueue(job);
1333 }
1334
1335-void NotesStore::createNoteJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result)
1336+void NotesStore::createNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result)
1337 {
1338- if (errorCode != ErrorCodeNoError) {
1339+ if (errorCode != EvernoteConnection::ErrorCodeNoError) {
1340 qWarning() << "Error creating note:" << errorMessage;
1341 return;
1342 }
1343@@ -303,12 +196,12 @@
1344
1345 SaveNoteJob *job = new SaveNoteJob(note, this);
1346 connect(job, &SaveNoteJob::jobDone, this, &NotesStore::saveNoteJobDone);
1347- enqueue(job);
1348+ EvernoteConnection::instance()->enqueue(job);
1349 }
1350
1351-void NotesStore::saveNoteJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result)
1352+void NotesStore::saveNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result)
1353 {
1354- if (errorCode != ErrorCodeNoError) {
1355+ if (errorCode != EvernoteConnection::ErrorCodeNoError) {
1356 qWarning() << "error saving note" << errorMessage;
1357 return;
1358 }
1359@@ -326,12 +219,12 @@
1360 {
1361 DeleteNoteJob *job = new DeleteNoteJob(guid, this);
1362 connect(job, &DeleteNoteJob::jobDone, this, &NotesStore::deleteNoteJobDone);
1363- enqueue(job);
1364+ EvernoteConnection::instance()->enqueue(job);
1365 }
1366
1367-void NotesStore::deleteNoteJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, const QString &guid)
1368+void NotesStore::deleteNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid)
1369 {
1370- if (errorCode != ErrorCodeNoError) {
1371+ if (errorCode != EvernoteConnection::ErrorCodeNoError) {
1372 qWarning() << "Cannot delete note:" << errorMessage;
1373 return;
1374 }
1375
1376=== modified file 'src/plugin/Evernote/notesstore.h'
1377--- src/plugin/Evernote/notesstore.h 2013-11-28 00:46:50 +0000
1378+++ src/plugin/Evernote/notesstore.h 2013-11-28 00:46:50 +0000
1379@@ -1,8 +1,14 @@
1380 #ifndef NOTESSTORE_H
1381 #define NOTESSTORE_H
1382
1383+#include "evernoteconnection.h"
1384+
1385 // Thrift
1386+#include <arpa/inet.h> // seems thrift forgot this one
1387+#include <protocol/TBinaryProtocol.h>
1388 #include <transport/THttpClient.h>
1389+#include <transport/TSSLSocket.h>
1390+#include <Thrift.h>
1391
1392 // Evernote SDK
1393 #include <NoteStore.h>
1394@@ -12,8 +18,6 @@
1395 #include <QObject>
1396 #include <QHash>
1397
1398-class EvernoteJob;
1399-
1400 class Notebook;
1401 class Note;
1402
1403@@ -22,29 +26,14 @@
1404 class NotesStore : public QObject
1405 {
1406 Q_OBJECT
1407- Q_PROPERTY(QString token READ token WRITE setToken NOTIFY tokenChanged)
1408-
1409- friend class EvernoteJob;
1410
1411 public:
1412- enum ErrorCode {
1413- ErrorCodeNoError,
1414- ErrorCodeUserException,
1415- ErrorCodeSystemException,
1416- ErrorCodeNotFoundExcpetion,
1417- ErrorCodeConnectionLost
1418- };
1419-
1420 Q_INVOKABLE void createNote(const QString &title, const QString &notebookGuid, const QString &content);
1421
1422 static NotesStore *instance();
1423- static QString errorCodeToString(ErrorCode errorCode);
1424
1425 ~NotesStore();
1426
1427- QString token() const;
1428- void setToken(const QString &token);
1429-
1430 QList<Note*> notes() const;
1431 Note* note(const QString &guid);
1432 void saveNote(const QString &guid);
1433@@ -53,6 +42,7 @@
1434 QList<Notebook*> notebooks() const;
1435 Notebook* notebook(const QString &guid);
1436
1437+public slots:
1438 void refreshNotes(const QString &filterNotebookGuid = QString());
1439 void refreshNoteContent(const QString &guid);
1440 void refreshNotebooks();
1441@@ -68,41 +58,20 @@
1442 void notebookChanged(const QString &guid);
1443
1444 private slots:
1445- void fetchNotesJobDone(ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results);
1446- void fetchNotebooksJobDone(ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results);
1447- void fetchNoteJobDone(ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);
1448- void createNoteJobDone(ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);
1449- void saveNoteJobDone(ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);
1450- void deleteNoteJobDone(ErrorCode errorCode, const QString &errorMessage, const QString &guid);
1451-
1452- // Use this to enqueue a new job. It will automatically start it if there is no other job pending.
1453- void enqueue(EvernoteJob *job);
1454- void startJobQueue();
1455-
1456- // You should not use this. It's called by the job queue.
1457- // If you have a new job to run, just enqueue it. The queue will process it eventually.
1458- void startNextJob();
1459+ void fetchNotesJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results);
1460+ void fetchNotebooksJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results);
1461+ void fetchNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);
1462+ void createNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);
1463+ void saveNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);
1464+ void deleteNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid);
1465
1466 private:
1467 explicit NotesStore(QObject *parent = 0);
1468 static NotesStore *s_instance;
1469
1470- QString m_token;
1471-
1472 QHash<QString, Notebook*> m_notebooks;
1473 QHash<QString, Note*> m_notes;
1474
1475- // There must be only one job running at a time
1476- // Do not start jobs other than with startJobQueue()
1477- QList<EvernoteJob*> m_jobQueue;
1478- EvernoteJob *m_currentJob;
1479-
1480- // Those two are accessed from the job thread.
1481- // Make sure to not access them while any jobs are running
1482- // or we need to mutex them.
1483- evernote::edam::NoteStoreClient *m_client;
1484- boost::shared_ptr<THttpClient> m_httpClient;
1485-
1486 };
1487
1488 #endif // NOTESSTORE_H
1489
1490=== modified file 'src/plugin/Evernote/userstore.cpp'
1491--- src/plugin/Evernote/userstore.cpp 2013-11-26 17:18:33 +0000
1492+++ src/plugin/Evernote/userstore.cpp 2013-11-28 00:46:50 +0000
1493@@ -19,6 +19,8 @@
1494 */
1495
1496 #include "userstore.h"
1497+#include "evernoteconnection.h"
1498+#include "jobs/fetchusernamejob.h"
1499
1500 // Evernote sdk
1501 #include <UserStore.h>
1502@@ -34,106 +36,47 @@
1503
1504 #include <QDebug>
1505
1506-using namespace evernote::edam;
1507 using namespace apache::thrift;
1508 using namespace apache::thrift::protocol;
1509 using namespace apache::thrift::transport;
1510
1511+UserStore* UserStore::s_instance = 0;
1512+
1513 UserStore::UserStore(QObject *parent) :
1514 QObject(parent)
1515 {
1516-
1517- try {
1518- // FIXME: need to populate this string from the system
1519- // The structure should be:
1520- // application/version; platform/version; [ device/version ]
1521- // E.g. "Evernote Windows/3.0.1; Windows/XP SP3"
1522- QString EDAM_CLIENT_NAME = QStringLiteral("Reminders/0.1; Ubuntu/13.10");
1523- QString EVERNOTE_HOST = QStringLiteral("sandbox.evernote.com");
1524- QString EDAM_USER_STORE_PATH = QStringLiteral("/edam/user");
1525- boost::shared_ptr<TSocket> socket;
1526- bool use_SSL = false;
1527-
1528- if (use_SSL) {
1529- // Create an SSL socket
1530- // FIXME: this fails with the following error:
1531- // Thrift: Fri Nov 15 12:47:31 2013 SSL_shutdown: error code: 0
1532- // SSL_get_verify_result(), unable to get local issuer certificate
1533- // Additionally, the UI blocks and does not load for about 2 minutes
1534- boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory());
1535- socket = sslSocketFactory->createSocket(EVERNOTE_HOST.toStdString(), 443);
1536- } else {
1537- // Create a non-secure socket
1538- socket = boost::shared_ptr<TSocket> (new TSocket(EVERNOTE_HOST.toStdString(), 80));
1539- }
1540-
1541- boost::shared_ptr<TBufferedTransport> bufferedTransport(new TBufferedTransport(socket));
1542- boost::shared_ptr<THttpClient> userStoreHttpClient (new THttpClient(bufferedTransport,
1543- EVERNOTE_HOST.toStdString(),
1544- EDAM_USER_STORE_PATH.toStdString()));
1545- userStoreHttpClient->open();
1546-
1547- boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(userStoreHttpClient));
1548- UserStoreClient m_client(iprot);
1549- UserStoreConstants constants;
1550-
1551- // checkVersion returns true if the client is capable of talking to the service,
1552- // false otherwise
1553- qDebug() << "version check:" << m_client.checkVersion(EDAM_CLIENT_NAME.toStdString(),
1554- constants.EDAM_VERSION_MAJOR,
1555- constants.EDAM_VERSION_MINOR);
1556-
1557- } catch(...) {
1558- displayException();
1559- }
1560-}
1561-
1562-void UserStore::getPublicUserInfo(const QString &user)
1563-{
1564- qDebug() << "should get public user info for user" << user;
1565- // PublicUserInfo userInfo;
1566-
1567-}
1568-
1569-// TODO: move to a common place instead of copying it through *store.cpps
1570-void UserStore::displayException()
1571-{
1572- QString error_message = "Unknown Exception";
1573- try
1574- {
1575- // this function is meant to be called from a catch block
1576- // rethrow the exception to catch it again
1577- throw;
1578- }
1579- catch (const EDAMNotFoundException & e)
1580- {
1581- qDebug() << e.what();
1582- }
1583- catch (const EDAMSystemException & e)
1584- {
1585- qDebug() << e.what();
1586- }
1587- catch (const EDAMUserException & e)
1588- {
1589- qDebug() << e.what();
1590- }
1591- catch (const TTransportException & e)
1592- {
1593- qDebug() << e.what();
1594- }
1595- catch (const TException & e)
1596- {
1597- qDebug() << e.what();
1598- }
1599- catch (const std::exception & e)
1600- {
1601- qDebug() << e.what();
1602- }
1603- catch (...)
1604- {
1605- error_message = "Tried to sync, but something went wrong.\n Unknown exception.";
1606- }
1607-
1608- qDebug() << error_message;
1609- disconnect();
1610+ connect(EvernoteConnection::instance(), &EvernoteConnection::tokenChanged, this, &UserStore::fetchUsername);
1611+
1612+ fetchUsername();
1613+}
1614+
1615+UserStore *UserStore::instance()
1616+{
1617+ if (!s_instance) {
1618+ s_instance = new UserStore();
1619+ }
1620+ return s_instance;
1621+}
1622+
1623+QString UserStore::username() const
1624+{
1625+ return m_username;
1626+}
1627+
1628+void UserStore::fetchUsername()
1629+{
1630+ FetchUsernameJob *job = new FetchUsernameJob();
1631+ connect(job, &FetchUsernameJob::jobDone, this, &UserStore::fetchUsernameJobDone);
1632+ EvernoteConnection::instance()->enqueue(job);
1633+}
1634+
1635+void UserStore::fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result)
1636+{
1637+ if (errorCode != EvernoteConnection::ErrorCodeNoError) {
1638+ qWarning() << "Error fetching username:" << errorMessage;
1639+ return;
1640+ }
1641+
1642+ m_username = result;
1643+ emit usernameChanged();
1644 }
1645
1646=== modified file 'src/plugin/Evernote/userstore.h'
1647--- src/plugin/Evernote/userstore.h 2013-11-24 17:03:28 +0000
1648+++ src/plugin/Evernote/userstore.h 2013-11-28 00:46:50 +0000
1649@@ -1,6 +1,9 @@
1650 #ifndef USERSTORE_H
1651 #define USERSTORE_H
1652
1653+#include "evernoteconnection.h"
1654+
1655+//Evernote SDK
1656 #include "UserStore.h"
1657
1658 #include <QObject>
1659@@ -8,17 +11,28 @@
1660 class UserStore : public QObject
1661 {
1662 Q_OBJECT
1663+
1664+ // TODO: Once we need more than just the username, turn this into a class User
1665+ Q_PROPERTY(QString username READ username NOTIFY usernameChanged)
1666+
1667 public:
1668- explicit UserStore(QObject *parent = 0);
1669+ static UserStore* instance();
1670+
1671+ QString username() const;
1672
1673 signals:
1674-
1675-public slots:
1676- void getPublicUserInfo(const QString &user);
1677+ void usernameChanged();
1678+
1679+private slots:
1680+ void fetchUsername();
1681+
1682+ void fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result);
1683
1684 private:
1685+ static UserStore* s_instance;
1686+ explicit UserStore(QObject *parent = 0);
1687
1688- void displayException();
1689+ QString m_username;
1690 };
1691
1692 #endif // USERSTORE_H

Subscribers

People subscribed via source and target branches