Merge lp:~mzanetti/reminders-app/two-job-queues into lp:reminders-app

Proposed by Michael Zanetti
Status: Superseded
Proposed branch: lp:~mzanetti/reminders-app/two-job-queues
Merge into: lp:reminders-app
Diff against target: 2258 lines (+402/-338)
36 files modified
src/app/formattinghelper.cpp (+0/-1)
src/app/main.cpp (+49/-7)
src/app/preferences.h (+0/-1)
src/libqtevernote/CMakeLists.txt (+1/-1)
src/libqtevernote/evernoteconnection.cpp (+98/-59)
src/libqtevernote/evernoteconnection.h (+18/-2)
src/libqtevernote/jobs/createnotebookjob.cpp (+0/-2)
src/libqtevernote/jobs/createnotejob.cpp (+0/-3)
src/libqtevernote/jobs/createtagjob.cpp (+0/-2)
src/libqtevernote/jobs/evernotejob.cpp (+17/-12)
src/libqtevernote/jobs/evernotejob.h (+5/-3)
src/libqtevernote/jobs/expungenotebookjob.cpp (+0/-2)
src/libqtevernote/jobs/fetchnotebooksjob.cpp (+0/-2)
src/libqtevernote/jobs/fetchnotesjob.cpp (+3/-3)
src/libqtevernote/jobs/fetchtagsjob.cpp (+0/-2)
src/libqtevernote/jobs/savenotebookjob.cpp (+0/-2)
src/libqtevernote/jobs/savenotejob.cpp (+0/-3)
src/libqtevernote/jobs/savetagjob.cpp (+0/-2)
src/libqtevernote/logging.cpp (+32/-0)
src/libqtevernote/logging.h (+34/-0)
src/libqtevernote/note.cpp (+14/-25)
src/libqtevernote/note.h (+1/-3)
src/libqtevernote/notebook.cpp (+1/-2)
src/libqtevernote/notebooks.cpp (+0/-2)
src/libqtevernote/notes.cpp (+0/-2)
src/libqtevernote/notesstore.cpp (+113/-103)
src/libqtevernote/resource.cpp (+5/-5)
src/libqtevernote/resourceimageprovider.cpp (+2/-2)
src/libqtevernote/tag.h (+0/-1)
src/libqtevernote/tags.cpp (+0/-2)
src/libqtevernote/userstore.cpp (+2/-3)
src/libqtevernote/utils/enmldocument.cpp (+3/-3)
src/libqtevernote/utils/organizeradapter.cpp (+4/-4)
src/libqtevernote/utils/textformat.cpp (+0/-25)
src/libqtevernote/utils/textformat.h (+0/-43)
src/plugin/Evernote/evernoteplugin.cpp (+0/-4)
To merge this branch: bzr merge lp:~mzanetti/reminders-app/two-job-queues
Reviewer Review Type Date Requested Status
Riccardo Padovani Needs Information
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+251838@code.launchpad.net

This proposal has been superseded by a proposal from 2015-03-06.

Commit message

split the job queue into two

having two job queues allows more fine grained scheduling and should help with responsiveness in the initial sync of huge evernote accounts. So far we could only prepend high priority jobs and append low priority ones. Now we can also prepend to the low priority queue and react faster to what the user most likely wants to see.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Looks good to me, but I left a couple of comments, just to be sure changes you made are wanted :-)

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

Thanks for those comments. While I think this branch is ok, I found an issue with the attachToDuplicate() mechanism. I will fix that in another branch, as that issue is not introduced by this branch.

379. By Michael Zanetti

merge prereq

380. By Michael Zanetti

also allow reprioritizing low priority jobs

381. By Michael Zanetti

add a new priority VeryLow

Resources fetched solely for the purpose of polupating a list should not fill up
the jobqueue that much and prevent text from loading. VeryLow priority jobs
will be appended (as opposed to prepended) to the low priority queue and
thus fetched at the end.

382. By Michael Zanetti

make the resources update in the notes list when they are fetched

383. By Michael Zanetti

improve job queuing further

384. By Michael Zanetti

merge trunk

385. By Michael Zanetti

revert debug print changes

386. By Michael Zanetti

fix url for rtf editor

387. By Michael Zanetti

fix issues from reviews

388. By Michael Zanetti

