diff options
author | Camila San <hello@camila.codes> | 2018-04-11 16:20:41 +0300 |
---|---|---|
committer | Camila San <hello@camila.codes> | 2018-04-11 16:21:00 +0300 |
commit | 1fbeb52806b8393df41392b6d151f924525be805 (patch) | |
tree | a6a4f45a199a4d22ac03c18aae751b4286fe4b54 | |
parent | c7ee0ec42e945d91e9ce4592f668b82b890c1841 (diff) |
Only updates the list of apps when there is a change in the server (not 304 status).adds-etag-navigatiion-apps
Signed-off-by: Camila San <hello@camila.codes>
-rw-r--r-- | src/gui/owncloudgui.cpp | 75 | ||||
-rw-r--r-- | src/gui/owncloudgui.h | 2 |
2 files changed, 35 insertions, 42 deletions
diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index a89dae26e..bd8256386 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -759,68 +759,61 @@ void ownCloudGui::fetchNavigationApps(AccountStatePtr account, QMenu *accountMen job->getNavigationApps(); } -void ownCloudGui::buildNavigationAppsMenu(QMenu *accountMenu){ - QMapIterator<AccountStatePtr, QJsonArray> it(_navApps); - while(it.hasNext()){ - - //qDebug() << it.key() << it.value(); - - auto account = it.key(); - auto navLinks = it.value(); - - if(navLinks.size() > 0){ - - // when there is only one account add the nav links above the settings - QAction *actionBefore = _actionSettings; - - // when there is more than one account add the nav links above pause/unpause folder or logout action - if(AccountManager::instance()->accounts().size() > 1){ - foreach(QAction *action, accountMenu->actions()){ - - // pause/unpause folder and logout actions have propertyAccountC - if(auto actionAccount = qvariant_cast<AccountStatePtr>(action->property(propertyAccountC))){ - if(actionAccount == account){ - actionBefore = action; - break; - } +void ownCloudGui::buildNavigationAppsMenu(AccountStatePtr account, QMenu *accountMenu){ + auto navLinks = _navApps.value(account); + if(navLinks.size() > 0){ + + // when there is only one account add the nav links above the settings + QAction *actionBefore = _actionSettings; + + // when there is more than one account add the nav links above pause/unpause folder or logout action + if(AccountManager::instance()->accounts().size() > 1){ + foreach(QAction *action, accountMenu->actions()){ + + // pause/unpause folder and logout actions have propertyAccountC + if(auto actionAccount = qvariant_cast<AccountStatePtr>(action->property(propertyAccountC))){ + if(actionAccount == account){ + actionBefore = action; + break; } } } - - // Create submenu with links - QMenu *navLinksMenu = new QMenu(tr("Apps")); - accountMenu->insertSeparator(actionBefore); - accountMenu->insertMenu(actionBefore, navLinksMenu); - foreach (const QJsonValue &value, navLinks) { - auto navLink = value.toObject(); - QAction *action = new QAction(navLink.value("name").toString(), this); - QUrl href(navLink.value("href").toString()); - connect(action, &QAction::triggered, this, [href] { QDesktopServices::openUrl(href); }); - navLinksMenu->addAction(action); - } - accountMenu->insertSeparator(actionBefore); } - it.next(); + // Create submenu with links + QMenu *navLinksMenu = new QMenu(tr("Apps")); + accountMenu->insertSeparator(actionBefore); + accountMenu->insertMenu(actionBefore, navLinksMenu); + foreach (const QJsonValue &value, navLinks) { + auto navLink = value.toObject(); + QAction *action = new QAction(navLink.value("name").toString(), this); + QUrl href(navLink.value("href").toString()); + connect(action, &QAction::triggered, this, [href] { QDesktopServices::openUrl(href); }); + navLinksMenu->addAction(action); + } + accountMenu->insertSeparator(actionBefore); } } void ownCloudGui::slotNavigationAppsFetched(const QJsonDocument &reply, int statusCode) { + auto account = qvariant_cast<AccountStatePtr>(sender()->property(propertyAccountC)); + auto accountMenu = qvariant_cast<QMenu*>(sender()->property(propertyMenuC)); + if (statusCode == 304) { qCWarning(lcApplication) << "Status code " << statusCode << " Not Modified - No new navigation apps."; } else { if(!reply.isEmpty()){ auto element = reply.object().value("ocs").toObject().value("data"); auto navLinks = element.toArray(); - if(auto account = qvariant_cast<AccountStatePtr>(sender()->property(propertyAccountC))){ + if(account){ _navApps.insert(account, navLinks); } } } - if(QMenu *accountMenu = qvariant_cast<QMenu*>(sender()->property(propertyMenuC))) - buildNavigationAppsMenu(accountMenu); + if(accountMenu) + buildNavigationAppsMenu(account, accountMenu); } void ownCloudGui::slotOcsError(int statusCode, const QString &message) diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index 8420f3f89..c855c5c74 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -123,7 +123,7 @@ private: void setupActions(); void addAccountContextMenu(AccountStatePtr accountState, QMenu *menu, bool separateMenu); void fetchNavigationApps(AccountStatePtr account, QMenu *accountMenu); - void buildNavigationAppsMenu(QMenu *accountMenu); + void buildNavigationAppsMenu(AccountStatePtr account, QMenu *accountMenu); QPointer<Systray> _tray; #if defined(Q_OS_MAC) |