mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Merge pull request #195 from nextcloud/apps-external-sites-menu
Adds apps and external sites to menu.
This commit is contained in:
commit
eb3b3f02a0
@ -59,6 +59,7 @@ set(client_SRCS
|
||||
logbrowser.cpp
|
||||
navigationpanehelper.cpp
|
||||
networksettings.cpp
|
||||
ocsnavigationappsjob.cpp
|
||||
ocsjob.cpp
|
||||
ocssharejob.cpp
|
||||
ocsshareejob.cpp
|
||||
|
||||
38
src/gui/ocsnavigationappsjob.cpp
Normal file
38
src/gui/ocsnavigationappsjob.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) by Camila Ayres <camila@nextcloud.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include "ocsnavigationappsjob.h"
|
||||
|
||||
namespace OCC {
|
||||
|
||||
OcsNavigationAppsJob::OcsNavigationAppsJob(AccountPtr account)
|
||||
: OcsJob(account)
|
||||
{
|
||||
setPath("ocs/v2.php/core/navigation/apps");
|
||||
connect(this, &OcsNavigationAppsJob::jobFinished, this, &OcsNavigationAppsJob::jobDone);
|
||||
}
|
||||
|
||||
void OcsNavigationAppsJob::getNavigationApps()
|
||||
{
|
||||
setVerb("GET");
|
||||
addParam("absolute", "true");
|
||||
start();
|
||||
}
|
||||
|
||||
void OcsNavigationAppsJob::jobDone(const QJsonDocument &reply)
|
||||
{
|
||||
|
||||
emit appsJobFinished(reply);
|
||||
}
|
||||
}
|
||||
54
src/gui/ocsnavigationappsjob.h
Normal file
54
src/gui/ocsnavigationappsjob.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) by Camila Ayres <camila@nextcloud.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef OCSNAVIGATIONAPPSJOB_H
|
||||
#define OCSNAVIGATIONAPPSJOB_H
|
||||
|
||||
#include "ocsjob.h"
|
||||
class QJsonDocument;
|
||||
|
||||
namespace OCC {
|
||||
|
||||
/**
|
||||
* @brief The OcsAppsJob class
|
||||
* @ingroup gui
|
||||
*
|
||||
* Fetching enabled apps from the OCS Apps API
|
||||
*/
|
||||
class OcsNavigationAppsJob : public OcsJob
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit OcsNavigationAppsJob(AccountPtr account);
|
||||
|
||||
/**
|
||||
* Get a list of enabled apps and external sites
|
||||
* visible in the Navigation menu
|
||||
*/
|
||||
void getNavigationApps();
|
||||
|
||||
signals:
|
||||
/**
|
||||
* Result of the OCS request
|
||||
*
|
||||
* @param reply The reply
|
||||
*/
|
||||
void appsJobFinished(const QJsonDocument &reply);
|
||||
|
||||
private slots:
|
||||
void jobDone(const QJsonDocument &reply);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // OCSNAVIGATIONAPPSJOB_H
|
||||
@ -14,6 +14,7 @@
|
||||
|
||||
#include "application.h"
|
||||
#include "owncloudgui.h"
|
||||
#include "ocsnavigationappsjob.h"
|
||||
#include "theme.h"
|
||||
#include "folderman.h"
|
||||
#include "configfile.h"
|
||||
@ -51,9 +52,14 @@
|
||||
#include <QX11Info>
|
||||
#endif
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
namespace OCC {
|
||||
|
||||
const char propertyAccountC[] = "oc_account";
|
||||
const char propertyMenuC[] = "oc_account_menu";
|
||||
|
||||
ownCloudGui::ownCloudGui(Application *parent)
|
||||
: QObject(parent)
|
||||
@ -565,7 +571,6 @@ void ownCloudGui::updateContextMenu()
|
||||
}
|
||||
_accountMenus.clear();
|
||||
|
||||
|
||||
auto accountList = AccountManager::instance()->accounts();
|
||||
|
||||
bool isConfigured = (!accountList.isEmpty());
|
||||
@ -592,9 +597,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();
|
||||
@ -729,11 +736,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);
|
||||
@ -742,6 +744,64 @@ void ownCloudGui::setupActions()
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if(!reply.isEmpty()){
|
||||
auto element = reply.object().value("ocs").toObject().value("data");
|
||||
auto navLinks = element.toArray();
|
||||
if(navLinks.size() > 0){
|
||||
if(auto account = qvariant_cast<AccountPtr>(sender()->property(propertyAccountC))){
|
||||
if(QMenu *accountMenu = qvariant_cast<QMenu*>(sender()->property(propertyMenuC))){
|
||||
|
||||
// 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() == 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ownCloudGui::slotOcsError(int statusCode, const QString &message)
|
||||
{
|
||||
emit serverError(statusCode, message);
|
||||
}
|
||||
|
||||
void ownCloudGui::slotRebuildRecentMenus()
|
||||
{
|
||||
_recentActionsMenu->clear();
|
||||
|
||||
@ -65,6 +65,7 @@ public:
|
||||
|
||||
signals:
|
||||
void setupProxy();
|
||||
void serverError(int code, const QString &message);
|
||||
|
||||
public slots:
|
||||
void setupContextMenu();
|
||||
@ -92,6 +93,7 @@ public slots:
|
||||
void slotOpenPath(const QString &path);
|
||||
void slotAccountStateChanged();
|
||||
void slotTrayMessageIfServerUnsupported(Account *account);
|
||||
void slotNavigationAppsFetched(const QJsonDocument &reply);
|
||||
|
||||
/**
|
||||
* Open a share dialog for a file or folder.
|
||||
@ -104,6 +106,9 @@ public slots:
|
||||
|
||||
void slotRemoveDestroyedShareDialogs();
|
||||
|
||||
protected slots:
|
||||
void slotOcsError(int statusCode, const QString &message);
|
||||
|
||||
private slots:
|
||||
void slotLogin();
|
||||
void slotLogout();
|
||||
@ -115,6 +120,7 @@ private:
|
||||
void setPauseOnAllFoldersHelper(bool pause);
|
||||
void setupActions();
|
||||
void addAccountContextMenu(AccountStatePtr accountState, QMenu *menu, bool separateMenu);
|
||||
void fetchNavigationApps(AccountStatePtr account, QMenu *accountMenu);
|
||||
|
||||
QPointer<Systray> _tray;
|
||||
#if defined(Q_OS_MAC)
|
||||
@ -140,9 +146,6 @@ private:
|
||||
QTimer _workaroundBatchTrayUpdate;
|
||||
QMap<QString, QPointer<ShareDialog>> _shareDialogs;
|
||||
|
||||
QAction *_actionLogin;
|
||||
QAction *_actionLogout;
|
||||
|
||||
QAction *_actionNewAccountWizard;
|
||||
QAction *_actionSettings;
|
||||
QAction *_actionStatus;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user