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

Proposed by Michael Zanetti
Status: Merged
Approved by: David Planella
Approved revision: 12
Merged at revision: 10
Proposed branch: lp:~mzanetti/reminders-app/create-edit-delete-notes
Merge into: lp:reminders-app
Prerequisite: lp:~mzanetti/reminders-app/notes-refactor
Diff against target: 967 lines (+466/-90)
24 files modified
src/app/qml/ui/NotePage.qml (+23/-4)
src/app/qml/ui/NotesPage.qml (+25/-0)
src/plugin/Evernote/Evernote.pro (+14/-6)
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 (+3/-5)
src/plugin/Evernote/jobs/fetchnotebooksjob.h (+4/-15)
src/plugin/Evernote/jobs/fetchnotejob.cpp (+9/-8)
src/plugin/Evernote/jobs/fetchnotejob.h (+4/-11)
src/plugin/Evernote/jobs/fetchnotesjob.cpp (+3/-7)
src/plugin/Evernote/jobs/fetchnotesjob.h (+4/-13)
src/plugin/Evernote/jobs/savenotejob.cpp (+40/-0)
src/plugin/Evernote/jobs/savenotejob.h (+20/-0)
src/plugin/Evernote/note.cpp (+20/-0)
src/plugin/Evernote/note.h (+8/-2)
src/plugin/Evernote/notebooks.cpp (+0/-1)
src/plugin/Evernote/notes.cpp (+13/-1)
src/plugin/Evernote/notes.h (+1/-0)
src/plugin/Evernote/notesstore.cpp (+82/-15)
src/plugin/Evernote/notesstore.h (+16/-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 Approve
David Planella Approve
Review via email: mp+196500@code.launchpad.net

This proposal supersedes 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 : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :

FAILED: Continuous integration, rev:12
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~mzanetti/reminders-app/create-edit-delete-notes/+merge/196500/+edit-commit-message

http://91.189.93.70:8080/job/reminders-app-ci/14/
Executed test runs:
    FAILURE: http://91.189.93.70:8080/job/generic-mediumtests-trusty/236/console
    SUCCESS: http://91.189.93.70:8080/job/reminders-app-raring-amd64-ci/14
    SUCCESS: http://91.189.93.70:8080/job/reminders-app-saucy-amd64-ci/14
    SUCCESS: http://91.189.93.70:8080/job/reminders-app-trusty-amd64-ci/14

Click here to trigger a rebuild:
http://91.189.93.70:8080/job/reminders-app-ci/14/rebuild

review: Needs Fixing (continuous-integration)
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
David Planella (dpm) wrote :

Works well here.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/app/qml/ui/NotePage.qml'
--- src/app/qml/ui/NotePage.qml 2013-11-25 09:14:33 +0000
+++ src/app/qml/ui/NotePage.qml 2013-11-25 09:14:33 +0000
@@ -6,11 +6,30 @@
6 title: note.title6 title: note.title
7 property var note7 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)
13 text: note.content12 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 }
14 }33 }
15}34}
1635
1736
=== modified file 'src/app/qml/ui/NotesPage.qml'
--- src/app/qml/ui/NotesPage.qml 2013-11-25 09:14:33 +0000
+++ src/app/qml/ui/NotesPage.qml 2013-11-25 09:14:33 +0000
@@ -8,6 +8,27 @@
88
9 property alias filter: notes.filterNotebookGuid9 property alias filter: notes.filterNotebookGuid
1010
11 onActiveChanged: {
12 if (active) {
13 print("refreshing notes")
14 notes.refresh();
15 }
16 }
17
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
11 Notes {32 Notes {
12 id: notes33 id: notes
13 }34 }
@@ -22,6 +43,10 @@
22 onClicked: {43 onClicked: {
23 pageStack.push(Qt.resolvedUrl("NotePage.qml"), {note: notes.note(guid)})44 pageStack.push(Qt.resolvedUrl("NotePage.qml"), {note: notes.note(guid)})
24 }45 }
46
47 onPressAndHold: {
48 notes.note(guid).remove();
49 }
25 }50 }
26 }51 }
27}52}
2853
=== modified file 'src/plugin/Evernote/Evernote.pro'
--- src/plugin/Evernote/Evernote.pro 2013-11-25 09:14:33 +0000
+++ src/plugin/Evernote/Evernote.pro 2013-11-25 09:14:33 +0000
@@ -16,9 +16,13 @@
16 notes.cpp \16 notes.cpp \
17 note.cpp \17 note.cpp \
18 notebook.cpp \18 notebook.cpp \
19 fetchnotesjob.cpp \19 jobs/fetchnotesjob.cpp \
20 fetchnotebooksjob.cpp \20 jobs/fetchnotebooksjob.cpp \
21 fetchnotejob.cpp21 jobs/fetchnotejob.cpp \
22 jobs/createnotejob.cpp \
23 jobs/evernotejob.cpp \
24 jobs/savenotejob.cpp \
25 jobs/deletenotejob.cpp
2226
23HEADERS += evernoteplugin.h \27HEADERS += evernoteplugin.h \
24 notesstore.h \28 notesstore.h \
@@ -27,9 +31,13 @@
27 notes.h \31 notes.h \
28 note.h \32 note.h \
29 notebook.h \33 notebook.h \
30 fetchnotesjob.h \34 jobs/fetchnotesjob.h \
31 fetchnotebooksjob.h \35 jobs/fetchnotebooksjob.h \
32 fetchnotejob.h36 jobs/fetchnotejob.h \
37 jobs/createnotejob.h \
38 jobs/evernotejob.h \
39 jobs/savenotejob.h \
40 jobs/deletenotejob.h
3341
34message(building in $$OUT_PWD)42message(building in $$OUT_PWD)
35LIBS += -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
3644
=== 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 09:14:33 +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 09:14:33 +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 09:14:33 +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 09:14:33 +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 09:14:33 +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 09:14:33 +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
=== renamed file 'src/plugin/Evernote/fetchnotebooksjob.cpp' => 'src/plugin/Evernote/jobs/fetchnotebooksjob.cpp'
--- src/plugin/Evernote/fetchnotebooksjob.cpp 2013-11-25 09:14:33 +0000
+++ src/plugin/Evernote/jobs/fetchnotebooksjob.cpp 2013-11-25 09:14:33 +0000
@@ -2,10 +2,8 @@
22
3#include <QDebug>3#include <QDebug>
44
5FetchNotebooksJob::FetchNotebooksJob(evernote::edam::NoteStoreClient *client, const QString &token, QObject *parent) :5FetchNotebooksJob::FetchNotebooksJob(QObject *parent) :
6 QThread(parent),6 EvernoteJob(parent)
7 m_client(client),
8 m_token(token)
9{7{
10}8}
119
@@ -15,7 +13,7 @@
15 NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError;13 NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError;
16 std::vector<evernote::edam::Notebook> results;14 std::vector<evernote::edam::Notebook> results;
17 try {15 try {
18 m_client->listNotebooks(results, m_token.toStdString());16 client()->listNotebooks(results, token().toStdString());
19 } catch(evernote::edam::EDAMUserException) {17 } catch(evernote::edam::EDAMUserException) {
20 errorCode = NotesStore::ErrorCodeUserException;18 errorCode = NotesStore::ErrorCodeUserException;
21 } catch(evernote::edam::EDAMSystemException) {19 } catch(evernote::edam::EDAMSystemException) {
2220
=== renamed file 'src/plugin/Evernote/fetchnotebooksjob.h' => 'src/plugin/Evernote/jobs/fetchnotebooksjob.h'
--- src/plugin/Evernote/fetchnotebooksjob.h 2013-11-25 09:14:33 +0000
+++ src/plugin/Evernote/jobs/fetchnotebooksjob.h 2013-11-25 09:14:33 +0000
@@ -1,29 +1,18 @@
1#ifndef FETCHNOTEBOOKSJOB_H1#ifndef FETCHNOTEBOOKSJOB_H
2#define FETCHNOTEBOOKSJOB_H2#define FETCHNOTEBOOKSJOB_H
33
4#include "notesstore.h"4#include "evernotejob.h"
55
6// Evernote SDK6class FetchNotebooksJob : public EvernoteJob
7#include <NoteStore.h>
8#include <NoteStore_constants.h>
9#include <Errors_types.h>
10
11#include <QThread>
12
13class FetchNotebooksJob : public QThread
14{7{
15 Q_OBJECT8 Q_OBJECT
16public:9public:
17 explicit FetchNotebooksJob(evernote::edam::NoteStoreClient *client, const QString &token, QObject *parent = 0);10 explicit FetchNotebooksJob(QObject *parent = 0);
1811
19 void run();12 void run();
2013
21signals:14signals:
22 void resultReady(NotesStore::ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results);15 void resultReady(NotesStore::ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results);
23
24private:
25 evernote::edam::NoteStoreClient *m_client;
26 QString m_token;
27};16};
2817
29#endif // FETCHNOTEBOOKSJOB_H18#endif // FETCHNOTEBOOKSJOB_H
3019
=== renamed file 'src/plugin/Evernote/fetchnotejob.cpp' => 'src/plugin/Evernote/jobs/fetchnotejob.cpp'
--- src/plugin/Evernote/fetchnotejob.cpp 2013-11-25 09:14:33 +0000
+++ src/plugin/Evernote/jobs/fetchnotejob.cpp 2013-11-25 09:14:33 +0000
@@ -1,9 +1,7 @@
1#include "fetchnotejob.h"1#include "fetchnotejob.h"
22
3FetchNoteJob::FetchNoteJob(evernote::edam::NoteStoreClient *client, const QString &token, const QString &guid, QObject *parent) :3FetchNoteJob::FetchNoteJob(const QString &guid, QObject *parent) :
4 QThread(parent),4 EvernoteJob(parent),
5 m_client(client),
6 m_token(token),
7 m_guid(guid)5 m_guid(guid)
8{6{
9}7}
@@ -13,13 +11,16 @@
13 NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError;11 NotesStore::ErrorCode errorCode = NotesStore::ErrorCodeNoError;
14 evernote::edam::Note result;12 evernote::edam::Note result;
15 try {13 try {
16 m_client->getNote(result, m_token.toStdString(), m_guid.toStdString(), true, true, false, false);14 client()->getNote(result, token().toStdString(), m_guid.toStdString(), true, true, false, false);
17 } catch(evernote::edam::EDAMUserException) {15 } catch (evernote::edam::EDAMUserException) {
18 errorCode = NotesStore::ErrorCodeUserException;16 errorCode = NotesStore::ErrorCodeUserException;
19 } catch(evernote::edam::EDAMSystemException) {17 } catch (evernote::edam::EDAMSystemException) {
20 errorCode = NotesStore::ErrorCodeSystemException;18 errorCode = NotesStore::ErrorCodeSystemException;
21 } catch(evernote::edam::EDAMNotFoundException) {19 } catch (evernote::edam::EDAMNotFoundException) {
22 errorCode = NotesStore::ErrorCodeNotFoundExcpetion;20 errorCode = NotesStore::ErrorCodeNotFoundExcpetion;
21 } catch (...) {
22 catchTransportException();
23 errorCode = NotesStore::ErrorCodeConnectionLost;
23 }24 }
2425
25 emit resultReady(errorCode, result);26 emit resultReady(errorCode, result);
2627
=== renamed file 'src/plugin/Evernote/fetchnotejob.h' => 'src/plugin/Evernote/jobs/fetchnotejob.h'
--- src/plugin/Evernote/fetchnotejob.h 2013-11-25 09:14:33 +0000
+++ src/plugin/Evernote/jobs/fetchnotejob.h 2013-11-25 09:14:33 +0000
@@ -1,20 +1,13 @@
1#ifndef FETCHNOTEJOB_H1#ifndef FETCHNOTEJOB_H
2#define FETCHNOTEJOB_H2#define FETCHNOTEJOB_H
33
4#include "notesstore.h"4#include "evernotejob.h"
55
6// Evernote SDK6class FetchNoteJob : public EvernoteJob
7#include <NoteStore.h>
8#include <NoteStore_constants.h>
9#include <Errors_types.h>
10
11#include <QThread>
12
13class FetchNoteJob : public QThread
14{7{
15 Q_OBJECT8 Q_OBJECT
16public:9public:
17 explicit FetchNoteJob(evernote::edam::NoteStoreClient *client, const QString &token, const QString &guid, QObject *parent = 0);10 explicit FetchNoteJob(const QString &guid, QObject *parent = 0);
1811
19 void run();12 void run();
20signals:13signals:
2114
=== renamed file 'src/plugin/Evernote/fetchnotesjob.cpp' => 'src/plugin/Evernote/jobs/fetchnotesjob.cpp'
--- src/plugin/Evernote/fetchnotesjob.cpp 2013-11-25 09:14:33 +0000
+++ src/plugin/Evernote/jobs/fetchnotesjob.cpp 2013-11-25 09:14:33 +0000
@@ -4,12 +4,8 @@
44
5#include <QDebug>5#include <QDebug>
66
7FetchNotesJob::FetchNotesJob(evernote::edam::NoteStoreClient *client,7FetchNotesJob::FetchNotesJob( const QString &filterNotebookGuid, QObject *parent) :
8 const QString &token,8 EvernoteJob(parent),
9 const QString &filterNotebookGuid, QObject *parent) :
10 QThread(parent),
11 m_client(client),
12 m_token(token),
13 m_filterNotebookGuid(filterNotebookGuid)9 m_filterNotebookGuid(filterNotebookGuid)
14{10{
15}11}
@@ -36,7 +32,7 @@
36 evernote::edam::NotesMetadataList results;32 evernote::edam::NotesMetadataList results;
3733
38 try {34 try {
39 m_client->findNotesMetadata(results, m_token.toStdString(), filter, start, end, resultSpec);35 client()->findNotesMetadata(results, token().toStdString(), filter, start, end, resultSpec);
40 } catch(evernote::edam::EDAMUserException) {36 } catch(evernote::edam::EDAMUserException) {
41 errorCode = NotesStore::ErrorCodeUserException;37 errorCode = NotesStore::ErrorCodeUserException;
42 } catch(evernote::edam::EDAMSystemException) {38 } catch(evernote::edam::EDAMSystemException) {
4339
=== renamed file 'src/plugin/Evernote/fetchnotesjob.h' => 'src/plugin/Evernote/jobs/fetchnotesjob.h'
--- src/plugin/Evernote/fetchnotesjob.h 2013-11-25 09:14:33 +0000
+++ src/plugin/Evernote/jobs/fetchnotesjob.h 2013-11-25 09:14:33 +0000
@@ -1,20 +1,13 @@
1#ifndef FETCHNOTESJOB_H1#ifndef FETCHNOTESJOB_H
2#define FETCHNOTESJOB_H2#define FETCHNOTESJOB_H
33
4#include "notesstore.h"4#include "evernotejob.h"
55
6// Evernote SDK6class FetchNotesJob : public EvernoteJob
7#include <NoteStore.h>
8#include <NoteStore_constants.h>
9#include <Errors_types.h>
10
11#include <QThread>
12
13class FetchNotesJob : public QThread
14{7{
15 Q_OBJECT8 Q_OBJECT
16public:9public:
17 explicit FetchNotesJob(evernote::edam::NoteStoreClient *client, const QString &token, const QString &filterNotebookGuid, QObject *parent = 0);10 explicit FetchNotesJob(const QString &filterNotebookGuid, QObject *parent = 0);
1811
19 void run();12 void run();
2013
@@ -22,8 +15,6 @@
22 void resultReady(NotesStore::ErrorCode errorCode, const evernote::edam::NotesMetadataList &results);15 void resultReady(NotesStore::ErrorCode errorCode, const evernote::edam::NotesMetadataList &results);
2316
24private:17private:
25 evernote::edam::NoteStoreClient *m_client;
26 QString m_token;
27 QString m_filterNotebookGuid;18 QString m_filterNotebookGuid;
28};19};
2920
3021
=== 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 09:14:33 +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 09:14:33 +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
=== modified file 'src/plugin/Evernote/note.cpp'
--- src/plugin/Evernote/note.cpp 2013-11-25 09:14:33 +0000
+++ src/plugin/Evernote/note.cpp 2013-11-25 09:14:33 +0000
@@ -1,5 +1,7 @@
1#include "note.h"1#include "note.h"
22
3#include "notesstore.h"
4
3Note::Note(const QString &guid, QObject *parent) :5Note::Note(const QString &guid, QObject *parent) :
4 QObject(parent),6 QObject(parent),
5 m_guid(guid)7 m_guid(guid)
@@ -11,6 +13,14 @@
11 return m_guid;13 return m_guid;
12}14}
1315
16void Note::setGuid(const QString &guid)
17{
18 if (m_guid == guid) {
19 m_guid = guid;
20 emit guidChanged();
21 }
22}
23
14QString Note::notebookGuid() const24QString Note::notebookGuid() const
15{25{
16 return m_notebookGuid;26 return m_notebookGuid;
@@ -49,3 +59,13 @@
49 emit contentChanged();59 emit contentChanged();
50 }60 }
51}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}
5272
=== modified file 'src/plugin/Evernote/note.h'
--- src/plugin/Evernote/note.h 2013-11-25 09:14:33 +0000
+++ src/plugin/Evernote/note.h 2013-11-25 09:14:33 +0000
@@ -7,14 +7,15 @@
7{7{
8 Q_OBJECT8 Q_OBJECT
99
10 Q_PROPERTY(QString guid READ guid CONSTANT)10 Q_PROPERTY(QString guid READ guid NOTIFY guidChanged)
11 Q_PROPERTY(QString notebookGuid READ notebookGuid WRITE setNotebookGuid NOTIFY notebookGuidChanged)11 Q_PROPERTY(QString notebookGuid READ notebookGuid WRITE setNotebookGuid NOTIFY notebookGuidChanged)
12 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)12 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
13 Q_PROPERTY(QString content READ content WRITE setContent NOTIFY contentChanged)13 Q_PROPERTY(QString content READ content WRITE setContent NOTIFY contentChanged)
14public:14public:
15 explicit Note(const QString &guid, QObject *parent = 0);15 explicit Note(const QString &guid = QString(), QObject *parent = 0);
1616
17 QString guid() const;17 QString guid() const;
18 void setGuid(const QString &guid);
1819
19 QString notebookGuid() const;20 QString notebookGuid() const;
20 void setNotebookGuid(const QString &notebookGuid);21 void setNotebookGuid(const QString &notebookGuid);
@@ -25,7 +26,12 @@
25 QString content() const;26 QString content() const;
26 void setContent(const QString &content);27 void setContent(const QString &content);
2728
29public slots:
30 void save();
31 void remove();
32
28signals:33signals:
34 void guidChanged();
29 void titleChanged();35 void titleChanged();
30 void notebookGuidChanged();36 void notebookGuidChanged();
31 void contentChanged();37 void contentChanged();
3238
=== modified file 'src/plugin/Evernote/notebooks.cpp'
--- src/plugin/Evernote/notebooks.cpp 2013-11-25 09:14:33 +0000
+++ src/plugin/Evernote/notebooks.cpp 2013-11-25 09:14:33 +0000
@@ -41,7 +41,6 @@
4141
42void Notebooks::refresh()42void Notebooks::refresh()
43{43{
44 qDebug() << "refreshing notebooks";
45 NotesStore::instance()->refreshNotebooks();44 NotesStore::instance()->refreshNotebooks();
46}45}
4746
4847
=== modified file 'src/plugin/Evernote/notes.cpp'
--- src/plugin/Evernote/notes.cpp 2013-11-25 09:14:33 +0000
+++ src/plugin/Evernote/notes.cpp 2013-11-25 09:14:33 +0000
@@ -6,7 +6,9 @@
6Notes::Notes(QObject *parent) :6Notes::Notes(QObject *parent) :
7 QAbstractListModel(parent)7 QAbstractListModel(parent)
8{8{
9 connect(NotesStore::instance(), SIGNAL(noteAdded(const QString &)), SLOT(noteAdded(const QString &)));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);
10}12}
1113
12QVariant Notes::data(const QModelIndex &index, int role) const14QVariant Notes::data(const QModelIndex &index, int role) const
@@ -85,3 +87,13 @@
85 emit dataChanged(index(row), index(row));87 emit dataChanged(index(row), index(row));
86 }88 }
87}89}
90
91void Notes::noteRemoved(const QString &guid)
92{
93 int index = m_list.indexOf(guid);
94 if (index >= 0) {
95 beginRemoveRows(QModelIndex(), index, index);
96 m_list.removeAt(index);
97 endRemoveRows();
98 }
99}
88100
=== modified file 'src/plugin/Evernote/notes.h'
--- src/plugin/Evernote/notes.h 2013-11-25 09:14:33 +0000
+++ src/plugin/Evernote/notes.h 2013-11-25 09:14:33 +0000
@@ -35,6 +35,7 @@
35private slots:35private slots:
36 void noteAdded(const QString &guid);36 void noteAdded(const QString &guid);
37 void noteChanged(const QString &guid);37 void noteChanged(const QString &guid);
38 void noteRemoved(const QString &guid);
3839
39signals:40signals:
40 void filterNotebookGuidChanged();41 void filterNotebookGuidChanged();
4142
=== modified file 'src/plugin/Evernote/notesstore.cpp'
--- src/plugin/Evernote/notesstore.cpp 2013-11-25 09:14:33 +0000
+++ src/plugin/Evernote/notesstore.cpp 2013-11-25 09:14:33 +0000
@@ -3,9 +3,12 @@
3#include "notebook.h"3#include "notebook.h"
4#include "note.h"4#include "note.h"
55
6#include "fetchnotesjob.h"6#include "jobs/fetchnotesjob.h"
7#include "fetchnotebooksjob.h"7#include "jobs/fetchnotebooksjob.h"
8#include "fetchnotejob.h"8#include "jobs/fetchnotejob.h"
9#include "jobs/createnotejob.h"
10#include "jobs/savenotejob.h"
11#include "jobs/deletenotejob.h"
912
10// Thrift13// Thrift
11#include <arpa/inet.h> // seems thrift forgot this one14#include <arpa/inet.h> // seems thrift forgot this one
@@ -127,6 +130,23 @@
127 return m_notes.value(guid);130 return m_notes.value(guid);
128}131}
129132
133void NotesStore::saveNote(const QString &guid)
134{
135 Note *note = m_notes.value(guid);
136 SaveNoteJob *job = new SaveNoteJob(note, this);
137 connect(job, &SaveNoteJob::resultReady, this, &NotesStore::saveNoteJobDone);
138 m_jobQueue.append(job);
139 startJobQueue();
140}
141
142void NotesStore::deleteNote(const QString &guid)
143{
144 DeleteNoteJob *job = new DeleteNoteJob(guid, this);
145 connect(job, &DeleteNoteJob::resultReady, this, &NotesStore::deleteNoteJobDone);
146 m_jobQueue.append(job);
147 startJobQueue();
148}
149
130QList<Notebook *> NotesStore::notebooks() const150QList<Notebook *> NotesStore::notebooks() const
131{151{
132 return m_notebooks.values();152 return m_notebooks.values();
@@ -139,14 +159,14 @@
139159
140void NotesStore::startJobQueue()160void NotesStore::startJobQueue()
141{161{
142 if (m_requestQueue.isEmpty()) {162 if (m_jobQueue.isEmpty()) {
143 return;163 return;
144 }164 }
145165
146 if (m_currentJob) {166 if (m_currentJob) {
147 return;167 return;
148 }168 }
149 m_currentJob = m_requestQueue.takeFirst();169 m_currentJob = m_jobQueue.takeFirst();
150 m_currentJob->start();170 m_currentJob->start();
151}171}
152172
@@ -163,11 +183,10 @@
163 return;183 return;
164 }184 }
165185
166 FetchNotesJob *job = new FetchNotesJob(m_client, m_token, filterNotebookGuid);186 FetchNotesJob *job = new FetchNotesJob(filterNotebookGuid);
167 connect(job, &FetchNotesJob::resultReady, this, &NotesStore::fetchNotesJobDone);187 connect(job, &FetchNotesJob::resultReady, this, &NotesStore::fetchNotesJobDone);
168 connect(job, &FetchNoteJob::finished, job, &FetchNotesJob::deleteLater);
169188
170 m_requestQueue.append(job);189 m_jobQueue.append(job);
171 startJobQueue();190 startJobQueue();
172}191}
173192
@@ -183,7 +202,9 @@
183 evernote::edam::NoteMetadata result = results.notes.at(i);202 evernote::edam::NoteMetadata result = results.notes.at(i);
184 Note *note = m_notes.value(QString::fromStdString(result.guid));203 Note *note = m_notes.value(QString::fromStdString(result.guid));
185 if (note) {204 if (note) {
186 qDebug() << "Received update for existing note";205 note->setTitle(QString::fromStdString(result.title));
206 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));
207 emit noteChanged(note->guid());
187 } else {208 } else {
188 note = new Note(QString::fromStdString(result.guid), this);209 note = new Note(QString::fromStdString(result.guid), this);
189 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));210 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));
@@ -203,10 +224,9 @@
203 return;224 return;
204 }225 }
205226
206 FetchNoteJob *job = new FetchNoteJob(m_client, m_token, guid, this);227 FetchNoteJob *job = new FetchNoteJob(guid, this);
207 connect(job, &FetchNoteJob::resultReady, this, &NotesStore::fetchNoteJobDone);228 connect(job, &FetchNoteJob::resultReady, this, &NotesStore::fetchNoteJobDone);
208 connect(job, &FetchNoteJob::finished, job, &FetchNoteJob::deleteLater);229 m_jobQueue.append(job);
209 m_requestQueue.append(job);
210230
211 startJobQueue();231 startJobQueue();
212}232}
@@ -235,11 +255,10 @@
235 return;255 return;
236 }256 }
237257
238 FetchNotebooksJob *job = new FetchNotebooksJob(m_client, m_token);258 FetchNotebooksJob *job = new FetchNotebooksJob();
239 connect(job, &FetchNotebooksJob::resultReady, this, &NotesStore::fetchNotebooksJobDone);259 connect(job, &FetchNotebooksJob::resultReady, this, &NotesStore::fetchNotebooksJobDone);
240 connect(job, &FetchNotebooksJob::finished, job, &FetchNotebooksJob::deleteLater);
241260
242 m_requestQueue.append(job);261 m_jobQueue.append(job);
243 startJobQueue();262 startJobQueue();
244}263}
245264
@@ -256,13 +275,61 @@
256 Notebook *notebook = m_notebooks.value(QString::fromStdString(result.guid));275 Notebook *notebook = m_notebooks.value(QString::fromStdString(result.guid));
257 if (notebook) {276 if (notebook) {
258 qDebug() << "got notebook update";277 qDebug() << "got notebook update";
278 notebook->setName(QString::fromStdString(result.name));
279 emit notebookChanged(notebook->guid());
259 } else {280 } else {
260 notebook = new Notebook(QString::fromStdString(result.guid), this);281 notebook = new Notebook(QString::fromStdString(result.guid), this);
261 notebook->setName(QString::fromStdString(result.name));282 notebook->setName(QString::fromStdString(result.name));
262 m_notebooks.insert(notebook->guid(), notebook);283 m_notebooks.insert(notebook->guid(), notebook);
263 emit notebookAdded(notebook->guid());284 emit notebookAdded(notebook->guid());
285 qDebug() << "got new notebook" << notebook->guid();
264 }286 }
265 }287 }
266288
267 startNextJob();289 startNextJob();
268}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
269336
=== modified file 'src/plugin/Evernote/notesstore.h'
--- src/plugin/Evernote/notesstore.h 2013-11-25 09:14:33 +0000
+++ src/plugin/Evernote/notesstore.h 2013-11-25 09:14:33 +0000
@@ -9,6 +9,8 @@
9#include <QObject>9#include <QObject>
10#include <QHash>10#include <QHash>
1111
12class EvernoteJob;
13
12class Notebook;14class Notebook;
13class Note;15class Note;
1416
@@ -17,14 +19,19 @@
17 Q_OBJECT19 Q_OBJECT
18 Q_PROPERTY(QString token READ token WRITE setToken NOTIFY tokenChanged)20 Q_PROPERTY(QString token READ token WRITE setToken NOTIFY tokenChanged)
1921
22 friend class EvernoteJob;
23
20public:24public:
21 enum ErrorCode {25 enum ErrorCode {
22 ErrorCodeNoError,26 ErrorCodeNoError,
23 ErrorCodeUserException,27 ErrorCodeUserException,
24 ErrorCodeSystemException,28 ErrorCodeSystemException,
25 ErrorCodeNotFoundExcpetion29 ErrorCodeNotFoundExcpetion,
30 ErrorCodeConnectionLost
26 };31 };
2732
33 Q_INVOKABLE void createNote(const QString &title, const QString &notebookGuid, const QString &content);
34
28 static NotesStore *instance();35 static NotesStore *instance();
29 static QString errorCodeToString(ErrorCode errorCode);36 static QString errorCodeToString(ErrorCode errorCode);
3037
@@ -35,6 +42,8 @@
3542
36 QList<Note*> notes() const;43 QList<Note*> notes() const;
37 Note* note(const QString &guid);44 Note* note(const QString &guid);
45 void saveNote(const QString &guid);
46 void deleteNote(const QString &guid);
3847
39 QList<Notebook*> notebooks() const;48 QList<Notebook*> notebooks() const;
40 Notebook* notebook(const QString &guid);49 Notebook* notebook(const QString &guid);
@@ -48,13 +57,18 @@
4857
49 void noteAdded(const QString &guid);58 void noteAdded(const QString &guid);
50 void noteChanged(const QString &guid);59 void noteChanged(const QString &guid);
60 void noteRemoved(const QString &guid);
5161
52 void notebookAdded(const QString &guid);62 void notebookAdded(const QString &guid);
63 void notebookChanged(const QString &guid);
5364
54private slots:65private slots:
55 void fetchNotesJobDone(ErrorCode errorCode, const evernote::edam::NotesMetadataList &results);66 void fetchNotesJobDone(ErrorCode errorCode, const evernote::edam::NotesMetadataList &results);
56 void fetchNotebooksJobDone(ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results);67 void fetchNotebooksJobDone(ErrorCode errorCode, const std::vector<evernote::edam::Notebook> &results);
57 void fetchNoteJobDone(ErrorCode errorCode, const evernote::edam::Note &result);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);
5872
59 void startJobQueue();73 void startJobQueue();
60 void startNextJob();74 void startNextJob();
@@ -69,7 +83,7 @@
69 QHash<QString, Notebook*> m_notebooks;83 QHash<QString, Notebook*> m_notebooks;
70 QHash<QString, Note*> m_notes;84 QHash<QString, Note*> m_notes;
7185
72 QList<QThread*> m_requestQueue;86 QList<EvernoteJob*> m_jobQueue;
73 QThread *m_currentJob;87 QThread *m_currentJob;
74};88};
7589

Subscribers

People subscribed via source and target branches