List apps for each user in the tray main menu.

Signed-off-by: Camila San <hello@camila.codes>
This commit is contained in:
Camila San 2018-01-26 13:50:47 +01:00
parent 08769b2803
commit 8ada9d0471
No known key found for this signature in database
GPG key ID: A0A1A2FD03979524
2 changed files with 57 additions and 1 deletions

View file

@ -14,6 +14,7 @@
#include "application.h"
#include "owncloudgui.h"
#include "ocsappsjob.h"
#include "ocsexternalsitesjob.h"
#include "theme.h"
#include "folderman.h"
@ -649,6 +650,8 @@ void ownCloudGui::updateContextMenu()
if(_cfg.showExternalSites())
fetchExternalSites();
fetchApps();
if (_qdbusmenuWorkaround) {
_tray->show();
}
@ -799,6 +802,56 @@ void ownCloudGui::slotExternalSitesFetched(const QJsonDocument &reply)
}
}
void ownCloudGui::fetchApps(){
foreach (AccountStatePtr account, AccountManager::instance()->accounts()) {
OcsAppsJob *job = new OcsAppsJob(account->account());
job->setProperty(propertyAccountC, QVariant::fromValue(account->account()));
connect(job, &OcsAppsJob::appsJobFinished, this, &ownCloudGui::slotAppsFetched);
connect(job, &OcsAppsJob::ocsError, this, &ownCloudGui::slotOcsError);
job->getApps();
}
}
void ownCloudGui::setupAppsMenu(QAction *actionBefore, QAction *actionTitle, QMenu *menu, QJsonArray apps){
menu->insertSeparator(actionBefore);
menu->insertAction(actionBefore, actionTitle);
foreach (const QJsonValue &value, apps) {
QString app = value.toString();
QAction *action = new QAction(app, this);
connect(action, &QAction::triggered, this, [] { QDesktopServices::openUrl(QUrl(Theme::instance()->helpUrl())); });
menu->insertAction(actionBefore, action);
}
}
void ownCloudGui::slotAppsFetched(const QJsonDocument &reply)
{
if(!reply.isEmpty()){
auto data = reply.object().value("ocs").toObject().value("data").toObject().value("apps");
auto appsList = data.toArray();
if(appsList.size() > 0){
QAction *apps = new QAction(tr("Apps:"), this);
apps->setDisabled(true);
auto accountList = AccountManager::instance()->accounts();
if(accountList.size() > 1){
// the list of apps will be displayed under the account that it belongs to
if(auto account = qvariant_cast<AccountPtr>(sender()->property(propertyAccountC))){
foreach (QMenu *menu, _accountMenus) {
if(menu->title() == account->displayName()){
setupAppsMenu(_actionLogout, apps, menu, appsList);
}
}
}
} else if(accountList.size() == 1){
setupAppsMenu(_actionSettings, apps, _contextMenu.data(), appsList);
_contextMenu->insertSeparator(_actionSettings);
}
}
}
}
void ownCloudGui::slotOcsError(int statusCode, const QString &message)
{
emit serverError(statusCode, message);

View file

@ -100,7 +100,7 @@ public slots:
void slotAccountStateChanged();
void slotTrayMessageIfServerUnsupported(Account *account);
void slotExternalSitesFetched(const QJsonDocument &reply);
void slotAppsFetched(const QJsonDocument &reply);
/**
* Open a share dialog for a file or folder.
*
@ -129,6 +129,9 @@ private:
void addAccountContextMenu(AccountStatePtr accountState, QMenu *menu, bool separateMenu);
void fetchExternalSites();
void setupExternalSitesMenu(QAction *actionBefore, QAction *actionTitle, QMenu *menu, QJsonArray sites);
void fetchApps();
void setupAppsMenu(QAction *actionBefore, QAction *actionTitle, QMenu *menu, QJsonArray apps);
QPointer<Systray> _tray;
#if defined(Q_OS_MAC)