From 624213956e624c0f7319dae7ea01c121a274135c Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 10 Jan 2022 11:29:24 +0100 Subject: [PATCH] Add ability to copy internal link from share dialog Signed-off-by: Claudio Cambra --- src/gui/CMakeLists.txt | 2 + src/gui/internallinkwidget.cpp | 86 +++++++++++++++++ src/gui/internallinkwidget.h | 59 ++++++++++++ src/gui/internallinkwidget.ui | 168 +++++++++++++++++++++++++++++++++ src/gui/sharedialog.cpp | 6 ++ src/gui/sharedialog.h | 2 + theme.qrc.in | 1 + theme/external.svg | 1 + 8 files changed, 325 insertions(+) create mode 100644 src/gui/internallinkwidget.cpp create mode 100644 src/gui/internallinkwidget.h create mode 100644 src/gui/internallinkwidget.ui create mode 100644 theme/external.svg diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 744d6501a24db..0834d25c82404 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -27,6 +27,7 @@ set(theme_dir ${CMAKE_SOURCE_DIR}/theme) set(client_UI_SRCS accountsettings.ui conflictdialog.ui + internallinkwidget.ui invalidfilenamedialog.ui foldercreationdialog.ui folderwizardsourcepage.ui @@ -80,6 +81,7 @@ set(client_SRCS folderwizard.cpp generalsettings.cpp legalnotice.cpp + internallinkwidget.cpp ignorelisteditor.cpp ignorelisttablewidget.cpp lockwatcher.cpp diff --git a/src/gui/internallinkwidget.cpp b/src/gui/internallinkwidget.cpp new file mode 100644 index 0000000000000..e8c65005fe5f4 --- /dev/null +++ b/src/gui/internallinkwidget.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2022 by Claudio Cambra + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 "internallinkwidget.h" +#include "accountstate.h" +#include "folderman.h" +#include "theme.h" + +#include "QProgressIndicator.h" +#include + +namespace OCC { + +Q_LOGGING_CATEGORY(lcInternalLink, "nextcloud.gui.internallink", QtInfoMsg) + +InternalLinkWidget::InternalLinkWidget(const QString &localPath, + QWidget *parent) + : QWidget(parent) + , _localPath(localPath) +{ + _ui->setupUi(this); + + const auto folder = FolderMan::instance()->folderForPath(_localPath); + const auto folderRelativePath = _localPath.mid(folder->cleanPath().length() + 1); + const auto serverRelativePath = QDir(folder->remotePath()).filePath(folderRelativePath); + + const auto bindLinkSlot = [this](QString link) { slotLinkFetched(link); }; + + fetchPrivateLinkUrl( + folder->accountState()->account(), + serverRelativePath, + {}, + this, + bindLinkSlot + ); + + _ui->copyInternalLinkButton->setEnabled(false); + _ui->internalLinkProgressIndicator->setVisible(true); + _ui->internalLinkProgressIndicator->startAnimation(); + + connect(_ui->copyInternalLinkButton, &QPushButton::clicked, this, &InternalLinkWidget::slotCopyInternalLink); +} + +void InternalLinkWidget::slotLinkFetched(const QString &url) +{ + _internalUrl = url; + _ui->copyInternalLinkButton->setEnabled(true); + _ui->internalLinkProgressIndicator->setVisible(false); + _ui->internalLinkProgressIndicator->stopAnimation(); + _ui->horizontalSpacer->changeSize(0, 0); + _ui->horizontalSpacer_2->changeSize(0, 0); +} + +void InternalLinkWidget::slotCopyInternalLink() const +{ + QApplication::clipboard()->setText(_internalUrl); +} + +void InternalLinkWidget::setupUiOptions() +{ + customizeStyle(); +} + +void InternalLinkWidget::slotStyleChanged() +{ + customizeStyle(); +} + +void InternalLinkWidget::customizeStyle() +{ + _ui->copyInternalLinkButton->setIcon(Theme::createColorAwareIcon(":/client/theme/copy.svg")); + _ui->internalLinkIconLabel->setPixmap(Theme::createColorAwarePixmap(":/client/theme/external.svg")); +} + +} diff --git a/src/gui/internallinkwidget.h b/src/gui/internallinkwidget.h new file mode 100644 index 0000000000000..cb343a11e876b --- /dev/null +++ b/src/gui/internallinkwidget.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2022 by Claudio Cambra + * + * 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; either version 2 of the License, or + * (at your option) any later version. + * + * 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 INTERNALLINKWIDGET_H +#define INTERNALLINKWIDGET_H + +#include "QProgressIndicator.h" +#include +#include + +#include "ui_internallinkwidget.h" + +namespace OCC { + +/** + * @brief The ShareDialog class + * @ingroup gui + */ +class InternalLinkWidget : public QWidget +{ + Q_OBJECT + +public: + explicit InternalLinkWidget(const QString &localPath, + QWidget *parent = nullptr); + ~InternalLinkWidget() override = default; + + void setupUiOptions(); + +public slots: + void slotStyleChanged(); + +private slots: + void slotLinkFetched(const QString &url); + void slotCopyInternalLink() const; + +private: + void customizeStyle(); + + std::unique_ptr _ui = std::make_unique(); + QString _localPath; + QString _internalUrl; + + QPushButton *_copyInternalLinkButton{}; +}; +} + +#endif // INTERNALLINKWIDGET_H diff --git a/src/gui/internallinkwidget.ui b/src/gui/internallinkwidget.ui new file mode 100644 index 0000000000000..202ec7240e729 --- /dev/null +++ b/src/gui/internallinkwidget.ui @@ -0,0 +1,168 @@ + + + OCC::InternalLinkWidget + + + + 0 + 0 + 400 + 238 + + + + + 0 + 0 + + + + + 0 + + + 12 + + + 0 + + + 20 + + + + + 6 + + + 0 + + + + + + + + :/client/theme/external.svg + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + 0 + 0 + + + + Internal link + + + + + + + + 0 + 0 + + + + true + + + color: rgb(118, 118, 118) + + + Only works for users with access to this folder + + + true + + + + + + + + + Qt::Horizontal + + + + 40 + 25 + + + + + + + + + 0 + 0 + + + + + 28 + 27 + + + + + + + + Qt::Horizontal + + + + 40 + 25 + + + + + + + + + + + + :/client/theme/copy.svg:/client/theme/copy.svg + + + false + + + true + + + + + + + + + + + QProgressIndicator + QWidget +
QProgressIndicator.h
+ 1 +
+
+ + + + +
diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index b88bf5409cc4e..6e48b70bea1b7 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -16,6 +16,7 @@ #include "sharedialog.h" #include "sharee.h" #include "sharelinkwidget.h" +#include "internallinkwidget.h" #include "shareusergroupwidget.h" #include "passwordinputdialog.h" @@ -142,6 +143,11 @@ ShareDialog::ShareDialog(QPointer accountState, _scrollAreaLayout = new QVBoxLayout(_scrollAreaViewPort); _scrollAreaLayout->setContentsMargins(0, 0, 0, 0); _ui->scrollArea->setWidget(_scrollAreaViewPort); + + _internalLinkWidget = new InternalLinkWidget(localPath, this); + _ui->verticalLayout->addWidget(_internalLinkWidget); + _internalLinkWidget->setupUiOptions(); + connect(this, &ShareDialog::styleChanged, _internalLinkWidget, &InternalLinkWidget::slotStyleChanged); } ShareLinkWidget *ShareDialog::addLinkShareWidget(const QSharedPointer &linkShare) diff --git a/src/gui/sharedialog.h b/src/gui/sharedialog.h index 531998d42b57a..7b4aade18863b 100644 --- a/src/gui/sharedialog.h +++ b/src/gui/sharedialog.h @@ -35,6 +35,7 @@ namespace Ui { } class ShareLinkWidget; +class InternalLinkWidget; class ShareUserGroupWidget; class ShareManager; class LinkShare; @@ -96,6 +97,7 @@ private slots: QList _linkWidgetList; ShareLinkWidget* _emptyShareLinkWidget = nullptr; + InternalLinkWidget* _internalLinkWidget = nullptr; ShareUserGroupWidget *_userGroupWidget = nullptr; QProgressIndicator *_progressIndicator = nullptr; diff --git a/theme.qrc.in b/theme.qrc.in index aba4639b4fe60..f927692f8b9a1 100644 --- a/theme.qrc.in +++ b/theme.qrc.in @@ -202,6 +202,7 @@ theme/share.svg theme/reply.svg theme/magnifying-glass.svg + theme/external.svg theme/colored/user-status-online.svg theme/colored/user-status-invisible.svg theme/colored/user-status-away.svg diff --git a/theme/external.svg b/theme/external.svg new file mode 100644 index 0000000000000..79c9cebf58892 --- /dev/null +++ b/theme/external.svg @@ -0,0 +1 @@ + \ No newline at end of file