Removes dynamic cast when building navigation apps.

- It checks for the menu title to know where to add the apps menu instead of trying to cast
the menu pointer saved in the sender() property.
- The previous solution was not working reliably - see #523
- Adds TODO.

Signed-off-by: Camila San <hello@camila.codes>
This commit is contained in:
Camila San 2018-08-21 14:54:10 +02:00
parent fa4328a596
commit c8d5d9a622
No known key found for this signature in database
GPG Key ID: 544A4C2534D90695
2 changed files with 16 additions and 9 deletions

View File

@ -58,7 +58,6 @@
namespace OCC {
const char propertyAccountC[] = "oc_account";
const char propertyMenuC[] = "oc_account_menu";
ownCloudGui::ownCloudGui(Application *parent)
: QObject(parent)
@ -617,11 +616,11 @@ void ownCloudGui::updateContextMenu()
_contextMenu->addMenu(accountMenu);
addAccountContextMenu(account, accountMenu, true);
fetchNavigationApps(account, accountMenu);
fetchNavigationApps(account);
}
} else if (accountList.count() == 1) {
addAccountContextMenu(accountList.first(), _contextMenu.data(), false);
fetchNavigationApps(accountList.first(), _contextMenu.data());
fetchNavigationApps(accountList.first());
}
_contextMenu->addSeparator();
@ -769,10 +768,9 @@ void ownCloudGui::slotEtagResponseHeaderReceived(const QByteArray &value, int st
}
}
void ownCloudGui::fetchNavigationApps(AccountStatePtr account, QMenu *accountMenu){
void ownCloudGui::fetchNavigationApps(AccountStatePtr account){
OcsNavigationAppsJob *job = new OcsNavigationAppsJob(account->account());
job->setProperty(propertyAccountC, QVariant::fromValue(account));
job->setProperty(propertyMenuC, QVariant::fromValue(accountMenu));
job->addRawHeader("If-None-Match", account->navigationAppsEtagResponseHeader());
connect(job, &OcsNavigationAppsJob::appsJobFinished, this, &ownCloudGui::slotNavigationAppsFetched);
connect(job, &OcsNavigationAppsJob::etagResponseHeaderReceived, this, &ownCloudGui::slotEtagResponseHeaderReceived);
@ -829,9 +827,18 @@ void ownCloudGui::slotNavigationAppsFetched(const QJsonDocument &reply, int stat
}
}
if(QObject *accountMenuObj = qvariant_cast<QObject*>(sender()->property(propertyMenuC))){
if(QMenu *accountMenu = dynamic_cast<QMenu*>(accountMenuObj))
buildNavigationAppsMenu(account, accountMenu);
// TODO see pull #523
auto accountList = AccountManager::instance()->accounts();
if(accountList.size() > 1){
// the list of apps will be displayed under the account that it belongs to
foreach (QMenu *accountMenu, _accountMenus) {
if(accountMenu->title() == account->account()->displayName()){
buildNavigationAppsMenu(account, accountMenu);
break;
}
}
} else if(accountList.size() == 1){
buildNavigationAppsMenu(account, _contextMenu.data());
}
}
}

View File

@ -127,7 +127,7 @@ private:
void setPauseOnAllFoldersHelper(bool pause);
void setupActions();
void addAccountContextMenu(AccountStatePtr accountState, QMenu *menu, bool separateMenu);
void fetchNavigationApps(AccountStatePtr account, QMenu *accountMenu);
void fetchNavigationApps(AccountStatePtr account);
void buildNavigationAppsMenu(AccountStatePtr account, QMenu *accountMenu);
QPointer<Systray> _tray;