Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 20661ff6 authored by Pino Toscano's avatar Pino Toscano

Add an interface (implemented by the Part) for controlling the really basic...

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 <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
parent fa3f297b
/***************************************************************************
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
* *
* 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
......@@ -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);*/
......
......@@ -22,6 +22,7 @@
#include <qpointer.h>
#include "core/observer.h"
#include "core/document.h"
#include "kdocumentviewer.h"
#include <QtDBus/QtDBus>
......@@ -66,10 +67,11 @@ class BrowserExtension;
* @author Wilco Greven <greven@kde.org>
* @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<Okular::ExportFormat> m_exportFormats;
bool m_cliPresentation;
private slots:
void slotGeneratorPreferences();
......
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/..
)
########### next target ###############
set(okular_SRCS main.cpp shell.cpp )
......
......@@ -25,6 +25,9 @@ static const char version[] = "0.5.81";
static KCmdLineOptions options[] =
{
{ "p", 0, 0 },
{ "page <number>", 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();
......
......@@ -22,6 +22,7 @@
#include <qtimer.h>
#include <kaction.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <kedittoolbar.h>
#include <kfiledialog.h>
#include <klibloader.h>
......@@ -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<KToggleAction*>(toolBarMenuAction());
m_doc = qobject_cast<KDocumentViewer*>(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 );
}
......
......@@ -23,10 +23,12 @@
#include <kparts/mainwindow.h>
#include <kmimetype.h>
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;
......
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