Merge lp:~mzanetti/reminders-app/fix-enable-push into lp:reminders-app

Proposed by Michael Zanetti
Status: Merged
Approved by: Riccardo Padovani
Approved revision: 459
Merged at revision: 460
Proposed branch: lp:~mzanetti/reminders-app/fix-enable-push
Merge into: lp:reminders-app
Diff against target: 616 lines (+175/-106)
13 files modified
src/account-plugin/qml/evernote/Main.qml.in (+2/-2)
src/app/preferences.cpp (+16/-0)
src/app/preferences.h (+3/-0)
src/app/qml/reminders.qml (+33/-15)
src/libqtevernote/jobs/fetchusernamejob.cpp (+2/-4)
src/libqtevernote/jobs/fetchusernamejob.h (+2/-2)
src/libqtevernote/notesstore.cpp (+59/-40)
src/libqtevernote/notesstore.h (+3/-1)
src/libqtevernote/userstore.cpp (+17/-9)
src/libqtevernote/userstore.h (+8/-5)
src/push-helper/core.cpp (+28/-26)
src/push-helper/core.h (+1/-2)
src/push-helper/main.cpp (+1/-0)
To merge this branch: bzr merge lp:~mzanetti/reminders-app/fix-enable-push
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Riccardo Padovani Approve
Review via email: mp+262541@code.launchpad.net

Commit message

Fix the remaining issues in the push notification integration and enable it.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
457. By Michael Zanetti

drop unused included

458. By Michael Zanetti

drop unused method declaration

459. By Michael Zanetti

only try to register push on remote users

Revision history for this message
Riccardo Padovani (rpadovani) wrote :