use qCDebug

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/app/formattinghelper.cpp'
--- src/app/formattinghelper.cpp 2014-11-12 22:14:59 +0000
+++ src/app/formattinghelper.cpp 2015-03-06 21:14:46 +0000
@@ -21,7 +21,6 @@
2121
22#include "formattinghelper.h"22#include "formattinghelper.h"
2323
24#include <QDebug>
25#include <QTextBlock>24#include <QTextBlock>
26#include <QTextObject>25#include <QTextObject>
27#include <QTextCharFormat>26#include <QTextCharFormat>
2827
=== modified file 'src/app/main.cpp'
--- src/app/main.cpp 2015-02-24 18:55:55 +0000
+++ src/app/main.cpp 2015-03-06 21:14:46 +0000
@@ -29,7 +29,22 @@
29#include <QLibrary>29#include <QLibrary>
30#include <QCommandLineParser>30#include <QCommandLineParser>
31#include <QCommandLineOption>31#include <QCommandLineOption>
32#include <QDebug>32#include <QLoggingCategory>
33
34QHash<QString, bool> s_loggingFilters;
35QLoggingCategory dcApplication("Application");
36
37void loggingCategoryFilter(QLoggingCategory *category)
38{
39 if (s_loggingFilters.contains(category->categoryName())) {
40 bool debugEnabled = s_loggingFilters.value(category->categoryName());
41 category->setEnabled(QtDebugMsg, debugEnabled);
42 category->setEnabled(QtWarningMsg, debugEnabled || s_loggingFilters.value("Warnings"));
43 } else {
44 category->setEnabled(QtDebugMsg, false);
45 category->setEnabled(QtWarningMsg, s_loggingFilters.value("qml") || s_loggingFilters.value("Warnings"));
46 }
47}
3348
34int main(int argc, char *argv[])49int main(int argc, char *argv[])
35{50{
@@ -37,6 +52,16 @@
37 QQuickView view;52 QQuickView view;
38 view.setResizeMode(QQuickView::SizeRootObjectToView);53 view.setResizeMode(QQuickView::SizeRootObjectToView);
3954
55 s_loggingFilters.insert("Warnings", true);
56 s_loggingFilters.insert("Application", true);
57 s_loggingFilters.insert("NotesStore", true);
58 s_loggingFilters.insert("JobQueue", false);
59 s_loggingFilters.insert("Sync", true);
60 s_loggingFilters.insert("Connection", true);
61 s_loggingFilters.insert("Enml", false);
62 s_loggingFilters.insert("Organizer", false);
63 s_loggingFilters.insert("qml", true);
64
40 // Set up import paths65 // Set up import paths
41 QStringList importPathList = view.engine()->importPathList();66 QStringList importPathList = view.engine()->importPathList();
42 // Prepend the location of the plugin in the build dir,67 // Prepend the location of the plugin in the build dir,
@@ -50,10 +75,16 @@
50 cmdLineParser.addOption(phoneFactorOption);75 cmdLineParser.addOption(phoneFactorOption);
51 QCommandLineOption tabletFactorOption(QStringList() << "t" << "tablet", "If running on Desktop, start in a tablet sized window.");76 QCommandLineOption tabletFactorOption(QStringList() << "t" << "tablet", "If running on Desktop, start in a tablet sized window.");
52 cmdLineParser.addOption(tabletFactorOption);77 cmdLineParser.addOption(tabletFactorOption);
53 QCommandLineOption importPathOption("I", "Give a path for an additional QML import directory. May be used multiple times.", "paths");78 QCommandLineOption importPathOption("I", "Give a path for an additional QML import directory. May be used multiple times.", "path");
54 cmdLineParser.addOption(importPathOption);79 cmdLineParser.addOption(importPathOption);
55 QCommandLineOption sandboxOption(QStringList() << "s" << "sandbox", "Use sandbox.evernote.com instead of www.evernote.com.");80 QCommandLineOption sandboxOption(QStringList() << "s" << "sandbox", "Use sandbox.evernote.com instead of www.evernote.com.");
56 cmdLineParser.addOption(sandboxOption);81 cmdLineParser.addOption(sandboxOption);
82 QString debugDescription = QString("Debug categories to enable. Prefix with \"No\" to disable. Warnings from all categories will be printed unless explicitly muted with \"NoWarnings\". May be used multiple times. Categories are:");
83 foreach (const QString &filterName, s_loggingFilters.keys()) {
84 debugDescription += "\n" + filterName + " (" + (s_loggingFilters.value(filterName) ? "yes" : "no") + ")";
85 }
86 QCommandLineOption debugOption(QStringList() << "d" << "debug", debugDescription, "[No]DebugCategory");
87 cmdLineParser.addOption(debugOption);
57 QCommandLineOption testabilityOption("testability", "Load the testability driver.");88 QCommandLineOption testabilityOption("testability", "Load the testability driver.");
58 cmdLineParser.addOption(testabilityOption);89 cmdLineParser.addOption(testabilityOption);
59 cmdLineParser.addPositionalArgument("uri", "Uri to start the application in a specific mode. E.g. evernote://newnote to directly create and edit a new note.");90 cmdLineParser.addPositionalArgument("uri", "Uri to start the application in a specific mode. E.g. evernote://newnote to directly create and edit a new note.");
@@ -61,6 +92,17 @@
6192
62 cmdLineParser.process(a);93 cmdLineParser.process(a);
6394
95 foreach (QString debugArea, cmdLineParser.values(debugOption)) {
96 bool enable = !debugArea.startsWith("No");
97 debugArea.remove(QRegExp("^No"));
98 if (s_loggingFilters.contains(debugArea)) {
99 s_loggingFilters[debugArea] = enable;
100 } else {
101 qWarning() << "No such debug category:" << debugArea;
102 }
103 }
104 QLoggingCategory::installFilter(loggingCategoryFilter);
105
64 foreach (QString addedPath, cmdLineParser.values(importPathOption)) {106 foreach (QString addedPath, cmdLineParser.values(importPathOption)) {
65 if (addedPath == "." || addedPath.startsWith("./")) {107 if (addedPath == "." || addedPath.startsWith("./")) {
66 addedPath = addedPath.right(addedPath.length() - 1);108 addedPath = addedPath.right(addedPath.length() - 1);
@@ -86,20 +128,20 @@
86128
87 if (cmdLineParser.isSet(sandboxOption)) {129 if (cmdLineParser.isSet(sandboxOption)) {
88 view.engine()->rootContext()->setContextProperty("useSandbox", QVariant(true));130 view.engine()->rootContext()->setContextProperty("useSandbox", QVariant(true));
89 qDebug() << "Running against the sandbox server";131 qCDebug(dcApplication) << "Running against the sandbox server";
90 } else {132 } else {
91 view.engine()->rootContext()->setContextProperty("useSandbox", QVariant(false));133 view.engine()->rootContext()->setContextProperty("useSandbox", QVariant(false));
92 qDebug() << "Running against the production server";134 qCDebug(dcApplication) << "Running against the production server";
93 }135 }
94136
95 view.engine()->rootContext()->setContextProperty("tablet", QVariant(false));137 view.engine()->rootContext()->setContextProperty("tablet", QVariant(false));
96 view.engine()->rootContext()->setContextProperty("phone", QVariant(false));138 view.engine()->rootContext()->setContextProperty("phone", QVariant(false));
97139
98 if (cmdLineParser.isSet(tabletFactorOption)) {140 if (cmdLineParser.isSet(tabletFactorOption)) {
99 qDebug() << "running in tablet mode";141 qCDebug(dcApplication) << "Running in tablet mode";
100 view.engine()->rootContext()->setContextProperty("tablet", QVariant(true));142 view.engine()->rootContext()->setContextProperty("tablet", QVariant(true));
101 } else if (cmdLineParser.isSet(phoneFactorOption)){143 } else if (cmdLineParser.isSet(phoneFactorOption)){
102 qDebug() << "running in phone mode";144 qCDebug(dcApplication) << "Running in phone mode";
103 view.engine()->rootContext()->setContextProperty("phone", QVariant(true));145 view.engine()->rootContext()->setContextProperty("phone", QVariant(true));
104 } else if (qgetenv("QT_QPA_PLATFORM") != "ubuntumirclient") {146 } else if (qgetenv("QT_QPA_PLATFORM") != "ubuntumirclient") {
105 // Default to tablet size on X11147 // Default to tablet size on X11
@@ -140,7 +182,7 @@
140 // So if you want to change it, make sure to find all the places where it is set, not just here :D182 // So if you want to change it, make sure to find all the places where it is set, not just here :D
141 QCoreApplication::setApplicationName("com.ubuntu.reminders");183 QCoreApplication::setApplicationName("com.ubuntu.reminders");
142184
143 qDebug() << "using main qml file from:" << qmlfile;185 qCDebug(dcApplication) << "Using main qml file from:" << qmlfile;
144 view.setSource(QUrl::fromLocalFile(qmlfile));186 view.setSource(QUrl::fromLocalFile(qmlfile));
145 view.show();187 view.show();
146188
147189
=== modified file 'src/app/preferences.h'
--- src/app/preferences.h 2015-02-23 18:00:46 +0000
+++ src/app/preferences.h 2015-03-06 21:14:46 +0000
@@ -26,7 +26,6 @@
26#include <QSettings>26#include <QSettings>
27#include <QStandardPaths>27#include <QStandardPaths>
28#include <QObject>28#include <QObject>
29#include <QDebug>
30#include <QList>29#include <QList>
31#include <QColor>30#include <QColor>
3231
3332
=== modified file 'src/libqtevernote/CMakeLists.txt'
--- src/libqtevernote/CMakeLists.txt 2014-12-06 22:35:01 +0000
+++ src/libqtevernote/CMakeLists.txt 2015-03-06 21:14:46 +0000
@@ -14,6 +14,7 @@
14 notebook.cpp14 notebook.cpp
15 tag.cpp15 tag.cpp
16 tags.cpp16 tags.cpp
17 logging.cpp
17 jobs/fetchnotesjob.cpp18 jobs/fetchnotesjob.cpp
18 jobs/fetchnotebooksjob.cpp19 jobs/fetchnotebooksjob.cpp
19 jobs/fetchnotejob.cpp20 jobs/fetchnotejob.cpp
@@ -33,7 +34,6 @@
33 jobs/savetagjob.cpp34 jobs/savetagjob.cpp
34 resourceimageprovider.cpp35 resourceimageprovider.cpp
35 utils/enmldocument.cpp36 utils/enmldocument.cpp
36 utils/textformat.cpp
37 utils/organizeradapter.cpp37 utils/organizeradapter.cpp
38)38)
3939
4040
=== modified file 'src/libqtevernote/evernoteconnection.cpp'
--- src/libqtevernote/evernoteconnection.cpp 2015-02-27 21:32:29 +0000
+++ src/libqtevernote/evernoteconnection.cpp 2015-03-06 21:14:46 +0000
@@ -21,6 +21,7 @@
2121
22#include "evernoteconnection.h"22#include "evernoteconnection.h"
23#include "jobs/evernotejob.h"23#include "jobs/evernotejob.h"
24#include "logging.h"
2425
25// Thrift26// Thrift
26#include <arpa/inet.h> // seems thrift forgot this one27#include <arpa/inet.h> // seems thrift forgot this one
@@ -36,7 +37,6 @@
36#include <UserStore_constants.h>37#include <UserStore_constants.h>
37#include <Errors_types.h>38#include <Errors_types.h>
3839
39#include <QDebug>
40#include <QUrl>40#include <QUrl>
4141
42#include <libintl.h>42#include <libintl.h>
@@ -79,11 +79,11 @@
79 if (m_useSSL) {79 if (m_useSSL) {
80 boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory());80 boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory());
81 socket = sslSocketFactory->createSocket(m_hostname.toStdString(), 443);81 socket = sslSocketFactory->createSocket(m_hostname.toStdString(), 443);
82 qDebug() << "created UserStore SSL socket to host " << m_hostname;82 qCDebug(dcConnection) << "created UserStore SSL socket to host " << m_hostname;
83 } else {83 } else {
84 // Create a non-secure socket84 // Create a non-secure socket
85 socket = boost::shared_ptr<TSocket> (new TSocket(m_hostname.toStdString(), 80));85 socket = boost::shared_ptr<TSocket> (new TSocket(m_hostname.toStdString(), 80));
86 qDebug() << "created insecure UserStore socket to host " << m_hostname;86 qCDebug(dcConnection) << "created insecure UserStore socket to host " << m_hostname;
87 }87 }
8888
89 // setup UserStore client89 // setup UserStore client
@@ -108,11 +108,11 @@
108 if (m_useSSL) {108 if (m_useSSL) {
109 boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory());109 boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory());
110 socket = sslSocketFactory->createSocket(m_hostname.toStdString(), 443);110 socket = sslSocketFactory->createSocket(m_hostname.toStdString(), 443);
111 qDebug() << "created NotesStore SSL socket to host " << m_hostname;111 qCDebug(dcConnection) << "created NotesStore SSL socket to host " << m_hostname;
112 } else {112 } else {
113 // Create a non-secure socket113 // Create a non-secure socket
114 socket = boost::shared_ptr<TSocket> (new TSocket(m_hostname.toStdString(), 80));114 socket = boost::shared_ptr<TSocket> (new TSocket(m_hostname.toStdString(), 80));
115 qDebug() << "created insecure NotesStore socket to host " << m_hostname;115 qCDebug(dcConnection) << "created insecure NotesStore socket to host " << m_hostname;
116 }116 }
117117
118 // setup NotesStore client118 // setup NotesStore client
@@ -147,17 +147,23 @@
147147
148void EvernoteConnection::disconnectFromEvernote()148void EvernoteConnection::disconnectFromEvernote()
149{149{
150 qDebug() << "[Connection] Disconnecting from Evernote.";150 qCDebug(dcConnection) << "Disconnecting from Evernote.";
151 if (!isConnected()) {151 if (!isConnected()) {
152 qWarning() << "Not connected. Can't disconnect.";152 qCWarning(dcConnection()) << "Not connected. Can't disconnect.";
153 return;153 return;
154 }154 }
155155
156 foreach (EvernoteJob *job, m_jobQueue) {156 foreach (EvernoteJob *job, m_highPriorityJobQueue) {
157 job->emitJobDone(EvernoteConnection::ErrorCodeConnectionLost, "Disconnected from Evernote");157 job->emitJobDone(EvernoteConnection::ErrorCodeConnectionLost, "Disconnected from Evernote");
158 job->deleteLater();158 job->deleteLater();
159 }159 }
160 m_jobQueue.clear();160 m_highPriorityJobQueue.clear();
161
162 foreach (EvernoteJob *job, m_lowPriorityJobQueue) {
163 job->emitJobDone(EvernoteConnection::ErrorCodeConnectionLost, "Disconnected from Evernote");
164 job->deleteLater();
165 }
166 m_lowPriorityJobQueue.clear();
161167
162 m_errorMessage.clear();168 m_errorMessage.clear();
163 emit errorChanged();169 emit errorChanged();
@@ -198,38 +204,38 @@
198void EvernoteConnection::connectToEvernote()204void EvernoteConnection::connectToEvernote()
199{205{
200 if (isConnected()) {206 if (isConnected()) {
201 qWarning() << "Already connected.";207 qCWarning(dcConnection) << "Already connected.";
202 return;208 return;
203 }209 }
204210
205 qDebug() << "[Connection] Connecting to Evernote:" << m_hostname;211 qCDebug(dcConnection) << "Connecting to Evernote:" << m_hostname;
206212
207 m_errorMessage.clear();213 m_errorMessage.clear();
208 emit errorChanged();214 emit errorChanged();
209215
210 if (m_token.isEmpty()) {216 if (m_token.isEmpty()) {
211 qWarning() << "[Connection] Can't connect to Evernote. No token set.";217 qCWarning(dcConnection) << "Can't connect to Evernote. No token set.";
212 return;218 return;
213 }219 }
214 if (m_hostname.isEmpty()) {220 if (m_hostname.isEmpty()) {
215 qWarning() << "[Connection] Can't connect to Evernote. No hostname set.";221 qCWarning(dcConnection) << "Can't connect to Evernote. No hostname set.";
216 }222 }
217223
218 setupUserStore();224 setupUserStore();
219 bool ok = connectUserStore();225 bool ok = connectUserStore();
220 if (!ok) {226 if (!ok) {
221 qWarning() << "[Connection] Error connecting User Store. Cannot continue.";227 qCWarning(dcConnection) << "Error connecting User Store. Cannot continue.";
222 return;228 return;
223 }229 }
224 setupNotesStore();230 setupNotesStore();
225 ok = connectNotesStore();231 ok = connectNotesStore();
226232
227 if (!ok) {233 if (!ok) {
228 qWarning() << "[Connection] Error connecting Notes Store. Cannot continue.";234 qCWarning(dcConnection) << "Error connecting Notes Store. Cannot continue.";
229 return;235 return;
230 }236 }
231237
232 qDebug() << "[Connection] Connected!";238 qCDebug(dcConnection) << "Connected!";
233 emit isConnectedChanged();239 emit isConnectedChanged();
234240
235}241}
@@ -242,14 +248,14 @@
242248
243 try {249 try {
244 m_userStoreHttpClient->open();250 m_userStoreHttpClient->open();
245 qDebug() << "UserStoreClient socket opened.";251 qCDebug(dcConnection) << "UserStoreClient socket opened.";
246 } catch (const TTransportException & e) {252 } catch (const TTransportException & e) {
247 qWarning() << "Failed to open connection:" << e.what() << e.getType();253 qCWarning(dcConnection) << "Failed to open connection:" << e.what() << e.getType();
248 m_errorMessage = gettext("Offline mode");254 m_errorMessage = gettext("Offline mode");
249 emit errorChanged();255 emit errorChanged();
250 return false;256 return false;
251 } catch (const TException & e) {257 } catch (const TException & e) {
252 qWarning() << "Generic Thrift exception when opening the connection:" << e.what();258 qCWarning(dcConnection) << "Generic Thrift exception when opening the connection:" << e.what();
253 m_errorMessage = gettext("Unknown error connecting to Evernote.");259 m_errorMessage = gettext("Unknown error connecting to Evernote.");
254 emit errorChanged();260 emit errorChanged();
255 return false;261 return false;
@@ -262,28 +268,28 @@
262 constants.EDAM_VERSION_MINOR);268 constants.EDAM_VERSION_MINOR);
263269
264 if (!versionOk) {270 if (!versionOk) {
265 qWarning() << "Server version mismatch! This application should be updated!";271 qCWarning(dcConnection) << "Server version mismatch! This application should be updated!";
266 m_errorMessage = QString(gettext("Error connecting to Evernote: Server version does not match app version. Please update the application."));272 m_errorMessage = QString(gettext("Error connecting to Evernote: Server version does not match app version. Please update the application."));
267 emit errorChanged();273 emit errorChanged();
268 return false;274 return false;
269 }275 }
270 } catch (const evernote::edam::EDAMUserException e) {276 } catch (const evernote::edam::EDAMUserException e) {
271 qWarning() << "Error fetching server version (EDAMUserException):" << e.what() << e.errorCode;277 qCWarning(dcConnection) << "Error fetching server version (EDAMUserException):" << e.what() << e.errorCode;
272 m_errorMessage = QString(gettext("Error connecting to Evernote: Error code %1")).arg(e.errorCode);278 m_errorMessage = QString(gettext("Error connecting to Evernote: Error code %1")).arg(e.errorCode);
273 emit errorChanged();279 emit errorChanged();
274 return false;280 return false;
275 } catch (const evernote::edam::EDAMSystemException e) {281 } catch (const evernote::edam::EDAMSystemException e) {
276 qWarning() << "Error fetching server version: (EDAMSystemException):" << e.what() << e.errorCode;282 qCWarning(dcConnection) << "Error fetching server version: (EDAMSystemException):" << e.what() << e.errorCode;
277 m_errorMessage = QString(gettext("Error connecting to Evernote: Error code %1")).arg(e.errorCode);283 m_errorMessage = QString(gettext("Error connecting to Evernote: Error code %1")).arg(e.errorCode);
278 emit errorChanged();284 emit errorChanged();
279 return false;285 return false;
280 } catch (const TTransportException & e) {286 } catch (const TTransportException & e) {
281 qWarning() << "Failed to fetch server version:" << e.what();287 qCWarning(dcConnection) << "Failed to fetch server version:" << e.what();
282 m_errorMessage = QString(gettext("Error connecting to Evernote: Cannot download version information from server."));288 m_errorMessage = QString(gettext("Error connecting to Evernote: Cannot download version information from server."));
283 emit errorChanged();289 emit errorChanged();
284 return false;290 return false;
285 } catch (const TException & e) {291 } catch (const TException & e) {
286 qWarning() << "Generic Thrift exception when fetching server version:" << e.what();292 qCWarning(dcConnection) << "Generic Thrift exception when fetching server version:" << e.what();
287 m_errorMessage = QString(gettext("Unknown error connecting to Evernote"));293 m_errorMessage = QString(gettext("Unknown error connecting to Evernote"));
288 emit errorChanged();294 emit errorChanged();
289 return false;295 return false;
@@ -291,24 +297,24 @@
291297
292 try {298 try {
293 std::string notesStoreUrl;299 std::string notesStoreUrl;
294 qDebug() << "getting ntoe store url with token" << m_token;300 qCDebug(dcConnection) << "getting ntoe store url with token" << m_token;
295 m_userstoreClient->getNoteStoreUrl(notesStoreUrl, m_token.toStdString());301 m_userstoreClient->getNoteStoreUrl(notesStoreUrl, m_token.toStdString());
296302
297 m_notesStorePath = QUrl(QString::fromStdString(notesStoreUrl)).path();303 m_notesStorePath = QUrl(QString::fromStdString(notesStoreUrl)).path();
298304
299 if (m_notesStorePath.isEmpty()) {305 if (m_notesStorePath.isEmpty()) {
300 qWarning() << "Failed to fetch notesstore path from server. Fetching notes will not work.";306 qCWarning(dcConnection) << "Failed to fetch notesstore path from server. Fetching notes will not work.";
301 m_errorMessage = QString(gettext("Error connecting to Evernote: Cannot download server information."));307 m_errorMessage = QString(gettext("Error connecting to Evernote: Cannot download server information."));
302 emit errorChanged();308 emit errorChanged();
303 return false;309 return false;
304 }310 }
305 } catch (const TTransportException & e) {311 } catch (const TTransportException & e) {
306 qWarning() << "Failed to fetch notestore path:" << e.what();312 qCWarning(dcConnection) << "Failed to fetch notestore path:" << e.what();
307 m_errorMessage = QString(gettext("Error connecting to Evernote: Connection failure when downloading server information."));313 m_errorMessage = QString(gettext("Error connecting to Evernote: Connection failure when downloading server information."));
308 emit errorChanged();314 emit errorChanged();
309 return false;315 return false;
310 } catch (const TException & e) {316 } catch (const TException & e) {
311 qWarning() << "Generic Thrift exception when fetching notestore path:" << e.what();317 qCWarning(dcConnection) << "Generic Thrift exception when fetching notestore path:" << e.what();
312 m_errorMessage = gettext("Unknown error connecting to Evernote");318 m_errorMessage = gettext("Unknown error connecting to Evernote");
313 emit errorChanged();319 emit errorChanged();
314 return false;320 return false;
@@ -325,26 +331,42 @@
325331
326 try {332 try {
327 m_notesStoreHttpClient->open();333 m_notesStoreHttpClient->open();
328 qDebug() << "NotesStoreClient socket opened." << m_notesStoreHttpClient->isOpen();334 qCDebug(dcConnection) << "NotesStoreClient socket opened." << m_notesStoreHttpClient->isOpen();
329 return true;335 return true;
330336
331 } catch (const TTransportException & e) {337 } catch (const TTransportException & e) {
332 qWarning() << "Failed to open connection:" << e.what();338 qCWarning(dcConnection) << "Failed to open connection:" << e.what();
333 m_errorMessage = QString(gettext("Error connecting to Evernote: Connection failure"));339 m_errorMessage = QString(gettext("Error connecting to Evernote: Connection failure"));
334 emit errorChanged();340 emit errorChanged();
335 } catch (const TException & e) {341 } catch (const TException & e) {
336 qWarning() << "Generic Thrift exception when opening the NotesStore connection:" << e.what();342 qCWarning(dcConnection) << "Generic Thrift exception when opening the NotesStore connection:" << e.what();
337 m_errorMessage = QString(gettext("Unknown Error connecting to Evernote"));343 m_errorMessage = QString(gettext("Unknown Error connecting to Evernote"));
338 emit errorChanged();344 emit errorChanged();
339 }345 }
340 return false;346 return false;
341}347}
342348
343EvernoteJob* EvernoteConnection::findDuplicate(EvernoteJob *job)349void EvernoteConnection::attachDuplicate(EvernoteJob *original, EvernoteJob *duplicate)
344{350{
345 foreach (EvernoteJob *queuedJob, m_jobQueue) {351 if (duplicate->originatingObject() && duplicate->originatingObject() != original->originatingObject()) {
346 // explicitly use custom operator==()352 duplicate->attachToDuplicate(m_currentJob);
347 if (job->operator ==(queuedJob)) {353 }
354 connect(original, &EvernoteJob::finished, duplicate, &EvernoteJob::deleteLater);
355}
356
357EvernoteJob* EvernoteConnection::findExistingDuplicate(EvernoteJob *job)
358{
359 foreach (EvernoteJob *queuedJob, m_highPriorityJobQueue) {
360 // explicitly use custom operator==()
361 if (job->operator ==(queuedJob)) {
362 qCDebug(dcJobQueue) << "Found duplicate in high priority queue";
363 return queuedJob;
364 }
365 }
366 foreach (EvernoteJob *queuedJob, m_lowPriorityJobQueue) {
367 // explicitly use custom operator==()
368 if (job->operator ==(queuedJob)) {
369 qCDebug(dcJobQueue) << "Found duplicate in low priority queue";
348 return queuedJob;370 return queuedJob;
349 }371 }
350 }372 }
@@ -354,31 +376,43 @@
354void EvernoteConnection::enqueue(EvernoteJob *job)376void EvernoteConnection::enqueue(EvernoteJob *job)
355{377{
356 if (!isConnected()) {378 if (!isConnected()) {
357 qWarning() << "[JobQueue] Not connected to evernote. Can't enqueue job.";379 qCWarning(dcJobQueue) << "Not connected to evernote. Can't enqueue job.";
358 job->emitJobDone(ErrorCodeConnectionLost, gettext("Disconnected from Evernote."));380 job->emitJobDone(ErrorCodeConnectionLost, gettext("Disconnected from Evernote."));
359 job->deleteLater();381 job->deleteLater();
360 return;382 return;
361 }383 }
362 EvernoteJob *duplicate = findDuplicate(job);384 if (m_currentJob && m_currentJob->operator ==(job)) {
363 if (duplicate) {385 qCDebug(dcJobQueue) << "Duplicate of new job request already running:" << job->toString();
364 job->attachToDuplicate(duplicate);386 if (m_currentJob->isFinished()) {
365 connect(duplicate, &EvernoteJob::finished, job, &EvernoteJob::deleteLater);387 job->deleteLater();
388 } else {
389 attachDuplicate(m_currentJob, job);
390 }
391 return;
392 }
393 EvernoteJob *existingJob = findExistingDuplicate(job);
394 if (existingJob) {
395 qCDebug(dcJobQueue) << "Duplicate job already queued:" << job->toString();
396 attachDuplicate(existingJob, job);
366 // reprioritze the repeated request397 // reprioritze the repeated request
367 qDebug() << "[JobQueue] Duplicate job already queued:" << job->toString();
368 if (job->jobPriority() == EvernoteJob::JobPriorityHigh) {398 if (job->jobPriority() == EvernoteJob::JobPriorityHigh) {
369 qDebug() << "[JobQueue] Reprioritising duplicate job:" << job->toString();399 qCDebug(dcJobQueue) << "Reprioritising duplicate job:" << job->toString();
370 duplicate->setJobPriority(job->jobPriority());400 existingJob->setJobPriority(job->jobPriority());
371 m_jobQueue.prepend(m_jobQueue.takeAt(m_jobQueue.indexOf(duplicate)));401 if (m_highPriorityJobQueue.contains(existingJob)) {
402 m_highPriorityJobQueue.prepend(m_highPriorityJobQueue.takeAt(m_highPriorityJobQueue.indexOf(existingJob)));
403 } else {
404 m_highPriorityJobQueue.prepend(m_lowPriorityJobQueue.takeAt(m_lowPriorityJobQueue.indexOf(existingJob)));
405 }
372 }406 }
373 } else {407 } else {
374 connect(job, &EvernoteJob::finished, job, &EvernoteJob::deleteLater);408 connect(job, &EvernoteJob::finished, job, &EvernoteJob::deleteLater);
375 connect(job, &EvernoteJob::finished, this, &EvernoteConnection::startNextJob);409 connect(job, &EvernoteJob::finished, this, &EvernoteConnection::startNextJob);
376 if (job->jobPriority() == EvernoteJob::JobPriorityHigh) {410 if (job->jobPriority() == EvernoteJob::JobPriorityHigh) {
377 qDebug() << "[JobQueue] Prepending high priority job request:" << job->toString();411 qCDebug(dcJobQueue) << "Adding high priority job request:" << job->toString();
378 m_jobQueue.prepend(job);412 m_highPriorityJobQueue.prepend(job);
379 } else {413 } else {
380 qDebug() << "[JobQueue] Appending low priority job request:" << job->toString();414 qCDebug(dcJobQueue) << "Adding low priority job request:" << job->toString();
381 m_jobQueue.append(job);415 m_lowPriorityJobQueue.prepend(job);
382 }416 }
383 startJobQueue();417 startJobQueue();
384 }418 }
@@ -401,22 +435,27 @@
401435
402void EvernoteConnection::startJobQueue()436void EvernoteConnection::startJobQueue()
403{437{
404 if (m_jobQueue.isEmpty()) {
405 return;
406 }
407
408 if (m_currentJob) {438 if (m_currentJob) {
409 return;439 return;
410 }440 }
411441
412 m_currentJob = m_jobQueue.takeFirst();442 if (m_highPriorityJobQueue.isEmpty() && m_lowPriorityJobQueue.isEmpty()) {
413 qDebug() << "[JobQueue] Starting job:" << m_currentJob->toString();443 return;
444 }
445
446 if (!m_highPriorityJobQueue.isEmpty()) {
447 m_currentJob = m_highPriorityJobQueue.takeFirst();
448 } else {
449 m_currentJob = m_lowPriorityJobQueue.takeFirst();
450 }
451
452 qCDebug(dcJobQueue) << "Starting job:" << m_currentJob->toString();
414 m_currentJob->start();453 m_currentJob->start();
415}454}
416455
417void EvernoteConnection::startNextJob()456void EvernoteConnection::startNextJob()
418{457{
419 qDebug() << "[JobQueue] Job done:" << m_currentJob->toString();458 qCDebug(dcJobQueue) << "Job done:" << m_currentJob->toString();
420 m_currentJob = 0;459 m_currentJob = 0;
421 startJobQueue();460 startJobQueue();
422}461}
423462
=== modified file 'src/libqtevernote/evernoteconnection.h'
--- src/libqtevernote/evernoteconnection.h 2015-02-26 22:47:10 +0000
+++ src/libqtevernote/evernoteconnection.h 2015-03-06 21:14:46 +0000
@@ -73,6 +73,18 @@
73 QString token() const;73 QString token() const;
74 void setToken(const QString &token);74 void setToken(const QString &token);
7575
76 // This will add the job to the job queue. The job queue will take ownership of the object
77 // and manage it's lifetime.
78 // * If there is an identical job already existing in the queue, the duplicate will be
79 // attached to original job and not actually fetched a second time from the network in
80 // order to reduce network traffic.
81 // * If the new job has a higher priority than the existing one, the existing one will
82 // reprioritized to the higher priorty.
83 // * If the jobs have different originatingObjects, each job will emit the jobDone signal,
84 // if instead the originatingObject is the same in both jobs, only one of them will emit
85 // a jobDone signal. This is useful if you want to reschedule a job with higher priority
86 // without having to track previously queued jobs and avoid invoking the connected slot
87 // multiple times.
76 void enqueue(EvernoteJob *job);88 void enqueue(EvernoteJob *job);
7789
78 bool isConnected() const;90 bool isConnected() const;
@@ -104,7 +116,10 @@
104 bool connectUserStore();116 bool connectUserStore();
105 bool connectNotesStore();117 bool connectNotesStore();
106118
107 EvernoteJob* findDuplicate(EvernoteJob *job);119 EvernoteJob* findExistingDuplicate(EvernoteJob *job);
120
121 // "duplicate" will be attached to "original"
122 void attachDuplicate(EvernoteJob *original, EvernoteJob *duplicate);
108123
109 bool m_useSSL;124 bool m_useSSL;
110 bool m_isConnected;125 bool m_isConnected;
@@ -115,7 +130,8 @@
115130
116 // There must be only one job running at a time131 // There must be only one job running at a time
117 // Do not start jobs other than with startJobQueue()132 // Do not start jobs other than with startJobQueue()
118 QList<EvernoteJob*> m_jobQueue;133 QList<EvernoteJob*> m_highPriorityJobQueue;
134 QList<EvernoteJob*> m_lowPriorityJobQueue;
119 EvernoteJob *m_currentJob;135 EvernoteJob *m_currentJob;
120136
121 // Those need to be mutexed137 // Those need to be mutexed
122138
=== modified file 'src/libqtevernote/jobs/createnotebookjob.cpp'
--- src/libqtevernote/jobs/createnotebookjob.cpp 2014-12-08 20:43:10 +0000
+++ src/libqtevernote/jobs/createnotebookjob.cpp 2015-03-06 21:14:46 +0000
@@ -21,8 +21,6 @@
21#include "createnotebookjob.h"21#include "createnotebookjob.h"
22#include "notebook.h"22#include "notebook.h"
2323
24#include <QDebug>
25
26CreateNotebookJob::CreateNotebookJob(Notebook *notebook, QObject *parent) :24CreateNotebookJob::CreateNotebookJob(Notebook *notebook, QObject *parent) :
27 NotesStoreJob(parent),25 NotesStoreJob(parent),
28 m_notebook(notebook->clone())26 m_notebook(notebook->clone())
2927
=== modified file 'src/libqtevernote/jobs/createnotejob.cpp'
--- src/libqtevernote/jobs/createnotejob.cpp 2014-12-14 02:40:47 +0000
+++ src/libqtevernote/jobs/createnotejob.cpp 2015-03-06 21:14:46 +0000
@@ -20,8 +20,6 @@
2020
21#include "createnotejob.h"21#include "createnotejob.h"
2222
23#include <QDebug>
24
25CreateNoteJob::CreateNoteJob(Note *note, QObject *parent) :23CreateNoteJob::CreateNoteJob(Note *note, QObject *parent) :
26 NotesStoreJob(parent)24 NotesStoreJob(parent)
27{25{
@@ -46,7 +44,6 @@
4644
47void CreateNoteJob::startJob()45void CreateNoteJob::startJob()
48{46{
49 qDebug() << "creating note:" << m_note->guid() << m_note->enmlContent() << m_note->notebookGuid() << m_note->title();
50 evernote::edam::Note input;47 evernote::edam::Note input;
51 input.updateSequenceNum = m_note->updateSequenceNumber();48 input.updateSequenceNum = m_note->updateSequenceNumber();
52 input.__isset.updateSequenceNum = true;49 input.__isset.updateSequenceNum = true;
5350
=== modified file 'src/libqtevernote/jobs/createtagjob.cpp'
--- src/libqtevernote/jobs/createtagjob.cpp 2014-12-10 21:08:38 +0000
+++ src/libqtevernote/jobs/createtagjob.cpp 2015-03-06 21:14:46 +0000
@@ -21,8 +21,6 @@
21#include "createtagjob.h"21#include "createtagjob.h"
22#include "tag.h"22#include "tag.h"
2323
24#include <QDebug>
25
26CreateTagJob::CreateTagJob(Tag *tag, QObject *parent) :24CreateTagJob::CreateTagJob(Tag *tag, QObject *parent) :
27 NotesStoreJob(parent),25 NotesStoreJob(parent),
28 m_tag(tag->clone())26 m_tag(tag->clone())
2927
=== modified file 'src/libqtevernote/jobs/evernotejob.cpp'
--- src/libqtevernote/jobs/evernotejob.cpp 2015-02-27 21:32:29 +0000
+++ src/libqtevernote/jobs/evernotejob.cpp 2015-03-06 21:14:46 +0000
@@ -20,6 +20,7 @@
2020
21#include "evernotejob.h"21#include "evernotejob.h"
22#include "evernoteconnection.h"22#include "evernoteconnection.h"
23#include "logging.h"
2324
24// Thrift25// Thrift
25#include <arpa/inet.h> // seems thrift forgot this one26#include <arpa/inet.h> // seems thrift forgot this one
@@ -33,16 +34,15 @@
3334
34#include <libintl.h>35#include <libintl.h>
3536
36#include <QDebug>
37
38using namespace apache::thrift;37using namespace apache::thrift;
39using namespace apache::thrift::protocol;38using namespace apache::thrift::protocol;
40using namespace apache::thrift::transport;39using namespace apache::thrift::transport;
4140
42EvernoteJob::EvernoteJob(QObject *parent, JobPriority jobPriority) :41EvernoteJob::EvernoteJob(QObject *originatingObject, JobPriority jobPriority) :
43 QThread(parent),42 QThread(nullptr),
44 m_token(EvernoteConnection::instance()->token()),43 m_token(EvernoteConnection::instance()->token()),
45 m_jobPriority(jobPriority)44 m_jobPriority(jobPriority),
45 m_originatingObject(originatingObject)
46{46{
47}47}
4848
@@ -63,7 +63,7 @@
63void EvernoteJob::run()63void EvernoteJob::run()
64{64{
65 if (!EvernoteConnection::instance()->isConnected()) {65 if (!EvernoteConnection::instance()->isConnected()) {
66 qWarning() << "EvernoteConnection is not connected. (" << this->metaObject()->className() << ")";66 qCWarning(dcJobQueue) << "EvernoteConnection is not connected. (" << toString() << ")";
67 emitJobDone(EvernoteConnection::ErrorCodeUserException, QStringLiteral("Not connected."));67 emitJobDone(EvernoteConnection::ErrorCodeUserException, QStringLiteral("Not connected."));
68 return;68 return;
69 }69 }
@@ -76,9 +76,9 @@
76 startJob();76 startJob();
77 emitJobDone(EvernoteConnection::ErrorCodeNoError, QString());77 emitJobDone(EvernoteConnection::ErrorCodeNoError, QString());
78 } catch (const TTransportException & e) {78 } catch (const TTransportException & e) {
79 qWarning() << "TTransportException in" << metaObject()->className() << e.what();79 qCWarning(dcJobQueue) << "TTransportException in" << metaObject()->className() << e.what();
80 if (tryCount < 2) {80 if (tryCount < 2) {
81 qWarning() << "[JobQueue] Resetting connection...";81 qCWarning(dcJobQueue) << "Resetting connection...";
82 try {82 try {
83 resetConnection();83 resetConnection();
84 } catch(...) {}84 } catch(...) {}
@@ -87,9 +87,9 @@
87 emitJobDone(EvernoteConnection::ErrorCodeConnectionLost, e.what());87 emitJobDone(EvernoteConnection::ErrorCodeConnectionLost, e.what());
88 }88 }
89 } catch (const TApplicationException &e) {89 } catch (const TApplicationException &e) {
90 qWarning() << "TApplicationException in " << metaObject()->className() << e.what();90 qCWarning(dcJobQueue) << "TApplicationException in " << metaObject()->className() << e.what();
91 if (tryCount < 2) {91 if (tryCount < 2) {
92 qWarning() << "Resetting connection...";92 qCWarning(dcJobQueue) << "Resetting connection...";
93 try {93 try {
94 resetConnection();94 resetConnection();
95 } catch(...) {}95 } catch(...) {}
@@ -159,10 +159,10 @@
159 break;159 break;
160 }160 }
161 message = message.arg(QString::fromStdString(e.parameter));161 message = message.arg(QString::fromStdString(e.parameter));
162 qWarning() << metaObject()->className() << "EDAMUserException:" << message;162 qCWarning(dcJobQueue) << metaObject()->className() << "EDAMUserException:" << message;
163 emitJobDone(EvernoteConnection::ErrorCodeUserException, message);163 emitJobDone(EvernoteConnection::ErrorCodeUserException, message);
164 } catch (const evernote::edam::EDAMSystemException &e) {164 } catch (const evernote::edam::EDAMSystemException &e) {
165 qWarning() << "EDAMSystemException in" << metaObject()->className() << e.what() << e.errorCode << QString::fromStdString(e.message);165 qCWarning(dcJobQueue) << "EDAMSystemException in" << metaObject()->className() << e.what() << e.errorCode << QString::fromStdString(e.message);
166 QString message;166 QString message;
167 EvernoteConnection::ErrorCode errorCode;167 EvernoteConnection::ErrorCode errorCode;
168 switch (e.errorCode) {168 switch (e.errorCode) {
@@ -199,6 +199,11 @@
199 return metaObject()->className();199 return metaObject()->className();
200}200}
201201
202QObject *EvernoteJob::originatingObject() const
203{
204 return m_originatingObject;
205}
206
202QString EvernoteJob::token()207QString EvernoteJob::token()
203{208{
204 return m_token;209 return m_token;
205210
=== modified file 'src/libqtevernote/jobs/evernotejob.h'
--- src/libqtevernote/jobs/evernotejob.h 2015-02-26 22:47:10 +0000
+++ src/libqtevernote/jobs/evernotejob.h 2015-03-06 21:14:46 +0000
@@ -37,8 +37,7 @@
37 * your job won't be executed but you should instead forward the other's job results.37 * your job won't be executed but you should instead forward the other's job results.
38 *38 *
39 * Jobs can be enqueue()d in NotesStore.39 * Jobs can be enqueue()d in NotesStore.
40 * They will destroy themselves when finished.40 * The jobqueue will take care about starting them and deleting them.
41 * The jobqueue will take care about starting them.
42 */41 */
43class EvernoteJob : public QThread42class EvernoteJob : public QThread
44{43{
@@ -49,7 +48,7 @@
49 JobPriorityLow48 JobPriorityLow
50 };49 };
5150
52 explicit EvernoteJob(QObject *parent = 0, JobPriority jobPriority = JobPriorityHigh);51 explicit EvernoteJob(QObject *originatingObject = 0, JobPriority jobPriority = JobPriorityHigh);
53 virtual ~EvernoteJob();52 virtual ~EvernoteJob();
5453
55 JobPriority jobPriority() const;54 JobPriority jobPriority() const;
@@ -63,6 +62,8 @@
6362
64 virtual QString toString() const;63 virtual QString toString() const;
6564
65 QObject* originatingObject() const;
66
66signals:67signals:
67 void connectionLost(const QString &errorMessage);68 void connectionLost(const QString &errorMessage);
6869
@@ -76,6 +77,7 @@
76private:77private:
77 QString m_token;78 QString m_token;
78 JobPriority m_jobPriority;79 JobPriority m_jobPriority;
80 QObject *m_originatingObject;
7981
80 friend class EvernoteConnection;82 friend class EvernoteConnection;
81};83};
8284
=== modified file 'src/libqtevernote/jobs/expungenotebookjob.cpp'
--- src/libqtevernote/jobs/expungenotebookjob.cpp 2014-09-19 21:31:39 +0000
+++ src/libqtevernote/jobs/expungenotebookjob.cpp 2015-03-06 21:14:46 +0000
@@ -20,8 +20,6 @@
2020
21#include "expungenotebookjob.h"21#include "expungenotebookjob.h"
2222
23#include <QDebug>
24
25ExpungeNotebookJob::ExpungeNotebookJob(const QString &guid, QObject *parent) :23ExpungeNotebookJob::ExpungeNotebookJob(const QString &guid, QObject *parent) :
26 NotesStoreJob(parent),24 NotesStoreJob(parent),
27 m_guid(guid)25 m_guid(guid)
2826
=== modified file 'src/libqtevernote/jobs/fetchnotebooksjob.cpp'
--- src/libqtevernote/jobs/fetchnotebooksjob.cpp 2014-09-19 21:31:39 +0000
+++ src/libqtevernote/jobs/fetchnotebooksjob.cpp 2015-03-06 21:14:46 +0000
@@ -20,8 +20,6 @@
2020
21#include "fetchnotebooksjob.h"21#include "fetchnotebooksjob.h"
2222
23#include <QDebug>
24
25FetchNotebooksJob::FetchNotebooksJob(QObject *parent) :23FetchNotebooksJob::FetchNotebooksJob(QObject *parent) :
26 NotesStoreJob(parent)24 NotesStoreJob(parent)
27{25{
2826
=== modified file 'src/libqtevernote/jobs/fetchnotesjob.cpp'
--- src/libqtevernote/jobs/fetchnotesjob.cpp 2015-02-26 22:47:10 +0000
+++ src/libqtevernote/jobs/fetchnotesjob.cpp 2015-03-06 21:14:46 +0000
@@ -25,8 +25,6 @@
25// evernote sdk25// evernote sdk
26#include "Limits_constants.h"26#include "Limits_constants.h"
2727
28#include <QDebug>
29
30FetchNotesJob::FetchNotesJob(const QString &filterNotebookGuid, const QString &searchWords, int startIndex, int chunkSize, QObject *parent) :28FetchNotesJob::FetchNotesJob(const QString &filterNotebookGuid, const QString &searchWords, int startIndex, int chunkSize, QObject *parent) :
31 NotesStoreJob(parent),29 NotesStoreJob(parent),
32 m_filterNotebookGuid(filterNotebookGuid),30 m_filterNotebookGuid(filterNotebookGuid),
@@ -43,7 +41,9 @@
43 return false;41 return false;
44 }42 }
45 return this->m_filterNotebookGuid == otherJob->m_filterNotebookGuid43 return this->m_filterNotebookGuid == otherJob->m_filterNotebookGuid
46 && this->m_searchWords == otherJob->m_searchWords;44 && this->m_searchWords == otherJob->m_searchWords
45 && this->m_startIndex == otherJob->m_startIndex
46 && this->m_chunkSize == otherJob->m_chunkSize;
47}47}
4848
49void FetchNotesJob::attachToDuplicate(const EvernoteJob *other)49void FetchNotesJob::attachToDuplicate(const EvernoteJob *other)
5050
=== modified file 'src/libqtevernote/jobs/fetchtagsjob.cpp'
--- src/libqtevernote/jobs/fetchtagsjob.cpp 2014-10-09 00:08:52 +0000
+++ src/libqtevernote/jobs/fetchtagsjob.cpp 2015-03-06 21:14:46 +0000
@@ -20,8 +20,6 @@
2020
21#include "fetchtagsjob.h"21#include "fetchtagsjob.h"
2222
23#include <QDebug>
24
25FetchTagsJob::FetchTagsJob(QObject *parent) :23FetchTagsJob::FetchTagsJob(QObject *parent) :
26 NotesStoreJob(parent)24 NotesStoreJob(parent)
27{25{
2826
=== modified file 'src/libqtevernote/jobs/savenotebookjob.cpp'
--- src/libqtevernote/jobs/savenotebookjob.cpp 2015-03-04 00:23:45 +0000
+++ src/libqtevernote/jobs/savenotebookjob.cpp 2015-03-06 21:14:46 +0000
@@ -21,8 +21,6 @@
21#include "savenotebookjob.h"21#include "savenotebookjob.h"
22#include "notebook.h"22#include "notebook.h"
2323
24#include <QDebug>
25
26SaveNotebookJob::SaveNotebookJob(Notebook *notebook, QObject *parent) :24SaveNotebookJob::SaveNotebookJob(Notebook *notebook, QObject *parent) :
27 NotesStoreJob(parent)25 NotesStoreJob(parent)
28{26{
2927
=== modified file 'src/libqtevernote/jobs/savenotejob.cpp'
--- src/libqtevernote/jobs/savenotejob.cpp 2015-02-27 22:15:02 +0000
+++ src/libqtevernote/jobs/savenotejob.cpp 2015-03-06 21:14:46 +0000
@@ -21,8 +21,6 @@
21#include "savenotejob.h"21#include "savenotejob.h"
22#include "note.h"22#include "note.h"
2323
24#include <QDebug>
25
26SaveNoteJob::SaveNoteJob(Note *note, QObject *parent) :24SaveNoteJob::SaveNoteJob(Note *note, QObject *parent) :
27 NotesStoreJob(parent)25 NotesStoreJob(parent)
28{26{
@@ -86,7 +84,6 @@
86 note.attributes.reminderDoneTime = m_note->reminderDoneTime().toMSecsSinceEpoch();84 note.attributes.reminderDoneTime = m_note->reminderDoneTime().toMSecsSinceEpoch();
87 note.attributes.__isset.reminderDoneTime = true;85 note.attributes.__isset.reminderDoneTime = true;
8886
89 qDebug() << "*** needs content sync" << m_note->needsContentSync();
90 if (m_note->needsContentSync()) {87 if (m_note->needsContentSync()) {
91 note.content = m_note->enmlContent().toStdString();88 note.content = m_note->enmlContent().toStdString();
92 note.__isset.content = true;89 note.__isset.content = true;
9390
=== modified file 'src/libqtevernote/jobs/savetagjob.cpp'
--- src/libqtevernote/jobs/savetagjob.cpp 2014-12-13 03:55:52 +0000
+++ src/libqtevernote/jobs/savetagjob.cpp 2015-03-06 21:14:46 +0000
@@ -21,8 +21,6 @@
21#include "savetagjob.h"21#include "savetagjob.h"
22#include "tag.h"22#include "tag.h"
2323
24#include <QDebug>
25
26SaveTagJob::SaveTagJob(Tag *tag, QObject *parent) :24SaveTagJob::SaveTagJob(Tag *tag, QObject *parent) :
27 NotesStoreJob(parent)25 NotesStoreJob(parent)
28{26{
2927
=== added file 'src/libqtevernote/logging.cpp'
--- src/libqtevernote/logging.cpp 1970-01-01 00:00:00 +0000
+++ src/libqtevernote/logging.cpp 2015-03-06 21:14:46 +0000
@@ -0,0 +1,32 @@
1/*
2 * Copyright: 2015 Canonical, Ltd
3 *
4 * This file is part of reminders
5 *
6 * reminders is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * reminders is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
19 * Riccardo Padovani <rpadovani@ubuntu.com>
20 */
21
22#include "logging.h"
23
24#include <QLoggingCategory>
25
26Q_LOGGING_CATEGORY(dcNotesStore, "NotesStore")
27Q_LOGGING_CATEGORY(dcJobQueue,"JobQueue")
28Q_LOGGING_CATEGORY(dcConnection,"Connection")
29Q_LOGGING_CATEGORY(dcSync,"Sync")
30Q_LOGGING_CATEGORY(dcStorage,"Storage")
31Q_LOGGING_CATEGORY(dcEnml,"Enml")
32Q_LOGGING_CATEGORY(dcOrganizer,"Organizer")
033
=== added file 'src/libqtevernote/logging.h'
--- src/libqtevernote/logging.h 1970-01-01 00:00:00 +0000
+++ src/libqtevernote/logging.h 2015-03-06 21:14:46 +0000
@@ -0,0 +1,34 @@
1/*
2 * Copyright: 2015 Canonical, Ltd
3 *
4 * This file is part of reminders
5 *
6 * reminders is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * reminders is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
19 * Riccardo Padovani <rpadovani@ubuntu.com>
20 */
21
22#ifndef LOGGING_H
23#define LOGGING_H
24
25#include <QLoggingCategory>
26
27Q_DECLARE_LOGGING_CATEGORY(dcNotesStore)
28Q_DECLARE_LOGGING_CATEGORY(dcJobQueue)
29Q_DECLARE_LOGGING_CATEGORY(dcConnection)
30Q_DECLARE_LOGGING_CATEGORY(dcSync)
31Q_DECLARE_LOGGING_CATEGORY(dcEnml)
32Q_DECLARE_LOGGING_CATEGORY(dcOrganizer)
33
34#endif
035
=== modified file 'src/libqtevernote/note.cpp'
--- src/libqtevernote/note.cpp 2015-03-05 18:23:25 +0000
+++ src/libqtevernote/note.cpp 2015-03-06 21:14:46 +0000
@@ -21,6 +21,7 @@
21#include "note.h"21#include "note.h"
2222
23#include "notesstore.h"23#include "notesstore.h"
24#include "logging.h"
2425
25#include <libintl.h>26#include <libintl.h>
2627
@@ -28,7 +29,6 @@
28#include <QUrl>29#include <QUrl>
29#include <QUrlQuery>30#include <QUrlQuery>
30#include <QStandardPaths>31#include <QStandardPaths>
31#include <QDebug>
32#include <QCryptographicHash>32#include <QCryptographicHash>
33#include <QFile>33#include <QFile>
3434
@@ -71,15 +71,13 @@
71 infoFile.endGroup();71 infoFile.endGroup();
72 } else {72 } else {
73 // uh oh... have a resource description without file... reset sequence number to indicate we need a sync73 // uh oh... have a resource description without file... reset sequence number to indicate we need a sync
74 qWarning() << "Have a resource description but no resource file for it";74 qCWarning(dcNotesStore) << "Have a resource description but no resource file for it";
75 }75 }
76 }76 }
77 infoFile.endGroup();77 infoFile.endGroup();
7878
79 connect(NotesStore::instance(), &NotesStore::notebookGuidChanged, this, &Note::slotNotebookGuidChanged);79 connect(NotesStore::instance(), &NotesStore::notebookGuidChanged, this, &Note::slotNotebookGuidChanged);
80 connect(NotesStore::instance(), &NotesStore::tagGuidChanged, this, &Note::slotTagGuidChanged);80 connect(NotesStore::instance(), &NotesStore::tagGuidChanged, this, &Note::slotTagGuidChanged);
81
82 qDebug() << "Note created:" << m_guid << m_title << m_tagline << m_content.enml();
83}81}
8482
85Note::~Note()83Note::~Note()
@@ -122,7 +120,6 @@
122 m_guid = guid;120 m_guid = guid;
123 QString newCacheFileName = NotesStore::instance()->storageLocation() + "note-" + guid + ".enml";121 QString newCacheFileName = NotesStore::instance()->storageLocation() + "note-" + guid + ".enml";
124 if (m_cacheFile.exists()) {122 if (m_cacheFile.exists()) {
125 qDebug() << "renaming cachefile from" << m_cacheFile.fileName() << "to" << newCacheFileName;
126 m_cacheFile.rename(newCacheFileName);123 m_cacheFile.rename(newCacheFileName);
127 } else {124 } else {
128 m_cacheFile.setFileName(newCacheFileName);125 m_cacheFile.setFileName(newCacheFileName);
@@ -246,7 +243,7 @@
246243
247QString Note::enmlContent() const244QString Note::enmlContent() const
248{245{
249 load();246 load(true);
250 return m_content.enml();247 return m_content.enml();
251}248}
252249
@@ -266,15 +263,13 @@
266263
267QString Note::htmlContent() const264QString Note::htmlContent() const
268{265{
269 qDebug() << "html content asked;";266 load(true);
270 load();
271 qDebug() << "returning" << m_content.toHtml(m_guid);
272 return m_content.toHtml(m_guid);267 return m_content.toHtml(m_guid);
273}268}
274269
275QString Note::richTextContent() const270QString Note::richTextContent() const
276{271{
277 load();272 load(true);
278 return m_content.toRichText(m_guid);273 return m_content.toRichText(m_guid);
279}274}
280275
@@ -430,9 +425,7 @@
430425
431void Note::setDeleted(bool deleted)426void Note::setDeleted(bool deleted)
432{427{
433 qDebug() << "note" << this << "isDelted:" << m_deleted << "setting to" << deleted;
434 if (m_deleted != deleted) {428 if (m_deleted != deleted) {
435 qDebug() << "setting m_deleted to to" << deleted;
436 m_deleted = deleted;429 m_deleted = deleted;
437 emit deletedChanged();430 emit deletedChanged();
438 }431 }
@@ -518,7 +511,6 @@
518 return m_resources.value(hash);511 return m_resources.value(hash);
519 }512 }
520513
521 qDebug() << "adding resource" << fileName << type;
522 Resource *resource = new Resource(data, hash, fileName, type, this);514 Resource *resource = new Resource(data, hash, fileName, type, this);
523 m_resources.insert(hash, resource);515 m_resources.insert(hash, resource);
524 emit resourcesChanged();516 emit resourcesChanged();
@@ -544,7 +536,7 @@
544{536{
545 QFile importedFile(fileName.path());537 QFile importedFile(fileName.path());
546 if (!importedFile.exists()) {538 if (!importedFile.exists()) {
547 qWarning() << "File doesn't exist. Cannot attach.";539 qCWarning(dcNotesStore) << "File doesn't exist. Cannot attach.";
548 return;540 return;
549 }541 }
550542
@@ -562,11 +554,6 @@
562 m_needsContentSync = true;554 m_needsContentSync = true;
563}555}
564556
565void Note::format(int startPos, int endPos, TextFormat::Format format)
566{
567 qDebug() << "Should format from" << startPos << "to" << endPos << "with format:" << format;
568}
569
570void Note::addTag(const QString &tagGuid)557void Note::addTag(const QString &tagGuid)
571{558{
572 NotesStore::instance()->tagNote(m_guid, tagGuid);559 NotesStore::instance()->tagNote(m_guid, tagGuid);
@@ -638,12 +625,14 @@
638 if (m_loading != loading) {625 if (m_loading != loading) {
639 m_loading = loading;626 m_loading = loading;
640 emit loadingChanged();627 emit loadingChanged();
628 }
641629
642 if (!m_loading) {630 if (m_loading) {
643 m_loadingHighPriority = false;631 if (!m_loadingHighPriority && highPriority) {
644 } else {632 m_loadingHighPriority = true;
645 m_loadingHighPriority = highPriority;
646 }633 }
634 } else {
635 m_loadingHighPriority = false;
647 }636 }
648}637}
649638
@@ -700,9 +689,9 @@
700 m_content.setEnml(QString::fromUtf8(m_cacheFile.readAll()).trimmed());689 m_content.setEnml(QString::fromUtf8(m_cacheFile.readAll()).trimmed());
701 m_tagline = m_content.toPlaintext().left(100);690 m_tagline = m_content.toPlaintext().left(100);
702 m_cacheFile.close();691 m_cacheFile.close();
703 qDebug() << "[Storage] Loaded note from storage:" << m_guid;692 qCDebug(dcNotesStore) << "Loaded note content from disk:" << m_guid;
704 } else {693 } else {
705 qDebug() << "[Storage] Failed attempt to load note from storage:" << m_guid;694 qCDebug(dcNotesStore) << "Failed attempt to load note content from disk:" << m_guid;
706 }695 }
707 m_loaded = true;696 m_loaded = true;
708}697}
709698
=== modified file 'src/libqtevernote/note.h'
--- src/libqtevernote/note.h 2015-03-05 18:23:25 +0000
+++ src/libqtevernote/note.h 2015-03-06 21:14:46 +0000
@@ -23,7 +23,6 @@
2323
24#include "utils/enmldocument.h"24#include "utils/enmldocument.h"
25#include "resource.h"25#include "resource.h"
26#include "utils/textformat.h"
2726
28#include <QObject>27#include <QObject>
29#include <QDateTime>28#include <QDateTime>
@@ -162,7 +161,6 @@
162161
163 Q_INVOKABLE void markTodo(const QString &todoId, bool checked);162 Q_INVOKABLE void markTodo(const QString &todoId, bool checked);
164 Q_INVOKABLE void attachFile(int position, const QUrl &fileName);163 Q_INVOKABLE void attachFile(int position, const QUrl &fileName);
165 Q_INVOKABLE void format(int startPos, int endPos, TextFormat::Format format);
166 Q_INVOKABLE void addTag(const QString &tagGuid);164 Q_INVOKABLE void addTag(const QString &tagGuid);
167 Q_INVOKABLE void removeTag(const QString &tagGuid);165 Q_INVOKABLE void removeTag(const QString &tagGuid);
168166
@@ -214,7 +212,7 @@
214 void setConflicting(bool conflicting);212 void setConflicting(bool conflicting);
215213
216 // const because we want to load on demand in getters. Keep this private!214 // const because we want to load on demand in getters. Keep this private!
217 void load(bool priorityHigh = true) const;215 void load(bool highPriority = false) const;
218 void loadFromCacheFile() const;216 void loadFromCacheFile() const;
219217
220private:218private:
221219
=== modified file 'src/libqtevernote/notebook.cpp'
--- src/libqtevernote/notebook.cpp 2015-03-04 20:30:55 +0000
+++ src/libqtevernote/notebook.cpp 2015-03-06 21:14:46 +0000
@@ -24,7 +24,7 @@
2424
25#include <libintl.h>25#include <libintl.h>
2626
27#include <QDebug>27#include <QLocale>
28#include <QStandardPaths>28#include <QStandardPaths>
2929
30Notebook::Notebook(QString guid, quint32 updateSequenceNumber, QObject *parent) :30Notebook::Notebook(QString guid, quint32 updateSequenceNumber, QObject *parent) :
@@ -191,7 +191,6 @@
191 }191 }
192 } else {192 } else {
193 if (!m_notesList.contains(noteGuid)) {193 if (!m_notesList.contains(noteGuid)) {
194 qDebug() << "****** appending to notebook";
195 m_notesList.append(noteGuid);194 m_notesList.append(noteGuid);
196 emit noteCountChanged();195 emit noteCountChanged();
197 }196 }
198197
=== modified file 'src/libqtevernote/notebooks.cpp'
--- src/libqtevernote/notebooks.cpp 2015-03-04 00:23:45 +0000
+++ src/libqtevernote/notebooks.cpp 2015-03-06 21:14:46 +0000
@@ -21,8 +21,6 @@
21#include "notebooks.h"21#include "notebooks.h"
22#include "notebook.h"22#include "notebook.h"
2323
24#include <QDebug>
25
26Notebooks::Notebooks(QObject *parent) :24Notebooks::Notebooks(QObject *parent) :
27 QAbstractListModel(parent)25 QAbstractListModel(parent)
28{26{
2927
=== modified file 'src/libqtevernote/notes.cpp'
--- src/libqtevernote/notes.cpp 2015-03-04 23:50:24 +0000
+++ src/libqtevernote/notes.cpp 2015-03-06 21:14:46 +0000
@@ -21,8 +21,6 @@
21#include "notes.h"21#include "notes.h"
22#include "note.h"22#include "note.h"
2323
24#include <QDebug>
25
26Notes::Notes(QObject *parent) :24Notes::Notes(QObject *parent) :
27 QSortFilterProxyModel(parent),25 QSortFilterProxyModel(parent),
28 m_onlyReminders(false),26 m_onlyReminders(false),
2927
=== modified file 'src/libqtevernote/notesstore.cpp'
--- src/libqtevernote/notesstore.cpp 2015-03-04 23:24:54 +0000
+++ src/libqtevernote/notesstore.cpp 2015-03-06 21:14:46 +0000
@@ -27,6 +27,7 @@
27#include "utils/enmldocument.h"27#include "utils/enmldocument.h"
28#include "utils/organizeradapter.h"28#include "utils/organizeradapter.h"
29#include "userstore.h"29#include "userstore.h"
30#include "logging.h"
3031
31#include "jobs/fetchnotesjob.h"32#include "jobs/fetchnotesjob.h"
32#include "jobs/fetchnotebooksjob.h"33#include "jobs/fetchnotebooksjob.h"
@@ -44,7 +45,6 @@
44#include "libintl.h"45#include "libintl.h"
4546
46#include <QImage>47#include <QImage>
47#include <QDebug>
48#include <QStandardPaths>48#include <QStandardPaths>
49#include <QUuid>49#include <QUuid>
50#include <QPointer>50#include <QPointer>
@@ -59,6 +59,7 @@
59 m_notebooksLoading(false),59 m_notebooksLoading(false),
60 m_tagsLoading(false)60 m_tagsLoading(false)
61{61{
62 qCDebug(dcNotesStore) << "Creating NotesStore instance.";
62 connect(UserStore::instance(), &UserStore::usernameChanged, this, &NotesStore::userStoreConnected);63 connect(UserStore::instance(), &UserStore::usernameChanged, this, &NotesStore::userStoreConnected);
6364
64 qRegisterMetaType<evernote::edam::NotesMetadataList>("evernote::edam::NotesMetadataList");65 qRegisterMetaType<evernote::edam::NotesMetadataList>("evernote::edam::NotesMetadataList");
@@ -72,7 +73,7 @@
7273
73 QDir storageDir(QStandardPaths::standardLocations(QStandardPaths::DataLocation).first());74 QDir storageDir(QStandardPaths::standardLocations(QStandardPaths::DataLocation).first());
74 if (!storageDir.exists()) {75 if (!storageDir.exists()) {
75 qDebug() << "creating storage directory:" << storageDir.absolutePath();76 qCDebug(dcNotesStore) << "Creating storage directory:" << storageDir.absolutePath();
76 storageDir.mkpath(storageDir.absolutePath());77 storageDir.mkpath(storageDir.absolutePath());
77 }78 }
78}79}
@@ -97,7 +98,7 @@
97 return;98 return;
98 }99 }
99 if (!UserStore::instance()->username().isEmpty() && username != UserStore::instance()->username()) {100 if (!UserStore::instance()->username().isEmpty() && username != UserStore::instance()->username()) {
100 qWarning() << "Logged in to Evernote. Can't change account manually. User EvernoteConnection to log in to another account or log out and change this manually.";101 qCWarning(dcNotesStore) << "Logged in to Evernote. Can't change account manually. User EvernoteConnection to log in to another account or log out and change this manually.";
101 return;102 return;
102 }103 }
103104
@@ -106,7 +107,7 @@
106 emit usernameChanged();107 emit usernameChanged();
107108
108 m_cacheFile = storageLocation() + "notes.cache";109 m_cacheFile = storageLocation() + "notes.cache";
109 qDebug() << "initialized cacheFile" << m_cacheFile;110 qCDebug(dcNotesStore) << "Initialized cacheFile:" << m_cacheFile;
110 loadFromCacheFile();111 loadFromCacheFile();
111 }112 }
112}113}
@@ -118,7 +119,7 @@
118119
119void NotesStore::userStoreConnected(const QString &username)120void NotesStore::userStoreConnected(const QString &username)
120{121{
121 qDebug() << "User store connected!" << username;122 qCDebug(dcNotesStore) << "User store connected! Using username:" << username;
122 setUsername(username);123 setUsername(username);
123124
124 refreshNotebooks();125 refreshNotebooks();
@@ -274,6 +275,7 @@
274{275{
275 QString newGuid = QUuid::createUuid().toString();276 QString newGuid = QUuid::createUuid().toString();
276 newGuid.remove("{").remove("}");277 newGuid.remove("{").remove("}");
278 qCDebug(dcNotesStore) << "Creating notebook:" << newGuid;
277 Notebook *notebook = new Notebook(newGuid, 1, this);279 Notebook *notebook = new Notebook(newGuid, 1, this);
278 notebook->setName(name);280 notebook->setName(name);
279 if (m_notebooks.isEmpty()) {281 if (m_notebooks.isEmpty()) {
@@ -287,6 +289,7 @@
287 syncToCacheFile(notebook);289 syncToCacheFile(notebook);
288290
289 if (EvernoteConnection::instance()->isConnected()) {291 if (EvernoteConnection::instance()->isConnected()) {
292 qCDebug(dcSync) << "Creating notebook on server:" << notebook->guid();
290 notebook->setLoading(true);293 notebook->setLoading(true);
291 CreateNotebookJob *job = new CreateNotebookJob(notebook);294 CreateNotebookJob *job = new CreateNotebookJob(notebook);
292 connect(job, &CreateNotebookJob::jobDone, this, &NotesStore::createNotebookJobDone);295 connect(job, &CreateNotebookJob::jobDone, this, &NotesStore::createNotebookJobDone);
@@ -298,19 +301,21 @@
298{301{
299 Notebook *notebook = m_notebooksHash.value(tmpGuid);302 Notebook *notebook = m_notebooksHash.value(tmpGuid);
300 if (!notebook) {303 if (!notebook) {
301 qWarning() << "Cannot find temporary notebook after create finished";304 qCWarning(dcSync) << "Cannot find temporary notebook after create finished";
302 return;305 return;
303 }306 }
304307
305 notebook->setLoading(false);308 notebook->setLoading(false);
306309
307 if (errorCode != EvernoteConnection::ErrorCodeNoError) {310 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
308 qWarning() << "Error creating notebook:" << errorMessage;311 qCWarning(dcSync) << "Error creating notebook:" << errorMessage;
309 notebook->setSyncError(true);312 notebook->setSyncError(true);
310 return;313 return;
311 }314 }
312 QString guid = QString::fromStdString(result.guid);315 QString guid = QString::fromStdString(result.guid);
313 qDebug() << "create notebooks job done2";316
317 qCDebug(dcSync) << "Notebook created on server. Old guid:" << tmpGuid << "New guid:" << guid;
318 qCDebug(dcNotesStore) << "Changing notebook guid. Old guid:" << tmpGuid << "New guid:" << guid;
314319
315 m_notebooksHash.insert(guid, notebook);320 m_notebooksHash.insert(guid, notebook);
316 notebook->setGuid(QString::fromStdString(result.guid));321 notebook->setGuid(QString::fromStdString(result.guid));
@@ -338,7 +343,7 @@
338{343{
339 Notebook *notebook = m_notebooksHash.value(guid);344 Notebook *notebook = m_notebooksHash.value(guid);
340 if (!notebook) {345 if (!notebook) {
341 qWarning() << "Can't save notebook. Guid not found:" << guid;346 qCWarning(dcNotesStore) << "Can't save notebook. Guid not found:" << guid;
342 return;347 return;
343 }348 }
344349
@@ -358,11 +363,11 @@
358{363{
359 Notebook *notebook = m_notebooksHash.value(guid);364 Notebook *notebook = m_notebooksHash.value(guid);
360 if (!notebook) {365 if (!notebook) {
361 qWarning() << "[NotesStore] Notebook guid not found:" << guid;366 qCWarning(dcNotesStore) << "Notebook guid not found:" << guid;
362 return;367 return;
363 }368 }
364369
365 qDebug() << "[NotesStore] Setting default notebook:" << guid;370 qCDebug(dcNotesStore) << "Setting default notebook:" << guid;
366 foreach (Notebook *tmp, m_notebooks) {371 foreach (Notebook *tmp, m_notebooks) {
367 if (tmp->isDefaultNotebook()) {372 if (tmp->isDefaultNotebook()) {
368 tmp->setIsDefaultNotebook(false);373 tmp->setIsDefaultNotebook(false);
@@ -379,7 +384,7 @@
379{384{
380 Tag *tag = m_tagsHash.value(guid);385 Tag *tag = m_tagsHash.value(guid);
381 if (!tag) {386 if (!tag) {
382 qWarning() << "Can't save tag. Guid not found:" << guid;387 qCWarning(dcNotesStore) << "Can't save tag. Guid not found:" << guid;
383 return;388 return;
384 }389 }
385390
@@ -398,7 +403,7 @@
398void NotesStore::expungeNotebook(const QString &guid)403void NotesStore::expungeNotebook(const QString &guid)
399{404{
400 if (m_username != "@local") {405 if (m_username != "@local") {
401 qWarning() << "[NotesStore] Account managed by Evernote. Cannot delete notebooks.";406 qCWarning(dcNotesStore) << "Account managed by Evernote. Cannot delete notebooks.";
402 m_errorQueue.append(QString(gettext("This account is managed by Evernote. Use the Evernote website to delete notebooks.")));407 m_errorQueue.append(QString(gettext("This account is managed by Evernote. Use the Evernote website to delete notebooks.")));
403 emit errorChanged();408 emit errorChanged();
404 return;409 return;
@@ -406,12 +411,12 @@
406411
407 Notebook* notebook = m_notebooksHash.value(guid);412 Notebook* notebook = m_notebooksHash.value(guid);
408 if (!notebook) {413 if (!notebook) {
409 qWarning() << "[NotesStore] Cannot delete notebook. Notebook not found for guid:" << guid;414 qCWarning(dcNotesStore) << "Cannot delete notebook. Notebook not found for guid:" << guid;
410 return;415 return;
411 }416 }
412417
413 if (notebook->isDefaultNotebook()) {418 if (notebook->isDefaultNotebook()) {
414 qWarning() << "[NotesStore] Cannot delete the default notebook.";419 qCWarning(dcNotesStore) << "Cannot delete the default notebook.";
415 m_errorQueue.append(QString(gettext("Cannot delete the default notebook. Set another notebook to be the default first.")));420 m_errorQueue.append(QString(gettext("Cannot delete the default notebook. Set another notebook to be the default first.")));
416 emit errorChanged();421 emit errorChanged();
417 return;422 return;
@@ -426,7 +431,7 @@
426 }431 }
427 }432 }
428 if (defaultNotebook.isEmpty()) {433 if (defaultNotebook.isEmpty()) {
429 qWarning() << "[NotesStore] No default notebook set. Can't delete notebooks.";434 qCWarning(dcNotesStore) << "No default notebook set. Can't delete notebooks.";
430 return;435 return;
431 }436 }
432437
@@ -434,11 +439,11 @@
434 QString noteGuid = notebook->noteAt(0);439 QString noteGuid = notebook->noteAt(0);
435 Note *note = m_notesHash.value(noteGuid);440 Note *note = m_notesHash.value(noteGuid);
436 if (!note) {441 if (!note) {
437 qWarning() << "[NotesStore] Notebook holds a noteGuid which cannot be found in notes store";442 qCWarning(dcNotesStore) << "Notebook holds a noteGuid which cannot be found in notes store";
438 Q_ASSERT(false);443 Q_ASSERT(false);
439 continue;444 continue;
440 }445 }
441 qDebug() << "[NotesStore] Moving note" << noteGuid << "to default Notebook";446 qCDebug(dcNotesStore) << "Moving note" << noteGuid << "to default Notebook";
442 note->setNotebookGuid(defaultNotebook);447 note->setNotebookGuid(defaultNotebook);
443 saveNote(note->guid());448 saveNote(note->guid());
444 emit noteChanged(note->guid(), defaultNotebook);449 emit noteChanged(note->guid(), defaultNotebook);
@@ -491,16 +496,15 @@
491496
492void NotesStore::createTagJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &tmpGuid, const evernote::edam::Tag &result)497void NotesStore::createTagJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &tmpGuid, const evernote::edam::Tag &result)
493{498{
494 qDebug() << "CreateTagJob done";
495 Tag *tag = m_tagsHash.value(tmpGuid);499 Tag *tag = m_tagsHash.value(tmpGuid);
496 if (!tag) {500 if (!tag) {
497 qWarning() << "Create Tag job done but tag can't be found any more";501 qCWarning(dcSync) << "Create Tag job done but tag can't be found any more";
498 return;502 return;
499 }503 }
500504
501 tag->setLoading(false);505 tag->setLoading(false);
502 if (errorCode != EvernoteConnection::ErrorCodeNoError) {506 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
503 qWarning() << "Error creating tag:" << errorMessage;507 qCWarning(dcSync) << "Error creating tag on server:" << errorMessage;
504 tag->setSyncError(true);508 tag->setSyncError(true);
505 emit tagChanged(tag->guid());509 emit tagChanged(tag->guid());
506 return;510 return;
@@ -532,12 +536,12 @@
532{536{
533 Tag *tag = m_tagsHash.value(QString::fromStdString(result.guid));537 Tag *tag = m_tagsHash.value(QString::fromStdString(result.guid));
534 if (!tag) {538 if (!tag) {
535 qWarning() << "Save tag job finished, but tag can't be found any more";539 qCWarning(dcSync) << "Save tag job finished, but tag can't be found any more";
536 return;540 return;
537 }541 }
538 tag->setLoading(false);542 tag->setLoading(false);
539 if (errorCode != EvernoteConnection::ErrorCodeNoError) {543 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
540 qWarning() << "error updating tag" << errorMessage;544 qCWarning(dcSync) << "Error updating tag on server" << errorMessage;
541 tag->setSyncError(true);545 tag->setSyncError(true);
542 emit tagChanged(tag->guid());546 emit tagChanged(tag->guid());
543 return;547 return;
@@ -554,18 +558,18 @@
554{558{
555 Note *note = m_notesHash.value(noteGuid);559 Note *note = m_notesHash.value(noteGuid);
556 if (!note) {560 if (!note) {
557 qWarning() << "No such note" << noteGuid;561 qCWarning(dcNotesStore) << "No such note" << noteGuid;
558 return;562 return;
559 }563 }
560564
561 Tag *tag = m_tagsHash.value(tagGuid);565 Tag *tag = m_tagsHash.value(tagGuid);
562 if (!tag) {566 if (!tag) {
563 qWarning() << "No such tag" << tagGuid;567 qCWarning(dcNotesStore) << "No such tag" << tagGuid;
564 return;568 return;
565 }569 }
566570
567 if (note->tagGuids().contains(tagGuid)) {571 if (note->tagGuids().contains(tagGuid)) {
568 qWarning() << "Note" << noteGuid << "already tagged with tag" << tagGuid;572 qCWarning(dcNotesStore) << "Note" << noteGuid << "already tagged with tag" << tagGuid;
569 return;573 return;
570 }574 }
571575
@@ -577,18 +581,18 @@
577{581{
578 Note *note = m_notesHash.value(noteGuid);582 Note *note = m_notesHash.value(noteGuid);
579 if (!note) {583 if (!note) {
580 qWarning() << "No such note" << noteGuid;584 qCWarning(dcNotesStore) << "No such note" << noteGuid;
581 return;585 return;
582 }586 }
583587
584 Tag *tag = m_tagsHash.value(tagGuid);588 Tag *tag = m_tagsHash.value(tagGuid);
585 if (!tag) {589 if (!tag) {
586 qWarning() << "No such tag" << tagGuid;590 qCWarning(dcNotesStore) << "No such tag" << tagGuid;
587 return;591 return;
588 }592 }
589593
590 if (!note->tagGuids().contains(tagGuid)) {594 if (!note->tagGuids().contains(tagGuid)) {
591 qWarning() << "Note" << noteGuid << "is not tagged with tag" << tagGuid;595 qCWarning(dcNotesStore) << "Note" << noteGuid << "is not tagged with tag" << tagGuid;
592 return;596 return;
593 }597 }
594598
@@ -601,7 +605,7 @@
601void NotesStore::refreshNotes(const QString &filterNotebookGuid, int startIndex)605void NotesStore::refreshNotes(const QString &filterNotebookGuid, int startIndex)
602{606{
603 if (m_loading && startIndex == 0) {607 if (m_loading && startIndex == 0) {
604 qWarning() << "Still busy with refreshing...";608 qCWarning(dcSync) << "Still busy with refreshing...";
605 return;609 return;
606 }610 }
607611
@@ -626,22 +630,22 @@
626 // All is well...630 // All is well...
627 break;631 break;
628 case EvernoteConnection::ErrorCodeUserException:632 case EvernoteConnection::ErrorCodeUserException:
629 qWarning() << "FetchNotesJobDone: EDAMUserException:" << errorMessage;633 qCWarning(dcSync) << "FetchNotesJobDone: EDAMUserException:" << errorMessage;
630 m_loading = false;634 m_loading = false;
631 emit loadingChanged();635 emit loadingChanged();
632 return; // silently discarding...636 return; // silently discarding...
633 case EvernoteConnection::ErrorCodeConnectionLost:637 case EvernoteConnection::ErrorCodeConnectionLost:
634 qWarning() << "FetchNotesJobDone: Connection with evernote lost:" << errorMessage;638 qCWarning(dcSync) << "FetchNotesJobDone: Connection with evernote lost:" << errorMessage;
635 m_loading = false;639 m_loading = false;
636 emit loadingChanged();640 emit loadingChanged();
637 return; // silently discarding...641 return; // silently discarding...
638 case EvernoteConnection::ErrorCodeNotFoundExcpetion:642 case EvernoteConnection::ErrorCodeNotFoundExcpetion:
639 qWarning() << "FetchNotesJobDone: Item not found on server:" << errorMessage;643 qCWarning(dcSync) << "FetchNotesJobDone: Item not found on server:" << errorMessage;
640 m_loading = false;644 m_loading = false;
641 emit loadingChanged();645 emit loadingChanged();
642 return; // silently discarding...646 return; // silently discarding...
643 default:647 default:
644 qWarning() << "FetchNotesJobDone: Failed to fetch notes list:" << errorMessage << errorCode;648 qCWarning(dcSync) << "FetchNotesJobDone: Failed to fetch notes list:" << errorMessage << errorCode;
645 m_loading = false;649 m_loading = false;
646 emit loadingChanged();650 emit loadingChanged();
647 return;651 return;
@@ -654,7 +658,7 @@
654 QVector<int> changedRoles;658 QVector<int> changedRoles;
655 bool newNote = note == 0;659 bool newNote = note == 0;
656 if (newNote) {660 if (newNote) {
657 qDebug() << "FetchNotesJobDone: Found new note on server.";661 qCDebug(dcSync) << "Found new note on server. Creating local copy:" << QString::fromStdString(result.guid);
658 note = new Note(QString::fromStdString(result.guid), 0, this);662 note = new Note(QString::fromStdString(result.guid), 0, this);
659 connect(note, &Note::reminderChanged, this, &NotesStore::emitDataChanged);663 connect(note, &Note::reminderChanged, this, &NotesStore::emitDataChanged);
660 connect(note, &Note::reminderDoneChanged, this, &NotesStore::emitDataChanged);664 connect(note, &Note::reminderDoneChanged, this, &NotesStore::emitDataChanged);
@@ -671,7 +675,7 @@
671 } else if (note->synced()) {675 } else if (note->synced()) {
672 // Local note did not change. Check if we need to refresh from server.676 // Local note did not change. Check if we need to refresh from server.
673 if (note->updateSequenceNumber() < result.updateSequenceNum) {677 if (note->updateSequenceNumber() < result.updateSequenceNum) {
674 qDebug() << "refreshing note from network. suequence number changed: " << note->updateSequenceNumber() << "->" << result.updateSequenceNum;678 qCDebug(dcSync) << "refreshing note from network. suequence number changed: " << note->updateSequenceNumber() << "->" << result.updateSequenceNum;
675 changedRoles = updateFromEDAM(result, note);679 changedRoles = updateFromEDAM(result, note);
676 refreshNoteContent(note->guid(), FetchNoteJob::LoadContent, EvernoteJob::JobPriorityLow);680 refreshNoteContent(note->guid(), FetchNoteJob::LoadContent, EvernoteJob::JobPriorityLow);
677 syncToCacheFile(note);681 syncToCacheFile(note);
@@ -679,7 +683,7 @@
679 } else {683 } else {
680 // Local note changed. See if we can push our changes.684 // Local note changed. See if we can push our changes.
681 if (note->lastSyncedSequenceNumber() == result.updateSequenceNum) {685 if (note->lastSyncedSequenceNumber() == result.updateSequenceNum) {
682 qDebug() << "Local note" << note->guid() << "has changed while server note did not. Pushing changes.";686 qCDebug(dcSync) << "Local note" << note->guid() << "has changed while server note did not. Pushing changes.";
683687
684 // Make sure we have everything loaded from cache before saving to server688 // Make sure we have everything loaded from cache before saving to server
685 if (!note->loaded() && note->isCached()) {689 if (!note->loaded() && note->isCached()) {
@@ -692,10 +696,10 @@
692 connect(job, &SaveNoteJob::jobDone, this, &NotesStore::saveNoteJobDone);696 connect(job, &SaveNoteJob::jobDone, this, &NotesStore::saveNoteJobDone);
693 EvernoteConnection::instance()->enqueue(job);697 EvernoteConnection::instance()->enqueue(job);
694 } else {698 } else {
695 qWarning() << "CONFLICT: Note has been changed on server and locally!";699 qCWarning(dcSync) << "CONFLICT: Note has been changed on server and locally!";
696 qWarning() << "local note sequence:" << note->updateSequenceNumber();700 qCWarning(dcSync) << "local note sequence:" << note->updateSequenceNumber();
697 qWarning() << "last synced sequence:" << note->lastSyncedSequenceNumber();701 qCWarning(dcSync) << "last synced sequence:" << note->lastSyncedSequenceNumber();
698 qWarning() << "remote sequence:" << result.updateSequenceNum;702 qCWarning(dcSync) << "remote sequence:" << result.updateSequenceNum;
699 note->setConflicting(true);703 note->setConflicting(true);
700 changedRoles << RoleConflicting;704 changedRoles << RoleConflicting;
701 }705 }
@@ -714,10 +718,10 @@
714 }718 }
715719
716 if (results.startIndex + (int32_t)results.notes.size() < results.totalNotes) {720 if (results.startIndex + (int32_t)results.notes.size() < results.totalNotes) {
717 qDebug() << "FetchNotesJobDone: Not all notes fetched yet. Fetching next batch.";721 qCDebug(dcSync) << "Not all notes fetched yet. Fetching next batch.";
718 refreshNotes(filterNotebookGuid, results.startIndex + results.notes.size());722 refreshNotes(filterNotebookGuid, results.startIndex + results.notes.size());
719 } else {723 } else {
720 qDebug() << "Fetched all notes. Starting merge...";724 qCDebug(dcSync) << "Fetched all notes from Evernote. Starting merge of local changes...";
721 m_organizerAdapter->startSync();725 m_organizerAdapter->startSync();
722 m_loading = false;726 m_loading = false;
723 emit loadingChanged();727 emit loadingChanged();
@@ -728,7 +732,7 @@
728 if (!note) {732 if (!note) {
729 continue; // Note might be deleted locally by now733 continue; // Note might be deleted locally by now
730 }734 }
731 qDebug() << "Have a local note that's not available on server!" << note->guid();735 qCDebug(dcSync) << "Have a local note that's not available on server!" << note->guid();
732 if (note->lastSyncedSequenceNumber() == 0) {736 if (note->lastSyncedSequenceNumber() == 0) {
733 // This note hasn't been created on the server yet. Do that now.737 // This note hasn't been created on the server yet. Do that now.
734 bool hasUnsyncedTag = false;738 bool hasUnsyncedTag = false;
@@ -741,15 +745,15 @@
741 }745 }
742 }746 }
743 if (hasUnsyncedTag) {747 if (hasUnsyncedTag) {
744 qDebug() << "Not syncing note to server yet. Have a tag that needs sync first";748 qCDebug(dcSync) << "Not syncing note to server yet. Have a tag that needs sync first";
745 continue;749 continue;
746 }750 }
747 Notebook *notebook = m_notebooksHash.value(note->notebookGuid());751 Notebook *notebook = m_notebooksHash.value(note->notebookGuid());
748 if (notebook && notebook->lastSyncedSequenceNumber() == 0) {752 if (notebook && notebook->lastSyncedSequenceNumber() == 0) {
749 qDebug() << "Not syncing note to server yet. The notebook needs to be synced first";753 qCDebug(dcSync) << "Not syncing note to server yet. The notebook needs to be synced first";
750 continue;754 continue;
751 }755 }
752 qDebug() << "Creating note on server:" << note->guid();756 qCDebug(dcSync) << "Creating note on server:" << note->guid();
753757
754 // Make sure we have everything loaded from cache before saving to server758 // Make sure we have everything loaded from cache before saving to server
755 if (!note->loaded() && note->isCached()) {759 if (!note->loaded() && note->isCached()) {
@@ -782,18 +786,24 @@
782 }786 }
783 }787 }
784 }788 }
789 qCDebug(dcSync) << "Local changes merged.";
785 }790 }
786}791}
787792
788void NotesStore::refreshNoteContent(const QString &guid, FetchNoteJob::LoadWhat what, EvernoteJob::JobPriority priority)793void NotesStore::refreshNoteContent(const QString &guid, FetchNoteJob::LoadWhat what, EvernoteJob::JobPriority priority)
789{794{
790 qDebug() << "fetching note content from network for note" << guid << (what == FetchNoteJob::LoadContent ? "content" : "image");
791 Note *note = m_notesHash.value(guid);795 Note *note = m_notesHash.value(guid);
792 if (!note) {796 if (!note) {
793 qWarning() << "RefreshNoteContent: Can't refresn note content. Note guid not found:" << guid;797 qCWarning(dcSync) << "RefreshNoteContent: Can't refresn note content. Note guid not found:" << guid;
798 return;
799 }
800 qCDebug(dcSync) << "should start another one?" << note->loading() << note->m_loadingHighPriority;
801 if (note->loading() && (priority != EvernoteJob::JobPriorityHigh || note->m_loadingHighPriority)) {
802 qCDebug(dcSync) << "Load already loading with high priorty. Not starting again";
794 return;803 return;
795 }804 }
796 if (EvernoteConnection::instance()->isConnected()) {805 if (EvernoteConnection::instance()->isConnected()) {
806 qCDebug(dcNotesStore) << "Fetching note content from network for note" << guid << (what == FetchNoteJob::LoadContent ? "content" : "image");
797 FetchNoteJob *job = new FetchNoteJob(guid, what, this);807 FetchNoteJob *job = new FetchNoteJob(guid, what, this);
798 job->setJobPriority(priority);808 job->setJobPriority(priority);
799 connect(job, &FetchNoteJob::resultReady, this, &NotesStore::fetchNoteJobDone);809 connect(job, &FetchNoteJob::resultReady, this, &NotesStore::fetchNoteJobDone);
@@ -810,34 +820,30 @@
810 FetchNoteJob *job = static_cast<FetchNoteJob*>(sender());820 FetchNoteJob *job = static_cast<FetchNoteJob*>(sender());
811 Note *note = m_notesHash.value(QString::fromStdString(result.guid));821 Note *note = m_notesHash.value(QString::fromStdString(result.guid));
812 if (!note) {822 if (!note) {
813 qWarning() << "can't find note for this update... ignoring...";823 qCWarning(dcSync) << "can't find note for this update... ignoring...";
814 return;824 return;
815 }825 }
816 QModelIndex noteIndex = index(m_notes.indexOf(note));826 QModelIndex noteIndex = index(m_notes.indexOf(note));
817 QVector<int> roles;827 QVector<int> roles;
818828
819 note->setLoading(false);
820 roles << RoleLoading;
821
822 switch (errorCode) {829 switch (errorCode) {
823 case EvernoteConnection::ErrorCodeNoError:830 case EvernoteConnection::ErrorCodeNoError:
824 // All is well831 // All is well
825 emit dataChanged(noteIndex, noteIndex, roles);
826 break;832 break;
827 case EvernoteConnection::ErrorCodeUserException:833 case EvernoteConnection::ErrorCodeUserException:
828 qWarning() << "FetchNoteJobDone: EDAMUserException:" << errorMessage;834 qCWarning(dcSync) << "FetchNoteJobDone: EDAMUserException:" << errorMessage;
829 emit dataChanged(noteIndex, noteIndex, roles);835 emit dataChanged(noteIndex, noteIndex, roles);
830 return; // silently discarding...836 return; // silently discarding...
831 case EvernoteConnection::ErrorCodeConnectionLost:837 case EvernoteConnection::ErrorCodeConnectionLost:
832 qWarning() << "FetchNoteJobDone: Connection with evernote lost:" << errorMessage;838 qCWarning(dcSync) << "FetchNoteJobDone: Connection with evernote lost:" << errorMessage;
833 emit dataChanged(noteIndex, noteIndex, roles);839 emit dataChanged(noteIndex, noteIndex, roles);
834 return; // silently discarding...840 return; // silently discarding...
835 case EvernoteConnection::ErrorCodeNotFoundExcpetion:841 case EvernoteConnection::ErrorCodeNotFoundExcpetion:
836 qWarning() << "FetchNoteJobDone: Item not found on server:" << errorMessage;842 qCWarning(dcSync) << "FetchNoteJobDone: Item not found on server:" << errorMessage;
837 emit dataChanged(noteIndex, noteIndex, roles);843 emit dataChanged(noteIndex, noteIndex, roles);
838 return; // silently discarding...844 return; // silently discarding...
839 default:845 default:
840 qWarning() << "FetchNoteJobDone: Failed to fetch note content:" << errorMessage << errorCode;846 qCWarning(dcSync) << "FetchNoteJobDone: Failed to fetch note content:" << errorMessage << errorCode;
841 note->setSyncError(true);847 note->setSyncError(true);
842 roles << RoleSyncError;848 roles << RoleSyncError;
843 emit dataChanged(noteIndex, noteIndex, roles);849 emit dataChanged(noteIndex, noteIndex, roles);
@@ -861,7 +867,7 @@
861 // data in the cache, let's refresh the note again with resource data.867 // data in the cache, let's refresh the note again with resource data.
862 bool refreshWithResourceData = false;868 bool refreshWithResourceData = false;
863869
864 qDebug() << "got note content" << note->guid() << (what == FetchNoteJob::LoadContent ? "content" : "image") << result.resources.size();870 qCDebug(dcSync) << "got note content" << note->guid() << (what == FetchNoteJob::LoadContent ? "content" : "image") << result.resources.size();
865 // Resources need to be set before the content because otherwise the image provider won't find them when the content is updated in the ui871 // Resources need to be set before the content because otherwise the image provider won't find them when the content is updated in the ui
866 for (unsigned int i = 0; i < result.resources.size(); ++i) {872 for (unsigned int i = 0; i < result.resources.size(); ++i) {
867873
@@ -872,14 +878,14 @@
872 QString mime = QString::fromStdString(resource.mime);878 QString mime = QString::fromStdString(resource.mime);
873879
874 if (what == FetchNoteJob::LoadResources) {880 if (what == FetchNoteJob::LoadResources) {
875 qDebug() << "[Sync] Resource fetched for note:" << note->guid() << "Filename:" << fileName << "Mimetype:" << mime << "Hash:" << hash;881 qCDebug(dcSync) << "Resource fetched for note:" << note->guid() << "Filename:" << fileName << "Mimetype:" << mime << "Hash:" << hash;
876 QByteArray resourceData = QByteArray(resource.data.body.data(), resource.data.size);882 QByteArray resourceData = QByteArray(resource.data.body.data(), resource.data.size);
877 note->addResource(resourceData, hash, fileName, mime);883 note->addResource(resourceData, hash, fileName, mime);
878 } else if (Resource::isCached(hash)) {884 } else if (Resource::isCached(hash)) {
879 qDebug() << "[Sync] Resource already cached for note:" << note->guid() << "Filename:" << fileName << "Mimetype:" << mime << "Hash:" << hash;885 qCDebug(dcSync) << "Resource already cached for note:" << note->guid() << "Filename:" << fileName << "Mimetype:" << mime << "Hash:" << hash;
880 note->addResource(QByteArray(), hash, fileName, mime);886 note->addResource(QByteArray(), hash, fileName, mime);
881 } else {887 } else {
882 qDebug() << "[Sync] Resource not yet fetched for note:" << note->guid() << "Filename:" << fileName << "Mimetype:" << mime << "Hash:" << hash;888 qCDebug(dcSync) << "Resource not yet fetched for note:" << note->guid() << "Filename:" << fileName << "Mimetype:" << mime << "Hash:" << hash;
883 refreshWithResourceData = true;889 refreshWithResourceData = true;
884 }890 }
885 roles << RoleHtmlContent << RoleEnmlContent << RoleResourceUrls;891 roles << RoleHtmlContent << RoleEnmlContent << RoleResourceUrls;
@@ -910,12 +916,16 @@
910 note->setReminderDoneTime(reminderDoneTime);916 note->setReminderDoneTime(reminderDoneTime);
911 roles << RoleReminderDone << RoleReminderDoneTime;917 roles << RoleReminderDone << RoleReminderDoneTime;
912 }918 }
919
920 note->setLoading(false);
921 roles << RoleLoading;
922
913 emit noteChanged(note->guid(), note->notebookGuid());923 emit noteChanged(note->guid(), note->notebookGuid());
914924
915 emit dataChanged(noteIndex, noteIndex, roles);925 emit dataChanged(noteIndex, noteIndex, roles);
916926
917 if (refreshWithResourceData) {927 if (refreshWithResourceData) {
918 qDebug() << "refreshWithResourceData";928 qCDebug(dcSync) << "Fetching Note resources:" << note->guid();
919 refreshNoteContent(note->guid(), FetchNoteJob::LoadResources, job->jobPriority());929 refreshNoteContent(note->guid(), FetchNoteJob::LoadResources, job->jobPriority());
920 } else {930 } else {
921 syncToCacheFile(note); // Syncs into the list cache931 syncToCacheFile(note); // Syncs into the list cache
@@ -926,7 +936,7 @@
926void NotesStore::refreshNotebooks()936void NotesStore::refreshNotebooks()
927{937{
928 if (!EvernoteConnection::instance()->isConnected()) {938 if (!EvernoteConnection::instance()->isConnected()) {
929 qWarning() << "Not connected. Cannot fetch notebooks from server.";939 qCWarning(dcSync) << "Not connected. Cannot fetch notebooks from server.";
930 return;940 return;
931 }941 }
932942
@@ -947,27 +957,27 @@
947 // All is well...957 // All is well...
948 break;958 break;
949 case EvernoteConnection::ErrorCodeUserException:959 case EvernoteConnection::ErrorCodeUserException:
950 qWarning() << "FetchNotebooksJobDone: EDAMUserException:" << errorMessage;960 qCWarning(dcSync) << "FetchNotebooksJobDone: EDAMUserException:" << errorMessage;
951 // silently discarding...961 // silently discarding...
952 return;962 return;
953 case EvernoteConnection::ErrorCodeConnectionLost:963 case EvernoteConnection::ErrorCodeConnectionLost:
954 qWarning() << "FetchNotebooksJobDone: Connection lost:" << errorMessage;964 qCWarning(dcSync) << "FetchNotebooksJobDone: Connection lost:" << errorMessage;
955 return; // silently discarding965 return; // silently discarding
956 default:966 default:
957 qWarning() << "FetchNotebooksJobDone: Failed to fetch notes list:" << errorMessage << errorCode;967 qCWarning(dcSync) << "FetchNotebooksJobDone: Failed to fetch notes list:" << errorMessage << errorCode;
958 return; // silently discarding968 return; // silently discarding
959 }969 }
960970
961 QList<Notebook*> unhandledNotebooks = m_notebooks;971 QList<Notebook*> unhandledNotebooks = m_notebooks;
962972
963 qDebug() << "[NotesStore] Have" << results.size() << "from Evernote.";973 qCDebug(dcSync) << "Received" << results.size() << "notebooks from Evernote.";
964 for (unsigned int i = 0; i < results.size(); ++i) {974 for (unsigned int i = 0; i < results.size(); ++i) {
965 evernote::edam::Notebook result = results.at(i);975 evernote::edam::Notebook result = results.at(i);
966 Notebook *notebook = m_notebooksHash.value(QString::fromStdString(result.guid));976 Notebook *notebook = m_notebooksHash.value(QString::fromStdString(result.guid));
967 unhandledNotebooks.removeAll(notebook);977 unhandledNotebooks.removeAll(notebook);
968 bool newNotebook = notebook == 0;978 bool newNotebook = notebook == 0;
969 if (newNotebook) {979 if (newNotebook) {
970 qDebug() << "[NotesStore] Found new notebook on Evernote:" << QString::fromStdString(result.guid);980 qCDebug(dcSync) << "Found new notebook on Evernote:" << QString::fromStdString(result.guid);
971 notebook = new Notebook(QString::fromStdString(result.guid), 0, this);981 notebook = new Notebook(QString::fromStdString(result.guid), 0, this);
972 updateFromEDAM(result, notebook);982 updateFromEDAM(result, notebook);
973 m_notebooksHash.insert(notebook->guid(), notebook);983 m_notebooksHash.insert(notebook->guid(), notebook);
@@ -976,25 +986,23 @@
976 syncToCacheFile(notebook);986 syncToCacheFile(notebook);
977 } else if (notebook->synced()) {987 } else if (notebook->synced()) {
978 if (notebook->updateSequenceNumber() < result.updateSequenceNum) {988 if (notebook->updateSequenceNumber() < result.updateSequenceNum) {
979 qDebug() << "[NotesStore] Notebook on Evernote is newer than local copy. Updating:" << notebook->guid();989 qCDebug(dcSync) << "Notebook on Evernote is newer than local copy. Updating:" << notebook->guid();
980 updateFromEDAM(result, notebook);990 updateFromEDAM(result, notebook);
981 emit notebookChanged(notebook->guid());991 emit notebookChanged(notebook->guid());
982 syncToCacheFile(notebook);992 syncToCacheFile(notebook);
983 } else {
984 qDebug() << "[NotesStore] Notebook is in sync:" << notebook->guid();
985 }993 }
986 } else {994 } else {
987 // Local notebook changed. See if we can push our changes995 // Local notebook changed. See if we can push our changes
988 if (result.updateSequenceNum == notebook->lastSyncedSequenceNumber()) {996 if (result.updateSequenceNum == notebook->lastSyncedSequenceNumber()) {
989 qDebug() << "[NotesStore] Local Notebook changed. Uploading changes to Evernote:" << notebook->guid();997 qCDebug(dcNotesStore) << "Local Notebook changed. Uploading changes to Evernote:" << notebook->guid();
990 SaveNotebookJob *job = new SaveNotebookJob(notebook);998 SaveNotebookJob *job = new SaveNotebookJob(notebook);
991 connect(job, &SaveNotebookJob::jobDone, this, &NotesStore::saveNotebookJobDone);999 connect(job, &SaveNotebookJob::jobDone, this, &NotesStore::saveNotebookJobDone);
992 EvernoteConnection::instance()->enqueue(job);1000 EvernoteConnection::instance()->enqueue(job);
993 notebook->setLoading(true);1001 notebook->setLoading(true);
994 emit notebookChanged(notebook->guid());1002 emit notebookChanged(notebook->guid());
995 } else {1003 } else {
996 qWarning() << "[NotesStore] Sync conflict in notebook:" << notebook->name();1004 qCWarning(dcNotesStore) << "Sync conflict in notebook:" << notebook->name();
997 qWarning() << "[NotesStore] Resolving of sync conflicts is not implemented yet.";1005 qCWarning(dcNotesStore) << "Resolving of sync conflicts is not implemented yet.";
998 notebook->setSyncError(true);1006 notebook->setSyncError(true);
999 emit notebookChanged(notebook->guid());1007 emit notebookChanged(notebook->guid());
1000 }1008 }
@@ -1003,14 +1011,14 @@
10031011
1004 foreach (Notebook *notebook, unhandledNotebooks) {1012 foreach (Notebook *notebook, unhandledNotebooks) {
1005 if (notebook->lastSyncedSequenceNumber() == 0) {1013 if (notebook->lastSyncedSequenceNumber() == 0) {
1006 qDebug() << "[NotesStore] Have a local notebook that doesn't exist on Evernote. Creating on server:" << notebook->guid();1014 qCDebug(dcSync) << "Have a local notebook that doesn't exist on Evernote. Creating on server:" << notebook->guid();
1007 notebook->setLoading(true);1015 notebook->setLoading(true);
1008 CreateNotebookJob *job = new CreateNotebookJob(notebook);1016 CreateNotebookJob *job = new CreateNotebookJob(notebook);
1009 connect(job, &CreateNotebookJob::jobDone, this, &NotesStore::createNotebookJobDone);1017 connect(job, &CreateNotebookJob::jobDone, this, &NotesStore::createNotebookJobDone);
1010 EvernoteConnection::instance()->enqueue(job);1018 EvernoteConnection::instance()->enqueue(job);
1011 emit notebookChanged(notebook->guid());1019 emit notebookChanged(notebook->guid());
1012 } else {1020 } else {
1013 qDebug() << "[NotesStore] Notebook has been deleted on the server. Deleting local copy:" << notebook->guid();1021 qCDebug(dcSync) << "Notebook has been deleted on the server. Deleting local copy:" << notebook->guid();
1014 m_notebooks.removeAll(notebook);1022 m_notebooks.removeAll(notebook);
1015 m_notebooksHash.remove(notebook->guid());1023 m_notebooksHash.remove(notebook->guid());
1016 emit notebookRemoved(notebook->guid());1024 emit notebookRemoved(notebook->guid());
@@ -1029,7 +1037,7 @@
1029void NotesStore::refreshTags()1037void NotesStore::refreshTags()
1030{1038{
1031 if (!EvernoteConnection::instance()->isConnected()) {1039 if (!EvernoteConnection::instance()->isConnected()) {
1032 qWarning() << "Not connected. Cannot fetch tags from server.";1040 qCWarning(dcSync) << "Not connected. Cannot fetch tags from server.";
1033 return;1041 return;
1034 }1042 }
1035 m_tagsLoading = true;1043 m_tagsLoading = true;
@@ -1057,14 +1065,14 @@
1057 // All is well...1065 // All is well...
1058 break;1066 break;
1059 case EvernoteConnection::ErrorCodeUserException:1067 case EvernoteConnection::ErrorCodeUserException:
1060 qWarning() << "FetchTagsJobDone: EDAMUserException:" << errorMessage;1068 qCWarning(dcSync) << "FetchTagsJobDone: EDAMUserException:" << errorMessage;
1061 // silently discarding...1069 // silently discarding...
1062 return;1070 return;
1063 case EvernoteConnection::ErrorCodeConnectionLost:1071 case EvernoteConnection::ErrorCodeConnectionLost:
1064 qWarning() << "FetchTagsJobDone: Connection lost:" << errorMessage;1072 qCWarning(dcSync) << "FetchTagsJobDone: Connection lost:" << errorMessage;
1065 return; // silently discarding1073 return; // silently discarding
1066 default:1074 default:
1067 qWarning() << "FetchTagsJobDone: Failed to fetch notes list:" << errorMessage << errorCode;1075 qCWarning(dcSync) << "FetchTagsJobDone: Failed to fetch notes list:" << errorMessage << errorCode;
1068 return; // silently discarding1076 return; // silently discarding
1069 }1077 }
10701078
@@ -1077,7 +1085,7 @@
1077 if (newTag) {1085 if (newTag) {
1078 tag = new Tag(QString::fromStdString(result.guid), result.updateSequenceNum, this);1086 tag = new Tag(QString::fromStdString(result.guid), result.updateSequenceNum, this);
1079 tag->setLastSyncedSequenceNumber(result.updateSequenceNum);1087 tag->setLastSyncedSequenceNumber(result.updateSequenceNum);
1080 qDebug() << "got new tag with seq:" << result.updateSequenceNum << tag->synced() << tag->updateSequenceNumber() << tag->lastSyncedSequenceNumber();1088 qCDebug(dcSync) << "got new tag with seq:" << result.updateSequenceNum << tag->synced() << tag->updateSequenceNumber() << tag->lastSyncedSequenceNumber();
1081 tag->setName(QString::fromStdString(result.name));1089 tag->setName(QString::fromStdString(result.name));
1082 m_tagsHash.insert(tag->guid(), tag);1090 m_tagsHash.insert(tag->guid(), tag);
1083 m_tags.append(tag);1091 m_tags.append(tag);
@@ -1100,7 +1108,7 @@
1100 tag->setLoading(true);1108 tag->setLoading(true);
1101 emit tagChanged(tag->guid());1109 emit tagChanged(tag->guid());
1102 } else {1110 } else {
1103 qWarning() << "CONFLICT in tag" << tag->name();1111 qCWarning(dcSync) << "CONFLICT in tag" << tag->name();
1104 tag->setSyncError(true);1112 tag->setSyncError(true);
1105 emit tagChanged(tag->guid());1113 emit tagChanged(tag->guid());
1106 }1114 }
@@ -1183,7 +1191,7 @@
1183{1191{
1184 Note *note = m_notesHash.value(tmpGuid);1192 Note *note = m_notesHash.value(tmpGuid);
1185 if (!note) {1193 if (!note) {
1186 qWarning() << "Cannot find temporary note after create operation!";1194 qCWarning(dcSync) << "Cannot find temporary note after create operation!";
1187 return;1195 return;
1188 }1196 }
1189 int idx = m_notes.indexOf(note);1197 int idx = m_notes.indexOf(note);
@@ -1193,7 +1201,7 @@
1193 roles << RoleLoading;1201 roles << RoleLoading;
11941202
1195 if (errorCode != EvernoteConnection::ErrorCodeNoError) {1203 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
1196 qWarning() << "Error creating note:" << tmpGuid << errorMessage;1204 qCWarning(dcSync) << "Error creating note on server:" << tmpGuid << errorMessage;
1197 note->setSyncError(true);1205 note->setSyncError(true);
1198 roles << RoleSyncError;1206 roles << RoleSyncError;
1199 emit dataChanged(index(idx), index(idx), roles);1207 emit dataChanged(index(idx), index(idx), roles);
@@ -1206,7 +1214,7 @@
1206 }1214 }
12071215
1208 QString guid = QString::fromStdString(result.guid);1216 QString guid = QString::fromStdString(result.guid);
1209 qDebug() << "Note created on server. Old guid:" << tmpGuid << "New guid:" << guid;1217 qCDebug(dcSync) << "Note created on server. Old guid:" << tmpGuid << "New guid:" << guid;
1210 m_notesHash.insert(guid, note);1218 m_notesHash.insert(guid, note);
1211 note->setGuid(guid);1219 note->setGuid(guid);
1212 m_notesHash.remove(tmpGuid);1220 m_notesHash.remove(tmpGuid);
@@ -1252,7 +1260,7 @@
1252{1260{
1253 Note *note = m_notesHash.value(guid);1261 Note *note = m_notesHash.value(guid);
1254 if (!note) {1262 if (!note) {
1255 qWarning() << "Can't save note. Guid not found:" << guid;1263 qCWarning(dcNotesStore) << "Can't save note. Guid not found:" << guid;
1256 return;1264 return;
1257 }1265 }
1258 note->setUpdateSequenceNumber(note->updateSequenceNumber()+1);1266 note->setUpdateSequenceNumber(note->updateSequenceNumber()+1);
@@ -1283,10 +1291,10 @@
12831291
1284void NotesStore::saveNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result)1292void NotesStore::saveNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Note &result)
1285{1293{
1286 qDebug() << "saveNoteJobDone. guid:" << QString::fromStdString(result.guid);1294 qCDebug(dcSync) << "Note saved to server:" << QString::fromStdString(result.guid);
1287 Note *note = m_notesHash.value(QString::fromStdString(result.guid));1295 Note *note = m_notesHash.value(QString::fromStdString(result.guid));
1288 if (!note) {1296 if (!note) {
1289 qWarning() << "Got a save note job result, but note has disappeared locally.";1297 qCWarning(dcSync) << "Got a save note job result, but note has disappeared locally.";
1290 return;1298 return;
1291 }1299 }
12921300
@@ -1294,7 +1302,7 @@
1294 note->setLoading(false);1302 note->setLoading(false);
12951303
1296 if (errorCode != EvernoteConnection::ErrorCodeNoError) {1304 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
1297 qWarning() << "Error saving note:" << errorMessage;1305 qCWarning(dcSync) << "Error saving note:" << errorMessage;
1298 note->setSyncError(true);1306 note->setSyncError(true);
1299 emit dataChanged(index(idx), index(idx), QVector<int>() << RoleLoading << RoleSyncError);1307 emit dataChanged(index(idx), index(idx), QVector<int>() << RoleLoading << RoleSyncError);
1300 return;1308 return;
@@ -1317,16 +1325,16 @@
1317void NotesStore::saveNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Notebook &result)1325void NotesStore::saveNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const evernote::edam::Notebook &result)
1318{1326{
1319 if (errorCode != EvernoteConnection::ErrorCodeNoError) {1327 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
1320 qWarning() << "error saving notebook" << errorMessage;1328 qCWarning(dcSync) << "Error saving notebook to server" << errorMessage;
1321 return;1329 return;
1322 }1330 }
13231331
1324 Notebook *notebook = m_notebooksHash.value(QString::fromStdString(result.guid));1332 Notebook *notebook = m_notebooksHash.value(QString::fromStdString(result.guid));
1325 if (!notebook) {1333 if (!notebook) {
1326 qWarning() << "Save notebook job done but notebook can't be found any more!";1334 qCWarning(dcSync) << "Save notebook job done but notebook can't be found any more!";
1327 return;1335 return;
1328 }1336 }
1329 qDebug() << "save notebook done for:" << notebook->name() << notebook->lastSyncedSequenceNumber() << notebook->updateSequenceNumber() << result.updateSequenceNum;1337 qCDebug(dcSync) << "Notebooks saved to server:" << notebook->guid();
1330 updateFromEDAM(result, notebook);1338 updateFromEDAM(result, notebook);
1331 notebook->setLoading(false);1339 notebook->setLoading(false);
1332 emit notebookChanged(notebook->guid());1340 emit notebookChanged(notebook->guid());
@@ -1337,7 +1345,7 @@
1337{1345{
1338 Note *note = m_notesHash.value(guid);1346 Note *note = m_notesHash.value(guid);
1339 if (!note) {1347 if (!note) {
1340 qWarning() << "Note not found. Can't delete";1348 qCWarning(dcNotesStore) << "Note not found. Can't delete";
1341 return;1349 return;
1342 }1350 }
13431351
@@ -1354,7 +1362,7 @@
1354 note->deleteLater();1362 note->deleteLater();
1355 } else {1363 } else {
13561364
1357 qDebug() << "setting note" << note << "to deleted" << idx;1365 qCDebug(dcNotesStore) << "Setting note to deleted:" << note->guid();
1358 note->setDeleted(true);1366 note->setDeleted(true);
1359 note->setUpdateSequenceNumber(note->updateSequenceNumber()+1);1367 note->setUpdateSequenceNumber(note->updateSequenceNumber()+1);
1360 emit dataChanged(index(idx), index(idx), QVector<int>() << RoleDeleted);1368 emit dataChanged(index(idx), index(idx), QVector<int>() << RoleDeleted);
@@ -1400,7 +1408,7 @@
1400void NotesStore::deleteNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid)1408void NotesStore::deleteNoteJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid)
1401{1409{
1402 if (errorCode != EvernoteConnection::ErrorCodeNoError) {1410 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
1403 qWarning() << "Cannot delete note:" << errorMessage;1411 qCWarning(dcSync) << "Cannot delete note from server:" << errorMessage;
1404 return;1412 return;
1405 }1413 }
1406 Note *note = m_notesHash.value(guid);1414 Note *note = m_notesHash.value(guid);
@@ -1420,7 +1428,7 @@
1420void NotesStore::expungeNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid)1428void NotesStore::expungeNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid)
1421{1429{
1422 if (errorCode != EvernoteConnection::ErrorCodeNoError) {1430 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
1423 qWarning() << "Error expunging notebook:" << errorMessage;1431 qCWarning(dcSync) << "Error expunging notebook:" << errorMessage;
1424 return;1432 return;
1425 }1433 }
1426 emit notebookRemoved(guid);1434 emit notebookRemoved(guid);
@@ -1465,7 +1473,7 @@
14651473
1466void NotesStore::syncToCacheFile(Note *note)1474void NotesStore::syncToCacheFile(Note *note)
1467{1475{
1468 qDebug() << "syncToCacheFile for note" << note->guid();1476 qCDebug(dcNotesStore) << "Syncing note to disk:" << note->guid();
1469 QSettings cacheFile(m_cacheFile, QSettings::IniFormat);1477 QSettings cacheFile(m_cacheFile, QSettings::IniFormat);
1470 cacheFile.beginGroup("notes");1478 cacheFile.beginGroup("notes");
1471 cacheFile.setValue(note->guid(), note->updateSequenceNumber());1479 cacheFile.setValue(note->guid(), note->updateSequenceNumber());
@@ -1515,6 +1523,7 @@
1515 }1523 }
1516 }1524 }
1517 cacheFile.endGroup();1525 cacheFile.endGroup();
1526 qCDebug(dcNotesStore) << "Loaded" << m_notebooks.count() << "notebooks from disk.";
15181527
1519 cacheFile.beginGroup("tags");1528 cacheFile.beginGroup("tags");
1520 if (cacheFile.allKeys().count() > 0) {1529 if (cacheFile.allKeys().count() > 0) {
@@ -1526,13 +1535,14 @@
1526 }1535 }
1527 }1536 }
1528 cacheFile.endGroup();1537 cacheFile.endGroup();
1538 qCDebug(dcNotesStore) << "Loaded" << m_tags.count() << "tags from disk.";
15291539
1530 cacheFile.beginGroup("notes");1540 cacheFile.beginGroup("notes");
1531 if (cacheFile.allKeys().count() > 0) {1541 if (cacheFile.allKeys().count() > 0) {
1532 beginInsertRows(QModelIndex(), 0, cacheFile.allKeys().count()-1);1542 beginInsertRows(QModelIndex(), 0, cacheFile.allKeys().count()-1);
1533 foreach (const QString &key, cacheFile.allKeys()) {1543 foreach (const QString &key, cacheFile.allKeys()) {
1534 if (m_notesHash.contains(key)) {1544 if (m_notesHash.contains(key)) {
1535 qWarning() << "already have note. Not reloading from cache.";1545 qCWarning(dcNotesStore) << "already have note. Not reloading from cache.";
1536 continue;1546 continue;
1537 }1547 }
1538 Note *note = new Note(key, cacheFile.value(key).toUInt(), this);1548 Note *note = new Note(key, cacheFile.value(key).toUInt(), this);
@@ -1543,6 +1553,7 @@
1543 endInsertRows();1553 endInsertRows();
1544 }1554 }
1545 cacheFile.endGroup();1555 cacheFile.endGroup();
1556 qCDebug(dcNotesStore) << "Loaded" << m_notes.count() << "notes from disk.";
1546}1557}
15471558
1548QVector<int> NotesStore::updateFromEDAM(const evernote::edam::NoteMetadata &evNote, Note *note)1559QVector<int> NotesStore::updateFromEDAM(const evernote::edam::NoteMetadata &evNote, Note *note)
@@ -1623,7 +1634,6 @@
1623 if (evNotebook.__isset.published && evNotebook.published != notebook->published()) {1634 if (evNotebook.__isset.published && evNotebook.published != notebook->published()) {
1624 notebook->setPublished(evNotebook.published);1635 notebook->setPublished(evNotebook.published);
1625 }1636 }
1626 qDebug() << "readong from evernote:" << evNotebook.__isset.defaultNotebook << evNotebook.defaultNotebook << notebook->name();
1627 if (evNotebook.__isset.defaultNotebook && evNotebook.defaultNotebook != notebook->isDefaultNotebook()) {1637 if (evNotebook.__isset.defaultNotebook && evNotebook.defaultNotebook != notebook->isDefaultNotebook()) {
1628 notebook->setIsDefaultNotebook(evNotebook.defaultNotebook);1638 notebook->setIsDefaultNotebook(evNotebook.defaultNotebook);
1629 }1639 }
@@ -1634,7 +1644,7 @@
1634void NotesStore::expungeTag(const QString &guid)1644void NotesStore::expungeTag(const QString &guid)
1635{1645{
1636 if (m_username != "@local") {1646 if (m_username != "@local") {
1637 qWarning() << "This account is managed by Evernote. Cannot delete tags.";1647 qCWarning(dcNotesStore) << "This account is managed by Evernote. Cannot delete tags.";
1638 m_errorQueue.append(gettext("This account is managed by Evernote. Please use the Evernote website to delete tags."));1648 m_errorQueue.append(gettext("This account is managed by Evernote. Please use the Evernote website to delete tags."));
1639 emit errorChanged();1649 emit errorChanged();
1640 return;1650 return;
@@ -1642,7 +1652,7 @@
16421652
1643 Tag *tag = m_tagsHash.value(guid);1653 Tag *tag = m_tagsHash.value(guid);
1644 if (!tag) {1654 if (!tag) {
1645 qWarning() << "[NotesStore] No tag with guid" << guid;1655 qCWarning(dcNotesStore) << "No tag with guid" << guid;
1646 return;1656 return;
1647 }1657 }
16481658
@@ -1650,7 +1660,7 @@
1650 QString noteGuid = tag->noteAt(0);1660 QString noteGuid = tag->noteAt(0);
1651 Note *note = m_notesHash.value(noteGuid);1661 Note *note = m_notesHash.value(noteGuid);
1652 if (!note) {1662 if (!note) {
1653 qWarning() << "[NotesStore] Tag holds note" << noteGuid << "which hasn't been found in Notes Store";1663 qCWarning(dcNotesStore) << "Tag holds note" << noteGuid << "which hasn't been found in Notes Store";
1654 continue;1664 continue;
1655 }1665 }
1656 untagNote(noteGuid, guid);1666 untagNote(noteGuid, guid);
16571667
=== modified file 'src/libqtevernote/resource.cpp'
--- src/libqtevernote/resource.cpp 2015-02-27 00:43:59 +0000
+++ src/libqtevernote/resource.cpp 2015-03-06 21:14:46 +0000
@@ -20,10 +20,10 @@
2020
21#include "resource.h"21#include "resource.h"
22#include "notesstore.h"22#include "notesstore.h"
23#include "logging.h"
2324
24#include <QFile>25#include <QFile>
25#include <QStandardPaths>26#include <QStandardPaths>
26#include <QDebug>
27#include <QCryptographicHash>27#include <QCryptographicHash>
28#include <QFileInfo>28#include <QFileInfo>
29#include <QDir>29#include <QDir>
@@ -44,7 +44,7 @@
44 if (!data.isEmpty() && !file.exists()) {44 if (!data.isEmpty() && !file.exists()) {
4545
46 if (!file.open(QFile::WriteOnly)) {46 if (!file.open(QFile::WriteOnly)) {
47 qWarning() << "error writing file" << m_filePath;47 qCWarning(dcNotesStore) << "error writing file" << m_filePath;
48 return;48 return;
49 }49 }
50 file.write(data);50 file.write(data);
@@ -69,7 +69,7 @@
6969
70 QFile file(path);70 QFile file(path);
71 if (!file.open(QFile::ReadOnly)) {71 if (!file.open(QFile::ReadOnly)) {
72 qWarning() << "Cannot open file for reading...";72 qCWarning(dcNotesStore) << "Cannot open file for reading...";
73 return;73 return;
74 }74 }
75 QByteArray fileContent = file.readAll();75 QByteArray fileContent = file.readAll();
@@ -84,7 +84,7 @@
84 } else if (m_fileName.endsWith(".gif")) {84 } else if (m_fileName.endsWith(".gif")) {
85 m_type = "image/gif";85 m_type = "image/gif";
86 } else {86 } else {
87 qWarning() << "cannot determine mime type of file" << m_fileName;87 qCWarning(dcNotesStore) << "cannot determine mime type of file" << m_fileName;
88 }88 }
8989
90 m_filePath = NotesStore::instance()->storageLocation() + m_hash + "." + m_fileName.split('.').last();90 m_filePath = NotesStore::instance()->storageLocation() + m_hash + "." + m_fileName.split('.').last();
@@ -93,7 +93,7 @@
93 if (!copy.exists()) {93 if (!copy.exists()) {
9494
95 if (!copy.open(QFile::WriteOnly)) {95 if (!copy.open(QFile::WriteOnly)) {
96 qWarning() << "error writing file" << m_filePath;96 qCWarning(dcNotesStore) << "error writing file" << m_filePath;
97 return;97 return;
98 }98 }
99 copy.write(fileContent);99 copy.write(fileContent);
100100
=== modified file 'src/libqtevernote/resourceimageprovider.cpp'
--- src/libqtevernote/resourceimageprovider.cpp 2015-02-20 22:35:03 +0000
+++ src/libqtevernote/resourceimageprovider.cpp 2015-03-06 21:14:46 +0000
@@ -1,10 +1,10 @@
1#include "resourceimageprovider.h"1#include "resourceimageprovider.h"
2#include "logging.h"
23
3#include <notesstore.h>4#include <notesstore.h>
4#include <note.h>5#include <note.h>
56
6#include <QUrlQuery>7#include <QUrlQuery>
7#include <QDebug>
88
9ResourceImageProvider::ResourceImageProvider():9ResourceImageProvider::ResourceImageProvider():
10 QQuickImageProvider(QQuickImageProvider::Image)10 QQuickImageProvider(QQuickImageProvider::Image)
@@ -20,7 +20,7 @@
20 QString resourceHash = arguments.queryItemValue("hash");20 QString resourceHash = arguments.queryItemValue("hash");
21 Note *note = NotesStore::instance()->note(noteGuid);21 Note *note = NotesStore::instance()->note(noteGuid);
22 if (!note) {22 if (!note) {
23 qWarning() << "Unable to find note for resource:" << id;23 qCWarning(dcNotesStore) << "Unable to find note for resource:" << id;
24 return QImage();24 return QImage();
25 }25 }
2626
2727
=== modified file 'src/libqtevernote/tag.h'
--- src/libqtevernote/tag.h 2015-03-04 20:30:55 +0000
+++ src/libqtevernote/tag.h 2015-03-06 21:14:46 +0000
@@ -23,7 +23,6 @@
2323
24#include "utils/enmldocument.h"24#include "utils/enmldocument.h"
25#include "resource.h"25#include "resource.h"
26#include "utils/textformat.h"
2726
28#include <QObject>27#include <QObject>
29#include <QDateTime>28#include <QDateTime>
3029
=== modified file 'src/libqtevernote/tags.cpp'
--- src/libqtevernote/tags.cpp 2015-03-04 00:23:45 +0000
+++ src/libqtevernote/tags.cpp 2015-03-06 21:14:46 +0000
@@ -21,8 +21,6 @@
21#include "tags.h"21#include "tags.h"
22#include "tag.h"22#include "tag.h"
2323
24#include <QDebug>
25
26Tags::Tags(QObject *parent) :24Tags::Tags(QObject *parent) :
27 QAbstractListModel(parent)25 QAbstractListModel(parent)
28{26{
2927
=== modified file 'src/libqtevernote/userstore.cpp'
--- src/libqtevernote/userstore.cpp 2014-12-09 18:50:55 +0000
+++ src/libqtevernote/userstore.cpp 2015-03-06 21:14:46 +0000
@@ -21,6 +21,7 @@
21#include "userstore.h"21#include "userstore.h"
22#include "evernoteconnection.h"22#include "evernoteconnection.h"
23#include "jobs/fetchusernamejob.h"23#include "jobs/fetchusernamejob.h"
24#include "logging.h"
2425
25// Evernote sdk26// Evernote sdk
26#include <UserStore.h>27#include <UserStore.h>
@@ -34,8 +35,6 @@
34#include <transport/TSSLSocket.h>35#include <transport/TSSLSocket.h>
35#include <Thrift.h>36#include <Thrift.h>
3637
37#include <QDebug>
38
39using namespace apache::thrift;38using namespace apache::thrift;
40using namespace apache::thrift::protocol;39using namespace apache::thrift::protocol;
41using namespace apache::thrift::transport;40using namespace apache::thrift::transport;
@@ -78,7 +77,7 @@
78void UserStore::fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result)77void UserStore::fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result)
79{78{
80 if (errorCode != EvernoteConnection::ErrorCodeNoError) {79 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
81 qWarning() << "Error fetching username:" << errorMessage;80 qCWarning(dcConnection) << "Error fetching username:" << errorMessage;
82 return;81 return;
83 }82 }
8483
8584
=== modified file 'src/libqtevernote/utils/enmldocument.cpp'
--- src/libqtevernote/utils/enmldocument.cpp 2015-03-05 18:23:25 +0000
+++ src/libqtevernote/utils/enmldocument.cpp 2015-03-06 21:14:46 +0000
@@ -21,6 +21,7 @@
21#include "enmldocument.h"21#include "enmldocument.h"
22#include "notesstore.h"22#include "notesstore.h"
23#include "note.h"23#include "note.h"
24#include "logging.h"
2425
25#include <QXmlStreamReader>26#include <QXmlStreamReader>
26#include <QXmlStreamWriter>27#include <QXmlStreamWriter>
@@ -28,7 +29,6 @@
28#include <QUrl>29#include <QUrl>
29#include <QUrlQuery>30#include <QUrlQuery>
30#include <QStandardPaths>31#include <QStandardPaths>
31#include <QDebug>
3232
33// ENML spec: http://xml.evernote.com/pub/enml2.dtd33// ENML spec: http://xml.evernote.com/pub/enml2.dtd
34// QML supported HTML subset: http://qt-project.org/doc/qt-5.0/qtgui/richtext-html-subset.html34// QML supported HTML subset: http://qt-project.org/doc/qt-5.0/qtgui/richtext-html-subset.html
@@ -203,7 +203,7 @@
203 }203 }
204 }204 }
205 } else {205 } else {
206 qDebug() << "unknown mediatype" << mediaType;206 qCWarning(dcEnml) << "Unknown mediatype" << mediaType;
207 if (type == TypeRichText) {207 if (type == TypeRichText) {
208 writer.writeAttribute("src", composeMediaTypeUrl(mediaType, noteGuid, hash));208 writer.writeAttribute("src", composeMediaTypeUrl(mediaType, noteGuid, hash));
209 } else if (type == TypeHtml) {209 } else if (type == TypeHtml) {
@@ -276,7 +276,7 @@
276276
277 writer.writeEndElement();277 writer.writeEndElement();
278 writer.writeEndDocument();278 writer.writeEndDocument();
279 qDebug() << "converted to html" << html;279 qCDebug(dcEnml) << QString("Converted to %1:").arg(type == TypeHtml ? "HTML" : "RichText") << html;
280 return html;280 return html;
281}281}
282282
283283
=== modified file 'src/libqtevernote/utils/organizeradapter.cpp'
--- src/libqtevernote/utils/organizeradapter.cpp 2015-02-28 02:48:16 +0000
+++ src/libqtevernote/utils/organizeradapter.cpp 2015-03-06 21:14:46 +0000
@@ -1,7 +1,7 @@
1#include "organizeradapter.h"1#include "organizeradapter.h"
2#include "notesstore.h"2#include "notesstore.h"
3#include "logging.h"
34
4#include <QDebug>
5#include <QOrganizerItemVisualReminder>5#include <QOrganizerItemVisualReminder>
6#include <QOrganizerItemAudibleReminder>6#include <QOrganizerItemAudibleReminder>
7#include <QOrganizerItemSaveRequest>7#include <QOrganizerItemSaveRequest>
@@ -47,12 +47,12 @@
47 // EDS requires extra metadata to be set47 // EDS requires extra metadata to be set
48 m_collection.setExtendedMetaData("collection-type", "Task List");48 m_collection.setExtendedMetaData("collection-type", "Task List");
49 if (!m_manager->saveCollection(&m_collection)) {49 if (!m_manager->saveCollection(&m_collection)) {
50 qWarning() << "WARNING: Creating dedicated collection for reminders was not possible, reminders will be saved into the default collection!";50 qCWarning(dcOrganizer) << "WARNING: Creating dedicated collection for reminders was not possible, reminders will be saved into the default collection!";
51 m_collection = m_manager->defaultCollection();51 m_collection = m_manager->defaultCollection();
52 }52 }
53 }53 }
5454
55 qDebug() << "have collection" << m_collection.id().toString();55 qCDebug(dcOrganizer) << "Have Organizer collection" << m_collection.id().toString();
56}56}
5757
58void OrganizerAdapter::startSync()58void OrganizerAdapter::startSync()
@@ -133,7 +133,7 @@
133 }133 }
134134
135 if (state == QOrganizerAbstractRequest::CanceledState) {135 if (state == QOrganizerAbstractRequest::CanceledState) {
136 qWarning() << "Error syncing reminders. Could not read organizer items.";136 qCWarning(dcOrganizer) << "Error syncing reminders. Could not read organizer items.";
137 m_busy = false;137 m_busy = false;
138 request->deleteLater();138 request->deleteLater();
139 return;139 return;
140140
=== removed file 'src/libqtevernote/utils/textformat.cpp'
--- src/libqtevernote/utils/textformat.cpp 2014-01-29 16:04:00 +0000
+++ src/libqtevernote/utils/textformat.cpp 1970-01-01 00:00:00 +0000
@@ -1,25 +0,0 @@
1/*
2 * Copyright: 2013 Canonical, Ltd
3 *
4 * This file is part of reminders-app
5 *
6 * reminders-app is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * reminders-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
19 */
20
21#include "textformat.h"
22
23TextFormat::TextFormat(QObject *parent): QObject(parent)
24{
25}
260
=== removed file 'src/libqtevernote/utils/textformat.h'
--- src/libqtevernote/utils/textformat.h 2014-01-29 18:27:11 +0000
+++ src/libqtevernote/utils/textformat.h 1970-01-01 00:00:00 +0000
@@ -1,43 +0,0 @@
1/*
2 * Copyright: 2013 Canonical, Ltd
3 *
4 * This file is part of reminders-app
5 *
6 * reminders-app is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * reminders-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
19 */
20
21#ifndef TEXTFORMAT_H
22#define TEXTFORMAT_H
23
24#include <QObject>
25
26class TextFormat: public QObject
27{
28 Q_OBJECT
29 Q_ENUMS(Format)
30public:
31 enum Format {
32 Bold,
33 Italic,
34 Underlined
35 };
36 Q_DECLARE_FLAGS(Formats, Format)
37
38 TextFormat(QObject *parent = 0);
39};
40Q_DECLARE_OPERATORS_FOR_FLAGS(TextFormat::Formats)
41Q_DECLARE_METATYPE(TextFormat::Format)
42
43#endif
440
=== modified file 'src/plugin/Evernote/evernoteplugin.cpp'
--- src/plugin/Evernote/evernoteplugin.cpp 2014-10-09 00:08:52 +0000
+++ src/plugin/Evernote/evernoteplugin.cpp 2015-03-06 21:14:46 +0000
@@ -32,8 +32,6 @@
32#include "tag.h"32#include "tag.h"
33#include "resourceimageprovider.h"33#include "resourceimageprovider.h"
3434
35#include "utils/textformat.h"
36
37#include <QtQml>35#include <QtQml>
3836
39static QObject* userStoreProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)37static QObject* userStoreProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
@@ -64,8 +62,6 @@
64 qmlRegisterUncreatableType<Notebook>(uri, 0, 1, "Notebook", "Cannot create Notes in QML. Use NotesStore.createNotebook() instead.");62 qmlRegisterUncreatableType<Notebook>(uri, 0, 1, "Notebook", "Cannot create Notes in QML. Use NotesStore.createNotebook() instead.");
65 qmlRegisterUncreatableType<Tag>(uri, 0, 1, "Tag", "Cannot create Tags in QML. Use NotesStore.createTag() instead.");63 qmlRegisterUncreatableType<Tag>(uri, 0, 1, "Tag", "Cannot create Tags in QML. Use NotesStore.createTag() instead.");
66 qmlRegisterUncreatableType<Resource>(uri, 0, 1, "Resource", "Cannot create Resources. Use Note.attachFile() instead.");64 qmlRegisterUncreatableType<Resource>(uri, 0, 1, "Resource", "Cannot create Resources. Use Note.attachFile() instead.");
67
68 qmlRegisterUncreatableType<TextFormat>(uri, 0, 1, "TextFormat", "TextFormat is not creatable. It's just here to export enums to QML");
69}65}
7066
71void EvernotePlugin::initializeEngine(QQmlEngine *engine, const char *uri)67void EvernotePlugin::initializeEngine(QQmlEngine *engine, const char *uri)

Subscribers

People subscribed via source and target branches