2015-02-25 20:32:25 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
|
2015-02-25 19:00:27 +03:00
|
|
|
* Copyright (C) 2015 by Klaas Freitag <freitag@owncloud.com>
|
2015-02-25 20:32:25 +03:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
#include "ui_sharedialog.h"
|
|
|
|
#include "account.h"
|
|
|
|
#include "json.h"
|
|
|
|
#include "folderman.h"
|
2015-01-21 17:03:01 +03:00
|
|
|
#include "folder.h"
|
2015-04-09 17:19:17 +03:00
|
|
|
#include "accountmanager.h"
|
2015-01-21 17:03:01 +03:00
|
|
|
#include "theme.h"
|
2015-03-26 20:08:06 +03:00
|
|
|
#include "configfile.h"
|
2015-07-16 22:49:12 +03:00
|
|
|
#include "capabilities.h"
|
2015-01-21 17:03:01 +03:00
|
|
|
|
2015-09-07 14:50:01 +03:00
|
|
|
#include "thumbnailjob.h"
|
2015-10-29 13:09:10 +03:00
|
|
|
#include "share.h"
|
2015-09-07 14:50:01 +03:00
|
|
|
|
2015-01-14 20:42:56 +03:00
|
|
|
#include "QProgressIndicator.h"
|
2014-09-03 18:12:21 +04:00
|
|
|
#include <QBuffer>
|
2015-01-16 16:48:56 +03:00
|
|
|
#include <QFileIconProvider>
|
2015-02-03 15:02:52 +03:00
|
|
|
#include <QClipboard>
|
2015-08-20 14:40:10 +03:00
|
|
|
#include <QFileInfo>
|
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
|
|
|
|
2015-03-11 16:09:31 +03:00
|
|
|
ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QString &localPath, bool resharingAllowed, QWidget *parent) :
|
2015-01-14 12:35:09 +03:00
|
|
|
QDialog(parent),
|
|
|
|
_ui(new Ui::ShareDialog),
|
2015-01-28 12:52:55 +03:00
|
|
|
_account(account),
|
2015-01-16 16:48:56 +03:00
|
|
|
_sharePath(sharePath),
|
2015-02-06 18:24:08 +03:00
|
|
|
_localPath(localPath),
|
2015-02-25 15:44:12 +03:00
|
|
|
_passwordJobRunning(false),
|
2015-10-29 13:09:10 +03:00
|
|
|
_manager(NULL),
|
|
|
|
_share(NULL),
|
2015-03-11 16:09:31 +03:00
|
|
|
_resharingAllowed(resharingAllowed)
|
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
|
|
|
|
|
|
|
//Is this a file or folder?
|
|
|
|
_isFile = QFileInfo(localPath).isFile();
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
_ui->pushButton_copy->setIcon(QIcon::fromTheme("edit-copy"));
|
2015-03-09 16:33:02 +03:00
|
|
|
_ui->pushButton_copy->setEnabled(false);
|
2015-02-03 15:02:52 +03:00
|
|
|
connect(_ui->pushButton_copy, SIGNAL(clicked(bool)), SLOT(slotPushButtonCopyLinkPressed()));
|
2014-09-03 18:12:21 +04:00
|
|
|
|
2015-02-25 15:41:44 +03:00
|
|
|
QPushButton *closeButton = _ui->buttonBox->button(QDialogButtonBox::Close);
|
|
|
|
if( closeButton ) {
|
|
|
|
connect( closeButton, SIGNAL(clicked()), this, SLOT(close()) );
|
|
|
|
}
|
|
|
|
|
2015-01-21 17:03:01 +03:00
|
|
|
// the following progress indicator widgets are added to layouts which makes them
|
|
|
|
// automatically deleted once the dialog dies.
|
|
|
|
_pi_link = new QProgressIndicator();
|
2015-01-14 20:42:56 +03:00
|
|
|
_pi_password = new QProgressIndicator();
|
2015-01-21 17:03:01 +03:00
|
|
|
_pi_date = new QProgressIndicator();
|
2015-08-20 14:40:10 +03:00
|
|
|
_pi_editing = new QProgressIndicator();
|
2015-01-17 10:10:18 +03:00
|
|
|
_ui->horizontalLayout_shareLink->addWidget(_pi_link);
|
|
|
|
_ui->horizontalLayout_password->addWidget(_pi_password);
|
2015-08-20 14:40:10 +03:00
|
|
|
_ui->horizontalLayout_editing->addWidget(_pi_editing);
|
2015-03-09 16:33:02 +03:00
|
|
|
// _ui->horizontalLayout_expire->addWidget(_pi_date);
|
2014-09-03 18:12:21 +04:00
|
|
|
|
|
|
|
connect(_ui->checkBox_shareLink, SIGNAL(clicked()), this, SLOT(slotCheckBoxShareLinkClicked()));
|
|
|
|
connect(_ui->checkBox_password, SIGNAL(clicked()), this, SLOT(slotCheckBoxPasswordClicked()));
|
|
|
|
connect(_ui->lineEdit_password, SIGNAL(returnPressed()), this, SLOT(slotPasswordReturnPressed()));
|
2015-03-11 16:57:55 +03:00
|
|
|
connect(_ui->lineEdit_password, SIGNAL(textChanged(QString)), this, SLOT(slotPasswordChanged(QString)));
|
2015-02-12 00:14:34 +03:00
|
|
|
connect(_ui->pushButton_setPassword, SIGNAL(clicked(bool)), SLOT(slotPasswordReturnPressed()));
|
2014-09-03 18:12:21 +04:00
|
|
|
connect(_ui->checkBox_expire, SIGNAL(clicked()), this, SLOT(slotCheckBoxExpireClicked()));
|
2015-03-11 17:46:05 +03:00
|
|
|
connect(_ui->calendar, SIGNAL(dateChanged(QDate)), SLOT(slotCalendarClicked(QDate)));
|
2015-08-20 14:40:10 +03:00
|
|
|
connect(_ui->checkBox_editing, SIGNAL(clicked()), this, SLOT(slotCheckBoxEditingClicked()));
|
2014-09-03 18:12:21 +04:00
|
|
|
|
2015-07-08 23:39:09 +03:00
|
|
|
//Disable checkbox
|
|
|
|
_ui->checkBox_shareLink->setEnabled(false);
|
|
|
|
_pi_link->startAnimation();
|
|
|
|
|
2015-03-11 16:57:55 +03:00
|
|
|
_ui->pushButton_setPassword->setEnabled(false);
|
2015-01-17 10:10:18 +03:00
|
|
|
_ui->widget_shareLink->hide();
|
2014-09-03 18:12:21 +04:00
|
|
|
_ui->lineEdit_password->hide();
|
2015-02-25 15:44:12 +03:00
|
|
|
_ui->pushButton_setPassword->hide();
|
2015-03-09 16:33:02 +03:00
|
|
|
|
|
|
|
_ui->calendar->setEnabled(false);
|
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-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("/*$"), "");
|
|
|
|
if( ocDir.isEmpty() ) {
|
2015-03-26 20:08:06 +03:00
|
|
|
_ui->label_sharePath->setText(QString());
|
|
|
|
} else {
|
|
|
|
_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()));
|
2015-03-26 20:08:06 +03:00
|
|
|
_ui->checkBox_password->setText(tr("P&assword protect"));
|
2015-01-21 17:03:01 +03:00
|
|
|
// check if the file is already inside of a synced folder
|
|
|
|
if( sharePath.isEmpty() ) {
|
2015-01-29 20:09:46 +03:00
|
|
|
// The file is not yet in an ownCloud synced folder. We could automatically
|
2015-10-05 07:21:19 +03:00
|
|
|
// copy it over, but that is skipped as not all questions can be answered that
|
2015-01-29 20:09:46 +03:00
|
|
|
// are involved in that, see https://github.com/owncloud/client/issues/2732
|
|
|
|
//
|
|
|
|
// _ui->checkBox_shareLink->setEnabled(false);
|
|
|
|
// uploadExternalFile();
|
|
|
|
qDebug() << Q_FUNC_INFO << "Unable to share files not in a sync folder.";
|
|
|
|
return;
|
2015-01-16 16:48:56 +03:00
|
|
|
}
|
2015-01-21 17:03:01 +03:00
|
|
|
|
|
|
|
// error label, red box and stuff
|
|
|
|
_ui->errorLabel->setLineWidth(1);
|
|
|
|
_ui->errorLabel->setFrameStyle(QFrame::Plain);
|
|
|
|
|
|
|
|
QPalette errPalette = _ui->errorLabel->palette();
|
|
|
|
errPalette.setColor(QPalette::Active, QPalette::Base, QColor(0xaa, 0x4d, 0x4d));
|
|
|
|
errPalette.setColor(QPalette::Active, QPalette::WindowText, QColor(0xaa, 0xaa, 0xaa));
|
|
|
|
|
|
|
|
_ui->errorLabel->setPalette(errPalette);
|
|
|
|
_ui->errorLabel->setFrameShape(QFrame::Box);
|
|
|
|
_ui->errorLabel->setContentsMargins(QMargins(12,12,12,12));
|
2015-01-23 11:10:02 +03:00
|
|
|
_ui->errorLabel->hide();
|
2015-07-10 16:46:17 +03:00
|
|
|
|
|
|
|
|
|
|
|
// Parse capabilities
|
|
|
|
|
2015-10-05 07:21:19 +03:00
|
|
|
// If password is enforced then don't allow users to disable it
|
2015-10-06 10:07:45 +03:00
|
|
|
if (_account->capabilities().sharePublicLinkEnforcePassword()) {
|
2015-07-10 16:46:17 +03:00
|
|
|
_ui->checkBox_password->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If expiredate is enforced do not allow disable and set max days
|
2015-10-06 10:07:45 +03:00
|
|
|
if (_account->capabilities().sharePublicLinkEnforceExpireDate()) {
|
2015-07-10 16:46:17 +03:00
|
|
|
_ui->checkBox_expire->setEnabled(false);
|
|
|
|
_ui->calendar->setMaximumDate(QDate::currentDate().addDays(
|
2015-10-06 10:07:45 +03:00
|
|
|
_account->capabilities().sharePublicLinkExpireDateDays()
|
2015-07-10 16:46:17 +03:00
|
|
|
));
|
|
|
|
}
|
2015-08-20 14:40:10 +03:00
|
|
|
|
|
|
|
// File can't have public upload set.
|
|
|
|
if (_isFile) {
|
|
|
|
_ui->checkBox_editing->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
if (!_account->capabilities().sharePublicLinkAllowUpload()) {
|
|
|
|
_ui->checkBox_editing->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the share manager and connect it properly
|
|
|
|
*/
|
2015-10-29 16:27:49 +03:00
|
|
|
_manager = new ShareManager(_account, this);
|
2015-10-29 13:09:10 +03:00
|
|
|
|
2015-10-29 18:56:23 +03:00
|
|
|
connect(_manager, SIGNAL(sharesFetched(QList<QSharedPointer<Share>>)), SLOT(slotSharesFetched(QList<QSharedPointer<Share>>)));
|
|
|
|
connect(_manager, SIGNAL(linkShareCreated(QSharedPointer<LinkShare>)), SLOT(slotCreateShareFetched(const QSharedPointer<LinkShare>)));
|
|
|
|
connect(_manager, SIGNAL(linkShareRequiresPassword()), SLOT(slotCreateShareRequiresPassword()));
|
|
|
|
connect(_manager, SIGNAL(serverError(int, QString)), SLOT(displayError(int, QString)));
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
|
2015-03-26 20:08:06 +03:00
|
|
|
void ShareDialog::done( int r ) {
|
|
|
|
ConfigFile cfg;
|
|
|
|
cfg.saveGeometry(this);
|
|
|
|
QDialog::done(r);
|
|
|
|
}
|
|
|
|
|
2015-01-17 11:57:17 +03:00
|
|
|
void ShareDialog::setExpireDate(const QDate &date)
|
2014-09-09 03:50:31 +04:00
|
|
|
{
|
2015-01-14 20:42:56 +03:00
|
|
|
_pi_date->startAnimation();
|
2015-10-29 13:09:10 +03:00
|
|
|
_share->setExpireDate(date);
|
2014-09-09 03:50:31 +04:00
|
|
|
}
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
void ShareDialog::slotExpireSet()
|
2014-09-09 03:50:31 +04:00
|
|
|
{
|
2015-01-14 20:42:56 +03:00
|
|
|
_pi_date->stopAnimation();
|
2014-09-09 03:50:31 +04:00
|
|
|
}
|
|
|
|
|
2015-01-11 13:19:12 +03:00
|
|
|
void ShareDialog::slotCalendarClicked(const QDate &date)
|
2014-09-09 03:50:31 +04:00
|
|
|
{
|
2015-02-06 18:24:08 +03:00
|
|
|
setExpireDate(date);
|
2014-09-09 03:50:31 +04:00
|
|
|
}
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
ShareDialog::~ShareDialog()
|
|
|
|
{
|
|
|
|
delete _ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::slotPasswordReturnPressed()
|
2014-09-09 03:50:31 +04:00
|
|
|
{
|
2015-02-06 18:24:08 +03:00
|
|
|
setPassword(_ui->lineEdit_password->text());
|
2015-01-11 15:27:32 +03:00
|
|
|
_ui->lineEdit_password->setText(QString());
|
2015-01-14 21:08:04 +03:00
|
|
|
_ui->lineEdit_password->setPlaceholderText(tr("Password Protected"));
|
|
|
|
_ui->lineEdit_password->clearFocus();
|
2014-09-09 03:50:31 +04:00
|
|
|
}
|
|
|
|
|
2015-03-11 16:57:55 +03:00
|
|
|
void ShareDialog::slotPasswordChanged(const QString& newText)
|
|
|
|
{
|
2015-10-05 07:21:19 +03:00
|
|
|
// disable the set-password button
|
2015-03-11 16:57:55 +03:00
|
|
|
_ui->pushButton_setPassword->setEnabled( newText.length() > 0 );
|
|
|
|
}
|
|
|
|
|
2015-01-14 21:36:42 +03:00
|
|
|
void ShareDialog::setPassword(const QString &password)
|
2014-09-03 18:12:21 +04:00
|
|
|
{
|
2015-08-12 19:22:51 +03:00
|
|
|
_pi_link->startAnimation();
|
2015-01-14 20:42:56 +03:00
|
|
|
_pi_password->startAnimation();
|
2015-10-29 15:31:36 +03:00
|
|
|
|
|
|
|
_ui->checkBox_password->setEnabled(false);
|
|
|
|
_ui->lineEdit_password->setEnabled(false);
|
2015-02-06 18:24:08 +03:00
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
if( !_share.isNull() ) {
|
|
|
|
_share->setPassword(password);
|
2015-02-06 18:24:08 +03:00
|
|
|
} else {
|
2015-10-29 15:31:36 +03:00
|
|
|
_ui->checkBox_shareLink->setEnabled(false);
|
2015-10-29 13:09:10 +03:00
|
|
|
_manager->createLinkShare(_sharePath, password);
|
2015-07-16 21:55:54 +03:00
|
|
|
}
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
void ShareDialog::slotPasswordSet()
|
2014-09-09 03:50:31 +04:00
|
|
|
{
|
2015-02-25 15:44:12 +03:00
|
|
|
/*
|
2015-10-29 13:09:10 +03:00
|
|
|
* When setting/deleting a password from a share the old share is
|
|
|
|
* deleted and a new one is created. So we need to refetch the shares
|
|
|
|
* at this point.
|
|
|
|
*/
|
2015-02-25 15:44:12 +03:00
|
|
|
getShares();
|
2015-01-14 21:47:25 +03:00
|
|
|
|
2015-01-14 20:42:56 +03:00
|
|
|
_pi_password->stopAnimation();
|
2014-09-09 03:50:31 +04:00
|
|
|
}
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
void ShareDialog::getShares()
|
|
|
|
{
|
2015-10-29 13:09:10 +03:00
|
|
|
_manager->fetchShares(_sharePath);
|
2015-07-09 10:19:04 +03:00
|
|
|
|
|
|
|
if (QFileInfo(_localPath).isFile()) {
|
|
|
|
ThumbnailJob *job2 = new ThumbnailJob(_sharePath, _account, this);
|
|
|
|
connect(job2, SIGNAL(jobFinished(int, QByteArray)), SLOT(slotThumbnailFetched(int, QByteArray)));
|
|
|
|
job2->start();
|
|
|
|
}
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
void ShareDialog::slotSharesFetched(const QList<QSharedPointer<Share>> &shares)
|
2014-09-03 18:12:21 +04:00
|
|
|
{
|
2015-04-17 18:56:17 +03:00
|
|
|
const QString versionString = _account->serverVersion();
|
2015-10-29 13:09:10 +03:00
|
|
|
qDebug() << Q_FUNC_INFO << versionString << "Fetched" << shares.count() << "shares";
|
2015-08-12 19:22:51 +03:00
|
|
|
|
2015-07-08 23:39:09 +03:00
|
|
|
//Show link checkbox now
|
|
|
|
_ui->checkBox_shareLink->setEnabled(true);
|
|
|
|
_pi_link->stopAnimation();
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
Q_FOREACH(auto share, shares) {
|
2014-09-03 18:12:21 +04:00
|
|
|
|
2015-10-29 23:47:47 +03:00
|
|
|
if (share->getShareType() == Share::TypeLink) {
|
2015-10-29 13:09:10 +03:00
|
|
|
_share = qSharedPointerDynamicCast<LinkShare>(share);
|
2015-05-08 15:53:38 +03:00
|
|
|
_ui->pushButton_copy->show();
|
2014-09-03 18:12:21 +04:00
|
|
|
|
2015-01-17 10:10:18 +03:00
|
|
|
_ui->widget_shareLink->show();
|
2014-09-03 18:12:21 +04:00
|
|
|
_ui->checkBox_shareLink->setChecked(true);
|
|
|
|
|
2015-10-29 15:31:36 +03:00
|
|
|
_ui->checkBox_password->setEnabled(true);
|
2015-10-29 13:09:10 +03:00
|
|
|
if (_share->isPasswordSet()) {
|
2015-10-29 15:31:36 +03:00
|
|
|
_ui->lineEdit_password->setEnabled(true);
|
2014-09-03 18:12:21 +04:00
|
|
|
_ui->checkBox_password->setChecked(true);
|
2015-01-14 21:08:04 +03:00
|
|
|
_ui->lineEdit_password->setPlaceholderText("********");
|
2014-09-03 18:12:21 +04:00
|
|
|
_ui->lineEdit_password->show();
|
2015-02-25 15:44:12 +03:00
|
|
|
_ui->pushButton_setPassword->show();
|
|
|
|
} else {
|
|
|
|
_ui->checkBox_password->setChecked(false);
|
|
|
|
// _ui->lineEdit_password->setPlaceholderText("********");
|
|
|
|
_ui->lineEdit_password->hide();
|
|
|
|
_ui->pushButton_setPassword->hide();
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
|
2015-10-29 15:31:36 +03:00
|
|
|
_ui->checkBox_expire->setEnabled(true);
|
2015-10-29 13:09:10 +03:00
|
|
|
if (_share->getExpireDate().isValid()) {
|
|
|
|
_ui->calendar->setDate(_share->getExpireDate());
|
2015-01-17 11:10:42 +03:00
|
|
|
_ui->calendar->setMinimumDate(QDate::currentDate().addDays(1));
|
2015-03-09 16:33:02 +03:00
|
|
|
_ui->calendar->setEnabled(true);
|
2014-09-09 03:50:31 +04:00
|
|
|
_ui->checkBox_expire->setChecked(true);
|
2015-02-25 15:44:12 +03:00
|
|
|
} else {
|
2015-03-09 16:33:02 +03:00
|
|
|
_ui->calendar->setEnabled(false);
|
2015-02-25 15:44:12 +03:00
|
|
|
_ui->checkBox_expire->setChecked(false);
|
2014-09-09 03:50:31 +04:00
|
|
|
}
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
/*
|
|
|
|
* Only directories can have public upload set
|
|
|
|
* For public links the server sets CREATE and UPDATE permissions.
|
|
|
|
*/
|
2015-10-29 15:31:36 +03:00
|
|
|
if (!_isFile) {
|
|
|
|
_ui->checkBox_editing->setEnabled(true);
|
|
|
|
if (_share->getPublicUpload()) {
|
|
|
|
_ui->checkBox_editing->setChecked(true);
|
|
|
|
} else {
|
|
|
|
_ui->checkBox_editing->setChecked(false);
|
|
|
|
}
|
2015-02-12 19:04:03 +03:00
|
|
|
}
|
2015-03-09 16:33:02 +03:00
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
setShareLink(_share->getLink().toString());
|
2015-03-09 16:33:02 +03:00
|
|
|
_ui->pushButton_copy->setEnabled(true);
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
// Connect all shares signals to gui slots
|
2015-10-29 18:56:23 +03:00
|
|
|
connect(_share.data(), SIGNAL(expireDateSet()), SLOT(slotExpireSet()));
|
|
|
|
connect(_share.data(), SIGNAL(publicUploadSet()), SLOT(slotPublicUploadSet()));
|
|
|
|
connect(_share.data(), SIGNAL(passwordSet()), SLOT(slotPasswordSet()));
|
|
|
|
connect(_share.data(), SIGNAL(shareDeleted()), SLOT(slotDeleteShareFetched()));
|
|
|
|
connect(_share.data(), SIGNAL(serverError(int, QString)), SLOT(displayError(int, QString)));
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
break;
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
}
|
2015-10-29 13:09:10 +03:00
|
|
|
if( !_share.isNull() ) {
|
2015-03-09 16:33:02 +03:00
|
|
|
setShareCheckBoxTitle(true);
|
|
|
|
} else {
|
2015-03-11 16:09:31 +03:00
|
|
|
// If there are no shares yet, check the checkbox to create a link automatically.
|
|
|
|
// If its clear that resharing is not allowed, display an error
|
|
|
|
if( !_resharingAllowed ) {
|
|
|
|
displayError(tr("The file can not be shared because it was shared without sharing permission."));
|
|
|
|
_ui->checkBox_shareLink->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
_ui->checkBox_shareLink->setChecked(true);
|
|
|
|
slotCheckBoxShareLinkClicked();
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 19:23:29 +03:00
|
|
|
void ShareDialog::resizeEvent(QResizeEvent *e)
|
2015-03-09 16:33:02 +03:00
|
|
|
{
|
2015-03-26 19:23:29 +03:00
|
|
|
QDialog::resizeEvent(e);
|
|
|
|
redrawElidedUrl();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::redrawElidedUrl()
|
|
|
|
{
|
|
|
|
QString u;
|
|
|
|
|
|
|
|
if( !_shareUrl.isEmpty() ) {
|
2015-03-26 18:51:31 +03:00
|
|
|
QFontMetrics fm( _ui->_labelShareLink->font() );
|
|
|
|
int linkLengthPixel = _ui->_labelShareLink->width();
|
|
|
|
|
2015-03-26 19:23:29 +03:00
|
|
|
const QUrl realUrl(_shareUrl);
|
|
|
|
QString elidedUrl = fm.elidedText(_shareUrl, Qt::ElideRight, linkLengthPixel);
|
2015-03-26 18:51:31 +03:00
|
|
|
|
2015-03-26 19:23:29 +03:00
|
|
|
u = QString("<a href=\"%1\">%2</a>").arg(realUrl.toString(QUrl::None)).arg(elidedUrl);
|
|
|
|
}
|
|
|
|
_ui->_labelShareLink->setText(u);
|
|
|
|
}
|
|
|
|
|
2015-03-09 16:33:02 +03:00
|
|
|
void ShareDialog::setShareLink( const QString& url )
|
|
|
|
{
|
|
|
|
// FIXME: shorten the url for output.
|
|
|
|
const QUrl realUrl(url);
|
|
|
|
if( realUrl.isValid() ) {
|
|
|
|
_shareUrl = url;
|
|
|
|
_ui->pushButton_copy->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
_shareUrl.clear();
|
|
|
|
_ui->_labelShareLink->setText(QString::null);
|
|
|
|
}
|
2015-03-26 19:23:29 +03:00
|
|
|
redrawElidedUrl();
|
2015-03-09 16:33:02 +03:00
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
void ShareDialog::slotDeleteShareFetched()
|
2014-09-03 18:12:21 +04:00
|
|
|
{
|
2015-10-29 13:09:10 +03:00
|
|
|
_share.clear();
|
2015-01-14 20:42:56 +03:00
|
|
|
_pi_link->stopAnimation();
|
2015-02-06 18:24:08 +03:00
|
|
|
_ui->lineEdit_password->clear();
|
2015-03-09 16:33:02 +03:00
|
|
|
_ui->_labelShareLink->clear();
|
|
|
|
_ui->pushButton_copy->setEnabled(false);
|
2015-01-17 10:10:18 +03:00
|
|
|
_ui->widget_shareLink->hide();
|
2014-09-03 18:12:21 +04:00
|
|
|
_ui->lineEdit_password->hide();
|
2015-03-11 16:57:55 +03:00
|
|
|
_ui->pushButton_setPassword->setEnabled(false);
|
2015-02-25 15:44:12 +03:00
|
|
|
_ui->pushButton_setPassword->hide();
|
2015-02-06 18:24:08 +03:00
|
|
|
_ui->checkBox_expire->setChecked(false);
|
2015-03-09 16:33:02 +03:00
|
|
|
_ui->checkBox_password->setChecked(false);
|
|
|
|
_ui->calendar->setEnabled(false);
|
|
|
|
|
|
|
|
_shareUrl.clear();
|
2015-02-25 15:44:12 +03:00
|
|
|
|
|
|
|
setShareCheckBoxTitle(false);
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::slotCheckBoxShareLinkClicked()
|
|
|
|
{
|
2015-08-12 19:22:51 +03:00
|
|
|
qDebug() << Q_FUNC_INFO <<( _ui->checkBox_shareLink->checkState() == Qt::Checked);
|
2015-02-25 15:44:12 +03:00
|
|
|
if (_ui->checkBox_shareLink->checkState() == Qt::Checked) {
|
2015-01-14 20:42:56 +03:00
|
|
|
_pi_link->startAnimation();
|
2015-07-10 16:26:26 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the capabilities if the server requires a password for a share
|
|
|
|
* Ask for it directly
|
|
|
|
*/
|
2015-10-06 10:07:45 +03:00
|
|
|
if (_account->capabilities().sharePublicLinkEnforcePassword()) {
|
2015-08-12 19:22:51 +03:00
|
|
|
_pi_link->stopAnimation();
|
2015-07-16 21:55:54 +03:00
|
|
|
_ui->checkBox_password->setChecked(true);
|
|
|
|
_ui->checkBox_password->setEnabled(false);
|
|
|
|
_ui->checkBox_password->setText(tr("Public shå requires a password"));
|
2015-10-29 15:31:36 +03:00
|
|
|
_ui->checkBox_expire->setEnabled(false);
|
|
|
|
_ui->checkBox_editing->setEnabled(false);
|
2015-07-16 21:55:54 +03:00
|
|
|
_ui->lineEdit_password->setFocus();
|
|
|
|
_ui->pushButton_copy->hide();
|
|
|
|
_ui->widget_shareLink->show();
|
|
|
|
|
|
|
|
slotCheckBoxPasswordClicked();
|
|
|
|
return;
|
2015-07-10 16:26:26 +03:00
|
|
|
}
|
|
|
|
|
2015-10-29 15:31:36 +03:00
|
|
|
_ui->checkBox_shareLink->setEnabled(false);
|
2015-10-29 13:09:10 +03:00
|
|
|
_manager->createLinkShare(_sharePath);
|
2015-02-25 15:44:12 +03:00
|
|
|
} else {
|
2015-10-29 15:31:36 +03:00
|
|
|
|
|
|
|
if (!_share.isNull()) {
|
|
|
|
// We have a share so delete it
|
|
|
|
_pi_link->startAnimation();
|
|
|
|
_share->deleteShare();
|
|
|
|
} else {
|
|
|
|
// No share object so we are deleting while a password is required
|
|
|
|
_ui->widget_shareLink->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
void ShareDialog::slotCreateShareFetched(const QSharedPointer<LinkShare> share)
|
2014-09-03 18:12:21 +04:00
|
|
|
{
|
2015-02-06 18:24:08 +03:00
|
|
|
_pi_link->stopAnimation();
|
2015-10-29 15:31:36 +03:00
|
|
|
_pi_password->stopAnimation();
|
2015-01-14 21:47:25 +03:00
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
_share = share;
|
2015-03-19 11:05:57 +03:00
|
|
|
getShares();
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
void ShareDialog::slotCreateShareRequiresPassword()
|
|
|
|
{
|
|
|
|
// there needs to be a password
|
|
|
|
_ui->checkBox_password->setChecked(true);
|
|
|
|
_ui->checkBox_password->setEnabled(false);
|
|
|
|
_ui->checkBox_password->setText(tr("Public shå requires a password"));
|
|
|
|
_ui->lineEdit_password->setFocus();
|
|
|
|
_ui->pushButton_copy->hide();
|
|
|
|
_ui->widget_shareLink->show();
|
2015-10-29 15:31:36 +03:00
|
|
|
_ui->checkBox_expire->setEnabled(false);
|
|
|
|
_ui->checkBox_editing->setEnabled(false);
|
2015-10-29 13:09:10 +03:00
|
|
|
|
|
|
|
slotCheckBoxPasswordClicked();
|
|
|
|
}
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
void ShareDialog::slotCheckBoxPasswordClicked()
|
|
|
|
{
|
2015-03-09 16:33:02 +03:00
|
|
|
if (_ui->checkBox_password->checkState() == Qt::Checked) {
|
2014-09-03 18:12:21 +04:00
|
|
|
_ui->lineEdit_password->show();
|
2015-02-25 15:44:12 +03:00
|
|
|
_ui->pushButton_setPassword->show();
|
2015-08-12 19:22:51 +03:00
|
|
|
_ui->lineEdit_password->setPlaceholderText(tr("Please Set Password"));
|
2015-03-09 16:33:02 +03:00
|
|
|
_ui->lineEdit_password->setFocus();
|
|
|
|
} else {
|
2015-10-29 15:31:36 +03:00
|
|
|
setPassword(QString());
|
2015-01-14 21:08:04 +03:00
|
|
|
_ui->lineEdit_password->setPlaceholderText(QString());
|
2015-01-14 20:42:56 +03:00
|
|
|
_pi_password->startAnimation();
|
2014-09-03 18:12:21 +04:00
|
|
|
_ui->lineEdit_password->hide();
|
2015-02-25 15:44:12 +03:00
|
|
|
_ui->pushButton_setPassword->hide();
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::slotCheckBoxExpireClicked()
|
|
|
|
{
|
|
|
|
if (_ui->checkBox_expire->checkState() == Qt::Checked)
|
|
|
|
{
|
2015-01-17 11:10:42 +03:00
|
|
|
const QDate date = QDate::currentDate().addDays(1);
|
2015-08-20 14:40:10 +03:00
|
|
|
setExpireDate(date);
|
2015-03-09 16:33:02 +03:00
|
|
|
_ui->calendar->setDate(date);
|
2015-01-17 11:10:42 +03:00
|
|
|
_ui->calendar->setMinimumDate(date);
|
2015-03-09 16:33:02 +03:00
|
|
|
_ui->calendar->setEnabled(true);
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-29 13:09:10 +03:00
|
|
|
setExpireDate(QDate());
|
2015-03-09 16:33:02 +03:00
|
|
|
_ui->calendar->setEnabled(false);
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-20 16:42:14 +03:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
extern void copyToPasteboard(const QString &string);
|
|
|
|
#endif
|
|
|
|
|
2015-02-03 15:02:52 +03:00
|
|
|
void ShareDialog::slotPushButtonCopyLinkPressed()
|
|
|
|
{
|
2015-10-20 16:42:14 +03:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
copyToPasteboard(_shareUrl);
|
|
|
|
#else
|
2015-02-03 15:02:52 +03:00
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
2015-03-09 16:33:02 +03:00
|
|
|
clipboard->setText(_shareUrl);
|
2015-10-20 16:42:14 +03:00
|
|
|
#endif
|
2015-02-03 15:02:52 +03:00
|
|
|
}
|
|
|
|
|
2015-08-20 14:40:10 +03:00
|
|
|
void ShareDialog::slotCheckBoxEditingClicked()
|
|
|
|
{
|
|
|
|
ShareDialog::setPublicUpload(_ui->checkBox_editing->checkState() == Qt::Checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::setPublicUpload(bool publicUpload)
|
|
|
|
{
|
|
|
|
_ui->checkBox_editing->setEnabled(false);
|
|
|
|
_pi_editing->startAnimation();
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
_share->setPublicUpload(publicUpload);
|
2015-08-20 14:40:10 +03:00
|
|
|
}
|
|
|
|
|
2015-10-29 13:09:10 +03:00
|
|
|
void ShareDialog::slotPublicUploadSet()
|
2015-08-20 14:40:10 +03:00
|
|
|
{
|
|
|
|
_pi_editing->stopAnimation();
|
2015-10-29 13:09:10 +03:00
|
|
|
_ui->checkBox_editing->setEnabled(true);
|
2015-08-20 14:40:10 +03:00
|
|
|
}
|
|
|
|
|
2015-02-25 15:44:12 +03:00
|
|
|
void ShareDialog::setShareCheckBoxTitle(bool haveShares)
|
|
|
|
{
|
2015-03-26 20:08:06 +03:00
|
|
|
const QString noSharesTitle(tr("&Share link"));
|
|
|
|
const QString haveSharesTitle(tr("&Share link"));
|
2015-02-25 15:44:12 +03:00
|
|
|
|
|
|
|
if( haveShares ) {
|
|
|
|
_ui->checkBox_shareLink->setText( haveSharesTitle );
|
|
|
|
} else {
|
|
|
|
_ui->checkBox_shareLink->setText( noSharesTitle );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-29 18:56:23 +03:00
|
|
|
void ShareDialog::displayError(int code, const QString &message)
|
|
|
|
{
|
|
|
|
const QString arg = QString("%1, %2").arg(code).arg(message);
|
|
|
|
const QString errMsg = tr("OCS API error code: %1").arg(arg);
|
|
|
|
displayError(errMsg);
|
|
|
|
}
|
|
|
|
|
2015-03-11 16:09:31 +03:00
|
|
|
void ShareDialog::displayError(const QString& errMsg)
|
2015-01-21 17:03:01 +03:00
|
|
|
{
|
|
|
|
_ui->errorLabel->setText( errMsg );
|
2015-01-23 11:10:02 +03:00
|
|
|
_ui->errorLabel->show();
|
2015-01-21 17:03:01 +03:00
|
|
|
}
|
|
|
|
|
2015-03-11 16:09:31 +03:00
|
|
|
void ShareDialog::displayError(int code)
|
|
|
|
{
|
|
|
|
const QString errMsg = tr("OCS API error code: %1").arg(code);
|
|
|
|
displayError(errMsg);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|