2015-10-29 13:09:10 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Roeland Jago Douma <rullzer@owncloud.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; version 2 of the License.
|
|
|
|
*
|
|
|
|
* 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 SHARE_H
|
|
|
|
#define SHARE_H
|
|
|
|
|
|
|
|
#include "accountfwd.h"
|
2015-11-05 00:00:35 +03:00
|
|
|
#include "sharee.h"
|
2016-03-30 12:33:34 +03:00
|
|
|
#include "sharepermissions.h"
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QDate>
|
|
|
|
#include <QString>
|
|
|
|
#include <QList>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QUrl>
|
2015-11-04 21:28:54 +03:00
|
|
|
#include <QVariantMap>
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
namespace OCC {
|
|
|
|
|
|
|
|
class Share : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2015-10-29 23:47:47 +03:00
|
|
|
/**
|
|
|
|
* Possible share types
|
2015-11-19 12:50:21 +03:00
|
|
|
* Need to be in sync with Sharee::Type
|
2015-10-29 23:47:47 +03:00
|
|
|
*/
|
|
|
|
enum ShareType {
|
2015-11-19 12:50:21 +03:00
|
|
|
TypeUser = Sharee::User,
|
|
|
|
TypeGroup = Sharee::Group,
|
2015-10-29 23:47:47 +03:00
|
|
|
TypeLink = 3,
|
2015-11-19 12:50:21 +03:00
|
|
|
TypeRemote = Sharee::Federated
|
2015-10-29 23:47:47 +03:00
|
|
|
};
|
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
typedef SharePermissions Permissions;
|
2015-10-29 23:47:47 +03:00
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
/*
|
2015-10-29 15:48:53 +03:00
|
|
|
* Constructor for shares
|
2015-10-29 13:09:10 +03:00
|
|
|
*/
|
|
|
|
explicit Share(AccountPtr account,
|
|
|
|
const QString& id,
|
|
|
|
const QString& path,
|
2015-10-31 15:39:08 +03:00
|
|
|
const ShareType shareType,
|
2016-03-30 12:33:34 +03:00
|
|
|
const Permissions permissions = SharePermissionDefault,
|
2015-11-05 00:00:35 +03:00
|
|
|
const QSharedPointer<Sharee> shareWith = QSharedPointer<Sharee>(NULL));
|
2015-10-29 13:09:10 +03:00
|
|
|
|
2015-12-08 14:58:56 +03:00
|
|
|
/**
|
|
|
|
* The account the share is defined on.
|
|
|
|
*/
|
|
|
|
AccountPtr account() const;
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
/*
|
|
|
|
* Get the id
|
|
|
|
*/
|
2015-10-29 15:48:53 +03:00
|
|
|
QString getId() const;
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the shareType
|
|
|
|
*/
|
2015-10-29 23:47:47 +03:00
|
|
|
ShareType getShareType() const;
|
2015-10-29 13:09:10 +03:00
|
|
|
|
2015-10-31 15:39:08 +03:00
|
|
|
/*
|
|
|
|
* Get the shareWith
|
|
|
|
*/
|
2015-11-05 00:00:35 +03:00
|
|
|
QSharedPointer<Sharee> getShareWith() const;
|
2015-10-31 15:39:08 +03:00
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
/*
|
|
|
|
* Get permissions
|
|
|
|
*/
|
2015-10-29 23:47:47 +03:00
|
|
|
Permissions getPermissions() const;
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the permissions of a share
|
|
|
|
*
|
|
|
|
* On success the permissionsSet signal is emitted
|
|
|
|
* In case of a server error the serverError signal is emitted.
|
|
|
|
*/
|
2015-10-31 15:39:08 +03:00
|
|
|
void setPermissions(Permissions permissions);
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a share
|
|
|
|
*
|
|
|
|
* On success the shareDeleted signal is emitted
|
2015-10-29 15:39:29 +03:00
|
|
|
* In case of a server error the serverError signal is emitted.
|
2015-10-29 13:09:10 +03:00
|
|
|
*/
|
|
|
|
void deleteShare();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void permissionsSet();
|
|
|
|
void shareDeleted();
|
|
|
|
void serverError(int code, const QString &message);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
AccountPtr _account;
|
|
|
|
QString _id;
|
|
|
|
QString _path;
|
2015-10-29 23:47:47 +03:00
|
|
|
ShareType _shareType;
|
|
|
|
Permissions _permissions;
|
2015-11-05 00:00:35 +03:00
|
|
|
QSharedPointer<Sharee> _shareWith;
|
2015-10-29 13:09:10 +03:00
|
|
|
|
2015-10-29 18:56:23 +03:00
|
|
|
protected slots:
|
|
|
|
void slotOcsError(int statusCode, const QString &message);
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
private slots:
|
2015-10-29 18:56:23 +03:00
|
|
|
void slotDeleted();
|
2015-10-31 15:39:08 +03:00
|
|
|
void slotPermissionsSet(const QVariantMap &, const QVariant &value);
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Link share is just like a regular share but then slightly different.
|
|
|
|
* There are several methods in the API that either work differently for
|
|
|
|
* link shares or are only available to link shares.
|
|
|
|
*/
|
|
|
|
class LinkShare : public Share {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
|
|
|
|
explicit LinkShare(AccountPtr account,
|
|
|
|
const QString& id,
|
|
|
|
const QString& path,
|
2015-10-31 15:39:08 +03:00
|
|
|
const Permissions permissions,
|
2015-10-29 13:09:10 +03:00
|
|
|
bool passwordSet,
|
|
|
|
const QUrl& url,
|
2015-10-29 16:27:49 +03:00
|
|
|
const QDate& expireDate);
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the share link
|
|
|
|
*/
|
2015-10-29 15:48:53 +03:00
|
|
|
QUrl getLink() const;
|
2015-10-29 13:09:10 +03:00
|
|
|
|
2015-10-29 13:47:14 +03:00
|
|
|
/*
|
|
|
|
* Get the publicUpload status of this share
|
|
|
|
*/
|
|
|
|
bool getPublicUpload();
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
/*
|
|
|
|
* Set a share to be public upload
|
|
|
|
* This function can only be called on link shares
|
|
|
|
*
|
|
|
|
* On success the publicUploadSet signal is emitted
|
|
|
|
* In case of a server error the serverError signal is emitted.
|
|
|
|
*/
|
|
|
|
void setPublicUpload(bool publicUpload);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the password
|
|
|
|
*
|
|
|
|
* On success the passwordSet signal is emitted
|
|
|
|
* In case of a server error the serverError signal is emitted.
|
|
|
|
*/
|
|
|
|
void setPassword(const QString& password);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is the password set?
|
|
|
|
*/
|
2015-10-29 15:48:53 +03:00
|
|
|
bool isPasswordSet() const;
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the expiration date
|
|
|
|
*/
|
2015-10-29 15:48:53 +03:00
|
|
|
QDate getExpireDate() const;
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the expiration date
|
|
|
|
*
|
|
|
|
* On success the expireDateSet signal is emitted
|
|
|
|
* In case of a server error the serverError signal is emitted.
|
|
|
|
*/
|
|
|
|
void setExpireDate(const QDate& expireDate);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void expireDateSet();
|
|
|
|
void publicUploadSet();
|
|
|
|
void passwordSet();
|
2016-01-22 13:56:05 +03:00
|
|
|
void passwordSetError(int statusCode, const QString &message);
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
private slots:
|
2015-10-29 18:56:23 +03:00
|
|
|
void slotPasswordSet(const QVariantMap&, const QVariant &value);
|
|
|
|
void slotPublicUploadSet(const QVariantMap&, const QVariant &value);
|
2016-04-19 12:22:32 +03:00
|
|
|
void slotExpireDateSet(const QVariantMap& reply, const QVariant &value);
|
2016-01-22 13:56:05 +03:00
|
|
|
void slotSetPasswordError(int statusCode, const QString &message);
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool _passwordSet;
|
|
|
|
QDate _expireDate;
|
|
|
|
QUrl _url;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The share manager allows for creating, retrieving and deletion
|
|
|
|
* of shares. It abstracts away from the OCS Share API, all the usages
|
|
|
|
* shares should talk to this manager and not use OCS Share Job directly
|
|
|
|
*/
|
|
|
|
class ShareManager : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit ShareManager(AccountPtr _account, QObject *parent = NULL);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tell the manager to create a link share
|
|
|
|
*
|
|
|
|
* @param path The path of the linkshare relative to the user folder on the server
|
|
|
|
* @param password The password of the share
|
|
|
|
*
|
|
|
|
* On success the signal linkShareCreated is emitted
|
|
|
|
* For older server the linkShareRequiresPassword signal is emitted when it seems appropiate
|
|
|
|
* In case of a server error the serverError signal is emitted
|
|
|
|
*/
|
|
|
|
void createLinkShare(const QString& path,
|
|
|
|
const QString& password="");
|
|
|
|
|
2015-10-31 15:39:08 +03:00
|
|
|
/**
|
|
|
|
* Tell the manager to create a new share
|
|
|
|
*
|
|
|
|
* @param path The path of the share relative to the user folder on the server
|
|
|
|
* @param shareType The type of share (TypeUser, TypeGroup, TypeRemote)
|
|
|
|
* @param Permissions The share permissions
|
|
|
|
*
|
|
|
|
* On success the signal shareCreated is emitted
|
|
|
|
* In case of a server error the serverError signal is emitted
|
|
|
|
*/
|
|
|
|
void createShare(const QString& path,
|
|
|
|
const Share::ShareType shareType,
|
|
|
|
const QString shareWith,
|
|
|
|
const Share::Permissions permissions);
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
/**
|
|
|
|
* Fetch all the shares for path
|
|
|
|
*
|
|
|
|
* @param path The path to get the shares for relative to the users folder on the server
|
|
|
|
*
|
|
|
|
* On success the sharesFetched signal is emitted
|
|
|
|
* In case of a server error the serverError signal is emitted
|
|
|
|
*/
|
|
|
|
void fetchShares(const QString& path);
|
|
|
|
|
|
|
|
signals:
|
2015-10-31 15:39:08 +03:00
|
|
|
void shareCreated(const QSharedPointer<Share> &share);
|
2015-10-29 16:27:49 +03:00
|
|
|
void linkShareCreated(const QSharedPointer<LinkShare> &share);
|
|
|
|
void sharesFetched(const QList<QSharedPointer<Share>> &shares);
|
2015-10-29 13:09:10 +03:00
|
|
|
void serverError(int code, const QString &message);
|
|
|
|
|
2016-01-19 16:03:13 +03:00
|
|
|
/** Emitted when creating a link share with password fails.
|
|
|
|
*
|
|
|
|
* @param message the error message reported by the server
|
|
|
|
*
|
|
|
|
* See createLinkShare().
|
|
|
|
*/
|
|
|
|
void linkShareRequiresPassword(const QString &message);
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
private slots:
|
|
|
|
void slotSharesFetched(const QVariantMap &reply);
|
|
|
|
void slotLinkShareCreated(const QVariantMap &reply);
|
2015-10-31 15:39:08 +03:00
|
|
|
void slotShareCreated(const QVariantMap &reply);
|
2015-10-29 18:56:23 +03:00
|
|
|
void slotOcsError(int statusCode, const QString &message);
|
2016-01-21 16:10:37 +03:00
|
|
|
void slotCreateShare(const QVariantMap &reply);
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
private:
|
2015-10-29 16:27:49 +03:00
|
|
|
QSharedPointer<LinkShare> parseLinkShare(const QVariantMap &data);
|
2015-10-31 15:39:08 +03:00
|
|
|
QSharedPointer<Share> parseShare(const QVariantMap &data);
|
2015-10-29 13:09:10 +03:00
|
|
|
|
2016-01-21 16:10:37 +03:00
|
|
|
QMap<QObject*, QVariant> _jobContinuation;
|
2015-10-29 13:09:10 +03:00
|
|
|
AccountPtr _account;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SHARE_H
|