lgtm

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/account-plugin/qml/evernote/Main.qml.in'
--- src/account-plugin/qml/evernote/Main.qml.in 2015-02-20 21:18:01 +0000
+++ src/account-plugin/qml/evernote/Main.qml.in 2015-06-22 08:14:09 +0000
@@ -24,7 +24,7 @@
24 creationComponent: OAuth {24 creationComponent: OAuth {
25 Connections {25 Connections {
26 target: UserStore26 target: UserStore
27 onUsernameChanged: saveUsername()27 onUserChanged: saveUsername()
28 }28 }
2929
30 function completeCreation(reply) {30 function completeCreation(reply) {
@@ -37,7 +37,7 @@
37 }37 }
3838
39 function saveUsername() {39 function saveUsername() {
40 account.updateDisplayName(UserStore.username)40 account.updateDisplayName(UserStore.userName)
41 account.synced.connect(finished)41 account.synced.connect(finished)
42 account.sync()42 account.sync()
43 }43 }
4444
=== modified file 'src/app/preferences.cpp'
--- src/app/preferences.cpp 2015-02-23 18:00:46 +0000
+++ src/app/preferences.cpp 2015-06-22 08:14:09 +0000
@@ -80,3 +80,19 @@
80 m_settings.endGroup();80 m_settings.endGroup();
81 return colorName;81 return colorName;
82}82}
83
84QString Preferences::tokenForUser(const QString &user)
85{
86 QString token;
87 m_settings.beginGroup("accounts");
88 token = m_settings.value(user).toString();
89 m_settings.endGroup();
90 return token;
91}
92
93void Preferences::setTokenForUser(const QString &user, const QString &token)
94{
95 m_settings.beginGroup("accounts");
96 m_settings.setValue(user, token);
97 m_settings.endGroup();
98}
8399
=== modified file 'src/app/preferences.h'
--- src/app/preferences.h 2015-03-06 00:47:45 +0000
+++ src/app/preferences.h 2015-06-22 08:14:09 +0000
@@ -45,6 +45,9 @@
4545
46 Q_INVOKABLE QString colorForNotebook(const QString &notebookGuid);46 Q_INVOKABLE QString colorForNotebook(const QString &notebookGuid);
4747
48 Q_INVOKABLE QString tokenForUser(const QString &user);
49 Q_INVOKABLE void setTokenForUser(const QString &user, const QString &token);
50
48signals:51signals:
49 void accountNameChanged();52 void accountNameChanged();
50 void haveLocalUserChanged();53 void haveLocalUserChanged();
5154
=== modified file 'src/app/qml/reminders.qml'
--- src/app/qml/reminders.qml 2015-06-12 09:48:22 +0000
+++ src/app/qml/reminders.qml 2015-06-22 08:14:09 +0000
@@ -280,9 +280,13 @@
280 }280 }
281281
282 function registerPushClient() {282 function registerPushClient() {
283 console.log("Registering push client");283 console.log("Registering push client", JSON.stringify({
284 "userId" : "" + UserStore.userId,
285 "appId": root.applicationName + "_reminders",
286 "token": pushClient.token
287 }));
284 var req = new XMLHttpRequest();288 var req = new XMLHttpRequest();
285 req.open("post", "http://162.213.35.108/register", true);289 req.open("post", "https://push.ubuntu.com/gateway/register", true);
286 req.setRequestHeader("content-type", "application/json");290 req.setRequestHeader("content-type", "application/json");
287 req.onreadystatechange = function() {//Call a function when the state changes.291 req.onreadystatechange = function() {//Call a function when the state changes.
288 print("push client register response")292 print("push client register response")
@@ -295,7 +299,7 @@
295 }299 }
296 }300 }
297 req.send(JSON.stringify({301 req.send(JSON.stringify({
298 "userId" : UserStore.username,302 "userId" : "" + UserStore.userId,
299 "appId": root.applicationName + "_reminders",303 "appId": root.applicationName + "_reminders",
300 "token": pushClient.token304 "token": pushClient.token
301 }))305 }))
@@ -324,18 +328,30 @@
324 onNotificationsChanged: {328 onNotificationsChanged: {
325 print("PushClient notification:", notifications)329 print("PushClient notification:", notifications)
326 var notification = JSON.parse(notifications)["payload"];330 var notification = JSON.parse(notifications)["payload"];
327 print("user", notification["userId"])331
328 if (notification["userId"] !== UserStore.username) {332 if (notification["userId"] != UserStore.userId) { // Yes, we want type coercion here.
329 console.warn("user mismatch:", notification["userId"], "!=", UserStore.username)333 console.warn("user mismatch:", notification["userId"], "!=", UserStore.userId)
330 return;334 return;
331 }335 }
332336
333 if (notification["notebookGUID"] !== undefined) {337 switch(notification["reason"]) {
338 case "update":
339 print("Note updated on server:", notification["guid"])
340 if (NotesStore.note(notification["guid"]) === null) {
341 NotesStore.refreshNotes();
342 } else {
343 NotesStore.refreshNoteContent(notification["guid"]);
344 }
345 break;
346 case "create":
347 print("New note appeared on server:", notification["guid"])
348 NotesStore.refreshNotes();
349 break;
350 case "notebook_update":
334 NotesStore.refreshNotebooks();351 NotesStore.refreshNotebooks();
335 NotesStore.refreshNotes(notification["notebookGUID"]);352 break;
336 }353 default:
337 if (notification["noteGUID"] !== undefined) {354 console.warn("Unhandled push notification:", notification["reason"])
338 NotesStore.refreshNoteContent(notification["noteGUID"]);
339 }355 }
340 }356 }
341357
@@ -412,10 +428,12 @@
412428
413 Connections {429 Connections {
414 target: UserStore430 target: UserStore
415 onUsernameChanged: {431 onUserChanged: {
416 print("Logged in as user:", UserStore.username);432 print("Logged in as user:", UserStore.userId, UserStore.userName);
417 // Disabling push notifications as we haven't had a chance to properly test that yet433 preferences.setTokenForUser(UserStore.userId, EvernoteConnection.token);
418 //registerPushClient();434 if (UserStore.userId >= 0) {
435 registerPushClient();
436 }
419 }437 }
420 }438 }
421439
422440
=== modified file 'src/libqtevernote/jobs/fetchusernamejob.cpp'
--- src/libqtevernote/jobs/fetchusernamejob.cpp 2014-09-19 21:31:39 +0000
+++ src/libqtevernote/jobs/fetchusernamejob.cpp 2015-06-22 08:14:09 +0000
@@ -42,12 +42,10 @@
4242
43void FetchUsernameJob::startJob()43void FetchUsernameJob::startJob()
44{44{
45 evernote::edam::User user;45 client()->getUser(m_user, token().toStdString());
46 client()->getUser(user, token().toStdString());
47 m_result = QString::fromStdString(user.username);
48}46}
4947
50void FetchUsernameJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)48void FetchUsernameJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage)
51{49{
52 emit jobDone(errorCode, errorMessage, m_result);50 emit jobDone(errorCode, errorMessage, m_user.id, QString::fromStdString(m_user.username));
53}51}
5452
=== modified file 'src/libqtevernote/jobs/fetchusernamejob.h'
--- src/libqtevernote/jobs/fetchusernamejob.h 2014-09-19 21:31:39 +0000
+++ src/libqtevernote/jobs/fetchusernamejob.h 2015-06-22 08:14:09 +0000
@@ -33,14 +33,14 @@
33 virtual void attachToDuplicate(const EvernoteJob *other) override;33 virtual void attachToDuplicate(const EvernoteJob *other) override;
3434
35signals:35signals:
36 void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result);36 void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const int userId, const QString &userName);
3737
38protected:38protected:
39 void startJob();39 void startJob();
40 void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);40 void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage);
4141
42private:42private:
43 QString m_result;43 evernote::edam::User m_user;
44};44};
4545
46#endif // FETCHUSERNAMEJOB_H46#endif // FETCHUSERNAMEJOB_H
4747
=== modified file 'src/libqtevernote/notesstore.cpp'
--- src/libqtevernote/notesstore.cpp 2015-06-12 09:48:22 +0000
+++ src/libqtevernote/notesstore.cpp 2015-06-22 08:14:09 +0000
@@ -61,7 +61,7 @@
61 m_tagsLoading(false)61 m_tagsLoading(false)
62{62{
63 qCDebug(dcNotesStore) << "Creating NotesStore instance.";63 qCDebug(dcNotesStore) << "Creating NotesStore instance.";
64 connect(UserStore::instance(), &UserStore::usernameChanged, this, &NotesStore::userStoreConnected);64 connect(UserStore::instance(), &UserStore::userChanged, this, &NotesStore::userStoreConnected);
6565
66 qRegisterMetaType<evernote::edam::NotesMetadataList>("evernote::edam::NotesMetadataList");66 qRegisterMetaType<evernote::edam::NotesMetadataList>("evernote::edam::NotesMetadataList");
67 qRegisterMetaType<evernote::edam::Note>("evernote::edam::Note");67 qRegisterMetaType<evernote::edam::Note>("evernote::edam::Note");
@@ -98,7 +98,7 @@
98 // We don't accept an empty username.98 // We don't accept an empty username.
99 return;99 return;
100 }100 }
101 if (!UserStore::instance()->username().isEmpty() && username != UserStore::instance()->username()) {101 if (!UserStore::instance()->userName().isEmpty() && username != UserStore::instance()->userName()) {
102 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.";102 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.";
103 return;103 return;
104 }104 }
@@ -118,8 +118,9 @@
118 return QStandardPaths::standardLocations(QStandardPaths::DataLocation).first() + "/" + m_username + "/";118 return QStandardPaths::standardLocations(QStandardPaths::DataLocation).first() + "/" + m_username + "/";
119}119}
120120
121void NotesStore::userStoreConnected(const QString &username)121void NotesStore::userStoreConnected()
122{122{
123 QString username = UserStore::instance()->userName();
123 qCDebug(dcNotesStore) << "User store connected! Using username:" << username;124 qCDebug(dcNotesStore) << "User store connected! Using username:" << username;
124 setUsername(username);125 setUsername(username);
125126
@@ -738,10 +739,12 @@
738 connect(job, &SaveNoteJob::jobDone, this, &NotesStore::saveNoteJobDone);739 connect(job, &SaveNoteJob::jobDone, this, &NotesStore::saveNoteJobDone);
739 EvernoteConnection::instance()->enqueue(job);740 EvernoteConnection::instance()->enqueue(job);
740 } else {741 } else {
741 qCWarning(dcSync) << "CONFLICT: Note has been changed on server and locally!";742 qCWarning(dcSync) << "********************************************************";
742 qCWarning(dcSync) << "local note sequence:" << note->updateSequenceNumber();743 qCWarning(dcSync) << "* CONFLICT: Note has been changed on server and locally!";
743 qCWarning(dcSync) << "last synced sequence:" << note->lastSyncedSequenceNumber();744 qCWarning(dcSync) << "* local note sequence:" << note->updateSequenceNumber();
744 qCWarning(dcSync) << "remote sequence:" << result.updateSequenceNum;745 qCWarning(dcSync) << "* last synced sequence:" << note->lastSyncedSequenceNumber();
746 qCWarning(dcSync) << "* remote update sequence:" << result.updateSequenceNum;
747 qCWarning(dcSync) << "********************************************************";
745 note->setConflicting(true);748 note->setConflicting(true);
746 changedRoles << RoleConflicting;749 changedRoles << RoleConflicting;
747750
@@ -826,19 +829,7 @@
826829
827 if (note->synced()) {830 if (note->synced()) {
828 qCDebug(dcSync) << "Note has been deleted from the server and not changed locally. Deleting local note:" << note->guid();831 qCDebug(dcSync) << "Note has been deleted from the server and not changed locally. Deleting local note:" << note->guid();
829 beginRemoveRows(QModelIndex(), idx, idx);832 removeNote(note->guid());
830 m_notes.removeAt(idx);
831 m_notesHash.remove(note->guid());
832 endRemoveRows();
833 emit noteRemoved(note->guid(), note->notebookGuid());
834 emit countChanged();
835
836 QSettings settings(m_cacheFile, QSettings::IniFormat);
837 settings.beginGroup("notes");
838 settings.remove(note->guid());
839 settings.endGroup();
840
841 note->deleteLater();
842 } else {833 } else {
843 qCDebug(dcSync) << "CONFLICT: Note has been deleted from the server but we have unsynced local changes for note:" << note->guid();834 qCDebug(dcSync) << "CONFLICT: Note has been deleted from the server but we have unsynced local changes for note:" << note->guid();
844 FetchNoteJob::LoadWhatFlags flags = 0x0;835 FetchNoteJob::LoadWhatFlags flags = 0x0;
@@ -902,6 +893,12 @@
902 return;893 return;
903 }894 }
904895
896 if (result.deleted > 0) {
897 qCDebug(dcSync) << "Note has been deleted on server. Deleting locally.";
898 removeNote(note->guid());
899 return;
900 }
901
905 if (note->notebookGuid() != QString::fromStdString(result.notebookGuid)) {902 if (note->notebookGuid() != QString::fromStdString(result.notebookGuid)) {
906 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));903 note->setNotebookGuid(QString::fromStdString(result.notebookGuid));
907 roles << RoleGuid;904 roles << RoleGuid;
@@ -914,6 +911,18 @@
914 note->setUpdated(QDateTime::fromMSecsSinceEpoch(result.updated));911 note->setUpdated(QDateTime::fromMSecsSinceEpoch(result.updated));
915 roles << RoleUpdated << RoleUpdatedString;912 roles << RoleUpdated << RoleUpdatedString;
916 }913 }
914 QStringList tagGuids;
915 for (quint32 i = 0; i < result.tagGuids.size(); i++) {
916 QString tag = QString::fromStdString(result.tagGuids.at(i));
917 if (m_tagsHash.contains(tag)) {
918 refreshTags();
919 }
920 tagGuids << tag;
921 }
922 if (note->tagGuids() != tagGuids) {
923 note->setTagGuids(tagGuids);
924 roles << RoleTagGuids;
925 }
917926
918 // Notes are fetched without resources by default. if we discover one or more resources where we don't have927 // Notes are fetched without resources by default. if we discover one or more resources where we don't have
919 // data in the cache, let's refresh the note again with resource data.928 // data in the cache, let's refresh the note again with resource data.
@@ -948,11 +957,14 @@
948 if (what == FetchNoteJob::LoadContent) {957 if (what == FetchNoteJob::LoadContent) {
949 note->setEnmlContent(QString::fromStdString(result.content));958 note->setEnmlContent(QString::fromStdString(result.content));
950 note->setUpdateSequenceNumber(result.updateSequenceNum);959 note->setUpdateSequenceNumber(result.updateSequenceNum);
960 note->setLastSyncedSequenceNumber(result.updateSequenceNum);
951 roles << RoleHtmlContent << RoleEnmlContent << RoleTagline << RolePlaintextContent;961 roles << RoleHtmlContent << RoleEnmlContent << RoleTagline << RolePlaintextContent;
952 }962 }
963 bool syncReminders = false;
953 if (note->reminderOrder() != result.attributes.reminderOrder) {964 if (note->reminderOrder() != result.attributes.reminderOrder) {
954 note->setReminderOrder(result.attributes.reminderOrder);965 note->setReminderOrder(result.attributes.reminderOrder);
955 roles << RoleReminder;966 roles << RoleReminder;
967 syncReminders = true;
956 }968 }
957 QDateTime reminderTime;969 QDateTime reminderTime;
958 if (result.attributes.reminderTime > 0) {970 if (result.attributes.reminderTime > 0) {
@@ -961,6 +973,7 @@
961 if (note->reminderTime() != reminderTime) {973 if (note->reminderTime() != reminderTime) {
962 note->setReminderTime(reminderTime);974 note->setReminderTime(reminderTime);
963 roles << RoleReminderTime << RoleReminderTimeString;975 roles << RoleReminderTime << RoleReminderTimeString;
976 syncReminders = true;
964 }977 }
965 QDateTime reminderDoneTime;978 QDateTime reminderDoneTime;
966 if (result.attributes.reminderDoneTime > 0) {979 if (result.attributes.reminderDoneTime > 0) {
@@ -969,6 +982,10 @@
969 if (note->reminderDoneTime() != reminderDoneTime) {982 if (note->reminderDoneTime() != reminderDoneTime) {
970 note->setReminderDoneTime(reminderDoneTime);983 note->setReminderDoneTime(reminderDoneTime);
971 roles << RoleReminderDone << RoleReminderDoneTime;984 roles << RoleReminderDone << RoleReminderDoneTime;
985 syncReminders = true;
986 }
987 if (syncReminders) {
988 m_organizerAdapter->startSync();
972 }989 }
973990
974 note->setLoading(false);991 note->setLoading(false);
@@ -1456,14 +1473,7 @@
1456 int idx = m_notes.indexOf(note);1473 int idx = m_notes.indexOf(note);
14571474
1458 if (note->lastSyncedSequenceNumber() == 0) {1475 if (note->lastSyncedSequenceNumber() == 0) {
1459 emit noteRemoved(note->guid(), note->notebookGuid());1476 removeNote(guid);
1460 beginRemoveRows(QModelIndex(), idx, idx);
1461 m_notes.takeAt(idx);
1462 m_notesHash.take(guid);
1463 endRemoveRows();
1464 emit countChanged();
1465 deleteFromCacheFile(note);
1466 note->deleteLater();
1467 } else {1477 } else {
14681478
1469 qCDebug(dcNotesStore) << "Setting note to deleted:" << note->guid();1479 qCDebug(dcNotesStore) << "Setting note to deleted:" << note->guid();
@@ -1516,18 +1526,7 @@
1516 qCWarning(dcSync) << "Cannot delete note from server:" << errorMessage;1526 qCWarning(dcSync) << "Cannot delete note from server:" << errorMessage;
1517 return;1527 return;
1518 }1528 }
1519 Note *note = m_notesHash.value(guid);1529 removeNote(guid);
1520 int noteIndex = m_notes.indexOf(note);
1521
1522 emit noteRemoved(guid, note->notebookGuid());
1523
1524 beginRemoveRows(QModelIndex(), noteIndex, noteIndex);
1525 m_notes.takeAt(noteIndex);
1526 m_notesHash.take(guid);
1527 endRemoveRows();
1528 emit countChanged();
1529 deleteFromCacheFile(note);
1530 note->deleteLater();
1531}1530}
15321531
1533void NotesStore::expungeNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid)1532void NotesStore::expungeNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid)
@@ -1786,6 +1785,26 @@
1786 return true;1785 return true;
1787}1786}
17881787
1788void NotesStore::removeNote(const QString &guid)
1789{
1790 Note *note = m_notesHash.value(guid);
1791 int idx = m_notes.indexOf(note);
1792
1793 emit noteRemoved(note->guid(), note->notebookGuid());
1794
1795 beginRemoveRows(QModelIndex(), idx, idx);
1796 m_notes.removeAt(idx);
1797 m_notesHash.remove(note->guid());
1798 endRemoveRows();
1799 emit countChanged();
1800
1801 QSettings settings(m_cacheFile, QSettings::IniFormat);
1802 settings.beginGroup("notes");
1803 settings.remove(note->guid());
1804 settings.endGroup();
1805
1806 note->deleteLater();
1807}
17891808
1790void NotesStore::expungeTag(const QString &guid)1809void NotesStore::expungeTag(const QString &guid)
1791{1810{
17921811
=== modified file 'src/libqtevernote/notesstore.h'
--- src/libqtevernote/notesstore.h 2015-06-11 18:55:24 +0000
+++ src/libqtevernote/notesstore.h 2015-06-22 08:14:09 +0000
@@ -205,7 +205,7 @@
205 void syncToCacheFile(Tag *tag);205 void syncToCacheFile(Tag *tag);
206 void loadFromCacheFile();206 void loadFromCacheFile();
207207
208 void userStoreConnected(const QString &username);208 void userStoreConnected();
209 void emitDataChanged();209 void emitDataChanged();
210 void clear();210 void clear();
211211
@@ -215,6 +215,8 @@
215215
216 bool handleUserError(EvernoteConnection::ErrorCode errorCode);216 bool handleUserError(EvernoteConnection::ErrorCode errorCode);
217217
218 void removeNote(const QString &guid);
219
218private:220private:
219 explicit NotesStore(QObject *parent = 0);221 explicit NotesStore(QObject *parent = 0);
220 static NotesStore *s_instance;222 static NotesStore *s_instance;
221223
=== modified file 'src/libqtevernote/userstore.cpp'
--- src/libqtevernote/userstore.cpp 2015-03-06 00:47:45 +0000
+++ src/libqtevernote/userstore.cpp 2015-06-22 08:14:09 +0000
@@ -42,7 +42,8 @@
42UserStore* UserStore::s_instance = 0;42UserStore* UserStore::s_instance = 0;
4343
44UserStore::UserStore(QObject *parent) :44UserStore::UserStore(QObject *parent) :
45 QObject(parent)45 QObject(parent),
46 m_userId(-1)
46{47{
47 connect(EvernoteConnection::instance(), &EvernoteConnection::isConnectedChanged, this, &UserStore::fetchUsername);48 connect(EvernoteConnection::instance(), &EvernoteConnection::isConnectedChanged, this, &UserStore::fetchUsername);
4849
@@ -57,9 +58,13 @@
57 return s_instance;58 return s_instance;
58}59}
5960
60QString UserStore::username() const61qint32 UserStore::userId() const
61{62{
62 return m_username;63 return m_userId;
64}
65QString UserStore::userName() const
66{
67 return m_userName;
63}68}
6469
65void UserStore::fetchUsername()70void UserStore::fetchUsername()
@@ -69,18 +74,21 @@
69 connect(job, &FetchUsernameJob::jobDone, this, &UserStore::fetchUsernameJobDone);74 connect(job, &FetchUsernameJob::jobDone, this, &UserStore::fetchUsernameJobDone);
70 EvernoteConnection::instance()->enqueue(job);75 EvernoteConnection::instance()->enqueue(job);
71 } else {76 } else {
72 m_username.clear();77 m_userId = -1;
73 emit usernameChanged(m_username);78 m_userName.clear();
79 emit userChanged();
74 }80 }
75}81}
7682
77void UserStore::fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result)83void UserStore::fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const int userId, const QString &userName)
78{84{
79 if (errorCode != EvernoteConnection::ErrorCodeNoError) {85 if (errorCode != EvernoteConnection::ErrorCodeNoError) {
80 qCWarning(dcConnection) << "Error fetching username:" << errorMessage;86 qCWarning(dcConnection) << "Error fetching username:" << errorMessage;
81 return;87 return;
82 }88 }
8389
84 m_username = result;90 qCDebug(dcConnection) << "FetchUsername done. User ID:" << userId << "User name:" << userName;
85 emit usernameChanged(m_username);91 m_userId = userId;
92 m_userName = userName;
93 emit userChanged();
86}94}
8795
=== modified file 'src/libqtevernote/userstore.h'
--- src/libqtevernote/userstore.h 2014-12-08 10:25:48 +0000
+++ src/libqtevernote/userstore.h 2015-06-22 08:14:09 +0000
@@ -33,26 +33,29 @@
33 Q_OBJECT33 Q_OBJECT
3434
35 // TODO: Once we need more than just the username, turn this into a class User35 // TODO: Once we need more than just the username, turn this into a class User
36 Q_PROPERTY(QString username READ username NOTIFY usernameChanged)36 Q_PROPERTY(qint32 userId READ userId NOTIFY userChanged)
37 Q_PROPERTY(QString userName READ userName NOTIFY userChanged)
3738
38public:39public:
39 static UserStore* instance();40 static UserStore* instance();
4041
41 QString username() const;42 qint32 userId() const;
43 QString userName() const;
4244
43signals:45signals:
44 void usernameChanged(const QString &username);46 void userChanged();
4547
46private slots:48private slots:
47 void fetchUsername();49 void fetchUsername();
4850
49 void fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result);51 void fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const int userId, const QString &userName);
5052
51private:53private:
52 static UserStore* s_instance;54 static UserStore* s_instance;
53 explicit UserStore(QObject *parent = 0);55 explicit UserStore(QObject *parent = 0);
5456
55 QString m_username;57 qint32 m_userId;
58 QString m_userName;
56};59};
5760
58#endif // USERSTORE_H61#endif // USERSTORE_H
5962
=== modified file 'src/push-helper/core.cpp'
--- src/push-helper/core.cpp 2014-12-08 10:25:48 +0000
+++ src/push-helper/core.cpp 2015-06-22 08:14:09 +0000
@@ -6,33 +6,43 @@
66
7#include <QDebug>7#include <QDebug>
8#include <QOrganizerEvent>8#include <QOrganizerEvent>
9#include <QStandardPaths>
10#include <QJsonDocument>
911
10Core::Core(QObject *parent):12Core::Core(QObject *parent):
11 QObject(parent)13 QObject(parent)
12{14{
13 qDebug() << "Core starting up";
14 connect(EvernoteConnection::instance(), &EvernoteConnection::isConnectedChanged, this, &Core::connectedChanged);15 connect(EvernoteConnection::instance(), &EvernoteConnection::isConnectedChanged, this, &Core::connectedChanged);
15 qDebug() << "EvernoteConnection created";
16 connect(NotesStore::instance(), &NotesStore::loadingChanged, this, &Core::notesLoaded);16 connect(NotesStore::instance(), &NotesStore::loadingChanged, this, &Core::notesLoaded);
17 qDebug() << "notestore created";17}
18// connect(&m_oaSetup, &OnlineAccountsClient::Setup::finished, this, &Core::oaRequestFinished);18
1919bool Core::process(const QByteArray &pushNotification)
2020{
21// m_oaSetup.setApplicationId("com.ubuntu.reminders_reminders");21 qDebug() << "should process:" << pushNotification;
22// m_oaSetup.setServiceTypeId("evernote");22
23// m_oaSetup.exec();23 QJsonParseError error;
24// qDebug() << "OA request started";24 QJsonDocument jsonDoc = QJsonDocument::fromJson(pushNotification, &error);
2525 if (error.error != QJsonParseError::NoError) {
26 EvernoteConnection::instance()->setToken("S=s358:U=39eb980:E=1516e9a3575:C=14a16e90690:P=185:A=canonicalis:V=2:H=737f36850d4943e61ff2fcf7b4c809e2");26 qDebug() << "Error parsing notification json:" << error.errorString();
27 return false;
28 }
29 QVariantMap notification = jsonDoc.toVariant().toMap().value("payload").toMap();
30
31 QSettings settings(QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() + "/com.ubuntu.reminders/reminders.conf", QSettings::IniFormat);
32 settings.beginGroup("accounts");
33 QString token = settings.value(notification.value("userId").toString()).toString();
34 settings.endGroup();
35
36 if (token.isEmpty()) {
37 qDebug() << "No token found for this userId in " + settings.fileName() + ". Discarding push notification...";
38 return false;
39 }
40
41 EvernoteConnection::instance()->setToken(token);
27 EvernoteConnection::instance()->setHostname("www.evernote.com");42 EvernoteConnection::instance()->setHostname("www.evernote.com");
28 EvernoteConnection::instance()->connectToEvernote();43 EvernoteConnection::instance()->connectToEvernote();
2944
30 qDebug() << "Core created";45 return true;
31}
32
33void Core::process(const QByteArray &pushNotification)
34{
35 qDebug() << "should process:" << pushNotification;
36}46}
3747
38void Core::connectedChanged()48void Core::connectedChanged()
@@ -48,13 +58,5 @@
48void Core::notesLoaded()58void Core::notesLoaded()
49{59{
50 qDebug() << "notes loading changed:" << NotesStore::instance()->loading();60 qDebug() << "notes loading changed:" << NotesStore::instance()->loading();
51 foreach (Note *note, NotesStore::instance()->notes()) {
52 qDebug() << "have note" << note->title();
53 qDebug() << "content:" << note->plaintextContent();
54 }
55}61}
5662
57void Core::oaRequestFinished(const QVariantMap &reply)
58{
59 qDebug() << "OA reply" << reply;
60}
6163
=== modified file 'src/push-helper/core.h'
--- src/push-helper/core.h 2014-12-14 02:40:47 +0000
+++ src/push-helper/core.h 2015-06-22 08:14:09 +0000
@@ -9,7 +9,7 @@
9public:9public:
10 Core(QObject *parent = 0);10 Core(QObject *parent = 0);
1111
12 void process(const QByteArray &pushNotification);12 bool process(const QByteArray &pushNotification);
1313
1414
15signals:15signals:
@@ -17,7 +17,6 @@
1717
18private slots:18private slots:
19 void connectedChanged();19 void connectedChanged();
20 void oaRequestFinished(const QVariantMap &reply);
2120
22 void notesLoaded();21 void notesLoaded();
23};22};
2423
=== modified file 'src/push-helper/main.cpp'
--- src/push-helper/main.cpp 2014-12-06 22:35:01 +0000
+++ src/push-helper/main.cpp 2015-06-22 08:14:09 +0000
@@ -23,6 +23,7 @@
2323
24 Core core;24 Core core;
25 QObject::connect(&core, &Core::finished, &a, &QCoreApplication::exit);25 QObject::connect(&core, &Core::finished, &a, &QCoreApplication::exit);
26
26 core.process(data);27 core.process(data);
2728
28 a.exec();29 a.exec();

Subscribers

People subscribed via source and target branches