diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 358fc8a418..20bc90b1fa 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -147,8 +147,8 @@ Application::Application(int &argc, char **argv) : slotAccountStateAdded(ai); } - connect(FolderMan::instance()->socketApi(), SIGNAL(shareCommandReceived(QString)), - _gui, SLOT(slotShowShareDialog(QString))); + connect(FolderMan::instance()->socketApi(), SIGNAL(shareCommandReceived(QString, QString)), + _gui, SLOT(slotShowShareDialog(QString, QString))); // startup procedure. connect(&_checkConnectionTimer, SIGNAL(timeout()), this, SLOT(slotCheckConnection())); diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 18a4518574..9183a668bb 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -642,12 +642,12 @@ void ownCloudGui::raiseDialog( QWidget *raiseWidget ) } -void ownCloudGui::slotShowShareDialog(const QString &path) +void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &localPath) { qDebug() << Q_FUNC_INFO << "Opening share dialog"; - ShareDialog *w = new ShareDialog; + ShareDialog *w = new ShareDialog(sharePath, localPath); + w->getShares(); w->setAttribute( Qt::WA_DeleteOnClose, true ); - w->setPath(path); w->show(); } diff --git a/src/gui/owncloudgui.h b/src/gui/owncloudgui.h index f3f0c84683..18dccae871 100644 --- a/src/gui/owncloudgui.h +++ b/src/gui/owncloudgui.h @@ -70,7 +70,7 @@ public slots: void slotHelp(); void slotOpenPath(const QString& path); void slotAccountStateChanged(); - void slotShowShareDialog(const QString &path); + void slotShowShareDialog(const QString &sharePath, const QString &localPath); private slots: void slotDisplayIdle(); diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index 73cb504206..49e86f8e71 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -4,8 +4,11 @@ #include "account.h" #include "json.h" #include "folderman.h" +#include "QProgressIndicator.h" #include #include +#include +#include namespace { int SHARETYPE_PUBLIC = 3; @@ -13,51 +16,64 @@ namespace { namespace OCC { -ShareDialog::ShareDialog(QWidget *parent) : - QDialog(parent), - _ui(new Ui::ShareDialog) +ShareDialog::ShareDialog(const QString &sharePath, const QString &localPath, QWidget *parent) : + QDialog(parent), + _ui(new Ui::ShareDialog), + _sharePath(sharePath), + _localPath(localPath) { setAttribute(Qt::WA_DeleteOnClose); _ui->setupUi(this); _ui->pushButton_copy->setIcon(QIcon::fromTheme("edit-copy")); layout()->setSizeConstraint(QLayout::SetFixedSize); - QMovie *movie = new QMovie("/home/azelphur/ownCloud-share-tools/loading-icon.gif"); - movie->start(); - _ui->labelShareSpinner->setMovie(movie); - _ui->labelShareSpinner->hide(); - _ui->labelPasswordSpinner->setMovie(movie); - _ui->labelPasswordSpinner->hide(); + _pi_link = new QProgressIndicator(); + _pi_password = new QProgressIndicator(); + _pi_date = new QProgressIndicator(); + _ui->horizontalLayout_shareLink->addWidget(_pi_link); + _ui->horizontalLayout_password->addWidget(_pi_password); + _ui->horizontalLayout_expire->addWidget(_pi_date); - _ui->labelCalendarSpinner->setMovie(movie); - _ui->labelCalendarSpinner->hide(); 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->checkBox_expire, SIGNAL(clicked()), this, SLOT(slotCheckBoxExpireClicked())); connect(_ui->calendar, SIGNAL(clicked(QDate)), SLOT(slotCalendarClicked(QDate))); - _ui->labelShareSpinner->hide(); - _ui->lineEdit_shareLink->hide(); - _ui->pushButton_copy->hide(); + _ui->widget_shareLink->hide(); _ui->lineEdit_password->hide(); - _ui->checkBox_password->hide(); - _ui->checkBox_expire->hide(); _ui->calendar->hide(); - _ui->lineEdit_shareGroup->setPlaceholderText(tr("Share with group...")); - _ui->lineEdit_shareUser->setPlaceholderText(tr("Share with user...")); - _ui->lineEdit_password->setPlaceholderText(tr("Choose a password for the public link")); + + QFileInfo f_info(_localPath); + QFileIconProvider icon_provider; + QIcon icon = icon_provider.icon(f_info); + _ui->label_icon->setPixmap(icon.pixmap(40,40)); + if (f_info.isDir()) { + _ui->lineEdit_name->setText(f_info.dir().dirName()); + _ui->lineEdit_type->setText("Directory"); + } else { + _ui->lineEdit_name->setText(f_info.fileName()); + _ui->lineEdit_type->setText("File"); + } + _ui->lineEdit_localPath->setText(_localPath); + _ui->lineEdit_sharePath->setText(_sharePath); } -void ShareDialog::setExpireDate(const QString &date) +void ShareDialog::setExpireDate(const QDate &date) { - _ui->labelCalendarSpinner->show(); - QUrl url = Account::concatUrlPath(AccountManager::instance()->account()->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares/").append(QString::number(_public_share_id))); + _pi_date->startAnimation(); + QUrl url = Account::concatUrlPath(AccountManager::instance()->account()->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares/%1").arg(_public_share_id)); QUrl postData; QList > getParams; QList > postParams; getParams.append(qMakePair(QString::fromLatin1("format"), QString::fromLatin1("json"))); - postParams.append(qMakePair(QString::fromLatin1("expireDate"), date)); + + if (date.isValid()) { + postParams.append(qMakePair(QString::fromLatin1("expireDate"), date.toString("yyyy-MM-dd"))); + } else { + postParams.append(qMakePair(QString::fromLatin1("expireDate"), QString())); + } + url.setQueryItems(getParams); postData.setQueryItems(postParams); OcsShareJob *job = new OcsShareJob("PUT", url, postData, AccountManager::instance()->account(), this); @@ -65,25 +81,25 @@ void ShareDialog::setExpireDate(const QString &date) job->start(); } -void ShareDialog::slotExpireSet(const QString & /* reply */) +void ShareDialog::slotExpireSet(const QString &reply) { - _ui->labelCalendarSpinner->hide(); + QString message; + int code = checkJsonReturnCode(reply, message); + + qDebug() << Q_FUNC_INFO << "Status code: " << code; + if (code != 100) { + QMessageBox msgBox; + msgBox.setText(message); + msgBox.setWindowTitle(QString("Server replied with code %1").arg(code)); + msgBox.exec(); + } + + _pi_date->stopAnimation(); } void ShareDialog::slotCalendarClicked(const QDate &date) { - ShareDialog::setExpireDate(date.toString("yyyy-MM-dd")); -} - -QString ShareDialog::getPath() -{ - return _path; -} - -void ShareDialog::setPath(const QString &path) -{ - _path = path; - ShareDialog::getShares(); + ShareDialog::setExpireDate(date); } ShareDialog::~ShareDialog() @@ -94,14 +110,15 @@ ShareDialog::~ShareDialog() void ShareDialog::slotPasswordReturnPressed() { ShareDialog::setPassword(_ui->lineEdit_password->text()); - _ui->lineEdit_password->setPlaceholderText(tr("Password Protected")); _ui->lineEdit_password->setText(QString()); + _ui->lineEdit_password->setPlaceholderText(tr("Password Protected")); + _ui->lineEdit_password->clearFocus(); } -void ShareDialog::setPassword(QString password) +void ShareDialog::setPassword(const QString &password) { - _ui->labelPasswordSpinner->show(); - QUrl url = Account::concatUrlPath(AccountManager::instance()->account()->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares/").append(QString::number(_public_share_id))); + _pi_password->startAnimation(); + QUrl url = Account::concatUrlPath(AccountManager::instance()->account()->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares/%1").arg(_public_share_id)); QUrl postData; QList > getParams; QList > postParams; @@ -114,18 +131,37 @@ void ShareDialog::setPassword(QString password) job->start(); } -void ShareDialog::slotPasswordSet(const QString & /* reply */) +void ShareDialog::slotPasswordSet(const QString &reply) { - _ui->labelPasswordSpinner->hide(); + QString message; + int code = checkJsonReturnCode(reply, message); + + qDebug() << Q_FUNC_INFO << "Status code: " << code; + + if (code != 100) { + QMessageBox msgBox; + msgBox.setText(message); + msgBox.setWindowTitle(QString("Server replied with code %1").arg(code)); + msgBox.exec(); + } else { + /* + * 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() { - this->setWindowTitle(tr("Sharing %1").arg(_path)); + this->setWindowTitle(tr("Sharing %1").arg(_sharePath)); QUrl url = Account::concatUrlPath(AccountManager::instance()->account()->url(), QLatin1String("ocs/v1.php/apps/files_sharing/api/v1/shares")); QList > params; params.append(qMakePair(QString::fromLatin1("format"), QString::fromLatin1("json"))); - params.append(qMakePair(QString::fromLatin1("path"), _path)); + params.append(qMakePair(QString::fromLatin1("path"), _sharePath)); url.setQueryItems(params); OcsShareJob *job = new OcsShareJob("GET", url, QUrl(), AccountManager::instance()->account(), this); connect(job, SIGNAL(jobFinished(QString)), this, SLOT(slotSharesFetched(QString))); @@ -134,34 +170,42 @@ void ShareDialog::getShares() void ShareDialog::slotSharesFetched(const QString &reply) { + QString message; + int code = checkJsonReturnCode(reply, message); + + qDebug() << Q_FUNC_INFO << "Status code: " << code; + if (code != 100) { + QMessageBox msgBox; + msgBox.setText(message); + msgBox.setWindowTitle(QString("Server replied with code %1").arg(code)); + msgBox.exec(); + } + bool success = false; QVariantMap json = QtJson::parse(reply, success).toMap(); ShareDialog::_shares = json.value("ocs").toMap().values("data")[0].toList(); - for(int i = 0; i < ShareDialog::_shares.count(); i++) + Q_FOREACH(auto share, ShareDialog::_shares) { - QVariantMap data = ShareDialog::_shares[i].toMap(); + QVariantMap data = share.toMap(); if (data.value("share_type").toInt() == SHARETYPE_PUBLIC) { _public_share_id = data.value("id").toULongLong(); - _ui->lineEdit_shareLink->show(); - _ui->pushButton_copy->show(); - _ui->checkBox_password->show(); - _ui->checkBox_expire->show(); - _ui->pushButton_copy->show(); + _ui->widget_shareLink->show(); _ui->checkBox_shareLink->setChecked(true); if (data.value("share_with").isValid()) { _ui->checkBox_password->setChecked(true); - _ui->lineEdit_password->setText("********"); + _ui->lineEdit_password->setPlaceholderText("********"); _ui->lineEdit_password->show(); } if (data.value("expiration").isValid()) { _ui->calendar->setSelectedDate(QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00")); + _ui->calendar->setMinimumDate(QDate::currentDate().addDays(1)); _ui->calendar->show(); _ui->checkBox_expire->setChecked(true); } @@ -172,14 +216,22 @@ void ShareDialog::slotSharesFetched(const QString &reply) } } -void ShareDialog::slotDeleteShareFetched(const QString & /* reply */) +void ShareDialog::slotDeleteShareFetched(const QString &reply) { - _ui->labelShareSpinner->hide(); - _ui->lineEdit_shareLink->hide(); - _ui->pushButton_copy->hide(); + QString message; + int code = checkJsonReturnCode(reply, message); + + qDebug() << Q_FUNC_INFO << "Status code: " << code; + if (code != 100) { + QMessageBox msgBox; + msgBox.setText(message); + msgBox.setWindowTitle(QString("Server replied with code %1").arg(code)); + msgBox.exec(); + } + + _pi_link->stopAnimation(); + _ui->widget_shareLink->hide(); _ui->lineEdit_password->hide(); - _ui->checkBox_password->hide(); - _ui->checkBox_expire->hide(); _ui->calendar->hide(); } @@ -187,13 +239,13 @@ void ShareDialog::slotCheckBoxShareLinkClicked() { if (_ui->checkBox_shareLink->checkState() == Qt::Checked) { - _ui->labelShareSpinner->show(); + _pi_link->startAnimation(); QUrl url = Account::concatUrlPath(AccountManager::instance()->account()->url(), QLatin1String("ocs/v1.php/apps/files_sharing/api/v1/shares")); QUrl postData; QList > getParams; QList > postParams; getParams.append(qMakePair(QString::fromLatin1("format"), QString::fromLatin1("json"))); - postParams.append(qMakePair(QString::fromLatin1("path"), _path)); + postParams.append(qMakePair(QString::fromLatin1("path"), _sharePath)); postParams.append(qMakePair(QString::fromLatin1("shareType"), QString::number(SHARETYPE_PUBLIC))); url.setQueryItems(getParams); postData.setQueryItems(postParams); @@ -203,8 +255,8 @@ void ShareDialog::slotCheckBoxShareLinkClicked() } else { - _ui->labelShareSpinner->show(); - QUrl url = Account::concatUrlPath(AccountManager::instance()->account()->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares/").append(QString::number(_public_share_id))); + _pi_link->startAnimation(); + QUrl url = Account::concatUrlPath(AccountManager::instance()->account()->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares/%1").arg(_public_share_id)); QList > getParams; getParams.append(qMakePair(QString::fromLatin1("format"), QString::fromLatin1("json"))); url.setQueryItems(getParams); @@ -216,18 +268,25 @@ void ShareDialog::slotCheckBoxShareLinkClicked() void ShareDialog::slotCreateShareFetched(const QString &reply) { - qDebug() << Q_FUNC_INFO << reply; - _ui->labelShareSpinner->hide(); + QString message; + int code = checkJsonReturnCode(reply, message); + + if (code != 100) { + QMessageBox msgBox; + msgBox.setText(message); + msgBox.setWindowTitle(QString("Server replied with code %1").arg(code)); + msgBox.exec(); + return; + } + + _pi_link->stopAnimation(); bool success; QVariantMap json = QtJson::parse(reply, success).toMap(); _public_share_id = json.value("ocs").toMap().values("data")[0].toMap().value("id").toULongLong(); QString url = json.value("ocs").toMap().values("data")[0].toMap().value("url").toString(); _ui->lineEdit_shareLink->setText(url); - _ui->lineEdit_shareLink->show(); - _ui->pushButton_copy->show(); - _ui->checkBox_password->show(); - _ui->checkBox_expire->show(); - _ui->pushButton_copy->show(); + + _ui->widget_shareLink->show(); } void ShareDialog::slotCheckBoxPasswordClicked() @@ -235,11 +294,13 @@ void ShareDialog::slotCheckBoxPasswordClicked() if (_ui->checkBox_password->checkState() == Qt::Checked) { _ui->lineEdit_password->show(); + _ui->lineEdit_password->setPlaceholderText(tr("Choose a password for the public link")); } else { ShareDialog::setPassword(QString()); - _ui->labelPasswordSpinner->show(); + _ui->lineEdit_password->setPlaceholderText(QString()); + _pi_password->startAnimation(); _ui->lineEdit_password->hide(); } } @@ -248,18 +309,36 @@ void ShareDialog::slotCheckBoxExpireClicked() { if (_ui->checkBox_expire->checkState() == Qt::Checked) { - QDate date = QDate::currentDate().addDays(1); - ShareDialog::setExpireDate(date.toString("dd-MM-yyyy")); + const QDate date = QDate::currentDate().addDays(1); + ShareDialog::setExpireDate(date); _ui->calendar->setSelectedDate(date); + _ui->calendar->setMinimumDate(date); _ui->calendar->show(); } else { - ShareDialog::setExpireDate(QString()); + ShareDialog::setExpireDate(QDate()); _ui->calendar->hide(); } } +int ShareDialog::checkJsonReturnCode(const QString &reply, QString &message) +{ + bool success; + QVariantMap json = QtJson::parse(reply, success).toMap(); + + if (!success) { + qDebug() << Q_FUNC_INFO << "Failed to parse reply"; + } + + //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; +} + + OcsShareJob::OcsShareJob(const QByteArray &verb, const QUrl &url, const QUrl &postData, AccountPtr account, QObject* parent) : AbstractNetworkJob(account, "", parent), _verb(verb), diff --git a/src/gui/sharedialog.h b/src/gui/sharedialog.h index f7a30c705f..c0a8d45a3f 100644 --- a/src/gui/sharedialog.h +++ b/src/gui/sharedialog.h @@ -15,7 +15,9 @@ #define SHAREDIALOG_H #include "networkjobs.h" +#include "QProgressIndicator.h" #include +#include namespace OCC { @@ -49,11 +51,9 @@ class ShareDialog : public QDialog Q_OBJECT public: - explicit ShareDialog(QWidget *parent = 0); + explicit ShareDialog(const QString &sharePath, const QString &localPath, QWidget *parent = 0); ~ShareDialog(); void getShares(); - void setPath(const QString &path); - QString getPath(); private slots: void slotSharesFetched(const QString &reply); void slotCreateShareFetched(const QString &reply); @@ -67,11 +67,17 @@ private slots: void slotPasswordReturnPressed(); private: Ui::ShareDialog *_ui; - QString _path; + QString _sharePath; + QString _localPath; QList _shares; qulonglong _public_share_id; - void setPassword(QString password); - void setExpireDate(const QString &date); + void setPassword(const QString &password); + void setExpireDate(const QDate &date); + int checkJsonReturnCode(const QString &reply, QString &message); + + QProgressIndicator *_pi_link; + QProgressIndicator *_pi_password; + QProgressIndicator *_pi_date; }; } diff --git a/src/gui/sharedialog.ui b/src/gui/sharedialog.ui index 43239fcc26..ef1628212b 100644 --- a/src/gui/sharedialog.ui +++ b/src/gui/sharedialog.ui @@ -6,8 +6,8 @@ 0 0 - 500 - 535 + 454 + 558 @@ -20,72 +20,120 @@ QLayout::SetFixedSize - + - Share with + Share Info - - - - - - - - User: - - - - - - - - - - Group - - + + + + + + + TextLabel + + + + + + + + + + 75 + true + + + + Name: + + + + + + + true + + + true + + + + + + + + 75 + true + + + + Type: + + + + + + + true + + + + + + + + 75 + true + + + + Local path: + + + + + + + true + + + true + + + + + + + + 75 + true + + + + OwnCloud Path: + + + + + + + true + + + true + + + + + + - - - Qt::Horizontal - - - - 40 - 5 - - - - - - - - 1 - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - - 40 - 5 - - - - - - + @@ -93,85 +141,73 @@ - - - - - - - - - - QLayout::SetDefaultConstraint - - - - - true - - - - - - - - - - - - - - - - - - Set password - - - - - - - - - - - - - - - - - - QLineEdit::Password - - - - - - - - - - - Set expiry date - - - - - - - - - - - - - - + + + + 0 + + + + + QLayout::SetDefaultConstraint + + + + + true + + + + + + + + + + + + + + + + + + Set password + + + + + + + + + + + QLineEdit::Password + + + + + + + + + + + Set expiry date + + + + + + + + + + diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp index 4149c56725..752e8c20af 100644 --- a/src/gui/socketapi.cpp +++ b/src/gui/socketapi.cpp @@ -414,9 +414,10 @@ void SocketApi::command_SHARE(const QString& argument, SocketType* socket) } else { const QString message = QLatin1String("SHARE:OK:")+QDir::toNativeSeparators(argument); sendMessage(socket, message); + const QString folderForPath = shareFolder->path(); const QString path = shareFolder->remotePath() + argument.right(argument.count()-folderForPath.count()+1); - emit shareCommandReceived(path); + emit shareCommandReceived(path, argument); } } diff --git a/src/gui/socketapi.h b/src/gui/socketapi.h index ac6000ae27..e313c9c6a0 100644 --- a/src/gui/socketapi.h +++ b/src/gui/socketapi.h @@ -58,7 +58,7 @@ public slots: void slotClearExcludesList(); signals: - void shareCommandReceived(const QString &path); + void shareCommandReceived(const QString &sharePath, const QString &localPath); private slots: void slotNewConnection();