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
=== modified file 'src/app/qml/reminders-app.qml'
--- src/app/qml/reminders-app.qml 2013-11-26 17:18:33 +0000
+++ src/app/qml/reminders-app.qml 2013-11-28 00:46:50 +0000
@@ -47,11 +47,18 @@
4747
48 Component.onCompleted: {48 Component.onCompleted: {
49 pagestack.push(rootTabs)49 pagestack.push(rootTabs)
50 if (NotesStore.token.length === 0) {50 if (EvernoteConnection.token.length === 0) {
51 pagestack.push(Qt.resolvedUrl("ui/AccountSelectorPage.qml"));51 pagestack.push(Qt.resolvedUrl("ui/AccountSelectorPage.qml"));
52 }52 }
53 }53 }
5454
55 Connections {
56 target: UserStore
57 onUsernameChanged: {
58 print("Logged in as user:", UserStore.username)
59 }
60 }
61
55 PageStack {62 PageStack {
56 id: pagestack63 id: pagestack
5764
5865
=== modified file 'src/app/qml/ui/AccountSelectorPage.qml'
--- src/app/qml/ui/AccountSelectorPage.qml 2013-11-26 17:18:33 +0000
+++ src/app/qml/ui/AccountSelectorPage.qml 2013-11-28 00:46:50 +0000
@@ -51,7 +51,7 @@
51 // Print the access token on the console51 // Print the access token on the console
52 onAuthenticated: {52 onAuthenticated: {
53 console.log("Access token is " + reply.AccessToken)53 console.log("Access token is " + reply.AccessToken)
54 NotesStore.token = reply.AccessToken;54 EvernoteConnection.token = reply.AccessToken;
55 pagestack.pop();55 pagestack.pop();
56 }56 }
57 onAuthenticationError: { console.log("Authentication failed, code " + error.code) }57 onAuthenticationError: { console.log("Authentication failed, code " + error.code) }
5858
=== modified file 'src/plugin/Evernote/Evernote.pro'
--- src/plugin/Evernote/Evernote.pro 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/Evernote.pro 2013-11-28 00:46:50 +0000
@@ -23,7 +23,11 @@
23 jobs/evernotejob.cpp \23 jobs/evernotejob.cpp \
24 jobs/savenotejob.cpp \24 jobs/savenotejob.cpp \
25 jobs/deletenotejob.cpp \25 jobs/deletenotejob.cpp \
26 utils/html2enmlconverter.cpp26 utils/html2enmlconverter.cpp \
27 evernoteconnection.cpp \
28 jobs/userstorejob.cpp \
29 jobs/notesstorejob.cpp \
30 jobs/fetchusernamejob.cpp
2731
28HEADERS += evernoteplugin.h \32HEADERS += evernoteplugin.h \
29 notesstore.h \33 notesstore.h \
@@ -39,7 +43,11 @@
39 jobs/evernotejob.h \43 jobs/evernotejob.h \
40 jobs/savenotejob.h \44 jobs/savenotejob.h \
41 jobs/deletenotejob.h \45 jobs/deletenotejob.h \
42 utils/html2enmlconverter.h46 utils/html2enmlconverter.h \
47 evernoteconnection.h \
48 jobs/userstorejob.h \
49 jobs/notesstorejob.h \
50 jobs/fetchusernamejob.h
4351
44message(building in $$OUT_PWD)52message(building in $$OUT_PWD)
45LIBS += -L$$OUT_PWD/../../../3rdParty/evernote-sdk-cpp/ -L$$OUT_PWD/../../../3rdParty/libthrift/ -levernote-sdk-cpp -llibthrift -lssl -lcrypto53LIBS += -L$$OUT_PWD/../../../3rdParty/evernote-sdk-cpp/ -L$$OUT_PWD/../../../3rdParty/libthrift/ -levernote-sdk-cpp -llibthrift -lssl -lcrypto
4654
=== added file 'src/plugin/Evernote/evernoteconnection.cpp'
--- src/plugin/Evernote/evernoteconnection.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/evernoteconnection.cpp 2013-11-28 00:46:50 +0000
@@ -0,0 +1,190 @@
1/*
2 * Copyright: 2013 Canonical, Ltd
3 *
4 * This file is part of reminders-app
5 *
6 * reminders-app is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * reminders-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
19 */
20
21#include "evernoteconnection.h"
22#include "jobs/evernotejob.h"
23
24// Thrift
25#include <arpa/inet.h> // seems thrift forgot this one
26#include <protocol/TBinaryProtocol.h>
27#include <transport/THttpClient.h>
28#include <transport/TSSLSocket.h>
29#include <Thrift.h>
30
31// Evernote SDK
32#include <NoteStore.h>
33#include <NoteStore_constants.h>
34#include <UserStore.h>
35#include <UserStore_constants.h>
36#include <Errors_types.h>
37
38#include <QDebug>
39
40using namespace apache::thrift;
41using namespace apache::thrift::protocol;
42using namespace apache::thrift::transport;
43
44EvernoteConnection* EvernoteConnection::s_instance = 0;
45
46// FIXME: need to populate this string from the system
47// The structure should be:
48// application/version; platform/version; [ device/version ]
49// E.g. "Evernote Windows/3.0.1; Windows/XP SP3"
50QString EDAM_CLIENT_NAME = QStringLiteral("Reminders/0.1; Ubuntu/13.10");
51QString EVERNOTE_HOST = QStringLiteral("sandbox.evernote.com");
52QString EDAM_USER_STORE_PATH = QStringLiteral("/edam/user");
53QString EDAM_NOTE_STORE_PATH = QStringLiteral("/edam/note");
54
55EvernoteConnection::EvernoteConnection(QObject *parent) :
56 QObject(parent),
57 m_currentJob(0),
58 m_useSSL(true)
59{
60 setupUserStore();
61 setupNotesStore();
62}
63
64bool EvernoteConnection::setupUserStore()
65{
66 bool versionOK = false;
67 try {
68 boost::shared_ptr<TSocket> socket;
69
70 if (m_useSSL) {
71 boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory());
72 socket = sslSocketFactory->createSocket(EVERNOTE_HOST.toStdString(), 443);
73 qDebug() << "created UserStore SSL socket";
74 } else {
75 // Create a non-secure socket
76 socket = boost::shared_ptr<TSocket> (new TSocket(EVERNOTE_HOST.toStdString(), 80));
77 qDebug() << "created insecure UserStore socket";
78 }
79
80 boost::shared_ptr<TBufferedTransport> bufferedTransport(new TBufferedTransport(socket));
81 m_userStoreHttpClient = boost::shared_ptr<THttpClient>(new THttpClient(bufferedTransport,
82 EVERNOTE_HOST.toStdString(),
83 EDAM_USER_STORE_PATH.toStdString()));
84 m_userStoreHttpClient->open();
85 boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(m_userStoreHttpClient));
86 m_userstoreClient = new evernote::edam::UserStoreClient(iprot);
87 evernote::edam::UserStoreConstants constants;
88 versionOK = m_userstoreClient->checkVersion(EDAM_CLIENT_NAME.toStdString(),
89 constants.EDAM_VERSION_MAJOR,
90 constants.EDAM_VERSION_MINOR);
91 qDebug() << "UserStoreClient created. Version check:" << versionOK;
92
93 } catch (const TTransportException & e) {
94 qWarning() << "Failed to create Transport for UserStore:" << e.what();
95 } catch (const TException & e) {
96 qWarning() << "Generic Thrift exception in UserStore setup:" << e.what();
97 }
98 return versionOK;
99}
100
101bool EvernoteConnection::setupNotesStore()
102{
103 try {
104 boost::shared_ptr<TSocket> socket;
105
106 if (m_useSSL) {
107 boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory());
108 socket = sslSocketFactory->createSocket(EVERNOTE_HOST.toStdString(), 443);
109 qDebug() << "created NotesStore SSL socket";
110 } else {
111 // Create a non-secure socket
112 socket = boost::shared_ptr<TSocket> (new TSocket(EVERNOTE_HOST.toStdString(), 80));
113 qDebug() << "created insecure NotesStore socket";
114 }
115
116 // setup UserStore
117 boost::shared_ptr<TBufferedTransport> bufferedTransport(new TBufferedTransport(socket));
118 m_notesStoreHttpClient = boost::shared_ptr<THttpClient>(new THttpClient(bufferedTransport,
119 EVERNOTE_HOST.toStdString(),
120 EDAM_NOTE_STORE_PATH.toStdString()));
121 m_notesStoreHttpClient->open();
122 boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(m_notesStoreHttpClient));
123
124 // setup notesstore
125 m_notesStoreClient = new evernote::edam::NoteStoreClient(iprot);
126
127 qDebug() << "NoteStore client created.";
128
129 } catch (const TTransportException & e) {
130 qWarning() << "Failed to create Transport for NotesStore:" << e.what();
131 return false;
132 } catch (const TException & e) {
133 qWarning() << "Generic Thrift exception in NotesStore setup:" << e.what();
134 return false;
135 }
136 return true;
137}
138
139EvernoteConnection *EvernoteConnection::instance()
140{
141 if (!s_instance) {
142 s_instance = new EvernoteConnection();
143 }
144 return s_instance;
145}
146
147EvernoteConnection::~EvernoteConnection()
148{
149 delete m_notesStoreClient;
150}
151
152QString EvernoteConnection::token() const
153{
154 return m_token;
155}
156
157void EvernoteConnection::setToken(const QString &token)
158{
159 if (token != m_token) {
160 m_token = token;
161 emit tokenChanged();
162 }
163}
164
165void EvernoteConnection::enqueue(EvernoteJob *job)
166{
167 connect(job, &EvernoteJob::finished, this, &EvernoteConnection::startNextJob);
168
169 m_jobQueue.append(job);
170 startJobQueue();
171}
172
173void EvernoteConnection::startJobQueue()
174{
175 if (m_jobQueue.isEmpty()) {
176 return;
177 }
178
179 if (m_currentJob) {
180 return;
181 }
182 m_currentJob = m_jobQueue.takeFirst();
183 m_currentJob->start();
184}
185
186void EvernoteConnection::startNextJob()
187{
188 m_currentJob = 0;
189 startJobQueue();
190}
0191
=== added file 'src/plugin/Evernote/evernoteconnection.h'
--- src/plugin/Evernote/evernoteconnection.h 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/evernoteconnection.h 2013-11-28 00:46:50 +0000
@@ -0,0 +1,101 @@
1/*
2 * Copyright: 2013 Canonical, Ltd
3 *
4 * This file is part of reminders-app
5 *
6 * reminders-app is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * reminders-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
19 */
20
21#ifndef EVERNOTECONNECTION_H
22#define EVERNOTECONNECTION_H
23
24#include <boost/shared_ptr.hpp>
25
26// Thrift
27#include <transport/THttpClient.h>
28
29#include <QObject>
30
31namespace evernote {
32namespace edam {
33class NoteStoreClient;
34class UserStoreClient;
35}
36}
37
38using namespace apache::thrift::transport;
39
40class EvernoteJob;
41
42class EvernoteConnection : public QObject
43{
44 Q_OBJECT
45 Q_PROPERTY(QString token READ token WRITE setToken NOTIFY tokenChanged)
46
47 friend class NotesStoreJob;
48 friend class UserStoreJob;
49
50public:
51 enum ErrorCode {
52 ErrorCodeNoError,
53 ErrorCodeUserException,
54 ErrorCodeSystemException,
55 ErrorCodeNotFoundExcpetion,
56 ErrorCodeConnectionLost
57 };
58
59 static EvernoteConnection* instance();
60 ~EvernoteConnection();
61
62 QString token() const;
63 void setToken(const QString &token);
64
65 void enqueue(EvernoteJob *job);
66
67signals:
68 void tokenChanged();
69
70private slots:
71 void startJobQueue();
72 void startNextJob();
73
74private:
75 explicit EvernoteConnection(QObject *parent = 0);
76 static EvernoteConnection *s_instance;
77
78 bool setupUserStore();
79 bool setupNotesStore();
80
81 bool m_useSSL;
82
83 QString m_token;
84
85 // There must be only one job running at a time
86 // Do not start jobs other than with startJobQueue()
87 QList<EvernoteJob*> m_jobQueue;
88 EvernoteJob *m_currentJob;
89
90 // Those 4 are accessed from the job thread.
91 // Make sure to not access them while any jobs are running
92 // or we need to mutex them.
93 evernote::edam::NoteStoreClient *m_notesStoreClient;
94 boost::shared_ptr<THttpClient> m_notesStoreHttpClient;
95
96 evernote::edam::UserStoreClient *m_userstoreClient;
97 boost::shared_ptr<THttpClient> m_userStoreHttpClient;
98
99};
100
101#endif // EVERNOTECONNECTION_H
0102
=== modified file 'src/plugin/Evernote/evernoteplugin.cpp'
--- src/plugin/Evernote/evernoteplugin.cpp 2013-11-26 17:18:33 +0000
+++ src/plugin/Evernote/evernoteplugin.cpp 2013-11-28 00:46:50 +0000
@@ -20,6 +20,7 @@
2020
21#include "evernoteplugin.h"21#include "evernoteplugin.h"
2222
23#include "evernoteconnection.h"
23#include "userstore.h"24#include "userstore.h"
24#include "notesstore.h"25#include "notesstore.h"
25#include "notes.h"26#include "notes.h"
@@ -28,16 +29,27 @@
2829
29#include <QtQml>30#include <QtQml>
3031
32static QObject* userStoreProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
33{
34 return UserStore::instance();
35}
36
31static QObject* notesStoreProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)37static QObject* notesStoreProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
32{38{
33 return NotesStore::instance();39 return NotesStore::instance();
34}40}
3541
42static QObject* connectionProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
43{
44 return EvernoteConnection::instance();
45}
46
36void FitBitPlugin::registerTypes(const char *uri)47void FitBitPlugin::registerTypes(const char *uri)
37{48{
38 qmlRegisterType<UserStore>("Evernote", 0, 1, "UserStore");49 qmlRegisterSingletonType<UserStore>("Evernote", 0, 1, "UserStore", userStoreProvider);
39
40 qmlRegisterSingletonType<NotesStore>("Evernote", 0, 1, "NotesStore", notesStoreProvider);50 qmlRegisterSingletonType<NotesStore>("Evernote", 0, 1, "NotesStore", notesStoreProvider);
51 qmlRegisterSingletonType<EvernoteConnection>("Evernote", 0, 1, "EvernoteConnection", connectionProvider);
52
41 qmlRegisterType<Notes>("Evernote", 0, 1, "Notes");53 qmlRegisterType<Notes>("Evernote", 0, 1, "Notes");
42 qmlRegisterType<Notebooks>("Evernote", 0, 1, "Notebooks");54 qmlRegisterType<Notebooks>("Evernote", 0, 1, "Notebooks");
43 qmlRegisterUncreatableType<Note>("Evernote", 0, 1, "Note", "Cannot create Notes in QML. Use NotesStore.createNote() instead.");55 qmlRegisterUncreatableType<Note>("Evernote", 0, 1, "Note", "Cannot create Notes in QML. Use NotesStore.createNote() instead.");
4456
=== modified file 'src/plugin/Evernote/jobs/createnotejob.cpp'
--- src/plugin/Evernote/jobs/createnotejob.cpp 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/jobs/createnotejob.cpp 2013-11-28 00:46:50 +0000
@@ -23,7 +23,7 @@
23#include <QDebug>23#include <QDebug>
2424
25CreateNoteJob::CreateNoteJob(const QString &title, const QString &notebookGuid, const QString &content, QObject *parent) :25CreateNoteJob::CreateNoteJob(const QString &title, const QString &notebookGuid, const QString &content, QObject *parent) :
26 EvernoteJob(parent),26 NotesStoreJob(parent),
27 m_title(title),27 m_title(title),
28 m_notebookGuid(notebookGuid),28 m_notebookGuid(notebookGuid),
29 m_content(content)29 m_content(content)
@@ -45,7 +45,7 @@
45 client()->createNote(m_resultNote, token().toStdString(), input);45 client()->createNote(m_resultNote, token().toStdString(), input);
46}46}
4747
48void CreateNoteJob::emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage)48void CreateNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
49{49{
50 emit jobDone(errorCode, errorMessage, m_resultNote);50 emit jobDone(errorCode, errorMessage, m_resultNote);
51}51}
5252
=== modified file 'src/plugin/Evernote/jobs/createnotejob.h'
--- src/plugin/Evernote/jobs/createnotejob.h 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/jobs/createnotejob.h 2013-11-28 00:46:50 +0000
@@ -1,21 +1,20 @@
1#ifndef CREATENOTEJOB_H1#ifndef CREATENOTEJOB_H
2#define CREATENOTEJOB_H2#define CREATENOTEJOB_H
33
4#include "evernotejob.h"4#include "notesstorejob.h"
5#include "note.h"
65
7class CreateNoteJob : public EvernoteJob6class CreateNoteJob : public NotesStoreJob
8{7{
9 Q_OBJECT8 Q_OBJECT
10public:9public:
11 explicit CreateNoteJob(const QString &title, const QString &notebookGuid, const QString &content, QObject *parent = 0);10 explicit CreateNoteJob(const QString &title, const QString &notebookGuid, const QString &content, QObject *parent = 0);
1211
13signals:12signals:
14 void jobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, evernote::edam::Note note);13 void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, evernote::edam::Note note);
1514
16protected:15protected:
17 void startJob();16 void startJob();
18 void emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage);17 void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
1918
20private:19private:
21 QString m_title;20 QString m_title;
2221
=== modified file 'src/plugin/Evernote/jobs/deletenotejob.cpp'
--- src/plugin/Evernote/jobs/deletenotejob.cpp 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/jobs/deletenotejob.cpp 2013-11-28 00:46:50 +0000
@@ -21,7 +21,7 @@
21#include "deletenotejob.h"21#include "deletenotejob.h"
2222
23DeleteNoteJob::DeleteNoteJob(const QString &guid, QObject *parent):23DeleteNoteJob::DeleteNoteJob(const QString &guid, QObject *parent):
24 EvernoteJob(parent),24 NotesStoreJob(parent),
25 m_guid(guid)25 m_guid(guid)
26{26{
27}27}
@@ -31,7 +31,7 @@
31 client()->deleteNote(token().toStdString(), m_guid.toStdString());31 client()->deleteNote(token().toStdString(), m_guid.toStdString());
32}32}
3333
34void DeleteNoteJob::emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage)34void DeleteNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
35{35{
36 emit jobDone(errorCode, errorMessage, m_guid);36 emit jobDone(errorCode, errorMessage, m_guid);
37}37}
3838
=== modified file 'src/plugin/Evernote/jobs/deletenotejob.h'
--- src/plugin/Evernote/jobs/deletenotejob.h 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/jobs/deletenotejob.h 2013-11-28 00:46:50 +0000
@@ -1,20 +1,20 @@
1#ifndef DELETENOTEJOB_H1#ifndef DELETENOTEJOB_H
2#define DELETENOTEJOB_H2#define DELETENOTEJOB_H
33
4#include "evernotejob.h"4#include "notesstorejob.h"
55
6class DeleteNoteJob : public EvernoteJob6class DeleteNoteJob : public NotesStoreJob
7{7{
8 Q_OBJECT8 Q_OBJECT
9public:9public:
10 DeleteNoteJob(const QString &guid, QObject *parent = 0);10 DeleteNoteJob(const QString &guid, QObject *parent = 0);
1111
12signals:12signals:
13 void jobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, const QString &guid);13 void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid);
1414
15protected:15protected:
16 void startJob();16 void startJob();
17 void emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage);17 void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
1818
19private:19private:
20 QString m_guid;20 QString m_guid;
2121
=== modified file 'src/plugin/Evernote/jobs/evernotejob.cpp'
--- src/plugin/Evernote/jobs/evernotejob.cpp 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/jobs/evernotejob.cpp 2013-11-28 00:46:50 +0000
@@ -19,6 +19,7 @@
19 */19 */
2020
21#include "evernotejob.h"21#include "evernotejob.h"
22#include "evernoteconnection.h"
2223
23// Thrift24// Thrift
24#include <arpa/inet.h> // seems thrift forgot this one25#include <arpa/inet.h> // seems thrift forgot this one
@@ -35,10 +36,9 @@
3536
36EvernoteJob::EvernoteJob(QObject *parent) :37EvernoteJob::EvernoteJob(QObject *parent) :
37 QThread(parent),38 QThread(parent),
38 m_token(NotesStore::instance()->token())39 m_token(EvernoteConnection::instance()->token())
39{40{
40 connect(this, &EvernoteJob::finished, this, &EvernoteJob::deleteLater);41 connect(this, &EvernoteJob::finished, this, &EvernoteJob::deleteLater);
41 connect(this, &EvernoteJob::finished, NotesStore::instance(), &NotesStore::startNextJob);
42}42}
4343
44EvernoteJob::~EvernoteJob()44EvernoteJob::~EvernoteJob()
@@ -49,7 +49,7 @@
49{49{
50 if (m_token.isEmpty()) {50 if (m_token.isEmpty()) {
51 qWarning() << "No token set. Cannot execute job.";51 qWarning() << "No token set. Cannot execute job.";
52 emitJobDone(NotesStore::ErrorCodeUserException, QStringLiteral("No token set."));52 emitJobDone(EvernoteConnection::ErrorCodeUserException, QStringLiteral("No token set."));
53 return;53 return;
54 }54 }
5555
@@ -62,36 +62,29 @@
62 // so lets try to start the job once more.62 // so lets try to start the job once more.
63 qWarning() << "Got a transport exception:" << e.what() << ". Trying to reestablish connection...";63 qWarning() << "Got a transport exception:" << e.what() << ". Trying to reestablish connection...";
64 try {64 try {
65 NotesStore::instance()->m_httpClient->close();65 resetConnection();
66 NotesStore::instance()->m_httpClient->open();
67
68 startJob();66 startJob();
69 } catch (const TTransportException &e) {67 } catch (const TTransportException &e) {
70 // Giving up... the connection seems to be down for real.68 // Giving up... the connection seems to be down for real.
71 qWarning() << "Cannot reestablish connection:" << e.what();69 qWarning() << "Cannot reestablish connection:" << e.what();
72 emitJobDone(NotesStore::ErrorCodeConnectionLost, e.what());70 emitJobDone(EvernoteConnection::ErrorCodeConnectionLost, e.what());
73 } catch (const evernote::edam::EDAMUserException &e) {71 } catch (const evernote::edam::EDAMUserException &e) {
74 emitJobDone(NotesStore::ErrorCodeUserException, e.what());72 emitJobDone(EvernoteConnection::ErrorCodeUserException, e.what());
75 } catch (const evernote::edam::EDAMSystemException &e) {73 } catch (const evernote::edam::EDAMSystemException &e) {
76 emitJobDone(NotesStore::ErrorCodeSystemException, e.what());74 emitJobDone(EvernoteConnection::ErrorCodeSystemException, e.what());
77 } catch (const evernote::edam::EDAMNotFoundException &e) {75 } catch (const evernote::edam::EDAMNotFoundException &e) {
78 emitJobDone(NotesStore::ErrorCodeNotFoundExcpetion, e.what());76 emitJobDone(EvernoteConnection::ErrorCodeNotFoundExcpetion, e.what());
79 }77 }
8078
81 } catch (const evernote::edam::EDAMUserException &e) {79 } catch (const evernote::edam::EDAMUserException &e) {
82 emitJobDone(NotesStore::ErrorCodeUserException, e.what());80 emitJobDone(EvernoteConnection::ErrorCodeUserException, e.what());
83 } catch (const evernote::edam::EDAMSystemException &e) {81 } catch (const evernote::edam::EDAMSystemException &e) {
84 emitJobDone(NotesStore::ErrorCodeSystemException, e.what());82 emitJobDone(EvernoteConnection::ErrorCodeSystemException, e.what());
85 } catch (const evernote::edam::EDAMNotFoundException &e) {83 } catch (const evernote::edam::EDAMNotFoundException &e) {
86 emitJobDone(NotesStore::ErrorCodeNotFoundExcpetion, e.what());84 emitJobDone(EvernoteConnection::ErrorCodeNotFoundExcpetion, e.what());
87 }85 }
8886
89 emitJobDone(NotesStore::ErrorCodeNoError, QString());87 emitJobDone(EvernoteConnection::ErrorCodeNoError, QString());
90}
91
92evernote::edam::NoteStoreClient *EvernoteJob::client()
93{
94 return NotesStore::instance()->m_client;
95}88}
9689
97QString EvernoteJob::token()90QString EvernoteJob::token()
9891
=== modified file 'src/plugin/Evernote/jobs/evernotejob.h'
--- src/plugin/Evernote/jobs/evernotejob.h 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/jobs/evernotejob.h 2013-11-28 00:46:50 +0000
@@ -3,11 +3,6 @@
33
4#include "notesstore.h"4#include "notesstore.h"
55
6// Evernote SDK
7#include <NoteStore.h>
8#include <NoteStore_constants.h>
9#include <Errors_types.h>
10
11#include <QThread>6#include <QThread>
127
13/* How to create a new Job type:8/* How to create a new Job type:
@@ -15,7 +10,7 @@
15 * - Implement startJob() in which you do the call to evernote.10 * - Implement startJob() in which you do the call to evernote.
16 * - No need to catch exceptions, EvernoteJob will deal with those.11 * - No need to catch exceptions, EvernoteJob will deal with those.
17 * - Define a jobDone() signal with the result parameters you need.12 * - Define a jobDone() signal with the result parameters you need.
18 * - Keep the convention of jobDone(NotesStore::ErrorCode errorCode, const QString &message [, ...])13 * - Keep the convention of jobDone(EvernoteConnection::ErrorCode errorCode, const QString &message [, ...])
19 * - Emit jobDone() in your implementation of emitJobDone().14 * - Emit jobDone() in your implementation of emitJobDone().
20 * - NOTE: emitJobDone() might be called with an error even before startJob() is triggered.15 * - NOTE: emitJobDone() might be called with an error even before startJob() is triggered.
21 *16 *
@@ -36,10 +31,10 @@
36 void connectionLost(const QString &errorMessage);31 void connectionLost(const QString &errorMessage);
3732
38protected:33protected:
34 virtual void resetConnection() = 0;
39 virtual void startJob() = 0;35 virtual void startJob() = 0;
40 virtual void emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage) = 0;36 virtual void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) = 0;
4137
42 evernote::edam::NoteStoreClient* client();
43 QString token();38 QString token();
4439
45private:40private:
4641
=== modified file 'src/plugin/Evernote/jobs/fetchnotebooksjob.cpp'
--- src/plugin/Evernote/jobs/fetchnotebooksjob.cpp 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/jobs/fetchnotebooksjob.cpp 2013-11-28 00:46:50 +0000
@@ -23,7 +23,7 @@
23#include <QDebug>23#include <QDebug>
2424
25FetchNotebooksJob::FetchNotebooksJob(QObject *parent) :25FetchNotebooksJob::FetchNotebooksJob(QObject *parent) :
26 EvernoteJob(parent)26 NotesStoreJob(parent)
27{27{
28}28}
2929
@@ -33,7 +33,7 @@
33 client()->listNotebooks(m_results, token().toStdString());33 client()->listNotebooks(m_results, token().toStdString());
34}34}
3535
36void FetchNotebooksJob::emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage)36void FetchNotebooksJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
37{37{
38 emit jobDone(errorCode, errorMessage, m_results);38 emit jobDone(errorCode, errorMessage, m_results);
39}39}
4040
=== modified file 'src/plugin/Evernote/jobs/fetchnotebooksjob.h'
--- src/plugin/Evernote/jobs/fetchnotebooksjob.h 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/jobs/fetchnotebooksjob.h 2013-11-28 00:46:50 +0000
@@ -1,20 +1,20 @@
1#ifndef FETCHNOTEBOOKSJOB_H1#ifndef FETCHNOTEBOOKSJOB_H
2#define FETCHNOTEBOOKSJOB_H2#define FETCHNOTEBOOKSJOB_H
33
4#include "evernotejob.h"4#include "notesstorejob.h"
55
6class FetchNotebooksJob : public EvernoteJob6class FetchNotebooksJob : public NotesStoreJob
7{7{
8 Q_OBJECT8 Q_OBJECT
9public:9public:
10 explicit FetchNotebooksJob(QObject *parent = 0);10 explicit FetchNotebooksJob(QObject *parent = 0);
1111
12signals:12signals:
13 void jobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results);13 void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results);
1414
15protected:15protected:
16 void startJob();16 void startJob();
17 void emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage);17 void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
1818
19private:19private:
20 std::vector<evernote::edam::Notebook> m_results;20 std::vector<evernote::edam::Notebook> m_results;
2121
=== modified file 'src/plugin/Evernote/jobs/fetchnotejob.cpp'
--- src/plugin/Evernote/jobs/fetchnotejob.cpp 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/jobs/fetchnotejob.cpp 2013-11-28 00:46:50 +0000
@@ -21,7 +21,7 @@
21#include "fetchnotejob.h"21#include "fetchnotejob.h"
2222
23FetchNoteJob::FetchNoteJob(const QString &guid, QObject *parent) :23FetchNoteJob::FetchNoteJob(const QString &guid, QObject *parent) :
24 EvernoteJob(parent),24 NotesStoreJob(parent),
25 m_guid(guid)25 m_guid(guid)
26{26{
27}27}
@@ -31,7 +31,7 @@
31 client()->getNote(m_result, token().toStdString(), m_guid.toStdString(), true, true, false, false);31 client()->getNote(m_result, token().toStdString(), m_guid.toStdString(), true, true, false, false);
32}32}
3333
34void FetchNoteJob::emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage)34void FetchNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
35{35{
36 emit resultReady(errorCode, errorMessage, m_result);36 emit resultReady(errorCode, errorMessage, m_result);
37}37}
3838
=== modified file 'src/plugin/Evernote/jobs/fetchnotejob.h'
--- src/plugin/Evernote/jobs/fetchnotejob.h 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/jobs/fetchnotejob.h 2013-11-28 00:46:50 +0000
@@ -1,20 +1,20 @@
1#ifndef FETCHNOTEJOB_H1#ifndef FETCHNOTEJOB_H
2#define FETCHNOTEJOB_H2#define FETCHNOTEJOB_H
33
4#include "evernotejob.h"4#include "notesstorejob.h"
55
6class FetchNoteJob : public EvernoteJob6class FetchNoteJob : public NotesStoreJob
7{7{
8 Q_OBJECT8 Q_OBJECT
9public:9public:
10 explicit FetchNoteJob(const QString &guid, QObject *parent = 0);10 explicit FetchNoteJob(const QString &guid, QObject *parent = 0);
1111
12signals:12signals:
13 void resultReady(NotesStore::ErrorCode error, const QString &errorMessage, const evernote::edam::Note &note);13 void resultReady(EvernoteConnection::ErrorCode error, const QString &errorMessage, const evernote::edam::Note &note);
1414
15protected:15protected:
16 void startJob();16 void startJob();
17 void emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage);17 void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
1818
19private:19private:
20 evernote::edam::NoteStoreClient *m_client;20 evernote::edam::NoteStoreClient *m_client;
2121
=== modified file 'src/plugin/Evernote/jobs/fetchnotesjob.cpp'
--- src/plugin/Evernote/jobs/fetchnotesjob.cpp 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/jobs/fetchnotesjob.cpp 2013-11-28 00:46:50 +0000
@@ -25,13 +25,14 @@
25#include <QDebug>25#include <QDebug>
2626
27FetchNotesJob::FetchNotesJob( const QString &filterNotebookGuid, QObject *parent) :27FetchNotesJob::FetchNotesJob( const QString &filterNotebookGuid, QObject *parent) :
28 EvernoteJob(parent),28 NotesStoreJob(parent),
29 m_filterNotebookGuid(filterNotebookGuid)29 m_filterNotebookGuid(filterNotebookGuid)
30{30{
31}31}
3232
33void FetchNotesJob::startJob()33void FetchNotesJob::startJob()
34{34{
35 qDebug() << "starting fetch notes job";
35 // TODO: fix start/end (use smaller chunks and continue fetching if there are more notes available)36 // TODO: fix start/end (use smaller chunks and continue fetching if there are more notes available)
36 int32_t start = 0;37 int32_t start = 0;
37 int32_t end = 10000;38 int32_t end = 10000;
@@ -49,9 +50,10 @@
49 resultSpec.__isset.includeTitle = true;50 resultSpec.__isset.includeTitle = true;
5051
51 client()->findNotesMetadata(m_results, token().toStdString(), filter, start, end, resultSpec);52 client()->findNotesMetadata(m_results, token().toStdString(), filter, start, end, resultSpec);
53 qDebug() << "ending fetch notes job";
52}54}
5355
54void FetchNotesJob::emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage)56void FetchNotesJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
55{57{
56 emit jobDone(errorCode, errorMessage, m_results);58 emit jobDone(errorCode, errorMessage, m_results);
57}59}
5860
=== modified file 'src/plugin/Evernote/jobs/fetchnotesjob.h'
--- src/plugin/Evernote/jobs/fetchnotesjob.h 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/jobs/fetchnotesjob.h 2013-11-28 00:46:50 +0000
@@ -1,20 +1,20 @@
1#ifndef FETCHNOTESJOB_H1#ifndef FETCHNOTESJOB_H
2#define FETCHNOTESJOB_H2#define FETCHNOTESJOB_H
33
4#include "evernotejob.h"4#include "notesstorejob.h"
55
6class FetchNotesJob : public EvernoteJob6class FetchNotesJob : public NotesStoreJob
7{7{
8 Q_OBJECT8 Q_OBJECT
9public:9public:
10 explicit FetchNotesJob(const QString &filterNotebookGuid, QObject *parent = 0);10 explicit FetchNotesJob(const QString &filterNotebookGuid, QObject *parent = 0);
1111
12signals:12signals:
13 void jobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results);13 void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results);
1414
15protected:15protected:
16 void startJob();16 void startJob();
17 void emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage);17 void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
1818
19private:19private:
20 QString m_filterNotebookGuid;20 QString m_filterNotebookGuid;
2121
=== added file 'src/plugin/Evernote/jobs/fetchusernamejob.cpp'
--- src/plugin/Evernote/jobs/fetchusernamejob.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/fetchusernamejob.cpp 2013-11-28 00:46:50 +0000
@@ -0,0 +1,38 @@
1/*
2 * Copyright: 2013 Canonical, Ltd
3 *
4 * This file is part of reminders-app
5 *
6 * reminders-app is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * reminders-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
19 */
20
21#include "fetchusernamejob.h"
22
23FetchUsernameJob::FetchUsernameJob(QObject *parent) :
24 UserStoreJob(parent)
25{
26}
27
28void FetchUsernameJob::startJob()
29{
30 evernote::edam::User user;
31 client()->getUser(user, token().toStdString());
32 m_result = QString::fromStdString(user.username);
33}
34
35void FetchUsernameJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
36{
37 emit jobDone(errorCode, errorMessage, m_result);
38}
039
=== added file 'src/plugin/Evernote/jobs/fetchusernamejob.h'
--- src/plugin/Evernote/jobs/fetchusernamejob.h 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/fetchusernamejob.h 2013-11-28 00:46:50 +0000
@@ -0,0 +1,43 @@
1/*
2 * Copyright: 2013 Canonical, Ltd
3 *
4 * This file is part of reminders-app
5 *
6 * reminders-app is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * reminders-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
19 */
20
21#ifndef FETCHUSERNAMEJOB_H
22#define FETCHUSERNAMEJOB_H
23
24#include "userstorejob.h"
25
26class FetchUsernameJob : public UserStoreJob
27{
28 Q_OBJECT
29public:
30 explicit FetchUsernameJob(QObject *parent = 0);
31
32signals:
33 void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result);
34
35protected:
36 void startJob();
37 void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
38
39private:
40 QString m_result;
41};
42
43#endif // FETCHUSERNAMEJOB_H
044
=== added file 'src/plugin/Evernote/jobs/notesstorejob.cpp'
--- src/plugin/Evernote/jobs/notesstorejob.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/notesstorejob.cpp 2013-11-28 00:46:50 +0000
@@ -0,0 +1,39 @@
1/*
2 * Copyright: 2013 Canonical, Ltd
3 *
4 * This file is part of reminders-app
5 *
6 * reminders-app is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * reminders-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
19 */
20
21#include "notesstorejob.h"
22
23#include "evernoteconnection.h"
24
25NotesStoreJob::NotesStoreJob(QObject *parent) :
26 EvernoteJob(parent)
27{
28}
29
30void NotesStoreJob::resetConnection()
31{
32 EvernoteConnection::instance()->m_notesStoreHttpClient->close();
33 EvernoteConnection::instance()->m_notesStoreHttpClient->open();
34}
35
36evernote::edam::NoteStoreClient *NotesStoreJob::client() const
37{
38 return EvernoteConnection::instance()->m_notesStoreClient;
39}
040
=== added file 'src/plugin/Evernote/jobs/notesstorejob.h'
--- src/plugin/Evernote/jobs/notesstorejob.h 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/notesstorejob.h 2013-11-28 00:46:50 +0000
@@ -0,0 +1,44 @@
1/*
2 * Copyright: 2013 Canonical, Ltd
3 *
4 * This file is part of reminders-app
5 *
6 * reminders-app is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * reminders-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
19 */
20
21#ifndef NOTESSTOREJOB_H
22#define NOTESSTOREJOB_H
23
24#include "evernotejob.h"
25
26// Evernote SDK
27#include <NoteStore.h>
28#include <NoteStore_constants.h>
29#include <Errors_types.h>
30
31class NotesStoreJob : public EvernoteJob
32{
33 Q_OBJECT
34public:
35 explicit NotesStoreJob(QObject *parent = 0);
36
37protected:
38 void resetConnection() final;
39
40 evernote::edam::NoteStoreClient *client() const;
41
42};
43
44#endif // NOTESSTOREJOB_H
045
=== modified file 'src/plugin/Evernote/jobs/savenotejob.cpp'
--- src/plugin/Evernote/jobs/savenotejob.cpp 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/jobs/savenotejob.cpp 2013-11-28 00:46:50 +0000
@@ -24,7 +24,7 @@
24#include <QDebug>24#include <QDebug>
2525
26SaveNoteJob::SaveNoteJob(Note *note, QObject *parent) :26SaveNoteJob::SaveNoteJob(Note *note, QObject *parent) :
27 EvernoteJob(parent),27 NotesStoreJob(parent),
28 m_guid(note->guid()),28 m_guid(note->guid()),
29 m_title(note->title()),29 m_title(note->title()),
30 m_notebookGuid(note->notebookGuid()),30 m_notebookGuid(note->notebookGuid()),
@@ -48,7 +48,7 @@
48 client()->updateNote(m_note, token().toStdString(), note);48 client()->updateNote(m_note, token().toStdString(), note);
49}49}
5050
51void SaveNoteJob::emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage)51void SaveNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
52{52{
53 emit jobDone(errorCode, errorMessage, m_note);53 emit jobDone(errorCode, errorMessage, m_note);
54}54}
5555
=== modified file 'src/plugin/Evernote/jobs/savenotejob.h'
--- src/plugin/Evernote/jobs/savenotejob.h 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/jobs/savenotejob.h 2013-11-28 00:46:50 +0000
@@ -1,20 +1,20 @@
1#ifndef SAVENOTEJOB_H1#ifndef SAVENOTEJOB_H
2#define SAVENOTEJOB_H2#define SAVENOTEJOB_H
33
4#include "evernotejob.h"4#include "notesstorejob.h"
55
6class SaveNoteJob : public EvernoteJob6class SaveNoteJob : public NotesStoreJob
7{7{
8 Q_OBJECT8 Q_OBJECT
9public:9public:
10 explicit SaveNoteJob(Note *note, QObject *parent = 0);10 explicit SaveNoteJob(Note *note, QObject *parent = 0);
1111
12signals:12signals:
13 void jobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &note);13 void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &note);
1414
15protected:15protected:
16 void startJob();16 void startJob();
17 void emitJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage);17 void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
1818
19private:19private:
20 QString m_guid;20 QString m_guid;
2121
=== added file 'src/plugin/Evernote/jobs/userstorejob.cpp'
--- src/plugin/Evernote/jobs/userstorejob.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/userstorejob.cpp 2013-11-28 00:46:50 +0000
@@ -0,0 +1,39 @@
1/*
2 * Copyright: 2013 Canonical, Ltd
3 *
4 * This file is part of reminders-app
5 *
6 * reminders-app is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * reminders-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
19 */
20
21#include "userstorejob.h"
22
23#include "evernoteconnection.h"
24
25UserStoreJob::UserStoreJob(QObject *parent) :
26 EvernoteJob(parent)
27{
28}
29
30void UserStoreJob::resetConnection()
31{
32 EvernoteConnection::instance()->m_userStoreHttpClient->close();
33 EvernoteConnection::instance()->m_userStoreHttpClient->open();
34}
35
36evernote::edam::UserStoreClient *UserStoreJob::client() const
37{
38 return EvernoteConnection::instance()->m_userstoreClient;
39}
040
=== added file 'src/plugin/Evernote/jobs/userstorejob.h'
--- src/plugin/Evernote/jobs/userstorejob.h 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/userstorejob.h 2013-11-28 00:46:50 +0000
@@ -0,0 +1,46 @@
1/*
2 * Copyright: 2013 Canonical, Ltd
3 *
4 * This file is part of reminders-app
5 *
6 * reminders-app is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * reminders-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
19 */
20
21#ifndef USERSTOREJOB_H
22#define USERSTOREJOB_H
23
24#include "evernotejob.h"
25
26// Evernote SDK
27#include <UserStore.h>
28#include <UserStore_constants.h>
29#include <Errors_types.h>
30
31class UserStoreJob : public EvernoteJob
32{
33 Q_OBJECT
34public:
35 explicit UserStoreJob(QObject *parent = 0);
36
37protected:
38 void resetConnection() final;
39
40 evernote::edam::UserStoreClient* client() const;
41
42public slots:
43
44};
45
46#endif // USERSTOREJOB_H
047
=== modified file 'src/plugin/Evernote/notesstore.cpp'
--- src/plugin/Evernote/notesstore.cpp 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/notesstore.cpp 2013-11-28 00:46:50 +0000
@@ -19,6 +19,7 @@
19 */19 */
2020
21#include "notesstore.h"21#include "notesstore.h"
22#include "evernoteconnection.h"
22#include "notebooks.h"23#include "notebooks.h"
23#include "notebook.h"24#include "notebook.h"
24#include "note.h"25#include "note.h"
@@ -31,69 +32,17 @@
31#include "jobs/savenotejob.h"32#include "jobs/savenotejob.h"
32#include "jobs/deletenotejob.h"33#include "jobs/deletenotejob.h"
3334
34// Thrift
35#include <arpa/inet.h> // seems thrift forgot this one
36#include <protocol/TBinaryProtocol.h>
37#include <transport/THttpClient.h>
38#include <transport/TSSLSocket.h>
39#include <Thrift.h>
40
41#include <QDebug>35#include <QDebug>
4236
43using namespace apache::thrift;
44using namespace apache::thrift::protocol;
45using namespace apache::thrift::transport;
46
47NotesStore* NotesStore::s_instance = 0;37NotesStore* NotesStore::s_instance = 0;
4838
49NotesStore::NotesStore(QObject *parent) :39NotesStore::NotesStore(QObject *parent) :
50 QObject(parent),40 QObject(parent)
51 m_currentJob(0)
52{41{
53 try {42 connect(EvernoteConnection::instance(), &EvernoteConnection::tokenChanged, this, &NotesStore::refreshNotebooks);
54 // FIXME: need to populate this string from the system43 connect(EvernoteConnection::instance(), SIGNAL(tokenChanged()), this, SLOT(refreshNotes()));
55 // The structure should be:44
56 // application/version; platform/version; [ device/version ]45 qRegisterMetaType<EvernoteConnection::ErrorCode>("EvernoteConnection::ErrorCode");
57 // E.g. "Evernote Windows/3.0.1; Windows/XP SP3"
58 QString EDAM_CLIENT_NAME = QStringLiteral("Reminders/0.1; Ubuntu/13.10");
59 QString EVERNOTE_HOST = QStringLiteral("sandbox.evernote.com");
60 QString EDAM_USER_STORE_PATH = QStringLiteral("/edam/note");
61 boost::shared_ptr<TSocket> socket;
62 bool use_SSL = true;
63
64 if (use_SSL) {
65 // Create an SSL socket
66 // FIXME: this fails with the following error:
67 // Thrift: Fri Nov 15 12:47:31 2013 SSL_shutdown: error code: 0
68 // SSL_get_verify_result(), unable to get local issuer certificate
69 // Additionally, the UI blocks and does not load for about 2 minutes
70 boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory());
71 socket = sslSocketFactory->createSocket(EVERNOTE_HOST.toStdString(), 443);
72 qDebug() << "created SSL socket";
73 } else {
74 // Create a non-secure socket
75 socket = boost::shared_ptr<TSocket> (new TSocket(EVERNOTE_HOST.toStdString(), 80));
76 qDebug() << "created insecure socket";
77 }
78
79 boost::shared_ptr<TBufferedTransport> bufferedTransport(new TBufferedTransport(socket));
80 m_httpClient = boost::shared_ptr<THttpClient>(new THttpClient(bufferedTransport,
81 EVERNOTE_HOST.toStdString(),
82 EDAM_USER_STORE_PATH.toStdString()));
83 m_httpClient->open();
84
85 boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(m_httpClient));
86 m_client = new evernote::edam::NoteStoreClient(iprot);
87
88 qDebug() << "NoteStore client created.";
89
90 } catch (const TTransportException & e) {
91 qWarning() << "Failed to create Transport:" << e.what();
92 } catch (const TException & e) {
93 qWarning() << "Generic Thrift exception:" << e.what();
94 }
95
96 qRegisterMetaType<NotesStore::ErrorCode>("NotesStore::ErrorCode");
97 qRegisterMetaType<evernote::edam::NotesMetadataList>("evernote::edam::NotesMetadataList");46 qRegisterMetaType<evernote::edam::NotesMetadataList>("evernote::edam::NotesMetadataList");
98 qRegisterMetaType<evernote::edam::Note>("evernote::edam::Note");47 qRegisterMetaType<evernote::edam::Note>("evernote::edam::Note");
99 qRegisterMetaType<std::vector<evernote::edam::Notebook> >("std::vector<evernote::edam::Notebook>");48 qRegisterMetaType<std::vector<evernote::edam::Notebook> >("std::vector<evernote::edam::Notebook>");
@@ -108,39 +57,8 @@
108 return s_instance;57 return s_instance;
109}58}
11059
111QString NotesStore::errorCodeToString(NotesStore::ErrorCode errorCode)
112{
113 switch(errorCode) {
114 case ErrorCodeNoError:
115 return QStringLiteral("No error");
116 case ErrorCodeUserException:
117 return QStringLiteral("User exception");
118 case ErrorCodeSystemException:
119 return QStringLiteral("System exception");
120 case ErrorCodeNotFoundExcpetion:
121 return QStringLiteral("Not found");
122 }
123 return QString();
124}
125
126NotesStore::~NotesStore()60NotesStore::~NotesStore()
127{61{
128 delete m_client;
129}
130
131QString NotesStore::token() const
132{
133 return m_token;
134}
135
136void NotesStore::setToken(const QString &token)
137{
138 if (token != m_token) {
139 m_token = token;
140 emit tokenChanged();
141 refreshNotebooks();
142 refreshNotes();
143 }
144}62}
14563
146QList<Note*> NotesStore::notes() const64QList<Note*> NotesStore::notes() const
@@ -163,41 +81,16 @@
163 return m_notebooks.value(guid);81 return m_notebooks.value(guid);
164}82}
16583
166void NotesStore::enqueue(EvernoteJob *job)
167{
168 m_jobQueue.append(job);
169 startJobQueue();
170}
171
172void NotesStore::startJobQueue()
173{
174 if (m_jobQueue.isEmpty()) {
175 return;
176 }
177
178 if (m_currentJob) {
179 return;
180 }
181 m_currentJob = m_jobQueue.takeFirst();
182 m_currentJob->start();
183}
184
185void NotesStore::startNextJob()
186{
187 m_currentJob = 0;
188 startJobQueue();
189}
190
191void NotesStore::refreshNotes(const QString &filterNotebookGuid)84void NotesStore::refreshNotes(const QString &filterNotebookGuid)
192{85{
193 FetchNotesJob *job = new FetchNotesJob(filterNotebookGuid);86 FetchNotesJob *job = new FetchNotesJob(filterNotebookGuid);
194 connect(job, &FetchNotesJob::jobDone, this, &NotesStore::fetchNotesJobDone);87 connect(job, &FetchNotesJob::jobDone, this, &NotesStore::fetchNotesJobDone);
195 enqueue(job);88 EvernoteConnection::instance()->enqueue(job);
196}89}
19790
198void NotesStore::fetchNotesJobDone(ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results)91void NotesStore::fetchNotesJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results)
199{92{
200 if (errorCode != ErrorCodeNoError) {93 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
201 qWarning() << "Failed to fetch notes list:" << errorMessage;94 qWarning() << "Failed to fetch notes list:" << errorMessage;
202 return;95 return;
203 }96 }
@@ -223,12 +116,12 @@
223{116{
224 FetchNoteJob *job = new FetchNoteJob(guid, this);117 FetchNoteJob *job = new FetchNoteJob(guid, this);
225 connect(job, &FetchNoteJob::resultReady, this, &NotesStore::fetchNoteJobDone);118 connect(job, &FetchNoteJob::resultReady, this, &NotesStore::fetchNoteJobDone);
226 enqueue(job);119 EvernoteConnection::instance()->enqueue(job);
227}120}
228121
229void NotesStore::fetchNoteJobDone(ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result)122void NotesStore::fetchNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result)
230{123{
231 if (errorCode != ErrorCodeNoError) {124 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
232 qWarning() << "Error fetching note:" << errorMessage;125 qWarning() << "Error fetching note:" << errorMessage;
233 return;126 return;
234 }127 }
@@ -244,12 +137,12 @@
244{137{
245 FetchNotebooksJob *job = new FetchNotebooksJob();138 FetchNotebooksJob *job = new FetchNotebooksJob();
246 connect(job, &FetchNotebooksJob::jobDone, this, &NotesStore::fetchNotebooksJobDone);139 connect(job, &FetchNotebooksJob::jobDone, this, &NotesStore::fetchNotebooksJobDone);
247 enqueue(job);140 EvernoteConnection::instance()->enqueue(job);
248}141}
249142
250void NotesStore::fetchNotebooksJobDone(ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results)143void NotesStore::fetchNotebooksJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results)
251{144{
252 if (errorCode != ErrorCodeNoError) {145 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
253 qWarning() << "Error fetching notebooks:" << errorMessage;146 qWarning() << "Error fetching notebooks:" << errorMessage;
254 return;147 return;
255 }148 }
@@ -275,12 +168,12 @@
275{168{
276 CreateNoteJob *job = new CreateNoteJob(title, notebookGuid, content);169 CreateNoteJob *job = new CreateNoteJob(title, notebookGuid, content);
277 connect(job, &CreateNoteJob::jobDone, this, &NotesStore::createNoteJobDone);170 connect(job, &CreateNoteJob::jobDone, this, &NotesStore::createNoteJobDone);
278 enqueue(job);171 EvernoteConnection::instance()->enqueue(job);
279}172}
280173
281void NotesStore::createNoteJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result)174void NotesStore::createNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result)
282{175{
283 if (errorCode != ErrorCodeNoError) {176 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
284 qWarning() << "Error creating note:" << errorMessage;177 qWarning() << "Error creating note:" << errorMessage;
285 return;178 return;
286 }179 }
@@ -303,12 +196,12 @@
303196
304 SaveNoteJob *job = new SaveNoteJob(note, this);197 SaveNoteJob *job = new SaveNoteJob(note, this);
305 connect(job, &SaveNoteJob::jobDone, this, &NotesStore::saveNoteJobDone);198 connect(job, &SaveNoteJob::jobDone, this, &NotesStore::saveNoteJobDone);
306 enqueue(job);199 EvernoteConnection::instance()->enqueue(job);
307}200}
308201
309void NotesStore::saveNoteJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result)202void NotesStore::saveNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result)
310{203{
311 if (errorCode != ErrorCodeNoError) {204 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
312 qWarning() << "error saving note" << errorMessage;205 qWarning() << "error saving note" << errorMessage;
313 return;206 return;
314 }207 }
@@ -326,12 +219,12 @@
326{219{
327 DeleteNoteJob *job = new DeleteNoteJob(guid, this);220 DeleteNoteJob *job = new DeleteNoteJob(guid, this);
328 connect(job, &DeleteNoteJob::jobDone, this, &NotesStore::deleteNoteJobDone);221 connect(job, &DeleteNoteJob::jobDone, this, &NotesStore::deleteNoteJobDone);
329 enqueue(job);222 EvernoteConnection::instance()->enqueue(job);
330}223}
331224
332void NotesStore::deleteNoteJobDone(NotesStore::ErrorCode errorCode, const QString &errorMessage, const QString &guid)225void NotesStore::deleteNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid)
333{226{
334 if (errorCode != ErrorCodeNoError) {227 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
335 qWarning() << "Cannot delete note:" << errorMessage;228 qWarning() << "Cannot delete note:" << errorMessage;
336 return;229 return;
337 }230 }
338231
=== modified file 'src/plugin/Evernote/notesstore.h'
--- src/plugin/Evernote/notesstore.h 2013-11-28 00:46:50 +0000
+++ src/plugin/Evernote/notesstore.h 2013-11-28 00:46:50 +0000
@@ -1,8 +1,14 @@
1#ifndef NOTESSTORE_H1#ifndef NOTESSTORE_H
2#define NOTESSTORE_H2#define NOTESSTORE_H
33
4#include "evernoteconnection.h"
5
4// Thrift6// Thrift
7#include <arpa/inet.h> // seems thrift forgot this one
8#include <protocol/TBinaryProtocol.h>
5#include <transport/THttpClient.h>9#include <transport/THttpClient.h>
10#include <transport/TSSLSocket.h>
11#include <Thrift.h>
612
7// Evernote SDK13// Evernote SDK
8#include <NoteStore.h>14#include <NoteStore.h>
@@ -12,8 +18,6 @@
12#include <QObject>18#include <QObject>
13#include <QHash>19#include <QHash>
1420
15class EvernoteJob;
16
17class Notebook;21class Notebook;
18class Note;22class Note;
1923
@@ -22,29 +26,14 @@
22class NotesStore : public QObject26class NotesStore : public QObject
23{27{
24 Q_OBJECT28 Q_OBJECT
25 Q_PROPERTY(QString token READ token WRITE setToken NOTIFY tokenChanged)
26
27 friend class EvernoteJob;
2829
29public:30public:
30 enum ErrorCode {
31 ErrorCodeNoError,
32 ErrorCodeUserException,
33 ErrorCodeSystemException,
34 ErrorCodeNotFoundExcpetion,
35 ErrorCodeConnectionLost
36 };
37
38 Q_INVOKABLE void createNote(const QString &title, const QString &notebookGuid, const QString &content);31 Q_INVOKABLE void createNote(const QString &title, const QString &notebookGuid, const QString &content);
3932
40 static NotesStore *instance();33 static NotesStore *instance();
41 static QString errorCodeToString(ErrorCode errorCode);
4234
43 ~NotesStore();35 ~NotesStore();
4436
45 QString token() const;
46 void setToken(const QString &token);
47
48 QList<Note*> notes() const;37 QList<Note*> notes() const;
49 Note* note(const QString &guid);38 Note* note(const QString &guid);
50 void saveNote(const QString &guid);39 void saveNote(const QString &guid);
@@ -53,6 +42,7 @@
53 QList<Notebook*> notebooks() const;42 QList<Notebook*> notebooks() const;
54 Notebook* notebook(const QString &guid);43 Notebook* notebook(const QString &guid);
5544
45public slots:
56 void refreshNotes(const QString &filterNotebookGuid = QString());46 void refreshNotes(const QString &filterNotebookGuid = QString());
57 void refreshNoteContent(const QString &guid);47 void refreshNoteContent(const QString &guid);
58 void refreshNotebooks();48 void refreshNotebooks();
@@ -68,41 +58,20 @@
68 void notebookChanged(const QString &guid);58 void notebookChanged(const QString &guid);
6959
70private slots:60private slots:
71 void fetchNotesJobDone(ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results);61 void fetchNotesJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::NotesMetadataList &results);
72 void fetchNotebooksJobDone(ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results);62 void fetchNotebooksJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const std::vector<evernote::edam::Notebook> &results);
73 void fetchNoteJobDone(ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);63 void fetchNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);
74 void createNoteJobDone(ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);64 void createNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);
75 void saveNoteJobDone(ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);65 void saveNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result);
76 void deleteNoteJobDone(ErrorCode errorCode, const QString &errorMessage, const QString &guid);66 void deleteNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid);
77
78 // Use this to enqueue a new job. It will automatically start it if there is no other job pending.
79 void enqueue(EvernoteJob *job);
80 void startJobQueue();
81
82 // You should not use this. It's called by the job queue.
83 // If you have a new job to run, just enqueue it. The queue will process it eventually.
84 void startNextJob();
8567
86private:68private:
87 explicit NotesStore(QObject *parent = 0);69 explicit NotesStore(QObject *parent = 0);
88 static NotesStore *s_instance;70 static NotesStore *s_instance;
8971
90 QString m_token;
91
92 QHash<QString, Notebook*> m_notebooks;72 QHash<QString, Notebook*> m_notebooks;
93 QHash<QString, Note*> m_notes;73 QHash<QString, Note*> m_notes;
9474
95 // There must be only one job running at a time
96 // Do not start jobs other than with startJobQueue()
97 QList<EvernoteJob*> m_jobQueue;
98 EvernoteJob *m_currentJob;
99
100 // Those two are accessed from the job thread.
101 // Make sure to not access them while any jobs are running
102 // or we need to mutex them.
103 evernote::edam::NoteStoreClient *m_client;
104 boost::shared_ptr<THttpClient> m_httpClient;
105
106};75};
10776
108#endif // NOTESSTORE_H77#endif // NOTESSTORE_H
10978
=== modified file 'src/plugin/Evernote/userstore.cpp'
--- src/plugin/Evernote/userstore.cpp 2013-11-26 17:18:33 +0000
+++ src/plugin/Evernote/userstore.cpp 2013-11-28 00:46:50 +0000
@@ -19,6 +19,8 @@
19 */19 */
2020
21#include "userstore.h"21#include "userstore.h"
22#include "evernoteconnection.h"
23#include "jobs/fetchusernamejob.h"
2224
23// Evernote sdk25// Evernote sdk
24#include <UserStore.h>26#include <UserStore.h>
@@ -34,106 +36,47 @@
3436
35#include <QDebug>37#include <QDebug>
3638
37using namespace evernote::edam;
38using namespace apache::thrift;39using namespace apache::thrift;
39using namespace apache::thrift::protocol;40using namespace apache::thrift::protocol;
40using namespace apache::thrift::transport;41using namespace apache::thrift::transport;
4142
43UserStore* UserStore::s_instance = 0;
44
42UserStore::UserStore(QObject *parent) :45UserStore::UserStore(QObject *parent) :
43 QObject(parent)46 QObject(parent)
44{47{
4548 connect(EvernoteConnection::instance(), &EvernoteConnection::tokenChanged, this, &UserStore::fetchUsername);
46 try {49
47 // FIXME: need to populate this string from the system50 fetchUsername();
48 // The structure should be:51}
49 // application/version; platform/version; [ device/version ]52
50 // E.g. "Evernote Windows/3.0.1; Windows/XP SP3"53UserStore *UserStore::instance()
51 QString EDAM_CLIENT_NAME = QStringLiteral("Reminders/0.1; Ubuntu/13.10");54{
52 QString EVERNOTE_HOST = QStringLiteral("sandbox.evernote.com");55 if (!s_instance) {
53 QString EDAM_USER_STORE_PATH = QStringLiteral("/edam/user");56 s_instance = new UserStore();
54 boost::shared_ptr<TSocket> socket;57 }
55 bool use_SSL = false;58 return s_instance;
5659}
57 if (use_SSL) {60
58 // Create an SSL socket61QString UserStore::username() const
59 // FIXME: this fails with the following error:62{
60 // Thrift: Fri Nov 15 12:47:31 2013 SSL_shutdown: error code: 063 return m_username;
61 // SSL_get_verify_result(), unable to get local issuer certificate64}
62 // Additionally, the UI blocks and does not load for about 2 minutes65
63 boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory());66void UserStore::fetchUsername()
64 socket = sslSocketFactory->createSocket(EVERNOTE_HOST.toStdString(), 443);67{
65 } else {68 FetchUsernameJob *job = new FetchUsernameJob();
66 // Create a non-secure socket69 connect(job, &FetchUsernameJob::jobDone, this, &UserStore::fetchUsernameJobDone);
67 socket = boost::shared_ptr<TSocket> (new TSocket(EVERNOTE_HOST.toStdString(), 80));70 EvernoteConnection::instance()->enqueue(job);
68 }71}
6972
70 boost::shared_ptr<TBufferedTransport> bufferedTransport(new TBufferedTransport(socket));73void UserStore::fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result)
71 boost::shared_ptr<THttpClient> userStoreHttpClient (new THttpClient(bufferedTransport,74{
72 EVERNOTE_HOST.toStdString(),75 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
73 EDAM_USER_STORE_PATH.toStdString()));76 qWarning() << "Error fetching username:" << errorMessage;
74 userStoreHttpClient->open();77 return;
7578 }
76 boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(userStoreHttpClient));79
77 UserStoreClient m_client(iprot);80 m_username = result;
78 UserStoreConstants constants;81 emit usernameChanged();
79
80 // checkVersion returns true if the client is capable of talking to the service,
81 // false otherwise
82 qDebug() << "version check:" << m_client.checkVersion(EDAM_CLIENT_NAME.toStdString(),
83 constants.EDAM_VERSION_MAJOR,
84 constants.EDAM_VERSION_MINOR);
85
86 } catch(...) {
87 displayException();
88 }
89}
90
91void UserStore::getPublicUserInfo(const QString &user)
92{
93 qDebug() << "should get public user info for user" << user;
94 // PublicUserInfo userInfo;
95
96}
97
98// TODO: move to a common place instead of copying it through *store.cpps
99void UserStore::displayException()
100{
101 QString error_message = "Unknown Exception";
102 try
103 {
104 // this function is meant to be called from a catch block
105 // rethrow the exception to catch it again
106 throw;
107 }
108 catch (const EDAMNotFoundException & e)
109 {
110 qDebug() << e.what();
111 }
112 catch (const EDAMSystemException & e)
113 {
114 qDebug() << e.what();
115 }
116 catch (const EDAMUserException & e)
117 {
118 qDebug() << e.what();
119 }
120 catch (const TTransportException & e)
121 {
122 qDebug() << e.what();
123 }
124 catch (const TException & e)
125 {
126 qDebug() << e.what();
127 }
128 catch (const std::exception & e)
129 {
130 qDebug() << e.what();
131 }
132 catch (...)
133 {
134 error_message = "Tried to sync, but something went wrong.\n Unknown exception.";
135 }
136
137 qDebug() << error_message;
138 disconnect();
139}82}
14083
=== modified file 'src/plugin/Evernote/userstore.h'
--- src/plugin/Evernote/userstore.h 2013-11-24 17:03:28 +0000
+++ src/plugin/Evernote/userstore.h 2013-11-28 00:46:50 +0000
@@ -1,6 +1,9 @@
1#ifndef USERSTORE_H1#ifndef USERSTORE_H
2#define USERSTORE_H2#define USERSTORE_H
33
4#include "evernoteconnection.h"
5
6//Evernote SDK
4#include "UserStore.h"7#include "UserStore.h"
58
6#include <QObject>9#include <QObject>
@@ -8,17 +11,28 @@
8class UserStore : public QObject11class UserStore : public QObject
9{12{
10 Q_OBJECT13 Q_OBJECT
14
15 // TODO: Once we need more than just the username, turn this into a class User
16 Q_PROPERTY(QString username READ username NOTIFY usernameChanged)
17
11public:18public:
12 explicit UserStore(QObject *parent = 0);19 static UserStore* instance();
20
21 QString username() const;
1322
14signals:23signals:
1524 void usernameChanged();
16public slots:25
17 void getPublicUserInfo(const QString &user);26private slots:
27 void fetchUsername();
28
29 void fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result);
1830
19private:31private:
32 static UserStore* s_instance;
33 explicit UserStore(QObject *parent = 0);
2034
21 void displayException();35 QString m_username;
22};36};
2337
24#endif // USERSTORE_H38#endif // USERSTORE_H

Subscribers

People subscribed via source and target branches