diff --git a/CMakeLists.txt b/CMakeLists.txt index 08378359d9fc18e6eec358c9502dc27f4e5bd2d9..17b1cf99131ddb434fb95d93f18208859b03f240 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,16 +97,6 @@ if(KF5ItemViews_FOUND) set(HAVE_KF5ItemViews 1) endif() -find_package(KF5Kross ${KF5_MIN_VERSION}) -set_package_properties(KF5Kross - PROPERTIES - TYPE OPTIONAL - PURPOSE "Required for KTorrent's scripting plugin" -) -if(KF5Kross_FOUND) - set(HAVE_KF5Kross 1) -endif() - find_package(KF5Plotting ${KF5_MIN_VERSION}) set_package_properties(KF5Plotting PROPERTIES diff --git a/doc/index.docbook b/doc/index.docbook index 5e4b436ee9bd03aa3f608999b985892015cb439d..deaa7b623b049e6b08794f8b6bd6bf910223fd68 100644 --- a/doc/index.docbook +++ b/doc/index.docbook @@ -56,11 +56,10 @@ either 'xx.yy.zz (&kde; x.y)' or '&kde; x.y' Support for distributed hash tables (DHT, the Mainline version) Support for UPnP to automatically forward ports on a LAN with dynamic assigned hosts Support for webseeds -Scripting support via Kross and interprocess control via DBus interface System tray integration Tracker authentication support Connection though a proxy -Scripting support via Kross and interprocess control via DBus interface +Interprocess control via DBus interface diff --git a/ktorrent/org.kde.ktorrent.appdata.xml b/ktorrent/org.kde.ktorrent.appdata.xml index 705121e5fe3b859e8d82e73ae41462e87c1cf27d..18dfa79b14d5afd1548d5cfaf0d3cc48b7707844 100644 --- a/ktorrent/org.kde.ktorrent.appdata.xml +++ b/ktorrent/org.kde.ktorrent.appdata.xml @@ -631,37 +631,6 @@
  • Підтримка вебпоширення
  • xxSupport for webseedsxx
  • 支持 Webseed
  • -
  • Scripting support via Kross, and interprocess control via D-Bus interface
  • -
  • Suport per a crear scripts mitjançant el Kross i control entre processos a través de la interfície de D-Bus
  • -
  • Suport per a crear scripts mitjançant el Kross i control entre processos a través de la interfície de D-Bus
  • -
  • Scripting-understøttelse via Kross og interproceskontrol via D-Bus-grænseflade
  • -
  • Skript-Unterstützung mit Kross und Interprozess-Steuerung über die D-Bus-Schnittstelle
  • -
  • Υποστήριξη συγγραφής σεναρίων με Kross και έλεγχος επικοινωνίας διεργασιών με D-Bus διεπαφή
  • -
  • Scripting support via Kross, and interprocess control via D-Bus interface
  • -
  • Admite el uso de guiones vía Kross y control de interprocesos vía la interfaz D-Bus
  • -
  • Skriptimise toetus Krossi kaudu ja protsesside juhtimine D-Busi liidese abil
  • -
  • Skriptaustuki Krossin kautta sekä prosessienvälinen hallinta D-Bus-liitännän kautta
  • -
  • Scriptable par Kross et contrôle inter-processus par l'interface D-Bus
  • -
  • Funcionalidade de scripting mediante Kross, e control entre procesos mediante unha interface de D-Bus.
  • -
  • Dukungan penskripan via Kross, dan kendali interproses via D-Bus interface
  • -
  • Supporto per lo scripting tramite Kross, e per il controllo dei processi tramite interfaccia D-Bus
  • -
  • Kross를 통한 스크립팅 및 D-Bus 인터페이스를 통한 원격 제어 지원
  • -
  • Ondersteuning voor scripts via Kross en interprocescontrole via het D-Bus-interface
  • -
  • Obsługa skryptów przez Kross i sterowania międzyprocesowego poprzez interfejs D-Bus
  • -
  • Suporte de programação através do Kross e controlo entre processos por uma interface de D-Bus
  • -
  • Suporte a scripts via Kross e controle de interprocessos via interface D-Bus
  • -
  • Поддержка сценариев при помощи Kross и внешнего управления через интерфейс D-Bus
  • -
  • Podpora skriptovania cez Kross a medziprocesové ovládanie cez rozhrani D-Bus
  • -
  • Podpora za skripte prek Kross-a in medprocesni nadzor prek vmesnika D-Bus
  • -
  • Подршка за скриптовање преко Кроса и међупроцесно управљање преко д‑бус сучеља.
  • -
  • Podrška za skriptovanje preko Krossa i međuprocesno upravljanje preko D‑Bus sučelja.
  • -
  • Подршка за скриптовање преко Кроса и међупроцесно управљање преко д‑бус сучеља.
  • -
  • Podrška za skriptovanje preko Krossa i međuprocesno upravljanje preko D‑Bus sučelja.
  • -
  • Skriptstöd via Kross och styrning mellan processer via D-Bus gränssnitt
  • -
  • Kross üzerinden betik yazma desteği ve D-Bus arayüzü ile süreçler arası denetim
  • -
  • Підтримка керування за допомогою скриптів на Kross та обміну даними між процесами за допомогою D-Bus
  • -
  • xxScripting support via Kross, and interprocess control via D-Bus interfacexx
  • -
  • 通过 Kross 支持脚本编程,通过 D-Bus 接口实现进程间控制
  • System tray integration
  • Integració amb la safata del sistema
  • Integració amb la safata del sistema
  • diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index b918a3c14db0c8e6bc87a0cd86db6d7fb1d48ca2..4434e2454d14107821585eb37248aed2932479cf 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -31,9 +31,6 @@ macro_kt_plugin(ENABLE_BWSCHEDULER_PLUGIN bwscheduler bwscheduler) if (HAVE_Taglib AND PHONON_FOUND_EXPERIMENTAL) #AND Qt5Multimedia_FOUND) macro_kt_plugin(ENABLE_MEDIAPLAYER_PLUGIN mediaplayer mediaplayer) endif() -if (HAVE_KF5Archive AND HAVE_KF5ItemViews AND HAVE_KF5Kross) - macro_kt_plugin(ENABLE_SCRIPTING_PLUGIN scripting scripting) -endif() if (HAVE_KF5Syndication AND HAVE_Qt5WebEngineWidgets) macro_kt_plugin(ENABLE_SYNDICATION_PLUGIN syndication syndication) endif() diff --git a/plugins/scripting/CMakeLists.txt b/plugins/scripting/CMakeLists.txt deleted file mode 100644 index ea8d3cff2bb47d12466c6f1eb6406321e75700db..0000000000000000000000000000000000000000 --- a/plugins/scripting/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -add_subdirectory(scripts) - -add_library(ktorrent_scripting MODULE) - -target_sources(ktorrent_scripting PRIVATE - api/scriptingmodule.cpp - api/scriptablegroup.cpp - scriptingplugin.cpp - scriptmanager.cpp - scriptmodel.cpp - scriptdelegate.cpp - script.cpp) - -ki18n_wrap_ui(ktorrent_scripting scriptproperties.ui) - -kcoreaddons_desktop_to_json(ktorrent_scripting ktorrent_scripting.desktop) - -target_link_libraries( - ktorrent_scripting - ktcore - Qt5::Core - KF5::Torrent - KF5::Archive - KF5::ConfigCore - KF5::CoreAddons - KF5::I18n - KF5::IconThemes - KF5::ItemViews - KF5::KIOWidgets - KF5::KrossCore - KF5::XmlGui -) - -install(TARGETS ktorrent_scripting DESTINATION ${KTORRENT_PLUGIN_INSTALL_DIR} ) -install(FILES ktorrent_scriptingui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/ktorrent ) diff --git a/plugins/scripting/api/scriptablegroup.cpp b/plugins/scripting/api/scriptablegroup.cpp deleted file mode 100644 index c134e11082a729bb14c85c1094bd384f4b58888d..0000000000000000000000000000000000000000 --- a/plugins/scripting/api/scriptablegroup.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - SPDX-FileCopyrightText: 2008 Joris Guisson - SPDX-FileCopyrightText: 2008 Ivan Vasic - SPDX-License-Identifier: GPL-2.0-or-later -*/ - -#include "scriptablegroup.h" -#include -#include -#include -#include - -using namespace bt; - -namespace kt -{ -ScriptableGroup::ScriptableGroup(const QString &name, const QString &icon, const QString &path, Kross::Object::Ptr script, DBus *api) - : kt::Group(name, MIXED_GROUP, path) - , script(script) - , api(api) -{ - setIconByName(icon); -} - -ScriptableGroup::~ScriptableGroup() -{ -} - -bool ScriptableGroup::isMember(bt::TorrentInterface *tor) -{ - QVariantList args; - args << tor->getInfoHash().toString(); - QVariant ret = script->callMethod(QStringLiteral("isMember"), args); - return ret.toBool(); -} - -} diff --git a/plugins/scripting/api/scriptablegroup.h b/plugins/scripting/api/scriptablegroup.h deleted file mode 100644 index 997d4eaf9c4d2368492e5c89e6eea46e8cca87d5..0000000000000000000000000000000000000000 --- a/plugins/scripting/api/scriptablegroup.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - SPDX-FileCopyrightText: 2008 Joris Guisson - SPDX-FileCopyrightText: 2008 Ivan Vasic - SPDX-License-Identifier: GPL-2.0-or-later -*/ - -#ifndef KTAPISCRIPTABLEGROUP_H -#define KTAPISCRIPTABLEGROUP_H - -#include -#include - -namespace kt -{ -class DBus; - -/** - Group which uses objects in a script to determine if a torrent is a member of the group. -*/ -class ScriptableGroup : public kt::Group -{ - Kross::Object::Ptr script; - DBus *api; - -public: - ScriptableGroup(const QString &name, const QString &icon, const QString &path, Kross::Object::Ptr script, DBus *api); - ~ScriptableGroup() override; - - bool isMember(bt::TorrentInterface *tor) override; -}; - -} - -#endif diff --git a/plugins/scripting/api/scriptingmodule.cpp b/plugins/scripting/api/scriptingmodule.cpp deleted file mode 100644 index 2bb447a17d2434d67bdb7cc19747c573f9010924..0000000000000000000000000000000000000000 --- a/plugins/scripting/api/scriptingmodule.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - SPDX-FileCopyrightText: 2008 Joris Guisson - SPDX-FileCopyrightText: 2008 Ivan Vasic - SPDX-License-Identifier: GPL-2.0-or-later -*/ - -#include -#include - -#include -#include - -#include "scriptablegroup.h" -#include "scriptingmodule.h" -#include -#include -#include - -namespace kt -{ -ScriptingModule::ScriptingModule(GUIInterface *gui, CoreInterface *core, QObject *parent) - : QObject(parent) - , gui(gui) - , core(core) -{ -} - -ScriptingModule::~ScriptingModule() -{ -} - -QString ScriptingModule::scriptsDir() const -{ - QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("ktorrent/scripts"), QStandardPaths::LocateDirectory); - if (dirs.count() == 0) - return QString(); - - QString ret = dirs.front(); - if (!ret.endsWith(bt::DirSeparator())) - ret += bt::DirSeparator(); - - return ret; -} - -QString ScriptingModule::scriptDir(const QString &script) const -{ - QStringList dirs = - QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("ktorrent/scripts/") + script, QStandardPaths::LocateDirectory); - if (dirs.count() == 0) - return QString(); - - QString ret = dirs.front(); - if (!ret.endsWith(bt::DirSeparator())) - ret += bt::DirSeparator(); - - return ret; -} - -QString ScriptingModule::readConfigEntry(const QString &group, const QString &name, const QString &default_value) -{ - KConfigGroup g = KSharedConfig::openConfig()->group(group); - return g.readEntry(name, default_value); -} - -bool ScriptingModule::readConfigEntryBool(const QString &group, const QString &name, bool default_value) -{ - KConfigGroup g = KSharedConfig::openConfig()->group(group); - return g.readEntry(name, default_value); -} - -int ScriptingModule::readConfigEntryInt(const QString &group, const QString &name, int default_value) -{ - KConfigGroup g = KSharedConfig::openConfig()->group(group); - return g.readEntry(name, default_value); -} - -float ScriptingModule::readConfigEntryFloat(const QString &group, const QString &name, float default_value) -{ - KConfigGroup g = KSharedConfig::openConfig()->group(group); - return g.readEntry(name, default_value); -} - -void ScriptingModule::writeConfigEntry(const QString &group, const QString &name, const QString &value) -{ - KConfigGroup g = KSharedConfig::openConfig()->group(group); - g.writeEntry(name, value); -} - -void ScriptingModule::writeConfigEntryBool(const QString &group, const QString &name, bool value) -{ - KConfigGroup g = KSharedConfig::openConfig()->group(group); - g.writeEntry(name, value); -} - -void ScriptingModule::writeConfigEntryInt(const QString &group, const QString &name, int value) -{ - KConfigGroup g = KSharedConfig::openConfig()->group(group); - g.writeEntry(name, value); -} - -void ScriptingModule::writeConfigEntryFloat(const QString &group, const QString &name, float value) -{ - KConfigGroup g = KSharedConfig::openConfig()->group(group); - g.writeEntry(name, value); -} - -void ScriptingModule::syncConfig(const QString &group) -{ - KConfigGroup g = KSharedConfig::openConfig()->group(group); - g.sync(); -} - -QObject *ScriptingModule::createTimer(bool single_shot) -{ - QTimer *t = new QTimer(this); - t->setSingleShot(single_shot); - return t; -} - -bool ScriptingModule::addGroup(const QString &name, const QString &icon, const QString &path, Kross::Object::Ptr obj) -{ - ScriptableGroup *g = new ScriptableGroup(name, icon, path, obj, core->getExternalInterface()); - kt::GroupManager *gman = core->getGroupManager(); - gman->addDefaultGroup(g); - sgroups.insert(name, g); - return true; -} - -void ScriptingModule::removeGroup(const QString &name) -{ - if (!sgroups.contains(name)) - return; - - kt::GroupManager *gman = core->getGroupManager(); - ScriptableGroup *g = sgroups[name]; - sgroups.remove(name); - gman->removeDefaultGroup(g); -} -} diff --git a/plugins/scripting/api/scriptingmodule.h b/plugins/scripting/api/scriptingmodule.h deleted file mode 100644 index 245194ff1e844d7581adce8417cc4188d7739b0d..0000000000000000000000000000000000000000 --- a/plugins/scripting/api/scriptingmodule.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - SPDX-FileCopyrightText: 2008 Joris Guisson - SPDX-FileCopyrightText: 2008 Ivan Vasic - SPDX-License-Identifier: GPL-2.0-or-later -*/ -#ifndef KTSCRIPTINGMODULE_H -#define KTSCRIPTINGMODULE_H - -#include "scriptablegroup.h" -#include -#include - -namespace kt -{ -class GUIInterface; -class CoreInterface; - -/** - Additional functions to be used in scripts -*/ -class ScriptingModule : public QObject -{ - Q_OBJECT -public: - ScriptingModule(GUIInterface *gui, CoreInterface *core, QObject *parent); - ~ScriptingModule() override; - -public Q_SLOTS: - /// Get the scripts directory - QString scriptsDir() const; - - /// Get the data directory of a script - QString scriptDir(const QString &script) const; - - /// Read a config entry - QString readConfigEntry(const QString &group, const QString &name, const QString &default_value); - int readConfigEntryInt(const QString &group, const QString &name, int default_value); - float readConfigEntryFloat(const QString &group, const QString &name, float default_value); - bool readConfigEntryBool(const QString &group, const QString &name, bool default_value); - - /// Write a config entry - void writeConfigEntry(const QString &group, const QString &name, const QString &value); - void writeConfigEntryInt(const QString &group, const QString &name, int value); - void writeConfigEntryFloat(const QString &group, const QString &name, float value); - void writeConfigEntryBool(const QString &group, const QString &name, bool value); - - /// Sync a group - void syncConfig(const QString &group); - - /// Create a timer - QObject *createTimer(bool single_shot); - - /// Add a new scriptable group - bool addGroup(const QString &name, const QString &icon, const QString &path, Kross::Object::Ptr obj); - - /// Remove a previously added group - void removeGroup(const QString &name); - -private: - GUIInterface *gui; - CoreInterface *core; - QMap sgroups; -}; - -} - -#endif diff --git a/plugins/scripting/ktorrent_scripting.desktop b/plugins/scripting/ktorrent_scripting.desktop deleted file mode 100644 index 1a95419c9a7e7b3b6d237240cb44b42ef587efd3..0000000000000000000000000000000000000000 --- a/plugins/scripting/ktorrent_scripting.desktop +++ /dev/null @@ -1,108 +0,0 @@ -[Desktop Entry] -Name=Scripting -Name[bg]=Скриптиране -Name[bs]=Skriptovanje -Name[ca]=Crea scripts -Name[ca@valencia]=Crea scripts -Name[cs]=Skriptování -Name[da]=Scripting -Name[de]=Skripte -Name[el]=Σενάρια -Name[en_GB]=Scripting -Name[es]=Programación -Name[et]=Skriptid -Name[fi]=Skriptaus -Name[fr]=Langage de scripts -Name[ga]=Scriptiú -Name[gl]=Scripts -Name[hu]=Parancsfájlkezelés -Name[ia]=Scripting -Name[is]=Skriftun -Name[it]=Script -Name[ja]=スクリプティング -Name[kk]=Скриптті жазу -Name[km]=ការ​ស្គ្រីប -Name[ko]=스크립팅 -Name[lt]=Scenarijai -Name[lv]=Skriptēšana -Name[nb]=Skripting -Name[nds]=Skripten -Name[nl]=Scripting -Name[nn]=Skripting -Name[pl]=Skrypty -Name[pt]=Programação -Name[pt_BR]=Scripts -Name[ro]=Scriptare -Name[ru]=Сценарии -Name[si]=විධානාවලි -Name[sk]=Skriptovanie -Name[sl]=Skriptno izvajanje -Name[sq]=Skriptimi -Name[sr]=Скрипте -Name[sr@ijekavian]=Скрипте -Name[sr@ijekavianlatin]=Skripte -Name[sr@latin]=Skripte -Name[sv]=Skripthantering -Name[tr]=Betikleme -Name[ug]=قوليازما -Name[uk]=Запис сценаріїв -Name[x-test]=xxScriptingxx -Name[zh_CN]=脚本 -Name[zh_TW]=文稿 -Comment=Enables Kross scripting support -Comment[bg]=Включване на поддръжка на скриптиране на Kross -Comment[bs]=Omogućava podršku za skriptovanje Krosom -Comment[ca]=Habilita l'ús per a crear scripts del Kross -Comment[ca@valencia]=Habilita l'ús per a crear scripts del Kross -Comment[cs]=Podpora skriptování Kross -Comment[da]=Aktiverer understøttelse af Kross-scripting -Comment[de]=Aktiviert die Unterstützung für Kross-Skripte -Comment[el]=Ενεργοποίηση υποστήριξης σεναρίων Kross -Comment[en_GB]=Enables Kross scripting support -Comment[es]=Activa el uso de scripts con Kross -Comment[et]=Krossi skriptimise toetus -Comment[fi]=Ottaa käyttöön Kross-skriptaustuen -Comment[fr]=Active la prise en charge du langage de scripts Kross -Comment[ga]=Breiseán a chumasaíonn scriptiú Kross -Comment[gl]=Permite o uso de scripts escritos en Kross. -Comment[hu]=A Kross parancsfájlok támogatásának engedélyezése -Comment[is]=Virkja stuðning við Kross skriftun -Comment[it]=Abilita il supporto script Kross -Comment[ja]=Kross スクリプティングサポートを有効にします -Comment[kk]=Kross скриптін рұқсат ету -Comment[km]=អនុញ្ញាត​ការ​គាំទ្រ​ការ​ស្គ្រីប Kross -Comment[ko]=Kross 스크립팅 지원 사용 -Comment[lt]=Įgalina kryžminį scenarijų palaikymą -Comment[lv]=Kross skriptēšanas spraudnis -Comment[nb]=Skru på støtte for Kross skripting -Comment[nds]=Ünnerstütten för Kross-Skripten -Comment[nl]=Schakelt ondersteuning voor kross-scripting in -Comment[nn]=Slår på støtte for Kross-skripting -Comment[pl]=Włącza obsługę skryptową Kross -Comment[pt]=Activa o suporte de programação com o Kross -Comment[pt_BR]=Habilita suporte à scripts do Kross -Comment[ro]=Activează suportul pentru scripturi Kross -Comment[ru]=Модуль поддержки сценариев Kross в KTorrent -Comment[si]=Kross විධානාවලි සහාය සක්‍රීය කරයි -Comment[sk]=Povolí podporu Kross scripting -Comment[sl]=Omogoči podporo za pisanje skript Kross -Comment[sr]=Додаје подршку за скриптовање Кросом -Comment[sr@ijekavian]=Додаје подршку за скриптовање Кросом -Comment[sr@ijekavianlatin]=Dodaje podršku za skriptovanje Krossom -Comment[sr@latin]=Dodaje podršku za skriptovanje Krossom -Comment[sv]=Aktiverar stöd för skripthantering med Kross -Comment[tr]=Kross betikleme desteğini etkinleştirir -Comment[uk]=Уможливлює підтримку Kross -Comment[x-test]=xxEnables Kross scripting supportxx -Comment[zh_CN]=启用 Kross 脚本支持 -Comment[zh_TW]=Kross 文稿支援 -Type=Service -X-KDE-Library=ktscriptingplugin -X-KDE-PluginInfo-Author=Joris Guisson -X-KDE-PluginInfo-Email=joris.guisson@gmail.com -X-KDE-PluginInfo-Name=ScriptingPlugin -X-KDE-PluginInfo-Version=0.1 -X-KDE-PluginInfo-Website=http://kde.org/applications/internet/ktorrent/ -X-KDE-PluginInfo-License=GPL -X-KDE-PluginInfo-EnabledByDefault=false -Icon=text-x-script diff --git a/plugins/scripting/ktorrent_scriptingui.rc b/plugins/scripting/ktorrent_scriptingui.rc deleted file mode 100644 index 7ad609d8a8d997696d080161b16dd95815314e65..0000000000000000000000000000000000000000 --- a/plugins/scripting/ktorrent_scriptingui.rc +++ /dev/null @@ -1,27 +0,0 @@ - - - - - Scripting - - - - - - - - - - - Scripting - - - - - - - - - - - diff --git a/plugins/scripting/script.cpp b/plugins/scripting/script.cpp deleted file mode 100644 index 75a8332f401eb65e2d4697293eb7133b17c3a534..0000000000000000000000000000000000000000 --- a/plugins/scripting/script.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - SPDX-FileCopyrightText: 2008 Joris Guisson - SPDX-FileCopyrightText: 2008 Ivan Vasic - SPDX-License-Identifier: GPL-2.0-or-later -*/ - -#include -#include - -#include -#include -#include -#include - -#include "script.h" -#include -#include - -using namespace bt; - -namespace kt -{ -Script::Script(QObject *parent) - : QObject(parent) - , action(nullptr) - , executing(false) - , can_be_removed(true) -{ -} - -Script::Script(const QString &file, QObject *parent) - : QObject(parent) - , file(file) - , action(nullptr) - , executing(false) - , can_be_removed(true) -{ -} - -Script::~Script() -{ - stop(); -} - -bool Script::loadFromDesktopFile(const QString &dir, const QString &desktop_file) -{ - KDesktopFile df(dir + desktop_file); - // check if everything is OK - if (df.readType().trimmed() != QStringLiteral("KTorrentScript")) - return false; - - info.name = df.readName(); - info.comment = df.readComment(); - info.icon = df.readIcon(); - - KConfigGroup g = df.group("Desktop Entry"); - info.author = g.readEntry("X-KTorrent-Script-Author", QString()); - info.email = g.readEntry("X-KTorrent-Script-Email", QString()); - info.website = g.readEntry("X-KTorrent-Script-Website", QString()); - info.license = g.readEntry("X-KTorrent-Script-License", QString()); - file = g.readEntry("X-KTorrent-Script-File", QString()); - if (file.isEmpty() || !bt::Exists(dir + file)) // the script file must exist - return false; - - file = dir + file; - return true; -} - -bool Script::executeable() const -{ - return bt::Exists(file) && !Kross::Manager::self().interpreternameForFile(file).isNull(); -} - -bool Script::execute() -{ - if (!bt::Exists(file) || action) - return false; - - QMimeDatabase db; - QMimeType mt = db.mimeTypeForFile(file); - QString name = QFileInfo(file).fileName(); - action = new Kross::Action(this, name); - action->setText(name); - action->setDescription(name); - action->setFile(file); - action->setIconName(mt.iconName()); - QString interpreter = Kross::Manager::self().interpreternameForFile(file); - if (interpreter.isNull()) { - delete action; - action = nullptr; - return false; - } else { - action->setInterpreter(interpreter); - Kross::Manager::self().actionCollection()->addAction(file, action); - action->trigger(); - executing = true; - return true; - } -} - -void Script::stop() -{ - if (!executing) - return; - - // Call unload function if the script has one - if (action->functionNames().contains(QStringLiteral("unload"))) { - QVariantList args; - action->callFunction(QStringLiteral("unload"), args); - } - - Kross::ActionCollection *col = Kross::Manager::self().actionCollection(); - col->removeAction(action->file()); - action->deleteLater(); - action = nullptr; - executing = false; -} - -QString Script::name() const -{ - if (!info.name.isEmpty()) - return info.name; - else if (action) - return action->name(); - else - return QFileInfo(file).fileName(); -} - -QString Script::iconName() const -{ - QMimeDatabase db; - if (!info.icon.isEmpty()) - return info.icon; - else if (action) - return action->iconName(); - else - return db.mimeTypeForFile(file).iconName(); -} - -bool Script::hasConfigure() const -{ - if (!action) - return false; - - QStringList functions = action->functionNames(); - return functions.contains(QStringLiteral("configure")); -} - -void Script::configure() -{ - if (!action) - return; - - QVariantList args; - action->callFunction(QStringLiteral("configure"), args); -} - -} diff --git a/plugins/scripting/script.h b/plugins/scripting/script.h deleted file mode 100644 index 4ba1d712d9d2df93d0ab6fd208977171e73bf5b1..0000000000000000000000000000000000000000 --- a/plugins/scripting/script.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - SPDX-FileCopyrightText: 2008 Joris Guisson - SPDX-FileCopyrightText: 2008 Ivan Vasic - SPDX-License-Identifier: GPL-2.0-or-later -*/ - -#ifndef KTSCRIPT_H -#define KTSCRIPT_H - -#include - -namespace Kross -{ -class Action; -} - -namespace kt -{ -/** - Keeps track of a script -*/ -class Script : public QObject -{ - Q_OBJECT -public: - Script(QObject *parent); - Script(const QString &file, QObject *parent); - ~Script() override; - - struct MetaInfo { - QString name; - QString comment; - QString icon; - QString author; - QString email; - QString website; - QString license; - - bool valid() const - { - return !name.isEmpty() && !comment.isEmpty() && !icon.isEmpty() && !author.isEmpty() && !license.isEmpty(); - } - }; - - /** - * Load the script from a desktop file - * @param dir THe directory the desktop file is in - * @param desktop_file The desktop file itself (relative to dir) - * @return true upon success - */ - bool loadFromDesktopFile(const QString &dir, const QString &desktop_file); - - /** - * Load and execute the script - * @return true upon success - */ - bool execute(); - - /// Is the script executeable (i.e. is the interpreter not installed) - bool executeable() const; - - /** - * Stop the script - */ - void stop(); - - /// Is the script running - bool running() const - { - return executing; - } - - /// Get the name of the script - QString name() const; - - /// Get the icon name of the script - QString iconName() const; - - /// Get the file - QString scriptFile() const - { - return file; - } - - /// Get the package directory, this returns an empty string if the script is just a file - QString packageDirectory() const - { - return package_directory; - } - - /// Set the package directory - void setPackageDirectory(const QString &dir) - { - package_directory = dir; - } - - /// Get the meta info of the script - const MetaInfo &metaInfo() const - { - return info; - } - - /// Does the script has a configure function - bool hasConfigure() const; - - /// Call the configure function of the script - void configure(); - - /// Whether or not the script can be removed - bool removable() const - { - return can_be_removed; - } - - /// Set the script to be removable or not - void setRemovable(bool on) - { - can_be_removed = on; - } - -private: - QString file; - Kross::Action *action; - bool executing; - MetaInfo info; - bool can_be_removed; - QString package_directory; -}; - -} - -#endif diff --git a/plugins/scripting/scriptdelegate.cpp b/plugins/scripting/scriptdelegate.cpp deleted file mode 100644 index 68c91b914294c7d629a38bcf8ed3e27242b5cd4c..0000000000000000000000000000000000000000 --- a/plugins/scripting/scriptdelegate.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - SPDX-FileCopyrightText: 2009 Joris Guisson - SPDX-License-Identifier: GPL-2.0-or-later -*/ - -#include - -#include -#include -#include -#include - -#include "scriptdelegate.h" -#include "scriptmodel.h" - -#define MARGIN 5 - -namespace kt -{ -ScriptDelegate::ScriptDelegate(QAbstractItemView *parent) - : KWidgetItemDelegate(parent, parent) - , check_box(new QCheckBox) - , push_button(new QPushButton) -{ -} - -ScriptDelegate::~ScriptDelegate() -{ - delete check_box; - delete push_button; -} - -QFont ScriptDelegate::titleFont(const QFont &base) const -{ - QFont font(base); - font.setBold(true); - return font; -} - -void ScriptDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - if (!index.isValid()) - return; - - int x_offset = check_box->sizeHint().width(); - - painter->save(); - QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, nullptr); - - int iconSize = option.rect.height() - MARGIN * 2; - - QString icon = index.model()->data(index, Qt::DecorationRole).toString(); - KIconLoader::States state = option.state & QStyle::State_Enabled ? KIconLoader::DefaultState : KIconLoader::DisabledState; - QPixmap pixmap = KIconLoader::global()->loadIcon(icon, KIconLoader::Desktop, iconSize, state); - - int x = MARGIN + option.rect.left() + x_offset; - painter->drawPixmap(QRect(x, MARGIN + option.rect.top(), iconSize, iconSize), pixmap, QRect(0, 0, iconSize, iconSize)); - - x = MARGIN * 2 + iconSize + option.rect.left() + x_offset; - QRect contentsRect(x, MARGIN + option.rect.top(), option.rect.width() - MARGIN * 3 - iconSize - x_offset, option.rect.height() - MARGIN * 2); - - int lessHorizontalSpace = MARGIN * 2 + push_button->sizeHint().width(); - contentsRect.setWidth(contentsRect.width() - lessHorizontalSpace); - - QPalette::ColorGroup cg = QPalette::Active; - if (!(option.state & QStyle::State_Enabled)) - cg = QPalette::Inactive; - - if (option.state & QStyle::State_Selected) - painter->setPen(option.palette.color(cg, QPalette::HighlightedText)); - else - painter->setPen(option.palette.color(cg, QPalette::WindowText)); - - painter->save(); - painter->save(); - QFont font = titleFont(option.font); - QFontMetrics fmTitle(font); - painter->setFont(font); - QString text = index.model()->data(index, Qt::DisplayRole).toString(); - painter->drawText(contentsRect, Qt::AlignLeft | Qt::AlignTop, fmTitle.elidedText(text, Qt::ElideRight, contentsRect.width())); - painter->restore(); - - QString comment = index.model()->data(index, ScriptModel::CommentRole).toString(); - painter->drawText(contentsRect, Qt::AlignLeft | Qt::AlignBottom, option.fontMetrics.elidedText(comment, Qt::ElideRight, contentsRect.width())); - - painter->restore(); - painter->restore(); -} - -QSize ScriptDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - QFont font = titleFont(option.font); - QFontMetrics fm(font); - - int w = std::max(fm.horizontalAdvance(index.model()->data(index, Qt::DisplayRole).toString()), - option.fontMetrics.horizontalAdvance(index.model()->data(index, ScriptModel::CommentRole).toString())); - int h = std::max(KIconLoader::SizeMedium + MARGIN * 2, fm.height() + option.fontMetrics.height() + MARGIN * 2); - return QSize(w + KIconLoader::SizeMedium, h); -} - -QList ScriptDelegate::createItemWidgets(const QModelIndex &index) const -{ - Q_UNUSED(index) - QList widgets; - - QCheckBox *enabled_check = new QCheckBox; - connect(enabled_check, &QCheckBox::clicked, this, &ScriptDelegate::toggled); - - QPushButton *about_button = new QPushButton; - about_button->setIcon(QIcon::fromTheme(QStringLiteral("dialog-information"))); - connect(about_button, &QPushButton::clicked, this, &ScriptDelegate::aboutClicked); - - QPushButton *configure_button = new QPushButton; - configure_button->setIcon(QIcon::fromTheme(QStringLiteral("configure"))); - connect(configure_button, &QPushButton::clicked, this, &ScriptDelegate::settingsClicked); - - QList blocked; - blocked << QEvent::MouseButtonPress << QEvent::MouseButtonRelease << QEvent::MouseButtonDblClick; - setBlockedEventTypes(enabled_check, blocked); - setBlockedEventTypes(about_button, blocked); - setBlockedEventTypes(configure_button, blocked); - - widgets << enabled_check << configure_button << about_button; - return widgets; -} - -void ScriptDelegate::updateItemWidgets(const QList widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const -{ - QCheckBox *check_box = static_cast(widgets[0]); - check_box->resize(check_box->sizeHint()); - int x = MARGIN; - check_box->move(x, option.rect.height() / 2 - check_box->sizeHint().height() / 2); - - QPushButton *about_button = static_cast(widgets[2]); - QSize about_size_hint = about_button->sizeHint(); - about_button->resize(about_size_hint); - x = option.rect.width() - MARGIN - about_size_hint.width(); - about_button->move(x, option.rect.height() / 2 - about_size_hint.height() / 2); - - QPushButton *configure_button = static_cast(widgets[1]); - QSize configure_size_hint = configure_button->sizeHint(); - configure_button->resize(configure_size_hint); - x = option.rect.width() - MARGIN * 2 - configure_size_hint.width() - about_size_hint.width(); - configure_button->move(x, option.rect.height() / 2 - configure_size_hint.height() / 2); - - if (!index.isValid()) { - check_box->setVisible(false); - about_button->setVisible(false); - configure_button->setVisible(false); - } else { - check_box->setChecked(index.model()->data(index, Qt::CheckStateRole).toBool()); - check_box->setEnabled(true); - configure_button->setVisible(true); - configure_button->setEnabled(index.model()->data(index, ScriptModel::ConfigurableRole).toBool()); - } -} - -void ScriptDelegate::aboutClicked() -{ - QModelIndex index = focusedIndex(); - QAbstractItemModel *model = (QAbstractItemModel *)index.model(); - model->setData(index, 0, ScriptModel::AboutRole); -} - -void ScriptDelegate::settingsClicked() -{ - QModelIndex index = focusedIndex(); - QAbstractItemModel *model = (QAbstractItemModel *)index.model(); - model->setData(index, 0, ScriptModel::ConfigureRole); -} - -void ScriptDelegate::toggled(bool on) -{ - QModelIndex index = focusedIndex(); - QAbstractItemModel *model = (QAbstractItemModel *)index.model(); - model->setData(index, on, Qt::CheckStateRole); -} -} diff --git a/plugins/scripting/scriptdelegate.h b/plugins/scripting/scriptdelegate.h deleted file mode 100644 index 5fcfa6a6ba793c2a32632bb6b1b1bfabc2a8a64b..0000000000000000000000000000000000000000 --- a/plugins/scripting/scriptdelegate.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - SPDX-FileCopyrightText: 2009 Joris Guisson - SPDX-License-Identifier: GPL-2.0-or-later -*/ - -#ifndef KT_SCRIPTDELEGATE_H -#define KT_SCRIPTDELEGATE_H - -#include -#include -#include - -#include - -namespace kt -{ -class ScriptDelegate : public KWidgetItemDelegate -{ - Q_OBJECT -public: - ScriptDelegate(QAbstractItemView *parent); - ~ScriptDelegate() override; - - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; - QList createItemWidgets(const QModelIndex &index) const override; - void updateItemWidgets(const QList widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const override; - -private: - QFont titleFont(const QFont &baseFont) const; - -private Q_SLOTS: - void toggled(bool on); - void aboutClicked(); - void settingsClicked(); - -private: - QCheckBox *check_box; - QPushButton *push_button; -}; - -} - -#endif // KT_SCRIPTDELEGATE_H diff --git a/plugins/scripting/scriptingplugin.cpp b/plugins/scripting/scriptingplugin.cpp deleted file mode 100644 index fec130976bf250a7661d9f301c85bafc3b39edd4..0000000000000000000000000000000000000000 --- a/plugins/scripting/scriptingplugin.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* - SPDX-FileCopyrightText: 2008 Joris Guisson - SPDX-FileCopyrightText: 2008 Ivan Vasic - SPDX-License-Identifier: GPL-2.0-or-later -*/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "api/scriptingmodule.h" -#include "script.h" -#include "scriptingplugin.h" -#include "scriptmanager.h" -#include "scriptmodel.h" - -K_PLUGIN_FACTORY_WITH_JSON(ktorrent_scripting, "ktorrent_scripting.json", registerPlugin();) - -using namespace bt; - -namespace kt -{ -ScriptingPlugin::ScriptingPlugin(QObject *parent, const QVariantList &args) - : Plugin(parent) -{ - Q_UNUSED(args); -} - -ScriptingPlugin::~ScriptingPlugin() -{ -} - -void ScriptingPlugin::load() -{ - // make sure script dir exists - QString script_dir = kt::DataDir() + QStringLiteral("scripts") + bt::DirSeparator(); - if (!bt::Exists(script_dir)) - bt::MakeDir(script_dir, true); - - LogSystemManager::instance().registerSystem(i18n("Scripting"), SYS_SCR); - model = new ScriptModel(this); - // add the KTorrent object - Kross::Manager::self().addObject(getCore()->getExternalInterface(), QStringLiteral("KTorrent")); - Kross::Manager::self().addObject(new ScriptingModule(getGUI(), getCore(), this), QStringLiteral("KTScriptingPlugin")); - loadScripts(); - - Out(SYS_SCR | LOG_DEBUG) << "Supported interpreters : " << endl; - const QStringList interpreters = Kross::Manager::self().interpreters(); - for (const QString &s : interpreters) - Out(SYS_SCR | LOG_DEBUG) << s << endl; - - sman = new ScriptManager(model, nullptr); - connect(sman, &ScriptManager::addScript, this, &ScriptingPlugin::addScript); - connect(sman, &ScriptManager::removeScript, this, &ScriptingPlugin::removeScript); - connect(model, &ScriptModel::showPropertiesDialog, sman, qOverload