mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 23:28:14 +03:00
ShareDialog: Review fixes
* Allow creating nameless shares * Display token as name for nameless shares (both to be consistent with server) * Allow changing a share's name by editing it in the table * Minor adjustments
This commit is contained in:
parent
a1f7168d2a
commit
3c1a2cde33
8 changed files with 156 additions and 92 deletions
|
@ -84,6 +84,16 @@ void OcsShareJob::setPublicUpload(const QString &shareId, bool publicUpload)
|
|||
start();
|
||||
}
|
||||
|
||||
void OcsShareJob::setName(const QString &shareId, const QString &name)
|
||||
{
|
||||
appendPath(shareId);
|
||||
setVerb("PUT");
|
||||
addParam(QString::fromLatin1("name"), name);
|
||||
_value = name;
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
void OcsShareJob::setPermissions(const QString &shareId,
|
||||
const Share::Permissions permissions)
|
||||
{
|
||||
|
|
|
@ -68,12 +68,17 @@ public:
|
|||
void setPassword(const QString &shareId, const QString& password);
|
||||
|
||||
/**
|
||||
* Void set the share to be public upload
|
||||
* Set the share to be public upload
|
||||
*
|
||||
* @param publicUpload Set or remove public upload
|
||||
*/
|
||||
void setPublicUpload(const QString &shareId, bool publicUpload);
|
||||
|
||||
/**
|
||||
* Change the name of a share
|
||||
*/
|
||||
void setName(const QString &shareId, const QString &name);
|
||||
|
||||
/**
|
||||
* Set the permissions
|
||||
*
|
||||
|
|
|
@ -55,7 +55,9 @@ ShareLinkWidget::ShareLinkWidget(AccountPtr account,
|
|||
_ui->linkShares->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
||||
|
||||
//Is this a file or folder?
|
||||
_isFile = QFileInfo(localPath).isFile();
|
||||
QFileInfo fi(localPath);
|
||||
_isFile = fi.isFile();
|
||||
_ui->nameLineEdit->setText(tr("%1 link").arg(fi.fileName()));
|
||||
|
||||
// the following progress indicator widgets are added to layouts which makes them
|
||||
// automatically deleted once the dialog dies.
|
||||
|
@ -71,6 +73,7 @@ ShareLinkWidget::ShareLinkWidget(AccountPtr account,
|
|||
connect(_ui->nameLineEdit, SIGNAL(returnPressed()), SLOT(slotShareNameEntered()));
|
||||
connect(_ui->createShareButton, SIGNAL(clicked(bool)), SLOT(slotShareNameEntered()));
|
||||
connect(_ui->linkShares, SIGNAL(itemSelectionChanged()), SLOT(slotShareSelectionChanged()));
|
||||
connect(_ui->linkShares, SIGNAL(itemChanged(QTableWidgetItem*)), SLOT(slotNameEdited(QTableWidgetItem*)));
|
||||
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)));
|
||||
|
@ -193,7 +196,6 @@ void ShareLinkWidget::slotSharesFetched(const QList<QSharedPointer<Share>> &shar
|
|||
table->clearContents();
|
||||
table->setRowCount(0);
|
||||
|
||||
auto shareIcon = QIcon::fromTheme(QLatin1String("mail-send"));
|
||||
auto deleteIcon = QIcon::fromTheme(QLatin1String("user-trash"),
|
||||
QIcon(QLatin1String(":/client/resources/delete.png")));
|
||||
|
||||
|
@ -215,16 +217,22 @@ void ShareLinkWidget::slotSharesFetched(const QList<QSharedPointer<Share>> &shar
|
|||
auto row = table->rowCount();
|
||||
table->insertRow(row);
|
||||
|
||||
auto nameItem = new QTableWidgetItem;
|
||||
QString name = linkShare->getName();
|
||||
if (name.isEmpty()) {
|
||||
name = tr("Public link");
|
||||
if (!_namesSupported) {
|
||||
name = tr("Public link");
|
||||
nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable);
|
||||
} else {
|
||||
name = linkShare->getToken();
|
||||
}
|
||||
}
|
||||
auto nameItem = new QTableWidgetItem(name);
|
||||
nameItem->setText(name);
|
||||
nameItem->setData(Qt::UserRole, QVariant::fromValue(linkShare));
|
||||
table->setItem(row, 0, nameItem);
|
||||
|
||||
auto shareButton = new QToolButton;
|
||||
shareButton->setIcon(shareIcon);
|
||||
shareButton->setText("...");
|
||||
shareButton->setProperty(propertyShareC, QVariant::fromValue(linkShare));
|
||||
shareButton->setMenu(_shareLinkMenu);
|
||||
shareButton->setPopupMode(QToolButton::InstantPopup);
|
||||
|
@ -339,10 +347,6 @@ void ShareLinkWidget::slotPasswordReturnPressed()
|
|||
{
|
||||
if (!selectedShare()) {
|
||||
// If share creation requires a password, we'll be in this case
|
||||
if (_namesSupported && _ui->nameLineEdit->text().isEmpty()) {
|
||||
_ui->nameLineEdit->setFocus();
|
||||
return;
|
||||
}
|
||||
if (_ui->lineEdit_password->text().isEmpty()) {
|
||||
_ui->lineEdit_password->setFocus();
|
||||
return;
|
||||
|
@ -362,6 +366,19 @@ void ShareLinkWidget::slotPasswordChanged(const QString& newText)
|
|||
_ui->pushButton_setPassword->setEnabled( newText.length() > 0 );
|
||||
}
|
||||
|
||||
void ShareLinkWidget::slotNameEdited(QTableWidgetItem* item)
|
||||
{
|
||||
if (!_namesSupported) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString newName = item->text();
|
||||
auto share = item->data(Qt::UserRole).value<QSharedPointer<LinkShare>>();
|
||||
if (share && newName != share->getName() && newName != share->getToken()) {
|
||||
share->setName(newName);
|
||||
}
|
||||
}
|
||||
|
||||
void ShareLinkWidget::setPassword(const QString &password)
|
||||
{
|
||||
if (auto current = selectedShare()) {
|
||||
|
@ -391,10 +408,8 @@ void ShareLinkWidget::slotPasswordSet()
|
|||
|
||||
void ShareLinkWidget::slotShareNameEntered()
|
||||
{
|
||||
if (!_ui->nameLineEdit->text().isEmpty() || !_namesSupported) {
|
||||
_pi_create->startAnimation();
|
||||
_manager->createLinkShare(_sharePath, _ui->nameLineEdit->text(), QString());
|
||||
}
|
||||
_pi_create->startAnimation();
|
||||
_manager->createLinkShare(_sharePath, _ui->nameLineEdit->text(), QString());
|
||||
}
|
||||
|
||||
void ShareLinkWidget::slotDeleteShareFetched()
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <QList>
|
||||
|
||||
class QMenu;
|
||||
class QTableWidgetItem;
|
||||
|
||||
namespace OCC {
|
||||
|
||||
|
@ -68,6 +69,7 @@ private slots:
|
|||
void slotCheckBoxEditingClicked();
|
||||
void slotExpireDateChanged(const QDate &date);
|
||||
void slotPasswordChanged(const QString& newText);
|
||||
void slotNameEdited(QTableWidgetItem* item);
|
||||
|
||||
void slotShareLinkButtonTriggered(QAction* action);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<item>
|
||||
<widget class="QPushButton" name="createShareButton">
|
||||
<property name="text">
|
||||
<string>&Create</string>
|
||||
<string>&Create new</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -81,7 +81,7 @@
|
|||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="4" column="0">
|
||||
<item row="7" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_expire">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
|
@ -102,7 +102,71 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<item row="5" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_password">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_setPassword">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Set &password </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_password">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_password">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Set password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Link properties:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QWidget" name="widget_editing" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_editing">
|
||||
<property name="leftMargin">
|
||||
|
@ -140,63 +204,6 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_password">
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_setPassword">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Set &password </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_password">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_password">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Set password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -122,13 +122,15 @@ bool LinkShare::isPasswordSet() const
|
|||
LinkShare::LinkShare(AccountPtr account,
|
||||
const QString& id,
|
||||
const QString& path,
|
||||
const QString &name,
|
||||
const QString& name,
|
||||
const QString& token,
|
||||
Permissions permissions,
|
||||
bool passwordSet,
|
||||
const QUrl& url,
|
||||
const QDate& expireDate)
|
||||
: Share(account, id, path, Share::TypeLink, permissions),
|
||||
_name(name),
|
||||
_token(token),
|
||||
_passwordSet(passwordSet),
|
||||
_expireDate(expireDate),
|
||||
_url(url)
|
||||
|
@ -155,6 +157,19 @@ QString LinkShare::getName() const
|
|||
return _name;
|
||||
}
|
||||
|
||||
void LinkShare::setName(const QString& name)
|
||||
{
|
||||
OcsShareJob *job = new OcsShareJob(_account);
|
||||
connect(job, SIGNAL(shareJobFinished(QVariantMap,QVariant)), SLOT(slotNameSet(QVariantMap,QVariant)));
|
||||
connect(job, SIGNAL(ocsError(int,QString)), SLOT(slotOcsError(int,QString)));
|
||||
job->setName(getId(), name);
|
||||
}
|
||||
|
||||
QString LinkShare::getToken() const
|
||||
{
|
||||
return _token;
|
||||
}
|
||||
|
||||
void LinkShare::slotPublicUploadSet(const QVariantMap&, const QVariant &value)
|
||||
{
|
||||
if (value.toBool()) {
|
||||
|
@ -209,6 +224,12 @@ void LinkShare::slotSetPasswordError(int statusCode, const QString &message)
|
|||
emit passwordSetError(statusCode, message);
|
||||
}
|
||||
|
||||
void LinkShare::slotNameSet(const QVariantMap &, const QVariant &value)
|
||||
{
|
||||
_name = value.toString();
|
||||
emit nameSet();
|
||||
}
|
||||
|
||||
ShareManager::ShareManager(AccountPtr account, QObject *parent)
|
||||
: QObject(parent),
|
||||
_account(account)
|
||||
|
@ -345,7 +366,8 @@ void ShareManager::slotSharesFetched(const QVariantMap &reply)
|
|||
emit sharesFetched(shares);
|
||||
}
|
||||
|
||||
QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QVariantMap &data) {
|
||||
QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QVariantMap &data)
|
||||
{
|
||||
QUrl url;
|
||||
|
||||
// From ownCloud server 8.2 the url field is always set for public shares
|
||||
|
@ -366,12 +388,11 @@ QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QVariantMap &data)
|
|||
expireDate = QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00");
|
||||
}
|
||||
|
||||
QString name = data.value("name").toString();
|
||||
|
||||
return QSharedPointer<LinkShare>(new LinkShare(_account,
|
||||
data.value("id").toString(),
|
||||
data.value("path").toString(),
|
||||
name,
|
||||
data.value("name").toString(),
|
||||
data.value("token").toString(),
|
||||
(Share::Permissions)data.value("permissions").toInt(),
|
||||
data.value("share_with").isValid(),
|
||||
url,
|
||||
|
|
|
@ -133,6 +133,7 @@ public:
|
|||
const QString& id,
|
||||
const QString& path,
|
||||
const QString& name,
|
||||
const QString& token,
|
||||
const Permissions permissions,
|
||||
bool passwordSet,
|
||||
const QUrl& url,
|
||||
|
@ -158,10 +159,22 @@ public:
|
|||
void setPublicUpload(bool publicUpload);
|
||||
|
||||
/*
|
||||
* Returns the name of the link share.
|
||||
* Returns the name of the link share. Can be empty.
|
||||
*/
|
||||
QString getName() const;
|
||||
|
||||
/*
|
||||
* Set the name of the link share.
|
||||
*
|
||||
* Emits either nameSet() or serverError().
|
||||
*/
|
||||
void setName(const QString& name);
|
||||
|
||||
/*
|
||||
* Returns the token of the link share.
|
||||
*/
|
||||
QString getToken() const;
|
||||
|
||||
/*
|
||||
* Set the password
|
||||
*
|
||||
|
@ -193,15 +206,18 @@ signals:
|
|||
void publicUploadSet();
|
||||
void passwordSet();
|
||||
void passwordSetError(int statusCode, const QString &message);
|
||||
void nameSet();
|
||||
|
||||
private slots:
|
||||
void slotPasswordSet(const QVariantMap&, const QVariant &value);
|
||||
void slotPublicUploadSet(const QVariantMap&, const QVariant &value);
|
||||
void slotExpireDateSet(const QVariantMap& reply, const QVariant &value);
|
||||
void slotSetPasswordError(int statusCode, const QString &message);
|
||||
void slotNameSet(const QVariantMap&, const QVariant &value);
|
||||
|
||||
private:
|
||||
QString _name;
|
||||
QString _token;
|
||||
bool _passwordSet;
|
||||
QDate _expireDate;
|
||||
QUrl _url;
|
||||
|
|
|
@ -14,18 +14,6 @@
|
|||
<string>Share NewDocument.odt</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="shareeHorizontalLayout">
|
||||
<item>
|
||||
|
|
Loading…
Reference in a new issue