From 45c2a3613e55626f28fca738f304563f5577fc50 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Tue, 2 Feb 2021 00:08:39 +0100 Subject: [PATCH] [Notifications] Make job destination a clickable link Provides a handy shortcut. Since notifications are already rich text imho it's fine API-wise for job text to suddenly contain markup, too. --- libnotificationmanager/job_p.cpp | 20 ++++++++++++++++---- libnotificationmanager/job_p.h | 3 ++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/libnotificationmanager/job_p.cpp b/libnotificationmanager/job_p.cpp index daf809a7e..e6821de8b 100644 --- a/libnotificationmanager/job_p.cpp +++ b/libnotificationmanager/job_p.cpp @@ -78,14 +78,19 @@ QUrl JobPrivate::localFileOrUrl(const QString &urlString) return url; } -// Tries to return a more user-friendly displayed destination -QString JobPrivate::prettyDestUrl() const +QUrl JobPrivate::destUrl() const { QUrl url = m_destUrl; // In case of a single file and no destUrl, try using the second label (most likely "Destination")... if (!url.isValid() && m_totalFiles == 1) { url = localFileOrUrl(m_descriptionValue2).adjusted(QUrl::RemoveFilename); } + return url; +} + +QString JobPrivate::prettyUrl(const QUrl &_url) const +{ + QUrl url(_url); if (!url.isValid()) { return QString(); @@ -159,7 +164,14 @@ QString JobPrivate::text() const return m_infoMessage; } - const QString destUrlString = prettyDestUrl(); + const QUrl destUrl = this->destUrl(); + const QString prettyDestUrl = prettyUrl(destUrl); + + QString destUrlString; + if (!prettyDestUrl.isEmpty()) { + // Turn destination into a clickable hyperlink + destUrlString = QStringLiteral("%2").arg(destUrl.toString(QUrl::PrettyDecoded), prettyDestUrl); + } if (m_totalFiles == 0) { if (!destUrlString.isEmpty()) { @@ -204,7 +216,7 @@ QString JobPrivate::text() const qCInfo(NOTIFICATIONMANAGER) << "Failed to generate job text for job with following properties:"; qCInfo(NOTIFICATIONMANAGER) << " processedFiles =" << m_processedFiles << ", totalFiles =" << m_totalFiles << ", current file name =" << descriptionUrl().fileName() - << ", destination url string =" << destUrlString; + << ", destination url string =" << this->destUrl(); qCInfo(NOTIFICATIONMANAGER) << "label1 =" << m_descriptionLabel1 << ", value1 =" << m_descriptionValue1 << ", label2 =" << m_descriptionLabel2 << ", value2 =" << m_descriptionValue2; diff --git a/libnotificationmanager/job_p.h b/libnotificationmanager/job_p.h index 4ab42f7d2..c4a9ee245 100644 --- a/libnotificationmanager/job_p.h +++ b/libnotificationmanager/job_p.h @@ -109,7 +109,8 @@ private: static QUrl localFileOrUrl(const QString &stringUrl); - QString prettyDestUrl() const; + QUrl destUrl() const; + QString prettyUrl(const QUrl &url) const; void updateHasDetails(); void finish();