From 9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 20 Jan 2010 02:37:40 +0000 Subject: Updated to final KDE3 ktorrent release (2.2.6) git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/ktorrent@1077377 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- plugins/scanfolder/Makefile.am | 31 +++ plugins/scanfolder/ktscanfolderplugin.desktop | 26 +++ plugins/scanfolder/ktscanfolderplugin.kcfg | 53 +++++ plugins/scanfolder/scanfolder.cpp | 273 ++++++++++++++++++++++ plugins/scanfolder/scanfolder.h | 111 +++++++++ plugins/scanfolder/scanfolderplugin.cpp | 187 +++++++++++++++ plugins/scanfolder/scanfolderplugin.h | 61 +++++ plugins/scanfolder/scanfolderpluginsettings.kcfgc | 7 + plugins/scanfolder/scanfolderprefpage.cpp | 66 ++++++ plugins/scanfolder/scanfolderprefpage.h | 53 +++++ plugins/scanfolder/scanfolderprefpagewidget.cpp | 107 +++++++++ plugins/scanfolder/scanfolderprefpagewidget.h | 36 +++ plugins/scanfolder/sfprefwidgetbase.ui | 272 +++++++++++++++++++++ 13 files changed, 1283 insertions(+) create mode 100644 plugins/scanfolder/Makefile.am create mode 100644 plugins/scanfolder/ktscanfolderplugin.desktop create mode 100644 plugins/scanfolder/ktscanfolderplugin.kcfg create mode 100644 plugins/scanfolder/scanfolder.cpp create mode 100644 plugins/scanfolder/scanfolder.h create mode 100644 plugins/scanfolder/scanfolderplugin.cpp create mode 100644 plugins/scanfolder/scanfolderplugin.h create mode 100644 plugins/scanfolder/scanfolderpluginsettings.kcfgc create mode 100644 plugins/scanfolder/scanfolderprefpage.cpp create mode 100644 plugins/scanfolder/scanfolderprefpage.h create mode 100644 plugins/scanfolder/scanfolderprefpagewidget.cpp create mode 100644 plugins/scanfolder/scanfolderprefpagewidget.h create mode 100644 plugins/scanfolder/sfprefwidgetbase.ui (limited to 'plugins/scanfolder') diff --git a/plugins/scanfolder/Makefile.am b/plugins/scanfolder/Makefile.am new file mode 100644 index 0000000..eb8cc52 --- /dev/null +++ b/plugins/scanfolder/Makefile.am @@ -0,0 +1,31 @@ +INCLUDES = -I$(srcdir)/../../libktorrent $(all_includes) +METASOURCES = AUTO +kde_module_LTLIBRARIES = ktscanfolderplugin.la + + +# LD flags for the plugin +# -module says: this is a module, i.e. something you're going to dlopen +# so e.g. it has no version number like a normal shared lib would have. +ktscanfolderplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) + +# rc file containing the GUI for the plugin +# pluginsdir = $(kde_datadir)/ktscanfolderplugin +# plugins_DATA = ktscanfolderpluginui.rc + +# Install the desktop file needed to detect the plugin + +rcdir = $(kde_datadir)/ktorrent + +kde_kcfg_DATA = ktscanfolderplugin.kcfg +kde_services_DATA = ktscanfolderplugin.desktop + +noinst_HEADERS = scanfolderplugin.h scanfolderprefpage.h \ + scanfolderprefpagewidget.h scanfolder.h +ktscanfolderplugin_la_SOURCES = scanfolderplugin.cpp \ + scanfolderpluginsettings.kcfgc scanfolderprefpage.cpp sfprefwidgetbase.ui scanfolderprefpagewidget.cpp \ + scanfolder.cpp +ktscanfolderplugin_la_LIBADD = $(LIB_KPARTS) ../../libktorrent/libktorrent.la \ + $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI) $(LIB_KFILE) + + +KDE_CXXFLAGS = $(USE_EXCEPTIONS) $(USE_RTTI) diff --git a/plugins/scanfolder/ktscanfolderplugin.desktop b/plugins/scanfolder/ktscanfolderplugin.desktop new file mode 100644 index 0000000..b6180de --- /dev/null +++ b/plugins/scanfolder/ktscanfolderplugin.desktop @@ -0,0 +1,26 @@ +[Desktop Entry] +Name=ScanFolderPlugin +Name[bg]=Приставка за сканиране +Name[cs]=Modul prohledávání složek +Name[da]=Plugin for mappesøgning +Name[de]=Ordner-Durchsuchen-Modul +Name[el]=Πρόσθετο σάρωσης φακέλων +Name[et]=Kataloogi uurimise plugin +Name[it]=Plugin scansione cartella +Name[nb]=Katalogundersøkingsmdoul +Name[nds]=Moduul för't Dörkieken vun Ornern +Name[nl]=Mapscanplugin +Name[pl]=Wtyczka przeszukiwania katalogów +Name[pt_BR]=Plugins de Busca +Name[sk]=ScanFolder Plugin +Name[sr]=Прикључак прегледа фасцикле +Name[sr@Latn]=Priključak pregleda fascikle +Name[sv]=Insticksprogram för katalogsökning +Name[tr]=Dizin Tarama Eklentisi +Name[uk]=Втулок сканування тек +Name[xx]=xxScanFolderPluginxx +Name[zh_CN]=扫描文件夹插件 +Name[zh_TW]=掃描資料夾外掛程式 +ServiceTypes=KTorrent/Plugin +Type=Service +X-KDE-Library=ktscanfolderplugin diff --git a/plugins/scanfolder/ktscanfolderplugin.kcfg b/plugins/scanfolder/ktscanfolderplugin.kcfg new file mode 100644 index 0000000..f9b919f --- /dev/null +++ b/plugins/scanfolder/ktscanfolderplugin.kcfg @@ -0,0 +1,53 @@ + + + + + + + FALSE + + + + + FALSE + + + + + FALSE + + + + + + + + + + + + + + + + + + + + FALSE + + + + + FALSE + + + + + FALSE + + + diff --git a/plugins/scanfolder/scanfolder.cpp b/plugins/scanfolder/scanfolder.cpp new file mode 100644 index 0000000..3c30299 --- /dev/null +++ b/plugins/scanfolder/scanfolder.cpp @@ -0,0 +1,273 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * 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. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "scanfolder.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include + +using namespace bt; + +namespace kt +{ + + ScanFolder::ScanFolder(CoreInterface* core, QString& dir, LoadedTorrentAction action, bool openSilently) + : m_core(core), m_dir(0), m_loadedAction(action), m_openSilently(openSilently) + { + m_dir = new KDirLister(); + + if(!m_dir->openURL(dir)) { + m_valid = false; + return; + } else + m_valid = true; + + m_dir->setShowingDotFiles(true); + + connect(m_dir, SIGNAL(newItems( const KFileItemList& )), this, SLOT(onNewItems( const KFileItemList& ))); + connect(m_core, SIGNAL(loadingFinished( const KURL&, bool, bool )), this, SLOT(onLoadingFinished( const KURL&, bool, bool ))); + connect(&m_incomplePollingTimer,SIGNAL(timeout()),this,SLOT(onIncompletePollingTimeout())); + } + + + ScanFolder::~ScanFolder() + { +// Out() << "UNLOADING SCANFOLDER: " << m_dir->url().path() << endl; + delete m_dir; + } + + void ScanFolder::onNewItems(const KFileItemList& items) + { + KFileItemList list = items; + KFileItem* file; + for(file=list.first(); file; file=list.next()) + { + QString name = file->name(); + QString dirname = m_dir->url().path(); + QString filename = dirname + bt::DirSeparator() + name; + + if(!name.endsWith(".torrent")) + continue; + + if(name.startsWith(".")) + { + //Check if corresponding torrent exists + if(!QFile::exists(m_dir->url().path() + bt::DirSeparator() + name.right(name.length() - 1)) && (m_loadedAction == defaultAction)) + QFile::remove(filename); + + continue; + } + + KURL source; + source.setPath(filename); + + //If torrent has it's hidden complement - skip it. + if(QFile::exists(dirname + "/." + name)) + continue; + + if (incomplete(source)) + { + // incomplete file, try this again in 10 seconds + bt::Out(SYS_SNF|LOG_NOTICE) << "ScanFolder : incomplete file " << source << endl; + m_incompleteURLs.append(source); + if (m_incompleteURLs.count() == 1) + { + // first URL so start the poll timer + // lets poll every 10 seconds + m_incomplePollingTimer.start(10000,false); + } + } + else + { + bt::Out(SYS_SNF|LOG_NOTICE) << "ScanFolder : found " << source << endl; + //Add pending entry... + m_pendingURLs.push_back(source); + + //Load torrent + if(m_openSilently) + m_core->loadSilently(source); + else + m_core->load(source); + } + } + } + + void ScanFolder::onLoadingFinished(const KURL & url, bool success, bool canceled) + { + if(m_pendingURLs.empty() || !success) + return; + + //search for entry + QValueList::iterator it = m_pendingURLs.find(url); + + //if no entry is found than this torrent was not started by this plugin so - quit + if(it == m_pendingURLs.end()) + return; + + //remove this entry + m_pendingURLs.erase(it); + + if(canceled) + return; + + QString name = url.filename(false); + QString dirname = m_dir->url().path(); + QString filename = dirname + "/" + name; + KURL destination(dirname + "/" + i18n("loaded") + "/" + name); + + switch(m_loadedAction) { + case deleteAction: + //If torrent has it's hidden complement - remove it too. + if(QFile::exists(dirname + "/." + name)) + QFile::remove(dirname + "/." + name); + // Out() << "Deleting: " << name.ascii() << endl; + QFile::remove(filename); + break; + case moveAction: + // Out() << "Moving: " << name.ascii() << endl; + //If torrent has it's hidden complement - remove it too. + if(QFile::exists(dirname + "/." + name)) + QFile::remove(dirname + "/." + name); + + // NetAccess considered harmfull !!! + KIO::file_move(url, destination); + break; + case defaultAction: + QFile f(dirname + "/." + name); + f.open(IO_WriteOnly); + f.close(); + break; + } + } + + void ScanFolder::setOpenSilently(bool theValue) + { + m_openSilently = theValue; + } + + void ScanFolder::setLoadedAction(const LoadedTorrentAction& theValue) + { + m_loadedAction = theValue; + + QDir tmp(m_dir->url().path()); + + if( (m_loadedAction == moveAction) && !tmp.exists(i18n("loaded"), false)) + tmp.mkdir(i18n("loaded"), false); + } + + void ScanFolder::setFolderUrl(QString& url) + { + if(!m_dir->openURL(url)) { + m_valid = false; + return; + } else + m_valid = true; + } + + bool ScanFolder::incomplete(const KURL & src) + { + // try to decode file, if it is syntactically correct, we can try to load it + QFile fptr(src.path()); + if (!fptr.open(IO_ReadOnly)) + return false; + + try + { + QByteArray data(fptr.size()); + fptr.readBlock(data.data(),fptr.size()); + bt::BDecoder dec(data,false); + bt::BNode* n = dec.decode(); + if (n) + { + // valid node, so file is complete + delete n; + return false; + } + else + { + // decoding failed so incomplete + return true; + } + } + catch (...) + { + // any error means shit happened and the file is incomplete + return true; + } + return false; + } + + void ScanFolder::onIncompletePollingTimeout() + { + bt::Out(SYS_SNF|LOG_NOTICE) << "ScanFolder : checking incomplete files" << endl; + for (QValueList::iterator i = m_incompleteURLs.begin(); i != m_incompleteURLs.end();) + { + KURL source = *i; + if (!bt::Exists(source.path())) + { + // doesn't exist anymore, so throw out of list + i = m_incompleteURLs.erase(i); + } + else if (!incomplete(source)) + { + bt::Out(SYS_SNF|LOG_NOTICE) << "ScanFolder : incomplete file " << source << " appears to be completed " << endl; + //Add pending entry... + m_pendingURLs.push_back(source); + + //Load torrent + if(m_openSilently) + m_core->loadSilently(source); + else + m_core->load(source); + + // remove from incomplete list + i = m_incompleteURLs.erase(i); + } + else + { + bt::Out(SYS_SNF|LOG_NOTICE) << "ScanFolder : still incomplete : " << source << endl; + i++; + } + } + + // stop timer when no incomple URL's are left + if (m_incompleteURLs.count() == 0) + m_incomplePollingTimer.stop(); + } +} + +#include "scanfolder.moc" diff --git a/plugins/scanfolder/scanfolder.h b/plugins/scanfolder/scanfolder.h new file mode 100644 index 0000000..8e8c27c --- /dev/null +++ b/plugins/scanfolder/scanfolder.h @@ -0,0 +1,111 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * 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. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef SCANFOLDER_H +#define SCANFOLDER_H + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace kt +{ + ///Action to perform after loading torrent. + enum LoadedTorrentAction + { + deleteAction, + moveAction, + defaultAction + }; + + class CoreInterface; + + /** + * @brief Scanned folder class. + * @author Ivan Vasić + * + * It will monitor m_dir directory for changes and automatically pass new torrents to core for loading. + * After loading, it will perform specified action which can be: + * 1. Deleting torrent in question + * 2. Moving torrent to 'loaded' subdirectory + * 3. Default action (neither 1. nor 2.) + * @see LoadedTorrentAction + * + */ + class ScanFolder : public QObject + { + Q_OBJECT + public: + + /** + * Default constructor. + * @param core Pointer to core interface + * @param dir Full directory path + * @param action Action to perform on loaded torrents. + * @param openSilently Wheather to open torrent silently or not. + */ + ScanFolder(CoreInterface* core, QString& dir, LoadedTorrentAction action = defaultAction, bool openSilently = true); + ~ScanFolder(); + + ///Accessor method for m_openSilently. + bool openSilently() const { return m_openSilently; } + ///Accessor method for m_openSilently + void setOpenSilently(bool theValue); + + ///Accessor method for m_loadedAction. + void setLoadedAction(const LoadedTorrentAction& theValue); + ///Accessor method for m_loadedAction. + LoadedTorrentAction loadedAction() const { return m_loadedAction; } + + ///Returns true if this object is valid, that is - weather directory is valid and this object does its work. + bool isValid() const { return m_valid; } + + ///Sets directory path + void setFolderUrl(QString& url); + + public slots: + void onNewItems(const KFileItemList &items); + void onLoadingFinished(const KURL & url,bool success,bool canceled); + void onIncompletePollingTimeout(); + + private: + /// Check if the URL is a complete file + bool incomplete(const KURL & src); + + private: + CoreInterface* m_core; + + bool m_valid; + KDirLister* m_dir; + + LoadedTorrentAction m_loadedAction; + bool m_openSilently; + + QValueList m_pendingURLs; + QValueList m_incompleteURLs; + + QTimer m_incomplePollingTimer; + }; +} +#endif diff --git a/plugins/scanfolder/scanfolderplugin.cpp b/plugins/scanfolder/scanfolderplugin.cpp new file mode 100644 index 0000000..a994243 --- /dev/null +++ b/plugins/scanfolder/scanfolderplugin.cpp @@ -0,0 +1,187 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * 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. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "scanfolder.h" +#include "scanfolderplugin.h" +#include "scanfolderprefpage.h" +#include "scanfolderpluginsettings.h" + +using namespace bt; + +K_EXPORT_COMPONENT_FACTORY(ktscanfolderplugin,KGenericFactory("scanfolderplugin")) + +namespace kt +{ + const QString NAME = "Scan Folder"; + const QString AUTHOR = "Ivan Vasic"; + const QString EMAIL = "ivasic@gmail.com"; + const QString DESCRIPTION = i18n("Automatically scans directories for torrent files and loads them."); + + ScanFolderPlugin::ScanFolderPlugin(QObject* parent, const char* name, const QStringList& args) + : Plugin(parent, name, args,NAME,i18n("Scan Folder"),AUTHOR,EMAIL,DESCRIPTION,"view_sidetree") + { +// setXMLFile("ktscanfolderpluginui.rc"); + m_sf1 = 0; + m_sf2 = 0; + m_sf3 = 0; + } + + + ScanFolderPlugin::~ScanFolderPlugin() + { + } + + void ScanFolderPlugin::load() + { + pref = new ScanFolderPrefPage(this); + getGUI()->addPrefPage(pref); + updateScanFolders(); + } + + void ScanFolderPlugin::unload() + { + getGUI()->removePrefPage(pref); + delete pref; + pref = 0; + + if(m_sf1) + delete m_sf1; + m_sf1 = 0; + + if(m_sf2) + delete m_sf2; + m_sf2 = 0; + + if(m_sf3) + delete m_sf3; + m_sf3 = 0; + } + + void ScanFolderPlugin::updateScanFolders() + { + QString sfPath1 = ScanFolderPluginSettings::folder1(); + QString sfPath2 = ScanFolderPluginSettings::folder2(); + QString sfPath3 = ScanFolderPluginSettings::folder3(); + + bool valid1 = QFile::exists(sfPath1); + bool valid2 = QFile::exists(sfPath2); + bool valid3 = QFile::exists(sfPath3); + + bool usesf1 = ScanFolderPluginSettings::useFolder1() && valid1; + bool usesf2 = ScanFolderPluginSettings::useFolder2() && valid2; + bool usesf3 = ScanFolderPluginSettings::useFolder3() && valid3; + + bool silently = ScanFolderPluginSettings::openSilently(); + + LoadedTorrentAction action; + + if(ScanFolderPluginSettings::actionDelete()) + action = deleteAction; + else if(ScanFolderPluginSettings::actionMove()) + action = moveAction; + else + action = defaultAction; + + + if(usesf1) + { + if(!m_sf1) + m_sf1 = new ScanFolder(getCore(), sfPath1, action, silently); + else + { + m_sf1->setFolderUrl(sfPath1); + m_sf1->setLoadedAction(action); + m_sf1->setOpenSilently(silently); + } + } + else + { + if(m_sf1) + delete m_sf1; + m_sf1 = 0; + } + + if(usesf2) + { + if(!m_sf2) + m_sf2 = new ScanFolder(getCore(), sfPath1, action, silently); + else + { + m_sf2->setFolderUrl(sfPath1); + m_sf2->setLoadedAction(action); + m_sf2->setOpenSilently(silently); + } + } + else + { + if(m_sf2) + delete m_sf2; + m_sf2 = 0; + } + + if(usesf3) + { + if(!m_sf3) + m_sf3 = new ScanFolder(getCore(), sfPath1, action, silently); + else + { + m_sf3->setFolderUrl(sfPath1); + m_sf3->setLoadedAction(action); + m_sf3->setOpenSilently(silently); + } + } + else + { + if(m_sf3) + delete m_sf3; + m_sf3 = 0; + } + + //update config file + if(!valid1) + ScanFolderPluginSettings::setUseFolder1(false); + if(!valid2) + ScanFolderPluginSettings::setUseFolder2(false); + if(!valid3) + ScanFolderPluginSettings::setUseFolder3(false); + + ScanFolderPluginSettings::writeConfig(); + + } + + bool ScanFolderPlugin::versionCheck(const QString & version) const + { + return version == KT_VERSION_MACRO; + } +} diff --git a/plugins/scanfolder/scanfolderplugin.h b/plugins/scanfolder/scanfolderplugin.h new file mode 100644 index 0000000..2ef50c1 --- /dev/null +++ b/plugins/scanfolder/scanfolderplugin.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * 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. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTSCANFOLDERPLUGIN_H +#define KTSCANFOLDERPLUGIN_H + +#include + +class QString; + + +namespace kt +{ + class ScanFolder; + class ScanFolderPrefPage; + + /** + * @author Ivan Vasic + * @brief KTorrent ScanFolder plugin + * Automatically scans selected folder for torrent files and loads them. + */ + class ScanFolderPlugin : public Plugin + { + Q_OBJECT + public: + ScanFolderPlugin(QObject* parent, const char* name, const QStringList& args); + virtual ~ScanFolderPlugin(); + + virtual void load(); + virtual void unload(); + virtual bool versionCheck(const QString& version) const; + + void updateScanFolders(); + + private: + ScanFolder* m_sf1; + ScanFolder* m_sf2; + ScanFolder* m_sf3; + + ScanFolderPrefPage* pref; + }; + +} + +#endif diff --git a/plugins/scanfolder/scanfolderpluginsettings.kcfgc b/plugins/scanfolder/scanfolderpluginsettings.kcfgc new file mode 100644 index 0000000..af1ebbc --- /dev/null +++ b/plugins/scanfolder/scanfolderpluginsettings.kcfgc @@ -0,0 +1,7 @@ +# Code generation options for kconfig_compiler +File=ktscanfolderplugin.kcfg +ClassName=ScanFolderPluginSettings +Namespace=kt +Singleton=true +Mutators=true +# will create the necessary code for setting those variables \ No newline at end of file diff --git a/plugins/scanfolder/scanfolderprefpage.cpp b/plugins/scanfolder/scanfolderprefpage.cpp new file mode 100644 index 0000000..9abbf0d --- /dev/null +++ b/plugins/scanfolder/scanfolderprefpage.cpp @@ -0,0 +1,66 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * 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. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "scanfolderplugin.h" +#include "scanfolderprefpage.h" + +#include +#include +#include +#include + + + +namespace kt +{ + + ScanFolderPrefPage::ScanFolderPrefPage(ScanFolderPlugin* plugin) + : PrefPageInterface(i18n("ScanFolder"), i18n("ScanFolder Options"), + KGlobal::iconLoader()->loadIcon("view_sidetree",KIcon::NoGroup)), m_plugin(plugin) + {} + + + ScanFolderPrefPage::~ScanFolderPrefPage() + {} + + bool ScanFolderPrefPage::apply() + { + if(m_widget) + m_widget->apply(); + + m_plugin->updateScanFolders(); + + return true; + } + + void ScanFolderPrefPage::createWidget(QWidget* parent) + { + m_widget = new ScanFolderPrefPageWidget(parent); + } + + void ScanFolderPrefPage::updateData() + { + } + + void ScanFolderPrefPage::deleteWidget() + { + delete m_widget; + } + +} diff --git a/plugins/scanfolder/scanfolderprefpage.h b/plugins/scanfolder/scanfolderprefpage.h new file mode 100644 index 0000000..539a5fe --- /dev/null +++ b/plugins/scanfolder/scanfolderprefpage.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * 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. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTSCANFOLDERPREFPAGE_H +#define KTSCANFOLDERPREFPAGE_H + +#include + +#include "scanfolderplugin.h" +#include "scanfolderprefpagewidget.h" + +namespace kt +{ + + /** + * ScanFolder plugin preferences page + * @author Ivan Vasić + */ + class ScanFolderPrefPage : public PrefPageInterface + { + public: + ScanFolderPrefPage(ScanFolderPlugin* plugin); + virtual ~ScanFolderPrefPage(); + + virtual bool apply(); + virtual void createWidget(QWidget* parent); + virtual void updateData(); + virtual void deleteWidget(); + + private: + ScanFolderPlugin* m_plugin; + ScanFolderPrefPageWidget* m_widget; + }; + +} + +#endif diff --git a/plugins/scanfolder/scanfolderprefpagewidget.cpp b/plugins/scanfolder/scanfolderprefpagewidget.cpp new file mode 100644 index 0000000..b577a88 --- /dev/null +++ b/plugins/scanfolder/scanfolderprefpagewidget.cpp @@ -0,0 +1,107 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * 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. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "scanfolderprefpagewidget.h" +#include "scanfolderpluginsettings.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace kt +{ + ScanFolderPrefPageWidget::ScanFolderPrefPageWidget(QWidget *parent, const char *name) + :SfPrefPageWidgetBase(parent, name) + { + use1->setChecked(ScanFolderPluginSettings::useFolder1()); + use2->setChecked(ScanFolderPluginSettings::useFolder2()); + use3->setChecked(ScanFolderPluginSettings::useFolder3()); + + url1->setURL(ScanFolderPluginSettings::folder1()); + url2->setURL(ScanFolderPluginSettings::folder2()); + url3->setURL(ScanFolderPluginSettings::folder3()); + + openSilently->setChecked(ScanFolderPluginSettings::openSilently()); + deleteCheck->setChecked(ScanFolderPluginSettings::actionDelete()); + moveCheck->setChecked(ScanFolderPluginSettings::actionMove()); + + url1->setMode(KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly); + url2->setMode(KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly); + url3->setMode(KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly); + } + + void ScanFolderPrefPageWidget::apply() + { + bool usesf1 = use1->isChecked(); + bool usesf2 = use2->isChecked(); + bool usesf3 = use3->isChecked(); + + QString sfPath1 = url1->url(); + QString sfPath2 = url2->url(); + QString sfPath3 = url3->url(); + + bool silently = openSilently->isChecked(); + bool deleteChecked = deleteCheck->isChecked(); + bool moveChecked = moveCheck->isChecked(); + + ScanFolderPluginSettings::setOpenSilently(silently); + ScanFolderPluginSettings::setActionDelete(deleteChecked); + ScanFolderPluginSettings::setActionMove(moveChecked); + + QString message = i18n( "ScanFolder - Folder %1: Invalid URL or folder does not exist. Please, choose a valid directory." ); + if(!QFile::exists(sfPath1) && usesf1) + { + KMessageBox::sorry(0, message.arg( 1 ) ); + usesf1 = false; + } + else + ScanFolderPluginSettings::setFolder1(sfPath1); + + if(!QFile::exists(sfPath2) && usesf2) + { + KMessageBox::sorry(0, message.arg( 2 ) ); + usesf2 = false; + } + else + ScanFolderPluginSettings::setFolder2(sfPath2); + + if(!QFile::exists(sfPath3) && usesf3) + { + KMessageBox::sorry(0, message.arg( 3 ) ); + usesf3 = false; + } + else + ScanFolderPluginSettings::setFolder3(sfPath3); + + + ScanFolderPluginSettings::setUseFolder1(usesf1); + ScanFolderPluginSettings::setUseFolder2(usesf2); + ScanFolderPluginSettings::setUseFolder3(usesf3); + + ScanFolderPluginSettings::writeConfig(); + } + +} +#include "scanfolderprefpagewidget.moc" diff --git a/plugins/scanfolder/scanfolderprefpagewidget.h b/plugins/scanfolder/scanfolderprefpagewidget.h new file mode 100644 index 0000000..480b3b0 --- /dev/null +++ b/plugins/scanfolder/scanfolderprefpagewidget.h @@ -0,0 +1,36 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * 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. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef SCANFOLDERPREFPAGEWIDGET_H +#define SCANFOLDERPREFPAGEWIDGET_H + +#include "sfprefwidgetbase.h" + +namespace kt +{ + class ScanFolderPrefPageWidget: public SfPrefPageWidgetBase + { + Q_OBJECT + public: + ScanFolderPrefPageWidget(QWidget *parent = 0, const char *name = 0); + + void apply(); + }; +} +#endif diff --git a/plugins/scanfolder/sfprefwidgetbase.ui b/plugins/scanfolder/sfprefwidgetbase.ui new file mode 100644 index 0000000..8b2c83a --- /dev/null +++ b/plugins/scanfolder/sfprefwidgetbase.ui @@ -0,0 +1,272 @@ + +SfPrefPageWidgetBase + + + SfPrefPageWidgetBase + + + + 0 + 0 + 546 + 480 + + + + ScanFolder Preferences + + + + unnamed + + + + layout16 + + + + unnamed + + + + use1 + + + Scan folder &1 + + + Alt+1 + + + + + use2 + + + Scan folder &2 + + + Alt+2 + + + + + use3 + + + Scan folder &3 + + + Alt+3 + + + + + + + buttonGroup1 + + + Options + + + + unnamed + + + + moveCheck + + + Move to "loaded" directory &after loading + + + Move torrent to "loaded" directory after loading it + + + + + openSilently + + + Open torrents silentl&y + + + Do not show 'Select files to download' dialog + + + + + deleteCheck + + + Delete after loadin&g + + + Deletes torrent after loading + + + + + + + groupBox9 + + + Folders to scan + + + + unnamed + + + + url1 + + + false + + + + + url2 + + + false + + + + + url3 + + + false + + + + + textLabel1 + + + Folder 1: + + + kURLRequester1 + + + + + textLabel2 + + + Folder 2: + + + kURLRequester4 + + + + + textLabel3 + + + Folder 3: + + + kURLRequester5 + + + + + + + spacer6 + + + Vertical + + + Fixed + + + + 20 + 20 + + + + + + spacer4 + + + Vertical + + + Expanding + + + + 20 + 90 + + + + + + + + use1 + toggled(bool) + url1 + setEnabled(bool) + + + use2 + toggled(bool) + url2 + setEnabled(bool) + + + use3 + toggled(bool) + url3 + setEnabled(bool) + + + deleteCheck + toggled(bool) + moveCheck + setDisabled(bool) + + + moveCheck + toggled(bool) + deleteCheck + setDisabled(bool) + + + + use1 + use2 + use3 + url1 + url2 + url3 + openSilently + deleteCheck + moveCheck + + + + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + + -- cgit v1.2.1