Merge lp:~mzanetti/reminders-app/add-reminders into lp:reminders-app

Proposed by Michael Zanetti
Status: Merged
Approved by: Michael Zanetti
Approved revision: 19
Merged at revision: 17
Proposed branch: lp:~mzanetti/reminders-app/add-reminders
Merge into: lp:reminders-app
Prerequisite: lp:~mzanetti/reminders-app/get-username
Diff against target: 952 lines (+375/-195)
13 files modified
src/app/qml/ui/NotesPage.qml (+2/-3)
src/app/qml/ui/RemindersPage.qml (+9/-10)
src/plugin/Evernote/jobs/evernotejob.cpp (+1/-1)
src/plugin/Evernote/jobs/fetchnotesjob.cpp (+13/-3)
src/plugin/Evernote/jobs/savenotejob.cpp (+22/-13)
src/plugin/Evernote/jobs/savenotejob.h (+2/-6)
src/plugin/Evernote/note.cpp (+90/-10)
src/plugin/Evernote/note.h (+44/-4)
src/plugin/Evernote/notebooks.cpp (+0/-1)
src/plugin/Evernote/notes.cpp (+38/-80)
src/plugin/Evernote/notes.h (+11/-24)
src/plugin/Evernote/notesstore.cpp (+116/-31)
src/plugin/Evernote/notesstore.h (+27/-9)
To merge this branch: bzr merge lp:~mzanetti/reminders-app/add-reminders
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Jordan Keyes Approve
Review via email: mp+197261@code.launchpad.net

Commit message

Add support for reminders

Description of the change

This adds support for reminders.

Also moves the QAbstractListModel logic into notesstore, so that Notes is just a stupid QSortFilterProxyModel. This additionally has the benefit that we can easily filter for notebookGuid or the reminder flag (and in the future for tags) and sort the model according to the note creation timestamp (or whatever we need in the future).

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

fix savenotejob to also store reminder stuff

18. By Michael Zanetti

delete note clone after savejob is done

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
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Jordan Keyes (jkeyes0) wrote :

Maybe this is by design, but when you select a note from the Notes tab, then click the "Save" button (or make a change to the text and click "Save"), it adds a reminder to the note. I haven't noticed this behavior from other Evernote clients.
It appears this was added in src/plugin/Evernote/jobs/savenotejob.cpp, in void SaveNoteJob::startJob(), but my C++ is definitely a bit rusty.

Is this something that will need to be pulled out and put into a separate job for when a new reminder is created?

Revision history for this message
Michael Zanetti (mzanetti) wrote :

> Maybe this is by design, but when you select a note from the Notes tab, then
> click the "Save" button (or make a change to the text and click "Save"), it
> adds a reminder to the note. I haven't noticed this behavior from other
> Evernote clients.

No, this is a bug in my code. Thanks for finding!

> It appears this was added in src/plugin/Evernote/jobs/savenotejob.cpp, in void
> SaveNoteJob::startJob(), but my C++ is definitely a bit rusty.
>
> Is this something that will need to be pulled out and put into a separate job
> for when a new reminder is created?

Not really no, we just need initialize it with some sane defaults... I'll fix tonight.

Btw. feel free to put "Needs fixing" on my merges. If really unsure, mark it as "Needs information". I'm thankful for every found issue. After all that's what those merge requests are for.

19. By Michael Zanetti

fix reminder flag when saving notes

Revision history for this message
Michael Zanetti (mzanetti) wrote :

> Maybe this is by design, but when you select a note from the Notes tab, then
> click the "Save" button (or make a change to the text and click "Save"), it
> adds a reminder to the note. I haven't noticed this behavior from other
> Evernote clients.

fixed

Revision history for this message
Jordan Keyes (jkeyes0) wrote :

