← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~mardy/reminders-app/new-api into lp:reminders-app

 

Michael Zanetti has proposed merging lp:~mardy/reminders-app/new-api into lp:reminders-app.

Commit message:
Use the new Online Accounts API and hook format

Requested reviews:
  Jenkins Bot (ubuntu-core-apps-jenkins-bot): continuous-integration
  Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot): continuous-integration
  Ubuntu Notes app developers (notes-app-dev)

For more details, see:
https://code.launchpad.net/~mardy/reminders-app/new-api/+merge/271505

Use the new Online Accounts API and hook format

Note that I've also added ubuntu-system-settings-online-accounts to the debian/control file as a dependency. In fact, even without these changes, that package was indeed needed if one wanted to create an Evernote account from inside the application. I'm not sure whether not listing it as a dependency was an omission or a deliberate choice (it might indeed be a deliberate choice, given that u-s-s-o-a is tricky to get to work on the unity7 dekstop and brings in a lot of unwanted packages like the Ubuntu Touch system settings) -- but with the new API, having that package is essential to get the Online Accounts functionality working at all.

Please let me know if the added dependency is acceptable; if it isn't, we might remove it along with the qml-module-ubuntu-onlineaccounts2 dependency and put all the Online Accounts functionality behind a Loader element, so that we disable the Evernote integration if the needed packages are not installed.
-- 
Your team Ubuntu Notes app developers is requested to review the proposed merge of lp:~mardy/reminders-app/new-api into lp:reminders-app.
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt	2015-11-02 20:26:37 +0000
+++ CMakeLists.txt	2016-03-08 07:11:08 +0000
@@ -19,6 +19,7 @@
 set(APP_NAME reminders)
 set(DESKTOP_FILE "${PROJECT_NAME}.desktop")
 set(APPLICATION_FILE "${PROJECT_NAME}_${APP_NAME}.application")
+set(APPLICATION_ACCOUNTS_FILE "${PROJECT_NAME}_${APP_NAME}.accounts")
 set(ICON ${APP_NAME}.png)
 set(AUTOPILOT_DIR reminders)
 set(APP_HARDCODE reminders)
@@ -115,6 +116,9 @@
 configure_file(${APPLICATION_FILE}.in ${CMAKE_CURRENT_BINARY_DIR}/${APPLICATION_FILE})
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${APPLICATION_FILE} DESTINATION ${APPLICATION_DIR})
 
+configure_file(${APPLICATION_ACCOUNTS_FILE}.in ${CMAKE_CURRENT_BINARY_DIR}/${APPLICATION_ACCOUNTS_FILE})
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${APPLICATION_ACCOUNTS_FILE} DESTINATION ${APPLICATION_DIR})
+
 add_subdirectory(po)
 add_subdirectory(tests)
 add_subdirectory(3rdParty)

=== added file 'com.ubuntu.reminders_reminders.accounts.in'
--- com.ubuntu.reminders_reminders.accounts.in	1970-01-01 00:00:00 +0000
+++ com.ubuntu.reminders_reminders.accounts.in	2016-03-08 07:11:08 +0000
@@ -0,0 +1,8 @@
+{
+  "services": [
+    {
+      "provider": "@PROJECT_NAME@_evernote-account-plugin_evernote",
+      "description": "Synchronize your notes with Evernote"
+    }
+  ]
+}

=== modified file 'debian/control'
--- debian/control	2016-01-29 09:57:34 +0000
+++ debian/control	2016-03-08 07:11:08 +0000
@@ -14,11 +14,10 @@
                qml-module-qttest,
                qml-module-qt-labs-settings,
                qml-module-ubuntu-connectivity,
+               qml-module-ubuntu-onlineaccounts2,
                qt5-default,
-               qtdeclarative5-accounts-plugin,
                qtdeclarative5-dev,
                qtdeclarative5-dev-tools,
