Commit 37403a03 authored by Pino Toscano's avatar Pino Toscano

Small rework on the system used to pass parameters of the document:

- on command line, properly read the URL ref ('#foobar' at the end), avoiding a KCmdLineArgs behaviour which encodes it as part of the file name
- pass what was specified as ref or the page (as specified with -p/--page) to the kpart
- make the okularpart take out the ref from the URL it opens and then:
  a) if it is a number, assume it is the destination page number
  b) otherwise, use that string as named destination

CCMAIL: okular-devel@kde.org

svn path=/trunk/KDE/kdegraphics/okular/; revision=969227
parent 6e6ea570
......@@ -994,8 +994,30 @@ bool Part::openFile()
return true;
}
bool Part::openUrl(const KUrl &url)
bool Part::openUrl(const KUrl &_url)
{
KUrl url( _url );
if ( url.hasHTMLRef() )
{
const QString dest = url.htmlRef();
bool ok = true;
const int page = dest.toInt( &ok );
if ( ok )
{
Okular::DocumentViewport vp( page - 1 );
vp.rePos.enabled = true;
vp.rePos.normalizedX = 0;
vp.rePos.normalizedY = 0;
vp.rePos.pos = Okular::DocumentViewport::TopLeft;
m_document->setNextDocumentViewport( vp );
}
else
{
m_document->setNextDocumentDestination( dest );
}
url.setHTMLRef( QString() );
}
// this calls in sequence the 'closeUrl' and 'openFile' methods
bool openOk = KParts::ReadOnlyPart::openUrl( url );
......
......@@ -72,7 +72,7 @@ int main(int argc, char** argv)
{
for (int i = 0; i < args->count(); ++i)
{
Shell* widget = new Shell(args, args->url(i));
Shell* widget = new Shell(args, i);
widget->show();
}
}
......
......@@ -46,10 +46,31 @@
// local includes
#include "kdocumentviewer.h"
Shell::Shell(KCmdLineArgs* args, const KUrl &url)
Shell::Shell(KCmdLineArgs* args, int argIndex)
: KParts::MainWindow(), m_args(args), m_menuBarWasShown(true), m_toolBarWasShown(true)
{
m_openUrl = url;
if (m_args && argIndex != -1)
{
/*
Rationale for the small "cut-and-paste" work being done below:
KCmdLineArgs::makeURL() (used by ::url() encodes any # into the URL itself,
so we have to find it manually and build up the URL by taking its ref,
if any.
*/
KUrl url = m_args->url(argIndex);
const QString arg = m_args->arg(argIndex);
const int sharpPos = arg.lastIndexOf(QLatin1Char('#'));
if (sharpPos != -1)
{
url = KCmdLineArgs::makeURL(arg.left(sharpPos).toUtf8());
url.setHTMLRef(arg.mid(sharpPos + 1));
}
else if (!m_args->getOption("page").isEmpty())
{
url.setHTMLRef(m_args->getOption("page"));
}
m_openUrl = url;
}
init();
}
......@@ -105,13 +126,7 @@ void Shell::init()
void Shell::delayedOpen()
{
uint page = 0;
if (m_args && m_doc)
{
QString pageopt = m_args->getOption("page");
page = pageopt.toUInt();
}
openUrl(m_openUrl, page);
openUrl( m_openUrl );
}
Shell::~Shell()
......@@ -122,13 +137,13 @@ Shell::~Shell()
m_args->clear();
}
void Shell::openUrl( const KUrl & url, uint page )
void Shell::openUrl( const KUrl & url )
{
if ( m_part )
{
if ( m_doc && m_args && m_args->isSet( "presentation" ) )
m_doc->startPresentation();
bool openOk = page > 0 && m_doc ? m_doc->openDocument( url, page ) : m_part->openUrl( url );
bool openOk = m_part->openUrl( url );
const bool isstdin = url.fileName( KUrl::ObeyTrailingSlash ) == QLatin1String( "-" );
if ( !isstdin )
{
......
......@@ -41,7 +41,7 @@ public:
/**
* Constructor
*/
explicit Shell(KCmdLineArgs* args = 0, const KUrl &url = KUrl());
explicit Shell(KCmdLineArgs* args = 0, int argIndex = -1);
/**
* Default Destructor
......@@ -77,7 +77,7 @@ private slots:
void slotUpdateFullScreen();
void slotShowMenubar();
void openUrl( const KUrl & url, uint page = 0 );
void openUrl( const KUrl & url );
void delayedOpen();
signals:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment