summaryrefslogtreecommitdiffstats
path: root/plugins/scanfolder
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 02:37:40 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 02:37:40 +0000
commit9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0 (patch)
treed088b5210e77d9fa91d954d8550e00e372b47378 /plugins/scanfolder
downloadktorrent-9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0.tar.gz
ktorrent-9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0.zip
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
Diffstat (limited to 'plugins/scanfolder')
-rw-r--r--plugins/scanfolder/Makefile.am31
-rw-r--r--plugins/scanfolder/ktscanfolderplugin.desktop26
-rw-r--r--plugins/scanfolder/ktscanfolderplugin.kcfg53
-rw-r--r--plugins/scanfolder/scanfolder.cpp273
-rw-r--r--plugins/scanfolder/scanfolder.h111
-rw-r--r--plugins/scanfolder/scanfolderplugin.cpp187
-rw-r--r--plugins/scanfolder/scanfolderplugin.h61
-rw-r--r--plugins/scanfolder/scanfolderpluginsettings.kcfgc7
-rw-r--r--plugins/scanfolder/scanfolderprefpage.cpp66
-rw-r--r--plugins/scanfolder/scanfolderprefpage.h53
-rw-r--r--plugins/scanfolder/scanfolderprefpagewidget.cpp107
-rw-r--r--plugins/scanfolder/scanfolderprefpagewidget.h36
-rw-r--r--plugins/scanfolder/sfprefwidgetbase.ui272
13 files changed, 1283 insertions, 0 deletions
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
+ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
+
+ <group name="general">
+ <entry name="useFolder1" type="Bool">
+ <label>Enable scanning of folder1?</label>
+ <default>FALSE</default>
+ </entry>
+
+ <entry name="useFolder2" type="Bool">
+ <label>Enable scanning of folder2?</label>
+ <default>FALSE</default>
+ </entry>
+
+ <entry name="useFolder3" type="Bool">
+ <label>Enable scanning of folder3?</label>
+ <default>FALSE</default>
+ </entry>
+
+ <entry name="folder1" type="String">
+ <label>Folder1 path</label>
+ <default></default>
+ </entry>
+
+ <entry name="folder2" type="String">
+ <label>Folder2 path</label>
+ <default></default>
+ </entry>
+
+ <entry name="folder3" type="String">
+ <label>Folder3 path</label>
+ <default></default>
+ </entry>
+
+ <entry name="openSilently" type="Bool">
+ <label>Whether to open torrent silently or not.</label>
+ <default>FALSE</default>
+ </entry>
+
+ <entry name="actionDelete" type="Bool">
+ <label>Delete action checked.</label>
+ <default>FALSE</default>
+ </entry>
+
+ <entry name="actionMove" type="Bool">
+ <label>Move action checked.</label>
+ <default>FALSE</default>
+ </entry>
+ </group>
+</kcfg>
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 <kdirlister.h>
+#include <kfileitem.h>
+#include <klocale.h>
+#include <kio/job.h>
+
+#include <qstring.h>
+#include <qobject.h>
+#include <qfile.h>
+#include <qvaluelist.h>
+
+#include <torrent/globals.h>
+#include <util/log.h>
+#include <util/fileops.h>
+#include <util/functions.h>
+#include <util/constants.h>
+
+#include <torrent/bnode.h>
+#include <torrent/bdecoder.h>
+
+#include <interfaces/coreinterface.h>
+
+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<KURL>::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<KURL>::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 <kdirlister.h>
+#include <kfileitem.h>
+#include <qstring.h>
+#include <qobject.h>
+#include <qdir.h>
+#include <qvaluelist.h>
+#include <qtimer.h>
+#include <kurl.h>
+
+namespace kt
+{
+ ///Action to perform after loading torrent.
+ enum LoadedTorrentAction
+ {
+ deleteAction,
+ moveAction,
+ defaultAction
+ };
+
+ class CoreInterface;
+
+ /**
+ * @brief Scanned folder class.
+ * @author Ivan Vasić <ivasic@gmail.com>
+ *
+ * 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<KURL> m_pendingURLs;
+ QValueList<KURL> 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 <kgenericfactory.h>
+
+#include <interfaces/coreinterface.h>
+#include <interfaces/guiinterface.h>
+#include <interfaces/plugin.h>
+#include <util/constants.h>
+#include <util/log.h>
+
+#include <qstring.h>
+#include <qfile.h>
+
+#include <kmessagebox.h>
+#include <klocale.h>
+#include <kglobal.h>
+
+#include "scanfolder.h"
+#include "scanfolderplugin.h"
+#include "scanfolderprefpage.h"
+#include "scanfolderpluginsettings.h"
+
+using namespace bt;
+
+K_EXPORT_COMPONENT_FACTORY(ktscanfolderplugin,KGenericFactory<kt::ScanFolderPlugin>("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 <interfaces/plugin.h>
+
+class QString;
+
+
+namespace kt
+{
+ class ScanFolder;
+ class ScanFolderPrefPage;
+
+ /**
+ * @author Ivan Vasic <ivasic@gmail.com>
+ * @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 <klocale.h>
+#include <kglobal.h>
+#include <kstandarddirs.h>
+#include <kiconloader.h>
+
+
+
+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 <interfaces/prefpageinterface.h>
+
+#include "scanfolderplugin.h"
+#include "scanfolderprefpagewidget.h"
+
+namespace kt
+{
+
+ /**
+ * ScanFolder plugin preferences page
+ * @author Ivan Vasić <ivasic@gmail.com>
+ */
+ 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 <qwidget.h>
+#include <qstring.h>
+#include <qcheckbox.h>
+#include <qfile.h>
+
+#include <kglobal.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kurlrequester.h>
+
+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 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>SfPrefPageWidgetBase</class>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>SfPrefPageWidgetBase</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>546</width>
+ <height>480</height>
+ </rect>
+ </property>
+ <property name="caption">
+ <string>ScanFolder Preferences</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLayoutWidget" row="0" column="0">
+ <property name="name">
+ <cstring>layout16</cstring>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>use1</cstring>
+ </property>
+ <property name="text">
+ <string>Scan folder &amp;1</string>
+ </property>
+ <property name="accel">
+ <string>Alt+1</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>use2</cstring>
+ </property>
+ <property name="text">
+ <string>Scan folder &amp;2</string>
+ </property>
+ <property name="accel">
+ <string>Alt+2</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>use3</cstring>
+ </property>
+ <property name="text">
+ <string>Scan folder &amp;3</string>
+ </property>
+ <property name="accel">
+ <string>Alt+3</string>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
+ <widget class="QButtonGroup" row="3" column="0">
+ <property name="name">
+ <cstring>buttonGroup1</cstring>
+ </property>
+ <property name="title">
+ <string>Options</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QCheckBox" row="2" column="0">
+ <property name="name">
+ <cstring>moveCheck</cstring>
+ </property>
+ <property name="text">
+ <string>Move to "loaded" directory &amp;after loading</string>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Move torrent to "loaded" directory after loading it</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" row="0" column="0">
+ <property name="name">
+ <cstring>openSilently</cstring>
+ </property>
+ <property name="text">
+ <string>Open torrents silentl&amp;y</string>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Do not show 'Select files to download' dialog</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" row="1" column="0">
+ <property name="name">
+ <cstring>deleteCheck</cstring>
+ </property>
+ <property name="text">
+ <string>Delete after loadin&amp;g</string>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Deletes torrent after loading</string>
+ </property>
+ </widget>
+ </grid>
+ </widget>
+ <widget class="QGroupBox" row="2" column="0">
+ <property name="name">
+ <cstring>groupBox9</cstring>
+ </property>
+ <property name="title">
+ <string>Folders to scan</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="KURLRequester" row="0" column="1">
+ <property name="name">
+ <cstring>url1</cstring>
+ </property>
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ </widget>
+ <widget class="KURLRequester" row="1" column="1">
+ <property name="name">
+ <cstring>url2</cstring>
+ </property>
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ </widget>
+ <widget class="KURLRequester" row="2" column="1">
+ <property name="name">
+ <cstring>url3</cstring>
+ </property>
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ </widget>
+ <widget class="QLabel" row="0" column="0">
+ <property name="name">
+ <cstring>textLabel1</cstring>
+ </property>
+ <property name="text">
+ <string>Folder 1:</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>kURLRequester1</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="1" column="0">
+ <property name="name">
+ <cstring>textLabel2</cstring>
+ </property>
+ <property name="text">
+ <string>Folder 2:</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>kURLRequester4</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="2" column="0">
+ <property name="name">
+ <cstring>textLabel3</cstring>
+ </property>
+ <property name="text">
+ <string>Folder 3:</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>kURLRequester5</cstring>
+ </property>
+ </widget>
+ </grid>
+ </widget>
+ <spacer row="1" column="0">
+ <property name="name">
+ <cstring>spacer6</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Fixed</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ <spacer row="4" column="0">
+ <property name="name">
+ <cstring>spacer4</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>90</height>
+ </size>
+ </property>
+ </spacer>
+ </grid>
+</widget>
+<connections>
+ <connection>
+ <sender>use1</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>url1</receiver>
+ <slot>setEnabled(bool)</slot>
+ </connection>
+ <connection>
+ <sender>use2</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>url2</receiver>
+ <slot>setEnabled(bool)</slot>
+ </connection>
+ <connection>
+ <sender>use3</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>url3</receiver>
+ <slot>setEnabled(bool)</slot>
+ </connection>
+ <connection>
+ <sender>deleteCheck</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>moveCheck</receiver>
+ <slot>setDisabled(bool)</slot>
+ </connection>
+ <connection>
+ <sender>moveCheck</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>deleteCheck</receiver>
+ <slot>setDisabled(bool)</slot>
+ </connection>
+</connections>
+<tabstops>
+ <tabstop>use1</tabstop>
+ <tabstop>use2</tabstop>
+ <tabstop>use3</tabstop>
+ <tabstop>url1</tabstop>
+ <tabstop>url2</tabstop>
+ <tabstop>url3</tabstop>
+ <tabstop>openSilently</tabstop>
+ <tabstop>deleteCheck</tabstop>
+ <tabstop>moveCheck</tabstop>
+</tabstops>
+<layoutdefaults spacing="6" margin="11"/>
+<includehints>
+ <includehint>kurlrequester.h</includehint>
+ <includehint>klineedit.h</includehint>
+ <includehint>kpushbutton.h</includehint>
+ <includehint>kurlrequester.h</includehint>
+ <includehint>klineedit.h</includehint>
+ <includehint>kpushbutton.h</includehint>
+ <includehint>kurlrequester.h</includehint>
+ <includehint>klineedit.h</includehint>
+ <includehint>kpushbutton.h</includehint>
+</includehints>
+</UI>