2008-04-01 09:10:46 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* 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"
|
|
|
|
|
2009-10-26 20:59:24 +00:00
|
|
|
namespace Okular
|
|
|
|
{
|
|
|
|
|
2008-04-01 09:10:46 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
2015-10-29 12:37:11 +00:00
|
|
|
emit partEvent( 0, QStringLiteral("eval"), args );
|
2008-04-01 09:10:46 +00:00
|
|
|
m_inEval = false;
|
|
|
|
return m_evalRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OkularLiveConnectExtension::postMessage( const QStringList &args )
|
|
|
|
{
|
|
|
|
QStringList arrayargs;
|
2019-12-12 22:48:27 +00:00
|
|
|
for ( const QString &arg : args )
|
2008-04-01 09:10:46 +00:00
|
|
|
{
|
|
|
|
QString newarg = arg;
|
2016-07-11 20:11:43 +00:00
|
|
|
newarg.replace( QLatin1Char('\''), QLatin1String("\\'") );
|
|
|
|
arrayargs.append( QLatin1Char('"') + newarg + QLatin1Char('"') );
|
2008-04-01 09:10:46 +00:00
|
|
|
}
|
2016-07-11 20:11:43 +00:00
|
|
|
const QString arrayarg = QLatin1Char('[') + arrayargs.join( QStringLiteral(", ") ) + QLatin1Char(']');
|
|
|
|
eval( QStringLiteral("if (this.messageHandler && typeof this.messageHandler.onMessage == 'function') "
|
|
|
|
"{ this.messageHandler.onMessage(") + arrayarg + QStringLiteral(") }") );
|
2008-04-01 09:10:46 +00:00
|
|
|
}
|
|
|
|
|
2009-10-26 20:59:24 +00:00
|
|
|
}
|
2008-04-01 09:10:46 +00:00
|
|
|
|
2014-08-08 22:00:07 +00:00
|
|
|
#include "moc_extensions.cpp"
|
2008-04-01 09:10:46 +00:00
|
|
|
|
|
|
|
/* kate: replace-tabs on; indent-width 4; */
|