Commit cf1b9ea7 authored by Pino Toscano's avatar Pino Toscano

split the KParts extensions in an own file

svn path=/trunk/KDE/kdegraphics/okular/; revision=792473
parent 09bc4c14
......@@ -101,6 +101,7 @@ install(FILES core/okularGenerator.desktop DESTINATION ${SERVICETYPES_INSTALL_DI
set(okularpart_SRCS
part.cpp
extensions.cpp
conf/preferencesdialog.cpp
conf/dlgaccessibility.cpp
conf/dlgdebug.cpp
......
/***************************************************************************
* Copyright (C) 2002 by Wilco Greven <greven@kde.org> *
* Copyright (C) 2008 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. *
***************************************************************************/
#include "extensions.h"
// local includes
#include "part.h"
/*
* BrowserExtension class
*/
BrowserExtension::BrowserExtension(Part* parent)
: KParts::BrowserExtension( parent ), m_part( parent )
{
emit enableAction("print", true);
setURLDropHandlingEnabled(true);
}
void BrowserExtension::print()
{
m_part->slotPrint();
}
/*
* OkularLiveConnectExtension class
*/
#define OKULAR_EVAL_RES_OBJ_NAME "__okular_object"
#define OKULAR_EVAL_RES_OBJ "this." OKULAR_EVAL_RES_OBJ_NAME
OkularLiveConnectExtension::OkularLiveConnectExtension( Part *parent )
: KParts::LiveConnectExtension( parent ), m_inEval( false )
{
}
bool OkularLiveConnectExtension::get( const unsigned long objid, const QString &field,
KParts::LiveConnectExtension::Type &type,
unsigned long &retobjid, QString &value )
{
Q_UNUSED( value )
retobjid = objid;
bool result = false;
if ( field == QLatin1String( "postMessage" ) )
{
type = KParts::LiveConnectExtension::TypeFunction;
result = true;
}
return result;
}
bool OkularLiveConnectExtension::put( const unsigned long objid, const QString &field, const QString &value )
{
Q_UNUSED( objid )
if ( m_inEval )
{
if ( field == QLatin1String( OKULAR_EVAL_RES_OBJ_NAME ) )
m_evalRes = value;
return true;
}
return false;
}
bool OkularLiveConnectExtension::call( const unsigned long objid, const QString &func, const QStringList &args,
KParts::LiveConnectExtension::Type &type, unsigned long &retobjid, QString &value )
{
retobjid = objid;
bool result = false;
if ( func == QLatin1String( "postMessage" ) )
{
type = KParts::LiveConnectExtension::TypeVoid;
postMessage( args );
value = QString();
result = true;
}
return result;
}
QString OkularLiveConnectExtension::eval( const QString &script )
{
KParts::LiveConnectExtension::ArgList args;
args.append( qMakePair( KParts::LiveConnectExtension::TypeString, script ) );
m_evalRes.clear();
m_inEval = true;
emit partEvent( 0, "eval", args );
m_inEval = false;
return m_evalRes;
}
void OkularLiveConnectExtension::postMessage( const QStringList &args )
{
QStringList arrayargs;
Q_FOREACH ( const QString &arg, args )
{
QString newarg = arg;
newarg.replace( '\'', "\\'" );
arrayargs.append( "\"" + newarg + "\"" );
}
const QString arrayarg = "[" + arrayargs.join( ", " ) + "]";
eval( "if (this.messageHandler && typeof this.messageHandler.onMessage == 'function') "
"{ this.messageHandler.onMessage(" + arrayarg + ") }" );
}
#include "extensions.moc"
/* kate: replace-tabs on; indent-width 4; */
/***************************************************************************
* Copyright (C) 2002 by Wilco Greven <greven@kde.org> *
* Copyright (C) 2008 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 _EXTENSIONS_H_
#define _EXTENSIONS_H_
#include <kparts/browserextension.h>
class Part;
class BrowserExtension : public KParts::BrowserExtension
{
Q_OBJECT
public:
BrowserExtension(Part*);
public slots:
// Automatically detected by the host.
void print();
private:
Part *m_part;
};
class OkularLiveConnectExtension : public KParts::LiveConnectExtension
{
Q_OBJECT
public:
OkularLiveConnectExtension( Part *parent );
// from LiveConnectExtension
virtual bool get( const unsigned long objid, const QString &field, Type &type,
unsigned long &retobjid, QString &value );
virtual bool put( const unsigned long objid, const QString &field, const QString &value );
virtual bool call( const unsigned long objid, const QString &func, const QStringList &args,
Type &type, unsigned long &retobjid, QString &value );
private:
QString eval( const QString &script );
void postMessage( const QStringList &args );
bool m_inEval;
QString m_evalRes;
};
#endif
/* kate: replace-tabs on; indent-width 4; */
......@@ -61,6 +61,7 @@
// local includes
#include "aboutdata.h"
#include "extensions.h"
#include "ui/pageview.h"
#include "ui/toc.h"
#include "ui/searchwidget.h"
......@@ -1896,108 +1897,6 @@ void Part::updateAboutBackendAction()
}
/*
* BrowserExtension class
*/
BrowserExtension::BrowserExtension(Part* parent)
: KParts::BrowserExtension( parent ), m_part( parent )
{
emit enableAction("print", true);
setURLDropHandlingEnabled(true);
}
void BrowserExtension::print()
{
m_part->slotPrint();
}
/*
* OkularLiveConnectExtension class
*/
#define OKULAR_EVAL_RES_OBJ_NAME "__okular_object"
#define OKULAR_EVAL_RES_OBJ "this." OKULAR_EVAL_RES_OBJ_NAME
OkularLiveConnectExtension::OkularLiveConnectExtension( Part *parent )
: KParts::LiveConnectExtension( parent ), m_inEval( false )
{
}
bool OkularLiveConnectExtension::get( const unsigned long objid, const QString &field,
KParts::LiveConnectExtension::Type &type,
unsigned long &retobjid, QString &value )
{
Q_UNUSED( value )
retobjid = objid;
bool result = false;
if ( field == QLatin1String( "postMessage" ) )
{
type = KParts::LiveConnectExtension::TypeFunction;
result = true;
}
return result;
}
bool OkularLiveConnectExtension::put( const unsigned long objid, const QString &field, const QString &value )
{
Q_UNUSED( objid )
if ( m_inEval )
{
if ( field == QLatin1String( OKULAR_EVAL_RES_OBJ_NAME ) )
m_evalRes = value;
return true;
}
return false;
}
bool OkularLiveConnectExtension::call( const unsigned long objid, const QString &func, const QStringList &args,
KParts::LiveConnectExtension::Type &type, unsigned long &retobjid, QString &value )
{
retobjid = objid;
bool result = false;
if ( func == QLatin1String( "postMessage" ) )
{
type = KParts::LiveConnectExtension::TypeVoid;
postMessage( args );
value = QString();
result = true;
}
return result;
}
QString OkularLiveConnectExtension::eval( const QString &script )
{
KParts::LiveConnectExtension::ArgList args;
args.append( qMakePair( KParts::LiveConnectExtension::TypeString, script ) );
m_evalRes.clear();
m_inEval = true;
emit partEvent( 0, "eval", args );
m_inEval = false;
return m_evalRes;
}
void OkularLiveConnectExtension::postMessage( const QStringList &args )
{
QStringList arrayargs;
Q_FOREACH ( const QString &arg, args )
{
QString newarg = arg;
newarg.replace( '\'', "\\'" );
arrayargs.append( "\"" + newarg + "\"" );
}
const QString arrayarg = "[" + arrayargs.join( ", " ) + "]";
eval( "if (this.messageHandler && typeof this.messageHandler.onMessage == 'function') "
"{ this.messageHandler.onMessage(" + arrayarg + ") }" );
}
#include "part.moc"
/* kate: replace-tabs on; indent-width 4; */
......@@ -253,42 +253,6 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
void slotGeneratorPreferences();
};
class BrowserExtension : public KParts::BrowserExtension
{
Q_OBJECT
public:
BrowserExtension(Part*);
public slots:
// Automatically detected by the host.
void print();
private:
Part *m_part;
};
class OkularLiveConnectExtension : public KParts::LiveConnectExtension
{
Q_OBJECT
public:
OkularLiveConnectExtension( Part *parent );
// from LiveConnectExtension
virtual bool get( const unsigned long objid, const QString &field, Type &type,
unsigned long &retobjid, QString &value );
virtual bool put( const unsigned long objid, const QString &field, const QString &value );
virtual bool call( const unsigned long objid, const QString &func, const QStringList &args,
Type &type, unsigned long &retobjid, QString &value );
private:
QString eval( const QString &script );
void postMessage( const QStringList &args );
bool m_inEval;
QString m_evalRes;
};
#endif
/* kate: replace-tabs on; indent-width 4; */
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