mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-24 21:35:47 +03:00
Only updates the list of apps when there is a change in the server (not 304 status).
Signed-off-by: Camila San <hello@camila.codes>
This commit is contained in:
parent
402dc6c33b
commit
bbff83fe7c
2 changed files with 32 additions and 39 deletions
|
@ -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()){
|
||||
void ownCloudGui::buildNavigationAppsMenu(AccountStatePtr account, QMenu *accountMenu){
|
||||
auto navLinks = _navApps.value(account);
|
||||
if(navLinks.size() > 0){
|
||||
|
||||
//qDebug() << it.key() << it.value();
|
||||
// when there is only one account add the nav links above the settings
|
||||
QAction *actionBefore = _actionSettings;
|
||||
|
||||
auto account = it.key();
|
||||
auto navLinks = it.value();
|
||||
// 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()){
|
||||
|
||||
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;
|
||||
}
|
||||
// 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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue