2015-02-25 20:32:25 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
#include "sharedialog.h"
|
2015-11-05 11:58:16 +03:00
|
|
|
#include "sharelinkwidget.h"
|
|
|
|
#include "shareusergroupwidget.h"
|
2014-09-03 18:12:21 +04:00
|
|
|
#include "ui_sharedialog.h"
|
2015-11-05 11:58:16 +03:00
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
#include "account.h"
|
2016-02-22 12:38:10 +03:00
|
|
|
#include "accountstate.h"
|
2015-03-26 20:08:06 +03:00
|
|
|
#include "configfile.h"
|
2015-11-05 11:58:16 +03:00
|
|
|
#include "theme.h"
|
2015-09-07 14:50:01 +03:00
|
|
|
#include "thumbnailjob.h"
|
|
|
|
|
2015-08-20 14:40:10 +03:00
|
|
|
#include <QFileInfo>
|
2015-11-05 11:58:16 +03:00
|
|
|
#include <QFileIconProvider>
|
|
|
|
#include <QDebug>
|
2016-02-22 12:38:10 +03:00
|
|
|
#include <QPointer>
|
2015-11-05 11:58:16 +03:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QFrame>
|
2014-09-03 18:12:21 +04:00
|
|
|
|
2014-12-19 18:56:17 +03:00
|
|
|
namespace OCC {
|
2014-09-03 18:12:21 +04:00
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
ShareDialog::ShareDialog(QPointer<AccountState> accountState,
|
|
|
|
const QString &sharePath,
|
|
|
|
const QString &localPath,
|
|
|
|
SharePermissions maxSharingPermissions,
|
|
|
|
QWidget *parent) :
|
2015-11-05 11:58:16 +03:00
|
|
|
QDialog(parent),
|
2015-01-14 12:35:09 +03:00
|
|
|
_ui(new Ui::ShareDialog),
|
2016-02-22 12:38:10 +03:00
|
|
|
_accountState(accountState),
|
2015-01-16 16:48:56 +03:00
|
|
|
_sharePath(sharePath),
|
2015-02-06 18:24:08 +03:00
|
|
|
_localPath(localPath),
|
2016-03-30 12:33:34 +03:00
|
|
|
_maxSharingPermissions(maxSharingPermissions),
|
2015-11-05 11:58:16 +03:00
|
|
|
_linkWidget(NULL),
|
2016-03-30 12:33:34 +03:00
|
|
|
_userGroupWidget(NULL),
|
|
|
|
_progressIndicator(NULL)
|
2014-09-03 18:12:21 +04:00
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
2015-03-26 20:08:06 +03:00
|
|
|
setObjectName("SharingDialog"); // required as group for saveGeometry call
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
_ui->setupUi(this);
|
2015-08-20 14:40:10 +03:00
|
|
|
|
2015-02-25 15:41:44 +03:00
|
|
|
QPushButton *closeButton = _ui->buttonBox->button(QDialogButtonBox::Close);
|
2015-11-05 11:58:16 +03:00
|
|
|
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
|
2015-11-24 11:58:18 +03:00
|
|
|
|
2016-02-22 12:38:10 +03:00
|
|
|
// We want to act on account state changes
|
|
|
|
connect(_accountState, SIGNAL(stateChanged(int)), SLOT(slotAccountStateChanged(int)));
|
|
|
|
|
2015-11-24 11:58:18 +03:00
|
|
|
// Because people press enter in the dialog and we don't want to close for that
|
|
|
|
closeButton->setDefault(false);
|
|
|
|
closeButton->setAutoDefault(false);
|
2015-01-16 16:48:56 +03:00
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
// Set icon
|
2015-01-16 16:48:56 +03:00
|
|
|
QFileInfo f_info(_localPath);
|
|
|
|
QFileIconProvider icon_provider;
|
|
|
|
QIcon icon = icon_provider.icon(f_info);
|
|
|
|
_ui->label_icon->setPixmap(icon.pixmap(40,40));
|
2015-01-21 17:03:01 +03:00
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
// Set filename
|
2015-03-26 18:51:31 +03:00
|
|
|
QFileInfo lPath(_localPath);
|
|
|
|
QString fileName = lPath.fileName();
|
|
|
|
_ui->label_name->setText(tr("%1").arg(fileName));
|
|
|
|
QFont f( _ui->label_name->font());
|
|
|
|
f.setPointSize( f.pointSize() * 1.4 );
|
|
|
|
_ui->label_name->setFont( f );
|
2015-02-25 15:44:12 +03:00
|
|
|
|
2015-01-21 17:03:01 +03:00
|
|
|
_ui->label_sharePath->setWordWrap(true);
|
2015-03-26 18:51:31 +03:00
|
|
|
QString ocDir(_sharePath);
|
|
|
|
ocDir.truncate(ocDir.length()-fileName.length());
|
|
|
|
|
2015-09-04 16:15:26 +03:00
|
|
|
ocDir.replace(QRegExp("^/*"), "");
|
|
|
|
ocDir.replace(QRegExp("/*$"), "");
|
2015-11-24 14:30:53 +03:00
|
|
|
|
|
|
|
// Laying this out is complex because sharePath
|
|
|
|
// may be in use or not.
|
|
|
|
_ui->gridLayout->removeWidget(_ui->label_sharePath);
|
|
|
|
_ui->gridLayout->removeWidget(_ui->label_name);
|
2015-09-04 16:15:26 +03:00
|
|
|
if( ocDir.isEmpty() ) {
|
2015-11-24 14:30:53 +03:00
|
|
|
_ui->gridLayout->addWidget(_ui->label_name, 0, 1, 2, 1);
|
2015-03-26 20:08:06 +03:00
|
|
|
_ui->label_sharePath->setText(QString());
|
|
|
|
} else {
|
2015-11-24 14:30:53 +03:00
|
|
|
_ui->gridLayout->addWidget(_ui->label_name, 0, 1, 1, 1);
|
|
|
|
_ui->gridLayout->addWidget(_ui->label_sharePath, 1, 1, 1, 1);
|
2015-03-26 20:08:06 +03:00
|
|
|
_ui->label_sharePath->setText(tr("Folder: %2").arg(ocDir));
|
2015-01-21 17:03:01 +03:00
|
|
|
}
|
2015-02-25 15:44:12 +03:00
|
|
|
|
2015-01-21 17:03:01 +03:00
|
|
|
this->setWindowTitle(tr("%1 Sharing").arg(Theme::instance()->appNameGUI()));
|
|
|
|
|
2016-02-22 12:38:10 +03:00
|
|
|
if (!accountState->account()->capabilities().shareAPI()) {
|
2015-11-19 14:00:53 +03:00
|
|
|
_ui->shareWidgetsLayout->addWidget(new QLabel(tr("The server does not allow sharing")));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
if (QFileInfo(_localPath).isFile()) {
|
|
|
|
ThumbnailJob *job = new ThumbnailJob(_sharePath, _accountState->account(), this);
|
|
|
|
connect(job, SIGNAL(jobFinished(int, QByteArray)), SLOT(slotThumbnailFetched(int, QByteArray)));
|
|
|
|
job->start();
|
2015-07-10 16:46:17 +03:00
|
|
|
}
|
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
_progressIndicator = new QProgressIndicator(this);
|
|
|
|
_progressIndicator->startAnimation();
|
|
|
|
_progressIndicator->setToolTip(tr("Retrieving maximum possible sharing permissions from server..."));
|
|
|
|
_ui->shareWidgetsLayout->addWidget(_progressIndicator);
|
|
|
|
|
|
|
|
// Server versions >= 9.1 support the "share-permissions" property
|
|
|
|
// older versions will just return share-permissions: ""
|
|
|
|
auto job = new PropfindJob(accountState->account(), _sharePath);
|
2016-04-22 15:38:43 +03:00
|
|
|
job->setProperties(QList<QByteArray>() << "http://open-collaboration-services.org/ns:share-permissions");
|
2016-03-30 12:33:34 +03:00
|
|
|
job->setTimeout(10 * 1000);
|
|
|
|
connect(job, SIGNAL(result(QVariantMap)), SLOT(slotMaxSharingPermissionsReceived(QVariantMap)));
|
|
|
|
connect(job, SIGNAL(finishedWithError(QNetworkReply*)), SLOT(slotMaxSharingPermissionsError()));
|
|
|
|
job->start();
|
2014-09-09 03:50:31 +04:00
|
|
|
}
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
ShareDialog::~ShareDialog()
|
|
|
|
{
|
|
|
|
delete _ui;
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
void ShareDialog::done( int r ) {
|
|
|
|
ConfigFile cfg;
|
|
|
|
cfg.saveGeometry(this);
|
|
|
|
QDialog::done(r);
|
2014-09-09 03:50:31 +04:00
|
|
|
}
|
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
void ShareDialog::slotMaxSharingPermissionsReceived(const QVariantMap & result)
|
2014-09-03 18:12:21 +04:00
|
|
|
{
|
2016-03-30 12:33:34 +03:00
|
|
|
const QVariant receivedPermissions = result["share-permissions"];
|
|
|
|
if (!receivedPermissions.toString().isEmpty()) {
|
|
|
|
_maxSharingPermissions = static_cast<SharePermissions>(receivedPermissions.toInt());
|
|
|
|
qDebug() << "Received sharing permissions for" << _sharePath << _maxSharingPermissions;
|
2015-03-26 19:23:29 +03:00
|
|
|
}
|
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
showSharingUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::slotMaxSharingPermissionsError()
|
|
|
|
{
|
|
|
|
// On error show the share ui anyway. The user can still see shares,
|
|
|
|
// delete them and so on, even though adding new shares or granting
|
|
|
|
// some of the permissions might fail.
|
|
|
|
|
|
|
|
showSharingUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::showSharingUi()
|
|
|
|
{
|
|
|
|
_progressIndicator->stopAnimation();
|
|
|
|
|
|
|
|
auto theme = Theme::instance();
|
|
|
|
|
2016-04-14 11:03:15 +03:00
|
|
|
// There's no difference between being unable to reshare and
|
|
|
|
// being unable to reshare with reshare permission.
|
|
|
|
bool canReshare = _maxSharingPermissions & SharePermissionShare;
|
|
|
|
|
|
|
|
if (!canReshare) {
|
|
|
|
auto label = new QLabel(this);
|
|
|
|
label->setText(tr("The file can not be shared because it was shared without sharing permission."));
|
|
|
|
_ui->shareWidgetsLayout->addWidget(label);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-30 12:33:34 +03:00
|
|
|
// We only do user/group sharing from 8.2.0
|
|
|
|
bool userGroupSharing =
|
|
|
|
theme->userGroupSharing()
|
|
|
|
&& _accountState->account()->serverVersionInt() >= ((8 << 16) + (2 << 8));
|
|
|
|
|
|
|
|
bool autoShare = !userGroupSharing;
|
|
|
|
|
|
|
|
if (userGroupSharing) {
|
|
|
|
_userGroupWidget = new ShareUserGroupWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, this);
|
|
|
|
_ui->shareWidgetsLayout->addWidget(_userGroupWidget);
|
2015-11-05 11:58:16 +03:00
|
|
|
_userGroupWidget->getShares();
|
2015-03-09 16:33:02 +03:00
|
|
|
}
|
2016-03-30 12:33:34 +03:00
|
|
|
|
|
|
|
if (theme->linkSharing()) {
|
|
|
|
if (userGroupSharing) {
|
|
|
|
QFrame *hline = new QFrame(this);
|
|
|
|
hline->setFrameShape(QFrame::HLine);
|
|
|
|
QPalette p = palette();
|
|
|
|
// Make the line softer:
|
|
|
|
p.setColor(QPalette::Foreground, QColor::fromRgba((p.color(QPalette::Foreground).rgba() & 0x00ffffff) | 0x50000000));
|
|
|
|
hline->setPalette(p);
|
|
|
|
_ui->shareWidgetsLayout->addWidget(hline);
|
|
|
|
}
|
|
|
|
|
|
|
|
_linkWidget = new ShareLinkWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, autoShare, this);
|
|
|
|
_linkWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
|
|
|
_ui->shareWidgetsLayout->addWidget(_linkWidget);
|
|
|
|
_linkWidget->getShares();
|
|
|
|
}
|
2015-03-11 16:09:31 +03:00
|
|
|
}
|
|
|
|
|
2015-01-21 15:51:16 +03:00
|
|
|
void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply)
|
|
|
|
{
|
|
|
|
if (statusCode != 200) {
|
|
|
|
qDebug() << Q_FUNC_INFO << "Status code: " << statusCode;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap p;
|
|
|
|
p.loadFromData(reply, "PNG");
|
|
|
|
_ui->label_icon->setPixmap(p);
|
|
|
|
}
|
|
|
|
|
2016-02-22 12:38:10 +03:00
|
|
|
void ShareDialog::slotAccountStateChanged(int state) {
|
|
|
|
bool enabled = (state == AccountState::State::Connected);
|
|
|
|
qDebug() << Q_FUNC_INFO << enabled;
|
|
|
|
|
|
|
|
if (_userGroupWidget != NULL) {
|
|
|
|
_userGroupWidget->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_linkWidget != NULL) {
|
|
|
|
_linkWidget->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
2015-11-05 11:58:16 +03:00
|
|
|
|