Merge lp:~mzanetti/reminders-app/create-edit-delete-notes into lp:reminders-app

Proposed by Michael Zanetti
Status: Superseded
Proposed branch: lp:~mzanetti/reminders-app/create-edit-delete-notes
Merge into: lp:reminders-app
Diff against target: 1577 lines (+1029/-175)
30 files modified
src/app/qml/reminders-app.qml (+1/-1)
src/app/qml/ui/NotePage.qml (+26/-6)
src/app/qml/ui/NotesPage.qml (+20/-3)
src/plugin/Evernote/Evernote.pro (+20/-2)
src/plugin/Evernote/evernoteplugin.cpp (+2/-0)
src/plugin/Evernote/jobs/createnotejob.cpp (+37/-0)
src/plugin/Evernote/jobs/createnotejob.h (+22/-0)
src/plugin/Evernote/jobs/deletenotejob.cpp (+18/-0)
src/plugin/Evernote/jobs/deletenotejob.h (+21/-0)
src/plugin/Evernote/jobs/evernotejob.cpp (+49/-0)
src/plugin/Evernote/jobs/evernotejob.h (+30/-0)
src/plugin/Evernote/jobs/fetchnotebooksjob.cpp (+23/-0)
src/plugin/Evernote/jobs/fetchnotebooksjob.h (+18/-0)
src/plugin/Evernote/jobs/fetchnotejob.cpp (+27/-0)
src/plugin/Evernote/jobs/fetchnotejob.h (+22/-0)
src/plugin/Evernote/jobs/fetchnotesjob.cpp (+44/-0)
src/plugin/Evernote/jobs/fetchnotesjob.h (+21/-0)
src/plugin/Evernote/jobs/savenotejob.cpp (+40/-0)
src/plugin/Evernote/jobs/savenotejob.h (+20/-0)
src/plugin/Evernote/note.cpp (+71/-0)
src/plugin/Evernote/note.h (+46/-0)
src/plugin/Evernote/notebook.cpp (+25/-0)
src/plugin/Evernote/notebook.h (+30/-0)
src/plugin/Evernote/notebooks.cpp (+19/-25)
src/plugin/Evernote/notebooks.h (+4/-5)
src/plugin/Evernote/notes.cpp (+49/-53)
src/plugin/Evernote/notes.h (+13/-6)
src/plugin/Evernote/notesstore.cpp (+255/-59)
src/plugin/Evernote/notesstore.h (+56/-13)
src/plugin/Evernote/userstore.h (+0/-2)
To merge this branch: bzr merge lp:~mzanetti/reminders-app/create-edit-delete-notes
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Needs Fixing
Ubuntu Notes app developers Pending
Review via email: mp+196456@code.launchpad.net

This proposal has been superseded by a proposal from 2013-11-25.

Commit message

Adds support creating, editing and deleting notes.

Description of the change

Adds support creating, editing and deleting notes. Still a bit experimental. Need to figure a way to deal with the doctype.

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: Needs Fixing (continuous-integration)