-               qtdeclarative5-online-accounts-client0.1 (>= 0.3+14.10.20140506),
                qtdeclarative5-quicklayouts-plugin,
                qtdeclarative5-ubuntu-content1,
                qtdeclarative5-ubuntu-push-plugin,
@@ -35,16 +34,16 @@
 Depends: account-plugin-evernote,
          liboxideqt-qmlplugin,
          qml-module-ubuntu-connectivity,
-         qtdeclarative5-accounts-plugin,
+         qml-module-ubuntu-onlineaccounts2,
          qtdeclarative5-evernote0.1,
          qtdeclarative5-localstorage-plugin,
-         qtdeclarative5-online-accounts-client0.1 (>= 0.3+14.10.20140506),
          qtdeclarative5-qtquick2-plugin,
          qtdeclarative5-quicklayouts-plugin,
          qtdeclarative5-ubuntu-push-plugin,
          qtdeclarative5-ubuntu-ui-toolkit-plugin | qt-components-ubuntu,
          signon-plugin-oauth2 (>= 0.19-0~57~),
          suru-icon-theme | ubuntu-mobile-icons,
+         ubuntu-system-settings-online-accounts,
          ${misc:Depends},
          ${shlibs:Depends}
 Description: Notes application
@@ -59,7 +58,7 @@
 Package: account-plugin-evernote
 Architecture: any
 Depends: libaccount-plugin-generic-oauth,
-         qtdeclarative5-online-accounts-client0.1,
+         qml-module-ubuntu-onlineaccounts,
          ${misc:Depends},
          ${shlibs:Depends}
 Description: Allow Ubuntu applications to access Evernote accounts
@@ -70,7 +69,7 @@
 Architecture: any
 Depends: account-plugin-evernote,
          libaccount-plugin-generic-oauth,
-         qtdeclarative5-online-accounts-client0.1,
+         qml-module-ubuntu-onlineaccounts,
          ${misc:Depends},
          ${shlibs:Depends}
 Description: Allow Ubuntu applications to access Evernote sandbox accounts

=== modified file 'manifest.json.in'
--- manifest.json.in	2015-10-24 09:59:39 +0000
+++ manifest.json.in	2016-03-08 07:11:08 +0000
@@ -4,16 +4,14 @@
     "architecture": "@CLICK_ARCH@",
     "hooks": {
         "reminders": {
-            "account-application": "com.ubuntu.reminders_reminders.application",
-            "account-service": "@ACCOUNT_SERVICE_DIR@/com.ubuntu.reminders_reminders.service",
+            "accounts": "com.ubuntu.reminders_reminders.accounts",
             "apparmor": "reminders.apparmor",
             "desktop": "com.ubuntu.reminders.desktop",
             "urls": "reminders.url-dispatcher",
             "content-hub": "reminders-contenthub.json"
         },
         "evernote-account-plugin": {
-            "account-qml-plugin": "@ACCOUNT_QML_PLUGIN_DIR@/evernote",
-            "account-provider": "@ACCOUNT_PROVIDER_DIR@/com.ubuntu.reminders_evernote-account-plugin.provider"
+            "accounts": "com.ubuntu.reminders_evernote-account-plugin.accounts"
         },
         "pushHelper": {
             "apparmor": "push-helper.apparmor",

=== modified file 'src/account-plugin/CMakeLists.txt'
--- src/account-plugin/CMakeLists.txt	2014-09-24 15:02:10 +0000
+++ src/account-plugin/CMakeLists.txt	2016-03-08 07:11:08 +0000
@@ -25,6 +25,7 @@
     set(PROVIDER_FILE data/providers/${EVERNOTE_PROVIDER_ID}.provider)
     set(SERVICE_FILE data/services/${EVERNOTE_SERVICE_ID}.service)
     set(QML_PLUGIN_FILE qml/${account_name}/Main.qml)
+    set(PLUGIN_ACCOUNTS_FILE com.ubuntu.reminders_evernote-account-plugin.accounts)
 
     install(FILES ${ICON_FILE} DESTINATION ${ACCOUNT_ICON_DIR})
 
@@ -40,6 +41,10 @@
     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${QML_PLUGIN_FILE}
             DESTINATION ${ACCOUNT_QML_PLUGIN_DIR}/${EVERNOTE_ACCOUNT_NAME})
 
+    configure_file(${PLUGIN_ACCOUNTS_FILE}.in
+            ${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_ACCOUNTS_FILE})
+    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_ACCOUNTS_FILE}
+            DESTINATION ${CMAKE_INSTALL_PREFIX})
 endfunction()
 
 # Build and install the files for the production plugin

