compile
[kdegraphics.git] / okular / extensions.cpp
bloba56fdf423e97ad7b3affac0466d8501240b0ddd2
1 /***************************************************************************
2 * Copyright (C) 2002 by Wilco Greven <greven@kde.org> *
3 * Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
4 * *
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"
13 // local includes
14 #include "part.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()
29 m_part->slotPrint();
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 )
49 Q_UNUSED( value )
50 retobjid = objid;
51 bool result = false;
52 if ( field == QLatin1String( "postMessage" ) )
54 type = KParts::LiveConnectExtension::TypeFunction;
55 result = true;
57 return result;
61 bool OkularLiveConnectExtension::put( const unsigned long objid, const QString &field, const QString &value )
63 Q_UNUSED( objid )
64 if ( m_inEval )
66 if ( field == QLatin1String( OKULAR_EVAL_RES_OBJ_NAME ) )
67 m_evalRes = value;
68 return true;
71 return false;
75 bool OkularLiveConnectExtension::call( const unsigned long objid, const QString &func, const QStringList &args,
76 KParts::LiveConnectExtension::Type &type, unsigned long &retobjid, QString &value )
78 retobjid = objid;
79 bool result = false;
80 if ( func == QLatin1String( "postMessage" ) )
82 type = KParts::LiveConnectExtension::TypeVoid;
83 postMessage( args );
84 value = QString();
85 result = true;
87 return result;
91 QString OkularLiveConnectExtension::eval( const QString &script )
93 KParts::LiveConnectExtension::ArgList args;
94 args.append( qMakePair( KParts::LiveConnectExtension::TypeString, script ) );
95 m_evalRes.clear();
96 m_inEval = true;
97 emit partEvent( 0, "eval", args );
98 m_inEval = false;
99 return m_evalRes;
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; */