Add option to create label for share link.
authorCamila <hello@camila.codes>
Tue, 14 Sep 2021 12:10:44 +0000 (14:10 +0200)
committerMatthieu Gallien (Rebase PR Action) <matthieu_gallien@yahoo.fr>
Tue, 21 Sep 2021 10:01:20 +0000 (10:01 +0000)
Signed-off-by: Camila <hello@camila.codes>
src/gui/ocssharejob.cpp
src/gui/ocssharejob.h
src/gui/sharelinkwidget.cpp
src/gui/sharelinkwidget.h
src/gui/sharemanager.cpp
src/gui/sharemanager.h
theme.qrc.in
theme/black/edit.svg [new file with mode: 0644]

index fcbfafe77ae0735471115c94829106cfde06edff..900074dbcc3c84401fb1b79ed87ec78bc2675908 100644 (file)
@@ -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)
index 074fa07621866413954ae7c146ed39d99d72970e..064706b5c6db555b1fcba593b82e74d5a75e508f 100644 (file)
@@ -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
index 7a50639bf462d625bf7408a583de96c6f975ac82..d0c422409e37fa81e5202aed39e9ecd34da34709 100644 (file)
@@ -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()));
+    } 
+}
+
 }
index 08071218f95ef62164aca502312e6dd7ca482e59..a6818fcad86db219a6edb776341b8be510defcdd 100644 (file)
 #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{};
 };
 }
 
index 4b40213e39bbc80e415aff7e09514e4db8c9c366..fec6b1bef86272bc6a59896bed7b8a8816a55108 100644 (file)
@@ -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)
index 64a3a22da5097c14b3299faff8cbaf04fef83303..48f58b81e370f0aab53063bc6dc6f6bb4a72410f 100644 (file)
@@ -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;
 };
 
 /**
index 0638c48537cce99dbed77f63f4d1e10202f916b9..c3779673420dc6810af1ad58d2bca86c0503b5bb 100644 (file)
         <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>
diff --git a/theme/black/edit.svg b/theme/black/edit.svg
new file mode 100644 (file)
index 0000000..dda21eb
--- /dev/null
@@ -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>