=== added file 'src/account-plugin/com.ubuntu.reminders_evernote-account-plugin.accounts.in'
--- src/account-plugin/com.ubuntu.reminders_evernote-account-plugin.accounts.in	1970-01-01 00:00:00 +0000
+++ src/account-plugin/com.ubuntu.reminders_evernote-account-plugin.accounts.in	2016-03-08 07:11:08 +0000
@@ -0,0 +1,22 @@
+{
+  "plugin": {
+    "provider": "evernote",
+    "name": "@EVERNOTE_ACCOUNT_DISPLAY_NAME@",
+    "icon": "@EVERNOTE_ICON_NAME@",
+    "qml": "@ACCOUNT_QML_PLUGIN_DIR@/evernote",
+    "auth": {
+      "oauth2/HMAC-SHA1": {
+        "RequestEndpoint": "https://@EVERNOTE_HOSTNAME@/oauth";,
+        "TokenEndpoint": "https://@EVERNOTE_HOSTNAME@/oauth";,
+        "AuthorizationEndpoint": "https://@EVERNOTE_HOSTNAME@/OAuth.action";,
+        "Callback": "https://wiki.ubuntu.com/";,
+        "ConsumerKey": "@EVERNOTE_CONSUMER_KEY@",
+        "ConsumerSecret": "@EVERNOTE_CONSUMER_SECRET@",
+        "HostName": "@EVERNOTE_HOSTNAME@"
+      }
+    },
+    "settings": {
+      "HostName": "@EVERNOTE_HOSTNAME@"
+    }
+  }
+}

=== modified file 'src/app/qml/Reminders.qml'
--- src/app/qml/Reminders.qml	2015-11-20 11:11:49 +0000
+++ src/app/qml/Reminders.qml	2016-03-08 07:11:08 +0000
@@ -23,8 +23,7 @@
 import Ubuntu.Components.ListItems 1.3
 import Ubuntu.Connectivity 1.0
 import Evernote 0.1
-import Ubuntu.OnlineAccounts 0.1
-import Ubuntu.OnlineAccounts.Client 0.1
+import Ubuntu.OnlineAccounts 2.0
 import Ubuntu.PushNotifications 0.1
 import Ubuntu.Content 1.0
 import com.canonical.Oxide 1.5