Looks good here.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/app/qml/ui/NotesPage.qml'
--- src/app/qml/ui/NotesPage.qml 2013-11-26 17:18:33 +0000
+++ src/app/qml/ui/NotesPage.qml 2013-12-12 21:36:37 +0000
@@ -28,8 +28,7 @@
2828
29 onActiveChanged: {29 onActiveChanged: {
30 if (active) {30 if (active) {
31 print("refreshing notes")31 NotesStore.refreshNotes();
32 notes.refresh();
33 }32 }
34 }33 }
3534
@@ -59,7 +58,7 @@
59 text: title58 text: title
6059
61 onClicked: {60 onClicked: {
62 pageStack.push(Qt.resolvedUrl("NotePage.qml"), {note: notes.note(guid)})61 pageStack.push(Qt.resolvedUrl("NotePage.qml"), {note: NotesStore.note(guid)})
63 }62 }
6463
65 onPressAndHold: {64 onPressAndHold: {
6665
=== modified file 'src/app/qml/ui/RemindersPage.qml'
--- src/app/qml/ui/RemindersPage.qml 2013-11-26 17:18:33 +0000
+++ src/app/qml/ui/RemindersPage.qml 2013-12-12 21:36:37 +0000
@@ -19,28 +19,27 @@
19import QtQuick 2.019import QtQuick 2.0
20import Ubuntu.Components 0.120import Ubuntu.Components 0.1
21import Ubuntu.Components.ListItems 0.121import Ubuntu.Components.ListItems 0.1
22//import "../components"22import Evernote 0.1
2323
24Page {24Page {
25 id: remindersPage25 id: remindersPage
2626
27 Label {27 Notes {
28 id: developmentWarning28 id: notes
29 anchors.centerIn: parent29 onlyReminders: true
30 text: i18n.tr("This page is still in development")
31 }30 }
3231
33 ListView {32 ListView {
3433
35 width: parent.width; height: parent.height34 anchors.fill: parent
3635
37 delegate: Subtitled {36 delegate: Subtitled {
38 text: '<b>Name:</b> ' + model.name37 text: '<b>Name:</b> ' + model.title
39 subText: '<b>Date:</b> ' + model.date38 subText: '<b>Date:</b> ' + Qt.formatDateTime(model.created) +
39 (model.reminderDone ? " - <b>Done:</b> " + Qt.formatDate(model.reminderDoneTime) : "")
40 }40 }
4141
42// model: RemindersModel {}42 model: notes
43
44 }43 }
4544
46}45}
4746
=== modified file 'src/plugin/Evernote/jobs/evernotejob.cpp'
--- src/plugin/Evernote/jobs/evernotejob.cpp 2013-12-12 21:36:37 +0000
+++ src/plugin/Evernote/jobs/evernotejob.cpp 2013-12-12 21:36:37 +0000
@@ -48,7 +48,7 @@
48void EvernoteJob::run()48void EvernoteJob::run()
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. (" << this->metaObject()->className() << ")";
52 emitJobDone(EvernoteConnection::ErrorCodeUserException, QStringLiteral("No token set."));52 emitJobDone(EvernoteConnection::ErrorCodeUserException, QStringLiteral("No token set."));
53 return;53 return;
54 }54 }
5555
=== modified file 'src/plugin/Evernote/jobs/fetchnotesjob.cpp'
--- src/plugin/Evernote/jobs/fetchnotesjob.cpp 2013-12-12 21:36:37 +0000
+++ src/plugin/Evernote/jobs/fetchnotesjob.cpp 2013-12-12 21:36:37 +0000
@@ -22,6 +22,9 @@
2222
23#include "notesstore.h"23#include "notesstore.h"
2424
25// evernote sdk
26#include "Limits_constants.h"
27
25#include <QDebug>28#include <QDebug>
2629
27FetchNotesJob::FetchNotesJob( const QString &filterNotebookGuid, QObject *parent) :30FetchNotesJob::FetchNotesJob( const QString &filterNotebookGuid, QObject *parent) :
@@ -32,10 +35,10 @@
3235
33void FetchNotesJob::startJob()36void FetchNotesJob::startJob()
34{37{
35 qDebug() << "starting fetch notes job";
36 // TODO: fix start/end (use smaller chunks and continue fetching if there are more notes available)38 // TODO: fix start/end (use smaller chunks and continue fetching if there are more notes available)
37 int32_t start = 0;39 int32_t start = 0;
38 int32_t end = 10000;40 evernote::limits::LimitsConstants limits;
41 int32_t end = limits.EDAM_USER_NOTES_MAX;
3942
40 // Prepare filter43 // Prepare filter
41 evernote::edam::NoteFilter filter;44 evernote::edam::NoteFilter filter;
@@ -44,13 +47,20 @@
4447
45 // Prepare ResultSpec48 // Prepare ResultSpec
46 evernote::edam::NotesMetadataResultSpec resultSpec;49 evernote::edam::NotesMetadataResultSpec resultSpec;
50
47 resultSpec.includeNotebookGuid = true;51 resultSpec.includeNotebookGuid = true;
48 resultSpec.__isset.includeNotebookGuid = true;52 resultSpec.__isset.includeNotebookGuid = true;
53
54 resultSpec.includeCreated = true;
55 resultSpec.__isset.includeCreated = true;
56
49 resultSpec.includeTitle = true;57 resultSpec.includeTitle = true;
50 resultSpec.__isset.includeTitle = true;58 resultSpec.__isset.includeTitle = true;
5159
60 resultSpec.includeAttributes = true;
61 resultSpec.__isset.includeAttributes = true;
62
52 client()->findNotesMetadata(m_results, token().toStdString(), filter, start, end, resultSpec);63 client()->findNotesMetadata(m_results, token().toStdString(), filter, start, end, resultSpec);
53 qDebug() << "ending fetch notes job";
54}64}
5565
56void FetchNotesJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)66void FetchNotesJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
5767
=== modified file 'src/plugin/Evernote/jobs/savenotejob.cpp'
--- src/plugin/Evernote/jobs/savenotejob.cpp 2013-12-12 21:36:37 +0000
+++ src/plugin/Evernote/jobs/savenotejob.cpp 2013-12-12 21:36:37 +0000
@@ -24,31 +24,40 @@
24#include <QDebug>24#include <QDebug>
2525
26SaveNoteJob::SaveNoteJob(Note *note, QObject *parent) :26SaveNoteJob::SaveNoteJob(Note *note, QObject *parent) :
27 NotesStoreJob(parent),27 NotesStoreJob(parent)
28 m_guid(note->guid()),
29 m_title(note->title()),
30 m_notebookGuid(note->notebookGuid()),
31 m_content(note->content())
32{28{
29 // Need to clone it. As startJob() will run in another thread we can't access the real note from there.
30 m_note = note->clone();
31
32 // Make sure we delete the clone when done
33 m_note->setParent(this);
33}34}
3435
35void SaveNoteJob::startJob()36void SaveNoteJob::startJob()
36{37{
37 evernote::edam::Note note;38 evernote::edam::Note note;
38 note.guid = m_guid.toStdString();39 note.guid = m_note->guid().toStdString();
39 note.__isset.guid = true;40 note.__isset.guid = true;
40 note.title = m_title.toStdString();41 note.title = m_note->title().toStdString();
41 note.__isset.title = true;42 note.__isset.title = true;
42 note.notebookGuid = m_notebookGuid.toStdString();43 note.notebookGuid = m_note->notebookGuid().toStdString();
43 note.__isset.notebookGuid = true;44 note.__isset.notebookGuid = true;
44 note.content = m_content.toStdString();45 note.content = m_note->content().toStdString();
45 note.__isset.content = true;46 note.__isset.content = true;
46 note.contentLength = m_content.length();47 note.contentLength = m_note->content().length();
4748
48 client()->updateNote(m_note, token().toStdString(), note);49 note.__isset.attributes = true;
50 note.attributes.reminderOrder = m_note->reminderOrder();
51 note.attributes.__isset.reminderOrder = true;
52 note.attributes.reminderTime = m_note->reminderTime().toMSecsSinceEpoch();
53 note.attributes.__isset.reminderTime = true;
54 note.attributes.reminderDoneTime = m_note->reminderDoneTime().toMSecsSinceEpoch();
55 note.attributes.__isset.reminderDoneTime = true;
56
57 client()->updateNote(m_resultNote, token().toStdString(), note);
49}58}
5059
51void SaveNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)60void SaveNoteJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
52{61{
53 emit jobDone(errorCode, errorMessage, m_note);62 emit jobDone(errorCode, errorMessage, m_resultNote);
54}63}
5564
=== modified file 'src/plugin/Evernote/jobs/savenotejob.h'
--- src/plugin/Evernote/jobs/savenotejob.h 2013-12-12 21:36:37 +0000
+++ src/plugin/Evernote/jobs/savenotejob.h 2013-12-12 21:36:37 +0000
@@ -17,12 +17,8 @@
17 void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);17 void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
1818
19private:19private:
20 QString m_guid;20 Note* m_note;
21 QString m_title;21 evernote::edam::Note m_resultNote;
22 QString m_notebookGuid;
23 QString m_content;
24
25 evernote::edam::Note m_note;
26};22};
2723
28#endif // SAVENOTEJOB_H24#endif // SAVENOTEJOB_H
2925
=== modified file 'src/plugin/Evernote/note.cpp'
--- src/plugin/Evernote/note.cpp 2013-12-12 21:36:37 +0000
+++ src/plugin/Evernote/note.cpp 2013-12-12 21:36:37 +0000
@@ -22,9 +22,12 @@
2222
23#include "notesstore.h"23#include "notesstore.h"
2424
25Note::Note(const QString &guid, QObject *parent) :25#include <QDateTime>
26
27Note::Note(const QString &guid, const QDateTime &created, QObject *parent) :
26 QObject(parent),28 QObject(parent),
27 m_guid(guid)29 m_guid(guid),
30 m_created(created)
28{31{
29}32}
3033
@@ -33,14 +36,6 @@
33 return m_guid;36 return m_guid;
34}37}
3538
36void Note::setGuid(const QString &guid)
37{
38 if (m_guid != guid) {
39 m_guid = guid;
40 emit guidChanged();
41 }
42}
43
44QString Note::notebookGuid() const39QString Note::notebookGuid() const
45{40{
46 return m_notebookGuid;41 return m_notebookGuid;
@@ -54,6 +49,11 @@
54 }49 }
55}50}
5651
52QDateTime Note::created() const
53{
54 return m_created;
55}
56
57QString Note::title() const57QString Note::title() const
58{58{
59 return m_title;59 return m_title;
@@ -80,6 +80,86 @@
80 }80 }
81}81}
8282
83bool Note::reminder() const
84{
85 return m_reminderOrder > 0;
86}
87
88void Note::setReminder(bool reminder)
89{
90 if (reminder && m_reminderOrder == 0) {
91 m_reminderOrder = QDateTime::currentMSecsSinceEpoch();
92 emit reminderChanged();
93 } else if (!reminder && m_reminderOrder > 0) {
94 m_reminderOrder = 0;
95 emit reminderChanged();
96 }
97}
98
99qint64 Note::reminderOrder() const
100{
101 return m_reminderOrder;
102}
103
104void Note::setReminderOrder(qint64 reminderOrder)
105{
106 if (m_reminderOrder != reminderOrder) {
107 m_reminderOrder = reminderOrder;
108 emit reminderChanged();
109 }
110}
111
112QDateTime Note::reminderTime() const
113{
114 return m_reminderTime;
115}
116
117void Note::setReminderTime(const QDateTime &reminderTime)
118{
119 if (m_reminderTime != reminderTime) {
120 m_reminderTime = reminderTime;
121 emit reminderTimeChanged();
122 }
123}
124
125bool Note::reminderDone() const
126{
127 return !m_reminderDoneTime.isNull();
128}
129
130void Note::setReminderDone(bool reminderDone)
131{
132 if (reminderDone && m_reminderDoneTime.isNull()) {
133 m_reminderDoneTime = QDateTime::currentDateTime();
134 emit reminderDoneChanged();
135 }
136}
137
138QDateTime Note::reminderDoneTime() const
139{
140 return m_reminderDoneTime;
141}
142
143void Note::setReminderDoneTime(const QDateTime &reminderDoneTime)
144{
145 if (m_reminderDoneTime != reminderDoneTime) {
146 m_reminderDoneTime = reminderDoneTime;
147 emit reminderDoneChanged();
148 }
149}
150
151Note *Note::clone()
152{
153 Note *note = new Note(m_guid, m_created);
154 note->setNotebookGuid(m_notebookGuid);
155 note->setTitle(m_title);
156 note->setContent(m_content);
157 note->setReminderOrder(m_reminderOrder);
158 note->setReminderTime(m_reminderTime);
159 note->setReminderDoneTime(m_reminderDoneTime);
160 return note;
161}
162
83void Note::save()163void Note::save()
84{164{
85 NotesStore::instance()->saveNote(m_guid);165 NotesStore::instance()->saveNote(m_guid);
86166
=== modified file 'src/plugin/Evernote/note.h'
--- src/plugin/Evernote/note.h 2013-11-25 00:49:48 +0000
+++ src/plugin/Evernote/note.h 2013-12-12 21:36:37 +0000
@@ -2,45 +2,85 @@
2#define NOTE_H2#define NOTE_H
33
4#include <QObject>4#include <QObject>
5#include <QDateTime>
6#include <QStringList>
57
6class Note : public QObject8class Note : public QObject
7{9{
8 Q_OBJECT10 Q_OBJECT
911
10 Q_PROPERTY(QString guid READ guid NOTIFY guidChanged)12 // Don't forget to update clone() if you add properties!
13 Q_PROPERTY(QString guid READ guid CONSTANT)
11 Q_PROPERTY(QString notebookGuid READ notebookGuid WRITE setNotebookGuid NOTIFY notebookGuidChanged)14 Q_PROPERTY(QString notebookGuid READ notebookGuid WRITE setNotebookGuid NOTIFY notebookGuidChanged)
15 Q_PROPERTY(QDateTime created READ created CONSTANT)
12 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)16 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
13 Q_PROPERTY(QString content READ content WRITE setContent NOTIFY contentChanged)17 Q_PROPERTY(QString content READ content WRITE setContent NOTIFY contentChanged)
18 Q_PROPERTY(bool reminder READ reminder WRITE setReminder NOTIFY reminderChanged)
19 Q_PROPERTY(QDateTime reminderTime READ reminderTime WRITE setReminderTime NOTIFY reminderTimeChanged)
20 Q_PROPERTY(bool reminderDone READ reminderDone WRITE setReminderDone NOTIFY reminderDoneChanged)
21 Q_PROPERTY(QDateTime reminderDoneTime READ reminderDoneTime WRITE setReminderDoneTime NOTIFY reminderDoneChanged)
22 // Don't forget to update clone() if you add properties!
23
14public:24public:
15 explicit Note(const QString &guid = QString(), QObject *parent = 0);25 explicit Note(const QString &guid, const QDateTime &created, QObject *parent = 0);
1626
17 QString guid() const;27 QString guid() const;
18 void setGuid(const QString &guid);
1928
20 QString notebookGuid() const;29 QString notebookGuid() const;
21 void setNotebookGuid(const QString &notebookGuid);30 void setNotebookGuid(const QString &notebookGuid);
2231
32 QDateTime created() const;
33
23 QString title() const;34 QString title() const;
24 void setTitle(const QString &title);35 void setTitle(const QString &title);
2536
26 QString content() const;37 QString content() const;
27 void setContent(const QString &content);38 void setContent(const QString &content);
2839
40 // This is the QML representation as we don't want to deal with timestamps there.
41 // setting it to false will reset the reminderOrder to 0, setting it to true will
42 // create a new timestamp for it.
43 bool reminder() const;
44 void setReminder(bool reminder);
45
46 qint64 reminderOrder() const;
47 void setReminderOrder(qint64 reminderOrder);
48
49 QDateTime reminderTime() const;
50 void setReminderTime(const QDateTime &reminderTime);
51
52 // This is the QML representation as we don't want to deal with timestamps there.
53 // setting it to false will reset reminderDoneTime to 0, setting it to true will
54 // create a new timestamp for it.
55 bool reminderDone() const;
56 void setReminderDone(bool reminderDone);
57
58 QDateTime reminderDoneTime() const;
59 void setReminderDoneTime(const QDateTime &reminderDoneTime);
60
61 Note* clone();
62
29public slots:63public slots:
30 void save();64 void save();
31 void remove();65 void remove();
3266
33signals:67signals:
34 void guidChanged();
35 void titleChanged();68 void titleChanged();
36 void notebookGuidChanged();69 void notebookGuidChanged();
37 void contentChanged();70 void contentChanged();
71 void reminderChanged();
72 void reminderTimeChanged();
73 void reminderDoneChanged();
3874
39private:75private:
40 QString m_guid;76 QString m_guid;
41 QString m_notebookGuid;77 QString m_notebookGuid;
78 QDateTime m_created;
42 QString m_title;79 QString m_title;
43 QString m_content;80 QString m_content;
81 qint64 m_reminderOrder;
82 QDateTime m_reminderTime;
83 QDateTime m_reminderDoneTime;
44};84};
4585
46#endif // NOTE_H86#endif // NOTE_H
4787
=== modified file 'src/plugin/Evernote/notebooks.cpp'
--- src/plugin/Evernote/notebooks.cpp 2013-11-26 17:18:33 +0000
+++ src/plugin/Evernote/notebooks.cpp 2013-12-12 21:36:37 +0000
@@ -35,7 +35,6 @@
3535
36QVariant Notebooks::data(const QModelIndex &index, int role) const36QVariant Notebooks::data(const QModelIndex &index, int role) const
37{37{
38
39 Notebook *notebook = NotesStore::instance()->notebook(m_list.at(index.row()));38 Notebook *notebook = NotesStore::instance()->notebook(m_list.at(index.row()));
40 switch(role) {39 switch(role) {
41 case RoleGuid:40 case RoleGuid:
4241
=== modified file 'src/plugin/Evernote/notes.cpp'
--- src/plugin/Evernote/notes.cpp 2013-11-26 17:18:33 +0000
+++ src/plugin/Evernote/notes.cpp 2013-12-12 21:36:37 +0000
@@ -24,37 +24,12 @@
24#include <QDebug>24#include <QDebug>
2525
26Notes::Notes(QObject *parent) :26Notes::Notes(QObject *parent) :
27 QAbstractListModel(parent)27 QSortFilterProxyModel(parent),
28{28 m_onlyReminders(false)
29 connect(NotesStore::instance(), &NotesStore::noteAdded, this, &Notes::noteAdded);29{
30 connect(NotesStore::instance(), &NotesStore::noteRemoved, this, &Notes::noteRemoved);30 setSourceModel(NotesStore::instance());
31 connect(NotesStore::instance(), &NotesStore::noteChanged, this, &Notes::noteChanged);31 setSortRole(NotesStore::RoleCreated);
32}32 sort(0, Qt::DescendingOrder);
33
34QVariant Notes::data(const QModelIndex &index, int role) const
35{
36 Note *note = NotesStore::instance()->note(m_list.at(index.row()));
37 switch(role) {
38 case RoleGuid:
39 return note->guid();
40 case RoleTitle:
41 return note->title();
42 }
43
44 return QVariant();
45}
46
47int Notes::rowCount(const QModelIndex &parent) const
48{
49 return m_list.count();
50}
51
52QHash<int, QByteArray> Notes::roleNames() const
53{
54 QHash<int, QByteArray> roles;
55 roles.insert(RoleGuid, "guid");
56 roles.insert(RoleTitle, "title");
57 return roles;
58}33}
5934
60QString Notes::filterNotebookGuid() const35QString Notes::filterNotebookGuid() const
@@ -67,53 +42,36 @@
67 if (m_filterNotebookGuid != notebookGuid) {42 if (m_filterNotebookGuid != notebookGuid) {
68 m_filterNotebookGuid = notebookGuid;43 m_filterNotebookGuid = notebookGuid;
69 emit filterNotebookGuidChanged();44 emit filterNotebookGuidChanged();
70 }45 invalidateFilter();
71}46 }
7247}
73Note* Notes::note(const QString &guid)48
74{49bool Notes::onlyReminders() const
75 NotesStore::instance()->refreshNoteContent(guid);50{
76 return NotesStore::instance()->note(guid);51 return m_onlyReminders;
77}52}
7853
79void Notes::componentComplete()54void Notes::setOnlyReminders(bool onlyReminders)
80{55{
81 foreach (Note *note, NotesStore::instance()->notes()) {56 if (m_onlyReminders != onlyReminders) {
82 if (m_filterNotebookGuid.isEmpty() || note->notebookGuid() == m_filterNotebookGuid) {57 m_onlyReminders = onlyReminders;
83 m_list.append(note->guid());58 emit onlyRemindersChanged();
84 }59 invalidateFilter();
85 }60 }
86 beginInsertRows(QModelIndex(), 0, m_list.count() - 1);61}
87 endInsertRows();62
88 refresh();63bool Notes::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
89}64{
9065 QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent);
91void Notes::refresh()66 if (!m_filterNotebookGuid.isEmpty()) {
92{67 if (sourceModel()->data(sourceIndex, NotesStore::RoleNotebookGuid).toString() != m_filterNotebookGuid) {
93 NotesStore::instance()->refreshNotes(m_filterNotebookGuid);68 return false;
94}69 }
9570 }
96void Notes::noteAdded(const QString &guid)71 if (m_onlyReminders) {
97{72 if (!sourceModel()->data(sourceIndex, NotesStore::RoleReminder).toBool()) {
98 beginInsertRows(QModelIndex(), m_list.count(), m_list.count());73 return false;
99 m_list.append(guid);74 }
100 endInsertRows();75 }
101}76 return true;
102
103void Notes::noteChanged(const QString &guid)
104{
105 int row = m_list.indexOf(guid);
106 if (row >= 0) {
107 emit dataChanged(index(row), index(row));
108 }
109}
110
111void Notes::noteRemoved(const QString &guid)
112{
113 int index = m_list.indexOf(guid);
114 if (index >= 0) {
115 beginRemoveRows(QModelIndex(), index, index);
116 m_list.removeAt(index);
117 endRemoveRows();
118 }
119}77}
12078
=== modified file 'src/plugin/Evernote/notes.h'
--- src/plugin/Evernote/notes.h 2013-11-25 00:49:48 +0000
+++ src/plugin/Evernote/notes.h 2013-12-12 21:36:37 +0000
@@ -3,46 +3,33 @@
33
4#include "notesstore.h"4#include "notesstore.h"
55
6#include <QAbstractListModel>6#include <QSortFilterProxyModel>
7#include <QQmlParserStatus>
87
9class Notes : public QAbstractListModel, public QQmlParserStatus8class Notes : public QSortFilterProxyModel
10{9{
11 Q_OBJECT10 Q_OBJECT
12 Q_PROPERTY(QString filterNotebookGuid READ filterNotebookGuid WRITE setFilterNotebookGuid NOTIFY filterNotebookGuidChanged)11 Q_PROPERTY(QString filterNotebookGuid READ filterNotebookGuid WRITE setFilterNotebookGuid NOTIFY filterNotebookGuidChanged)
12 Q_PROPERTY(bool onlyReminders READ onlyReminders WRITE setOnlyReminders NOTIFY onlyRemindersChanged)
13
13public:14public:
14 enum Roles {
15 RoleGuid,
16 RoleTitle
17 };
18 explicit Notes(QObject *parent = 0);15 explicit Notes(QObject *parent = 0);
1916
20 QVariant data(const QModelIndex &index, int role) const;
21 int rowCount(const QModelIndex &parent) const;
22 QHash<int, QByteArray> roleNames() const;
23
24 QString filterNotebookGuid() const;17 QString filterNotebookGuid() const;
25 void setFilterNotebookGuid(const QString &notebookGuid);18 void setFilterNotebookGuid(const QString &notebookGuid);
2619
27 Q_INVOKABLE Note* note(const QString &guid);20 bool onlyReminders() const;
2821 void setOnlyReminders(bool onlyReminders);
29 void classBegin() {}22
30 void componentComplete();23protected:
3124 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
32public slots:
33 void refresh();
34
35private slots:
36 void noteAdded(const QString &guid);
37 void noteChanged(const QString &guid);
38 void noteRemoved(const QString &guid);
3925
40signals:26signals:
41 void filterNotebookGuidChanged();27 void filterNotebookGuidChanged();
28 void onlyRemindersChanged();
4229
43private:30private:
44 QList<QString> m_list;
45 QString m_filterNotebookGuid;31 QString m_filterNotebookGuid;
32 bool m_onlyReminders;
4633
47};34};
4835
4936
=== modified file 'src/plugin/Evernote/notesstore.cpp'
--- src/plugin/Evernote/notesstore.cpp 2013-12-12 21:36:37 +0000
+++ src/plugin/Evernote/notesstore.cpp 2013-12-12 21:36:37 +0000
@@ -37,7 +37,7 @@
37NotesStore* NotesStore::s_instance = 0;37NotesStore* NotesStore::s_instance = 0;
3838
39NotesStore::NotesStore(QObject *parent) :39NotesStore::NotesStore(QObject *parent) :
40 QObject(parent)40 QAbstractListModel(parent)
41{41{
42 connect(EvernoteConnection::instance(), &EvernoteConnection::tokenChanged, this, &NotesStore::refreshNotebooks);42 connect(EvernoteConnection::instance(), &EvernoteConnection::tokenChanged, this, &NotesStore::refreshNotebooks);
43 connect(EvernoteConnection::instance(), SIGNAL(tokenChanged()), this, SLOT(refreshNotes()));43 connect(EvernoteConnection::instance(), SIGNAL(tokenChanged()), this, SLOT(refreshNotes()));
@@ -57,28 +57,71 @@
57 return s_instance;57 return s_instance;
58}58}
5959
60int NotesStore::rowCount(const QModelIndex &parent) const
61{
62 return m_notes.count();
63}
64
65QVariant NotesStore::data(const QModelIndex &index, int role) const
66{
67 switch (role) {
68 case RoleGuid:
69 return m_notes.at(index.row())->guid();
70 case RoleNotebookGuid:
71 return m_notes.at(index.row())->notebookGuid();
72 case RoleCreated:
73 return m_notes.at(index.row())->created();
74 case RoleTitle:
75 return m_notes.at(index.row())->title();
76 case RoleReminder:
77 return m_notes.at(index.row())->reminder();
78 case RoleReminderTime:
79 return m_notes.at(index.row())->reminderTime();
80 case RoleReminderDone:
81 return m_notes.at(index.row())->reminderDone();
82 case RoleReminderDoneTime:
83 return m_notes.at(index.row())->reminderDoneTime();
84 }
85 return QVariant();
86}
87
88QHash<int, QByteArray> NotesStore::roleNames() const
89{
90 QHash<int, QByteArray> roles;
91 roles.insert(RoleGuid, "guid");
92 roles.insert(RoleNotebookGuid, "notebookGuid");
93 roles.insert(RoleCreated, "created");
94 roles.insert(RoleTitle, "title");
95 roles.insert(RoleReminder, "reminder");
96 roles.insert(RoleReminderTime, "reminderTime");
97 roles.insert(RoleReminderDone, "reminderDone");
98 roles.insert(RoleReminderDoneTime, "reminderDoneTime");
99 return roles;
100}
101
60NotesStore::~NotesStore()102NotesStore::~NotesStore()
61{103{
62}104}
63105
64QList<Note*> NotesStore::notes() const106QList<Note*> NotesStore::notes() const
65{107{
66 return m_notes.values();108 return m_notes;
67}109}
68110
69Note *NotesStore::note(const QString &guid)111Note *NotesStore::note(const QString &guid)
70{112{
71 return m_notes.value(guid);113 refreshNoteContent(guid);
114 return m_notesHash.value(guid);
72}115}
73116
74QList<Notebook *> NotesStore::notebooks() const117QList<Notebook *> NotesStore::notebooks() const
75{118{
76 return m_notebooks.values();119 return m_notebooks;
77}120}
78121
79Notebook *NotesStore::notebook(const QString &guid)122Notebook *NotesStore::notebook(const QString &guid)
80{123{
81 return m_notebooks.value(guid);124 return m_notebooksHash.value(guid);
82}125}
83126
84void NotesStore::refreshNotes(const QString &filterNotebookGuid)127void NotesStore::refreshNotes(const QString &filterNotebookGuid)
@@ -97,17 +140,33 @@
97140
98 for (int i = 0; i < results.notes.size(); ++i) {141 for (int i = 0; i < results.notes.size(); ++i) {
99 evernote::edam::NoteMetadata result = results.notes.at(i);142 evernote::edam::NoteMetadata result = results.notes.at(i);
100 Note *note = m_notes.value(QString::fromStdString(result.guid));143 Note *note = m_notesHash.value(QString::fromStdString(result.guid));
101 if (note) {144 bool newNote = note == 0;
102 note->setTitle(QString::fromStdString(result.title));145 if (newNote) {
103 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));146 QString guid = QString::fromStdString(result.guid);
147 QDateTime created = QDateTime::fromMSecsSinceEpoch(result.created);
148 note = new Note(guid, created, this);
149 }
150
151 note->setTitle(QString::fromStdString(result.title));
152 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));
153 note->setReminderOrder(result.attributes.reminderOrder);
154 QDateTime reminderDoneTime;
155 if (result.attributes.reminderDoneTime > 0) {
156 reminderDoneTime = QDateTime::fromMSecsSinceEpoch(result.attributes.reminderDoneTime);
157 }
158 note->setReminderDoneTime(reminderDoneTime);
159
160 if (newNote) {
161 beginInsertRows(QModelIndex(), m_notes.count(), m_notes.count());
162 m_notesHash.insert(note->guid(), note);
163 m_notes.append(note);
164 endInsertRows();
165 emit noteAdded(note->guid());
166 } else {
167 QModelIndex noteIndex = index(m_notes.indexOf(note));
168 emit dataChanged(noteIndex, noteIndex);
104 emit noteChanged(note->guid());169 emit noteChanged(note->guid());
105 } else {
106 note = new Note(QString::fromStdString(result.guid), this);
107 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));
108 note->setTitle(QString::fromStdString(result.title));
109 m_notes.insert(note->guid(), note);
110 emit noteAdded(note->guid());
111 }170 }
112 }171 }
113}172}
@@ -126,11 +185,20 @@
126 return;185 return;
127 }186 }
128187
129 Note *note = m_notes.value(QString::fromStdString(result.guid));188 Note *note = m_notesHash.value(QString::fromStdString(result.guid));
130 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));189 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));
131 note->setTitle(QString::fromStdString(result.title));190 note->setTitle(QString::fromStdString(result.title));
132 note->setContent(QString::fromStdString(result.content));191 note->setContent(QString::fromStdString(result.content));
192 note->setReminderOrder(result.attributes.reminderOrder);
193 QDateTime reminderDoneTime;
194 if (result.attributes.reminderDoneTime > 0) {
195 reminderDoneTime = QDateTime::fromMSecsSinceEpoch(result.attributes.reminderDoneTime);
196 }
197 note->setReminderDoneTime(reminderDoneTime);
133 emit noteChanged(note->guid());198 emit noteChanged(note->guid());
199
200 QModelIndex noteIndex = index(m_notes.indexOf(note));
201 emit dataChanged(noteIndex, noteIndex);
134}202}
135203
136void NotesStore::refreshNotebooks()204void NotesStore::refreshNotebooks()
@@ -149,17 +217,19 @@
149217
150 for (int i = 0; i < results.size(); ++i) {218 for (int i = 0; i < results.size(); ++i) {
151 evernote::edam::Notebook result = results.at(i);219 evernote::edam::Notebook result = results.at(i);
152 Notebook *notebook = m_notebooks.value(QString::fromStdString(result.guid));220 Notebook *notebook = m_notebooksHash.value(QString::fromStdString(result.guid));
153 if (notebook) {221 bool newNoteNotebook = notebook == 0;
154 qDebug() << "got notebook update";222 if (newNoteNotebook) {
155 notebook->setName(QString::fromStdString(result.name));
156 emit notebookChanged(notebook->guid());
157 } else {
158 notebook = new Notebook(QString::fromStdString(result.guid), this);223 notebook = new Notebook(QString::fromStdString(result.guid), this);
159 notebook->setName(QString::fromStdString(result.name));224 }
160 m_notebooks.insert(notebook->guid(), notebook);225 notebook->setName(QString::fromStdString(result.name));
226
227 if (newNoteNotebook) {
228 m_notebooksHash.insert(notebook->guid(), notebook);
229 m_notebooks.append(notebook);
161 emit notebookAdded(notebook->guid());230 emit notebookAdded(notebook->guid());
162 qDebug() << "got new notebook" << notebook->guid();231 } else {
232 emit notebookChanged(notebook->guid());
163 }233 }
164 }234 }
165}235}
@@ -178,18 +248,24 @@
178 return;248 return;
179 }249 }
180250
181 Note *note = new Note(QString::fromStdString(result.guid));251 QString guid = QString::fromStdString(result.guid);
252 QDateTime created = QDateTime::fromMSecsSinceEpoch(result.created);
253 Note *note = new Note(guid, created, this);
182 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));254 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));
183 note->setTitle(QString::fromStdString(result.title));255 note->setTitle(QString::fromStdString(result.title));
184 note->setContent(QString::fromStdString(result.content));256 note->setContent(QString::fromStdString(result.content));
185257
186 m_notes.insert(note->guid(), note);258 beginInsertRows(QModelIndex(), m_notes.count(), m_notes.count());
187 noteAdded(note->guid());259 m_notesHash.insert(note->guid(), note);
260 m_notes.append(note);
261 endInsertRows();
262
263 emit noteAdded(note->guid());
188}264}
189265
190void NotesStore::saveNote(const QString &guid)266void NotesStore::saveNote(const QString &guid)
191{267{
192 Note *note = m_notes.value(guid);268 Note *note = m_notesHash.value(guid);
193269
194 QString enml = Html2EnmlConverter::html2enml(note->content());270 QString enml = Html2EnmlConverter::html2enml(note->content());
195 note->setContent(enml);271 note->setContent(enml);
@@ -206,12 +282,15 @@
206 return;282 return;
207 }283 }
208284
209 Note *note = m_notes.value(QString::fromStdString(result.guid));285 Note *note = m_notesHash.value(QString::fromStdString(result.guid));
210 if (note) {286 if (note) {
211 note->setTitle(QString::fromStdString(result.title));287 note->setTitle(QString::fromStdString(result.title));
212 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));288 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));
213289
214 emit noteChanged(note->guid());290 emit noteChanged(note->guid());
291
292 QModelIndex noteIndex = index(m_notes.indexOf(note));
293 emit dataChanged(noteIndex, noteIndex);
215 }294 }
216}295}
217296
@@ -229,5 +308,11 @@
229 return;308 return;
230 }309 }
231 emit noteRemoved(guid);310 emit noteRemoved(guid);
232 m_notes.take(guid)->deleteLater();311
312 Note *note = m_notesHash.value(guid);
313 int noteIndex = m_notes.indexOf(note);
314 beginRemoveRows(QModelIndex(), noteIndex, noteIndex);
315 m_notes.takeAt(noteIndex);
316 m_notesHash.take(guid)->deleteLater();
317 endRemoveRows();
233}318}
234319
=== modified file 'src/plugin/Evernote/notesstore.h'
--- src/plugin/Evernote/notesstore.h 2013-12-12 21:36:37 +0000
+++ src/plugin/Evernote/notesstore.h 2013-12-12 21:36:37 +0000
@@ -15,7 +15,7 @@
15#include <NoteStore_constants.h>15#include <NoteStore_constants.h>
16#include <Errors_types.h>16#include <Errors_types.h>
1717
18#include <QObject>18#include <QAbstractListModel>
19#include <QHash>19#include <QHash>
2020
21class Notebook;21class Notebook;
@@ -23,21 +23,36 @@
2323
24using namespace apache::thrift::transport;24using namespace apache::thrift::transport;
2525
26class NotesStore : public QObject26class NotesStore : public QAbstractListModel
27{27{
28 Q_OBJECT28 Q_OBJECT
2929
30public:30public:
31 Q_INVOKABLE void createNote(const QString &title, const QString &notebookGuid, const QString &content);31 enum Roles {
32 RoleGuid,
33 RoleNotebookGuid,
34 RoleCreated,
35 RoleTitle,
36 RoleReminder,
37 RoleReminderTime,
38 RoleReminderDone,
39 RoleReminderDoneTime
40 };
3241
42 ~NotesStore();
33 static NotesStore *instance();43 static NotesStore *instance();
3444
35 ~NotesStore();45 // reimplemented from QAbstractListModel
46 int rowCount(const QModelIndex &parent) const;
47 QVariant data(const QModelIndex &index, int role) const;
48 QHash<int, QByteArray> roleNames() const;
3649
37 QList<Note*> notes() const;50 QList<Note*> notes() const;
38 Note* note(const QString &guid);51
39 void saveNote(const QString &guid);52 Q_INVOKABLE Note* note(const QString &guid);
40 void deleteNote(const QString &guid);53 Q_INVOKABLE void createNote(const QString &title, const QString &notebookGuid, const QString &content);
54 Q_INVOKABLE void saveNote(const QString &guid);
55 Q_INVOKABLE void deleteNote(const QString &guid);
4156
42 QList<Notebook*> notebooks() const;57 QList<Notebook*> notebooks() const;
43 Notebook* notebook(const QString &guid);58 Notebook* notebook(const QString &guid);
@@ -69,9 +84,12 @@
69 explicit NotesStore(QObject *parent = 0);84 explicit NotesStore(QObject *parent = 0);
70 static NotesStore *s_instance;85 static NotesStore *s_instance;
7186
72 QHash<QString, Notebook*> m_notebooks;87 QList<Note*> m_notes;
73 QHash<QString, Note*> m_notes;88 QList<Notebook*> m_notebooks;
7489
90 // Keep hashes for faster lookups as we always identify notes via guid
91 QHash<QString, Note*> m_notesHash;
92 QHash<QString, Notebook*> m_notebooksHash;
75};93};
7694
77#endif // NOTESSTORE_H95#endif // NOTESSTORE_H

Subscribers

People subscribed via source and target branches