Commit dcb84c08 authored by Anmol Ahuja's avatar Anmol Ahuja
Browse files

Check for QtBindings at runtime.

Only check for a minimum set of bindings. Disable scripts and display warning if not found.

BUG: 325006
parent 088cb0f0
......@@ -95,8 +95,6 @@ add_definitions( ${QT_DEFINITIONS} ${KDE4_DEFINITIONS} )
# QCA2 is required for the Script Updater
find_package( QCA2 )
find_package( QtScriptQtBindings )
macro_optional_find_package( LibLastFm )
set( LIBLASTFM_MIN_VERSION "1.0.0" )
if( LIBLASTFM_FOUND )
......@@ -132,8 +130,6 @@ if( WITH_PLAYER )
macro_log_feature( QT_QTOPENGL_FOUND "QtOpenGL" "Required for the spectrum analyzer" "http://qt-project.org" FALSE "" "" )
macro_log_feature( QTSCRIPTQTBINDINGS_FOUND "qtscript-qt" "QtScript Qt Bindings" "http://code.google.com/p/qtscriptgenerator/" FALSE "" "" )
find_package(MySQLAmarok REQUIRED)
if( WITH_MYSQL_EMBEDDED )
set( BUILD_MYSQLE_COLLECTION TRUE )
......
......@@ -17,6 +17,8 @@ VERSION 2.9-Beta 1
from APE tags. Patch by Bruno Léon <bruno.leon@nividic.org>. (BR 323735)
* Using Shuffle keyboard shortcut no longer causes Amarok to crash.
(BR 323614)
* Check for QtBindings at runtime instead. Disable scripts and display error message
if missing. (BR 325006)
VERSION 2.8
......
......@@ -25,9 +25,7 @@ add_subdirectory( core-impl/collections )
#don't use our own libplasma anymore, but still pick up our applets/engines/containments
add_subdirectory( context )
add_subdirectory( services )
if( QTSCRIPTQTBINDINGS_FOUND )
add_subdirectory( scripts )
endif( QTSCRIPTQTBINDINGS_FOUND )
add_subdirectory( scripts )
add_subdirectory( aboutdialog/libattica-ocsclient )
add_subdirectory( transcoding )
add_subdirectory( kconf_update )
......
......@@ -1123,9 +1123,6 @@ MainWindow::createMenus()
m_toolsMenu.data()->addAction( Amarok::actionCollection()->action("bookmark_manager") );
m_toolsMenu.data()->addAction( Amarok::actionCollection()->action("cover_manager") );
m_toolsMenu.data()->addAction( Amarok::actionCollection()->action("equalizer_dialog") );
#ifdef QTSCRIPTQTBINDINGS_FOUND
m_toolsMenu.data()->addAction( Amarok::actionCollection()->action("script_manager") );
#endif
#ifdef DEBUG_BUILD_TYPE
m_toolsMenu.data()->addAction( Amarok::actionCollection()->action("network_request_viewer") );
#endif // DEBUG_BUILD_TYPE
......
......@@ -50,6 +50,7 @@
#include "scriptengine/ScriptImporter.h"
#include "ScriptUpdater.h"
#include <KMessageBox>
#include <KStandardDirs>
#include <QFileInfo>
......@@ -73,10 +74,43 @@ ScriptManager::ScriptManager( QObject* parent )
s_instance = this;
if( AmarokConfig::enableScripts() == false )
{
if( !minimumBindingsAvailable() )
{
KMessageBox::error( 0,
i18n( "Scripts have been disabled since you are missing the QtScriptQtBindings "
"package. Please install the package and restart Amarok for scripts to work." ),
i18n( "Scripts Disabled!" ) );
return;
}
AmarokConfig::setEnableScripts( true );
}
// Delay this call via eventloop, because it's a bit slow and would block
QTimer::singleShot( 0, this, SLOT(updateAllScripts()) );
}
bool
ScriptManager::minimumBindingsAvailable()
{
QStringList minimumBindings;
minimumBindings << "qt.core" << "qt.gui" << "qt.sql" << "qt.webkit" << "qt.xml" << "qt.uitools" << "qt.network";
QScriptEngine engine;
foreach( const QString &binding, minimumBindings )
{
// simply compare with availableExtensions()? Or can import still fail?
QScriptValue error = engine.importExtension( binding );
if( error.isUndefined() )
continue; // undefined indicates success
debug() << "Extension" << binding << "not found:" << error.toString();
debug() << "Available extensions:" << engine.availableExtensions();
return false;
}
return true;
}
ScriptManager::~ScriptManager()
{
DEBUG_BLOCK
......@@ -294,7 +328,7 @@ ScriptManager::slotRunScript( const QString &name, bool silent )
return true;
}
void ScriptManager::handleException(const QScriptValue& value)
void ScriptManager::handleException( const QScriptValue &value )
{
DEBUG_BLOCK
......
......@@ -88,6 +88,8 @@ class AMAROK_EXPORT ScriptManager : public QObject
void ServiceScriptCustomize( const QString &name );
static bool minimumBindingsAvailable();
typedef QHash<QString, ScriptItem*> ScriptMap;
ScriptMap m_scripts;
QString m_lyricsScript;
......
......@@ -578,6 +578,11 @@
</group>
<group name="ScriptManager">
<entry key="Enable Scripts" type="Bool">
<label>Whether to enable Amarok's scripting module.</label>
<whatsthis>Enable/Disable Amarok's scripting module.</whatsthis>
<default>false</default>
</entry>
<entry key="AutoUpdateScripts" type="Bool">
<label>Whether to automatically update built-in scripts</label>
<whatsthis>Enable/Disable automatic update for built-in scripts.</whatsthis>
......
......@@ -59,6 +59,7 @@ ScriptsConfig::ScriptsConfig( QWidget *parent )
connect( m_selector, SIGNAL(changed(bool)), SLOT(slotConfigChanged(bool)) );
connect( m_selector, SIGNAL(changed(bool)), parent, SLOT(updateButtons()) );
this->setEnabled( AmarokConfig::enableScripts() );
}
ScriptsConfig::~ScriptsConfig()
......
......@@ -24,6 +24,7 @@
#include <QScriptEngine>
#include <QSet>
#include <QStringList>
using namespace AmarokScript;
......@@ -46,16 +47,13 @@ ScriptImporter::loadExtension( const QString& src )
bool
ScriptImporter::loadQtBinding( const QString& binding )
{
QSet<QString> allowedBindings;
#ifdef QTSCRIPTQTBINDINGS_FOUND
allowedBindings << "qt.core" << "qt.gui" << "qt.sql" << "qt.webkit" << "qt.xml" << "qt.uitools" << "qt.network";
#endif
if( allowedBindings.contains( binding ) )
QStringList availableBindings = m_scriptEngine->availableExtensions();
if( availableBindings.contains( binding ) )
{
if( !m_importedBindings.contains( binding ) )
{
if( m_scriptEngine->importExtension( binding ).isUndefined() )
{ // undefined indiciates success
{ // undefined indicates success
m_importedBindings << binding;
return true;
}
......@@ -65,7 +63,7 @@ ScriptImporter::loadQtBinding( const QString& binding )
return true;
}
else
warning() << __PRETTY_FUNCTION__ << "Qt Binding" << binding << "not allowed!";
warning() << __PRETTY_FUNCTION__ << "Binding \"" << binding << "\" could not be found!";
return false;
}
......@@ -85,3 +83,9 @@ ScriptImporter::include( const QString& relativeFilename )
m_scriptEngine->evaluate( file.readAll(), relativeFilename );
return true;
}
QStringList
ScriptImporter::availableBindings() const
{
return m_scriptEngine->availableExtensions();
}
......@@ -34,6 +34,7 @@ namespace AmarokScript
ScriptImporter( QScriptEngine* ScriptEngine, const KUrl &url );
public slots:
QStringList availableBindings() const;
void loadExtension( const QString &src );
bool loadQtBinding( const QString &binding );
bool include( const QString &relativeFile );
......
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