From 8408851ceeb482538d5ab34121948dbe1e629e94 Mon Sep 17 00:00:00 2001 From: Camila San Date: Fri, 19 Jan 2018 20:52:10 +0100 Subject: [PATCH 01/21] Adds OCS External Sites Job to retrieve it from the server. Signed-off-by: Camila San --- src/gui/CMakeLists.txt | 1 + src/gui/ocsexternalsitesjob.cpp | 37 ++++++++++++++++++++++ src/gui/ocsexternalsitesjob.h | 55 +++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 src/gui/ocsexternalsitesjob.cpp create mode 100644 src/gui/ocsexternalsitesjob.h diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 22b313b5de128..70aaecf1f6818 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -60,6 +60,7 @@ set(client_SRCS navigationpanehelper.cpp networksettings.cpp ocsjob.cpp + ocsexternalsitesjob.cpp ocssharejob.cpp ocsshareejob.cpp openfilemanager.cpp diff --git a/src/gui/ocsexternalsitesjob.cpp b/src/gui/ocsexternalsitesjob.cpp new file mode 100644 index 0000000000000..de07003e1fc4f --- /dev/null +++ b/src/gui/ocsexternalsitesjob.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) by Camila Ayres + * + * 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 "ocsexternalsitesjob.h" + +namespace OCC { + +OcsExternalSitesJob::OcsExternalSitesJob(AccountPtr account) + : OcsJob(account) +{ + setPath("ocs/v2.php/apps/external/api/v1/sites"); + connect(this, &OcsExternalSitesJob::jobFinished, this, &OcsExternalSitesJob::jobDone); +} + +void OcsExternalSitesJob::getExternalSites() +{ + setVerb("GET"); + start(); +} + +void OcsExternalSitesJob::jobDone(const QJsonDocument &reply) +{ + + emit externalSitesJobFinished(reply); +} +} diff --git a/src/gui/ocsexternalsitesjob.h b/src/gui/ocsexternalsitesjob.h new file mode 100644 index 0000000000000..892a462d349ff --- /dev/null +++ b/src/gui/ocsexternalsitesjob.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) by Camila Ayres + * + * 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 EXTERNALSITESJOB_H +#define EXTERNALSITESJOB_H + +#include "ocsjob.h" +class QJsonDocument; + +namespace OCC { + +/** + * @brief The ExternalSitesJob class + * @ingroup gui + * + * Fetching expernal sites from the OCS External Sites API + */ +class OcsExternalSitesJob : public OcsJob +{ + Q_OBJECT +public: + explicit OcsExternalSitesJob(AccountPtr account); + + /** + * Get a list of external sites + * + * @param path Path to request external sites for + */ + void getExternalSites(); + +signals: + /** + * Result of the OCS request + * + * @param reply The reply + */ + void externalSitesJobFinished(const QJsonDocument &reply); + +private slots: + void jobDone(const QJsonDocument &reply); +}; +} + +#endif // EXTERNALSITESJOB_H From 69f3468ec0bb81c61e31fd41dec9f09c072f98f6 Mon Sep 17 00:00:00 2001 From: Camila San Date: Fri, 19 Jan 2018 20:53:45 +0100 Subject: [PATCH 02/21] Lists external sites for each user in the main menu. Signed-off-by: Camila San --- src/gui/owncloudgui.cpp | 62 +++++++++++++++++++++++++++++++++++++++++ src/gui/owncloudgui.h | 14 +++++++++- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 10be7f430e302..f658665109d21 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -14,6 +14,7 @@ #include "application.h" #include "owncloudgui.h" +#include "ocsexternalsitesjob.h" #include "theme.h" #include "folderman.h" #include "configfile.h" @@ -51,6 +52,9 @@ #include #endif +#include +#include + namespace OCC { const char propertyAccountC[] = "oc_account"; @@ -610,6 +614,7 @@ void ownCloudGui::updateContextMenu() _contextMenu->addAction(_actionNewAccountWizard); } _contextMenu->addAction(_actionSettings); + if (!Theme::instance()->helpUrl().isEmpty()) { _contextMenu->addAction(_actionHelp); } @@ -641,6 +646,8 @@ void ownCloudGui::updateContextMenu() } _contextMenu->addAction(_actionQuit); + fetchExternalSites(); + if (_qdbusmenuWorkaround) { _tray->show(); } @@ -742,6 +749,61 @@ void ownCloudGui::setupActions() } } +void ownCloudGui::fetchExternalSites(){ + foreach (AccountStatePtr account, AccountManager::instance()->accounts()) { + OcsExternalSitesJob *job = new OcsExternalSitesJob(account->account()); + job->setProperty(propertyAccountC, QVariant::fromValue(account->account())); + connect(job, &OcsExternalSitesJob::externalSitesJobFinished, this, &ownCloudGui::slotExternalSitesFetched); + connect(job, &OcsExternalSitesJob::ocsError, this, &ownCloudGui::slotOcsError); + job->getExternalSites(); + } +} + +void ownCloudGui::setupExternalSitesMenu(QAction *actionBefore, QAction *actionTitle, QMenu *menu, QJsonArray sites){ + menu->insertSeparator(actionBefore); + menu->insertAction(actionBefore, actionTitle); + foreach (const QJsonValue &value, sites) { + QJsonObject site = value.toObject(); + QAction *action = new QAction(site["name"].toString(), this); + connect(action, &QAction::triggered, this, [site] { QDesktopServices::openUrl(QUrl(site["url"].toString())); }); + menu->insertAction(actionBefore, action); + } +} + +void ownCloudGui::slotExternalSitesFetched(const QJsonDocument &reply) +{ + if(!reply.isEmpty()){ + auto data = reply.object().value("ocs").toObject().value("data").toObject(); + auto sitesList = data.value("sites").toArray(); + + if(sitesList.size() > 0){ + QAction *externalSites = new QAction(tr("External sites:"), this); + externalSites->setDisabled(true); + auto accountList = AccountManager::instance()->accounts(); + + if(accountList.size() > 1){ + // the list of external sites will be displayed under the account that it belongs to + if(auto account = qvariant_cast(sender()->property(propertyAccountC))){ + foreach (QMenu *menu, _accountMenus) { + if(menu->title() == account->displayName()){ + setupExternalSitesMenu(_actionLogout, externalSites, menu, sitesList); + } + } + } + } else if(accountList.size() == 1){ + setupExternalSitesMenu(_actionSettings, externalSites, _contextMenu.data(), sitesList); + _contextMenu->insertSeparator(_actionSettings); + } + } + } +} + +void ownCloudGui::slotOcsError(int statusCode, const QString &message) +{ + emit serverError(statusCode, message); +} + + void ownCloudGui::slotRebuildRecentMenus() { _recentActionsMenu->clear(); diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index cba88c1e4eeb7..76e04324b6e63 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -29,6 +29,11 @@ #include #endif +#include + +class QJsonDocument; +class QJsonObject; + namespace OCC { class Folder; @@ -65,6 +70,7 @@ class ownCloudGui : public QObject signals: void setupProxy(); + void serverError(int code, const QString &message); public slots: void setupContextMenu(); @@ -92,6 +98,7 @@ public slots: void slotOpenPath(const QString &path); void slotAccountStateChanged(); void slotTrayMessageIfServerUnsupported(Account *account); + void slotExternalSitesFetched(const QJsonDocument &reply); /** * Open a share dialog for a file or folder. @@ -104,6 +111,9 @@ public slots: void slotRemoveDestroyedShareDialogs(); +protected slots: + void slotOcsError(int statusCode, const QString &message); + private slots: void slotLogin(); void slotLogout(); @@ -111,10 +121,13 @@ private slots: void slotPauseAllFolders(); void slotNewAccountWizard(); + private: void setPauseOnAllFoldersHelper(bool pause); void setupActions(); void addAccountContextMenu(AccountStatePtr accountState, QMenu *menu, bool separateMenu); + void fetchExternalSites(); + void setupExternalSitesMenu(QAction *actionBefore, QAction *actionTitle, QMenu *menu, QJsonArray sites); QPointer _tray; #if defined(Q_OS_MAC) @@ -151,7 +164,6 @@ private slots: QAction *_actionHelp; QAction *_actionQuit; QAction *_actionCrash; - QList _recentItemsActions; Application *_app; }; From ec428786acb16f27f849ac61a22671be12d8837e Mon Sep 17 00:00:00 2001 From: Camila San Date: Tue, 23 Jan 2018 20:23:17 +0100 Subject: [PATCH 03/21] Adds checkbox to toggle display of external sites list in the menu. Signed-off-by: Camila San --- src/gui/generalsettings.ui | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/gui/generalsettings.ui b/src/gui/generalsettings.ui index aacce23c2a317..6d3340396096d 100644 --- a/src/gui/generalsettings.ui +++ b/src/gui/generalsettings.ui @@ -44,6 +44,22 @@ + + + + Show external sites list in tray menu + + + true + + + true + + + false + + + From f48a94ba71414ac3adf37f89d7050449a1760d4b Mon Sep 17 00:00:00 2001 From: Camila San Date: Tue, 23 Jan 2018 20:27:57 +0100 Subject: [PATCH 04/21] Saves 'show external sites list' option to the config file. Uses option to toggle display of external sites list in the main menu. Signed-off-by: Camila San --- src/gui/generalsettings.cpp | 9 +++++++++ src/gui/generalsettings.h | 1 + src/gui/owncloudgui.cpp | 5 +++-- src/gui/owncloudgui.h | 3 +++ src/libsync/configfile.cpp | 14 ++++++++++++++ src/libsync/configfile.h | 3 +++ 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index 69baaa84be4f4..0cbb9d84d3938 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -49,6 +49,9 @@ GeneralSettings::GeneralSettings(QWidget *parent) _ui->autostartCheckBox->setChecked(Utility::hasLaunchOnStartup(Theme::instance()->appName())); connect(_ui->autostartCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotToggleLaunchOnStartup); + _ui->showExternalSitesCheckBox->setChecked(false); + connect(_ui->showExternalSitesCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotShowExternalSites); + // setup about section QString about = Theme::instance()->about(); if (about.isEmpty()) { @@ -115,6 +118,7 @@ void GeneralSettings::loadMiscSettings() ConfigFile cfgFile; _ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons()); _ui->desktopNotificationsCheckBox->setChecked(cfgFile.optionalDesktopNotifications()); + _ui->showExternalSitesCheckBox->setChecked(cfgFile.showExternalSites()); _ui->showInExplorerNavigationPaneCheckBox->setChecked(cfgFile.showInExplorerNavigationPane()); _ui->crashreporterCheckBox->setChecked(cfgFile.crashReporter()); auto newFolderLimit = cfgFile.newBigFolderSizeLimit(); @@ -190,4 +194,9 @@ void GeneralSettings::slotIgnoreFilesEditor() } } +void GeneralSettings::slotShowExternalSites(bool checked){ + ConfigFile cfgFile; + cfgFile.setShowExternalSites(checked); +} + } // namespace OCC diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index 4e92337e632b2..c78491f9a7a6d 100644 --- a/src/gui/generalsettings.h +++ b/src/gui/generalsettings.h @@ -47,6 +47,7 @@ private slots: void slotUpdateInfo(); void slotIgnoreFilesEditor(); void loadMiscSettings(); + void slotShowExternalSites(bool checked); private: Ui::GeneralSettings *_ui; diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index f658665109d21..1d8e7749c81c4 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -17,7 +17,6 @@ #include "ocsexternalsitesjob.h" #include "theme.h" #include "folderman.h" -#include "configfile.h" #include "progressdispatcher.h" #include "owncloudsetupwizard.h" #include "sharedialog.h" @@ -35,6 +34,7 @@ #include "accountmanager.h" #include "common/syncjournalfilerecord.h" #include "creds/abstractcredentials.h" +#include "configfile.h" #ifdef WITH_LIBCLOUDPROVIDERS #include "cloudproviders/cloudprovidermanager.h" #endif @@ -646,7 +646,8 @@ void ownCloudGui::updateContextMenu() } _contextMenu->addAction(_actionQuit); - fetchExternalSites(); + if(_cfg.showExternalSites()) + fetchExternalSites(); if (_qdbusmenuWorkaround) { _tray->show(); diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index 76e04324b6e63..517bfc77fef2a 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -18,6 +18,7 @@ #include "systray.h" #include "connectionvalidator.h" #include "progressdispatcher.h" +#include "configfile.h" #include #include @@ -166,6 +167,8 @@ private slots: QAction *_actionCrash; QList _recentItemsActions; Application *_app; + + ConfigFile _cfg; }; } // namespace OCC diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 295fafc17154b..4379cca108128 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -55,6 +55,7 @@ static const char promptDeleteC[] = "promptDeleteAllFiles"; static const char crashReporterC[] = "crashReporter"; static const char optionalDesktopNoficationsC[] = "optionalDesktopNotifications"; static const char showInExplorerNavigationPaneC[] = "showInExplorerNavigationPane"; +static const char showExternalSitesC[] = "showExternalSites"; static const char skipUpdateCheckC[] = "skipUpdateCheck"; static const char updateCheckIntervalC[] = "updateCheckInterval"; static const char geometryC[] = "geometry"; @@ -147,6 +148,19 @@ void ConfigFile::setShowInExplorerNavigationPane(bool show) settings.sync(); } +bool ConfigFile::showExternalSites() const +{ + QSettings settings(configFile(), QSettings::IniFormat); + return settings.value(QLatin1String(showExternalSitesC), false).toBool(); +} + +void ConfigFile::setShowExternalSites(bool show) +{ + QSettings settings(configFile(), QSettings::IniFormat); + settings.setValue(QLatin1String(showExternalSitesC), show); + settings.sync(); +} + int ConfigFile::timeout() const { QSettings settings(configFile(), QSettings::IniFormat); diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index c4c66ac1a84ee..f99cf3b49885b 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -126,6 +126,9 @@ class OWNCLOUDSYNC_EXPORT ConfigFile bool showInExplorerNavigationPane() const; void setShowInExplorerNavigationPane(bool show); + bool showExternalSites() const; + void setShowExternalSites(bool show); + int timeout() const; quint64 chunkSize() const; quint64 maxChunkSize() const; From 9f0c154e68129b38a5f7484af6366c867237b969 Mon Sep 17 00:00:00 2001 From: Camila San Date: Wed, 24 Jan 2018 15:12:06 +0100 Subject: [PATCH 05/21] Fixes request url - uses the one for all users. Signed-off-by: Camila San --- src/gui/ocsexternalsitesjob.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/ocsexternalsitesjob.cpp b/src/gui/ocsexternalsitesjob.cpp index de07003e1fc4f..0625db12563e6 100644 --- a/src/gui/ocsexternalsitesjob.cpp +++ b/src/gui/ocsexternalsitesjob.cpp @@ -19,7 +19,7 @@ namespace OCC { OcsExternalSitesJob::OcsExternalSitesJob(AccountPtr account) : OcsJob(account) { - setPath("ocs/v2.php/apps/external/api/v1/sites"); + setPath("ocs/v2.php/apps/external/api/v1"); connect(this, &OcsExternalSitesJob::jobFinished, this, &OcsExternalSitesJob::jobDone); } From 649f3ff904fa706b10b74fe70dd23f338757b69b Mon Sep 17 00:00:00 2001 From: Camila San Date: Wed, 24 Jan 2018 15:13:19 +0100 Subject: [PATCH 06/21] Changes response parsing for the new request. Signed-off-by: Camila San --- src/gui/owncloudgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 1d8e7749c81c4..908c1066705de 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -774,8 +774,8 @@ void ownCloudGui::setupExternalSitesMenu(QAction *actionBefore, QAction *actionT void ownCloudGui::slotExternalSitesFetched(const QJsonDocument &reply) { if(!reply.isEmpty()){ - auto data = reply.object().value("ocs").toObject().value("data").toObject(); - auto sitesList = data.value("sites").toArray(); + auto data = reply.object().value("ocs").toObject().value("data"); + auto sitesList = data.toArray(); if(sitesList.size() > 0){ QAction *externalSites = new QAction(tr("External sites:"), this); From 89d743396a1f400ca07391a1537138378a2ef318 Mon Sep 17 00:00:00 2001 From: Camila San Date: Fri, 26 Jan 2018 12:52:28 +0100 Subject: [PATCH 07/21] Fixes class name in comments and in ifndef. Signed-off-by: Camila San --- src/gui/ocsexternalsitesjob.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/gui/ocsexternalsitesjob.h b/src/gui/ocsexternalsitesjob.h index 892a462d349ff..5491e60388a6d 100644 --- a/src/gui/ocsexternalsitesjob.h +++ b/src/gui/ocsexternalsitesjob.h @@ -12,8 +12,8 @@ * for more details. */ -#ifndef EXTERNALSITESJOB_H -#define EXTERNALSITESJOB_H +#ifndef OCSEXTERNALSITESJOB_H +#define OCSEXTERNALSITESJOB_H #include "ocsjob.h" class QJsonDocument; @@ -21,7 +21,7 @@ class QJsonDocument; namespace OCC { /** - * @brief The ExternalSitesJob class + * @brief The OcsExternalSitesJob class * @ingroup gui * * Fetching expernal sites from the OCS External Sites API @@ -34,8 +34,6 @@ class OcsExternalSitesJob : public OcsJob /** * Get a list of external sites - * - * @param path Path to request external sites for */ void getExternalSites(); @@ -52,4 +50,4 @@ private slots: }; } -#endif // EXTERNALSITESJOB_H +#endif // OCSEXTERNALSITESJOB_H From 08769b28038541b906c0c55424ef476505252401 Mon Sep 17 00:00:00 2001 From: Camila San Date: Fri, 26 Jan 2018 13:11:35 +0100 Subject: [PATCH 08/21] Adds OcsAppsJob to retrieve apps enabled for the user. Signed-off-by: Camila San --- src/gui/CMakeLists.txt | 3 ++- src/gui/ocsappsjob.cpp | 37 +++++++++++++++++++++++++++++ src/gui/ocsappsjob.h | 53 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/gui/ocsappsjob.cpp create mode 100644 src/gui/ocsappsjob.h diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 70aaecf1f6818..ee282ca4e9338 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -59,8 +59,9 @@ set(client_SRCS logbrowser.cpp navigationpanehelper.cpp networksettings.cpp - ocsjob.cpp + ocsappsjob.cpp ocsexternalsitesjob.cpp + ocsjob.cpp ocssharejob.cpp ocsshareejob.cpp openfilemanager.cpp diff --git a/src/gui/ocsappsjob.cpp b/src/gui/ocsappsjob.cpp new file mode 100644 index 0000000000000..0a8654fd9da12 --- /dev/null +++ b/src/gui/ocsappsjob.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) by Camila Ayres + * + * 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 "ocsappsjob.h" + +namespace OCC { + +OcsAppsJob::OcsAppsJob(AccountPtr account) + : OcsJob(account) +{ + setPath("ocs/v1.php/cloud/apps/enabled"); + connect(this, &OcsAppsJob::jobFinished, this, &OcsAppsJob::jobDone); +} + +void OcsAppsJob::getApps() +{ + setVerb("GET"); + start(); +} + +void OcsAppsJob::jobDone(const QJsonDocument &reply) +{ + + emit appsJobFinished(reply); +} +} diff --git a/src/gui/ocsappsjob.h b/src/gui/ocsappsjob.h new file mode 100644 index 0000000000000..7109af1536946 --- /dev/null +++ b/src/gui/ocsappsjob.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) by Camila Ayres + * + * 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 OCSAPPSJOB_H +#define OCSAPPSJOB_H + +#include "ocsjob.h" +class QJsonDocument; + +namespace OCC { + +/** + * @brief The OcsAppsJob class + * @ingroup gui + * + * Fetching enabled apps from the OCS Apps API + */ +class OcsAppsJob : public OcsJob +{ + Q_OBJECT +public: + explicit OcsAppsJob(AccountPtr account); + + /** + * Get a list of enabled apps for the current user + */ + void getApps(); + +signals: + /** + * Result of the OCS request + * + * @param reply The reply + */ + void appsJobFinished(const QJsonDocument &reply); + +private slots: + void jobDone(const QJsonDocument &reply); +}; +} + +#endif // OCSAPPSJOB_H From 8ada9d04715b3d47d80867dda69a58c50ef7007b Mon Sep 17 00:00:00 2001 From: Camila San Date: Fri, 26 Jan 2018 13:50:47 +0100 Subject: [PATCH 09/21] List apps for each user in the tray main menu. Signed-off-by: Camila San --- src/gui/owncloudgui.cpp | 53 +++++++++++++++++++++++++++++++++++++++++ src/gui/owncloudgui.h | 5 +++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 908c1066705de..67726e4ddb4b0 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -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(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); diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index 517bfc77fef2a..5299a7635954d 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -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 slots: 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 _tray; #if defined(Q_OS_MAC) From e29953bc11296071b55fff2a6c5236ab2ef3e2e3 Mon Sep 17 00:00:00 2001 From: Camila San Date: Sun, 28 Jan 2018 19:57:31 +0100 Subject: [PATCH 10/21] Adds show apps option to the config file. Signed-off-by: Camila San --- src/libsync/configfile.cpp | 14 ++++++++++++++ src/libsync/configfile.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 4379cca108128..14d1c8ae6fe96 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -56,6 +56,7 @@ static const char crashReporterC[] = "crashReporter"; static const char optionalDesktopNoficationsC[] = "optionalDesktopNotifications"; static const char showInExplorerNavigationPaneC[] = "showInExplorerNavigationPane"; static const char showExternalSitesC[] = "showExternalSites"; +static const char showAppsC[] = "showApps"; static const char skipUpdateCheckC[] = "skipUpdateCheck"; static const char updateCheckIntervalC[] = "updateCheckInterval"; static const char geometryC[] = "geometry"; @@ -161,6 +162,19 @@ void ConfigFile::setShowExternalSites(bool show) settings.sync(); } +bool ConfigFile::showApps() const +{ + QSettings settings(configFile(), QSettings::IniFormat); + return settings.value(QLatin1String(showAppsC), false).toBool(); +} + +void ConfigFile::setShowApps(bool show) +{ + QSettings settings(configFile(), QSettings::IniFormat); + settings.setValue(QLatin1String(showAppsC), show); + settings.sync(); +} + int ConfigFile::timeout() const { QSettings settings(configFile(), QSettings::IniFormat); diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index f99cf3b49885b..76bb438c0fe0d 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -129,6 +129,9 @@ class OWNCLOUDSYNC_EXPORT ConfigFile bool showExternalSites() const; void setShowExternalSites(bool show); + bool showApps() const; + void setShowApps(bool show); + int timeout() const; quint64 chunkSize() const; quint64 maxChunkSize() const; From bf77dbac73def10fedc872e4d329fc6542b017df Mon Sep 17 00:00:00 2001 From: Camila San Date: Sun, 28 Jan 2018 19:59:10 +0100 Subject: [PATCH 11/21] Adds checkbox 'showApps' to the general settings form. Signed-off-by: Camila San --- src/gui/generalsettings.cpp | 9 +++++++ src/gui/generalsettings.h | 4 ++-- src/gui/generalsettings.ui | 48 ++++++++++++++++++++----------------- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index 0cbb9d84d3938..9cb20fec9cfd5 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -52,6 +52,9 @@ GeneralSettings::GeneralSettings(QWidget *parent) _ui->showExternalSitesCheckBox->setChecked(false); connect(_ui->showExternalSitesCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotShowExternalSites); + _ui->showAppsCheckBox->setChecked(false); + connect(_ui->showAppsCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotShowApps); + // setup about section QString about = Theme::instance()->about(); if (about.isEmpty()) { @@ -119,6 +122,7 @@ void GeneralSettings::loadMiscSettings() _ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons()); _ui->desktopNotificationsCheckBox->setChecked(cfgFile.optionalDesktopNotifications()); _ui->showExternalSitesCheckBox->setChecked(cfgFile.showExternalSites()); + _ui->showAppsCheckBox->setChecked(cfgFile.showApps()); _ui->showInExplorerNavigationPaneCheckBox->setChecked(cfgFile.showInExplorerNavigationPane()); _ui->crashreporterCheckBox->setChecked(cfgFile.crashReporter()); auto newFolderLimit = cfgFile.newBigFolderSizeLimit(); @@ -199,4 +203,9 @@ void GeneralSettings::slotShowExternalSites(bool checked){ cfgFile.setShowExternalSites(checked); } +void GeneralSettings::slotShowApps(bool checked){ + ConfigFile cfgFile; + cfgFile.setShowApps(checked); +} + } // namespace OCC diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index c78491f9a7a6d..096f71777ff43 100644 --- a/src/gui/generalsettings.h +++ b/src/gui/generalsettings.h @@ -47,8 +47,8 @@ private slots: void slotUpdateInfo(); void slotIgnoreFilesEditor(); void loadMiscSettings(); - void slotShowExternalSites(bool checked); - + void slotShowExternalSites(bool); + void slotShowApps(bool); private: Ui::GeneralSettings *_ui; QPointer _ignoreEditor; diff --git a/src/gui/generalsettings.ui b/src/gui/generalsettings.ui index 6d3340396096d..518c70bcf282b 100644 --- a/src/gui/generalsettings.ui +++ b/src/gui/generalsettings.ui @@ -20,10 +20,26 @@ General Settings - - + + - &Launch on System Startup + Show enabled apps in tray menu + + + + + + + Show external sites list in tray menu + + + true + + + false + + + false @@ -34,6 +50,13 @@ + + + + &Launch on System Startup + + + @@ -44,22 +67,6 @@ - - - - Show external sites list in tray menu - - - true - - - true - - - false - - - @@ -268,9 +275,6 @@ - autostartCheckBox - desktopNotificationsCheckBox - monoIconsCheckBox ignoredFilesButton newFolderLimitCheckBox newFolderLimitSpinBox From 9f559c8e003fefd6cb43c64748993ed7030e30b8 Mon Sep 17 00:00:00 2001 From: Camila San Date: Sun, 28 Jan 2018 20:04:08 +0100 Subject: [PATCH 12/21] Retrieves list of apps and displays it if 'show apps' checkbox is checked in the settings. Signed-off-by: Camila San --- src/gui/owncloudgui.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 67726e4ddb4b0..f0f2034a4d0e9 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -650,7 +650,8 @@ void ownCloudGui::updateContextMenu() if(_cfg.showExternalSites()) fetchExternalSites(); - fetchApps(); + if(_cfg.showApps()) + fetchApps(); if (_qdbusmenuWorkaround) { _tray->show(); @@ -815,11 +816,15 @@ void ownCloudGui::fetchApps(){ void ownCloudGui::setupAppsMenu(QAction *actionBefore, QAction *actionTitle, QMenu *menu, QJsonArray apps){ menu->insertSeparator(actionBefore); menu->insertAction(actionBefore, actionTitle); + foreach (const QJsonValue &value, apps) { + // TO DO: list all apps in the menu or just a few? 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); + if(app == "calendar"){ + QAction *action = new QAction("Calendar", this); + connect(action, &QAction::triggered, this, [] { QDesktopServices::openUrl(QUrl()); }); + menu->insertAction(actionBefore, action); + } } } From 00cfbe39be90c5bf00716ae3d597940a9f59aadb Mon Sep 17 00:00:00 2001 From: Camila San Date: Mon, 19 Feb 2018 20:49:13 +0100 Subject: [PATCH 13/21] Removes external sites/apps configuration from config file. Signed-off-by: Camila San --- src/libsync/configfile.cpp | 28 ---------------------------- src/libsync/configfile.h | 6 ------ 2 files changed, 34 deletions(-) diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 14d1c8ae6fe96..295fafc17154b 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -55,8 +55,6 @@ static const char promptDeleteC[] = "promptDeleteAllFiles"; static const char crashReporterC[] = "crashReporter"; static const char optionalDesktopNoficationsC[] = "optionalDesktopNotifications"; static const char showInExplorerNavigationPaneC[] = "showInExplorerNavigationPane"; -static const char showExternalSitesC[] = "showExternalSites"; -static const char showAppsC[] = "showApps"; static const char skipUpdateCheckC[] = "skipUpdateCheck"; static const char updateCheckIntervalC[] = "updateCheckInterval"; static const char geometryC[] = "geometry"; @@ -149,32 +147,6 @@ void ConfigFile::setShowInExplorerNavigationPane(bool show) settings.sync(); } -bool ConfigFile::showExternalSites() const -{ - QSettings settings(configFile(), QSettings::IniFormat); - return settings.value(QLatin1String(showExternalSitesC), false).toBool(); -} - -void ConfigFile::setShowExternalSites(bool show) -{ - QSettings settings(configFile(), QSettings::IniFormat); - settings.setValue(QLatin1String(showExternalSitesC), show); - settings.sync(); -} - -bool ConfigFile::showApps() const -{ - QSettings settings(configFile(), QSettings::IniFormat); - return settings.value(QLatin1String(showAppsC), false).toBool(); -} - -void ConfigFile::setShowApps(bool show) -{ - QSettings settings(configFile(), QSettings::IniFormat); - settings.setValue(QLatin1String(showAppsC), show); - settings.sync(); -} - int ConfigFile::timeout() const { QSettings settings(configFile(), QSettings::IniFormat); diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index 76bb438c0fe0d..c4c66ac1a84ee 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -126,12 +126,6 @@ class OWNCLOUDSYNC_EXPORT ConfigFile bool showInExplorerNavigationPane() const; void setShowInExplorerNavigationPane(bool show); - bool showExternalSites() const; - void setShowExternalSites(bool show); - - bool showApps() const; - void setShowApps(bool show); - int timeout() const; quint64 chunkSize() const; quint64 maxChunkSize() const; From f107b3348cdf2c1a972e4f7987f73cf1ecf626c0 Mon Sep 17 00:00:00 2001 From: Camila San Date: Mon, 19 Feb 2018 20:49:55 +0100 Subject: [PATCH 14/21] Removes external sites/apps configuration from general settings. Signed-off-by: Camila San --- src/gui/generalsettings.cpp | 18 ----------------- src/gui/generalsettings.h | 2 -- src/gui/generalsettings.ui | 39 ++++++++----------------------------- 3 files changed, 8 insertions(+), 51 deletions(-) diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index 9cb20fec9cfd5..69baaa84be4f4 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -49,12 +49,6 @@ GeneralSettings::GeneralSettings(QWidget *parent) _ui->autostartCheckBox->setChecked(Utility::hasLaunchOnStartup(Theme::instance()->appName())); connect(_ui->autostartCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotToggleLaunchOnStartup); - _ui->showExternalSitesCheckBox->setChecked(false); - connect(_ui->showExternalSitesCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotShowExternalSites); - - _ui->showAppsCheckBox->setChecked(false); - connect(_ui->showAppsCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotShowApps); - // setup about section QString about = Theme::instance()->about(); if (about.isEmpty()) { @@ -121,8 +115,6 @@ void GeneralSettings::loadMiscSettings() ConfigFile cfgFile; _ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons()); _ui->desktopNotificationsCheckBox->setChecked(cfgFile.optionalDesktopNotifications()); - _ui->showExternalSitesCheckBox->setChecked(cfgFile.showExternalSites()); - _ui->showAppsCheckBox->setChecked(cfgFile.showApps()); _ui->showInExplorerNavigationPaneCheckBox->setChecked(cfgFile.showInExplorerNavigationPane()); _ui->crashreporterCheckBox->setChecked(cfgFile.crashReporter()); auto newFolderLimit = cfgFile.newBigFolderSizeLimit(); @@ -198,14 +190,4 @@ void GeneralSettings::slotIgnoreFilesEditor() } } -void GeneralSettings::slotShowExternalSites(bool checked){ - ConfigFile cfgFile; - cfgFile.setShowExternalSites(checked); -} - -void GeneralSettings::slotShowApps(bool checked){ - ConfigFile cfgFile; - cfgFile.setShowApps(checked); -} - } // namespace OCC diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index 096f71777ff43..5640dd345d633 100644 --- a/src/gui/generalsettings.h +++ b/src/gui/generalsettings.h @@ -47,8 +47,6 @@ private slots: void slotUpdateInfo(); void slotIgnoreFilesEditor(); void loadMiscSettings(); - void slotShowExternalSites(bool); - void slotShowApps(bool); private: Ui::GeneralSettings *_ui; QPointer _ignoreEditor; diff --git a/src/gui/generalsettings.ui b/src/gui/generalsettings.ui index 518c70bcf282b..05aba5138bfe7 100644 --- a/src/gui/generalsettings.ui +++ b/src/gui/generalsettings.ui @@ -20,33 +20,13 @@ General Settings - - - - Show enabled apps in tray menu - - - - - - - Show external sites list in tray menu - - - true - - - false - - - false + + + + For System Tray - - - - - Show &Desktop Notifications + Use &Monochrome Icons @@ -57,13 +37,10 @@ - - - - For System Tray - + + - Use &Monochrome Icons + Show &Desktop Notifications From c9bc20c63d8f6ca51453786f4dd069e91e438288 Mon Sep 17 00:00:00 2001 From: Camila San Date: Mon, 19 Feb 2018 20:51:56 +0100 Subject: [PATCH 15/21] Creates navigation/apps API call class OcsNavigationAppsJob. Signed-off-by: Camila San --- src/gui/ocsexternalsitesjob.cpp | 37 ------------- src/gui/ocsexternalsitesjob.h | 53 ------------------- ...csappsjob.cpp => ocsnavigationappsjob.cpp} | 12 ++--- .../{ocsappsjob.h => ocsnavigationappsjob.h} | 15 +++--- 4 files changed, 14 insertions(+), 103 deletions(-) delete mode 100644 src/gui/ocsexternalsitesjob.cpp delete mode 100644 src/gui/ocsexternalsitesjob.h rename src/gui/{ocsappsjob.cpp => ocsnavigationappsjob.cpp} (66%) rename src/gui/{ocsappsjob.h => ocsnavigationappsjob.h} (75%) diff --git a/src/gui/ocsexternalsitesjob.cpp b/src/gui/ocsexternalsitesjob.cpp deleted file mode 100644 index 0625db12563e6..0000000000000 --- a/src/gui/ocsexternalsitesjob.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) by Camila Ayres - * - * 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 "ocsexternalsitesjob.h" - -namespace OCC { - -OcsExternalSitesJob::OcsExternalSitesJob(AccountPtr account) - : OcsJob(account) -{ - setPath("ocs/v2.php/apps/external/api/v1"); - connect(this, &OcsExternalSitesJob::jobFinished, this, &OcsExternalSitesJob::jobDone); -} - -void OcsExternalSitesJob::getExternalSites() -{ - setVerb("GET"); - start(); -} - -void OcsExternalSitesJob::jobDone(const QJsonDocument &reply) -{ - - emit externalSitesJobFinished(reply); -} -} diff --git a/src/gui/ocsexternalsitesjob.h b/src/gui/ocsexternalsitesjob.h deleted file mode 100644 index 5491e60388a6d..0000000000000 --- a/src/gui/ocsexternalsitesjob.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) by Camila Ayres - * - * 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 OCSEXTERNALSITESJOB_H -#define OCSEXTERNALSITESJOB_H - -#include "ocsjob.h" -class QJsonDocument; - -namespace OCC { - -/** - * @brief The OcsExternalSitesJob class - * @ingroup gui - * - * Fetching expernal sites from the OCS External Sites API - */ -class OcsExternalSitesJob : public OcsJob -{ - Q_OBJECT -public: - explicit OcsExternalSitesJob(AccountPtr account); - - /** - * Get a list of external sites - */ - void getExternalSites(); - -signals: - /** - * Result of the OCS request - * - * @param reply The reply - */ - void externalSitesJobFinished(const QJsonDocument &reply); - -private slots: - void jobDone(const QJsonDocument &reply); -}; -} - -#endif // OCSEXTERNALSITESJOB_H diff --git a/src/gui/ocsappsjob.cpp b/src/gui/ocsnavigationappsjob.cpp similarity index 66% rename from src/gui/ocsappsjob.cpp rename to src/gui/ocsnavigationappsjob.cpp index 0a8654fd9da12..29ed3d3967052 100644 --- a/src/gui/ocsappsjob.cpp +++ b/src/gui/ocsnavigationappsjob.cpp @@ -12,24 +12,24 @@ * for more details. */ -#include "ocsappsjob.h" +#include "ocsnavigationappsjob.h" namespace OCC { -OcsAppsJob::OcsAppsJob(AccountPtr account) +OcsNavigationAppsJob::OcsNavigationAppsJob(AccountPtr account) : OcsJob(account) { - setPath("ocs/v1.php/cloud/apps/enabled"); - connect(this, &OcsAppsJob::jobFinished, this, &OcsAppsJob::jobDone); + setPath("ocs/v2.php/core/navigation/apps"); + connect(this, &OcsNavigationAppsJob::jobFinished, this, &OcsNavigationAppsJob::jobDone); } -void OcsAppsJob::getApps() +void OcsNavigationAppsJob::getNavigationApps() { setVerb("GET"); start(); } -void OcsAppsJob::jobDone(const QJsonDocument &reply) +void OcsNavigationAppsJob::jobDone(const QJsonDocument &reply) { emit appsJobFinished(reply); diff --git a/src/gui/ocsappsjob.h b/src/gui/ocsnavigationappsjob.h similarity index 75% rename from src/gui/ocsappsjob.h rename to src/gui/ocsnavigationappsjob.h index 7109af1536946..2c0c7bd4a6c5e 100644 --- a/src/gui/ocsappsjob.h +++ b/src/gui/ocsnavigationappsjob.h @@ -12,8 +12,8 @@ * for more details. */ -#ifndef OCSAPPSJOB_H -#define OCSAPPSJOB_H +#ifndef OCSNAVIGATIONAPPSJOB_H +#define OCSNAVIGATIONAPPSJOB_H #include "ocsjob.h" class QJsonDocument; @@ -26,16 +26,17 @@ namespace OCC { * * Fetching enabled apps from the OCS Apps API */ -class OcsAppsJob : public OcsJob +class OcsNavigationAppsJob : public OcsJob { Q_OBJECT public: - explicit OcsAppsJob(AccountPtr account); + explicit OcsNavigationAppsJob(AccountPtr account); /** - * Get a list of enabled apps for the current user + * Get a list of enabled apps and external sites + * visible in the Navigation menu */ - void getApps(); + void getNavigationApps(); signals: /** @@ -50,4 +51,4 @@ private slots: }; } -#endif // OCSAPPSJOB_H +#endif // OCSNAVIGATIONAPPSJOB_H From fb080f08ec68fb85658d981b471270bae4f152c6 Mon Sep 17 00:00:00 2001 From: Camila San Date: Mon, 19 Feb 2018 20:53:12 +0100 Subject: [PATCH 16/21] Uses OcsNavigationAppsJob instead of OcsAppsJob and OcsExternalSitesJob in OwncloudGui. Signed-off-by: Camila San --- src/gui/owncloudgui.cpp | 76 ++++++----------------------------------- src/gui/owncloudgui.h | 7 ++-- 2 files changed, 14 insertions(+), 69 deletions(-) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index f0f2034a4d0e9..0a7e8c5d39000 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -14,8 +14,7 @@ #include "application.h" #include "owncloudgui.h" -#include "ocsappsjob.h" -#include "ocsexternalsitesjob.h" +#include "ocsnavigationappsjob.h" #include "theme.h" #include "folderman.h" #include "progressdispatcher.h" @@ -647,11 +646,7 @@ void ownCloudGui::updateContextMenu() } _contextMenu->addAction(_actionQuit); - if(_cfg.showExternalSites()) - fetchExternalSites(); - - if(_cfg.showApps()) - fetchApps(); + fetchNavigationApps(); if (_qdbusmenuWorkaround) { _tray->show(); @@ -754,66 +749,17 @@ void ownCloudGui::setupActions() } } -void ownCloudGui::fetchExternalSites(){ - foreach (AccountStatePtr account, AccountManager::instance()->accounts()) { - OcsExternalSitesJob *job = new OcsExternalSitesJob(account->account()); - job->setProperty(propertyAccountC, QVariant::fromValue(account->account())); - connect(job, &OcsExternalSitesJob::externalSitesJobFinished, this, &ownCloudGui::slotExternalSitesFetched); - connect(job, &OcsExternalSitesJob::ocsError, this, &ownCloudGui::slotOcsError); - job->getExternalSites(); - } -} - -void ownCloudGui::setupExternalSitesMenu(QAction *actionBefore, QAction *actionTitle, QMenu *menu, QJsonArray sites){ - menu->insertSeparator(actionBefore); - menu->insertAction(actionBefore, actionTitle); - foreach (const QJsonValue &value, sites) { - QJsonObject site = value.toObject(); - QAction *action = new QAction(site["name"].toString(), this); - connect(action, &QAction::triggered, this, [site] { QDesktopServices::openUrl(QUrl(site["url"].toString())); }); - menu->insertAction(actionBefore, action); - } -} - -void ownCloudGui::slotExternalSitesFetched(const QJsonDocument &reply) -{ - if(!reply.isEmpty()){ - auto data = reply.object().value("ocs").toObject().value("data"); - auto sitesList = data.toArray(); - - if(sitesList.size() > 0){ - QAction *externalSites = new QAction(tr("External sites:"), this); - externalSites->setDisabled(true); - auto accountList = AccountManager::instance()->accounts(); - - if(accountList.size() > 1){ - // the list of external sites will be displayed under the account that it belongs to - if(auto account = qvariant_cast(sender()->property(propertyAccountC))){ - foreach (QMenu *menu, _accountMenus) { - if(menu->title() == account->displayName()){ - setupExternalSitesMenu(_actionLogout, externalSites, menu, sitesList); - } - } - } - } else if(accountList.size() == 1){ - setupExternalSitesMenu(_actionSettings, externalSites, _contextMenu.data(), sitesList); - _contextMenu->insertSeparator(_actionSettings); - } - } - } -} - -void ownCloudGui::fetchApps(){ +void ownCloudGui::fetchNavigationApps(){ foreach (AccountStatePtr account, AccountManager::instance()->accounts()) { - OcsAppsJob *job = new OcsAppsJob(account->account()); + OcsNavigationAppsJob *job = new OcsNavigationAppsJob(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(); + connect(job, &OcsNavigationAppsJob::appsJobFinished, this, &ownCloudGui::slotNavigationAppsFetched); + connect(job, &OcsNavigationAppsJob::ocsError, this, &ownCloudGui::slotOcsError); + job->getNavigationApps(); } } -void ownCloudGui::setupAppsMenu(QAction *actionBefore, QAction *actionTitle, QMenu *menu, QJsonArray apps){ +void ownCloudGui::setupNavigationAppsMenu(QAction *actionBefore, QAction *actionTitle, QMenu *menu, QJsonArray apps){ menu->insertSeparator(actionBefore); menu->insertAction(actionBefore, actionTitle); @@ -828,7 +774,7 @@ void ownCloudGui::setupAppsMenu(QAction *actionBefore, QAction *actionTitle, QMe } } -void ownCloudGui::slotAppsFetched(const QJsonDocument &reply) +void ownCloudGui::slotNavigationAppsFetched(const QJsonDocument &reply) { if(!reply.isEmpty()){ auto data = reply.object().value("ocs").toObject().value("data").toObject().value("apps"); @@ -844,12 +790,12 @@ void ownCloudGui::slotAppsFetched(const QJsonDocument &reply) if(auto account = qvariant_cast(sender()->property(propertyAccountC))){ foreach (QMenu *menu, _accountMenus) { if(menu->title() == account->displayName()){ - setupAppsMenu(_actionLogout, apps, menu, appsList); + setupNavigationAppsMenu(_actionLogout, apps, menu, appsList); } } } } else if(accountList.size() == 1){ - setupAppsMenu(_actionSettings, apps, _contextMenu.data(), appsList); + setupNavigationAppsMenu(_actionSettings, apps, _contextMenu.data(), appsList); _contextMenu->insertSeparator(_actionSettings); } } diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index 5299a7635954d..7a8597abc1c1d 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -99,8 +99,7 @@ public slots: void slotOpenPath(const QString &path); void slotAccountStateChanged(); void slotTrayMessageIfServerUnsupported(Account *account); - void slotExternalSitesFetched(const QJsonDocument &reply); - void slotAppsFetched(const QJsonDocument &reply); + void slotNavigationAppsFetched(const QJsonDocument &reply); /** * Open a share dialog for a file or folder. * @@ -129,8 +128,8 @@ private slots: 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); + void fetchNavigationApps(); + void setupNavigationAppsMenu(QAction *actionBefore, QAction *actionTitle, QMenu *menu, QJsonArray apps); QPointer _tray; From 61062f98097dbbb2c21599f3aeb578fa90948c2b Mon Sep 17 00:00:00 2001 From: Camila San Date: Tue, 20 Feb 2018 19:33:25 +0100 Subject: [PATCH 17/21] Adds ocsnavigationapps files to CMakeslists.txt. Signed-off-by: Camila San --- src/gui/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index ee282ca4e9338..e0a1c69819d1e 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -59,8 +59,7 @@ set(client_SRCS logbrowser.cpp navigationpanehelper.cpp networksettings.cpp - ocsappsjob.cpp - ocsexternalsitesjob.cpp + ocsnavigationappsjob.cpp ocsjob.cpp ocssharejob.cpp ocsshareejob.cpp From 9acb30ecb228877bbe076c2cf7a6435310af9f42 Mon Sep 17 00:00:00 2001 From: Camila San Date: Tue, 20 Feb 2018 19:41:08 +0100 Subject: [PATCH 18/21] Refactores code to fetch and display sub menu with list from navigation/apps endpoint. Signed-off-by: Camila San --- src/gui/owncloudgui.cpp | 55 ++++++++++++++++++++--------------------- src/gui/owncloudgui.h | 3 --- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 0a7e8c5d39000..dc24726550d67 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -759,44 +759,43 @@ void ownCloudGui::fetchNavigationApps(){ } } -void ownCloudGui::setupNavigationAppsMenu(QAction *actionBefore, QAction *actionTitle, QMenu *menu, QJsonArray apps){ - menu->insertSeparator(actionBefore); - menu->insertAction(actionBefore, actionTitle); - - foreach (const QJsonValue &value, apps) { - // TO DO: list all apps in the menu or just a few? - QString app = value.toString(); - if(app == "calendar"){ - QAction *action = new QAction("Calendar", this); - connect(action, &QAction::triggered, this, [] { QDesktopServices::openUrl(QUrl()); }); - menu->insertAction(actionBefore, action); - } - } -} - void ownCloudGui::slotNavigationAppsFetched(const QJsonDocument &reply) { if(!reply.isEmpty()){ - auto data = reply.object().value("ocs").toObject().value("data").toObject().value("apps"); - auto appsList = data.toArray(); + auto element = reply.object().value("ocs").toObject().value("data"); + auto navLinks = element.toArray(); - if(appsList.size() > 0){ - QAction *apps = new QAction(tr("Apps:"), this); - apps->setDisabled(true); - auto accountList = AccountManager::instance()->accounts(); + if(navLinks.size() > 0){ + if(auto account = qvariant_cast(sender()->property(propertyAccountC))){ - if(accountList.size() > 1){ - // the list of apps will be displayed under the account that it belongs to - if(auto account = qvariant_cast(sender()->property(propertyAccountC))){ + // when there is only one account add the nav links above the settings + QMenu *accountMenu = _contextMenu.data(); + 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()){ - setupNavigationAppsMenu(_actionLogout, apps, menu, appsList); + accountMenu = menu; + break; } } } - } else if(accountList.size() == 1){ - setupNavigationAppsMenu(_actionSettings, apps, _contextMenu.data(), appsList); - _contextMenu->insertSeparator(_actionSettings); + + // 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); } } } diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index 7a8597abc1c1d..33c8d4356fe70 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -126,10 +126,7 @@ private slots: void setPauseOnAllFoldersHelper(bool pause); void setupActions(); void addAccountContextMenu(AccountStatePtr accountState, QMenu *menu, bool separateMenu); - void fetchExternalSites(); - void setupExternalSitesMenu(QAction *actionBefore, QAction *actionTitle, QMenu *menu, QJsonArray sites); void fetchNavigationApps(); - void setupNavigationAppsMenu(QAction *actionBefore, QAction *actionTitle, QMenu *menu, QJsonArray apps); QPointer _tray; From 4ffff7454e698ae3efcabd6885fc2103a2d72fa7 Mon Sep 17 00:00:00 2001 From: Camila San Date: Wed, 21 Feb 2018 18:49:12 +0100 Subject: [PATCH 19/21] Refactores code and displays nav. apps before Pause/Unpause folders sync. Signed-off-by: Camila San --- src/gui/owncloudgui.cpp | 87 ++++++++++++++++++++++------------------- src/gui/owncloudgui.h | 6 +-- 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index dc24726550d67..21838528e77d9 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))){ - - // when there is only one account add the nav links above the settings - QMenu *accountMenu = _contextMenu.data(); - 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; + if(QMenu *accountMenu = qvariant_cast(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 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 33c8d4356fe70..c0fe1f5c21102 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -126,7 +126,7 @@ private slots: 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 slots: QTimer _workaroundBatchTrayUpdate; QMap> _shareDialogs; - QAction *_actionLogin; - QAction *_actionLogout; - QAction *_actionNewAccountWizard; QAction *_actionSettings; QAction *_actionStatus; @@ -165,6 +162,7 @@ private slots: QAction *_actionQuit; QAction *_actionCrash; QList _recentItemsActions; + QList _storedActionsForNavApps; Application *_app; ConfigFile _cfg; From 99d8d050c23345877c4f9aa7a27ece4e1f8af455 Mon Sep 17 00:00:00 2001 From: Camila San Date: Thu, 22 Feb 2018 19:15:02 +0100 Subject: [PATCH 20/21] Compares account menu with the account associated with the action to make sure apps is added to the right position. Signed-off-by: Camila San --- src/gui/generalsettings.h | 1 + src/gui/generalsettings.ui | 23 +++++++++++++---------- src/gui/owncloudgui.cpp | 25 +++++++------------------ src/gui/owncloudgui.h | 13 ++----------- 4 files changed, 23 insertions(+), 39 deletions(-) diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index 5640dd345d633..4e92337e632b2 100644 --- a/src/gui/generalsettings.h +++ b/src/gui/generalsettings.h @@ -47,6 +47,7 @@ private slots: void slotUpdateInfo(); void slotIgnoreFilesEditor(); void loadMiscSettings(); + private: Ui::GeneralSettings *_ui; QPointer _ignoreEditor; diff --git a/src/gui/generalsettings.ui b/src/gui/generalsettings.ui index 05aba5138bfe7..aacce23c2a317 100644 --- a/src/gui/generalsettings.ui +++ b/src/gui/generalsettings.ui @@ -20,16 +20,6 @@ General Settings - - - - For System Tray - - - Use &Monochrome Icons - - - @@ -44,6 +34,16 @@ + + + + For System Tray + + + Use &Monochrome Icons + + + @@ -252,6 +252,9 @@ + autostartCheckBox + desktopNotificationsCheckBox + monoIconsCheckBox ignoredFilesButton newFolderLimitCheckBox newFolderLimitSpinBox diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 21838528e77d9..3e75882b97b65 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -17,6 +17,7 @@ #include "ocsnavigationappsjob.h" #include "theme.h" #include "folderman.h" +#include "configfile.h" #include "progressdispatcher.h" #include "owncloudsetupwizard.h" #include "sharedialog.h" @@ -34,7 +35,6 @@ #include "accountmanager.h" #include "common/syncjournalfilerecord.h" #include "creds/abstractcredentials.h" -#include "configfile.h" #ifdef WITH_LIBCLOUDPROVIDERS #include "cloudproviders/cloudprovidermanager.h" #endif @@ -54,6 +54,7 @@ #include #include +#include namespace OCC { @@ -398,13 +399,11 @@ 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()) { @@ -415,7 +414,6 @@ 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); } } } @@ -572,7 +570,6 @@ void ownCloudGui::updateContextMenu() menu->deleteLater(); } _accountMenus.clear(); - _storedActionsForNavApps.clear(); auto accountList = AccountManager::instance()->accounts(); @@ -620,7 +617,6 @@ void ownCloudGui::updateContextMenu() _contextMenu->addAction(_actionNewAccountWizard); } _contextMenu->addAction(_actionSettings); - if (!Theme::instance()->helpUrl().isEmpty()) { _contextMenu->addAction(_actionHelp); } @@ -762,7 +758,6 @@ 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(sender()->property(propertyAccountC))){ if(QMenu *accountMenu = qvariant_cast(sender()->property(propertyMenuC))){ @@ -770,17 +765,13 @@ void ownCloudGui::slotNavigationAppsFetched(const QJsonDocument &reply) // 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 + // 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, _storedActionsForNavApps){ - qDebug() << "Action: " - << action->text(); + foreach(QAction *action, accountMenu->actions()){ + + // pause/unpause folder and logout actions have propertyAccountC 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(); + if(actionAccount->account() == account){ actionBefore = action; break; } @@ -806,13 +797,11 @@ void ownCloudGui::slotNavigationAppsFetched(const QJsonDocument &reply) } } - void ownCloudGui::slotOcsError(int statusCode, const QString &message) { emit serverError(statusCode, message); } - void ownCloudGui::slotRebuildRecentMenus() { _recentActionsMenu->clear(); diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index c0fe1f5c21102..432a22014fbf0 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -18,7 +18,6 @@ #include "systray.h" #include "connectionvalidator.h" #include "progressdispatcher.h" -#include "configfile.h" #include #include @@ -30,11 +29,6 @@ #include #endif -#include - -class QJsonDocument; -class QJsonObject; - namespace OCC { class Folder; @@ -100,6 +94,7 @@ public slots: void slotAccountStateChanged(); void slotTrayMessageIfServerUnsupported(Account *account); void slotNavigationAppsFetched(const QJsonDocument &reply); + /** * Open a share dialog for a file or folder. * @@ -121,14 +116,12 @@ private slots: void slotPauseAllFolders(); void slotNewAccountWizard(); - private: void setPauseOnAllFoldersHelper(bool pause); void setupActions(); void addAccountContextMenu(AccountStatePtr accountState, QMenu *menu, bool separateMenu); void fetchNavigationApps(AccountStatePtr account, QMenu *accountMenu); - QPointer _tray; #if defined(Q_OS_MAC) QPointer _settingsDialog; @@ -161,11 +154,9 @@ private slots: QAction *_actionHelp; QAction *_actionQuit; QAction *_actionCrash; + QList _recentItemsActions; - QList _storedActionsForNavApps; Application *_app; - - ConfigFile _cfg; }; } // namespace OCC From 11d178ce1df5a41f30713975ac00286e6dd10fd2 Mon Sep 17 00:00:00 2001 From: Camila San Date: Sat, 3 Mar 2018 23:11:11 +0100 Subject: [PATCH 21/21] Adds absolute=true param to navigation/apps request. Signed-off-by: Camila San --- src/gui/ocsnavigationappsjob.cpp | 1 + src/gui/owncloudgui.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/ocsnavigationappsjob.cpp b/src/gui/ocsnavigationappsjob.cpp index 29ed3d3967052..b070873d51125 100644 --- a/src/gui/ocsnavigationappsjob.cpp +++ b/src/gui/ocsnavigationappsjob.cpp @@ -26,6 +26,7 @@ OcsNavigationAppsJob::OcsNavigationAppsJob(AccountPtr account) void OcsNavigationAppsJob::getNavigationApps() { setVerb("GET"); + addParam("absolute", "true"); start(); } diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 3e75882b97b65..d0d8fa940f3c3 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -786,7 +786,7 @@ void ownCloudGui::slotNavigationAppsFetched(const QJsonDocument &reply) 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()); + QUrl href(navLink.value("href").toString()); connect(action, &QAction::triggered, this, [href] { QDesktopServices::openUrl(href); }); navLinksMenu->addAction(action); }