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"
|
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>
|
|
|
|
#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
|
|
|
|
2015-03-11 16:09:31 +03:00
|
|
|
ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QString &localPath, bool resharingAllowed, QWidget *parent) :
|
2015-11-05 11:58:16 +03:00
|
|
|
QDialog(parent),
|
2015-01-14 12:35:09 +03:00
|
|
|
_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-11-05 11:58:16 +03:00
|
|
|
_resharingAllowed(resharingAllowed),
|
|
|
|
_linkWidget(NULL),
|
|
|
|
_userGroupWidget(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-17 12:24:35 +03:00
|
|
|
closeButton->setDefault(false); // Because people press enter in the dialog and we don't want to close for that
|
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("/*$"), "");
|
|
|
|
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-11-19 14:00:53 +03:00
|
|
|
if (!account->capabilities().shareAPI()) {
|
|
|
|
_ui->shareWidgetsLayout->addWidget(new QLabel(tr("The server does not allow sharing")));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
bool autoShare = true;
|
2015-07-10 16:46:17 +03:00
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
// We only do user/group sharing from 8.2.0
|
|
|
|
if (account->serverVersionInt() >= ((8 << 16) + (2 << 8))) {
|
|
|
|
_userGroupWidget = new ShareUserGroupWidget(account, sharePath, localPath, resharingAllowed, this);
|
|
|
|
_ui->shareWidgetsLayout->addWidget(_userGroupWidget);
|
2015-07-10 16:46:17 +03:00
|
|
|
|
2015-11-17 13:58:35 +03:00
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
QFrame *hline = new QFrame(this);
|
|
|
|
hline->setFrameShape(QFrame::HLine);
|
2015-11-17 13:58:35 +03:00
|
|
|
QPalette p = palette();
|
|
|
|
// Make the line softer:
|
|
|
|
p.setColor(QPalette::Foreground, QColor::fromRgba((p.color(QPalette::Foreground).rgba() & 0x00ffffff) | 0x50000000));
|
|
|
|
hline->setPalette(p);
|
2015-11-05 11:58:16 +03:00
|
|
|
_ui->shareWidgetsLayout->addWidget(hline);
|
2015-11-17 13:58:35 +03:00
|
|
|
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
autoShare = false;
|
2015-07-10 16:46:17 +03:00
|
|
|
}
|
|
|
|
|
2015-11-05 11:58:16 +03:00
|
|
|
_linkWidget = new ShareLinkWidget(account, sharePath, localPath, resharingAllowed, autoShare, this);
|
2015-11-16 19:59:24 +03:00
|
|
|
_linkWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
2015-11-05 11:58:16 +03:00
|
|
|
_ui->shareWidgetsLayout->addWidget(_linkWidget);
|
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
|
|
|
}
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
void ShareDialog::getShares()
|
|
|
|
{
|
2015-07-09 10:19:04 +03:00
|
|
|
if (QFileInfo(_localPath).isFile()) {
|
2015-11-05 11:58:16 +03:00
|
|
|
ThumbnailJob *job = new ThumbnailJob(_sharePath, _account, this);
|
|
|
|
connect(job, SIGNAL(jobFinished(int, QByteArray)), SLOT(slotThumbnailFetched(int, QByteArray)));
|
|
|
|
job->start();
|
2015-03-26 19:23:29 +03:00
|
|
|
}
|
|
|
|
|
2015-11-19 14:00:53 +03:00
|
|
|
if (_linkWidget) {
|
|
|
|
_linkWidget->getShares();
|
|
|
|
}
|
2015-11-05 11:58:16 +03:00
|
|
|
if (_userGroupWidget != NULL) {
|
|
|
|
_userGroupWidget->getShares();
|
2015-03-09 16:33:02 +03:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
2015-11-05 11:58:16 +03:00
|
|
|
|