Use proper QFlags

Now the ShareTypes and Permissions are part of the Share class (which is
a bit better abstracted away).
This commit is contained in:
Roeland Jago Douma 2015-10-29 21:47:47 +01:00
parent dd8d02b8ef
commit c7b814337a
6 changed files with 56 additions and 50 deletions

View file

@ -83,7 +83,7 @@ void OcsShareJob::setPublicUpload(const QString &shareId, bool publicUpload)
start();
}
void OcsShareJob::createShare(const QString &path, ShareType shareType, const QString &password, const QDate &date)
void OcsShareJob::createShare(const QString &path, Share::ShareType shareType, const QString &password, const QDate &date)
{
setVerb("POST");

View file

@ -15,6 +15,7 @@
#define OCSSHAREJOB_H
#include "ocsjob.h"
#include "share.h"
#include <QVector>
#include <QList>
#include <QPair>
@ -32,25 +33,6 @@ class OcsShareJob : public OcsJob {
Q_OBJECT
public:
/**
* Support sharetypes
*/
enum ShareType : int {
Link = 3
};
/**
* Possible permissions
*/
enum Permission : int {
Read = 1,
Update = 2,
Create = 4,
Delete = 8,
Share = 16,
All = 31
};
/**
* Constructor for new shares or listing of shares
*/
@ -99,7 +81,7 @@ public:
* @param password Optionally a password for the share
* @param date Optionally an expire date for the share
*/
void createShare(const QString& path, ShareType shareType, const QString& password = "", const QDate& date = QDate());
void createShare(const QString& path, Share::ShareType shareType, const QString& password = "", const QDate& date = QDate());
signals:
/**

View file

@ -19,8 +19,11 @@
namespace OCC {
Share::Share(AccountPtr account, const QString& id, const QString& path, int shareType,
int permissions)
Share::Share(AccountPtr account,
const QString& id,
const QString& path,
ShareType shareType,
Permissions permissions)
: _account(account),
_id(id),
_path(path),
@ -35,12 +38,12 @@ QString Share::getId() const
return _id;
}
int Share::getShareType() const
Share::ShareType Share::getShareType() const
{
return _shareType;
}
int Share::getPermissions() const
Share::Permissions Share::getPermissions() const
{
return _permissions;
}
@ -81,12 +84,11 @@ bool LinkShare::isPasswordSet() const
LinkShare::LinkShare(AccountPtr account,
const QString& id,
const QString& path,
int shareType,
int permissions,
Permissions permissions,
bool passwordSet,
const QUrl& url,
const QDate& expireDate)
: Share(account, id, path, shareType, permissions),
: Share(account, id, path, Share::TypeLink, permissions),
_passwordSet(passwordSet),
_expireDate(expireDate),
_url(url)
@ -96,8 +98,8 @@ LinkShare::LinkShare(AccountPtr account,
bool LinkShare::getPublicUpload()
{
return ((_permissions & OcsShareJob::Permission::Update) &&
(_permissions & OcsShareJob::Permission::Create));
return ((_permissions & PermissionUpdate) &&
(_permissions & PermissionCreate));
}
void LinkShare::setPublicUpload(bool publicUpload)
@ -112,9 +114,9 @@ void LinkShare::slotPublicUploadSet(const QVariantMap&, const QVariant &value)
{
//TODO FIX permission with names
if (value.toBool()) {
_permissions = 7;
_permissions = PermissionRead | PermissionUpdate | PermissionCreate;
} else {
_permissions = 1;
_permissions = PermissionRead;
}
emit publicUploadSet();
@ -161,7 +163,7 @@ void ShareManager::createLinkShare(const QString &path,
OcsShareJob *job = new OcsShareJob(_account, this);
connect(job, SIGNAL(shareJobFinished(QVariantMap, QVariant)), SLOT(slotLinkShareCreated(QVariantMap)));
connect(job, SIGNAL(ocsError(int, QString)), SLOT(slotOcsError(int, QString)));
job->createShare(path, OcsShareJob::ShareType::Link, password);
job->createShare(path, Share::TypeLink, password);
}
void ShareManager::slotLinkShareCreated(const QVariantMap &reply)
@ -208,14 +210,14 @@ void ShareManager::slotSharesFetched(const QVariantMap &reply)
QSharedPointer<Share> newShare;
if (shareType == OcsShareJob::ShareType::Link) {
if (shareType == Share::TypeLink) {
newShare = parseLinkShare(data);
} else {
newShare = QSharedPointer<Share>(new Share(_account,
data.value("id").toString(),
data.value("path").toString(),
shareType,
data.value("permissions").toInt()));
(Share::ShareType)shareType,
(Share::Permissions)data.value("permissions").toInt()));
}
shares.append(QSharedPointer<Share>(newShare));
@ -249,8 +251,7 @@ QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QVariantMap &data)
return QSharedPointer<LinkShare>(new LinkShare(_account,
data.value("id").toString(),
data.value("path").toString(),
data.value("share_type").toInt(),
data.value("permissions").toInt(),
(Share::Permissions)data.value("permissions").toInt(),
data.value("share_with").isValid(),
url,
expireDate));

View file

@ -30,14 +30,37 @@ class Share : public QObject {
public:
/**
* Possible share types
*/
enum ShareType {
TypeUser = 0,
TypeGroup = 1,
TypeLink = 3,
TypeRemote = 6,
};
Q_DECLARE_FLAGS(ShareTypes, ShareType)
/**
* Possible permissions
*/
enum Permission {
PermissionRead = 1,
PermissionUpdate = 2,
PermissionCreate = 4,
PermissionDelete = 8,
PermissionShare = 16
};
Q_DECLARE_FLAGS(Permissions, Permission)
/*
* Constructor for shares
*/
explicit Share(AccountPtr account,
const QString& id,
const QString& path,
int shareType,
int permissions);
ShareType shareType,
Permissions permissions);
/*
* Get the id
@ -47,12 +70,12 @@ public:
/*
* Get the shareType
*/
int getShareType() const;
ShareType getShareType() const;
/*
* Get permissions
*/
int getPermissions() const;
Permissions getPermissions() const;
/*
* Set the permissions of a share
@ -79,8 +102,8 @@ protected:
AccountPtr _account;
QString _id;
QString _path;
int _shareType;
int _permissions;
ShareType _shareType;
Permissions _permissions;
protected slots:
void slotOcsError(int statusCode, const QString &message);
@ -102,8 +125,7 @@ public:
explicit LinkShare(AccountPtr account,
const QString& id,
const QString& path,
int shareType,
int permissions,
Permissions permissions,
bool passwordSet,
const QUrl& url,
const QDate& expireDate);
@ -168,6 +190,7 @@ private:
QDate _expireDate;
QUrl _url;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Share::Permissions)
/**
* The share manager allows for creating, retrieving and deletion

View file

@ -23,7 +23,6 @@
#include "configfile.h"
#include "capabilities.h"
#include "ocssharejob.h"
#include "thumbnailjob.h"
#include "share.h"
@ -272,7 +271,7 @@ void ShareDialog::slotSharesFetched(const QList<QSharedPointer<Share>> &shares)
Q_FOREACH(auto share, shares) {
if (share->getShareType() == static_cast<int>(OcsShareJob::ShareType::Link)) {
if (share->getShareType() == Share::TypeLink) {
_share = qSharedPointerDynamicCast<LinkShare>(share);
_ui->pushButton_copy->show();

View file

@ -22,8 +22,6 @@
#include <QSharedPointer>
#include <QList>
#include "share.h"
namespace OCC {
namespace Ui {
@ -33,6 +31,9 @@ class ShareDialog;
class AbstractCredentials;
class QuotaInfo;
class SyncResult;
class LinkShare;
class Share;
class ShareManager;
/**
* @brief The ShareDialog class