@@ -127,9 +126,8 @@
     backgroundColor: "#dddddd"
 
     function openAccountPage() {
-        var unauthorizedAccounts = allAccounts.count - accounts.count > 0 ? true : false
-        var accountPage = pagestack.push(Qt.createComponent(Qt.resolvedUrl("ui/AccountSelectorPage.qml")), { accounts: accounts, unauthorizedAccounts: unauthorizedAccounts, oaSetup: setup });
-        accountPage.accountSelected.connect(function(username, handle) { accountService.startAuthentication(username, handle); pagestack.pop(); root.accountPage = null });
+        var accountPage = pagestack.push(Qt.createComponent(Qt.resolvedUrl("ui/AccountSelectorPage.qml")), { accounts: accounts });
+        accountPage.accountSelected.connect(function(username, account) { root.startAuthentication(username, account); pagestack.pop(); root.accountPage = null });
     }
 
     function displayNote(note, conflictMode) {
@@ -208,7 +206,7 @@
     function doLogin() {
         var accountName = preferences.accountName;
         if (accountName == "@local") {
-            accountService.startAuthentication("@local", null);
+            root.startAuthentication("@local", null);
             return;
         }
 
@@ -218,7 +216,7 @@
             for (i = 0; i < accounts.count; i++) {
                 if (accounts.get(i, "displayName") == accountName) {
                     print("Account", accountName, "still valid in Online Accounts.");
-                    accountService.startAuthentication(accounts.get(i, "displayName"), accounts.get(i, "accountServiceHandle"));
+                    root.startAuthentication(accounts.get(i, "displayName"), accounts.get(i, "account"));
                     return;
                 }
             }
@@ -231,7 +229,7 @@
             break;
         case 1:
             print("Connecting to account", accounts.get(0, "displayName"), "as there is only one account available");
-            accountService.startAuthentication(accounts.get(0, "displayName"), accounts.get(0, "accountServiceHandle"));
+            root.startAuthentication(accounts.get(0, "displayName"), accounts.get(0, "account"));
             break;
         default:
             print("There are multiple accounts. Allowing user to select one.");
@@ -396,53 +394,42 @@
         }
     }
 
-    AccountServiceModel {
+    AccountModel {
         id: accounts
         applicationId: "com.ubuntu.reminders_reminders"
     }
 
-    AccountServiceModel {
-        id: allAccounts
-        applicationId: "com.ubuntu.reminders_reminders"
-        service: useSandbox ? "evernote-sandbox" : "evernote"
-        includeDisabled: true
-    }
-
-    AccountService {
-        id: accountService
-        function startAuthentication(username, objectHandle) {
-            //Load the cache
-            EvernoteConnection.disconnectFromEvernote();
-            EvernoteConnection.token = "";
-            NotesStore.username = username;
-            preferences.accountName = username;
-            if (username === "@local" && !preferences.haveLocalUser) {
-                NotesStore.createNotebook(i18n.tr("Default notebook"));
-                preferences.haveLocalUser = true;
-            }
-
-            if (objectHandle === null) {
-                return;
-            }
-
-            accountService.objectHandle = objectHandle;
-            // FIXME: workaround for lp:1351041. We'd normally set the hostname
-            // under onAuthenticated, but it seems that now returns empty parameters
-            EvernoteConnection.hostname = accountService.authData.parameters["HostName"];
-            authenticate(null);
-        }
-
-        onAuthenticated: {
-            EvernoteConnection.token = reply.AccessToken;
-            print("token is:", EvernoteConnection.token)
-            print("NetworkingStatus.online:", NetworkingStatus.Online)
-            if (NetworkingStatus.Online) {
-                EvernoteConnection.connectToEvernote();
-            }
-        }
-        onAuthenticationError: {
-            console.log("Authentication failed, code " + error.code)
-        }
+    function startAuthentication(username, account) {
+        //Load the cache
+        EvernoteConnection.disconnectFromEvernote();
+        EvernoteConnection.token = "";
+        NotesStore.username = username;
+        preferences.accountName = username;
+        if (username === "@local" && !preferences.haveLocalUser) {
+            NotesStore.createNotebook(i18n.tr("Default notebook"));
+            preferences.haveLocalUser = true;
+        }
+
+        if (account === null) {
+            return;
+        }
+
+        // FIXME: workaround for lp:1351041. We'd normally set the hostname
+        // under onAuthenticated, but it seems that now returns empty parameters
+        EvernoteConnection.hostname = account.settings["HostName"];
+        account.authenticationReply.connect(function(reply) {
+            if ("errorCode" in reply) {
+                console.log("Authentication failed, code " + reply.errorCode)
+            } else {
+                EvernoteConnection.token = reply.AccessToken;
+                print("token is:", EvernoteConnection.token)
+                print("NetworkingStatus.online:", NetworkingStatus.Online)
+                if (NetworkingStatus.Online) {
+                    EvernoteConnection.connectToEvernote();
+                }
+            }
+        })
+        account.authenticate(null);
     }
 
     Component.onCompleted: {
@@ -653,10 +640,8 @@
 
                 page: AccountSelectorPage {
                     accounts: accounts
-                    unauthorizedAccounts: true
-                    oaSetup: setup
                     onAccountSelected: {
-                        accountService.startAuthentication(username, handle)
+                        root.startAuthentication(username, account)
                         rootTabs.selectedTabIndex = 0;
                     }
                 }
@@ -700,12 +685,6 @@
         }
     }
 
-    Setup {
-        id: setup
-        applicationId: "com.ubuntu.reminders_reminders"
-        providerId: useSandbox ? "com.ubuntu.reminders_evernote-account-plugin-sandbox" : "com.ubuntu.reminders_evernote-account-plugin"
-    }
-
     Component {
         id: noAccountDialog
         Dialog {
@@ -733,7 +712,7 @@
                     color: UbuntuColors.red
                     onClicked: {
                         PopupUtils.close(noAccount)
-                        accountService.startAuthentication("@local", null);
+                        root.startAuthentication("@local", null);
                     }
                     Layout.fillWidth: true
                 }
@@ -741,7 +720,10 @@
                     objectName: "openAccountButton"
                     text: i18n.tr("Yes")
                     color: UbuntuColors.green
-                    onClicked: setup.exec()
+                    onClicked: {
+                        var service = "com.ubuntu.reminders_reminders_com.ubuntu.reminders_evernote-account-plugin"
+                        accounts.requestAccess(service, {})
+                    }
                     Layout.fillWidth: true
                 }
             }

