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 "networkjobs.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"
|
|
|
|
#include "syncresult.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-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
|
|
|
|
|
|
|
namespace {
|
|
|
|
int SHARETYPE_PUBLIC = 3;
|
2015-08-20 14:40:10 +03:00
|
|
|
|
|
|
|
// int PERMISSION_READ = 1;
|
|
|
|
int PERMISSION_UPDATE = 2;
|
|
|
|
int PERMISSION_CREATE = 4;
|
|
|
|
// int PERMISSION_DELETE = 8;
|
|
|
|
// int PERMISSION_SHARE = 16;
|
|
|
|
// int PERMISSION_ALL = 31;
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
|
2015-08-20 14:40:10 +03: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-03-11 16:09:31 +03:00
|
|
|
_public_share_id(0),
|
|
|
|
_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->setDate(QDate::currentDate().addDays(1));
|
|
|
|
_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);
|
|
|
|
}
|
|
|
|
}
|
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-05-07 11:23:39 +03:00
|
|
|
static int getJsonReturnCode(const QVariantMap &json, QString &message)
|
|
|
|
{
|
|
|
|
//TODO proper checking
|
|
|
|
int code = json.value("ocs").toMap().value("meta").toMap().value("statuscode").toInt();
|
|
|
|
message = json.value("ocs").toMap().value("meta").toMap().value("message").toString();
|
|
|
|
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2015-01-17 11:57:17 +03:00
|
|
|
void ShareDialog::setExpireDate(const QDate &date)
|
2014-09-09 03:50:31 +04:00
|
|
|
{
|
2015-02-06 18:24:08 +03:00
|
|
|
if( _public_share_id == 0 ) {
|
|
|
|
// no public share so far.
|
|
|
|
return;
|
|
|
|
}
|
2015-01-14 20:42:56 +03:00
|
|
|
_pi_date->startAnimation();
|
2015-01-28 12:52:55 +03:00
|
|
|
QUrl url = Account::concatUrlPath(_account->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares/%1").arg(_public_share_id));
|
2014-09-09 03:50:31 +04:00
|
|
|
QList<QPair<QString, QString> > postParams;
|
2015-01-17 11:57:17 +03:00
|
|
|
|
|
|
|
if (date.isValid()) {
|
|
|
|
postParams.append(qMakePair(QString::fromLatin1("expireDate"), date.toString("yyyy-MM-dd")));
|
|
|
|
} else {
|
|
|
|
postParams.append(qMakePair(QString::fromLatin1("expireDate"), QString()));
|
|
|
|
}
|
|
|
|
|
2015-01-28 14:19:40 +03:00
|
|
|
OcsShareJob *job = new OcsShareJob("PUT", url, _account, this);
|
|
|
|
job->setPostParams(postParams);
|
2015-05-07 11:23:39 +03:00
|
|
|
connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotExpireSet(QVariantMap)));
|
2014-09-09 03:50:31 +04:00
|
|
|
job->start();
|
|
|
|
}
|
|
|
|
|
2015-05-07 11:23:39 +03:00
|
|
|
void ShareDialog::slotExpireSet(const QVariantMap &reply)
|
2014-09-09 03:50:31 +04:00
|
|
|
{
|
2015-01-17 10:29:20 +03:00
|
|
|
QString message;
|
2015-05-07 11:23:39 +03:00
|
|
|
int code = getJsonReturnCode(reply, message);
|
2015-01-17 10:29:20 +03:00
|
|
|
if (code != 100) {
|
2015-01-21 17:03:01 +03:00
|
|
|
displayError(code);
|
2015-01-17 10:29:20 +03: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-02-25 15:44:12 +03:00
|
|
|
if( _passwordJobRunning ) {
|
|
|
|
// This happens because the entry field and the button both trigger this slot.
|
|
|
|
return;
|
|
|
|
}
|
2015-08-12 19:22:51 +03:00
|
|
|
_pi_link->startAnimation();
|
2015-01-14 20:42:56 +03:00
|
|
|
_pi_password->startAnimation();
|
2015-02-06 18:24:08 +03:00
|
|
|
QUrl url;
|
|
|
|
QList<QPair<QString, QString> > requestParams;
|
|
|
|
QByteArray verb("PUT");
|
|
|
|
|
|
|
|
if( _public_share_id > 0 ) {
|
|
|
|
url = Account::concatUrlPath(_account->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares/%1").arg(_public_share_id));
|
|
|
|
requestParams.append(qMakePair(QString::fromLatin1("password"), password));
|
|
|
|
} else {
|
|
|
|
// lets create a new share.
|
|
|
|
url = Account::concatUrlPath(_account->url(), QLatin1String("ocs/v1.php/apps/files_sharing/api/v1/shares"));
|
|
|
|
requestParams.append(qMakePair(QString::fromLatin1("path"), _sharePath));
|
|
|
|
requestParams.append(qMakePair(QString::fromLatin1("shareType"), QString::number(SHARETYPE_PUBLIC)));
|
|
|
|
requestParams.append(qMakePair(QString::fromLatin1("password"), password));
|
|
|
|
verb = "POST";
|
|
|
|
|
|
|
|
if( _ui->checkBox_expire->isChecked() ) {
|
2015-03-09 16:33:02 +03:00
|
|
|
QDate date = _ui->calendar->date();
|
2015-02-06 18:24:08 +03:00
|
|
|
if( date.isValid() ) {
|
|
|
|
requestParams.append(qMakePair(QString::fromLatin1("expireDate"), date.toString("yyyy-MM-dd")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OcsShareJob *job = new OcsShareJob(verb, url, _account, this);
|
|
|
|
job->setPostParams(requestParams);
|
2015-05-07 11:23:39 +03:00
|
|
|
connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotPasswordSet(QVariantMap)));
|
2015-07-16 21:55:54 +03:00
|
|
|
|
|
|
|
if (_public_share_id == 0) {
|
|
|
|
connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotCreateShareFetched(QVariantMap)));
|
|
|
|
}
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
job->start();
|
2015-02-25 15:44:12 +03:00
|
|
|
_passwordJobRunning = true;
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
|
2015-05-07 11:23:39 +03:00
|
|
|
void ShareDialog::slotPasswordSet(const QVariantMap &reply)
|
2014-09-09 03:50:31 +04:00
|
|
|
{
|
2015-01-17 10:29:20 +03:00
|
|
|
QString message;
|
2015-05-07 11:23:39 +03:00
|
|
|
int code = getJsonReturnCode(reply, message);
|
2015-01-17 10:29:20 +03:00
|
|
|
if (code != 100) {
|
2015-01-22 11:28:26 +03:00
|
|
|
displayError(code);
|
2015-02-25 15:44:12 +03:00
|
|
|
}
|
|
|
|
/*
|
2015-01-17 10:50:28 +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-02-25 15:44:12 +03:00
|
|
|
_passwordJobRunning = false;
|
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-01-28 12:52:55 +03:00
|
|
|
QUrl url = Account::concatUrlPath(_account->url(), QLatin1String("ocs/v1.php/apps/files_sharing/api/v1/shares"));
|
2014-09-03 18:12:21 +04:00
|
|
|
QList<QPair<QString, QString> > params;
|
2015-01-16 16:48:56 +03:00
|
|
|
params.append(qMakePair(QString::fromLatin1("path"), _sharePath));
|
2014-09-03 18:12:21 +04:00
|
|
|
url.setQueryItems(params);
|
2015-01-28 14:19:40 +03:00
|
|
|
OcsShareJob *job = new OcsShareJob("GET", url, _account, this);
|
2015-05-07 11:23:39 +03:00
|
|
|
job->addPassStatusCode(404); // don't report error if share doesn't exist yet
|
|
|
|
connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotSharesFetched(QVariantMap)));
|
2014-09-03 18:12:21 +04:00
|
|
|
job->start();
|
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-05-07 11:23:39 +03:00
|
|
|
void ShareDialog::slotSharesFetched(const QVariantMap &reply)
|
2014-09-03 18:12:21 +04:00
|
|
|
{
|
2015-01-17 10:29:20 +03:00
|
|
|
QString message;
|
2015-05-07 11:23:39 +03:00
|
|
|
int code = getJsonReturnCode(reply, message);
|
2015-01-28 14:19:40 +03:00
|
|
|
if (code != 100 && code != 404) {
|
2015-01-21 17:03:01 +03:00
|
|
|
displayError(code);
|
2015-01-14 21:47:25 +03:00
|
|
|
}
|
|
|
|
|
2015-05-07 11:23:39 +03:00
|
|
|
ShareDialog::_shares = reply.value("ocs").toMap().value("data").toList();
|
2015-04-17 18:56:17 +03:00
|
|
|
const QString versionString = _account->serverVersion();
|
2015-02-25 15:44:12 +03:00
|
|
|
|
2015-08-12 19:22:51 +03:00
|
|
|
qDebug() << Q_FUNC_INFO << versionString << "Fetched" << ShareDialog::_shares.count() << "shares";
|
|
|
|
|
2015-07-08 23:39:09 +03:00
|
|
|
//Show link checkbox now
|
|
|
|
_ui->checkBox_shareLink->setEnabled(true);
|
|
|
|
_pi_link->stopAnimation();
|
|
|
|
|
2015-02-25 15:44:12 +03:00
|
|
|
Q_FOREACH(auto share, ShareDialog::_shares) {
|
2015-01-17 11:29:13 +03:00
|
|
|
QVariantMap data = share.toMap();
|
2014-09-03 18:12:21 +04:00
|
|
|
|
2015-02-25 15:44:12 +03:00
|
|
|
if (data.value("share_type").toInt() == SHARETYPE_PUBLIC) {
|
2014-12-24 16:44:35 +03:00
|
|
|
_public_share_id = data.value("id").toULongLong();
|
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-02-25 15:44:12 +03:00
|
|
|
if (data.value("share_with").isValid()) {
|
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-02-25 15:44:12 +03:00
|
|
|
if (data.value("expiration").isValid()) {
|
2015-03-09 16:33:02 +03:00
|
|
|
_ui->calendar->setDate(QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00"));
|
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-08-20 14:40:10 +03:00
|
|
|
if (data.value("permissions").isValid()) {
|
|
|
|
int permissions = data.value("permissions").toInt();
|
|
|
|
/*
|
|
|
|
* Only directories can have public upload set
|
|
|
|
* For public links the server sets CREATE and UPDATE permissions.
|
|
|
|
*/
|
|
|
|
if (!_isFile && (permissions & PERMISSION_UPDATE) && (permissions & PERMISSION_CREATE)) {
|
|
|
|
_ui->checkBox_editing->setChecked(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-12 19:04:03 +03:00
|
|
|
QString url;
|
2015-07-17 10:23:55 +03:00
|
|
|
// From ownCloud server 8.2 the url field is always set for public shares
|
|
|
|
if (data.contains("url")) {
|
|
|
|
url = data.value("url").toString();
|
|
|
|
} else if (versionString.contains('.') && versionString.split('.')[0].toInt() >= 8) {
|
|
|
|
// From ownCloud server version 8 on, a different share link scheme is used.
|
2015-02-12 19:04:03 +03:00
|
|
|
url = Account::concatUrlPath(_account->url(), QString("index.php/s/%1").arg(data.value("token").toString())).toString();
|
|
|
|
} else {
|
2015-02-13 16:52:40 +03:00
|
|
|
QList<QPair<QString, QString>> queryArgs;
|
|
|
|
queryArgs.append(qMakePair(QString("service"), QString("files")));
|
|
|
|
queryArgs.append(qMakePair(QString("t"), data.value("token").toString()));
|
|
|
|
url = Account::concatUrlPath(_account->url(), QLatin1String("public.php"), queryArgs).toString();
|
2015-02-12 19:04:03 +03:00
|
|
|
}
|
2015-03-09 16:33:02 +03:00
|
|
|
setShareLink(url);
|
|
|
|
|
|
|
|
_ui->pushButton_copy->setEnabled(true);
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
}
|
2015-03-09 16:33:02 +03:00
|
|
|
if( _shares.count()>0 ) {
|
|
|
|
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-05-07 11:23:39 +03:00
|
|
|
void ShareDialog::slotDeleteShareFetched(const QVariantMap &reply)
|
2014-09-03 18:12:21 +04:00
|
|
|
{
|
2015-01-17 11:48:18 +03:00
|
|
|
QString message;
|
2015-05-07 11:23:39 +03:00
|
|
|
int code = getJsonReturnCode(reply, message);
|
2015-01-17 11:48:18 +03:00
|
|
|
if (code != 100) {
|
2015-01-21 17:03:01 +03:00
|
|
|
displayError(code);
|
2015-01-17 11:48:18 +03:00
|
|
|
}
|
2015-01-14 21:08:04 +03:00
|
|
|
|
2015-02-10 09:51:58 +03:00
|
|
|
_public_share_id = 0;
|
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-01-28 12:52:55 +03:00
|
|
|
QUrl url = Account::concatUrlPath(_account->url(), QLatin1String("ocs/v1.php/apps/files_sharing/api/v1/shares"));
|
2014-09-03 18:12:21 +04:00
|
|
|
QList<QPair<QString, QString> > postParams;
|
2015-01-16 16:48:56 +03:00
|
|
|
postParams.append(qMakePair(QString::fromLatin1("path"), _sharePath));
|
2014-09-03 18:12:21 +04:00
|
|
|
postParams.append(qMakePair(QString::fromLatin1("shareType"), QString::number(SHARETYPE_PUBLIC)));
|
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"));
|
|
|
|
_ui->lineEdit_password->setFocus();
|
|
|
|
_ui->pushButton_copy->hide();
|
|
|
|
_ui->widget_shareLink->show();
|
|
|
|
|
|
|
|
slotCheckBoxPasswordClicked();
|
|
|
|
return;
|
2015-07-10 16:26:26 +03:00
|
|
|
}
|
|
|
|
|
2015-01-28 14:19:40 +03:00
|
|
|
OcsShareJob *job = new OcsShareJob("POST", url, _account, this);
|
|
|
|
job->setPostParams(postParams);
|
2015-05-07 11:23:39 +03:00
|
|
|
job->addPassStatusCode(403); // "password required" is not an error
|
|
|
|
connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotCreateShareFetched(QVariantMap)));
|
2014-09-03 18:12:21 +04:00
|
|
|
job->start();
|
2015-02-25 15:44:12 +03:00
|
|
|
} else {
|
2015-01-14 20:42:56 +03:00
|
|
|
_pi_link->startAnimation();
|
2015-01-28 12:52:55 +03:00
|
|
|
QUrl url = Account::concatUrlPath(_account->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares/%1").arg(_public_share_id));
|
2015-01-28 14:19:40 +03:00
|
|
|
OcsShareJob *job = new OcsShareJob("DELETE", url, _account, this);
|
2015-05-07 11:23:39 +03:00
|
|
|
connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotDeleteShareFetched(QVariantMap)));
|
2014-09-03 18:12:21 +04:00
|
|
|
job->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-07 11:23:39 +03:00
|
|
|
void ShareDialog::slotCreateShareFetched(const QVariantMap &reply)
|
2014-09-03 18:12:21 +04:00
|
|
|
{
|
2015-01-17 10:29:20 +03:00
|
|
|
QString message;
|
2015-05-07 11:23:39 +03:00
|
|
|
int code = getJsonReturnCode(reply, message);
|
2015-02-06 18:24:08 +03:00
|
|
|
_pi_link->stopAnimation();
|
2015-01-14 21:47:25 +03:00
|
|
|
|
2015-02-06 18:24:08 +03:00
|
|
|
if (code == 403) {
|
|
|
|
// there needs to be a password
|
|
|
|
_ui->checkBox_password->setChecked(true);
|
2015-05-08 15:53:38 +03:00
|
|
|
_ui->checkBox_password->setEnabled(false);
|
|
|
|
_ui->checkBox_password->setText(tr("Public shå requires a password"));
|
2015-02-06 18:24:08 +03:00
|
|
|
_ui->lineEdit_password->setFocus();
|
2015-05-08 15:53:38 +03:00
|
|
|
_ui->pushButton_copy->hide();
|
2015-02-06 18:24:08 +03:00
|
|
|
_ui->widget_shareLink->show();
|
|
|
|
|
|
|
|
slotCheckBoxPasswordClicked();
|
|
|
|
return;
|
|
|
|
} else if (code != 100) {
|
2015-01-21 17:03:01 +03:00
|
|
|
displayError(code);
|
2015-01-14 21:47:25 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-07 11:23:39 +03:00
|
|
|
_public_share_id = reply.value("ocs").toMap().values("data")[0].toMap().value("id").toULongLong();
|
2015-05-08 15:53:38 +03:00
|
|
|
_ui->pushButton_copy->show();
|
2015-03-19 11:05:57 +03:00
|
|
|
getShares();
|
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-01-11 15:24:40 +03:00
|
|
|
ShareDialog::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-01-17 11:57:17 +03:00
|
|
|
ShareDialog::setExpireDate(QDate());
|
2015-03-09 16:33:02 +03:00
|
|
|
_ui->calendar->setEnabled(false);
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-03 15:02:52 +03:00
|
|
|
void ShareDialog::slotPushButtonCopyLinkPressed()
|
|
|
|
{
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
2015-03-09 16:33:02 +03:00
|
|
|
clipboard->setText(_shareUrl);
|
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();
|
|
|
|
|
|
|
|
const QUrl url = Account::concatUrlPath(_account->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares/%1").arg(_public_share_id));
|
|
|
|
|
|
|
|
QList<QPair<QString, QString> > requestParams;
|
|
|
|
const QString value = QString::fromLatin1(publicUpload ? "true" : "false");
|
|
|
|
requestParams.append(qMakePair(QString::fromLatin1("publicUpload"), value));
|
|
|
|
|
|
|
|
OcsShareJob *job = new OcsShareJob("PUT", url, _account, this);
|
|
|
|
job->setPostParams(requestParams);
|
|
|
|
connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotPublicUploadSet(QVariantMap)));
|
|
|
|
|
|
|
|
job->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::slotPublicUploadSet(const QVariantMap &reply)
|
|
|
|
{
|
|
|
|
QString message;
|
|
|
|
int code = getJsonReturnCode(reply, message);
|
|
|
|
if (code == 100) {
|
|
|
|
_ui->checkBox_editing->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
qDebug() << Q_FUNC_INFO << reply;
|
|
|
|
displayError(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
_pi_editing->stopAnimation();
|
|
|
|
}
|
|
|
|
|
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-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);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2015-01-21 17:03:01 +03:00
|
|
|
void ShareDialog::displayInfo( const QString& msg )
|
|
|
|
{
|
|
|
|
_ui->label_sharePath->setText(msg);
|
|
|
|
}
|
|
|
|
|
2015-01-29 20:09:46 +03:00
|
|
|
/*
|
|
|
|
* This code is disabled for now as we do not have answers for all the questions involved
|
|
|
|
* here, see https://github.com/owncloud/client/issues/2732
|
|
|
|
*/
|
2015-01-21 17:03:01 +03:00
|
|
|
bool ShareDialog::uploadExternalFile()
|
|
|
|
{
|
|
|
|
bool re = false;
|
|
|
|
const QString folderName = QString("ownCloud"); // FIXME: get a proper folder name
|
|
|
|
|
|
|
|
Folder *folder = 0;
|
|
|
|
Folder::Map folders = FolderMan::instance()->map();
|
|
|
|
if( folders.isEmpty() ) {
|
2015-01-22 11:28:26 +03:00
|
|
|
displayInfo(tr("There is no sync folder configured."));
|
2015-01-21 17:03:01 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if( folders.contains( Theme::instance()->appNameGUI()) ) {
|
|
|
|
folder = folders.value(Theme::instance()->appNameGUI());
|
|
|
|
}
|
|
|
|
if( !folder ) {
|
|
|
|
folder = folders.value( folders.keys().at(0));
|
|
|
|
}
|
|
|
|
FolderMan::instance()->folder(folderName);
|
|
|
|
if( ! folder ) {
|
|
|
|
qDebug() << "Folder not defined: " << folderName;
|
2015-06-07 15:19:59 +03:00
|
|
|
displayInfo(tr("Cannot find a folder to upload to."));
|
2015-01-21 17:03:01 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFileInfo fi(_localPath);
|
|
|
|
if( fi.isDir() ) {
|
|
|
|
// we can not do this for directories yet.
|
|
|
|
displayInfo(tr("Sharing of external directories is not yet working."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
_sharePath = folder->remotePath()+QLatin1Char('/')+fi.fileName();
|
|
|
|
_folderAlias = folderName;
|
|
|
|
|
|
|
|
// connect the finish signal of the folder before the file to upload
|
|
|
|
// is copied to the sync folder.
|
|
|
|
connect( folder, SIGNAL(syncFinished(SyncResult)), this, SLOT(slotNextSyncFinished(SyncResult)) );
|
|
|
|
|
|
|
|
// copy the file
|
|
|
|
_expectedSyncFile = folder->path()+fi.fileName();
|
|
|
|
|
|
|
|
QFileInfo target(_expectedSyncFile);
|
|
|
|
if( target.exists() ) {
|
|
|
|
_ui->label_sharePath->setText(tr("A sync file with the same name exists. "
|
2015-02-06 00:00:13 +03:00
|
|
|
"The file cannot be registered to sync."));
|
2015-01-21 17:03:01 +03:00
|
|
|
// TODO: Add a file comparison here. If the existing file is still the same
|
2015-10-05 07:21:19 +03:00
|
|
|
// as the file-to-copy we can share it.
|
2015-01-21 17:03:01 +03:00
|
|
|
_sharePath.clear();
|
|
|
|
} else {
|
|
|
|
_uploadFails = 0;
|
|
|
|
_ui->pi_share->startAnimation();
|
|
|
|
QFile file( _localPath);
|
|
|
|
if( file.copy(_expectedSyncFile) ) {
|
|
|
|
// copying succeeded.
|
|
|
|
re = true;
|
|
|
|
displayInfo(tr("Waiting to upload..."));
|
|
|
|
} else {
|
|
|
|
displayInfo(tr("Unable to register in sync space."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShareDialog::slotNextSyncFinished( const SyncResult& result )
|
|
|
|
{
|
|
|
|
// FIXME: Check for state!
|
|
|
|
SyncFileItemVector itemVector = result.syncFileItemVector();
|
|
|
|
SyncFileItem targetItem;
|
|
|
|
Folder *folder = FolderMan::instance()->folder(_folderAlias);
|
|
|
|
const QString folderPath = folder->path();
|
|
|
|
|
|
|
|
_ui->pi_share->stopAnimation();
|
|
|
|
|
|
|
|
foreach( SyncFileItem item, itemVector ) {
|
|
|
|
const QString fullSyncedFile = folderPath + item._file;
|
|
|
|
if( item._direction == SyncFileItem::Up &&
|
|
|
|
fullSyncedFile == _expectedSyncFile) {
|
|
|
|
// found the item!
|
|
|
|
targetItem = item;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( targetItem.isEmpty() ) {
|
|
|
|
// The item was not in this sync run. Lets wait for the next one. FIXME
|
|
|
|
_uploadFails ++;
|
|
|
|
if( _uploadFails > 2 ) {
|
|
|
|
// stop the upload job
|
2015-02-06 00:00:13 +03:00
|
|
|
displayInfo(tr("The file cannot be synced."));
|
2015-01-21 17:03:01 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// it's there and the sync was successful.
|
|
|
|
// The server should be able to generate a share link now.
|
|
|
|
// Enable the sharing link
|
|
|
|
if( targetItem._status == SyncFileItem::Success ) {
|
|
|
|
_ui->checkBox_shareLink->setEnabled(true);
|
|
|
|
_ui->label_sharePath->setText(tr("%1 path: %2").arg(Theme::instance()->appNameGUI()).arg(_sharePath));
|
|
|
|
} else {
|
|
|
|
displayInfo(tr("Sync of registered file was not successful yet."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_expectedSyncFile.clear();
|
|
|
|
}
|
2015-01-29 20:09:46 +03:00
|
|
|
#endif
|
2015-01-13 18:33:57 +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);
|
|
|
|
}
|
|
|
|
|
2015-01-28 14:19:40 +03:00
|
|
|
OcsShareJob::OcsShareJob(const QByteArray &verb, const QUrl &url, AccountPtr account, QObject* parent)
|
2014-09-03 18:12:21 +04:00
|
|
|
: AbstractNetworkJob(account, "", parent),
|
|
|
|
_verb(verb),
|
2015-01-23 11:32:32 +03:00
|
|
|
_url(url)
|
2014-09-03 18:12:21 +04:00
|
|
|
{
|
2015-05-07 11:23:39 +03:00
|
|
|
_passStatusCodes.append(100);
|
2014-09-03 18:12:21 +04:00
|
|
|
setIgnoreCredentialFailure(true);
|
|
|
|
}
|
|
|
|
|
2015-01-28 14:19:40 +03:00
|
|
|
void OcsShareJob::setPostParams(const QList<QPair<QString, QString> >& postParams)
|
|
|
|
{
|
|
|
|
_postParams = postParams;
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
|
2015-05-07 11:23:39 +03:00
|
|
|
void OcsShareJob::addPassStatusCode(int code)
|
|
|
|
{
|
|
|
|
_passStatusCodes.append(code);
|
|
|
|
}
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
void OcsShareJob::start()
|
|
|
|
{
|
|
|
|
QNetworkRequest req;
|
|
|
|
req.setRawHeader("OCS-APIREQUEST", "true");
|
|
|
|
req.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
|
2014-12-19 18:56:17 +03:00
|
|
|
|
2015-02-26 11:40:54 +03:00
|
|
|
// Url encode the _postParams and put them in a buffer.
|
|
|
|
QByteArray postData;
|
2015-01-28 14:19:40 +03:00
|
|
|
Q_FOREACH(auto tmp2, _postParams) {
|
2015-02-26 11:40:54 +03:00
|
|
|
if (! postData.isEmpty()) {
|
|
|
|
postData.append("&");
|
|
|
|
}
|
|
|
|
postData.append(QUrl::toPercentEncoding(tmp2.first));
|
|
|
|
postData.append("=");
|
|
|
|
postData.append(QUrl::toPercentEncoding(tmp2.second));
|
2014-12-19 18:56:17 +03:00
|
|
|
}
|
2015-02-26 11:40:54 +03:00
|
|
|
QBuffer *buffer = new QBuffer;
|
|
|
|
buffer->setData(postData);
|
2014-12-19 18:56:17 +03:00
|
|
|
|
2015-01-23 11:17:00 +03:00
|
|
|
auto queryItems = _url.queryItems();
|
|
|
|
queryItems.append(qMakePair(QString::fromLatin1("format"), QString::fromLatin1("json")));
|
|
|
|
_url.setQueryItems(queryItems);
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
setReply(davRequest(_verb, _url, req, buffer));
|
|
|
|
setupConnections(reply());
|
|
|
|
buffer->setParent(reply());
|
|
|
|
AbstractNetworkJob::start();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OcsShareJob::finished()
|
|
|
|
{
|
2015-05-07 11:23:39 +03:00
|
|
|
const QString replyData = reply()->readAll();
|
|
|
|
|
|
|
|
bool success;
|
|
|
|
QVariantMap json = QtJson::parse(replyData, success).toMap();
|
|
|
|
if (!success) {
|
|
|
|
qDebug() << "Could not parse reply to" << _verb << _url << _postParams
|
|
|
|
<< ":" << replyData;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString message;
|
|
|
|
const int statusCode = getJsonReturnCode(json, message);
|
|
|
|
if (!_passStatusCodes.contains(statusCode)) {
|
|
|
|
qDebug() << "Reply to" << _verb << _url << _postParams
|
|
|
|
<< "has unexpected status code:" << statusCode << replyData;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit jobFinished(json);
|
2014-09-03 18:12:21 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-09 10:19:04 +03:00
|
|
|
ThumbnailJob::ThumbnailJob(const QString &path, AccountPtr account, QObject* parent)
|
|
|
|
: AbstractNetworkJob(account, "", parent)
|
|
|
|
{
|
|
|
|
_url = Account::concatUrlPath(account->url(), QLatin1String("index.php/apps/files/api/v1/thumbnail/150/150/") + path);
|
|
|
|
setIgnoreCredentialFailure(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThumbnailJob::start()
|
|
|
|
{
|
|
|
|
qDebug() << Q_FUNC_INFO;
|
|
|
|
setReply(getRequest(_url));
|
|
|
|
setupConnections(reply());
|
|
|
|
AbstractNetworkJob::start();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ThumbnailJob::finished()
|
|
|
|
{
|
|
|
|
emit jobFinished(reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), reply()->readAll());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|