From 20661ff61e33c4e2470134044a030ea621b215a4 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 4 Jan 2007 00:20:50 +0000 Subject: [PATCH] Add an interface (implemented by the Part) for controlling the really basic document viewer functionalities. This (along with a small refactor in the okular shell) gives the user the possibility to start okular with: -p, --page : to select the startup page --presentation : to start directly in presentation mode implementing also KPDF wishes #134115 and #137905. svn path=/trunk/playground/graphics/okular/; revision=619681 --- kdocumentviewer.h | 43 +++++++++++++++++++++++++++++++++++++++++++ part.cpp | 26 +++++++++++++++++++++----- part.h | 8 +++++++- shell/CMakeLists.txt | 4 ++++ shell/main.cpp | 8 +++++--- shell/shell.cpp | 28 +++++++++++++++++----------- shell/shell.h | 15 +++++++-------- 7 files changed, 104 insertions(+), 28 deletions(-) create mode 100644 kdocumentviewer.h diff --git a/kdocumentviewer.h b/kdocumentviewer.h new file mode 100644 index 000000000..15229f1f0 --- /dev/null +++ b/kdocumentviewer.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2007 by Pino Toscano * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef _KDOCUMENTVIEWER_H_ +#define _KDOCUMENTVIEWER_H_ + +class KUrl; + +/** + * @short Abstract interface for a document viewer + * + * This interface describe briefly the basic functions of a document viewer. + */ +class KDocumentViewer +{ + public: + virtual ~KDocumentViewer() {} + + /** + * Open the document at the specified @p url at page @p page. + */ + virtual bool openDocument( const KUrl& url, uint page ) = 0; + + /** + * Change to @p page the currently shown page. + */ + virtual void goToPage( uint page ) = 0; + + /** + * Start the presentation mode. + */ + virtual void startPresentation() = 0; +}; + +Q_DECLARE_INTERFACE( KDocumentViewer, "org.kde.kdocumentviewer/0.1" ) + +#endif diff --git a/part.cpp b/part.cpp index d0e02d02e..e1189da56 100644 --- a/part.cpp +++ b/part.cpp @@ -82,7 +82,7 @@ Part::Part(QWidget *parentWidget, const QStringList & /*args*/ ) : KParts::ReadOnlyPart(parent), m_showMenuBarAction(0), m_showFullScreenAction(0), m_actionsSearched(false), - m_searchStarted(false) + m_searchStarted(false), m_cliPresentation(false) { QDBusConnection::sessionBus().registerObject("/okular", this, QDBusConnection::ExportScriptableSlots); @@ -390,6 +390,19 @@ Part::~Part() delete *it; } +bool Part::openDocument(const KUrl& url, uint page) +{ + Okular::DocumentViewport vp( page - 1 ); + if ( vp.isValid() ) + m_document->setNextDocumentViewport( vp ); + return openUrl( url ); +} + +void Part::startPresentation() +{ + m_cliPresentation = true; +} + void Part::openUrlFromDocument(const KUrl &url) { m_bExtension->openUrlNotify(); @@ -648,11 +661,14 @@ bool Part::openFile() { m_toolBox->setCurrentIndex( 0 ); } - // if the 'StartFullScreen' flag is set, start presentation - if ( m_document->metaData( "StartFullScreen" ).toBool() ) + // if the 'StartFullScreen' flag is set, or the command line flag was + // specified, start presentation + if ( m_document->metaData( "StartFullScreen" ).toBool() || m_cliPresentation ) { - KMessageBox::information( m_presentationWidget, i18n("The document is going to be launched on presentation mode because the file requested it."), QString::null, "autoPresentationWarning" ); - slotShowPresentation(); + if ( !m_cliPresentation ) + KMessageBox::information( m_presentationWidget, i18n("The document is going to be launched on presentation mode because the file requested it."), QString::null, "autoPresentationWarning" ); + m_cliPresentation = false; + QMetaObject::invokeMethod(this, "slotShowPresentation", Qt::QueuedConnection); } /* if (m_document->getXMLFile() != QString::null) setXMLFile(m_document->getXMLFile(),true);*/ diff --git a/part.h b/part.h index 0b2ac4617..ffe71779d 100644 --- a/part.h +++ b/part.h @@ -22,6 +22,7 @@ #include #include "core/observer.h" #include "core/document.h" +#include "kdocumentviewer.h" #include @@ -66,10 +67,11 @@ class BrowserExtension; * @author Wilco Greven * @version 0.2 */ -class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver +class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, public KDocumentViewer { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.okular") +Q_INTERFACES(KDocumentViewer) public: // Default constructor @@ -84,6 +86,9 @@ public: static KAboutData* createAboutData(); + bool openDocument(const KUrl& url, uint page); + void startPresentation(); + public slots: // dbus Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page); Q_SCRIPTABLE Q_NOREPLY void openDocument(KUrl doc); @@ -212,6 +217,7 @@ private: QStringList m_supportedMimeTypes; KSelectAction * m_confGens; QList m_exportFormats; + bool m_cliPresentation; private slots: void slotGeneratorPreferences(); diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt index 5078aa7c3..3518376c2 100644 --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -1,4 +1,8 @@ +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/.. +) + ########### next target ############### set(okular_SRCS main.cpp shell.cpp ) diff --git a/shell/main.cpp b/shell/main.cpp index c8444c778..3e32756fa 100644 --- a/shell/main.cpp +++ b/shell/main.cpp @@ -25,6 +25,9 @@ static const char version[] = "0.5.81"; static KCmdLineOptions options[] = { + { "p", 0, 0 }, + { "page ", I18N_NOOP("Page of the document to be shown"), 0 }, + { "presentation", I18N_NOOP("Start the document in presentation mode"), 0 }, { "+[URL]", I18N_NOOP("Document to open"), 0 }, KCmdLineLastOption }; @@ -63,18 +66,17 @@ int main(int argc, char** argv) if (args->count() == 0) { - Shell* widget = new Shell; + Shell* widget = new Shell(args); widget->show(); } else { for (int i = 0; i < args->count(); ++i) { - Shell* widget = new Shell(args->url(i)); + Shell* widget = new Shell(args, args->url(i)); widget->show(); } } - args->clear(); } return app.exec(); diff --git a/shell/shell.cpp b/shell/shell.cpp index bb15b9e7e..2c7fe9b4d 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -44,15 +45,10 @@ // local includes #include "shell.h" +#include "kdocumentviewer.h" -Shell::Shell() - : KParts::MainWindow(), m_menuBarWasShown(true), m_toolBarWasShown(true) -{ - init(); -} - -Shell::Shell(const KUrl &url) - : KParts::MainWindow(), m_menuBarWasShown(true), m_toolBarWasShown(true) +Shell::Shell(KCmdLineArgs* args, const KUrl &url) + : KParts::MainWindow(), m_args(args), m_menuBarWasShown(true), m_toolBarWasShown(true) { m_openUrl = url; init(); @@ -63,6 +59,7 @@ void Shell::init() setObjectName( QLatin1String( "okular::Shell" ) ); // set the shell's ui resource file setXMLFile("shell.rc"); + m_doc=0L; m_fileformats=0L; m_tempfile=0L; // this routine will find and load our Part. it finds the Part by @@ -84,6 +81,7 @@ void Shell::init() setupGUI(Keys | Save); createGUI(m_part); m_showToolBarAction = static_cast(toolBarMenuAction()); + m_doc = qobject_cast(m_part); } } else @@ -112,7 +110,13 @@ void Shell::init() void Shell::delayedOpen() { - openUrl(m_openUrl); + uint page = 0; + if (m_args && m_doc) + { + QByteArray pageopt = m_args->getOption("page"); + page = pageopt.toUInt(); + } + openUrl(m_openUrl, page); } Shell::~Shell() @@ -123,11 +127,13 @@ Shell::~Shell() delete m_part; } -void Shell::openUrl( const KUrl & url ) +void Shell::openUrl( const KUrl & url, uint page ) { if ( m_part ) { - bool openOk = m_part->openUrl( url ); + 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 ); if ( openOk ) m_recent->addUrl( url ); else m_recent->removeUrl( url ); } diff --git a/shell/shell.h b/shell/shell.h index b8cf2abe1..fbc8105b3 100644 --- a/shell/shell.h +++ b/shell/shell.h @@ -23,10 +23,12 @@ #include #include +class KCmdLineArgs; class KRecentFilesAction; class KTemporaryFile; class KToggleAction; +class KDocumentViewer; class Part; /** @@ -43,14 +45,9 @@ class Shell : public KParts::MainWindow public: /** - * Default Constructor + * Constructor */ - Shell(); - - /** - * Open an url - */ - Shell(const KUrl &url); + Shell(KCmdLineArgs* args = 0, const KUrl &url = KUrl()); /** * Default Destructor @@ -84,7 +81,7 @@ private slots: void slotUpdateFullScreen(); void slotShowMenubar(); - void openUrl( const KUrl & url ); + void openUrl( const KUrl & url, uint page = 0 ); void delayedOpen(); signals: @@ -99,7 +96,9 @@ private: QStringList* fileFormats(); private: + KCmdLineArgs* m_args; KParts::ReadOnlyPart* m_part; + KDocumentViewer* m_doc; KTemporaryFile* m_tempfile; KRecentFilesAction* m_recent; QStringList* m_fileformats;