From 44ef0bd5fe47a43e47aec5f7981b6c1d728dd9a8 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 2 Mar 2025 18:37:22 +0900 Subject: Restructure source files into 'src' subfolder Signed-off-by: Michele Calgaro --- src/plugins/scanfolder/Makefile.am | 31 +++ src/plugins/scanfolder/ktscanfolderplugin.desktop | 26 ++ src/plugins/scanfolder/ktscanfolderplugin.kcfg | 53 ++++ src/plugins/scanfolder/scanfolder.cpp | 273 +++++++++++++++++++++ src/plugins/scanfolder/scanfolder.h | 112 +++++++++ src/plugins/scanfolder/scanfolderplugin.cpp | 187 ++++++++++++++ src/plugins/scanfolder/scanfolderplugin.h | 62 +++++ .../scanfolder/scanfolderpluginsettings.kcfgc | 7 + src/plugins/scanfolder/scanfolderprefpage.cpp | 66 +++++ src/plugins/scanfolder/scanfolderprefpage.h | 53 ++++ .../scanfolder/scanfolderprefpagewidget.cpp | 107 ++++++++ src/plugins/scanfolder/scanfolderprefpagewidget.h | 37 +++ src/plugins/scanfolder/sfprefwidgetbase.ui | 257 +++++++++++++++++++ 13 files changed, 1271 insertions(+) create mode 100644 src/plugins/scanfolder/Makefile.am create mode 100644 src/plugins/scanfolder/ktscanfolderplugin.desktop create mode 100644 src/plugins/scanfolder/ktscanfolderplugin.kcfg create mode 100644 src/plugins/scanfolder/scanfolder.cpp create mode 100644 src/plugins/scanfolder/scanfolder.h create mode 100644 src/plugins/scanfolder/scanfolderplugin.cpp create mode 100644 src/plugins/scanfolder/scanfolderplugin.h create mode 100644 src/plugins/scanfolder/scanfolderpluginsettings.kcfgc create mode 100644 src/plugins/scanfolder/scanfolderprefpage.cpp create mode 100644 src/plugins/scanfolder/scanfolderprefpage.h create mode 100644 src/plugins/scanfolder/scanfolderprefpagewidget.cpp create mode 100644 src/plugins/scanfolder/scanfolderprefpagewidget.h create mode 100644 src/plugins/scanfolder/sfprefwidgetbase.ui (limited to 'src/plugins/scanfolder') diff --git a/src/plugins/scanfolder/Makefile.am b/src/plugins/scanfolder/Makefile.am new file mode 100644 index 0000000..49ba5a7 --- /dev/null +++ b/src/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_TDEPARTS) ../../libktorrent/libktorrent.la \ + $(LIB_TQT) $(LIB_TDECORE) $(LIB_TDEUI) $(LIB_TDEFILE) + + +KDE_CXXFLAGS = $(USE_EXCEPTIONS) $(USE_RTTI) diff --git a/src/plugins/scanfolder/ktscanfolderplugin.desktop b/src/plugins/scanfolder/ktscanfolderplugin.desktop new file mode 100644 index 0000000..53c7a6c --- /dev/null +++ b/src/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]=掃描資料夾外掛程式 +X-TDE-ServiceTypes=KTorrent/Plugin +Type=Service +X-TDE-Library=ktscanfolderplugin diff --git a/src/plugins/scanfolder/ktscanfolderplugin.kcfg b/src/plugins/scanfolder/ktscanfolderplugin.kcfg new file mode 100644 index 0000000..f9b919f --- /dev/null +++ b/src/plugins/scanfolder/ktscanfolderplugin.kcfg @@ -0,0 +1,53 @@ + + + + + + + FALSE + + + + + FALSE + + + + + FALSE + + + + + + + + + + + + + + + + + + + + FALSE + + + + + FALSE + + + + + FALSE + + + diff --git a/src/plugins/scanfolder/scanfolder.cpp b/src/plugins/scanfolder/scanfolder.cpp new file mode 100644 index 0000000..135aea2 --- /dev/null +++ b/src/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, TQString& 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, TQ_SIGNAL(newItems( const KFileItemList& )), this, TQ_SLOT(onNewItems( const KFileItemList& ))); + connect(m_core, TQ_SIGNAL(loadingFinished( const KURL&, bool, bool )), this, TQ_SLOT(onLoadingFinished( const KURL&, bool, bool ))); + connect(&m_incomplePollingTimer,TQ_SIGNAL(timeout()),this,TQ_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()) + { + TQString name = file->name(); + TQString dirname = m_dir->url().path(); + TQString filename = dirname + bt::DirSeparator() + name; + + if(!name.endsWith(".torrent")) + continue; + + if(name.startsWith(".")) + { + //Check if corresponding torrent exists + if(!TQFile::exists(m_dir->url().path() + bt::DirSeparator() + name.right(name.length() - 1)) && (m_loadedAction == defaultAction)) + TQFile::remove(filename); + + continue; + } + + KURL source; + source.setPath(filename); + + //If torrent has it's hidden complement - skip it. + if(TQFile::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 + TQValueList::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; + + TQString name = url.filename(false); + TQString dirname = m_dir->url().path(); + TQString 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(TQFile::exists(dirname + "/." + name)) + TQFile::remove(dirname + "/." + name); + // Out() << "Deleting: " << name.ascii() << endl; + TQFile::remove(filename); + break; + case moveAction: + // Out() << "Moving: " << name.ascii() << endl; + //If torrent has it's hidden complement - remove it too. + if(TQFile::exists(dirname + "/." + name)) + TQFile::remove(dirname + "/." + name); + + // NetAccess considered harmfull !!! + TDEIO::file_move(url, destination); + break; + case defaultAction: + TQFile 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; + + TQDir tmp(m_dir->url().path()); + + if( (m_loadedAction == moveAction) && !tmp.exists(i18n("loaded"), false)) + tmp.mkdir(i18n("loaded"), false); + } + + void ScanFolder::setFolderUrl(TQString& 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 + TQFile fptr(src.path()); + if (!fptr.open(IO_ReadOnly)) + return false; + + try + { + TQByteArray 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 (TQValueList::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/src/plugins/scanfolder/scanfolder.h b/src/plugins/scanfolder/scanfolder.h new file mode 100644 index 0000000..58fbd04 --- /dev/null +++ b/src/plugins/scanfolder/scanfolder.h @@ -0,0 +1,112 @@ +/*************************************************************************** + * 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 TQObject + { + TQ_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, TQString& 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(TQString& 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; + + TQValueList m_pendingURLs; + TQValueList m_incompleteURLs; + + TQTimer m_incomplePollingTimer; + }; +} +#endif diff --git a/src/plugins/scanfolder/scanfolderplugin.cpp b/src/plugins/scanfolder/scanfolderplugin.cpp new file mode 100644 index 0000000..710d1d0 --- /dev/null +++ b/src/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 TQString NAME = "Scan Folder"; + const TQString AUTHOR = "Ivan Vasic"; + const TQString EMAIL = "ivasic@gmail.com"; + const TQString DESCRIPTION = i18n("Automatically scans directories for torrent files and loads them."); + + ScanFolderPlugin::ScanFolderPlugin(TQObject* parent, const char* name, const TQStringList& 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() + { + TQString sfPath1 = ScanFolderPluginSettings::folder1(); + TQString sfPath2 = ScanFolderPluginSettings::folder2(); + TQString sfPath3 = ScanFolderPluginSettings::folder3(); + + bool valid1 = TQFile::exists(sfPath1); + bool valid2 = TQFile::exists(sfPath2); + bool valid3 = TQFile::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 TQString & version) const + { + return version == KT_VERSION_MACRO; + } +} diff --git a/src/plugins/scanfolder/scanfolderplugin.h b/src/plugins/scanfolder/scanfolderplugin.h new file mode 100644 index 0000000..3ea18ce --- /dev/null +++ b/src/plugins/scanfolder/scanfolderplugin.h @@ -0,0 +1,62 @@ +/*************************************************************************** + * 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 TQString; + + +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 + { + TQ_OBJECT + + public: + ScanFolderPlugin(TQObject* parent, const char* name, const TQStringList& args); + virtual ~ScanFolderPlugin(); + + virtual void load(); + virtual void unload(); + virtual bool versionCheck(const TQString& version) const; + + void updateScanFolders(); + + private: + ScanFolder* m_sf1; + ScanFolder* m_sf2; + ScanFolder* m_sf3; + + ScanFolderPrefPage* pref; + }; + +} + +#endif diff --git a/src/plugins/scanfolder/scanfolderpluginsettings.kcfgc b/src/plugins/scanfolder/scanfolderpluginsettings.kcfgc new file mode 100644 index 0000000..7550c9d --- /dev/null +++ b/src/plugins/scanfolder/scanfolderpluginsettings.kcfgc @@ -0,0 +1,7 @@ +# Code generation options for tdeconfig_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/src/plugins/scanfolder/scanfolderprefpage.cpp b/src/plugins/scanfolder/scanfolderprefpage.cpp new file mode 100644 index 0000000..8846aa9 --- /dev/null +++ b/src/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"), + TDEGlobal::iconLoader()->loadIcon("view_sidetree",TDEIcon::NoGroup)), m_plugin(plugin) + {} + + + ScanFolderPrefPage::~ScanFolderPrefPage() + {} + + bool ScanFolderPrefPage::apply() + { + if(m_widget) + m_widget->apply(); + + m_plugin->updateScanFolders(); + + return true; + } + + void ScanFolderPrefPage::createWidget(TQWidget* parent) + { + m_widget = new ScanFolderPrefPageWidget(parent); + } + + void ScanFolderPrefPage::updateData() + { + } + + void ScanFolderPrefPage::deleteWidget() + { + delete m_widget; + } + +} diff --git a/src/plugins/scanfolder/scanfolderprefpage.h b/src/plugins/scanfolder/scanfolderprefpage.h new file mode 100644 index 0000000..cb2f80c --- /dev/null +++ b/src/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(TQWidget* parent); + virtual void updateData(); + virtual void deleteWidget(); + + private: + ScanFolderPlugin* m_plugin; + ScanFolderPrefPageWidget* m_widget; + }; + +} + +#endif diff --git a/src/plugins/scanfolder/scanfolderprefpagewidget.cpp b/src/plugins/scanfolder/scanfolderprefpagewidget.cpp new file mode 100644 index 0000000..14b89ff --- /dev/null +++ b/src/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(TQWidget *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(); + + TQString sfPath1 = url1->url(); + TQString sfPath2 = url2->url(); + TQString sfPath3 = url3->url(); + + bool silently = openSilently->isChecked(); + bool deleteChecked = deleteCheck->isChecked(); + bool moveChecked = moveCheck->isChecked(); + + ScanFolderPluginSettings::setOpenSilently(silently); + ScanFolderPluginSettings::setActionDelete(deleteChecked); + ScanFolderPluginSettings::setActionMove(moveChecked); + + TQString message = i18n( "ScanFolder - Folder %1: Invalid URL or folder does not exist. Please, choose a valid directory." ); + if(!TQFile::exists(sfPath1) && usesf1) + { + KMessageBox::sorry(0, message.arg( 1 ) ); + usesf1 = false; + } + else + ScanFolderPluginSettings::setFolder1(sfPath1); + + if(!TQFile::exists(sfPath2) && usesf2) + { + KMessageBox::sorry(0, message.arg( 2 ) ); + usesf2 = false; + } + else + ScanFolderPluginSettings::setFolder2(sfPath2); + + if(!TQFile::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/src/plugins/scanfolder/scanfolderprefpagewidget.h b/src/plugins/scanfolder/scanfolderprefpagewidget.h new file mode 100644 index 0000000..963ca40 --- /dev/null +++ b/src/plugins/scanfolder/scanfolderprefpagewidget.h @@ -0,0 +1,37 @@ +/*************************************************************************** + * 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 + { + TQ_OBJECT + + public: + ScanFolderPrefPageWidget(TQWidget *parent = 0, const char *name = 0); + + void apply(); + }; +} +#endif diff --git a/src/plugins/scanfolder/sfprefwidgetbase.ui b/src/plugins/scanfolder/sfprefwidgetbase.ui new file mode 100644 index 0000000..1e696e6 --- /dev/null +++ b/src/plugins/scanfolder/sfprefwidgetbase.ui @@ -0,0 +1,257 @@ + +SfPrefPageWidgetBase + + + SfPrefPageWidgetBase + + + + 0 + 0 + 546 + 480 + + + + ScanFolder Preferences + + + + unnamed + + + + layout16 + + + + unnamed + + + + use1 + + + Scan folder &1 + + + + + use2 + + + Scan folder &2 + + + + + use3 + + + Scan folder &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 + + + + klineedit.h + kpushbutton.h + kurlrequester.h + + -- cgit v1.2.1