From 3e4612a1f0c66e522d84359a479c1fc0e2f2c85b Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 5 Nov 2015 09:58:16 +0100 Subject: [PATCH] [Sharing] Reorganized sharedialog code Now we have 1 simple dialog that includes 2 widgets. * ShareLinkWidget (for link shares) * ShareUserGroupWidget (for user/group shares) The ShareUserGroupWidget is only included if the server version is >= 8.2.0 For <8.2.0 the old behavior is preserved --- src/gui/CMakeLists.txt | 8 +- src/gui/application.cpp | 2 - src/gui/owncloudgui.cpp | 22 - src/gui/owncloudgui.h | 1 - src/gui/sharedialog.cpp | 529 ++---------------- src/gui/sharedialog.h | 78 +-- src/gui/sharedialog.ui | 216 +------ src/gui/sharelinkwidget.cpp | 520 +++++++++++++++++ src/gui/sharelinkwidget.h | 114 ++++ src/gui/sharelinkwidget.ui | 218 ++++++++ src/gui/shareusergroupdialog.ui | 133 ----- ...oupdialog.cpp => shareusergroupwidget.cpp} | 48 +- ...ergroupdialog.h => shareusergroupwidget.h} | 30 +- src/gui/shareusergroupwidget.ui | 65 +++ .../{sharedialogshare.ui => sharewidget.ui} | 4 +- src/gui/socketapi.cpp | 45 -- src/gui/socketapi.h | 1 - 17 files changed, 1027 insertions(+), 1007 deletions(-) create mode 100644 src/gui/sharelinkwidget.cpp create mode 100644 src/gui/sharelinkwidget.h create mode 100644 src/gui/sharelinkwidget.ui delete mode 100644 src/gui/shareusergroupdialog.ui rename src/gui/{shareusergroupdialog.cpp => shareusergroupwidget.cpp} (83%) rename src/gui/{shareusergroupdialog.h => shareusergroupwidget.h} (78%) create mode 100644 src/gui/shareusergroupwidget.ui rename src/gui/{sharedialogshare.ui => sharewidget.ui} (94%) diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index f5939e91a..1c7832df1 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -23,8 +23,9 @@ set(client_UI protocolwidget.ui settingsdialog.ui sharedialog.ui - shareusergroupdialog.ui - sharedialogshare.ui + sharelinkwidget.ui + shareusergroupwidget.ui + sharewidget.ui sslerrordialog.ui owncloudsetuppage.ui addcertificatedialog.ui @@ -63,7 +64,8 @@ set(client_SRCS settingsdialog.cpp share.cpp sharedialog.cpp - shareusergroupdialog.cpp + sharelinkwidget.cpp + shareusergroupwidget.cpp sharee.cpp socketapi.cpp sslbutton.cpp diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 41e72e245..add9add91 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -174,8 +174,6 @@ Application::Application(int &argc, char **argv) : connect(FolderMan::instance()->socketApi(), SIGNAL(shareCommandReceived(QString, QString, bool)), _gui, SLOT(slotShowShareDialog(QString, QString, bool))); - connect(FolderMan::instance()->socketApi(), SIGNAL(shareUserGroupCommandReceived(QString, QString, bool)), - _gui, SLOT(slotShowShareUserGroupDialog(QString, QString, bool))); // startup procedure. connect(&_checkConnectionTimer, SIGNAL(timeout()), this, SLOT(slotCheckConnection())); diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 4a04598c3..4adaeaa50 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -20,7 +20,6 @@ #include "progressdispatcher.h" #include "owncloudsetupwizard.h" #include "sharedialog.h" -#include "shareusergroupdialog.h" #if defined(Q_OS_MAC) # include "settingsdialogmac.h" # include "macwindow.h" // qtmacgoodies @@ -781,26 +780,5 @@ void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &l raiseDialog(w); } -void ownCloudGui::slotShowShareUserGroupDialog(const QString &sharePath, const QString &localPath, bool resharingAllowed) -{ - const auto folder = FolderMan::instance()->folderForPath(localPath); - if (!folder) { - qDebug() << "Could not open share dialog for" << localPath << "no responsible folder found"; - return; - } - - // For https://github.com/owncloud/client/issues/3783 - _settingsDialog->hide(); - - const auto accountState = folder->accountState(); - - qDebug() << Q_FUNC_INFO << "Opening share dialog" << sharePath << localPath; - ShareUserGroupDialog *w = new ShareUserGroupDialog(accountState->account(), sharePath, localPath, resharingAllowed); - w->getShares(); - w->setAttribute( Qt::WA_DeleteOnClose, true ); - raiseDialog(w); -} - - } // end namespace diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index 014c3b180..891bd74d7 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -77,7 +77,6 @@ public slots: void slotOpenPath(const QString& path); void slotAccountStateChanged(); void slotShowShareDialog(const QString &sharePath, const QString &localPath, bool resharingAllowed); - void slotShowShareUserGroupDialog(const QString &sharePath, const QString &localPath, bool resharingAllowed); private slots: void slotDisplayIdle(); diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index 3b47057b7..7be123e5a 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -1,6 +1,5 @@ /* * Copyright (C) by Roeland Jago Douma - * Copyright (C) 2015 by Klaas Freitag * * 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 @@ -13,91 +12,48 @@ */ #include "sharedialog.h" +#include "sharelinkwidget.h" +#include "shareusergroupwidget.h" #include "ui_sharedialog.h" + #include "account.h" -#include "json.h" -#include "folderman.h" -#include "folder.h" -#include "accountmanager.h" -#include "theme.h" #include "configfile.h" -#include "capabilities.h" - +#include "theme.h" #include "thumbnailjob.h" -#include "share.h" -#include "QProgressIndicator.h" -#include -#include -#include #include +#include +#include +#include +#include namespace OCC { ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QString &localPath, bool resharingAllowed, QWidget *parent) : - QDialog(parent), + QDialog(parent), _ui(new Ui::ShareDialog), _account(account), _sharePath(sharePath), _localPath(localPath), - _passwordJobRunning(false), - _manager(NULL), - _share(NULL), - _resharingAllowed(resharingAllowed) + _resharingAllowed(resharingAllowed), + _linkWidget(NULL), + _userGroupWidget(NULL) { setAttribute(Qt::WA_DeleteOnClose); setObjectName("SharingDialog"); // required as group for saveGeometry call _ui->setupUi(this); - //Is this a file or folder? - _isFile = QFileInfo(localPath).isFile(); - - _ui->pushButton_copy->setIcon(QIcon::fromTheme("edit-copy")); - _ui->pushButton_copy->setEnabled(false); - connect(_ui->pushButton_copy, SIGNAL(clicked(bool)), SLOT(slotPushButtonCopyLinkPressed())); - QPushButton *closeButton = _ui->buttonBox->button(QDialogButtonBox::Close); - if( closeButton ) { - connect( closeButton, SIGNAL(clicked()), this, SLOT(close()) ); - } - - // the following progress indicator widgets are added to layouts which makes them - // automatically deleted once the dialog dies. - _pi_link = new QProgressIndicator(); - _pi_password = new QProgressIndicator(); - _pi_date = new QProgressIndicator(); - _pi_editing = new QProgressIndicator(); - _ui->horizontalLayout_shareLink->addWidget(_pi_link); - _ui->horizontalLayout_password->addWidget(_pi_password); - _ui->horizontalLayout_editing->addWidget(_pi_editing); - // _ui->horizontalLayout_expire->addWidget(_pi_date); - - 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())); - connect(_ui->lineEdit_password, SIGNAL(textChanged(QString)), this, SLOT(slotPasswordChanged(QString))); - connect(_ui->pushButton_setPassword, SIGNAL(clicked(bool)), SLOT(slotPasswordReturnPressed())); - connect(_ui->checkBox_expire, SIGNAL(clicked()), this, SLOT(slotCheckBoxExpireClicked())); - connect(_ui->calendar, SIGNAL(dateChanged(QDate)), SLOT(slotCalendarClicked(QDate))); - connect(_ui->checkBox_editing, SIGNAL(clicked()), this, SLOT(slotCheckBoxEditingClicked())); - - //Disable checkbox - _ui->checkBox_shareLink->setEnabled(false); - _pi_link->startAnimation(); - - _ui->pushButton_setPassword->setEnabled(false); - _ui->widget_shareLink->hide(); - _ui->lineEdit_password->hide(); - _ui->pushButton_setPassword->hide(); - - _ui->calendar->setEnabled(false); + connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); + // Set icon QFileInfo f_info(_localPath); QFileIconProvider icon_provider; QIcon icon = icon_provider.icon(f_info); _ui->label_icon->setPixmap(icon.pixmap(40,40)); + // Set filename QFileInfo lPath(_localPath); QString fileName = lPath.fileName(); _ui->label_name->setText(tr("%1").arg(fileName)); @@ -118,66 +74,27 @@ ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QSt } this->setWindowTitle(tr("%1 Sharing").arg(Theme::instance()->appNameGUI())); - _ui->checkBox_password->setText(tr("P&assword protect")); - // check if the file is already inside of a synced folder - if( sharePath.isEmpty() ) { - // The file is not yet in an ownCloud synced folder. We could automatically - // copy it over, but that is skipped as not all questions can be answered that - // 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; + + bool autoShare = true; + + // 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); + + QFrame *hline = new QFrame(this); + hline->setFrameShape(QFrame::HLine); + _ui->shareWidgetsLayout->addWidget(hline); + autoShare = false; } - // error label, red box and stuff - _ui->errorLabel->setLineWidth(1); - _ui->errorLabel->setFrameStyle(QFrame::Plain); + _linkWidget = new ShareLinkWidget(account, sharePath, localPath, resharingAllowed, autoShare, this); + _ui->shareWidgetsLayout->addWidget(_linkWidget); +} - 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)); - _ui->errorLabel->hide(); - - - // Parse capabilities - - // If password is enforced then don't allow users to disable it - if (_account->capabilities().sharePublicLinkEnforcePassword()) { - _ui->checkBox_password->setEnabled(false); - } - - // If expiredate is enforced do not allow disable and set max days - if (_account->capabilities().sharePublicLinkEnforceExpireDate()) { - _ui->checkBox_expire->setEnabled(false); - _ui->calendar->setMaximumDate(QDate::currentDate().addDays( - _account->capabilities().sharePublicLinkExpireDateDays() - )); - } - - // File can't have public upload set. - if (_isFile) { - _ui->checkBox_editing->setEnabled(false); - } else { - if (!_account->capabilities().sharePublicLinkAllowUpload()) { - _ui->checkBox_editing->setEnabled(false); - } - } - - /* - * Create the share manager and connect it properly - */ - _manager = new ShareManager(_account, this); - - connect(_manager, SIGNAL(sharesFetched(QList>)), SLOT(slotSharesFetched(QList>))); - connect(_manager, SIGNAL(linkShareCreated(QSharedPointer)), SLOT(slotCreateShareFetched(const QSharedPointer))); - connect(_manager, SIGNAL(linkShareRequiresPassword()), SLOT(slotCreateShareRequiresPassword())); - connect(_manager, SIGNAL(serverError(int, QString)), SLOT(displayError(int, QString))); +ShareDialog::~ShareDialog() +{ + delete _ui; } void ShareDialog::done( int r ) { @@ -186,383 +103,18 @@ void ShareDialog::done( int r ) { QDialog::done(r); } -void ShareDialog::setExpireDate(const QDate &date) -{ - _pi_date->startAnimation(); - _share->setExpireDate(date); -} - -void ShareDialog::slotExpireSet() -{ - _pi_date->stopAnimation(); -} - -void ShareDialog::slotCalendarClicked(const QDate &date) -{ - setExpireDate(date); -} - -ShareDialog::~ShareDialog() -{ - delete _ui; -} - -void ShareDialog::slotPasswordReturnPressed() -{ - setPassword(_ui->lineEdit_password->text()); - _ui->lineEdit_password->setText(QString()); - _ui->lineEdit_password->setPlaceholderText(tr("Password Protected")); - _ui->lineEdit_password->clearFocus(); -} - -void ShareDialog::slotPasswordChanged(const QString& newText) -{ - // disable the set-password button - _ui->pushButton_setPassword->setEnabled( newText.length() > 0 ); -} - -void ShareDialog::setPassword(const QString &password) -{ - _pi_link->startAnimation(); - _pi_password->startAnimation(); - - _ui->checkBox_password->setEnabled(false); - _ui->lineEdit_password->setEnabled(false); - - if( !_share.isNull() ) { - _share->setPassword(password); - } else { - _ui->checkBox_shareLink->setEnabled(false); - _manager->createLinkShare(_sharePath, password); - } -} - -void ShareDialog::slotPasswordSet() -{ - /* - * 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. - */ - getShares(); - - _pi_password->stopAnimation(); -} - void ShareDialog::getShares() { - _manager->fetchShares(_sharePath); - if (QFileInfo(_localPath).isFile()) { - ThumbnailJob *job2 = new ThumbnailJob(_sharePath, _account, this); - connect(job2, SIGNAL(jobFinished(int, QByteArray)), SLOT(slotThumbnailFetched(int, QByteArray))); - job2->start(); - } -} - -void ShareDialog::slotSharesFetched(const QList> &shares) -{ - const QString versionString = _account->serverVersion(); - qDebug() << Q_FUNC_INFO << versionString << "Fetched" << shares.count() << "shares"; - - //Show link checkbox now - _ui->checkBox_shareLink->setEnabled(true); - _pi_link->stopAnimation(); - - Q_FOREACH(auto share, shares) { - - if (share->getShareType() == Share::TypeLink) { - _share = qSharedPointerDynamicCast(share); - _ui->pushButton_copy->show(); - - _ui->widget_shareLink->show(); - _ui->checkBox_shareLink->setChecked(true); - - _ui->checkBox_password->setEnabled(true); - if (_share->isPasswordSet()) { - _ui->lineEdit_password->setEnabled(true); - _ui->checkBox_password->setChecked(true); - _ui->lineEdit_password->setPlaceholderText("********"); - _ui->lineEdit_password->show(); - _ui->pushButton_setPassword->show(); - } else { - _ui->checkBox_password->setChecked(false); - // _ui->lineEdit_password->setPlaceholderText("********"); - _ui->lineEdit_password->hide(); - _ui->pushButton_setPassword->hide(); - } - - _ui->checkBox_expire->setEnabled(true); - if (_share->getExpireDate().isValid()) { - _ui->calendar->setDate(_share->getExpireDate()); - _ui->calendar->setMinimumDate(QDate::currentDate().addDays(1)); - _ui->calendar->setEnabled(true); - _ui->checkBox_expire->setChecked(true); - } else { - _ui->calendar->setEnabled(false); - _ui->checkBox_expire->setChecked(false); - } - - /* - * Only directories can have public upload set - * For public links the server sets CREATE and UPDATE permissions. - */ - if (!_isFile) { - _ui->checkBox_editing->setEnabled(true); - if (_share->getPublicUpload()) { - _ui->checkBox_editing->setChecked(true); - } else { - _ui->checkBox_editing->setChecked(false); - } - } - - setShareLink(_share->getLink().toString()); - _ui->pushButton_copy->setEnabled(true); - - // Connect all shares signals to gui slots - 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))); - - break; - } - } - if( !_share.isNull() ) { - setShareCheckBoxTitle(true); - } else { - // 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(); - } - } -} - -void ShareDialog::resizeEvent(QResizeEvent *e) -{ - QDialog::resizeEvent(e); - redrawElidedUrl(); -} - -void ShareDialog::redrawElidedUrl() -{ - QString u; - - if( !_shareUrl.isEmpty() ) { - QFontMetrics fm( _ui->_labelShareLink->font() ); - int linkLengthPixel = _ui->_labelShareLink->width(); - - const QUrl realUrl(_shareUrl); - QString elidedUrl = fm.elidedText(_shareUrl, Qt::ElideRight, linkLengthPixel); - - u = QString("%2").arg(realUrl.toString(QUrl::None)).arg(elidedUrl); - } - _ui->_labelShareLink->setText(u); -} - -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); - } - redrawElidedUrl(); - -} - -void ShareDialog::slotDeleteShareFetched() -{ - _share.clear(); - _pi_link->stopAnimation(); - _ui->lineEdit_password->clear(); - _ui->_labelShareLink->clear(); - _ui->pushButton_copy->setEnabled(false); - _ui->widget_shareLink->hide(); - _ui->lineEdit_password->hide(); - _ui->pushButton_setPassword->setEnabled(false); - _ui->pushButton_setPassword->hide(); - _ui->checkBox_expire->setChecked(false); - _ui->checkBox_password->setChecked(false); - _ui->calendar->setEnabled(false); - - _shareUrl.clear(); - - setShareCheckBoxTitle(false); -} - -void ShareDialog::slotCheckBoxShareLinkClicked() -{ - qDebug() << Q_FUNC_INFO <<( _ui->checkBox_shareLink->checkState() == Qt::Checked); - if (_ui->checkBox_shareLink->checkState() == Qt::Checked) { - _pi_link->startAnimation(); - - /* - * Check the capabilities if the server requires a password for a share - * Ask for it directly - */ - if (_account->capabilities().sharePublicLinkEnforcePassword()) { - _pi_link->stopAnimation(); - _ui->checkBox_password->setChecked(true); - _ui->checkBox_password->setEnabled(false); - _ui->checkBox_password->setText(tr("Public shå requires a password")); - _ui->checkBox_expire->setEnabled(false); - _ui->checkBox_editing->setEnabled(false); - _ui->lineEdit_password->setFocus(); - _ui->pushButton_copy->hide(); - _ui->widget_shareLink->show(); - - slotCheckBoxPasswordClicked(); - return; - } - - _ui->checkBox_shareLink->setEnabled(false); - _manager->createLinkShare(_sharePath); - } else { - - 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(); - } - - - } -} - -void ShareDialog::slotCreateShareFetched(const QSharedPointer share) -{ - _pi_link->stopAnimation(); - _pi_password->stopAnimation(); - - _share = share; - getShares(); -} - -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(); - _ui->checkBox_expire->setEnabled(false); - _ui->checkBox_editing->setEnabled(false); - - slotCheckBoxPasswordClicked(); -} - -void ShareDialog::slotCheckBoxPasswordClicked() -{ - if (_ui->checkBox_password->checkState() == Qt::Checked) { - _ui->lineEdit_password->show(); - _ui->pushButton_setPassword->show(); - _ui->lineEdit_password->setPlaceholderText(tr("Please Set Password")); - _ui->lineEdit_password->setFocus(); - } else { - setPassword(QString()); - _ui->lineEdit_password->setPlaceholderText(QString()); - _pi_password->startAnimation(); - _ui->lineEdit_password->hide(); - _ui->pushButton_setPassword->hide(); - } -} - -void ShareDialog::slotCheckBoxExpireClicked() -{ - if (_ui->checkBox_expire->checkState() == Qt::Checked) - { - const QDate date = QDate::currentDate().addDays(1); - setExpireDate(date); - _ui->calendar->setDate(date); - _ui->calendar->setMinimumDate(date); - _ui->calendar->setEnabled(true); - } - else - { - setExpireDate(QDate()); - _ui->calendar->setEnabled(false); - } -} - -#ifdef Q_OS_MAC -extern void copyToPasteboard(const QString &string); -#endif - -void ShareDialog::slotPushButtonCopyLinkPressed() -{ -#ifdef Q_OS_MAC - copyToPasteboard(_shareUrl); -#else - QClipboard *clipboard = QApplication::clipboard(); - clipboard->setText(_shareUrl); -#endif -} - -void ShareDialog::slotCheckBoxEditingClicked() -{ - ShareDialog::setPublicUpload(_ui->checkBox_editing->checkState() == Qt::Checked); -} - -void ShareDialog::setPublicUpload(bool publicUpload) -{ - _ui->checkBox_editing->setEnabled(false); - _pi_editing->startAnimation(); - - _share->setPublicUpload(publicUpload); -} - -void ShareDialog::slotPublicUploadSet() -{ - _pi_editing->stopAnimation(); - _ui->checkBox_editing->setEnabled(true); -} - -void ShareDialog::setShareCheckBoxTitle(bool haveShares) -{ - const QString noSharesTitle(tr("&Share link")); - const QString haveSharesTitle(tr("&Share link")); - - if( haveShares ) { - _ui->checkBox_shareLink->setText( haveSharesTitle ); - } else { - _ui->checkBox_shareLink->setText( noSharesTitle ); + ThumbnailJob *job = new ThumbnailJob(_sharePath, _account, this); + connect(job, SIGNAL(jobFinished(int, QByteArray)), SLOT(slotThumbnailFetched(int, QByteArray))); + job->start(); } -} - -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); -} - -void ShareDialog::displayError(const QString& errMsg) -{ - _ui->errorLabel->setText( errMsg ); - _ui->errorLabel->show(); -} - -void ShareDialog::displayError(int code) -{ - const QString errMsg = tr("OCS API error code: %1").arg(code); - displayError(errMsg); + _linkWidget->getShares(); + if (_userGroupWidget != NULL) { + _userGroupWidget->getShares(); + } } void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply) @@ -578,3 +130,4 @@ void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray & } } + diff --git a/src/gui/sharedialog.h b/src/gui/sharedialog.h index 6b0c089ca..abf4ab414 100644 --- a/src/gui/sharedialog.h +++ b/src/gui/sharedialog.h @@ -1,6 +1,5 @@ /* * Copyright (C) by Roeland Jago Douma - * Copyright (C) 2015 by Klaas Freitag * * 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 @@ -16,11 +15,9 @@ #define SHAREDIALOG_H #include "accountfwd.h" -#include "QProgressIndicator.h" +#include #include -#include -#include -#include +#include namespace OCC { @@ -28,82 +25,37 @@ namespace Ui { class ShareDialog; } -class AbstractCredentials; -class QuotaInfo; -class SyncResult; -class LinkShare; -class Share; -class ShareManager; +class ShareLinkWidget; +class ShareUserGroupWidget; -/** - * @brief The ShareDialog class - * @ingroup gui - */ class ShareDialog : public QDialog { Q_OBJECT public: - explicit ShareDialog(AccountPtr account, const QString &sharePath, const QString &localPath, - bool resharingAllowed, QWidget *parent = 0); + explicit ShareDialog(AccountPtr account, + const QString &sharePath, + const QString &localPath, + bool resharingAllowed, + QWidget *parent = 0); ~ShareDialog(); + void getShares(); private slots: - void slotSharesFetched(const QList> &shares); - void slotCreateShareFetched(const QSharedPointer share); - void slotCreateShareRequiresPassword(); - void slotDeleteShareFetched(); - void slotPasswordSet(); - void slotExpireSet(); - void slotCalendarClicked(const QDate &date); - void slotCheckBoxShareLinkClicked(); - void slotCheckBoxPasswordClicked(); - void slotCheckBoxExpireClicked(); - void slotPasswordReturnPressed(); - void slotPasswordChanged(const QString& newText); - void slotPushButtonCopyLinkPressed(); - void slotThumbnailFetched(const int &statusCode, const QByteArray &reply); - void slotCheckBoxEditingClicked(); - void slotPublicUploadSet(); - - void displayError(int code, const QString &message); - void done( int r ); -private: - void setShareCheckBoxTitle(bool haveShares); - void displayError(int code); - void displayError(const QString& errMsg); - void setShareLink( const QString& url ); - void resizeEvent(QResizeEvent *e); - void redrawElidedUrl(); - void setPublicUpload(bool publicUpload); + void slotThumbnailFetched(const int &statusCode, const QByteArray &reply); +private: Ui::ShareDialog *_ui; AccountPtr _account; QString _sharePath; QString _localPath; - QString _shareUrl; -#if 0 - QString _folderAlias; - int _uploadFails; - QString _expectedSyncFile; -#endif - - bool _passwordJobRunning; - void setPassword(const QString &password); - void setExpireDate(const QDate &date); - - QProgressIndicator *_pi_link; - QProgressIndicator *_pi_password; - QProgressIndicator *_pi_date; - QProgressIndicator *_pi_editing; - - ShareManager *_manager; - QSharedPointer _share; bool _resharingAllowed; - bool _isFile; + + ShareLinkWidget *_linkWidget; + ShareUserGroupWidget *_userGroupWidget; }; } diff --git a/src/gui/sharedialog.ui b/src/gui/sharedialog.ui index dab61b8ff..75359d441 100644 --- a/src/gui/sharedialog.ui +++ b/src/gui/sharedialog.ui @@ -6,23 +6,16 @@ 0 0 - 372 - 277 + 400 + 300 - Share NewDocument.odt + Dialog - - + + - - - - TextLabel - - - @@ -42,9 +35,6 @@ - - - @@ -64,176 +54,19 @@ - - - - - - 10 - - - + + - Share link + TextLabel - - - - - 20 - - - 1 - - - 0 - - - - - 20 - - - - - QLineEdit::Password - - - - - - - - 0 - 0 - - - - Set &password - - - - - - - - - 0 - - - - - Set &expiration date - - - - - - - true - - - - - - - - - - - - 0 - 0 - - - - Set password - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - QLayout::SetDefaultConstraint - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - - - - Qt::RichText - - - true - - - - - - - Copy &link - - - - - - - - - - - Allow editing - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - + + - + Qt::Vertical @@ -246,20 +79,7 @@ - - - - - 0 - 0 - - - - TextLabel - - - - + @@ -273,19 +93,7 @@ - errorLabel - widget_shareLink - buttonBox - - - - QProgressIndicator - QWidget -
QProgressIndicator.h
- 1 -
-
diff --git a/src/gui/sharelinkwidget.cpp b/src/gui/sharelinkwidget.cpp new file mode 100644 index 000000000..9c64dde65 --- /dev/null +++ b/src/gui/sharelinkwidget.cpp @@ -0,0 +1,520 @@ +/* + * Copyright (C) by Roeland Jago Douma + * Copyright (C) 2015 by Klaas Freitag + * + * 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. + */ + +#include "sharelinkwidget.h" +#include "ui_sharelinkwidget.h" +#include "account.h" +#include "capabilities.h" + +#include "share.h" + +#include "QProgressIndicator.h" +#include +#include +#include + +namespace OCC { + +ShareLinkWidget::ShareLinkWidget(AccountPtr account, + const QString &sharePath, + const QString &localPath, + bool resharingAllowed, + bool autoShare, + QWidget *parent) : + QWidget(parent), + _ui(new Ui::ShareLinkWidget), + _account(account), + _sharePath(sharePath), + _localPath(localPath), + _passwordJobRunning(false), + _manager(NULL), + _share(NULL), + _resharingAllowed(resharingAllowed), + _autoShare(autoShare) +{ + _ui->setupUi(this); + + //Is this a file or folder? + _isFile = QFileInfo(localPath).isFile(); + + _ui->pushButton_copy->setIcon(QIcon::fromTheme("edit-copy")); + _ui->pushButton_copy->setEnabled(false); + connect(_ui->pushButton_copy, SIGNAL(clicked(bool)), SLOT(slotPushButtonCopyLinkPressed())); + + // the following progress indicator widgets are added to layouts which makes them + // automatically deleted once the dialog dies. + _pi_link = new QProgressIndicator(); + _pi_password = new QProgressIndicator(); + _pi_date = new QProgressIndicator(); + _pi_editing = new QProgressIndicator(); + _ui->horizontalLayout_shareLink->addWidget(_pi_link); + _ui->horizontalLayout_password->addWidget(_pi_password); + _ui->horizontalLayout_editing->addWidget(_pi_editing); + // _ui->horizontalLayout_expire->addWidget(_pi_date); + + 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())); + connect(_ui->lineEdit_password, SIGNAL(textChanged(QString)), this, SLOT(slotPasswordChanged(QString))); + connect(_ui->pushButton_setPassword, SIGNAL(clicked(bool)), SLOT(slotPasswordReturnPressed())); + connect(_ui->checkBox_expire, SIGNAL(clicked()), this, SLOT(slotCheckBoxExpireClicked())); + connect(_ui->calendar, SIGNAL(dateChanged(QDate)), SLOT(slotCalendarClicked(QDate))); + connect(_ui->checkBox_editing, SIGNAL(clicked()), this, SLOT(slotCheckBoxEditingClicked())); + + //Disable checkbox + _ui->checkBox_shareLink->setEnabled(false); + _pi_link->startAnimation(); + + _ui->pushButton_setPassword->setEnabled(false); + _ui->widget_shareLink->hide(); + _ui->lineEdit_password->hide(); + _ui->pushButton_setPassword->hide(); + + _ui->calendar->setEnabled(false); + + _ui->checkBox_password->setText(tr("P&assword protect")); + // check if the file is already inside of a synced folder + if( sharePath.isEmpty() ) { + // The file is not yet in an ownCloud synced folder. We could automatically + // copy it over, but that is skipped as not all questions can be answered that + // 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; + } + + // 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)); + _ui->errorLabel->hide(); + + + // Parse capabilities + + // If password is enforced then don't allow users to disable it + if (_account->capabilities().sharePublicLinkEnforcePassword()) { + _ui->checkBox_password->setEnabled(false); + } + + // If expiredate is enforced do not allow disable and set max days + if (_account->capabilities().sharePublicLinkEnforceExpireDate()) { + _ui->checkBox_expire->setEnabled(false); + _ui->calendar->setMaximumDate(QDate::currentDate().addDays( + _account->capabilities().sharePublicLinkExpireDateDays() + )); + } + + // File can't have public upload set. + if (_isFile) { + _ui->checkBox_editing->setEnabled(false); + } else { + if (!_account->capabilities().sharePublicLinkAllowUpload()) { + _ui->checkBox_editing->setEnabled(false); + } + } + + /* + * Create the share manager and connect it properly + */ + _manager = new ShareManager(_account, this); + + connect(_manager, SIGNAL(sharesFetched(QList>)), SLOT(slotSharesFetched(QList>))); + connect(_manager, SIGNAL(linkShareCreated(QSharedPointer)), SLOT(slotCreateShareFetched(const QSharedPointer))); + connect(_manager, SIGNAL(linkShareRequiresPassword()), SLOT(slotCreateShareRequiresPassword())); + connect(_manager, SIGNAL(serverError(int, QString)), SLOT(displayError(int, QString))); +} + +void ShareLinkWidget::setExpireDate(const QDate &date) +{ + _pi_date->startAnimation(); + _share->setExpireDate(date); +} + +void ShareLinkWidget::slotExpireSet() +{ + _pi_date->stopAnimation(); +} + +void ShareLinkWidget::slotCalendarClicked(const QDate &date) +{ + setExpireDate(date); +} + +ShareLinkWidget::~ShareLinkWidget() +{ + delete _ui; +} + +void ShareLinkWidget::slotPasswordReturnPressed() +{ + setPassword(_ui->lineEdit_password->text()); + _ui->lineEdit_password->setText(QString()); + _ui->lineEdit_password->setPlaceholderText(tr("Password Protected")); + _ui->lineEdit_password->clearFocus(); +} + +void ShareLinkWidget::slotPasswordChanged(const QString& newText) +{ + // disable the set-password button + _ui->pushButton_setPassword->setEnabled( newText.length() > 0 ); +} + +void ShareLinkWidget::setPassword(const QString &password) +{ + _pi_link->startAnimation(); + _pi_password->startAnimation(); + + _ui->checkBox_password->setEnabled(false); + _ui->lineEdit_password->setEnabled(false); + + if( !_share.isNull() ) { + _share->setPassword(password); + } else { + _ui->checkBox_shareLink->setEnabled(false); + _manager->createLinkShare(_sharePath, password); + } +} + +void ShareLinkWidget::slotPasswordSet() +{ + /* + * 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. + */ + getShares(); + + _pi_password->stopAnimation(); +} + +void ShareLinkWidget::getShares() +{ + _manager->fetchShares(_sharePath); +} + +void ShareLinkWidget::slotSharesFetched(const QList> &shares) +{ + const QString versionString = _account->serverVersion(); + qDebug() << Q_FUNC_INFO << versionString << "Fetched" << shares.count() << "shares"; + + //Show link checkbox now + _ui->checkBox_shareLink->setEnabled(true); + _pi_link->stopAnimation(); + + Q_FOREACH(auto share, shares) { + + if (share->getShareType() == Share::TypeLink) { + _share = qSharedPointerDynamicCast(share); + _ui->pushButton_copy->show(); + + _ui->widget_shareLink->show(); + _ui->checkBox_shareLink->setChecked(true); + + _ui->checkBox_password->setEnabled(true); + if (_share->isPasswordSet()) { + _ui->lineEdit_password->setEnabled(true); + _ui->checkBox_password->setChecked(true); + _ui->lineEdit_password->setPlaceholderText("********"); + _ui->lineEdit_password->show(); + _ui->pushButton_setPassword->show(); + } else { + _ui->checkBox_password->setChecked(false); + // _ui->lineEdit_password->setPlaceholderText("********"); + _ui->lineEdit_password->hide(); + _ui->pushButton_setPassword->hide(); + } + + _ui->checkBox_expire->setEnabled(true); + if (_share->getExpireDate().isValid()) { + _ui->calendar->setDate(_share->getExpireDate()); + _ui->calendar->setMinimumDate(QDate::currentDate().addDays(1)); + _ui->calendar->setEnabled(true); + _ui->checkBox_expire->setChecked(true); + } else { + _ui->calendar->setEnabled(false); + _ui->checkBox_expire->setChecked(false); + } + + /* + * Only directories can have public upload set + * For public links the server sets CREATE and UPDATE permissions. + */ + if (!_isFile) { + _ui->checkBox_editing->setEnabled(true); + if (_share->getPublicUpload()) { + _ui->checkBox_editing->setChecked(true); + } else { + _ui->checkBox_editing->setChecked(false); + } + } + + setShareLink(_share->getLink().toString()); + _ui->pushButton_copy->setEnabled(true); + + // Connect all shares signals to gui slots + 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))); + + break; + } + } + if( !_share.isNull() ) { + setShareCheckBoxTitle(true); + } else { + // 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 if (_autoShare) { + _ui->checkBox_shareLink->setChecked(true); + slotCheckBoxShareLinkClicked(); + } + } +} + +void ShareLinkWidget::resizeEvent(QResizeEvent *e) +{ + QWidget::resizeEvent(e); + redrawElidedUrl(); +} + +void ShareLinkWidget::redrawElidedUrl() +{ + QString u; + + if( !_shareUrl.isEmpty() ) { + QFontMetrics fm( _ui->_labelShareLink->font() ); + int linkLengthPixel = _ui->_labelShareLink->width(); + + const QUrl realUrl(_shareUrl); + QString elidedUrl = fm.elidedText(_shareUrl, Qt::ElideRight, linkLengthPixel); + + u = QString("%2").arg(realUrl.toString(QUrl::None)).arg(elidedUrl); + } + _ui->_labelShareLink->setText(u); +} + +void ShareLinkWidget::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); + } + redrawElidedUrl(); + +} + +void ShareLinkWidget::slotDeleteShareFetched() +{ + _share.clear(); + _pi_link->stopAnimation(); + _ui->lineEdit_password->clear(); + _ui->_labelShareLink->clear(); + _ui->pushButton_copy->setEnabled(false); + _ui->widget_shareLink->hide(); + _ui->lineEdit_password->hide(); + _ui->pushButton_setPassword->setEnabled(false); + _ui->pushButton_setPassword->hide(); + _ui->checkBox_expire->setChecked(false); + _ui->checkBox_password->setChecked(false); + _ui->calendar->setEnabled(false); + + _shareUrl.clear(); + + setShareCheckBoxTitle(false); +} + +void ShareLinkWidget::slotCheckBoxShareLinkClicked() +{ + qDebug() << Q_FUNC_INFO <<( _ui->checkBox_shareLink->checkState() == Qt::Checked); + if (_ui->checkBox_shareLink->checkState() == Qt::Checked) { + _pi_link->startAnimation(); + + /* + * Check the capabilities if the server requires a password for a share + * Ask for it directly + */ + if (_account->capabilities().sharePublicLinkEnforcePassword()) { + _pi_link->stopAnimation(); + _ui->checkBox_password->setChecked(true); + _ui->checkBox_password->setEnabled(false); + _ui->checkBox_password->setText(tr("Public shå requires a password")); + _ui->checkBox_expire->setEnabled(false); + _ui->checkBox_editing->setEnabled(false); + _ui->lineEdit_password->setFocus(); + _ui->pushButton_copy->hide(); + _ui->widget_shareLink->show(); + + slotCheckBoxPasswordClicked(); + return; + } + + _ui->checkBox_shareLink->setEnabled(false); + _manager->createLinkShare(_sharePath); + } else { + + 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(); + } + + + } +} + +void ShareLinkWidget::slotCreateShareFetched(const QSharedPointer share) +{ + _pi_link->stopAnimation(); + _pi_password->stopAnimation(); + + _share = share; + getShares(); +} + +void ShareLinkWidget::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(); + _ui->checkBox_expire->setEnabled(false); + _ui->checkBox_editing->setEnabled(false); + + slotCheckBoxPasswordClicked(); +} + +void ShareLinkWidget::slotCheckBoxPasswordClicked() +{ + if (_ui->checkBox_password->checkState() == Qt::Checked) { + _ui->lineEdit_password->show(); + _ui->pushButton_setPassword->show(); + _ui->lineEdit_password->setPlaceholderText(tr("Please Set Password")); + _ui->lineEdit_password->setFocus(); + } else { + setPassword(QString()); + _ui->lineEdit_password->setPlaceholderText(QString()); + _pi_password->startAnimation(); + _ui->lineEdit_password->hide(); + _ui->pushButton_setPassword->hide(); + } +} + +void ShareLinkWidget::slotCheckBoxExpireClicked() +{ + if (_ui->checkBox_expire->checkState() == Qt::Checked) + { + const QDate date = QDate::currentDate().addDays(1); + setExpireDate(date); + _ui->calendar->setDate(date); + _ui->calendar->setMinimumDate(date); + _ui->calendar->setEnabled(true); + } + else + { + setExpireDate(QDate()); + _ui->calendar->setEnabled(false); + } +} + +#ifdef Q_OS_MAC +extern void copyToPasteboard(const QString &string); +#endif + +void ShareLinkWidget::slotPushButtonCopyLinkPressed() +{ +#ifdef Q_OS_MAC + copyToPasteboard(_shareUrl); +#else + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(_shareUrl); +#endif +} + +void ShareLinkWidget::slotCheckBoxEditingClicked() +{ + ShareLinkWidget::setPublicUpload(_ui->checkBox_editing->checkState() == Qt::Checked); +} + +void ShareLinkWidget::setPublicUpload(bool publicUpload) +{ + _ui->checkBox_editing->setEnabled(false); + _pi_editing->startAnimation(); + + _share->setPublicUpload(publicUpload); +} + +void ShareLinkWidget::slotPublicUploadSet() +{ + _pi_editing->stopAnimation(); + _ui->checkBox_editing->setEnabled(true); +} + +void ShareLinkWidget::setShareCheckBoxTitle(bool haveShares) +{ + const QString noSharesTitle(tr("&Share link")); + const QString haveSharesTitle(tr("&Share link")); + + if( haveShares ) { + _ui->checkBox_shareLink->setText( haveSharesTitle ); + } else { + _ui->checkBox_shareLink->setText( noSharesTitle ); + } + +} + +void ShareLinkWidget::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); +} + +void ShareLinkWidget::displayError(const QString& errMsg) +{ + _ui->errorLabel->setText( errMsg ); + _ui->errorLabel->show(); +} + +void ShareLinkWidget::displayError(int code) +{ + const QString errMsg = tr("OCS API error code: %1").arg(code); + displayError(errMsg); +} + +} diff --git a/src/gui/sharelinkwidget.h b/src/gui/sharelinkwidget.h new file mode 100644 index 000000000..6fb78ffad --- /dev/null +++ b/src/gui/sharelinkwidget.h @@ -0,0 +1,114 @@ +/* + * Copyright (C) by Roeland Jago Douma + * Copyright (C) 2015 by Klaas Freitag + * + * 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 SHARELINKWIDGET_H +#define SHARELINKWIDGET_H + +#include "accountfwd.h" +#include "QProgressIndicator.h" +#include +#include +#include +#include + +namespace OCC { + +namespace Ui { +class ShareLinkWidget; +} + +class AbstractCredentials; +class QuotaInfo; +class SyncResult; +class LinkShare; +class Share; +class ShareManager; + +/** + * @brief The ShareDialog class + * @ingroup gui + */ +class ShareLinkWidget : public QWidget +{ + Q_OBJECT + +public: + explicit ShareLinkWidget(AccountPtr account, + const QString &sharePath, + const QString &localPath, + bool resharingAllowed, + bool autoShare = false, + QWidget *parent = 0); + ~ShareLinkWidget(); + void getShares(); + +private slots: + void slotSharesFetched(const QList> &shares); + void slotCreateShareFetched(const QSharedPointer share); + void slotCreateShareRequiresPassword(); + void slotDeleteShareFetched(); + void slotPasswordSet(); + void slotExpireSet(); + void slotCalendarClicked(const QDate &date); + void slotCheckBoxShareLinkClicked(); + void slotCheckBoxPasswordClicked(); + void slotCheckBoxExpireClicked(); + void slotPasswordReturnPressed(); + void slotPasswordChanged(const QString& newText); + void slotPushButtonCopyLinkPressed(); + void slotCheckBoxEditingClicked(); + void slotPublicUploadSet(); + + void displayError(int code, const QString &message); + +private: + void setShareCheckBoxTitle(bool haveShares); + void displayError(int code); + void displayError(const QString& errMsg); + void setShareLink( const QString& url ); + void resizeEvent(QResizeEvent *e); + void redrawElidedUrl(); + void setPublicUpload(bool publicUpload); + + Ui::ShareLinkWidget *_ui; + AccountPtr _account; + QString _sharePath; + QString _localPath; + QString _shareUrl; +#if 0 + QString _folderAlias; + int _uploadFails; + QString _expectedSyncFile; +#endif + + bool _passwordJobRunning; + void setPassword(const QString &password); + void setExpireDate(const QDate &date); + + QProgressIndicator *_pi_link; + QProgressIndicator *_pi_password; + QProgressIndicator *_pi_date; + QProgressIndicator *_pi_editing; + + ShareManager *_manager; + QSharedPointer _share; + + bool _resharingAllowed; + bool _isFile; + bool _autoShare; +}; + +} + +#endif // SHARELINKWIDGET_H diff --git a/src/gui/sharelinkwidget.ui b/src/gui/sharelinkwidget.ui new file mode 100644 index 000000000..71aa051b8 --- /dev/null +++ b/src/gui/sharelinkwidget.ui @@ -0,0 +1,218 @@ + + + OCC::ShareLinkWidget + + + + 0 + 0 + 372 + 212 + + + + Share NewDocument.odt + + + + + + 10 + + + + + Share link + + + + + + + + + + 0 + 0 + + + + TextLabel + + + + + + + + 20 + + + 1 + + + 0 + + + + + 20 + + + + + QLineEdit::Password + + + + + + + + 0 + 0 + + + + Set &password + + + + + + + + + 0 + + + + + Set &expiration date + + + + + + + true + + + + + + + + + + + + 0 + 0 + + + + Set password + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + + + + Qt::RichText + + + true + + + + + + + Copy &link + + + + + + + + + + + Allow editing + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + errorLabel + widget_shareLink + verticalSpacer + + + + + diff --git a/src/gui/shareusergroupdialog.ui b/src/gui/shareusergroupdialog.ui deleted file mode 100644 index 99c337d5e..000000000 --- a/src/gui/shareusergroupdialog.ui +++ /dev/null @@ -1,133 +0,0 @@ - - - OCC::ShareUserGroupDialog - - - - 0 - 0 - 372 - 505 - - - - Share NewDocument.odt - - - - - - - - TextLabel - - - - - - - - 0 - 0 - - - - - 75 - true - - - - share label - - - - - - - - - - - 0 - 0 - - - - - 50 - false - - - - ownCloud Path: - - - - - - - - - - 0 - 0 - - - - TextLabel - - - - - - - - 0 - 0 - - - - QDialogButtonBox::Close - - - - - - - - - Shares - - - - - - - - - - - - - - Search - - - - - - - - - - - QProgressIndicator - QWidget -
QProgressIndicator.h
- 1 -
-
- - -
diff --git a/src/gui/shareusergroupdialog.cpp b/src/gui/shareusergroupwidget.cpp similarity index 83% rename from src/gui/shareusergroupdialog.cpp rename to src/gui/shareusergroupwidget.cpp index 0799869e2..d359fe91f 100644 --- a/src/gui/shareusergroupdialog.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -11,9 +11,9 @@ * for more details. */ -#include "shareusergroupdialog.h" -#include "ui_shareusergroupdialog.h" -#include "ui_sharedialogshare.h" +#include "shareusergroupwidget.h" +#include "ui_shareusergroupwidget.h" +#include "ui_sharewidget.h" #include "account.h" #include "json.h" #include "folderman.h" @@ -36,9 +36,9 @@ namespace OCC { -ShareUserGroupDialog::ShareUserGroupDialog(AccountPtr account, const QString &sharePath, const QString &localPath, bool resharingAllowed, QWidget *parent) : - QDialog(parent), - _ui(new Ui::ShareUserGroupDialog), +ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account, const QString &sharePath, const QString &localPath, bool resharingAllowed, QWidget *parent) : + QWidget(parent), + _ui(new Ui::ShareUserGroupWidget), _account(account), _sharePath(sharePath), _localPath(localPath), @@ -64,18 +64,12 @@ ShareUserGroupDialog::ShareUserGroupDialog(AccountPtr account, const QString &sh connect(_completer, SIGNAL(activated(QModelIndex)), SLOT(slotCompleterActivated(QModelIndex))); } -void ShareUserGroupDialog::done( int r ) { - ConfigFile cfg; - cfg.saveGeometry(this); - QDialog::done(r); -} - -ShareUserGroupDialog::~ShareUserGroupDialog() +ShareUserGroupWidget::~ShareUserGroupWidget() { delete _ui; } -void ShareUserGroupDialog::on_shareeLineEdit_textChanged(const QString &text) +void ShareUserGroupWidget::on_shareeLineEdit_textChanged(const QString &text) { if (text == "") { _ui->searchPushButton->setEnabled(false); @@ -84,7 +78,7 @@ void ShareUserGroupDialog::on_shareeLineEdit_textChanged(const QString &text) } } -void ShareUserGroupDialog::on_searchPushButton_clicked() +void ShareUserGroupWidget::on_searchPushButton_clicked() { _completerModel = new ShareeModel(_account, _ui->shareeLineEdit->text(), @@ -94,18 +88,18 @@ void ShareUserGroupDialog::on_searchPushButton_clicked() _completerModel->fetch(); } -void ShareUserGroupDialog::slotUpdateCompletion() { +void ShareUserGroupWidget::slotUpdateCompletion() { _completer->setModel(_completerModel); _ui->shareeLineEdit->setCompleter(_completer); _completer->complete(); } -void ShareUserGroupDialog::getShares() +void ShareUserGroupWidget::getShares() { _manager->fetchShares(_sharePath); } -void ShareUserGroupDialog::slotSharesFetched(const QList> &shares) +void ShareUserGroupWidget::slotSharesFetched(const QList> &shares) { const QString versionString = _account->serverVersion(); qDebug() << Q_FUNC_INFO << versionString << "Fetched" << shares.count() << "shares"; @@ -121,13 +115,13 @@ void ShareUserGroupDialog::slotSharesFetched(const QList> continue; } - ShareDialogShare *s = new ShareDialogShare(share, this); + ShareWidget *s = new ShareWidget(share, this); _ui->sharesLayout->addWidget(s); } _ui->sharesLayout->invalidate(); } -void ShareUserGroupDialog::slotCompleterActivated(const QModelIndex & index) { +void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex & index) { auto sharee = _completerModel->getSharee(index.row()); if (sharee.isNull()) { @@ -140,10 +134,10 @@ void ShareUserGroupDialog::slotCompleterActivated(const QModelIndex & index) { Share::PermissionRead); } -ShareDialogShare::ShareDialogShare(QSharedPointer share, +ShareWidget::ShareWidget(QSharedPointer share, QWidget *parent) : QWidget(parent), - _ui(new Ui::ShareDialogShare), + _ui(new Ui::ShareWidget), _share(share) { _ui->setupUi(this); @@ -172,18 +166,18 @@ ShareDialogShare::ShareDialogShare(QSharedPointer share, connect(share.data(), SIGNAL(shareDeleted()), SLOT(slotShareDeleted())); } -void ShareDialogShare::on_deleteShareButton_clicked() +void ShareWidget::on_deleteShareButton_clicked() { setEnabled(false); _share->deleteShare(); } -ShareDialogShare::~ShareDialogShare() +ShareWidget::~ShareWidget() { delete _ui; } -void ShareDialogShare::slotPermissionsChanged() +void ShareWidget::slotPermissionsChanged() { setEnabled(false); @@ -208,12 +202,12 @@ void ShareDialogShare::slotPermissionsChanged() _share->setPermissions(permissions); } -void ShareDialogShare::slotShareDeleted() +void ShareWidget::slotShareDeleted() { deleteLater(); } -void ShareDialogShare::slotPermissionsSet() +void ShareWidget::slotPermissionsSet() { setEnabled(true); } diff --git a/src/gui/shareusergroupdialog.h b/src/gui/shareusergroupwidget.h similarity index 78% rename from src/gui/shareusergroupdialog.h rename to src/gui/shareusergroupwidget.h index 9a53432f3..b14896afc 100644 --- a/src/gui/shareusergroupdialog.h +++ b/src/gui/shareusergroupwidget.h @@ -11,8 +11,8 @@ * for more details. */ -#ifndef SHAREDIALOG_UG_H -#define SHAREDIALOG_UG_H +#ifndef SHAREUSERGROUPWIDGET_H +#define SHAREUSERGROUPWIDGET_H #include "accountfwd.h" #include "QProgressIndicator.h" @@ -28,8 +28,8 @@ class QCompleter; namespace OCC { namespace Ui { -class ShareUserGroupDialog; -class ShareDialogShare; +class ShareUserGroupWidget; +class ShareWidget; } class AbstractCredentials; @@ -39,16 +39,16 @@ class Share; class ShareManager; class ShareeModel; -class ShareDialogShare : public QWidget +class ShareWidget : public QWidget { Q_OBJECT public: - explicit ShareDialogShare(QSharedPointer Share, QWidget *parent = 0); - ~ShareDialogShare(); + explicit ShareWidget(QSharedPointer Share, QWidget *parent = 0); + ~ShareWidget(); signals: - void shareDeleted(ShareDialogShare *share); + void shareDeleted(ShareWidget *share); private slots: void on_deleteShareButton_clicked(); @@ -58,7 +58,7 @@ private slots: void slotPermissionsSet(); private: - Ui::ShareDialogShare *_ui; + Ui::ShareWidget *_ui; QSharedPointer _share; }; @@ -67,25 +67,23 @@ private: * @brief The ShareDialog (user/group) class * @ingroup gui */ -class ShareUserGroupDialog : public QDialog +class ShareUserGroupWidget : public QWidget { Q_OBJECT public: - explicit ShareUserGroupDialog(AccountPtr account, + explicit ShareUserGroupWidget(AccountPtr account, const QString &sharePath, const QString &localPath, bool resharingAllowed, QWidget *parent = 0); - ~ShareUserGroupDialog(); + ~ShareUserGroupWidget(); public slots: void getShares(); private slots: void slotSharesFetched(const QList> &shares); - void done( int r ); - void on_shareeLineEdit_textChanged(const QString &text); void on_searchPushButton_clicked(); @@ -94,7 +92,7 @@ private slots: void slotCompleterActivated(const QModelIndex & index); private: - Ui::ShareUserGroupDialog *_ui; + Ui::ShareUserGroupWidget *_ui; AccountPtr _account; QString _sharePath; QString _localPath; @@ -110,4 +108,4 @@ private: } -#endif // SHAREDIALOG_UG_H +#endif // SHAREUSERGROUPWIDGET_H diff --git a/src/gui/shareusergroupwidget.ui b/src/gui/shareusergroupwidget.ui new file mode 100644 index 000000000..19c2926f9 --- /dev/null +++ b/src/gui/shareusergroupwidget.ui @@ -0,0 +1,65 @@ + + + OCC::ShareUserGroupWidget + + + + 0 + 0 + 372 + 271 + + + + Share NewDocument.odt + + + + QLayout::SetDefaultConstraint + + + + + + + + + + Search + + + + + + + + + true + + + Shares + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + diff --git a/src/gui/sharedialogshare.ui b/src/gui/sharewidget.ui similarity index 94% rename from src/gui/sharedialogshare.ui rename to src/gui/sharewidget.ui index 614dc94e2..0e323cc87 100644 --- a/src/gui/sharedialogshare.ui +++ b/src/gui/sharewidget.ui @@ -1,7 +1,7 @@ - OCC::ShareDialogShare - + OCC::ShareWidget + true diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp index 5b59bb9fa..a3ffa9327 100644 --- a/src/gui/socketapi.cpp +++ b/src/gui/socketapi.cpp @@ -404,51 +404,6 @@ void SocketApi::command_SHARE(const QString& localFile, QIODevice* socket) } } -void SocketApi::command_SHARE_USER_GROUP(const QString& localFile, QIODevice* socket) -{ - if (!socket) { - qDebug() << Q_FUNC_INFO << "No valid socket object."; - return; - } - - qDebug() << Q_FUNC_INFO << localFile; - - Folder *shareFolder = FolderMan::instance()->folderForPath(localFile); - if (!shareFolder) { - const QString message = QLatin1String("SHARE:NOP:")+QDir::toNativeSeparators(localFile); - // files that are not within a sync folder are not synced. - sendMessage(socket, message); - } else if (!shareFolder->accountState()->isConnected()) { - const QString message = QLatin1String("SHARE:NOTCONNECTED:")+QDir::toNativeSeparators(localFile); - // if the folder isn't connected, don't open the share dialog - sendMessage(socket, message); - } else { - const QString folderForPath = shareFolder->path(); - const QString remotePath = shareFolder->remotePath() + localFile.right(localFile.count()-folderForPath.count()+1); - - // Can't share root folder - if (QDir::cleanPath(remotePath) == "/") { - const QString message = QLatin1String("SHARE:CANNOTSHAREROOT:")+QDir::toNativeSeparators(localFile); - sendMessage(socket, message); - return; - } - - SyncJournalFileRecord rec = dbFileRecord_capi(shareFolder, localFile); - - bool allowReshare = true; // lets assume the good - if( rec.isValid() ) { - // check the permission: Is resharing allowed? - if( !rec._remotePerm.contains('R') ) { - allowReshare = false; - } - } - const QString message = QLatin1String("SHARE:OK:")+QDir::toNativeSeparators(localFile); - sendMessage(socket, message); - - emit shareUserGroupCommandReceived(remotePath, localFile, allowReshare); - } -} - void SocketApi::command_VERSION(const QString&, QIODevice* socket) { sendMessage(socket, QLatin1String("VERSION:" MIRALL_VERSION_STRING ":" MIRALL_SOCKET_API_VERSION)); diff --git a/src/gui/socketapi.h b/src/gui/socketapi.h index 482f15158..f17660e4a 100644 --- a/src/gui/socketapi.h +++ b/src/gui/socketapi.h @@ -75,7 +75,6 @@ private: Q_INVOKABLE void command_RETRIEVE_FOLDER_STATUS(const QString& argument, QIODevice* socket); Q_INVOKABLE void command_RETRIEVE_FILE_STATUS(const QString& argument, QIODevice* socket); Q_INVOKABLE void command_SHARE(const QString& localFile, QIODevice* socket); - Q_INVOKABLE void command_SHARE_USER_GROUP(const QString& localFile, QIODevice* socket); Q_INVOKABLE void command_VERSION(const QString& argument, QIODevice* socket);