=== modified file 'src/app/qml/ui/AccountSelectorPage.qml'
--- src/app/qml/ui/AccountSelectorPage.qml	2015-09-15 14:50:55 +0000
+++ src/app/qml/ui/AccountSelectorPage.qml	2016-03-08 07:11:08 +0000
@@ -19,8 +19,7 @@
 import QtQuick 2.4
 import Ubuntu.Components 1.3
 import Ubuntu.Components.ListItems 1.3
-import Ubuntu.OnlineAccounts 0.1
-import Ubuntu.OnlineAccounts.Client 0.1
+import Ubuntu.OnlineAccounts 2.0
 import Evernote 0.1
 
 Page {
@@ -29,10 +28,8 @@
     title: i18n.tr("Select account")
 
     property alias accounts: optionSelector.model
-    property bool unauthorizedAccounts
-    property var oaSetup: null
 
-    signal accountSelected(string username, var handle)
+    signal accountSelected(string username, var account)
 
 
     Column {
@@ -64,23 +61,13 @@
 
                 MouseArea {
                     anchors.fill: parent
-                    onClicked: {
-                        if (model.enabled) {
-                            root.accountSelected(displayName, accountServiceHandle)
-                        }
-                        else {
-                            console.log('authorize')
-                        }
-                    }
+                    onClicked: root.accountSelected(displayName, account)
                 }
 
                 Component.onCompleted: {
                     if (displayName == preferences.accountName) {
                         optionSelector.selectedIndex = index;
                     }
-                    if (!model.enabled) {
-                        text = i18n.tr("%1 - Tap to authorize").arg(text)
-                    }
                 }
             }
         }
@@ -90,7 +77,10 @@
             width: parent.width - units.gu(2)
             text: i18n.tr("Add new account")
             color: UbuntuColors.orange
-            onClicked: root.oaSetup.exec()
+            onClicked: {
+                var service = "com.ubuntu.reminders_reminders_com.ubuntu.reminders_evernote-account-plugin"
+                accounts.requestAccess(service, {})
+            }
         }
      }
 


Follow ups