1 /***************************************************************************
2 * Copyright (C) 2002 by Wilco Greven <greven@kde.org> *
3 * Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
11 #include "extensions.h"
17 * BrowserExtension class
19 BrowserExtension::BrowserExtension(Part
* parent
)
20 : KParts::BrowserExtension( parent
), m_part( parent
)
22 emit
enableAction("print", true);
23 setURLDropHandlingEnabled(true);
27 void BrowserExtension::print()
34 * OkularLiveConnectExtension class
36 #define OKULAR_EVAL_RES_OBJ_NAME "__okular_object"
37 #define OKULAR_EVAL_RES_OBJ "this." OKULAR_EVAL_RES_OBJ_NAME
39 OkularLiveConnectExtension::OkularLiveConnectExtension( Part
*parent
)
40 : KParts::LiveConnectExtension( parent
), m_inEval( false )
45 bool OkularLiveConnectExtension::get( const unsigned long objid
, const QString
&field
,
46 KParts::LiveConnectExtension::Type
&type
,
47 unsigned long &retobjid
, QString
&value
)
52 if ( field
== QLatin1String( "postMessage" ) )
54 type
= KParts::LiveConnectExtension::TypeFunction
;
61 bool OkularLiveConnectExtension::put( const unsigned long objid
, const QString
&field
, const QString
&value
)
66 if ( field
== QLatin1String( OKULAR_EVAL_RES_OBJ_NAME
) )
75 bool OkularLiveConnectExtension::call( const unsigned long objid
, const QString
&func
, const QStringList
&args
,
76 KParts::LiveConnectExtension::Type
&type
, unsigned long &retobjid
, QString
&value
)
80 if ( func
== QLatin1String( "postMessage" ) )
82 type
= KParts::LiveConnectExtension::TypeVoid
;
91 QString
OkularLiveConnectExtension::eval( const QString
&script
)
93 KParts::LiveConnectExtension::ArgList args
;
94 args
.append( qMakePair( KParts::LiveConnectExtension::TypeString
, script
) );
97 emit
partEvent( 0, "eval", args
);
103 void OkularLiveConnectExtension::postMessage( const QStringList
&args
)
105 QStringList arrayargs
;
106 Q_FOREACH ( const QString
&arg
, args
)
108 QString newarg
= arg
;
109 newarg
.replace( '\'', "\\'" );
110 arrayargs
.append( "\"" + newarg
+ "\"" );
112 const QString arrayarg
= '[' + arrayargs
.join( ", " ) + ']';
113 eval( "if (this.messageHandler && typeof this.messageHandler.onMessage == 'function') "
114 "{ this.messageHandler.onMessage(" + arrayarg
+ ") }" );
118 #include "extensions.moc"
120 /* kate: replace-tabs on; indent-width 4; */