Add option to create label for share link.

Signed-off-by: Camila <hello@camila.codes>
This commit is contained in:
Camila 2021-09-14 14:10:44 +02:00 коммит произвёл Matthieu Gallien (Rebase PR Action)
Родитель d0d4b08a09
Коммит ba8ec56e65
8 изменённых файлов: 188 добавлений и 7 удалений

Просмотреть файл

@ -118,6 +118,17 @@ void OcsShareJob::setPermissions(const QString &shareId,
start();
}
void OcsShareJob::setLabel(const QString &shareId, const QString &label)
{
appendPath(shareId);
setVerb("PUT");
addParam(QStringLiteral("label"), label);
_value = label;
start();
}
void OcsShareJob::createLinkShare(const QString &path,
const QString &name,
const QString &password)

Просмотреть файл

@ -96,6 +96,11 @@ public:
*/
void setPermissions(const QString &shareId,
const Share::Permissions permissions);
/**
* Set share link label
*/
void setLabel(const QString &shareId, const QString &label);
/**
* Create a new link share

Просмотреть файл

@ -20,6 +20,7 @@
#include "guiutility.h"
#include "sharemanager.h"
#include "theme.h"
#include "elidedlabel.h"
#include "QProgressIndicator.h"
#include <QBuffer>
@ -168,6 +169,7 @@ void ShareLinkWidget::setupUiOptions()
connect(_linkShare.data(), &LinkShare::noteSet, this, &ShareLinkWidget::slotNoteSet);
connect(_linkShare.data(), &LinkShare::passwordSet, this, &ShareLinkWidget::slotPasswordSet);
connect(_linkShare.data(), &LinkShare::passwordSetError, this, &ShareLinkWidget::slotPasswordSetError);
connect(_linkShare.data(), &LinkShare::labelSet, this, &ShareLinkWidget::slotLabelSet);
// Prepare permissions check and create group action
const QDate expireDate = _linkShare.data()->getExpireDate().isValid() ? _linkShare.data()->getExpireDate() : QDate();
@ -189,7 +191,7 @@ void ShareLinkWidget::setupUiOptions()
} else {
checked = (perm == SharePermissionRead);
_readOnlyLinkAction = permissionsGroup->addAction(tr("Read only"));
_readOnlyLinkAction = permissionsGroup->addAction(tr("View only"));
_readOnlyLinkAction->setCheckable(true);
_readOnlyLinkAction->setChecked(checked);
@ -204,6 +206,40 @@ void ShareLinkWidget::setupUiOptions()
_allowUploadLinkAction->setCheckable(true);
_allowUploadLinkAction->setChecked(checked);
}
_shareLinkElidedLabel = new OCC::ElidedLabel(this);
_shareLinkElidedLabel->setElideMode(Qt::ElideRight);
displayShareLinkLabel();
_ui->horizontalLayout->insertWidget(2, _shareLinkElidedLabel);
_shareLinkLayout = new QHBoxLayout(this);
_shareLinkLabel = new QLabel(this);
_shareLinkLabel->setPixmap(QString(":/client/theme/black/edit.svg"));
_shareLinkLayout->addWidget(_shareLinkLabel);
_shareLinkEdit = new QLineEdit(this);
connect(_shareLinkEdit, &QLineEdit::returnPressed, this, &ShareLinkWidget::slotCreateLabel);
_shareLinkEdit->setPlaceholderText(tr("Link name"));
_shareLinkEdit->setText(_linkShare.data()->getLabel());
_shareLinkLayout->addWidget(_shareLinkEdit);
_shareLinkButton = new QToolButton(this);
connect(_shareLinkButton, &QToolButton::clicked, this, &ShareLinkWidget::slotCreateLabel);
_shareLinkButton->setIcon(QIcon(":/client/theme/confirm.svg"));
_shareLinkButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
_shareLinkLayout->addWidget(_shareLinkButton);
_shareLinkProgressIndicator = new QProgressIndicator(this);
_shareLinkProgressIndicator->setVisible(false);
_shareLinkLayout->addWidget(_shareLinkProgressIndicator);
_shareLinkDefaultWidget = new QWidget(this);
_shareLinkDefaultWidget->setLayout(_shareLinkLayout);
_shareLinkWidgetAction = new QWidgetAction(this);
_shareLinkWidgetAction->setDefaultWidget(_shareLinkDefaultWidget);
_linkContextMenu->addAction(_shareLinkWidgetAction);
// Adds permissions actions (radio button style)
if (_isFile) {
@ -263,7 +299,7 @@ void ShareLinkWidget::setupUiOptions()
// Adds action to unshare widget (check box)
_unshareLinkAction = _linkContextMenu->addAction(QIcon(":/client/theme/delete.svg"),
tr("Delete share link"));
tr("Delete link"));
_linkContextMenu->addSeparator();
@ -300,7 +336,7 @@ void ShareLinkWidget::setNote(const QString &note)
}
}
void ShareLinkWidget::slotCreateNote()
void ShareLinkWidget::slotCreateNote()
{
setNote(_ui->textEdit_note->toPlainText());
}
@ -435,6 +471,21 @@ void ShareLinkWidget::slotAnimationFinished()
deleteLater();
}
void ShareLinkWidget::slotCreateLabel()
{
if (_linkShare) {
slotToggleButtonAnimation(_shareLinkButton, _shareLinkProgressIndicator, true, true);
_ui->errorLabel->hide();
_linkShare->setLabel(_shareLinkEdit->text());
}
}
void ShareLinkWidget::slotLabelSet()
{
slotToggleButtonAnimation(_shareLinkButton, _shareLinkProgressIndicator, true, false);
displayShareLinkLabel();
}
void ShareLinkWidget::slotDeleteAnimationFinished()
{
// There is a painting bug where a small line of this widget isn't
@ -615,4 +666,12 @@ void ShareLinkWidget::customizeStyle()
_ui->passwordProgressIndicator->setColor(QGuiApplication::palette().color(QPalette::Text));
}
void ShareLinkWidget::displayShareLinkLabel()
{
_shareLinkElidedLabel->clear();
if(!_linkShare->getLabel().isEmpty()) {
_shareLinkElidedLabel->setText(QString("(%1)").arg(_linkShare->getLabel()));
}
}
}

Просмотреть файл

@ -23,6 +23,10 @@
#include <QSharedPointer>
#include <QList>
#include <QToolButton>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QWidgetAction>
class QMenu;
class QTableWidgetItem;
@ -37,6 +41,7 @@ class AbstractCredentials;
class SyncResult;
class LinkShare;
class Share;
class ElidedLabel;
/**
* @brief The ShareDialog class
@ -88,6 +93,9 @@ private slots:
void slotDeleteAnimationFinished();
void slotAnimationFinished();
void slotCreateLabel();
void slotLabelSet();
signals:
void createLinkShare();
@ -121,6 +129,8 @@ private:
void startAnimation(const int start, const int end);
void customizeStyle();
void displayShareLinkLabel();
Ui::ShareLinkWidget *_ui;
AccountPtr _account;
@ -146,6 +156,14 @@ private:
QAction *_unshareLinkAction;
QAction *_addAnotherLinkAction;
QAction *_noteLinkAction;
QHBoxLayout *_shareLinkLayout{};
QLabel *_shareLinkLabel{};
ElidedLabel *_shareLinkElidedLabel{};
QLineEdit *_shareLinkEdit{};
QToolButton *_shareLinkButton{};
QProgressIndicator *_shareLinkProgressIndicator{};
QWidget *_shareLinkDefaultWidget{};
QWidgetAction *_shareLinkWidgetAction{};
};
}

Просмотреть файл

@ -196,13 +196,15 @@ LinkShare::LinkShare(AccountPtr account,
bool isPasswordSet,
const QUrl &url,
const QDate &expireDate,
const QString &note)
const QString &note,
const QString &label)
: Share(account, id, uidowner, ownerDisplayName, path, Share::TypeLink, isPasswordSet, permissions)
, _name(name)
, _token(token)
, _note(note)
, _expireDate(expireDate)
, _url(url)
, _label(label)
{
}
@ -226,6 +228,11 @@ QString LinkShare::getNote() const
return _note;
}
QString LinkShare::getLabel() const
{
return _label;
}
void LinkShare::setName(const QString &name)
{
auto *job = new OcsShareJob(_account);
@ -261,6 +268,14 @@ void LinkShare::setExpireDate(const QDate &date)
job->setExpireDate(getId(), date);
}
void LinkShare::setLabel(const QString &label)
{
auto *job = new OcsShareJob(_account);
connect(job, &OcsShareJob::shareJobFinished, this, &LinkShare::slotLabelSet);
connect(job, &OcsJob::ocsError, this, &LinkShare::slotOcsError);
job->setLabel(getId(), label);
}
void LinkShare::slotExpireDateSet(const QJsonDocument &reply, const QVariant &value)
{
auto data = reply.object().value("ocs").toObject().value("data").toObject();
@ -283,6 +298,14 @@ void LinkShare::slotNameSet(const QJsonDocument &, const QVariant &value)
emit nameSet();
}
void LinkShare::slotLabelSet(const QJsonDocument &, const QVariant &label)
{
if (_label != label.toString()) {
_label = label.toString();
emit labelSet();
}
}
UserGroupShare::UserGroupShare(AccountPtr account,
const QString &id,
const QString &owner,
@ -548,7 +571,8 @@ QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QJsonObject &data)
data.value("share_with").isString(), // has password?
url,
expireDate,
note));
note,
data.value("label").toString()));
}
QSharedPointer<Share> ShareManager::parseShare(const QJsonObject &data)

Просмотреть файл

@ -176,7 +176,8 @@ public:
bool isPasswordSet,
const QUrl &url,
const QDate &expireDate,
const QString &note);
const QString &note,
const QString &label);
/*
* Get the share link
@ -207,6 +208,11 @@ public:
* Returns the note of the link share.
*/
QString getNote() const;
/*
* Returns the label of the link share.
*/
QString getLabel() const;
/*
* Set the name of the link share.
@ -237,16 +243,23 @@ public:
* In case of a server error the serverError signal is emitted.
*/
void setExpireDate(const QDate &expireDate);
/*
* Set the label of the share link.
*/
void setLabel(const QString &label);
signals:
void expireDateSet();
void noteSet();
void nameSet();
void labelSet();
private slots:
void slotNoteSet(const QJsonDocument &, const QVariant &value);
void slotExpireDateSet(const QJsonDocument &reply, const QVariant &value);
void slotNameSet(const QJsonDocument &, const QVariant &value);
void slotLabelSet(const QJsonDocument &, const QVariant &value);
private:
QString _name;
@ -254,6 +267,7 @@ private:
QString _note;
QDate _expireDate;
QUrl _url;
QString _label;
};
class UserGroupShare : public Share
@ -292,6 +306,7 @@ signals:
private:
QString _note;
QDate _expireDate;
QString _label;
};
/**

Просмотреть файл

@ -199,5 +199,7 @@
<file>theme/colored/user-status-away.svg</file>
<file>theme/colored/user-status-dnd.svg</file>
<file>theme/black/email.svg</file>
<file>theme/black/edit.svg</file>
<file>theme/delete.svg</file>
</qresource>
</RCC>

47
theme/black/edit.svg Normal file
Просмотреть файл

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
version="1.1"
id="svg2"
width="16"
height="16"
viewBox="0 0 16 16"
sodipodi:docname="edit.svg"
inkscape:version="1.1 (c4e8f9ed74, 2021-05-24)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs6" />
<sodipodi:namedview
id="namedview4"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
showgrid="false"
inkscape:zoom="5.8388225"
inkscape:cx="39.99094"
inkscape:cy="20.466455"
inkscape:window-width="2560"
inkscape:window-height="1367"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="g8"
inkscape:snap-bbox="true"
width="16px" />
<g
inkscape:groupmode="layer"
inkscape:label="Image"
id="g8">
<path
style="fill:#000000;stroke-width:0.237748"
d="m 8.0529525,14.60266 -5.533428,0.06384 -0.117155,-0.305305 -0.117156,-0.305304 0.06349,-6.2966204 0.06349,-6.2966201 4.281826,-0.064566 4.2818265,-0.064584 1.36947,1.3839101 1.36947,1.3839101 -0.06421,5.2187458 -0.06421,5.2187625 z m -1.95565,-1.84695 h 1.901987 v -0.475502 -0.475503 h -1.901987 -1.901988 v 0.475503 0.475502 z M 7.9992895,9.9027285 H 11.803266 V 9.4272255 8.9517225 H 7.9992895 4.1953145 v 0.475503 0.475503 z m -1.42649,-2.8529819 h 2.377485 v -0.475503 -0.475503 h -2.377485 -2.377485 v 0.475503 0.475503 z m 0.475496,-2.8529817 h 2.852983 V 3.721262 3.2457591 H 7.0482955 4.1953145 V 3.721262 4.1967649 Z"
id="path783" />
</g>
</svg>

После

Ширина:  |  Высота:  |  Размер: 1.9 KiB