Unmerged revisions

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-22 00:42:39 +0000
+++ src/app/qml/reminders-app.qml 2013-11-25 00:51:38 +0000
@@ -29,7 +29,7 @@
2929
30 Component.onCompleted: {30 Component.onCompleted: {
31 pagestack.push(rootTabs)31 pagestack.push(rootTabs)
32 if (NotesStore.token.length == 0) {32 if (NotesStore.token.length === 0) {
33 pagestack.push(Qt.resolvedUrl("ui/AccountSelectorPage.qml"));33 pagestack.push(Qt.resolvedUrl("ui/AccountSelectorPage.qml"));
34 }34 }
35 }35 }
3636
=== modified file 'src/app/qml/ui/NotePage.qml'
--- src/app/qml/ui/NotePage.qml 2013-11-21 23:30:15 +0000
+++ src/app/qml/ui/NotePage.qml 2013-11-25 00:51:38 +0000
@@ -3,13 +3,33 @@
3import Evernote 0.13import Evernote 0.1
44
5Page {5Page {
66 title: note.title
7 property alias text: noteTextArea.text7 property var note
88
9 TextArea {9 Column {
10 id: noteTextArea
11 anchors.fill: parent10 anchors.fill: parent
12 textFormat: TextEdit.RichText11 spacing: units.gu(1)
12 Button {
13 width: parent.width
14 text: "save"
15 onClicked: {
16 print("timer triggered")
17 var content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\"><en-note><div><br clear=\"none\"/>"
18 content = content + noteTextArea.getText(0, noteTextArea.length)
19 content = content + "<br clear=\"none\"/></div><div><br clear=\"none\"/></div></en-note>"
20 note.content = content
21 note.save();
22 }
23 }
24
25 TextArea {
26 id: noteTextArea
27 anchors { left: parent.left; right: parent.right }
28 height: parent.height - y
29
30 textFormat: TextEdit.RichText
31 text: note.content
32 }
13 }33 }
14}34}
1535
1636
=== modified file 'src/app/qml/ui/NotesPage.qml'
--- src/app/qml/ui/NotesPage.qml 2013-11-21 23:30:15 +0000
+++ src/app/qml/ui/NotesPage.qml 2013-11-25 00:51:38 +0000
@@ -10,14 +10,27 @@
1010
11 onActiveChanged: {11 onActiveChanged: {
12 if (active) {12 if (active) {
13 print("refreshing notes")
13 notes.refresh();14 notes.refresh();
14 }15 }
15 }16 }
1617
18 // Just for testing
19 tools: ToolbarItems {
20 ToolbarButton {
21 text: "add note"
22 enabled: notes.filterNotebookGuid.length > 0
23 onTriggered: {
24 var content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\"><en-note><div><br clear=\"none\"/>"
25 content = content + "fobar"
26 content = content + "<br clear=\"none\"/></div><div><br clear=\"none\"/></div></en-note>"
27 NotesStore.createNote("Untitled", notes.filterNotebookGuid, content);
28 }
29 }
30 }
31
17 Notes {32 Notes {
18 id: notes33 id: notes
19
20 onFilterNotebookGuidChanged: refresh();
21 }34 }
2235
23 ListView {36 ListView {
@@ -28,7 +41,11 @@
28 text: title41 text: title
2942
30 onClicked: {43 onClicked: {
31 pageStack.push(Qt.resolvedUrl("NotePage.qml"), {title: title, text: notes.note(guid)})44 pageStack.push(Qt.resolvedUrl("NotePage.qml"), {note: notes.note(guid)})
45 }
46
47 onPressAndHold: {
48 notes.note(guid).remove();
32 }49 }
33 }50 }
34 }51 }
3552
=== modified file 'src/plugin/Evernote/Evernote.pro'
--- src/plugin/Evernote/Evernote.pro 2013-11-21 23:30:15 +0000
+++ src/plugin/Evernote/Evernote.pro 2013-11-25 00:51:38 +0000
@@ -13,13 +13,31 @@
13 notesstore.cpp \13 notesstore.cpp \
14 userstore.cpp \14 userstore.cpp \
15 notebooks.cpp \15 notebooks.cpp \
16 notes.cpp16 notes.cpp \
17 note.cpp \
18 notebook.cpp \
19 jobs/fetchnotesjob.cpp \
20 jobs/fetchnotebooksjob.cpp \
21 jobs/fetchnotejob.cpp \
22 jobs/createnotejob.cpp \
23 jobs/evernotejob.cpp \
24 jobs/savenotejob.cpp \
25 jobs/deletenotejob.cpp
1726
18HEADERS += evernoteplugin.h \27HEADERS += evernoteplugin.h \
19 notesstore.h \28 notesstore.h \
20 userstore.h \29 userstore.h \
21 notebooks.h \30 notebooks.h \
22 notes.h31 notes.h \
32 note.h \
33 notebook.h \
34 jobs/fetchnotesjob.h \
35 jobs/fetchnotebooksjob.h \
36 jobs/fetchnotejob.h \
37 jobs/createnotejob.h \
38 jobs/evernotejob.h \
39 jobs/savenotejob.h \
40 jobs/deletenotejob.h
2341
24message(building in $$OUT_PWD)42message(building in $$OUT_PWD)
25LIBS += -L$$OUT_PWD/../../../3rdParty/evernote-sdk-cpp/ -L$$OUT_PWD/../../../3rdParty/libthrift/ -levernote-sdk-cpp -llibthrift43LIBS += -L$$OUT_PWD/../../../3rdParty/evernote-sdk-cpp/ -L$$OUT_PWD/../../../3rdParty/libthrift/ -levernote-sdk-cpp -llibthrift
2644
=== modified file 'src/plugin/Evernote/evernoteplugin.cpp'
--- src/plugin/Evernote/evernoteplugin.cpp 2013-11-21 23:30:15 +0000
+++ src/plugin/Evernote/evernoteplugin.cpp 2013-11-25 00:51:38 +0000
@@ -22,6 +22,7 @@
22#include "notesstore.h"22#include "notesstore.h"
23#include "notes.h"23#include "notes.h"
24#include "notebooks.h"24#include "notebooks.h"
25#include "note.h"
2526
26#include <QtQml>27#include <QtQml>
2728
@@ -37,4 +38,5 @@
37 qmlRegisterSingletonType<NotesStore>("Evernote", 0, 1, "NotesStore", notesStoreProvider);38 qmlRegisterSingletonType<NotesStore>("Evernote", 0, 1, "NotesStore", notesStoreProvider);
38 qmlRegisterType<Notes>("Evernote", 0, 1, "Notes");39 qmlRegisterType<Notes>("Evernote", 0, 1, "Notes");
39 qmlRegisterType<Notebooks>("Evernote", 0, 1, "Notebooks");40 qmlRegisterType<Notebooks>("Evernote", 0, 1, "Notebooks");
41 qmlRegisterUncreatableType<Note>("Evernote", 0, 1, "Note", "Cannot create Notes in QML. Use NotesStore.createNote() instead.");
40}42}
4143
=== added directory 'src/plugin/Evernote/jobs'
=== added file 'src/plugin/Evernote/jobs/createnotejob.cpp'
--- src/plugin/Evernote/jobs/createnotejob.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/createnotejob.cpp 2013-11-25 00:51:38 +0000
@@ -0,0 +1,37 @@
1#include "createnotejob.h"
2
3#include <QDebug>
4
5CreateNoteJob::CreateNoteJob(Note *note, QObject *parent) :
6 EvernoteJob(parent),
7 m_note(note)
8{
9}
10
11void CreateNoteJob::run()
12{
13 NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError;
14
15 try {
16 evernote::edam::Note input;
17 input.title = m_note->title().toStdString();
18 input.__isset.title = true;
19 input.notebookGuid = m_note->notebookGuid().toStdString();
20 input.__isset.notebookGuid = true;
21 input.content = m_note->content().toStdString();
22 input.__isset.content = true;
23 input.contentLength = m_note->content().length();
24 input.__isset.contentLength = true;
25
26 evernote::edam::Note result;
27 client()->createNote(result, token().toStdString(), input);
28
29 m_note->setGuid(QString::fromStdString(result.guid));
30
31 } catch(evernote::edam::EDAMUserException e) {
32 errorCode = NotesStore::ErrorCodeUserException;
33 } catch(evernote::edam::EDAMSystemException) {
34 errorCode = NotesStore::ErrorCodeSystemException;
35 }
36 emit resultReady(errorCode, m_note);
37}
038
=== added file 'src/plugin/Evernote/jobs/createnotejob.h'
--- src/plugin/Evernote/jobs/createnotejob.h 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/createnotejob.h 2013-11-25 00:51:38 +0000
@@ -0,0 +1,22 @@
1#ifndef CREATENOTEJOB_H
2#define CREATENOTEJOB_H
3
4#include "evernotejob.h"
5#include "note.h"
6
7class CreateNoteJob : public EvernoteJob
8{
9 Q_OBJECT
10public:
11 explicit CreateNoteJob(Note *note, QObject *parent = 0);
12
13 void run();
14
15signals:
16 void resultReady(NotesStore::ErrorCode errorCode, Note *note);
17
18private:
19 Note *m_note;
20};
21
22#endif // CREATENOTEJOB_H
023
=== added file 'src/plugin/Evernote/jobs/deletenotejob.cpp'
--- src/plugin/Evernote/jobs/deletenotejob.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/deletenotejob.cpp 2013-11-25 00:51:38 +0000
@@ -0,0 +1,18 @@
1#include "deletenotejob.h"
2
3DeleteNoteJob::DeleteNoteJob(const QString &guid, QObject *parent):
4 EvernoteJob(parent),
5 m_guid(guid)
6{
7}
8
9void DeleteNoteJob::run()
10{
11 NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError;
12 try {
13 client()->deleteNote(token().toStdString(), m_guid.toStdString());
14 } catch(...) {
15 catchTransportException();
16 }
17 emit resultReady(errorCode, m_guid);
18}
019
=== added file 'src/plugin/Evernote/jobs/deletenotejob.h'
--- src/plugin/Evernote/jobs/deletenotejob.h 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/deletenotejob.h 2013-11-25 00:51:38 +0000
@@ -0,0 +1,21 @@
1#ifndef DELETENOTEJOB_H
2#define DELETENOTEJOB_H
3
4#include "evernotejob.h"
5
6class DeleteNoteJob : public EvernoteJob
7{
8 Q_OBJECT
9public:
10 DeleteNoteJob(const QString &guid, QObject *parent = 0);
11
12 void run();
13
14signals:
15 void resultReady(NotesStore::ErrorCode errorCode, const QString &guid);
16
17private:
18 QString m_guid;
19};
20
21#endif // DELETENOTEJOB_H
022
=== added file 'src/plugin/Evernote/jobs/evernotejob.cpp'
--- src/plugin/Evernote/jobs/evernotejob.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/evernotejob.cpp 2013-11-25 00:51:38 +0000
@@ -0,0 +1,49 @@
1#include "evernotejob.h"
2
3// Thrift
4#include <arpa/inet.h> // seems thrift forgot this one
5#include <protocol/TBinaryProtocol.h>
6#include <transport/THttpClient.h>
7#include <transport/TSSLSocket.h>
8#include <Thrift.h>
9
10#include <QDebug>
11
12using namespace apache::thrift;
13using namespace apache::thrift::protocol;
14using namespace apache::thrift::transport;
15
16EvernoteJob::EvernoteJob(QObject *parent) :
17 QThread(parent),
18 m_token(NotesStore::instance()->token())
19{
20 connect(this, &EvernoteJob::finished, this, &EvernoteJob::deleteLater);
21}
22
23EvernoteJob::~EvernoteJob()
24{
25
26}
27
28evernote::edam::NoteStoreClient *EvernoteJob::client()
29{
30 return NotesStore::instance()->m_client;
31}
32
33QString EvernoteJob::token()
34{
35 return m_token;
36}
37
38void EvernoteJob::catchTransportException()
39{
40 try {
41 // this function is meant to be called from a catch block
42 // rethrow the exception to catch it again
43 throw;
44 } catch (const TTransportException & e) {
45 qDebug() << e.what();
46 } catch (const TException & e) {
47 qDebug() << e.what();
48 }
49}
050
=== added file 'src/plugin/Evernote/jobs/evernotejob.h'
--- src/plugin/Evernote/jobs/evernotejob.h 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/evernotejob.h 2013-11-25 00:51:38 +0000
@@ -0,0 +1,30 @@
1#ifndef EVERNOTEJOB_H
2#define EVERNOTEJOB_H
3
4#include "notesstore.h"
5
6// Evernote SDK
7#include <NoteStore.h>
8#include <NoteStore_constants.h>
9#include <Errors_types.h>
10
11#include <QThread>
12
13class EvernoteJob : public QThread
14{
15 Q_OBJECT
16public:
17 explicit EvernoteJob(QObject *parent = 0);
18 virtual ~EvernoteJob();
19
20protected:
21 evernote::edam::NoteStoreClient* client();
22 QString token();
23
24 void catchTransportException();
25
26private:
27 QString m_token;
28};
29
30#endif // EVERNOTEJOB_H
031
=== added file 'src/plugin/Evernote/jobs/fetchnotebooksjob.cpp'
--- src/plugin/Evernote/jobs/fetchnotebooksjob.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/fetchnotebooksjob.cpp 2013-11-25 00:51:38 +0000
@@ -0,0 +1,23 @@
1#include "fetchnotebooksjob.h"
2
3#include <QDebug>
4
5FetchNotebooksJob::FetchNotebooksJob(QObject *parent) :
6 EvernoteJob(parent)
7{
8}
9
10
11void FetchNotebooksJob::run()
12{
13 NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError;
14 std::vector<evernote::edam::Notebook> results;
15 try {
16 client()->listNotebooks(results, token().toStdString());
17 } catch(evernote::edam::EDAMUserException) {
18 errorCode = NotesStore::ErrorCodeUserException;
19 } catch(evernote::edam::EDAMSystemException) {
20 errorCode = NotesStore::ErrorCodeSystemException;
21 }
22 emit resultReady(errorCode, results);
23}
024
=== added file 'src/plugin/Evernote/jobs/fetchnotebooksjob.h'
--- src/plugin/Evernote/jobs/fetchnotebooksjob.h 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/fetchnotebooksjob.h 2013-11-25 00:51:38 +0000
@@ -0,0 +1,18 @@
1#ifndef FETCHNOTEBOOKSJOB_H
2#define FETCHNOTEBOOKSJOB_H
3
4#include "evernotejob.h"
5
6class FetchNotebooksJob : public EvernoteJob
7{
8 Q_OBJECT
9public:
10 explicit FetchNotebooksJob(QObject *parent = 0);
11
12 void run();
13
14signals:
15 void resultReady(NotesStore::ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results);
16};
17
18#endif // FETCHNOTEBOOKSJOB_H
019
=== added file 'src/plugin/Evernote/jobs/fetchnotejob.cpp'
--- src/plugin/Evernote/jobs/fetchnotejob.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/fetchnotejob.cpp 2013-11-25 00:51:38 +0000
@@ -0,0 +1,27 @@
1#include "fetchnotejob.h"
2
3FetchNoteJob::FetchNoteJob(const QString &guid, QObject *parent) :
4 EvernoteJob(parent),
5 m_guid(guid)
6{
7}
8
9void FetchNoteJob::run()
10{
11 NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError;
12 evernote::edam::Note result;
13 try {
14 client()->getNote(result, token().toStdString(), m_guid.toStdString(), true, true, false, false);
15 } catch (evernote::edam::EDAMUserException) {
16 errorCode = NotesStore::ErrorCodeUserException;
17 } catch (evernote::edam::EDAMSystemException) {
18 errorCode = NotesStore::ErrorCodeSystemException;
19 } catch (evernote::edam::EDAMNotFoundException) {
20 errorCode = NotesStore::ErrorCodeNotFoundExcpetion;
21 } catch (...) {
22 catchTransportException();
23 errorCode = NotesStore::ErrorCodeConnectionLost;
24 }
25
26 emit resultReady(errorCode, result);
27}
028
=== added file 'src/plugin/Evernote/jobs/fetchnotejob.h'
--- src/plugin/Evernote/jobs/fetchnotejob.h 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/fetchnotejob.h 2013-11-25 00:51:38 +0000
@@ -0,0 +1,22 @@
1#ifndef FETCHNOTEJOB_H
2#define FETCHNOTEJOB_H
3
4#include "evernotejob.h"
5
6class FetchNoteJob : public EvernoteJob
7{
8 Q_OBJECT
9public:
10 explicit FetchNoteJob(const QString &guid, QObject *parent = 0);
11
12 void run();
13signals:
14 void resultReady(NotesStore::ErrorCode error, const evernote::edam::Note &note);
15
16private:
17 evernote::edam::NoteStoreClient *m_client;
18 QString m_token;
19 QString m_guid;
20};
21
22#endif // FETCHNOTEJOB_H
023
=== added file 'src/plugin/Evernote/jobs/fetchnotesjob.cpp'
--- src/plugin/Evernote/jobs/fetchnotesjob.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/fetchnotesjob.cpp 2013-11-25 00:51:38 +0000
@@ -0,0 +1,44 @@
1#include "fetchnotesjob.h"
2
3#include "notesstore.h"
4
5#include <QDebug>
6
7FetchNotesJob::FetchNotesJob( const QString &filterNotebookGuid, QObject *parent) :
8 EvernoteJob(parent),
9 m_filterNotebookGuid(filterNotebookGuid)
10{
11}
12
13void FetchNotesJob::run()
14{
15 // TODO: fix start/end (use smaller chunks and continue fetching if there are more notes available)
16 int32_t start = 0;
17 int32_t end = 10000;
18
19 // Prepare filter
20 evernote::edam::NoteFilter filter;
21 filter.notebookGuid = m_filterNotebookGuid.toStdString();
22 filter.__isset.notebookGuid = !m_filterNotebookGuid.isEmpty();
23
24 // Prepare ResultSpec
25 evernote::edam::NotesMetadataResultSpec resultSpec;
26 resultSpec.includeNotebookGuid = true;
27 resultSpec.__isset.includeNotebookGuid = true;
28 resultSpec.includeTitle = true;
29 resultSpec.__isset.includeTitle = true;
30
31 NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError;
32 evernote::edam::NotesMetadataList results;
33
34 try {
35 client()->findNotesMetadata(results, token().toStdString(), filter, start, end, resultSpec);
36 } catch(evernote::edam::EDAMUserException) {
37 errorCode = NotesStore::ErrorCodeUserException;
38 } catch(evernote::edam::EDAMSystemException) {
39 errorCode = NotesStore::ErrorCodeSystemException;
40 } catch(evernote::edam::EDAMNotFoundException) {
41 errorCode = NotesStore::ErrorCodeNotFoundExcpetion;
42 }
43 emit resultReady(errorCode, results);
44}
045
=== added file 'src/plugin/Evernote/jobs/fetchnotesjob.h'
--- src/plugin/Evernote/jobs/fetchnotesjob.h 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/fetchnotesjob.h 2013-11-25 00:51:38 +0000
@@ -0,0 +1,21 @@
1#ifndef FETCHNOTESJOB_H
2#define FETCHNOTESJOB_H
3
4#include "evernotejob.h"
5
6class FetchNotesJob : public EvernoteJob
7{
8 Q_OBJECT
9public:
10 explicit FetchNotesJob(const QString &filterNotebookGuid, QObject *parent = 0);
11
12 void run();
13
14signals:
15 void resultReady(NotesStore::ErrorCode errorCode, const evernote::edam::NotesMetadataList &results);
16
17private:
18 QString m_filterNotebookGuid;
19};
20
21#endif // FETCHNOTESJOB_H
022
=== added file 'src/plugin/Evernote/jobs/savenotejob.cpp'
--- src/plugin/Evernote/jobs/savenotejob.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/savenotejob.cpp 2013-11-25 00:51:38 +0000
@@ -0,0 +1,40 @@
1#include "savenotejob.h"
2#include "note.h"
3
4#include <QDebug>
5
6SaveNoteJob::SaveNoteJob(Note *note, QObject *parent) :
7 EvernoteJob(parent),
8 m_note(note)
9{
10}
11
12void SaveNoteJob::run()
13{
14 NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError;
15 try {
16 evernote::edam::Note note;
17 note.guid = m_note->guid().toStdString();
18 note.__isset.guid = true;
19 note.title = m_note->title().toStdString();
20 note.__isset.title = true;
21 note.notebookGuid = m_note->notebookGuid().toStdString();
22 note.__isset.notebookGuid = true;
23 note.content = m_note->content().toStdString();
24 note.__isset.content = true;
25 note.contentLength = m_note->content().length();
26
27 client()->updateNote(note, token().toStdString(), note);
28
29 } catch (evernote::edam::EDAMUserException e) {
30 errorCode = NotesStore::ErrorCodeUserException;
31 qDebug() << QString::fromStdString(e.parameter);
32 } catch (evernote::edam::EDAMSystemException) {
33 errorCode = NotesStore::ErrorCodeSystemException;
34 } catch (...) {
35 catchTransportException();
36 errorCode = NotesStore::ErrorCodeConnectionLost;
37 }
38
39 emit resultReady(errorCode, m_note);
40}
041
=== added file 'src/plugin/Evernote/jobs/savenotejob.h'
--- src/plugin/Evernote/jobs/savenotejob.h 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/jobs/savenotejob.h 2013-11-25 00:51:38 +0000
@@ -0,0 +1,20 @@
1#ifndef SAVENOTEJOB_H
2#define SAVENOTEJOB_H
3
4#include "evernotejob.h"
5
6class SaveNoteJob : public EvernoteJob
7{
8 Q_OBJECT
9public:
10 explicit SaveNoteJob(Note *note, QObject *parent = 0);
11
12 void run();
13signals:
14 void resultReady(NotesStore::ErrorCode errorCode, Note *note);
15
16private:
17 Note *m_note;
18};
19
20#endif // SAVENOTEJOB_H
021
=== added file 'src/plugin/Evernote/note.cpp'
--- src/plugin/Evernote/note.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/note.cpp 2013-11-25 00:51:38 +0000
@@ -0,0 +1,71 @@
1#include "note.h"
2
3#include "notesstore.h"
4
5Note::Note(const QString &guid, QObject *parent) :
6 QObject(parent),
7 m_guid(guid)
8{
9}
10
11QString Note::guid() const
12{
13 return m_guid;
14}
15
16void Note::setGuid(const QString &guid)
17{
18 if (m_guid == guid) {
19 m_guid = guid;
20 emit guidChanged();
21 }
22}
23
24QString Note::notebookGuid() const
25{
26 return m_notebookGuid;
27}
28
29void Note::setNotebookGuid(const QString &notebookGuid)
30{
31 if (m_notebookGuid != notebookGuid) {
32 m_notebookGuid = notebookGuid;
33 emit notebookGuidChanged();
34 }
35}
36
37QString Note::title() const
38{
39 return m_title;
40}
41
42void Note::setTitle(const QString &title)
43{
44 if (m_title != title) {
45 m_title = title;
46 emit titleChanged();
47 }
48}
49
50QString Note::content() const
51{
52 return m_content;
53}
54
55void Note::setContent(const QString &content)
56{
57 if (m_content != content) {
58 m_content = content;
59 emit contentChanged();
60 }
61}
62
63void Note::save()
64{
65 NotesStore::instance()->saveNote(m_guid);
66}
67
68void Note::remove()
69{
70 NotesStore::instance()->deleteNote(m_guid);
71}
072
=== added file 'src/plugin/Evernote/note.h'
--- src/plugin/Evernote/note.h 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/note.h 2013-11-25 00:51:38 +0000
@@ -0,0 +1,46 @@
1#ifndef NOTE_H
2#define NOTE_H
3
4#include <QObject>
5
6class Note : public QObject
7{
8 Q_OBJECT
9
10 Q_PROPERTY(QString guid READ guid NOTIFY guidChanged)
11 Q_PROPERTY(QString notebookGuid READ notebookGuid WRITE setNotebookGuid NOTIFY notebookGuidChanged)
12 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
13 Q_PROPERTY(QString content READ content WRITE setContent NOTIFY contentChanged)
14public:
15 explicit Note(const QString &guid = QString(), QObject *parent = 0);
16
17 QString guid() const;
18 void setGuid(const QString &guid);
19
20 QString notebookGuid() const;
21 void setNotebookGuid(const QString &notebookGuid);
22
23 QString title() const;
24 void setTitle(const QString &title);
25
26 QString content() const;
27 void setContent(const QString &content);
28
29public slots:
30 void save();
31 void remove();
32
33signals:
34 void guidChanged();
35 void titleChanged();
36 void notebookGuidChanged();
37 void contentChanged();
38
39private:
40 QString m_guid;
41 QString m_notebookGuid;
42 QString m_title;
43 QString m_content;
44};
45
46#endif // NOTE_H
047
=== added file 'src/plugin/Evernote/notebook.cpp'
--- src/plugin/Evernote/notebook.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/notebook.cpp 2013-11-25 00:51:38 +0000
@@ -0,0 +1,25 @@
1#include "notebook.h"
2
3Notebook::Notebook(QString guid, QObject *parent) :
4 QObject(parent),
5 m_guid(guid)
6{
7}
8
9QString Notebook::guid() const
10{
11 return m_guid;
12}
13
14QString Notebook::name() const
15{
16 return m_name;
17}
18
19void Notebook::setName(const QString &name)
20{
21 if (m_name != name) {
22 m_name = name;
23 emit nameChanged();
24 }
25}
026
=== added file 'src/plugin/Evernote/notebook.h'
--- src/plugin/Evernote/notebook.h 1970-01-01 00:00:00 +0000
+++ src/plugin/Evernote/notebook.h 2013-11-25 00:51:38 +0000
@@ -0,0 +1,30 @@
1#ifndef NOTEBOOK_H
2#define NOTEBOOK_H
3
4#include <QObject>
5
6class Notebook : public QObject
7{
8 Q_OBJECT
9
10 Q_PROPERTY(QString guid READ guid CONSTANT)
11 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
12public:
13 explicit Notebook(QString guid, QObject *parent = 0);
14
15 QString guid() const;
16
17 QString name() const;
18 void setName(const QString &name);
19
20signals:
21 void nameChanged();
22
23public slots:
24
25private:
26 QString m_guid;
27 QString m_name;
28};
29
30#endif // NOTEBOOK_H
031
=== modified file 'src/plugin/Evernote/notebooks.cpp'
--- src/plugin/Evernote/notebooks.cpp 2013-11-21 23:30:15 +0000
+++ src/plugin/Evernote/notebooks.cpp 2013-11-25 00:51:38 +0000
@@ -1,27 +1,34 @@
1#include "notebooks.h"1#include "notebooks.h"
2#include "notebook.h"
23
3#include <QDebug>4#include <QDebug>
45
5Notebooks::Notebooks(QObject *parent) :6Notebooks::Notebooks(QObject *parent) :
6 QAbstractListModel(parent)7 QAbstractListModel(parent)
7{8{
9 foreach (Notebook *notebook, NotesStore::instance()->notebooks()) {
10 m_list.append(notebook->guid());
11 }
12
13 connect(NotesStore::instance(), SIGNAL(notebookAdded(const QString &)), SLOT(notebookAdded(const QString &)));
8}14}
915
10QVariant Notebooks::data(const QModelIndex &index, int role) const16QVariant Notebooks::data(const QModelIndex &index, int role) const
11{17{
18
19 Notebook *notebook = NotesStore::instance()->notebook(m_list.at(index.row()));
12 switch(role) {20 switch(role) {
13 case RoleGuid:21 case RoleGuid:
14 return QString::fromStdString(m_list.at(index.row()).guid);22 return notebook->guid();
15 case RoleName:23 case RoleName:
16 return QString::fromStdString(m_list.at(index.row()).name);24 return notebook->name();
17 }25 }
18
19 return QVariant();26 return QVariant();
20}27}
2128
22int Notebooks::rowCount(const QModelIndex &parent) const29int Notebooks::rowCount(const QModelIndex &parent) const
23{30{
24 return m_list.size();31 return m_list.count();
25}32}
2633
27QHash<int, QByteArray> Notebooks::roleNames() const34QHash<int, QByteArray> Notebooks::roleNames() const
@@ -34,25 +41,12 @@
3441
35void Notebooks::refresh()42void Notebooks::refresh()
36{43{
3744 NotesStore::instance()->refreshNotebooks();
38 QString token = NotesStore::instance()->token();45}
39 if (token.isEmpty()) {46
40 qDebug() << "No token set. Cannot fetch notebooks.";47void Notebooks::notebookAdded(const QString &guid)
41 return;48{
42 }49 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
4350 m_list.append(guid);
44 beginResetModel();51 endInsertRows();
45 try {
46 NotesStore::instance()->evernoteNotesStoreClient()->listNotebooks(m_list, token.toStdString());
47 } catch(...) {
48 qDebug() << "Error fetching notebooks.";
49// displayException();
50 }
51
52 endResetModel();
53
54// for (int i = 0; i < notebooks.size(); ++i) {
55// qDebug() << "got notebooks" << QString::fromStdString(notebooks.at(i).name) << QString::fromStdString(notebooks.at(i).name)
56// << QString::fromStdString(notebooks.at(i).guid);
57// }
58}52}
5953
=== modified file 'src/plugin/Evernote/notebooks.h'
--- src/plugin/Evernote/notebooks.h 2013-11-21 23:30:15 +0000
+++ src/plugin/Evernote/notebooks.h 2013-11-25 00:51:38 +0000
@@ -5,8 +5,6 @@
55
6#include <QAbstractListModel>6#include <QAbstractListModel>
77
8using namespace evernote::edam;
9
10class Notebooks : public QAbstractListModel8class Notebooks : public QAbstractListModel
11{9{
12 Q_OBJECT10 Q_OBJECT
@@ -24,10 +22,11 @@
24public slots:22public slots:
25 void refresh();23 void refresh();
2624
25private slots:
26 void notebookAdded(const QString &guid);
27
27private:28private:
28 std::vector<Notebook> m_list;29 QList<QString> m_list;
29
30
31};30};
3231
33#endif // NOTEBOOKS_H32#endif // NOTEBOOKS_H
3433
=== modified file 'src/plugin/Evernote/notes.cpp'
--- src/plugin/Evernote/notes.cpp 2013-11-21 23:30:15 +0000
+++ src/plugin/Evernote/notes.cpp 2013-11-25 00:51:38 +0000
@@ -1,19 +1,24 @@
1#include "notes.h"1#include "notes.h"
2#include "note.h"
23
3#include <QDebug>4#include <QDebug>
45
5Notes::Notes(QObject *parent) :6Notes::Notes(QObject *parent) :
6 QAbstractListModel(parent)7 QAbstractListModel(parent)
7{8{
9 connect(NotesStore::instance(), &NotesStore::noteAdded, this, &Notes::noteAdded);
10 connect(NotesStore::instance(), &NotesStore::noteRemoved, this, &Notes::noteRemoved);
11 connect(NotesStore::instance(), &NotesStore::noteChanged, this, &Notes::noteChanged);
8}12}
913
10QVariant Notes::data(const QModelIndex &index, int role) const14QVariant Notes::data(const QModelIndex &index, int role) const
11{15{
16 Note *note = NotesStore::instance()->note(m_list.at(index.row()));
12 switch(role) {17 switch(role) {
13 case RoleGuid:18 case RoleGuid:
14 return QString::fromStdString(m_list.at(index.row()).guid);19 return note->guid();
15 case RoleTitle:20 case RoleTitle:
16 return QString::fromStdString(m_list.at(index.row()).title);21 return note->title();
17 }22 }
1823
19 return QVariant();24 return QVariant();
@@ -45,59 +50,50 @@
45 }50 }
46}51}
4752
48QString Notes::note(const QString &noteGuid)53Note* Notes::note(const QString &guid)
49{54{
50 QString token = NotesStore::instance()->token();55 NotesStore::instance()->refreshNoteContent(guid);
51 if (token.isEmpty()) {56 return NotesStore::instance()->note(guid);
52 qDebug() << "No token set. Cannot fetch note.";57}
53 return QString();58
54 }59void Notes::componentComplete()
5560{
56 Note note;61 foreach (Note *note, NotesStore::instance()->notes()) {
57 try {62 if (m_filterNotebookGuid.isEmpty() || note->notebookGuid() == m_filterNotebookGuid) {
58 NotesStore::instance()->evernoteNotesStoreClient()->getNote(note, token.toStdString(), noteGuid.toStdString(), true, true, false, false);63 m_list.append(note->guid());
59 } catch(...) {64 }
60 qDebug() << "error fetching note";65 }
61 return QString();66 beginInsertRows(QModelIndex(), 0, m_list.count() - 1);
62 }67 endInsertRows();
6368 refresh();
64 return QString::fromStdString(note.content);
65}69}
6670
67void Notes::refresh()71void Notes::refresh()
68{72{
69 QString token = NotesStore::instance()->token();73 NotesStore::instance()->refreshNotes(m_filterNotebookGuid);
70 if (token.isEmpty()) {74}
71 qDebug() << "No token set. Cannot fetch notes.";75
72 return;76void Notes::noteAdded(const QString &guid)
73 }77{
7478 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());
75 int32_t start = 0;79 m_list.append(guid);
76 int32_t end = 10000;80 endInsertRows();
7781}
78 // Prepare filter82
79 NoteFilter filter;83void Notes::noteChanged(const QString &guid)
80 filter.notebookGuid = m_filterNotebookGuid.toStdString();84{
81 filter.__isset.notebookGuid = !m_filterNotebookGuid.isEmpty();85 int row = m_list.indexOf(guid);
8286 if (row >= 0) {
83 // Prepare ResultSpec87 emit dataChanged(index(row), index(row));
84 NotesMetadataResultSpec resultSpec;88 }
85 resultSpec.includeTitle = true;89}
86 resultSpec.__isset.includeTitle = true;90
8791void Notes::noteRemoved(const QString &guid)
88 NotesMetadataList notes;92{
89 try {93 int index = m_list.indexOf(guid);
90 NotesStore::instance()->evernoteNotesStoreClient()->findNotesMetadata(notes, token.toStdString(), filter, start, end, resultSpec);94 if (index >= 0) {
91 } catch(...) {95 beginRemoveRows(QModelIndex(), index, index);
92 qDebug() << "error fetching notes";96 m_list.removeAt(index);
93 return;97 endRemoveRows();
94 }98 }
95
96 beginResetModel();
97 m_list.clear();
98 foreach (NoteMetadata note, notes.notes) {
99 m_list.append(note);
100 qDebug() << QString::fromStdString(note.guid) << QString::fromStdString(note.title);
101 }
102 endResetModel();
103}99}
104100
=== modified file 'src/plugin/Evernote/notes.h'
--- src/plugin/Evernote/notes.h 2013-11-21 23:30:15 +0000
+++ src/plugin/Evernote/notes.h 2013-11-25 00:51:38 +0000
@@ -4,10 +4,9 @@
4#include "notesstore.h"4#include "notesstore.h"
55
6#include <QAbstractListModel>6#include <QAbstractListModel>
77#include <QQmlParserStatus>
8using namespace evernote::edam;8
99class Notes : public QAbstractListModel, public QQmlParserStatus
10class Notes : public QAbstractListModel
11{10{
12 Q_OBJECT11 Q_OBJECT
13 Q_PROPERTY(QString filterNotebookGuid READ filterNotebookGuid WRITE setFilterNotebookGuid NOTIFY filterNotebookGuidChanged)12 Q_PROPERTY(QString filterNotebookGuid READ filterNotebookGuid WRITE setFilterNotebookGuid NOTIFY filterNotebookGuidChanged)
@@ -25,16 +24,24 @@
25 QString filterNotebookGuid() const;24 QString filterNotebookGuid() const;
26 void setFilterNotebookGuid(const QString &notebookGuid);25 void setFilterNotebookGuid(const QString &notebookGuid);
2726
28 Q_INVOKABLE QString note(const QString &noteGuid);27 Q_INVOKABLE Note* note(const QString &guid);
28
29 void classBegin() {}
30 void componentComplete();
2931
30public slots:32public slots:
31 void refresh();33 void refresh();
3234
35private slots:
36 void noteAdded(const QString &guid);
37 void noteChanged(const QString &guid);
38 void noteRemoved(const QString &guid);
39
33signals:40signals:
34 void filterNotebookGuidChanged();41 void filterNotebookGuidChanged();
3542
36private:43private:
37 QList<NoteMetadata> m_list;44 QList<QString> m_list;
38 QString m_filterNotebookGuid;45 QString m_filterNotebookGuid;
3946
40};47};
4148
=== modified file 'src/plugin/Evernote/notesstore.cpp'
--- src/plugin/Evernote/notesstore.cpp 2013-11-21 23:30:15 +0000
+++ src/plugin/Evernote/notesstore.cpp 2013-11-25 00:51:38 +0000
@@ -1,6 +1,14 @@
1#include "notesstore.h"1#include "notesstore.h"
2
3#include "notebooks.h"2#include "notebooks.h"
3#include "notebook.h"
4#include "note.h"
5
6#include "jobs/fetchnotesjob.h"
7#include "jobs/fetchnotebooksjob.h"
8#include "jobs/fetchnotejob.h"
9#include "jobs/createnotejob.h"
10#include "jobs/savenotejob.h"
11#include "jobs/deletenotejob.h"
412
5// Thrift13// Thrift
6#include <arpa/inet.h> // seems thrift forgot this one14#include <arpa/inet.h> // seems thrift forgot this one
@@ -11,7 +19,6 @@
1119
12#include <QDebug>20#include <QDebug>
1321
14using namespace evernote::edam;
15using namespace apache::thrift;22using namespace apache::thrift;
16using namespace apache::thrift::protocol;23using namespace apache::thrift::protocol;
17using namespace apache::thrift::transport;24using namespace apache::thrift::transport;
@@ -19,11 +26,10 @@
19NotesStore* NotesStore::s_instance = 0;26NotesStore* NotesStore::s_instance = 0;
2027
21NotesStore::NotesStore(QObject *parent) :28NotesStore::NotesStore(QObject *parent) :
22 QObject(parent)29 QObject(parent),
30 m_currentJob(0)
23{31{
24 try {32 try {
25 // TODO: Move this to a common place instead of keeping a copy here and in UserStore
26
27 // FIXME: need to populate this string from the system33 // FIXME: need to populate this string from the system
28 // The structure should be:34 // The structure should be:
29 // application/version; platform/version; [ device/version ]35 // application/version; platform/version; [ device/version ]
@@ -54,13 +60,21 @@
54 userStoreHttpClient->open();60 userStoreHttpClient->open();
5561
56 boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(userStoreHttpClient));62 boost::shared_ptr<TProtocol> iprot(new TBinaryProtocol(userStoreHttpClient));
57 m_client = new NoteStoreClient(iprot);63 m_client = new evernote::edam::NoteStoreClient(iprot);
5864
59 qDebug() << "NoteStore client created.";65 qDebug() << "NoteStore client created.";
60 } catch(...) {66
61 displayException();67 } catch (const TTransportException & e) {
68 qWarning() << "Failed to create Transport:" << e.what();
69 } catch (const TException & e) {
70 qWarning() << "Generic Thrift exception:" << e.what();
62 }71 }
6372
73 qRegisterMetaType<NotesStore::ErrorCode>("NotesStore::ErrorCode");
74 qRegisterMetaType<evernote::edam::NotesMetadataList>("evernote::edam::NotesMetadataList");
75 qRegisterMetaType<evernote::edam::Note>("evernote::edam::Note");
76 qRegisterMetaType<std::vector<evernote::edam::Notebook> >("std::vector<evernote::edam::Notebook>");
77
64}78}
6579
66NotesStore *NotesStore::instance()80NotesStore *NotesStore::instance()
@@ -71,6 +85,21 @@
71 return s_instance;85 return s_instance;
72}86}
7387
88QString NotesStore::errorCodeToString(NotesStore::ErrorCode errorCode)
89{
90 switch(errorCode) {
91 case ErrorCodeNoError:
92 return QStringLiteral("No error");
93 case ErrorCodeUserException:
94 return QStringLiteral("User exception");
95 case ErrorCodeSystemException:
96 return QStringLiteral("System exception");
97 case ErrorCodeNotFoundExcpetion:
98 return QStringLiteral("Not found");
99 }
100 return QString();
101}
102
74NotesStore::~NotesStore()103NotesStore::~NotesStore()
75{104{
76 delete m_client;105 delete m_client;
@@ -84,56 +113,223 @@
84void NotesStore::setToken(const QString &token)113void NotesStore::setToken(const QString &token)
85{114{
86 if (token != m_token) {115 if (token != m_token) {
87 qDebug() << "NotesStore: setting token:" << token;
88 m_token = token;116 m_token = token;
89 emit tokenChanged();117 emit tokenChanged();
90 }118 refreshNotebooks();
91}119 refreshNotes();
92120 }
93NoteStoreClient *NotesStore::evernoteNotesStoreClient()121}
94{122
95 return m_client;123QList<Note*> NotesStore::notes() const
96}124{
97125 return m_notes.values();
98// TODO: move to a common place instead of copying it through *store.cpps126}
99void NotesStore::displayException()127
100{128Note *NotesStore::note(const QString &guid)
101 QString error_message = "Unknown Exception";129{
102 try130 return m_notes.value(guid);
103 {131}
104 // this function is meant to be called from a catch block132
105 // rethrow the exception to catch it again133void NotesStore::saveNote(const QString &guid)
106 throw;134{
107 }135 Note *note = m_notes.value(guid);
108 catch (const EDAMNotFoundException & e)136 SaveNoteJob *job = new SaveNoteJob(note, this);
109 {137 connect(job, &SaveNoteJob::resultReady, this, &NotesStore::saveNoteJobDone);
110 qDebug() << e.what();138 m_jobQueue.append(job);
111 }139 startJobQueue();
112 catch (const EDAMSystemException & e)140}
113 {141
114 qDebug() << e.what();142void NotesStore::deleteNote(const QString &guid)
115 }143{
116 catch (const EDAMUserException & e)144 DeleteNoteJob *job = new DeleteNoteJob(guid, this);
117 {145 connect(job, &DeleteNoteJob::resultReady, this, &NotesStore::deleteNoteJobDone);
118 qDebug() << e.what();146 m_jobQueue.append(job);
119 }147 startJobQueue();
120 catch (const TTransportException & e)148}
121 {149
122 qDebug() << e.what();150QList<Notebook *> NotesStore::notebooks() const
123 }151{
124 catch (const TException & e)152 return m_notebooks.values();
125 {153}
126 qDebug() << e.what();154
127 }155Notebook *NotesStore::notebook(const QString &guid)
128 catch (const std::exception & e)156{
129 {157 return m_notebooks.value(guid);
130 qDebug() << e.what();158}
131 }159
132 catch (...)160void NotesStore::startJobQueue()
133 {161{
134 error_message = "Tried to sync, but something went wrong.\n Unknown exception.";162 if (m_jobQueue.isEmpty()) {
135 }163 return;
136164 }
137 qDebug() << error_message;165
138 disconnect();166 if (m_currentJob) {
139}167 return;
168 }
169 m_currentJob = m_jobQueue.takeFirst();
170 m_currentJob->start();
171}
172
173void NotesStore::startNextJob()
174{
175 m_currentJob = 0;
176 startJobQueue();
177}
178
179void NotesStore::refreshNotes(const QString &filterNotebookGuid)
180{
181 if (m_token.isEmpty()) {
182 qWarning() << "No token set. Cannot fetch notes.";
183 return;
184 }
185
186 FetchNotesJob *job = new FetchNotesJob(filterNotebookGuid);
187 connect(job, &FetchNotesJob::resultReady, this, &NotesStore::fetchNotesJobDone);
188
189 m_jobQueue.append(job);
190 startJobQueue();
191}
192
193void NotesStore::fetchNotesJobDone(ErrorCode errorCode, const evernote::edam::NotesMetadataList &results)
194{
195 if (errorCode != ErrorCodeNoError) {
196 qWarning() << "Failed to fetch notes list:" << errorCodeToString(errorCode);
197 startNextJob();
198 return;
199 }
200
201 for (int i = 0; i < results.notes.size(); ++i) {
202 evernote::edam::NoteMetadata result = results.notes.at(i);
203 Note *note = m_notes.value(QString::fromStdString(result.guid));
204 if (note) {
205 note->setTitle(QString::fromStdString(result.title));
206 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));
207 emit noteChanged(note->guid());
208 } else {
209 note = new Note(QString::fromStdString(result.guid), this);
210 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));
211 note->setTitle(QString::fromStdString(result.title));
212 m_notes.insert(note->guid(), note);
213 emit noteAdded(note->guid());
214 }
215 }
216
217 startNextJob();
218}
219
220void NotesStore::refreshNoteContent(const QString &guid)
221{
222 if (m_token.isEmpty()) {
223 qWarning() << "No token set. Cannot fetch note.";
224 return;
225 }
226
227 FetchNoteJob *job = new FetchNoteJob(guid, this);
228 connect(job, &FetchNoteJob::resultReady, this, &NotesStore::fetchNoteJobDone);
229 m_jobQueue.append(job);
230
231 startJobQueue();
232}
233
234void NotesStore::fetchNoteJobDone(ErrorCode errorCode, const evernote::edam::Note &result)
235{
236 if (errorCode != ErrorCodeNoError) {
237 qWarning() << "Error fetching note:" << errorCode;
238 startNextJob();
239 return;
240 }
241
242 Note *note = m_notes.value(QString::fromStdString(result.guid));
243 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));
244 note->setTitle(QString::fromStdString(result.title));
245 note->setContent(QString::fromStdString(result.content));
246 emit noteChanged(note->guid());
247
248 startNextJob();
249}
250
251void NotesStore::refreshNotebooks()
252{
253 if (m_token.isEmpty()) {
254 qWarning() << "No token set. Cannot refresh notebooks.";
255 return;
256 }
257
258 FetchNotebooksJob *job = new FetchNotebooksJob();
259 connect(job, &FetchNotebooksJob::resultReady, this, &NotesStore::fetchNotebooksJobDone);
260
261 m_jobQueue.append(job);
262 startJobQueue();
263}
264
265void NotesStore::fetchNotebooksJobDone(ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results)
266{
267 if (errorCode != ErrorCodeNoError) {
268 qWarning() << "Error fetching notebooks:" << errorCodeToString(errorCode);
269 startNextJob();
270 return;
271 }
272
273 for (int i = 0; i < results.size(); ++i) {
274 evernote::edam::Notebook result = results.at(i);
275 Notebook *notebook = m_notebooks.value(QString::fromStdString(result.guid));
276 if (notebook) {
277 qDebug() << "got notebook update";
278 notebook->setName(QString::fromStdString(result.name));
279 emit notebookChanged(notebook->guid());
280 } else {
281 notebook = new Notebook(QString::fromStdString(result.guid), this);
282 notebook->setName(QString::fromStdString(result.name));
283 m_notebooks.insert(notebook->guid(), notebook);
284 emit notebookAdded(notebook->guid());
285 qDebug() << "got new notebook" << notebook->guid();
286 }
287 }
288
289 startNextJob();
290}
291
292void NotesStore::createNote(const QString &title, const QString &notebookGuid, const QString &content)
293{
294 Note *note = new Note();
295 note->setTitle(title);
296 note->setNotebookGuid(notebookGuid);
297 note->setContent(content);
298 CreateNoteJob *job = new CreateNoteJob(note);
299 connect(job, &CreateNoteJob::resultReady, this, &NotesStore::createNoteJobDone);
300
301 m_jobQueue.append(job);
302 startJobQueue();
303}
304
305void NotesStore::createNoteJobDone(NotesStore::ErrorCode errorCode, Note *note)
306{
307 if (errorCode != ErrorCodeNoError) {
308 qWarning() << "Error creating note:" << errorCodeToString(errorCode);
309 delete note;
310 startNextJob();
311 return;
312 }
313
314 m_notes.insert(note->guid(), note);
315 noteAdded(note->guid());
316 startNextJob();
317}
318
319void NotesStore::saveNoteJobDone(NotesStore::ErrorCode errorCode, Note *note)
320{
321 startNextJob();
322}
323
324void NotesStore::deleteNoteJobDone(NotesStore::ErrorCode errorCode, const QString &guid)
325{
326 if (errorCode != ErrorCodeNoError) {
327 qWarning() << "Cannot delete note:" << errorCodeToString(errorCode);
328 startNextJob();
329 return;
330 }
331 emit noteRemoved(guid);
332 m_notes.take(guid)->deleteLater();
333 startNextJob();
334}
335
140336
=== modified file 'src/plugin/Evernote/notesstore.h'
--- src/plugin/Evernote/notesstore.h 2013-11-21 23:30:15 +0000
+++ src/plugin/Evernote/notesstore.h 2013-11-25 00:51:38 +0000
@@ -6,42 +6,85 @@
6#include <NoteStore_constants.h>6#include <NoteStore_constants.h>
7#include <Errors_types.h>7#include <Errors_types.h>
88
9// Qt
10#include <QObject>9#include <QObject>
1110#include <QHash>
12using namespace evernote::edam;11
1312class EvernoteJob;
14class Notebooks;13
14class Notebook;
15class Note;
1516
16class NotesStore : public QObject17class NotesStore : public QObject
17{18{
18 Q_OBJECT19 Q_OBJECT
19 Q_PROPERTY(QString token READ token WRITE setToken NOTIFY tokenChanged)20 Q_PROPERTY(QString token READ token WRITE setToken NOTIFY tokenChanged)
2021
22 friend class EvernoteJob;
23
21public:24public:
25 enum ErrorCode {
26 ErrorCodeNoError,
27 ErrorCodeUserException,
28 ErrorCodeSystemException,
29 ErrorCodeNotFoundExcpetion,
30 ErrorCodeConnectionLost
31 };
32
33 Q_INVOKABLE void createNote(const QString &title, const QString &notebookGuid, const QString &content);
34
22 static NotesStore *instance();35 static NotesStore *instance();
36 static QString errorCodeToString(ErrorCode errorCode);
2337
24 ~NotesStore();38 ~NotesStore();
2539
26 QString token() const;40 QString token() const;
27 void setToken(const QString &token);41 void setToken(const QString &token);
2842
29 NoteStoreClient *evernoteNotesStoreClient();43 QList<Note*> notes() const;
3044 Note* note(const QString &guid);
31private:45 void saveNote(const QString &guid);
32 explicit NotesStore(QObject *parent = 0);46 void deleteNote(const QString &guid);
47
48 QList<Notebook*> notebooks() const;
49 Notebook* notebook(const QString &guid);
50
51 void refreshNotes(const QString &filterNotebookGuid = QString());
52 void refreshNoteContent(const QString &guid);
53 void refreshNotebooks();
3354
34signals:55signals:
35 void tokenChanged();56 void tokenChanged();
3657
58 void noteAdded(const QString &guid);
59 void noteChanged(const QString &guid);
60 void noteRemoved(const QString &guid);
61
62 void notebookAdded(const QString &guid);
63 void notebookChanged(const QString &guid);
64
65private slots:
66 void fetchNotesJobDone(ErrorCode errorCode, const evernote::edam::NotesMetadataList &results);
67 void fetchNotebooksJobDone(ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results);
68 void fetchNoteJobDone(ErrorCode errorCode, const evernote::edam::Note &result);
69 void createNoteJobDone(ErrorCode errorCode, Note *note);
70 void saveNoteJobDone(ErrorCode errorCode, Note *note);
71 void deleteNoteJobDone(ErrorCode errorCode, const QString &guid);
72
73 void startJobQueue();
74 void startNextJob();
75
37private:76private:
77 explicit NotesStore(QObject *parent = 0);
38 static NotesStore *s_instance;78 static NotesStore *s_instance;
3979
40 void displayException();
41
42 QString m_token;80 QString m_token;
43 NoteStoreClient *m_client;81 evernote::edam::NoteStoreClient *m_client;
4482
83 QHash<QString, Notebook*> m_notebooks;
84 QHash<QString, Note*> m_notes;
85
86 QList<EvernoteJob*> m_jobQueue;
87 QThread *m_currentJob;
45};88};
4689
47#endif // NOTESSTORE_H90#endif // NOTESSTORE_H
4891
=== modified file 'src/plugin/Evernote/userstore.h'
--- src/plugin/Evernote/userstore.h 2013-11-21 23:30:15 +0000
+++ src/plugin/Evernote/userstore.h 2013-11-25 00:51:38 +0000
@@ -5,8 +5,6 @@
55
6#include <QObject>6#include <QObject>
77
8using namespace evernote::edam;
9
10class UserStore : public QObject8class UserStore : public QObject
11{9{
12 Q_OBJECT10 Q_OBJECT

Subscribers

People subscribed via source and target branches