Support '#page=<pagenum>' fragment to open at page <pagenum>
Needs ReviewPublic

Authored by michaelweghorn on Apr 27 2019, 2:07 PM.


Group Reviewers

Support the '#page=<pagenum>' fragment to specify which page
to open the document at, in addition to the existing '#<pagenum>'
For PDF, the '#page=<pagenum>' fragment is specified in RFC 8118,
section 3.

BUG: 406831

Test Plan
  1. Put a test file that has multiple pages at '/tmp/testfile.pdf'
  2. Check that all of the following commands open the test file on page 2:

    okular /tmp/testfile.pdf#2 okular /tmp/testfile.pdf#page=2 okular file:///tmp/testfile.pdf#2 okular file:///tmp/testfile.pdf#page=2

Diff Detail

R223 Okular
No Linters Available
No Unit Test Coverage
Build Status
Buildable 11300
Build 11318: arc lint + arc unit
michaelweghorn created this revision.Apr 27 2019, 2:07 PM
Restricted Application added a project: Okular. · View Herald TranscriptApr 27 2019, 2:07 PM
Restricted Application added a subscriber: okular-devel. · View Herald Transcript
michaelweghorn requested review of this revision.Apr 27 2019, 2:07 PM

How about the following approach (not tested)? This way, other parameters (like nameddest) wouldn’t break it and can be added later.

const QString fragment = url.fragment(QUrl::EncodeDelimiters);

bool gotOpenPageNumber = false;
int openPageNumber = fragment.toInt(&gotOpenPageNumber);

for ( QString parameter : fragment.split(QChar('&') )
    if ( parameter.startsWith("page=", Qt::CaseInsensitive) )
        bool ok = false;
        int page = parameter.mid(5).toInt(&ok);
        if ( ok )
            openPageNumber = page;
            gotOpenPageNumber = true;

I`m not sure whether QUrl::EncodeDelimiters is optimal.

aacid added a subscriber: aacid.Apr 28 2019, 4:07 PM

needs autotest