[Okular-devel] KDE/kdegraphics/okular

Pino Toscano pino at kde.org
Sun May 17 20:08:44 CEST 2009


SVN commit 969227 by pino:

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 at kde.org


 M  +23 -1     part.cpp  
 M  +1 -1      shell/main.cpp  
 M  +26 -11    shell/shell.cpp  
 M  +2 -2      shell/shell.h  


--- trunk/KDE/kdegraphics/okular/part.cpp #969226:969227
@@ -994,8 +994,30 @@
     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 );
 
--- trunk/KDE/kdegraphics/okular/shell/main.cpp #969226:969227
@@ -72,7 +72,7 @@
         {
             for (int i = 0; i < args->count(); ++i)
             {
-                Shell* widget = new Shell(args, args->url(i));
+                Shell* widget = new Shell(args, i);
                 widget->show();
             }
         }
--- trunk/KDE/kdegraphics/okular/shell/shell.cpp #969226:969227
@@ -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::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 @@
         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 )
         {
--- trunk/KDE/kdegraphics/okular/shell/shell.h #969226:969227
@@ -41,7 +41,7 @@
   /**
    * Constructor
    */
-  explicit Shell(KCmdLineArgs* args = 0, const KUrl &url = KUrl());
+  explicit Shell(KCmdLineArgs* args = 0, int argIndex = -1);
 
   /**
    * Default Destructor
@@ -77,7 +77,7 @@
   void slotUpdateFullScreen();
   void slotShowMenubar();
 
-  void openUrl( const KUrl & url, uint page = 0 );
+  void openUrl( const KUrl & url );
   void delayedOpen();
 
 signals:


More information about the Okular-devel mailing list