From 5b1000834f0db625e0d4d3927367bd55f7c35cfd Mon Sep 17 00:00:00 2001 From: David Sansome Date: Fri, 31 Dec 2010 18:13:28 +0000 Subject: [PATCH] Add some basic script loading support and add python bindings for the Player class --- CMakeLists.txt | 14 ++ cmake/SipBindings.cmake | 63 +++++++++ src/CMakeLists.txt | 35 +++++ src/config.h.in | 3 + src/core/utilities.cpp | 3 + src/core/utilities.h | 1 + src/scripting/languageengine.cpp | 18 +++ src/scripting/languageengine.h | 35 +++++ src/scripting/python/clementine.sip | 6 + src/scripting/python/player.sip | 54 ++++++++ src/scripting/python/pythonengine.cpp | 47 +++++++ src/scripting/python/pythonengine.h | 36 ++++++ src/scripting/python/pythonscript.cpp | 67 ++++++++++ src/scripting/python/pythonscript.h | 36 ++++++ src/scripting/script.cpp | 24 ++++ src/scripting/script.h | 40 ++++++ src/scripting/scriptdialog.cpp | 37 ++++++ src/scripting/scriptdialog.h | 41 ++++++ src/scripting/scriptdialog.ui | 67 ++++++++++ src/scripting/scriptmanager.cpp | 178 ++++++++++++++++++++++++++ src/scripting/scriptmanager.h | 87 +++++++++++++ src/translations/ar.po | 3 + src/translations/be.po | 3 + src/translations/bg.po | 3 + src/translations/br.po | 3 + src/translations/ca.po | 3 + src/translations/cs.po | 3 + src/translations/cy.po | 3 + src/translations/da.po | 3 + src/translations/de.po | 3 + src/translations/el.po | 3 + src/translations/en.po | 3 + src/translations/en_CA.po | 3 + src/translations/en_GB.po | 3 + src/translations/eo.po | 3 + src/translations/es.po | 3 + src/translations/et.po | 3 + src/translations/eu.po | 3 + src/translations/fi.po | 3 + src/translations/fr.po | 3 + src/translations/gl.po | 3 + src/translations/he.po | 3 + src/translations/hi.po | 3 + src/translations/hr.po | 3 + src/translations/hu.po | 3 + src/translations/it.po | 3 + src/translations/ja.po | 3 + src/translations/kk.po | 3 + src/translations/lt.po | 3 + src/translations/nb.po | 3 + src/translations/nl.po | 3 + src/translations/oc.po | 3 + src/translations/pl.po | 3 + src/translations/pt.po | 3 + src/translations/pt_BR.po | 3 + src/translations/ro.po | 3 + src/translations/ru.po | 3 + src/translations/sk.po | 3 + src/translations/sl.po | 3 + src/translations/sr.po | 3 + src/translations/sv.po | 3 + src/translations/tr.po | 3 + src/translations/translations.pot | 3 + src/translations/uk.po | 3 + src/translations/zh_CN.po | 3 + src/translations/zh_TW.po | 3 + src/ui/mainwindow.cpp | 26 +++- src/ui/mainwindow.h | 9 ++ src/ui/mainwindow.ui | 13 +- 69 files changed, 1070 insertions(+), 5 deletions(-) create mode 100644 cmake/SipBindings.cmake create mode 100644 src/scripting/languageengine.cpp create mode 100644 src/scripting/languageengine.h create mode 100644 src/scripting/python/clementine.sip create mode 100644 src/scripting/python/player.sip create mode 100644 src/scripting/python/pythonengine.cpp create mode 100644 src/scripting/python/pythonengine.h create mode 100644 src/scripting/python/pythonscript.cpp create mode 100644 src/scripting/python/pythonscript.h create mode 100644 src/scripting/script.cpp create mode 100644 src/scripting/script.h create mode 100644 src/scripting/scriptdialog.cpp create mode 100644 src/scripting/scriptdialog.h create mode 100644 src/scripting/scriptdialog.ui create mode 100644 src/scripting/scriptmanager.cpp create mode 100644 src/scripting/scriptmanager.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 09b20ee15..d08810de5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ include(cmake/Summary.cmake) include(cmake/Version.cmake) include(cmake/Deb.cmake) include(cmake/Rpm.cmake) +include(cmake/SipBindings.cmake) find_package(Qt4 4.5.0 REQUIRED QtCore QtGui QtOpenGL QtSql QtNetwork QtXml) if(UNIX AND NOT APPLE) @@ -41,6 +42,7 @@ find_package(OpenGL REQUIRED) find_package(Boost REQUIRED) find_package(Gettext REQUIRED) find_package(PkgConfig REQUIRED) +find_package(PythonLibs) pkg_check_modules(TAGLIB REQUIRED taglib>=1.6) pkg_check_modules(GSTREAMER gstreamer-0.10) @@ -138,6 +140,8 @@ option(ENABLE_VISUALISATIONS "Use libprojectm visualisations" ON) option(BUNDLE_PROJECTM_PRESETS "Install Clementine's own copies of libprojectm presets - disable this if you want to use a system package instead" ON) option(ENABLE_SOUNDMENU "Add Clementine to the Gnome sound menu" ON) option(ENABLE_LIBLASTFM "Use liblastfm for fetching song info, scrobbling and radio streams" ON) +option(ENABLE_SCRIPTING "Enable scripting support" ON) +option(ENABLE_SCRIPTING_PYTHON "Enable python scripting" ON) if(ENABLE_LIBGPOD AND LIBGPOD_FOUND) set(HAVE_LIBGPOD ON) @@ -163,6 +167,14 @@ if(ENABLE_LIBLASTFM AND LASTFM_LIBRARIES AND LASTFM_INCLUDE_DIRS) set(HAVE_LIBLASTFM ON) endif(ENABLE_LIBLASTFM AND LASTFM_LIBRARIES AND LASTFM_INCLUDE_DIRS) +if(ENABLE_SCRIPTING) + set(HAVE_SCRIPTING ON) +endif(ENABLE_SCRIPTING) + +if(ENABLE_SCRIPTING_PYTHON AND ENABLE_SCRIPTING AND PYTHONLIBS_FOUND AND PYQT_SIP_DIR) + set(HAVE_SCRIPTING_PYTHON ON) +endif(ENABLE_SCRIPTING_PYTHON AND ENABLE_SCRIPTING AND PYTHONLIBS_FOUND AND PYQT_SIP_DIR) + if(ENABLE_VISUALISATIONS) # When/if upstream accepts our patches then these options can be used to link # to system installed projectM instead. @@ -278,5 +290,7 @@ summary_add("Gnome sound menu integration" HAVE_LIBINDICATE) summary_add("Wiimote support" ENABLE_WIIMOTEDEV) summary_add("Visualisations" ENABLE_VISUALISATIONS) summary_add("Last.fm support" HAVE_LIBLASTFM) +summary_add("Scripting support" HAVE_SCRIPTING) +summary_add("Scripting support: Python" HAVE_SCRIPTING_PYTHON) summary_add("(Mac OS X) Sparkle integration" HAVE_SPARKLE) summary_show() diff --git a/cmake/SipBindings.cmake b/cmake/SipBindings.cmake new file mode 100644 index 000000000..8f3b75e46 --- /dev/null +++ b/cmake/SipBindings.cmake @@ -0,0 +1,63 @@ +find_path(PYQT_SIP_DIR pyqt-gpl.sip + PATH_SUFFIXES share/sip/PyQt4 +) + +macro(add_sip_bindings outputvar) + # Work out what the SIP flags should be for PyQt4. These would normally be + # obtained from PyQt4.pyqtconfig.Configuration().pyqt_sip_flags, but we can't + # call that when cross-compiling. + set(PYQT_SIP_FLAGS + "-x" "VendorID" + "-x" "PyQt_NoPrintRangeBug" + "-t" "Qt_${QT_VERSION_MAJOR}_${QT_VERSION_MINOR}_${QT_VERSION_PATCH}" + ) + + if(WIN32) + list(APPEND PYQT_SIP_FLAGS "-t" "WS_WIN") + elseif(APPLE) + list(APPEND PYQT_SIP_FLAGS "-t" "WS_MAC") + else(WIN32) + list(APPEND PYQT_SIP_FLAGS "-t" "WS_X11") + endif(WIN32) + + foreach(source ${ARGN}) + get_filename_component(source_directory ${source} PATH) + get_filename_component(source_basename ${source} NAME) + get_filename_component(source_module ${source} NAME_WE) + + set(outputs + "${CMAKE_CURRENT_BINARY_DIR}/sip${source_module}cmodule.cpp" + "${CMAKE_CURRENT_BINARY_DIR}/sipAPI${source_module}.h" + ) + + # Find any included files + execute_process( + COMMAND "awk" "/^%Include/ {ORS=\";\"; print \"${source_directory}/\" $2}" + "${CMAKE_CURRENT_SOURCE_DIR}/${source}" + OUTPUT_VARIABLE included_files + ) + foreach(included_file ${included_files} ${source}) + # Sip creates 1 file per class... so we have to figure out what classes + # it will generate + execute_process( + COMMAND "awk" "/^\\s*class +([A-Za-z0-9]+)/ {ORS=\";\"; print $2}" + "${CMAKE_CURRENT_SOURCE_DIR}/${included_file}" + OUTPUT_VARIABLE classes + ) + foreach(class ${classes}) + list(APPEND outputs "${CMAKE_CURRENT_BINARY_DIR}/sip${source_module}${class}.cpp") + endforeach(class) + endforeach(included_file) + + add_custom_command( + OUTPUT ${outputs} + COMMAND "sip" ${PYQT_SIP_FLAGS} + "-I${PYQT_SIP_DIR}" + "-c" "${CMAKE_CURRENT_BINARY_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/${source}" + DEPENDS ${included_files} "${source}" + ) + + list(APPEND ${outputvar} ${outputs}) + endforeach(source) +endmacro(add_sip_bindings) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dea96e8e5..656e441f0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,6 +27,10 @@ if(HAVE_LIBLASTFM) include_directories(${LASTFM_INCLUDE_DIRS}) endif(HAVE_LIBLASTFM) +if(HAVE_SCRIPTING_PYTHON) + include_directories(${PYTHON_INCLUDE_DIRS}) +endif(HAVE_SCRIPTING_PYTHON) + cmake_policy(SET CMP0011 NEW) include(../cmake/ParseArguments.cmake) include(../cmake/Translations.cmake) @@ -684,6 +688,33 @@ if(APPLE) list(APPEND SOURCES core/mac_startup.mm) endif(APPLE) +if(HAVE_SCRIPTING) + list(APPEND SOURCES + scripting/languageengine.cpp + scripting/script.cpp + scripting/scriptdialog.cpp + scripting/scriptmanager.cpp + ) + list(APPEND HEADERS + scripting/scriptdialog.h + scripting/scriptmanager.h + ) + list(APPEND UI + scripting/scriptdialog.ui + ) + + if(HAVE_SCRIPTING_PYTHON) + list(APPEND SOURCES + scripting/python/pythonengine.cpp + scripting/python/pythonscript.cpp + ) + + add_sip_bindings(SOURCES + scripting/python/clementine.sip + ) + endif(HAVE_SCRIPTING_PYTHON) +endif(HAVE_SCRIPTING) + # OS-specific sources that should be searched for translatable strings even # if they're not compiled list(APPEND OTHER_SOURCES @@ -813,6 +844,10 @@ if(HAVE_LIBINDICATE) target_link_libraries(clementine_lib ${INDICATEQT_LIBRARIES}) endif(HAVE_LIBINDICATE) +if(HAVE_SCRIPTING_PYTHON) + target_link_libraries(clementine_lib ${PYTHON_LIBRARIES}) +endif(HAVE_SCRIPTING_PYTHON) + if (APPLE) target_link_libraries(clementine_lib ${GROWL} diff --git a/src/config.h.in b/src/config.h.in index 2baa3ae1b..3710d52cf 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -43,4 +43,7 @@ #cmakedefine HAVE_LIBLASTFM #cmakedefine HAVE_LIBMTP +#cmakedefine HAVE_SCRIPTING +#cmakedefine HAVE_SCRIPTING_PYTHON + #endif // CONFIG_H_IN diff --git a/src/core/utilities.cpp b/src/core/utilities.cpp index 625480255..8fb1b5a7a 100644 --- a/src/core/utilities.cpp +++ b/src/core/utilities.cpp @@ -220,6 +220,9 @@ QString GetConfigPath(ConfigPath config) { return GetConfigPath(Path_Root) + QString("/gst-registry-%1-bin").arg(QCoreApplication::applicationVersion()); + case Path_Scripts: + return GetConfigPath(Path_Root) + "/scripts"; + case Path_DefaultMusicLibrary: #ifdef Q_OS_DARWIN return mac::GetMusicDirectory(); diff --git a/src/core/utilities.h b/src/core/utilities.h index ab7338657..0cec3655b 100644 --- a/src/core/utilities.h +++ b/src/core/utilities.h @@ -48,6 +48,7 @@ namespace Utilities { Path_NetworkCache, Path_GstreamerRegistry, Path_DefaultMusicLibrary, + Path_Scripts, }; QString GetConfigPath(ConfigPath config); } diff --git a/src/scripting/languageengine.cpp b/src/scripting/languageengine.cpp new file mode 100644 index 000000000..6e9177e36 --- /dev/null +++ b/src/scripting/languageengine.cpp @@ -0,0 +1,18 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + Clementine 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 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include "languageengine.h" diff --git a/src/scripting/languageengine.h b/src/scripting/languageengine.h new file mode 100644 index 000000000..59abad251 --- /dev/null +++ b/src/scripting/languageengine.h @@ -0,0 +1,35 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + Clementine 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 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef LANGUAGEENGINE_H +#define LANGUAGEENGINE_H + +#include "scriptmanager.h" + +class Script; + +class LanguageEngine { +public: + virtual ~LanguageEngine() {} + + virtual ScriptManager::Language language() const = 0; + virtual QString name() const = 0; + + virtual Script* CreateScript(const QString& path, const QString& script_file) = 0; +}; + +#endif // LANGUAGEENGINE_H diff --git a/src/scripting/python/clementine.sip b/src/scripting/python/clementine.sip new file mode 100644 index 000000000..03ac2ff46 --- /dev/null +++ b/src/scripting/python/clementine.sip @@ -0,0 +1,6 @@ +%Module clementine 0 + +%Import QtCore/QtCoremod.sip +%Import QtGui/QtGuimod.sip + +%Include player.sip diff --git a/src/scripting/python/player.sip b/src/scripting/python/player.sip new file mode 100644 index 000000000..eb9a77263 --- /dev/null +++ b/src/scripting/python/player.sip @@ -0,0 +1,54 @@ +class Player : QObject { + +%TypeHeaderCode +#include "core/player.h" +%End + +public: + // Engine::State GetState() const; + int GetVolume() const; + + //PlaylistItemPtr GetCurrentItem() const { return current_item_; } + //PlaylistItemPtr GetItemAt(int pos) const; + //PlaylistManager* playlists() const { return playlists_; } + +public slots: + // Manual track change to the specified track + //void PlayAt(int i, Engine::TrackChangeType change, bool reshuffle); + + // If there's currently a song playing, pause it, otherwise play the track + // that was playing last, or the first one on the playlist + void PlayPause(); + + // Skips this track. Might load more of the current radio station. + void Next(); + void Previous(); + + void SetVolume(int value); + void VolumeUp(); + void VolumeDown(); + void Mute(); + + void Seek(int seconds); + void SeekForward(); + void SeekBackward(); + + void Pause(); + void Stop(); + void Play(); + void ShowOSD(); + +signals: + void Playing(); + void Paused(); + void Stopped(); + void PlaylistFinished(); + void VolumeChanged(int volume); + void Error(const QString& message); + //void TrackSkipped(PlaylistItemPtr old_track); + + //void ForceShowOSD(Song); + +private: + Player(); +}; diff --git a/src/scripting/python/pythonengine.cpp b/src/scripting/python/pythonengine.cpp new file mode 100644 index 000000000..980e05f95 --- /dev/null +++ b/src/scripting/python/pythonengine.cpp @@ -0,0 +1,47 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + Clementine 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 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include + +#include "pythonengine.h" +#include "pythonscript.h" + +extern "C" { + void initclementine(); +} + +PythonEngine::PythonEngine() + : initialised_(false) +{ +} + +Script* PythonEngine::CreateScript(const QString& path, const QString& script_file) { + // Initialise Python if it hasn't been done yet + if (!initialised_) { + // Add the Clementine builtin module + PyImport_AppendInittab(const_cast("clementine"), initclementine); + + Py_SetProgramName(const_cast("clementine")); + PyEval_InitThreads(); + Py_InitializeEx(0); + PyEval_ReleaseLock(); + + initialised_ = true; + } + + return new PythonScript(path, script_file); +} diff --git a/src/scripting/python/pythonengine.h b/src/scripting/python/pythonengine.h new file mode 100644 index 000000000..2d6636de0 --- /dev/null +++ b/src/scripting/python/pythonengine.h @@ -0,0 +1,36 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + Clementine 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 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef PYTHONENGINE_H +#define PYTHONENGINE_H + +#include "scripting/languageengine.h" + +class PythonEngine : public LanguageEngine { +public: + PythonEngine(); + + ScriptManager::Language language() const { return ScriptManager::Language_Python; } + QString name() const { return "python"; } + + Script* CreateScript(const QString& path, const QString& script_file); + +private: + bool initialised_; +}; + +#endif // PYTHONENGINE_H diff --git a/src/scripting/python/pythonscript.cpp b/src/scripting/python/pythonscript.cpp new file mode 100644 index 000000000..002fade19 --- /dev/null +++ b/src/scripting/python/pythonscript.cpp @@ -0,0 +1,67 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + Clementine 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 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include + +#include "pythonscript.h" + +#include +#include + + +PythonScript::PythonScript(const QString& path, const QString& script_file) + : Script(path, script_file), + interpreter_(NULL) +{ +} + +bool PythonScript::Init() { + // Open the file + QFile file(script_file()); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "Error opening file:" << script_file(); + return false; + } + + // Create a python interpreter + PyEval_AcquireLock(); + interpreter_ = Py_NewInterpreter(); + PyEval_ReleaseLock(); + + // Get a file stream from the file handle + FILE* stream = fdopen(file.handle(), "r"); + + if (PyRun_SimpleFile(stream, script_file().toLocal8Bit().constData()) != 0) { + PyEval_AcquireLock(); + Py_EndInterpreter(interpreter_); + PyEval_ReleaseLock(); + + interpreter_ = NULL; + return false; + } + + return true; +} + +bool PythonScript::Unload() { + PyEval_AcquireLock(); + Py_EndInterpreter(interpreter_); + PyEval_ReleaseLock(); + + interpreter_ = NULL; + return true; +} diff --git a/src/scripting/python/pythonscript.h b/src/scripting/python/pythonscript.h new file mode 100644 index 000000000..7747c018f --- /dev/null +++ b/src/scripting/python/pythonscript.h @@ -0,0 +1,36 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + Clementine 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 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef PYTHONSCRIPT_H +#define PYTHONSCRIPT_H + +#include "scripting/script.h" + +struct _ts; // PyThreadState + +class PythonScript : public Script { +public: + PythonScript(const QString& path, const QString& script_file); + + bool Init(); + bool Unload(); + +private: + _ts* interpreter_; +}; + +#endif // PYTHONSCRIPT_H diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp new file mode 100644 index 000000000..b81a02e4d --- /dev/null +++ b/src/scripting/script.cpp @@ -0,0 +1,24 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + Clementine 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 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include "script.h" + +Script::Script(const QString& path, const QString& script_file) + : path_(path), + script_file_(script_file) +{ +} diff --git a/src/scripting/script.h b/src/scripting/script.h new file mode 100644 index 000000000..3ad08f432 --- /dev/null +++ b/src/scripting/script.h @@ -0,0 +1,40 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + Clementine 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 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef SCRIPT_H +#define SCRIPT_H + +#include + +class Script { +public: + Script(const QString& path, const QString& script_file); + virtual ~Script() {} + + const QString& path() const { return path_; } + const QString& script_file() const { return script_file_; } + + virtual bool Init() = 0; + virtual bool Unload() = 0; + virtual bool Reload() { return Unload() && Init(); } + +private: + QString path_; + QString script_file_; +}; + +#endif // SCRIPT_H diff --git a/src/scripting/scriptdialog.cpp b/src/scripting/scriptdialog.cpp new file mode 100644 index 000000000..1f08e39a2 --- /dev/null +++ b/src/scripting/scriptdialog.cpp @@ -0,0 +1,37 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + Clementine 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 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include "scriptdialog.h" +#include "scriptmanager.h" +#include "ui_scriptdialog.h" + +ScriptDialog::ScriptDialog(QWidget* parent) + : QDialog(parent), + ui_(new Ui_ScriptDialog), + manager_(NULL) +{ + ui_->setupUi(this); +} + +ScriptDialog::~ScriptDialog() { + delete ui_; +} + +void ScriptDialog::SetManager(ScriptManager* manager) { + manager_ = manager; + ui_->list->setModel(manager); +} diff --git a/src/scripting/scriptdialog.h b/src/scripting/scriptdialog.h new file mode 100644 index 000000000..cee5f03a5 --- /dev/null +++ b/src/scripting/scriptdialog.h @@ -0,0 +1,41 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + Clementine 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 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef SCRIPTDIALOG_H +#define SCRIPTDIALOG_H + +#include + +class ScriptManager; +class Ui_ScriptDialog; + +class ScriptDialog : public QDialog { + Q_OBJECT + +public: + ScriptDialog(QWidget* parent = 0); + ~ScriptDialog(); + + void SetManager(ScriptManager* manager); + +private: + Ui_ScriptDialog* ui_; + + ScriptManager* manager_; +}; + +#endif // SCRIPTDIALOG_H diff --git a/src/scripting/scriptdialog.ui b/src/scripting/scriptdialog.ui new file mode 100644 index 000000000..128a2d673 --- /dev/null +++ b/src/scripting/scriptdialog.ui @@ -0,0 +1,67 @@ + + + ScriptDialog + + + + 0 + 0 + 645 + 388 + + + + Script Manager + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + button_box + accepted() + ScriptDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + button_box + rejected() + ScriptDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/scripting/scriptmanager.cpp b/src/scripting/scriptmanager.cpp new file mode 100644 index 000000000..35f03dfb4 --- /dev/null +++ b/src/scripting/scriptmanager.cpp @@ -0,0 +1,178 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + Clementine 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 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include "config.h" +#include "languageengine.h" +#include "script.h" +#include "scriptmanager.h" +#include "core/utilities.h" + +#ifdef HAVE_SCRIPTING_PYTHON +# include "scripting/python/pythonengine.h" +#endif + +#include +#include +#include + +const char* ScriptManager::kIniFileName = "script.ini"; + +ScriptManager::ScriptManager(QObject* parent) + : QAbstractListModel(parent) +{ +#ifdef HAVE_SCRIPTING_PYTHON + engines_ << new PythonEngine; +#endif + + search_paths_ << Utilities::GetConfigPath(Utilities::Path_Scripts); + + Reset(); +} + +ScriptManager::~ScriptManager() { + qDeleteAll(engines_); +} + +void ScriptManager::Reset() { + // Remove any scripts that aren't loaded + for (int i=0 ; iname() == language_name) { + return engine; + } + } + return NULL; +} + +LanguageEngine* ScriptManager::EngineForLanguage(ScriptManager::Language language) const { + foreach (LanguageEngine* engine, engines_) { + if (engine->language() == language) { + return engine; + } + } + return NULL; +} + +ScriptManager::ScriptInfo ScriptManager::LoadScriptInfo(const QString& path) { + const QString ini_file = path + "/" + kIniFileName; + + // Does the file exist? + ScriptManager::ScriptInfo ret; + if (!QFile::exists(ini_file)) { + qWarning() << "Script definition file not found:" << ini_file; + return ret; + } + + // Open it + QSettings s(ini_file, QSettings::IniFormat); + if (!s.childGroups().contains("Script")) { + qWarning() << "Missing [Script] section in" << ini_file; + return ret; + } + s.beginGroup("Script"); + + // Find out what language it's in + QString language_name = s.value("language").toString(); + LanguageEngine* engine = EngineForLanguage(language_name); + if (!engine) { + qWarning() << "Unknown language" << language_name << "in" << ini_file; + return ret; + } + ret.language_ = engine->language(); + + // Load the rest of the metadata + ret.path_ = path; + ret.name_ = s.value("name").toString(); + ret.description_ = s.value("description").toString(); + ret.author_ = s.value("author").toString(); + ret.url_ = s.value("url").toString(); + ret.script_file_ = path + "/" + s.value("script_file").toString(); + + // Load the script - TODO: move somewhere else + ret.loaded_ = engine->CreateScript(path, ret.script_file_); + if (ret.loaded_) { + ret.loaded_->Init(); + } + + return ret; +} + +int ScriptManager::rowCount(const QModelIndex& parent) const { + if (parent.isValid()) + return 0; + return info_.count(); +} + +QVariant ScriptManager::data(const QModelIndex& index, int role) const { + if (index.parent().isValid() || index.row() < 0 || index.row() >= info_.count()) + return QVariant(); + + const ScriptInfo& info = info_[index.row()]; + + switch (role) { + case Qt::DisplayRole: + return info.name_; + + case Role_Author: + return info.author_; + + case Role_Description: + return info.description_; + + case Role_Language: + return info.language_; + + case Role_ScriptFile: + return info.script_file_; + + case Role_Url: + return info.url_; + + default: + return QVariant(); + } +} diff --git a/src/scripting/scriptmanager.h b/src/scripting/scriptmanager.h new file mode 100644 index 000000000..301b33e1b --- /dev/null +++ b/src/scripting/scriptmanager.h @@ -0,0 +1,87 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + Clementine 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 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef SCRIPTMANAGER_H +#define SCRIPTMANAGER_H + +#include +#include + +class LanguageEngine; +class Script; + +class ScriptManager : public QAbstractListModel { + Q_OBJECT + +public: + ScriptManager(QObject* parent = 0); + ~ScriptManager(); + + enum Role { + Role_Description = Qt::UserRole, + Role_Author, + Role_Url, + Role_Language, + Role_ScriptFile, + + RoleCount + }; + + enum Language { + Language_Unknown = 0, + Language_Python, + }; + + static const char* kIniFileName; + + // QAbstractListModel + int rowCount(const QModelIndex& parent) const; + QVariant data(const QModelIndex& index, int role) const; + +private: + struct ScriptInfo { + ScriptInfo() : language_(Language_Unknown), loaded_(NULL) {} + + bool is_valid() const { return language_ != Language_Unknown; } + + QString path_; + + QString name_; + QString description_; + QString author_; + QString url_; + + Language language_; + QString script_file_; + + Script* loaded_; + }; + + void Reset(); + ScriptInfo LoadScriptInfo(const QString& path); + + LanguageEngine* EngineForLanguage(const QString& language_name) const; + LanguageEngine* EngineForLanguage(Language language) const; + +private: + QList engines_; + + QStringList search_paths_; + QList info_; +}; + +#endif // SCRIPTMANAGER_H diff --git a/src/translations/ar.po b/src/translations/ar.po index fd6a68292..f8166cce0 100644 --- a/src/translations/ar.po +++ b/src/translations/ar.po @@ -1888,6 +1888,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/be.po b/src/translations/be.po index c3eff923c..431e5cd91 100644 --- a/src/translations/be.po +++ b/src/translations/be.po @@ -1902,6 +1902,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/bg.po b/src/translations/bg.po index c4df61855..6aa0a42cc 100644 --- a/src/translations/bg.po +++ b/src/translations/bg.po @@ -1892,6 +1892,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/br.po b/src/translations/br.po index 5fe5410d2..7c90c751e 100644 --- a/src/translations/br.po +++ b/src/translations/br.po @@ -1888,6 +1888,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/ca.po b/src/translations/ca.po index 4137ffb99..e7049654c 100644 --- a/src/translations/ca.po +++ b/src/translations/ca.po @@ -1926,6 +1926,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/cs.po b/src/translations/cs.po index 51408d263..2b3db0c2c 100644 --- a/src/translations/cs.po +++ b/src/translations/cs.po @@ -1927,6 +1927,9 @@ msgstr "" msgid "Score" msgstr "Výsledek" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Se skladbami, které poslouchám, dělat to, čemu se říká \"scrobble\"" diff --git a/src/translations/cy.po b/src/translations/cy.po index 52329a5fc..923ff5bdf 100644 --- a/src/translations/cy.po +++ b/src/translations/cy.po @@ -1888,6 +1888,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/da.po b/src/translations/da.po index c2375d186..1bbbec2e3 100644 --- a/src/translations/da.po +++ b/src/translations/da.po @@ -1893,6 +1893,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Scrobble-spor som jeg lytter til" diff --git a/src/translations/de.po b/src/translations/de.po index 0fc9ef07f..9d9621581 100644 --- a/src/translations/de.po +++ b/src/translations/de.po @@ -1930,6 +1930,9 @@ msgstr "" msgid "Score" msgstr "Bewertung" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Stücke die ich höre \"scrobbeln\"" diff --git a/src/translations/el.po b/src/translations/el.po index 08c7caa94..bca7c244e 100644 --- a/src/translations/el.po +++ b/src/translations/el.po @@ -1937,6 +1937,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Κάνε \"srobble\" τα κομμάτια που ακούω" diff --git a/src/translations/en.po b/src/translations/en.po index 7cef9279e..5d8c41097 100644 --- a/src/translations/en.po +++ b/src/translations/en.po @@ -1877,6 +1877,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/en_CA.po b/src/translations/en_CA.po index d19bd4d2d..6c41a5567 100644 --- a/src/translations/en_CA.po +++ b/src/translations/en_CA.po @@ -1893,6 +1893,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Scrobble tracks that I listen to" diff --git a/src/translations/en_GB.po b/src/translations/en_GB.po index a5e68df23..b5fcdc6fc 100644 --- a/src/translations/en_GB.po +++ b/src/translations/en_GB.po @@ -1890,6 +1890,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Scrobble tracks that I listen to" diff --git a/src/translations/eo.po b/src/translations/eo.po index 93a63fa2d..2bd8ce0a4 100644 --- a/src/translations/eo.po +++ b/src/translations/eo.po @@ -1888,6 +1888,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/es.po b/src/translations/es.po index 2eb64e3e6..4805f1c24 100644 --- a/src/translations/es.po +++ b/src/translations/es.po @@ -1938,6 +1938,9 @@ msgstr "" msgid "Score" msgstr "Puntuación" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Enviar las pistas que reproduzco" diff --git a/src/translations/et.po b/src/translations/et.po index dba797f1a..41d5ac5c2 100644 --- a/src/translations/et.po +++ b/src/translations/et.po @@ -1890,6 +1890,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/eu.po b/src/translations/eu.po index 33fffb13b..03178e946 100644 --- a/src/translations/eu.po +++ b/src/translations/eu.po @@ -1888,6 +1888,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/fi.po b/src/translations/fi.po index 933f3eb95..78081e72a 100644 --- a/src/translations/fi.po +++ b/src/translations/fi.po @@ -1890,6 +1890,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/fr.po b/src/translations/fr.po index 6dd604215..45f607063 100644 --- a/src/translations/fr.po +++ b/src/translations/fr.po @@ -1943,6 +1943,9 @@ msgstr "" msgid "Score" msgstr "Score" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Envoyer les titres des pistes que j'écoute (scrobble)" diff --git a/src/translations/gl.po b/src/translations/gl.po index 191c9768e..841b47786 100644 --- a/src/translations/gl.po +++ b/src/translations/gl.po @@ -1894,6 +1894,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/he.po b/src/translations/he.po index e757bfb64..b8f7011dc 100644 --- a/src/translations/he.po +++ b/src/translations/he.po @@ -1896,6 +1896,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/hi.po b/src/translations/hi.po index fda27412b..97347697f 100644 --- a/src/translations/hi.po +++ b/src/translations/hi.po @@ -1888,6 +1888,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/hr.po b/src/translations/hr.po index d26484658..8c2ce05d2 100644 --- a/src/translations/hr.po +++ b/src/translations/hr.po @@ -1894,6 +1894,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/hu.po b/src/translations/hu.po index 07a8cabc2..00805b143 100644 --- a/src/translations/hu.po +++ b/src/translations/hu.po @@ -1926,6 +1926,9 @@ msgstr "" msgid "Score" msgstr "Pontszám" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Az általam hallgatott számok Scrobble funkcióval történő figyelése" diff --git a/src/translations/it.po b/src/translations/it.po index 8dc80c9b8..10572bbbd 100644 --- a/src/translations/it.po +++ b/src/translations/it.po @@ -1934,6 +1934,9 @@ msgstr "" msgid "Score" msgstr "Punteggio" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Scrobbling delle tracce ascoltate" diff --git a/src/translations/ja.po b/src/translations/ja.po index 2c22dcba4..3c0bdbddf 100644 --- a/src/translations/ja.po +++ b/src/translations/ja.po @@ -1916,6 +1916,9 @@ msgstr "" msgid "Score" msgstr "スコア" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "聴取するトラックを Scrobble する" diff --git a/src/translations/kk.po b/src/translations/kk.po index 26212e346..e627bc77d 100644 --- a/src/translations/kk.po +++ b/src/translations/kk.po @@ -1890,6 +1890,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/lt.po b/src/translations/lt.po index 819f2aa3f..a661295e4 100644 --- a/src/translations/lt.po +++ b/src/translations/lt.po @@ -1888,6 +1888,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/nb.po b/src/translations/nb.po index 79ccda941..f018e003c 100644 --- a/src/translations/nb.po +++ b/src/translations/nb.po @@ -1902,6 +1902,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Fortell last.fm om sangene jeg har lyttet til" diff --git a/src/translations/nl.po b/src/translations/nl.po index 1b28230d7..0bd16d19e 100644 --- a/src/translations/nl.po +++ b/src/translations/nl.po @@ -1921,6 +1921,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Scrobble de tracks waar ik naar luister" diff --git a/src/translations/oc.po b/src/translations/oc.po index 4d51a954c..ca8c11a21 100644 --- a/src/translations/oc.po +++ b/src/translations/oc.po @@ -1888,6 +1888,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/pl.po b/src/translations/pl.po index 5bd9ab35a..e63039eb9 100644 --- a/src/translations/pl.po +++ b/src/translations/pl.po @@ -1921,6 +1921,9 @@ msgstr "" msgid "Score" msgstr "Wynik" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Wysyłaj informacje o utworach których słucham" diff --git a/src/translations/pt.po b/src/translations/pt.po index 325cdfa41..ce0344232 100644 --- a/src/translations/pt.po +++ b/src/translations/pt.po @@ -1931,6 +1931,9 @@ msgstr "" msgid "Score" msgstr "Pontuação" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Enviar as faixas que eu oiço" diff --git a/src/translations/pt_BR.po b/src/translations/pt_BR.po index 3f6efdab4..2ca832eb2 100644 --- a/src/translations/pt_BR.po +++ b/src/translations/pt_BR.po @@ -1927,6 +1927,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Adicionar ao meu perfil os dados das músicas que eu ouvir" diff --git a/src/translations/ro.po b/src/translations/ro.po index b415b2e8d..8f7503ff3 100644 --- a/src/translations/ro.po +++ b/src/translations/ro.po @@ -1889,6 +1889,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/ru.po b/src/translations/ru.po index 1aeca20c0..7937fda59 100644 --- a/src/translations/ru.po +++ b/src/translations/ru.po @@ -1921,6 +1921,9 @@ msgstr "" msgid "Score" msgstr "Счет" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Скробблить треки, которые я слушаю" diff --git a/src/translations/sk.po b/src/translations/sk.po index 64163fbf8..7c1d9f2ef 100644 --- a/src/translations/sk.po +++ b/src/translations/sk.po @@ -1917,6 +1917,9 @@ msgstr "" msgid "Score" msgstr "Skóre" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Skrobblovať skladby, ktoré počúvam" diff --git a/src/translations/sl.po b/src/translations/sl.po index 879b717ef..6b7757cb4 100644 --- a/src/translations/sl.po +++ b/src/translations/sl.po @@ -1920,6 +1920,9 @@ msgstr "" msgid "Score" msgstr "Rezultat" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Pošlji podatke o predvajanih skladbah" diff --git a/src/translations/sr.po b/src/translations/sr.po index 8526e95be..e0d009ab3 100644 --- a/src/translations/sr.po +++ b/src/translations/sr.po @@ -1893,6 +1893,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/sv.po b/src/translations/sv.po index 75192aca6..f3605e658 100644 --- a/src/translations/sv.po +++ b/src/translations/sv.po @@ -1922,6 +1922,9 @@ msgstr "" msgid "Score" msgstr "Poäng" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Skrobbla låtar som jag lyssnar på" diff --git a/src/translations/tr.po b/src/translations/tr.po index 1e34413af..786ae62ff 100644 --- a/src/translations/tr.po +++ b/src/translations/tr.po @@ -1920,6 +1920,9 @@ msgstr "" msgid "Score" msgstr "Puan" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Dinlediğim parçaları skropla" diff --git a/src/translations/translations.pot b/src/translations/translations.pot index 45c3296c9..42b0d1d7a 100644 --- a/src/translations/translations.pot +++ b/src/translations/translations.pot @@ -1878,6 +1878,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/uk.po b/src/translations/uk.po index dc9ea8edf..db7204ce0 100644 --- a/src/translations/uk.po +++ b/src/translations/uk.po @@ -1922,6 +1922,9 @@ msgstr "" msgid "Score" msgstr "Рахунок" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "Скробблити доріжки, які я слухаю" diff --git a/src/translations/zh_CN.po b/src/translations/zh_CN.po index 31bfbdb0f..23e9dfb7a 100644 --- a/src/translations/zh_CN.po +++ b/src/translations/zh_CN.po @@ -1892,6 +1892,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/translations/zh_TW.po b/src/translations/zh_TW.po index ef18c9d02..26657a434 100644 --- a/src/translations/zh_TW.po +++ b/src/translations/zh_TW.po @@ -1893,6 +1893,9 @@ msgstr "" msgid "Score" msgstr "" +msgid "Script Manager" +msgstr "" + msgid "Scrobble tracks that I listen to" msgstr "" diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 7667d64b7..382e103c3 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -96,6 +96,11 @@ # include "visualisations/visualisationcontainer.h" #endif +#ifdef HAVE_SCRIPTING +# include "scripting/scriptdialog.h" +# include "scripting/scriptmanager.h" +#endif + #include #include #include @@ -166,6 +171,9 @@ MainWindow::MainWindow(QWidget* parent) #endif #ifdef ENABLE_WIIMOTEDEV wiimotedev_shortcuts_(NULL), +#endif +#ifdef HAVE_SCRIPTING + scripts_(new ScriptManager(this)), #endif playlist_menu_(new QMenu(this)), library_sort_model_(new QSortFilterProxyModel(this)), @@ -311,7 +319,7 @@ MainWindow::MainWindow(QWidget* parent) #ifdef HAVE_LIBLASTFM connect(ui_->action_cover_manager, SIGNAL(triggered()), SLOT(ShowCoverManager())); #else - ui_->action_cover_manager->setVisible(false); + ui_->action_cover_manager->setEnabled(false); #endif connect(ui_->action_equalizer, SIGNAL(triggered()), equalizer_.get(), SLOT(show())); connect(ui_->action_transcode, SIGNAL(triggered()), SLOT(ShowTranscodeDialog())); @@ -323,6 +331,12 @@ MainWindow::MainWindow(QWidget* parent) background_streams_, SLOT(AllGloryToTheHypnotoad(bool))); connect(ui_->action_queue_manager, SIGNAL(triggered()), SLOT(ShowQueueManager())); +#ifdef HAVE_SCRIPTING + connect(ui_->action_script_manager, SIGNAL(triggered()), SLOT(ShowScriptDialog())); +#else + ui_->action_script_manager->setEnabled(false); +#endif + // Give actions to buttons ui_->forward_button->setDefaultAction(ui_->action_next_track); ui_->back_button->setDefaultAction(ui_->action_previous_track); @@ -1781,3 +1795,13 @@ void MainWindow::PlaylistCurrentChanged(const QModelIndex& proxy_current) { if (source_current != playlist_menu_index_) playlist_menu_index_ = QModelIndex(); } + +void MainWindow::ShowScriptDialog() { +#ifdef HAVE_SCRIPTING + if (!script_dialog_) { + script_dialog_.reset(new ScriptDialog); + script_dialog_->SetManager(scripts_); + } + script_dialog_->show(); +#endif +} diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index d80bc4218..e4044feaf 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -57,6 +57,8 @@ class QueueManager; class RadioItem; class RadioModel; class RadioViewContainer; +class ScriptDialog; +class ScriptManager; class Song; class SongInfoBase; class SongInfoView; @@ -205,6 +207,7 @@ class MainWindow : public QMainWindow, public PlatformInterface { void OpenSettingsDialog(); void OpenSettingsDialogAtPage(SettingsDialog::Page page); void ShowSongInfoConfig(); + void ShowScriptDialog(); void SaveGeometry(); @@ -258,6 +261,7 @@ class MainWindow : public QMainWindow, public PlatformInterface { boost::scoped_ptr organise_dialog_; boost::scoped_ptr queue_manager_; + #ifdef ENABLE_VISUALISATIONS boost::scoped_ptr visualisation_; #endif @@ -266,6 +270,11 @@ class MainWindow : public QMainWindow, public PlatformInterface { boost::scoped_ptr wiimotedev_shortcuts_; #endif +#ifdef HAVE_SCRIPTING + ScriptManager* scripts_; + boost::scoped_ptr script_dialog_; +#endif + QMenu* playlist_menu_; QAction* playlist_play_pause_; QAction* playlist_stop_after_; diff --git a/src/ui/mainwindow.ui b/src/ui/mainwindow.ui index f5bfd64db..a23a2cd2c 100644 --- a/src/ui/mainwindow.ui +++ b/src/ui/mainwindow.ui @@ -36,7 +36,7 @@ 0 - + @@ -390,7 +390,7 @@ 0 0 1131 - 25 + 23 @@ -443,7 +443,7 @@ - + @@ -451,6 +451,7 @@ + @@ -750,6 +751,11 @@ Ctrl+M + + + Script Manager + + @@ -798,7 +804,6 @@ FancyTabWidget QWidget
widgets/fancytabwidget.h
- 0