From f6fd57439d7fd64b2cbbcef427b0328fae399db1 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Thu, 6 Jul 2023 04:14:55 +0300 Subject: [PATCH] okular: handle URLs in the part the same way it is done by the shell also adjusted the tests to the KUrl changes Signed-off-by: Ivailo Monev --- okular/part.cpp | 9 +++++++++ okular/tests/mainshelltest.cpp | 18 +++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/okular/part.cpp b/okular/part.cpp index 51256d23..75043612 100644 --- a/okular/part.cpp +++ b/okular/part.cpp @@ -1414,6 +1414,15 @@ bool Part::openUrl(const KUrl &_url) return false; KUrl url( _url ); + // More or less the same hack as in ShellUtils::urlFromArg() + if ( url.isLocalFile() && !QFile::exists(url.toLocalFile()) ) { + const QString localFile = url.toLocalFile(); + const int sharpPos = localFile.lastIndexOf( QLatin1Char('#') ); + if (sharpPos != -1) { + url.setPath( localFile.left(sharpPos) ); + url.setFragment( localFile.mid(sharpPos + 1) ); + } + } if ( url.hasFragment() ) { const QString dest = url.fragment(); diff --git a/okular/tests/mainshelltest.cpp b/okular/tests/mainshelltest.cpp index 6096fb67..2dc324cd 100644 --- a/okular/tests/mainshelltest.cpp +++ b/okular/tests/mainshelltest.cpp @@ -231,7 +231,7 @@ void MainShellTest::testShell() QCOMPARE(s->m_tabs.count(), 1); Okular::Part *part = s->findChild(); QVERIFY(part); - QCOMPARE(part->url().url(), QString("file://%1").arg(paths[0])); + QCOMPARE(part->url().url(), paths[0]); QCOMPARE(partDocument(part)->currentPage(), expectedPage); } else if (paths.count() == 2) @@ -244,8 +244,8 @@ void MainShellTest::testShell() Okular::Part *part = qobject_cast(s->m_tabs[0].part); Okular::Part *part2 = qobject_cast(s->m_tabs[1].part); QCOMPARE(s->m_tabs.count(), 2); - QCOMPARE(part->url().url(), QString("file://%1").arg(paths[0])); - QCOMPARE(part2->url().url(), QString("file://%1").arg(paths[1])); + QCOMPARE(part->url().url(), paths[0]); + QCOMPARE(part2->url().url(), paths[1]); QCOMPARE(partDocument(part)->currentPage(), expectedPage); QCOMPARE(partDocument(part2)->currentPage(), expectedPage); } @@ -270,7 +270,7 @@ void MainShellTest::testShell() foreach(const QString &path, paths) { - QVERIFY(openUrls.contains(QString("file://%1").arg(path))); + QVERIFY(openUrls.contains(path)); } } } @@ -307,7 +307,7 @@ void MainShellTest::testShell() { // It is unique so part got "overriten" QCOMPARE(s->m_tabs.count(), 1); - QCOMPARE(part->url().url(), QString("file://%1").arg(externalProcessPath)); + QCOMPARE(part->url().url(), externalProcessPath); QCOMPARE(partDocument(part)->currentPage(), externalProcessExpectedPage); } else @@ -315,7 +315,7 @@ void MainShellTest::testShell() // It is attaching to us so a second tab is there QCOMPARE(s->m_tabs.count(), 2); Okular::Part *part2 = qobject_cast(s->m_tabs[1].part); - QCOMPARE(part2->url().url(), QString("file://%1").arg(externalProcessPath)); + QCOMPARE(part2->url().url(), externalProcessPath); QCOMPARE(partDocument(part2)->currentPage(), externalProcessExpectedPage); } } @@ -331,7 +331,7 @@ void MainShellTest::testShell() // It opened on a new process, so no change for us QCOMPARE(s->m_tabs.count(), 1); - QCOMPARE(part->url().url(), QString("file://%1").arg(paths[0])); + QCOMPARE(part->url().url(), paths[0]); QCOMPARE(partDocument(part)->currentPage(), externalProcessExpectedPage); } } @@ -420,7 +420,7 @@ void MainShellTest::testFileRemembersPagePosition() QVERIFY(s); Okular::Part *part = s->findChild(); QVERIFY(part); - QCOMPARE(part->url().url(), QString("file://%1").arg(paths[0])); + QCOMPARE(part->url().url(), paths[0]); QCOMPARE(partDocument(part)->currentPage(), 0u); partDocument(part)->setViewportPage(3); QCOMPARE(partDocument(part)->currentPage(), 3u); @@ -455,7 +455,7 @@ void MainShellTest::testFileRemembersPagePosition() QVERIFY(s); part = s->findChild(); QVERIFY(part); - QCOMPARE(part->url().url(), QString("file://%1").arg(paths[0])); + QCOMPARE(part->url().url(), paths[0]); QCOMPARE(partDocument(part)->currentPage(), 3u); } -- 2.11.0