Skip to content

Commit b55b2d6

Browse files
committed
#3357 deck: fix url handling
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent 40ed6a7 commit b55b2d6

6 files changed

Lines changed: 38 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## 26.2.13
44

5+
- Fixed clicking a Nextcloud Deck link not opening the Nextcloud Deck dialog anymore
6+
(for [#3357](https://github.com/pbek/QOwnNotes/issues/3357))
7+
- The note editor's `openUrl` method now routes Nextcloud Deck card URLs (`https://…/apps/deck/#/board/…/card/…`) through `UrlHandler` instead of handing them off to `QDesktopServices`
8+
- The note preview's anchor-click handler (`onNotePreviewAnchorClicked`) now also recognises Deck card URLs and routes them through `UrlHandler` so the dialog opens correctly from the preview pane as well
9+
- The card ID is now parsed directly from the URL path instead of requiring a pre-configured board ID that exactly matches the clicked link, so the dialog opens regardless of which board the card belongs to
10+
- Removed the `isEnabled()` gate from the link-click handler so the Nextcloud Deck dialog opens even when the Deck integration is not fully configured for card creation
11+
512
- Improved multi-note selection preview styling in the QLiteHtml preview widget for dark mode
613
(for [#3466](https://github.com/pbek/QOwnNotes/issues/3466))
714
- Colors are now derived from the active editor schema instead of hardcoded light/dark fallback

src/mainwindow.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6484,7 +6484,10 @@ void MainWindow::onNotePreviewAnchorClicked(const QUrl &url) {
64846484
// Check if Ctrl key is pressed to open in new tab
64856485
bool openInNewTab = QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier);
64866486

6487-
if (UrlHandler::isUrlSchemeLocal(url)) {
6487+
const bool isLocalScheme = UrlHandler::isUrlSchemeLocal(url);
6488+
const bool isDeckCardUrl = NextcloudDeckService::isCardUrl(url.toString());
6489+
6490+
if (isLocalScheme || isDeckCardUrl) {
64886491
// Update _lastNoteId when opening in a new tab to ensure the current note
64896492
// is correctly placed in the old tab, not some previous note
64906493
if (openInNewTab && currentNote.exists()) {

src/services/nextclouddeckservice.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,17 @@ QString NextcloudDeckService::getCardUrlPattern() const {
241241
QStringLiteral("/card/");
242242
}
243243

244+
int NextcloudDeckService::parseCardIdFromUrlDirectly(const QString& url) {
245+
static const QRegularExpression re(QStringLiteral(R"(\/card\/(\d+))"));
246+
QRegularExpressionMatch match = re.match(url);
247+
248+
if (match.hasMatch()) {
249+
return match.captured(1).toInt();
250+
}
251+
252+
return -1;
253+
}
254+
244255
int NextcloudDeckService::parseCardIdFromUrl(const QString& url) const {
245256
qDebug() << __func__ << "getCardUrlPattern(): " << getCardUrlPattern();
246257
if (!url.startsWith(getCardUrlPattern())) {

src/services/nextclouddeckservice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class NextcloudDeckService : public QObject {
6161
bool deleteCard(int cardId);
6262
int parseCardIdFromUrl(const QString& url) const;
6363
static bool isCardUrl(const QString& url);
64+
static int parseCardIdFromUrlDirectly(const QString& url);
6465
QString getCardUrlPattern() const;
6566

6667
private:

src/utils/urlhandler.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,17 @@ void UrlHandler::openUrl(QString urlString, const bool openInNewTab) {
8181
}
8282

8383
void UrlHandler::handleNextcloudDeckUrl(const QString &urlString) {
84-
NextcloudDeckService nextcloudDeckService(MainWindow::instance());
85-
86-
if (nextcloudDeckService.isEnabled()) {
87-
auto cardId = nextcloudDeckService.parseCardIdFromUrl(urlString);
88-
qDebug() << __func__ << "cardId: " << cardId;
89-
90-
if (cardId > 0) {
91-
// Open the Nextcloud Deck dialog with the cardId
92-
MainWindow::instance()->openNextcloudDeckDialog(cardId);
93-
}
84+
// Parse the card ID directly from the URL path to avoid requiring
85+
// a pre-configured board ID that exactly matches the URL
86+
auto cardId = NextcloudDeckService::parseCardIdFromUrlDirectly(urlString);
87+
qDebug() << __func__ << "cardId: " << cardId;
88+
89+
if (cardId > 0) {
90+
// Open the Nextcloud Deck dialog with the cardId.
91+
// We do not require isEnabled() here because the user explicitly clicked
92+
// a Deck link and we should honour that regardless of whether the Deck
93+
// integration is fully configured for card creation.
94+
MainWindow::instance()->openNextcloudDeckDialog(cardId);
9495
}
9596
}
9697

src/widgets/qownnotesmarkdowntextedit.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,12 @@ void QOwnNotesMarkdownTextEdit::openUrl(const QString &urlString, bool openInNew
440440
QUrl url(urlCopy);
441441
const QString scheme = url.scheme();
442442

443-
// If it's a note URL, noteid URL, file URL in note folder, or has no scheme (relative link),
444-
// use UrlHandler which knows how to handle notes properly
443+
// If it's a note URL, noteid URL, file URL in note folder, has no scheme (relative link),
444+
// or is a Nextcloud Deck card URL, use UrlHandler which knows how to handle these properly
445445
if (scheme == QStringLiteral("note") || scheme == QStringLiteral("noteid") ||
446446
scheme == QStringLiteral("file") || scheme.isEmpty() ||
447-
Note::fileUrlIsNoteInCurrentNoteFolder(url)) {
448-
// Use UrlHandler for note URLs with the openInNewTab flag
447+
Note::fileUrlIsNoteInCurrentNoteFolder(url) || NextcloudDeckService::isCardUrl(urlCopy)) {
448+
// Use UrlHandler for note and Deck URLs with the openInNewTab flag
449449
UrlHandler().openUrl(urlCopy, openInNewTab);
450450
} else {
451451
// For other URLs (http, https, etc.), use the base class implementation

0 commit comments

Comments
 (0)