Merge lp:~mzanetti/reminders-app/fix-save-unloaded into lp:reminders-app

Proposed by Michael Zanetti
Status: Merged
Approved by: Riccardo Padovani
Approved revision: 351
Merged at revision: 354
Proposed branch: lp:~mzanetti/reminders-app/fix-save-unloaded
Merge into: lp:reminders-app
Diff against target: 106 lines (+25/-3)
3 files modified
src/libqtevernote/note.cpp (+9/-0)
src/libqtevernote/note.h (+2/-1)
src/libqtevernote/notesstore.cpp (+14/-2)
To merge this branch: bzr merge lp:~mzanetti/reminders-app/fix-save-unloaded
Reviewer Review Type Date Requested Status
Riccardo Padovani Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+251007@code.launchpad.net

Commit message

Fix an issue where a note can be saved to the server without its content

Description of the change

Sometimes it happens that a newly created note can't be created on the server. For example because the network connection breaks down. If the app is restarted before that recovered and synced, after restart, the note is synced to the server without loading it's content from the cache first.

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 :

lgtm, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/libqtevernote/note.cpp'
--- src/libqtevernote/note.cpp 2015-02-24 22:21:04 +0000
+++ src/libqtevernote/note.cpp 2015-02-25 21:19:39 +0000
@@ -75,6 +75,8 @@
7575
76 connect(NotesStore::instance(), &NotesStore::notebookGuidChanged, this, &Note::slotNotebookGuidChanged);76 connect(NotesStore::instance(), &NotesStore::notebookGuidChanged, this, &Note::slotNotebookGuidChanged);
77 connect(NotesStore::instance(), &NotesStore::tagGuidChanged, this, &Note::slotTagGuidChanged);77 connect(NotesStore::instance(), &NotesStore::tagGuidChanged, this, &Note::slotTagGuidChanged);
78
79 qDebug() << "Note created:" << m_guid << m_title << m_tagline << m_content.enml();
78}80}
7981
80Note::~Note()82Note::~Note()
@@ -585,6 +587,11 @@
585 return m_cacheFile.exists();587 return m_cacheFile.exists();
586}588}
587589
590bool Note::loaded() const
591{
592 return m_loaded;
593}
594
588void Note::save()595void Note::save()
589{596{
590 NotesStore::instance()->saveNote(m_guid);597 NotesStore::instance()->saveNote(m_guid);
@@ -649,10 +656,12 @@
649656
650void Note::loadFromCacheFile() const657void Note::loadFromCacheFile() const
651{658{
659 qDebug() << "Loading from cacheFile:" << m_guid;
652 if (m_cacheFile.exists() && m_cacheFile.open(QFile::ReadOnly)) {660 if (m_cacheFile.exists() && m_cacheFile.open(QFile::ReadOnly)) {
653 m_content.setEnml(QString::fromUtf8(m_cacheFile.readAll()).trimmed());661 m_content.setEnml(QString::fromUtf8(m_cacheFile.readAll()).trimmed());
654 m_tagline = m_content.toPlaintext().left(100);662 m_tagline = m_content.toPlaintext().left(100);
655 m_cacheFile.close();663 m_cacheFile.close();
664 qDebug() << "cache file opened" << m_tagline;
656 }665 }
657 m_loaded = true;666 m_loaded = true;
658}667}
659668
=== modified file 'src/libqtevernote/note.h'
--- src/libqtevernote/note.h 2015-02-16 19:28:02 +0000
+++ src/libqtevernote/note.h 2015-02-25 21:19:39 +0000
@@ -61,7 +61,7 @@
61 Q_PROPERTY(quint32 updateSequenceNumber READ updateSequenceNumber NOTIFY updateSequenceNumberChanged)61 Q_PROPERTY(quint32 updateSequenceNumber READ updateSequenceNumber NOTIFY updateSequenceNumberChanged)
62 Q_PROPERTY(bool deleted READ deleted NOTIFY deletedChanged)62 Q_PROPERTY(bool deleted READ deleted NOTIFY deletedChanged)
63 Q_PROPERTY(bool conflicting READ conflicting NOTIFY conflictingChanged)63 Q_PROPERTY(bool conflicting READ conflicting NOTIFY conflictingChanged)
64// Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)64 Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
65 // Don't forget to update clone() if you add properties!65 // Don't forget to update clone() if you add properties!
6666
67 // Don't clone() "loading" property as results of any current loading operation won't affect the clone.67 // Don't clone() "loading" property as results of any current loading operation won't affect the clone.
@@ -142,6 +142,7 @@
142 quint32 lastSyncedSequenceNumber() const;142 quint32 lastSyncedSequenceNumber() const;
143143
144 bool isCached() const;144 bool isCached() const;
145 bool loaded() const;
145 bool loading() const;146 bool loading() const;
146 bool synced() const;147 bool synced() const;
147 bool syncError() const;148 bool syncError() const;
148149
=== modified file 'src/libqtevernote/notesstore.cpp'
--- src/libqtevernote/notesstore.cpp 2015-02-24 18:55:55 +0000
+++ src/libqtevernote/notesstore.cpp 2015-02-25 21:19:39 +0000
@@ -611,6 +611,12 @@
611 // Local note changed. See if we can push our changes.611 // Local note changed. See if we can push our changes.
612 if (note->lastSyncedSequenceNumber() == result.updateSequenceNum) {612 if (note->lastSyncedSequenceNumber() == result.updateSequenceNum) {
613 qDebug() << "Local note" << note->guid() << "has changed while server note did not. Pushing changes.";613 qDebug() << "Local note" << note->guid() << "has changed while server note did not. Pushing changes.";
614
615 // Make sure we have everything loaded from cache before saving to server
616 if (!note->loaded() && note->isCached()) {
617 note->loadFromCacheFile();
618 }
619
614 note->setLoading(true);620 note->setLoading(true);
615 changedRoles << RoleLoading;621 changedRoles << RoleLoading;
616 SaveNoteJob *job = new SaveNoteJob(note, this);622 SaveNoteJob *job = new SaveNoteJob(note, this);
@@ -674,7 +680,12 @@
674 qDebug() << "Not syncing note to server yet. The notebook needs to be synced first";680 qDebug() << "Not syncing note to server yet. The notebook needs to be synced first";
675 continue;681 continue;
676 }682 }
677 qDebug() << "Creating note on server:" << note->notebookGuid() << m_notebooksHash.keys();683 qDebug() << "Creating note on server:" << note->guid();
684
685 // Make sure we have everything loaded from cache before saving to server
686 if (!note->loaded() && note->isCached()) {
687 note->loadFromCacheFile();
688 }
678689
679 QModelIndex idx = index(m_notes.indexOf(note));690 QModelIndex idx = index(m_notes.indexOf(note));
680 note->setLoading(true);691 note->setLoading(true);
@@ -1092,7 +1103,7 @@
1092 roles << RoleLoading;1103 roles << RoleLoading;
10931104
1094 if (errorCode != EvernoteConnection::ErrorCodeNoError) {1105 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
1095 qWarning() << "Error creating note:" << errorMessage;1106 qWarning() << "Error creating note:" << tmpGuid << errorMessage;
1096 note->setSyncError(true);1107 note->setSyncError(true);
1097 roles << RoleSyncError;1108 roles << RoleSyncError;
1098 emit dataChanged(index(idx), index(idx), roles);1109 emit dataChanged(index(idx), index(idx), roles);
@@ -1105,6 +1116,7 @@
1105 }1116 }
11061117
1107 QString guid = QString::fromStdString(result.guid);1118 QString guid = QString::fromStdString(result.guid);
1119 qDebug() << "Note created on server. Old guid:" << tmpGuid << "New guid:" << guid;
1108 m_notesHash.insert(guid, note);1120 m_notesHash.insert(guid, note);
1109 note->setGuid(guid);1121 note->setGuid(guid);
1110 m_notesHash.remove(tmpGuid);1122 m_notesHash.remove(tmpGuid);

Subscribers

People subscribed via source and target branches