Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [342337/titlebar] show/copy network url #1959

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,6 @@ inline constexpr char kAcComputerCrumbBarListView[] { "crumb_list_view" };

DPTITLEBAR_END_NAMESPACE
Q_DECLARE_METATYPE(QList<QVariantMap> *);
Q_DECLARE_METATYPE(QUrl *);

#endif // DFMPLUGIN_TITLEBAR_GLOBAL_H
4 changes: 3 additions & 1 deletion src/plugins/filemanager/core/dfmplugin-titlebar/titlebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TitleBar : public dpf::Plugin
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.deepin.plugin.filemanager" FILE "titlebar.json")

DPF_EVENT_NAMESPACE(DPTITLEBAR_NAMESPACE)
DPF_EVENT_NAMESPACE(DPTITLEBAR_NAMESPACE)
// singnal events
DPF_EVENT_REG_SIGNAL(signal_Search_Start)
DPF_EVENT_REG_SIGNAL(signal_Search_Stop)
Expand All @@ -37,6 +37,8 @@ class TitleBar : public dpf::Plugin

// hook events
DPF_EVENT_REG_HOOK(hook_Crumb_Seprate)
DPF_EVENT_REG_HOOK(hook_Show_Addr)
DPF_EVENT_REG_HOOK(hook_Copy_Addr)

public:
virtual void initialize() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <dfm-base/base/schemefactory.h>
#include <dfm-base/utils/fileutils.h>

#include <dfm-framework/event/event.h>

#include <dtkwidget_global.h>
#ifdef DTKWIDGET_CLASS_DSizeMode
# include <DSizeMode>
Expand Down Expand Up @@ -583,8 +585,13 @@ bool AddressBar::completerViewVisible()

void AddressBar::setCurrentUrl(const QUrl &url)
{
QString text = dfmbase::FileUtils::isLocalFile(url) ? url.toLocalFile() : UrlRoute::urlToLocalPath(url.toString());
this->setText(text);
QUrl u(url);
if (dpfHookSequence->run("dfmplugin_titlebar", "hook_Show_Addr", &u)) {
this->setText(u.toString());
} else {
QString text = dfmbase::FileUtils::isLocalFile(url) ? url.toLocalFile() : UrlRoute::urlToLocalPath(url.toString());
this->setText(text);
}
}

QUrl AddressBar::currentUrl()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,11 @@ void CrumbBar::onCustomContextMenu(const QPoint &point)
}

menu->addAction(copyIcon, QObject::tr("Copy path"), [this, url]() {
d->writeUrlToClipboard(url);
QUrl u(url);
if (dpfHookSequence->run("dfmplugin_titlebar", "hook_Copy_Addr", &u))
d->writeUrlToClipboard(u);
else
d->writeUrlToClipboard(url);
});

if (displayNewWindowAndTab) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "smbbrowsereventreceiver.h"
#include <dfm-base/file/local/syncfileinfo.h>
#include <dfm-base/utils/universalutils.h>
#include <dfm-base/utils/systempathutil.h>
#include <dfm-base/base/device/deviceutils.h>
#include <dfm-base/dfm_global_defines.h>

#include <dfm-framework/dpf.h>
Expand Down Expand Up @@ -80,5 +82,53 @@
return false;
}

bool SmbBrowserEventReceiver::hookTitleBarAddrHandle(QUrl *url)

Check warning on line 85 in src/plugins/filemanager/dfmplugin-smbbrowser/events/smbbrowsereventreceiver.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'hookTitleBarAddrHandle' is never used.
{
Q_ASSERT(url);
QUrl in(*url), out;
if (getOriginalUri(in, &out)) {
*url = out;
return true;
}
return false;
}

bool SmbBrowserEventReceiver::getOriginalUri(const QUrl &in, QUrl *out)
{
QString path = in.path();

// is cifs
static const QRegularExpression kCifsPrefix { R"(^/media/[^/]*/smbmounts/smb-share:[^/]*)" };
if (path.contains(kCifsPrefix)) {
QString host, share, port;
if (!DeviceUtils::parseSmbInfo(path, host, share, &port))
return false;

if (out) {
out->setScheme("smb");
out->setHost(host);
if (!port.isEmpty())
out->setPort(port.toInt());
QString subPath = "/" + share;
subPath += path.remove(kCifsPrefix);
out->setPath(subPath);
return true;
}
}

// is gvfs: since mtp/gphoto... scheme are not supported path lookup, only handle ftp/sftp/smb
// use GIO to obtain the original URI
if (path.contains(QRegularExpression(R"(((^/run/user/[0-9]*/gvfs)|(^/root/.gvfs))/(ftp|sftp|smb))"))) {
SyncFileInfo f(in);
QUrl u = f.urlOf(dfmbase::FileInfo::FileUrlInfoType::kOriginalUrl);
if (u.isValid() && out) {
*out = u;
return true;
}
}

return false;
}

SmbBrowserEventReceiver::SmbBrowserEventReceiver(QObject *parent)
: QObject(parent) { }
: QObject(parent) {}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ class SmbBrowserEventReceiver : public QObject

public Q_SLOTS:
bool detailViewIcon(const QUrl &url, QString *iconName);
bool cancelDelete(quint64, const QList<QUrl> &urls, const QUrl&rootUrl);
bool cancelMoveToTrash(quint64, const QList<QUrl> &, const QUrl&rootUrl);
bool cancelDelete(quint64, const QList<QUrl> &urls, const QUrl &rootUrl);
bool cancelMoveToTrash(quint64, const QList<QUrl> &, const QUrl &rootUrl);

bool hookSetTabName(const QUrl &url, QString *tabName);

bool hookTitleBarAddrHandle(QUrl *url);

private:
bool getOriginalUri(const QUrl &in, QUrl *out);

private:
explicit SmbBrowserEventReceiver(QObject *parent = nullptr);
};
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/filemanager/dfmplugin-smbbrowser/smbbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QMenu>

Q_DECLARE_METATYPE(QString *)
Q_DECLARE_METATYPE(QUrl *)

namespace dfmplugin_smbbrowser {
DFM_LOG_REISGER_CATEGORY(DPSMBBROWSER_NAMESPACE)
Expand Down Expand Up @@ -152,6 +153,8 @@ void SmbBrowser::followEvents()
dpfHookSequence->follow("dfmplugin_workspace", "hook_ShortCut_CutFiles", SmbBrowserEventReceiver::instance(), &SmbBrowserEventReceiver::cancelMoveToTrash);
dpfHookSequence->follow("dfmplugin_workspace", "hook_ShortCut_PreViewFiles", SmbBrowserEventReceiver::instance(), &SmbBrowserEventReceiver::cancelMoveToTrash);
dpfHookSequence->follow("dfmplugin_workspace", "hook_Tab_SetTabName", SmbBrowserEventReceiver::instance(), &SmbBrowserEventReceiver::hookSetTabName);
dpfHookSequence->follow("dfmplugin_titlebar", "hook_Show_Addr", SmbBrowserEventReceiver::instance(), &SmbBrowserEventReceiver::hookTitleBarAddrHandle);
dpfHookSequence->follow("dfmplugin_titlebar", "hook_Copy_Addr", SmbBrowserEventReceiver::instance(), &SmbBrowserEventReceiver::hookTitleBarAddrHandle);
}

void SmbBrowser::updateNeighborToSidebar()
Expand Down
Loading