mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-28 19:58:56 +03:00
List apps for each user in the tray main menu.
Signed-off-by: Camila San <hello@camila.codes>
This commit is contained in:
parent
08769b2803
commit
8ada9d0471
2 changed files with 57 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue