Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8408851
Adds OCS External Sites Job to retrieve it from the server.
Jan 19, 2018
69f3468
Lists external sites for each user in the main menu.
Jan 19, 2018
ec42878
Adds checkbox to toggle display of external sites list in the menu.
Jan 23, 2018
f48a94b
Saves 'show external sites list' option to the config file.
Jan 23, 2018
9f0c154
Fixes request url - uses the one for all users.
Jan 24, 2018
649f3ff
Changes response parsing for the new request.
Jan 24, 2018
89d7433
Fixes class name in comments and in ifndef.
Jan 26, 2018
08769b2
Adds OcsAppsJob to retrieve apps enabled for the user.
Jan 26, 2018
8ada9d0
List apps for each user in the tray main menu.
Jan 26, 2018
e29953b
Adds show apps option to the config file.
Jan 28, 2018
bf77dba
Adds checkbox 'showApps' to the general settings form.
Jan 28, 2018
9f559c8
Retrieves list of apps and displays it if 'show apps' checkbox is che…
Jan 28, 2018
00cfbe3
Removes external sites/apps configuration from config file.
Feb 19, 2018
f107b33
Removes external sites/apps configuration from general settings.
Feb 19, 2018
c9bc20c
Creates navigation/apps API call class OcsNavigationAppsJob.
Feb 19, 2018
fb080f0
Uses OcsNavigationAppsJob instead of OcsAppsJob and OcsExternalSitesJ…
Feb 19, 2018
61062f9
Adds ocsnavigationapps files to CMakeslists.txt.
Feb 20, 2018
9acb30e
Refactores code to fetch and display sub menu with list from navigati…
Feb 20, 2018
4ffff74
Refactores code and displays nav. apps before Pause/Unpause folders s…
Feb 21, 2018
99d8d05
Compares account menu with the account associated with the action to …
Feb 22, 2018
11d178c
Adds absolute=true param to navigation/apps request.
Mar 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ set(client_SRCS
logbrowser.cpp
navigationpanehelper.cpp
networksettings.cpp
ocsnavigationappsjob.cpp
ocsjob.cpp
ocssharejob.cpp
ocsshareejob.cpp
Expand Down
38 changes: 38 additions & 0 deletions src/gui/ocsnavigationappsjob.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) by Camila Ayres <[email protected]>
*
* 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 changes: 54 additions & 0 deletions src/gui/ocsnavigationappsjob.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) by Camila Ayres <[email protected]>
*
* 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
72 changes: 66 additions & 6 deletions src/gui/owncloudgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "application.h"
#include "owncloudgui.h"
#include "ocsnavigationappsjob.h"
#include "theme.h"
#include "folderman.h"
#include "configfile.h"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -565,7 +571,6 @@ void ownCloudGui::updateContextMenu()
}
_accountMenus.clear();


auto accountList = AccountManager::instance()->accounts();

bool isConfigured = (!accountList.isEmpty());
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down
9 changes: 6 additions & 3 deletions src/gui/owncloudgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ownCloudGui : public QObject

signals:
void setupProxy();
void serverError(int code, const QString &message);

public slots:
void setupContextMenu();
Expand Down Expand Up @@ -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.
Expand All @@ -104,6 +106,9 @@ public slots:

void slotRemoveDestroyedShareDialogs();

protected slots:
void slotOcsError(int statusCode, const QString &message);

private slots:
void slotLogin();
void slotLogout();
Expand All @@ -115,6 +120,7 @@ private slots:
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)
Expand All @@ -140,9 +146,6 @@ private slots:
QTimer _workaroundBatchTrayUpdate;
QMap<QString, QPointer<ShareDialog>> _shareDialogs;

QAction *_actionLogin;
QAction *_actionLogout;

QAction *_actionNewAccountWizard;
QAction *_actionSettings;
QAction *_actionStatus;
Expand Down