From 4ffff7454e698ae3efcabd6885fc2103a2d72fa7 Mon Sep 17 00:00:00 2001 From: Camila San Date: Wed, 21 Feb 2018 18:49:12 +0100 Subject: [PATCH] Refactores code and displays nav. apps before Pause/Unpause folders sync. Signed-off-by: Camila San --- src/gui/owncloudgui.cpp | 83 ++++++++++++++++++++++------------------- src/gui/owncloudgui.h | 6 +-- 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index dc24726550..21838528e7 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -58,6 +58,7 @@ namespace OCC { const char propertyAccountC[] = "oc_account"; +const char propertyMenuC[] = "oc_account_menu"; ownCloudGui::ownCloudGui(Application *parent) : QObject(parent) @@ -397,11 +398,13 @@ void ownCloudGui::addAccountContextMenu(AccountStatePtr accountState, QMenu *men QAction *enable = menu->addAction(tr("Unpause all folders")); enable->setProperty(propertyAccountC, QVariant::fromValue(accountState)); connect(enable, &QAction::triggered, this, &ownCloudGui::slotUnpauseAllFolders); + _storedActionsForNavApps.append(enable); } if (!allPaused) { QAction *enable = menu->addAction(tr("Pause all folders")); enable->setProperty(propertyAccountC, QVariant::fromValue(accountState)); connect(enable, &QAction::triggered, this, &ownCloudGui::slotPauseAllFolders); + _storedActionsForNavApps.append(enable); } if (accountState->isSignedOut()) { @@ -412,6 +415,7 @@ void ownCloudGui::addAccountContextMenu(AccountStatePtr accountState, QMenu *men QAction *signout = menu->addAction(tr("Log out")); signout->setProperty(propertyAccountC, QVariant::fromValue(accountState)); connect(signout, &QAction::triggered, this, &ownCloudGui::slotLogout); + _storedActionsForNavApps.append(signout); } } } @@ -568,7 +572,7 @@ void ownCloudGui::updateContextMenu() menu->deleteLater(); } _accountMenus.clear(); - + _storedActionsForNavApps.clear(); auto accountList = AccountManager::instance()->accounts(); @@ -596,9 +600,11 @@ void ownCloudGui::updateContextMenu() _contextMenu->addMenu(accountMenu); addAccountContextMenu(account, accountMenu, true); + fetchNavigationApps(account, accountMenu); } } else if (accountList.count() == 1) { addAccountContextMenu(accountList.first(), _contextMenu.data(), false); + fetchNavigationApps(accountList.first(), _contextMenu.data()); } _contextMenu->addSeparator(); @@ -646,8 +652,6 @@ void ownCloudGui::updateContextMenu() } _contextMenu->addAction(_actionQuit); - fetchNavigationApps(); - if (_qdbusmenuWorkaround) { _tray->show(); } @@ -736,11 +740,6 @@ void ownCloudGui::setupActions() _actionQuit = new QAction(tr("Quit %1").arg(Theme::instance()->appNameGUI()), this); QObject::connect(_actionQuit, SIGNAL(triggered(bool)), _app, SLOT(quit())); - _actionLogin = new QAction(tr("Log in..."), this); - connect(_actionLogin, &QAction::triggered, this, &ownCloudGui::slotLogin); - _actionLogout = new QAction(tr("Log out"), this); - connect(_actionLogout, &QAction::triggered, this, &ownCloudGui::slotLogout); - if (_app->debugMode()) { _actionCrash = new QAction(tr("Crash now", "Only shows in debug mode to allow testing the crash handler"), this); connect(_actionCrash, &QAction::triggered, _app, &Application::slotCrash); @@ -749,14 +748,13 @@ void ownCloudGui::setupActions() } } -void ownCloudGui::fetchNavigationApps(){ - foreach (AccountStatePtr account, AccountManager::instance()->accounts()) { - OcsNavigationAppsJob *job = new OcsNavigationAppsJob(account->account()); - job->setProperty(propertyAccountC, QVariant::fromValue(account->account())); - connect(job, &OcsNavigationAppsJob::appsJobFinished, this, &ownCloudGui::slotNavigationAppsFetched); - connect(job, &OcsNavigationAppsJob::ocsError, this, &ownCloudGui::slotOcsError); - job->getNavigationApps(); - } +void ownCloudGui::fetchNavigationApps(AccountStatePtr account, QMenu *accountMenu){ + OcsNavigationAppsJob *job = new OcsNavigationAppsJob(account->account()); + job->setProperty(propertyAccountC, QVariant::fromValue(account->account())); + job->setProperty(propertyMenuC, QVariant::fromValue(accountMenu)); + connect(job, &OcsNavigationAppsJob::appsJobFinished, this, &ownCloudGui::slotNavigationAppsFetched); + connect(job, &OcsNavigationAppsJob::ocsError, this, &ownCloudGui::slotOcsError); + job->getNavigationApps(); } void ownCloudGui::slotNavigationAppsFetched(const QJsonDocument &reply) @@ -767,35 +765,42 @@ void ownCloudGui::slotNavigationAppsFetched(const QJsonDocument &reply) if(navLinks.size() > 0){ if(auto account = qvariant_cast(sender()->property(propertyAccountC))){ + if(QMenu *accountMenu = qvariant_cast(sender()->property(propertyMenuC))){ - // when there is only one account add the nav links above the settings - QMenu *accountMenu = _contextMenu.data(); - QAction *actionBefore = _actionSettings; + // 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 bellow the account submenu - if(AccountManager::instance()->accounts().size() > 1){ - // the list of apps will be displayed under the account that it belongs to and before Log out - actionBefore = _actionLogout; - foreach (QMenu *menu, _accountMenus) { - if(menu->title() == account->displayName()){ - accountMenu = menu; - break; + // when there is more than one account add the nav links bellow the account submenu + if(AccountManager::instance()->accounts().size() > 1){ + foreach(QAction *action, _storedActionsForNavApps){ + qDebug() << "Action: " + << action->text(); + if(auto actionAccount = qvariant_cast(action->property(propertyAccountC))){ + qDebug() << "Account found!" + << actionAccount->account()->displayName(); + if(actionAccount->account()->displayName() == account->displayName()){ + qDebug() << "Menu found!" + << actionAccount->account()->displayName(); + 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(account->url().host() + navLink.value("href").toString()); - connect(action, &QAction::triggered, this, [href] { QDesktopServices::openUrl(href); }); - navLinksMenu->addAction(action); + // 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(account->url().host() + navLink.value("href").toString()); + connect(action, &QAction::triggered, this, [href] { QDesktopServices::openUrl(href); }); + navLinksMenu->addAction(action); + } + accountMenu->insertSeparator(actionBefore); } - accountMenu->insertSeparator(actionBefore); } } } diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index 33c8d4356f..c0fe1f5c21 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -126,7 +126,7 @@ private: void setPauseOnAllFoldersHelper(bool pause); void setupActions(); void addAccountContextMenu(AccountStatePtr accountState, QMenu *menu, bool separateMenu); - void fetchNavigationApps(); + void fetchNavigationApps(AccountStatePtr account, QMenu *accountMenu); QPointer _tray; @@ -153,9 +153,6 @@ private: QTimer _workaroundBatchTrayUpdate; QMap> _shareDialogs; - QAction *_actionLogin; - QAction *_actionLogout; - QAction *_actionNewAccountWizard; QAction *_actionSettings; QAction *_actionStatus; @@ -165,6 +162,7 @@ private: QAction *_actionQuit; QAction *_actionCrash; QList _recentItemsActions; + QList _storedActionsForNavApps; Application *_app; ConfigFile _cfg;