summaryrefslogtreecommitdiffstats
path: root/libktorrent/interfaces
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 /libktorrent/interfaces
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 'libktorrent/interfaces')
-rw-r--r--libktorrent/interfaces/Makefile.am15
-rw-r--r--libktorrent/interfaces/chunkdownloadinterface.cpp33
-rw-r--r--libktorrent/interfaces/chunkdownloadinterface.h62
-rw-r--r--libktorrent/interfaces/coreinterface.cpp33
-rw-r--r--libktorrent/interfaces/coreinterface.h258
-rw-r--r--libktorrent/interfaces/exitoperation.cpp47
-rw-r--r--libktorrent/interfaces/exitoperation.h67
-rw-r--r--libktorrent/interfaces/filetreediritem.cpp295
-rw-r--r--libktorrent/interfaces/filetreediritem.h140
-rw-r--r--libktorrent/interfaces/filetreeitem.cpp182
-rw-r--r--libktorrent/interfaces/filetreeitem.h91
-rw-r--r--libktorrent/interfaces/functions.cpp62
-rw-r--r--libktorrent/interfaces/functions.h47
-rw-r--r--libktorrent/interfaces/guiinterface.cpp54
-rw-r--r--libktorrent/interfaces/guiinterface.h218
-rw-r--r--libktorrent/interfaces/ipblockinginterface.cpp33
-rw-r--r--libktorrent/interfaces/ipblockinginterface.h48
-rw-r--r--libktorrent/interfaces/logmonitorinterface.cpp33
-rw-r--r--libktorrent/interfaces/logmonitorinterface.h50
-rw-r--r--libktorrent/interfaces/monitorinterface.cpp33
-rw-r--r--libktorrent/interfaces/monitorinterface.h79
-rw-r--r--libktorrent/interfaces/peerinterface.cpp33
-rw-r--r--libktorrent/interfaces/peerinterface.h91
-rw-r--r--libktorrent/interfaces/peersource.cpp64
-rw-r--r--libktorrent/interfaces/peersource.h118
-rw-r--r--libktorrent/interfaces/plugin.cpp49
-rw-r--r--libktorrent/interfaces/plugin.h152
-rw-r--r--libktorrent/interfaces/prefpageinterface.cpp32
-rw-r--r--libktorrent/interfaces/prefpageinterface.h84
-rw-r--r--libktorrent/interfaces/torrentfileinterface.cpp44
-rw-r--r--libktorrent/interfaces/torrentfileinterface.h131
-rw-r--r--libktorrent/interfaces/torrentinterface.cpp43
-rw-r--r--libktorrent/interfaces/torrentinterface.h509
-rw-r--r--libktorrent/interfaces/trackerslist.cpp51
-rw-r--r--libktorrent/interfaces/trackerslist.h89
35 files changed, 3370 insertions, 0 deletions
diff --git a/libktorrent/interfaces/Makefile.am b/libktorrent/interfaces/Makefile.am
new file mode 100644
index 0000000..dca1a4a
--- /dev/null
+++ b/libktorrent/interfaces/Makefile.am
@@ -0,0 +1,15 @@
+INCLUDES = -I$(srcdir)/.. $(all_includes)
+METASOURCES = AUTO
+libinterfaces_la_LDFLAGS = $(all_libraries)
+noinst_LTLIBRARIES = libinterfaces.la
+noinst_HEADERS = plugin.h coreinterface.h guiinterface.h torrentinterface.h \
+ monitorinterface.h chunkdownloadinterface.h peerinterface.h torrentfileinterface.h \
+ filetreeitem.h filetreediritem.h logmonitorinterface.h ipblockinginterface.h \
+ trackerslist.h peersource.h exitoperation.h
+libinterfaces_la_SOURCES = plugin.cpp coreinterface.cpp guiinterface.cpp \
+ prefpageinterface.cpp torrentinterface.cpp monitorinterface.cpp chunkdownloadinterface.cpp \
+ peerinterface.cpp torrentfileinterface.cpp filetreeitem.cpp filetreediritem.cpp \
+ functions.cpp logmonitorinterface.cpp ipblockinginterface.cpp trackerslist.cpp \
+ peersource.cpp exitoperation.cpp
+
+KDE_CXXFLAGS = $(USE_EXCEPTIONS) $(USE_RTTI)
diff --git a/libktorrent/interfaces/chunkdownloadinterface.cpp b/libktorrent/interfaces/chunkdownloadinterface.cpp
new file mode 100644
index 0000000..d991605
--- /dev/null
+++ b/libktorrent/interfaces/chunkdownloadinterface.cpp
@@ -0,0 +1,33 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 "chunkdownloadinterface.h"
+
+namespace kt
+{
+
+ ChunkDownloadInterface::ChunkDownloadInterface()
+ {}
+
+
+ ChunkDownloadInterface::~ChunkDownloadInterface()
+ {}
+
+
+}
diff --git a/libktorrent/interfaces/chunkdownloadinterface.h b/libktorrent/interfaces/chunkdownloadinterface.h
new file mode 100644
index 0000000..161a534
--- /dev/null
+++ b/libktorrent/interfaces/chunkdownloadinterface.h
@@ -0,0 +1,62 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 KTCHUNKDOWNLOADINTERFACE_H
+#define KTCHUNKDOWNLOADINTERFACE_H
+
+#include <qstring.h>
+#include <util/constants.h>
+
+namespace kt
+{
+
+ /**
+ * @author Joris Guisson
+ * @brief Interface for a ChunkDownload
+ *
+ * This class provides the interface for a ChunkDownload object.
+ */
+ class ChunkDownloadInterface
+ {
+ public:
+ ChunkDownloadInterface();
+ virtual ~ChunkDownloadInterface();
+
+ struct Stats
+ {
+ /// The PeerID of the current downloader
+ QString current_peer_id;
+ /// The current download speed
+ bt::Uint32 download_speed;
+ /// The index of the chunk
+ bt::Uint32 chunk_index;
+ /// The number of pieces of the chunk which have been downloaded
+ bt::Uint32 pieces_downloaded;
+ /// The total number of pieces of the chunk
+ bt::Uint32 total_pieces;
+ /// The number of assigned downloaders
+ bt::Uint32 num_downloaders;
+ };
+
+ virtual void getStats(Stats & s) = 0;
+ };
+
+}
+
+#endif
diff --git a/libktorrent/interfaces/coreinterface.cpp b/libktorrent/interfaces/coreinterface.cpp
new file mode 100644
index 0000000..cb350d8
--- /dev/null
+++ b/libktorrent/interfaces/coreinterface.cpp
@@ -0,0 +1,33 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 "coreinterface.h"
+
+namespace kt
+{
+
+ CoreInterface::CoreInterface()
+ {}
+
+
+ CoreInterface::~CoreInterface()
+ {}
+}
+
+#include "coreinterface.moc"
diff --git a/libktorrent/interfaces/coreinterface.h b/libktorrent/interfaces/coreinterface.h
new file mode 100644
index 0000000..613ba8e
--- /dev/null
+++ b/libktorrent/interfaces/coreinterface.h
@@ -0,0 +1,258 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 KTCOREINTERFACE_H
+#define KTCOREINTERFACE_H
+
+#include <kurl.h>
+#include <qobject.h>
+#include <util/constants.h>
+#include <torrent/queuemanager.h>
+
+///Stats struct
+struct CurrentStats
+{
+ bt::Uint32 download_speed;
+ bt::Uint32 upload_speed;
+ bt::Uint64 bytes_downloaded;
+ bt::Uint64 bytes_uploaded;
+};
+
+namespace bt
+{
+ class QueueManager;
+}
+namespace kt
+{
+ class TorrentInterface;
+
+ /**
+ * @author Joris Guisson
+ * @brief Interface for plugins to communicate with the application's core
+ *
+ * This interface provides the plugin with the functionality to modify
+ * the applications core, the core is responsible for managing all
+ * TorrentControl objects.
+ */
+ class CoreInterface : public QObject
+ {
+ Q_OBJECT
+ public:
+ CoreInterface();
+ virtual ~CoreInterface();
+
+ /**
+ * Set the maximum number of simultanious downloads.
+ * @param max The max num (0 == no limit)
+ */
+ virtual void setMaxDownloads(int max) = 0;
+
+ virtual void setMaxSeeds(int max) = 0;
+
+ virtual void setMaxDownloadSpeed(int v) = 0;
+ virtual void setMaxUploadSpeed(int v) = 0;
+
+ /**
+ * Set wether or not we should keep seeding after
+ * a download has finished.
+ * @param ks Keep seeding yes or no
+ */
+ virtual void setKeepSeeding(bool ks) = 0;
+
+ /**
+ * Change the data dir. This involves copying
+ * all data from the old dir to the new.
+ * This can offcourse go horribly wrong, therefore
+ * if it doesn't succeed it returns false
+ * and leaves everything where it supposed to be.
+ * @param new_dir The new directory
+ */
+ virtual bool changeDataDir(const QString & new_dir) = 0;
+
+ /**
+ * Start all, takes into account the maximum number of downloads.
+ * @param type - Weather to start downloads, seeds or both. 1=Downloads, 2=Seeds, 3=All
+ */
+ virtual void startAll(int type) = 0;
+
+ /**
+ * Stop all torrents.
+ * @param type - Weather to start downloads, seeds or both. 1=Downloads, 2=Seeds, 3=All
+ */
+ virtual void stopAll(int type) = 0;
+
+ /**
+ * Start a torrent, takes into account the maximum number of downloads.
+ * @param tc The TorrentControl
+ */
+ virtual void start(TorrentInterface* tc) = 0;
+
+ /**
+ * Stop a torrent, may start another download if it hasn't been started.
+ * @param tc The TorrentControl
+ * @param user true if user stopped the torrent, false otherwise
+ */
+ virtual void stop(TorrentInterface* tc, bool user = false) = 0;
+
+ /**
+ * Enqueue/Dequeue function. Places a torrent in queue.
+ * If the torrent is already in queue this will remove it from queue.
+ * @param tc TorrentControl pointer.
+ */
+ virtual void queue(kt::TorrentInterface* tc) = 0;
+
+ virtual bt::QueueManager* getQueueManager() = 0;
+
+ virtual CurrentStats getStats() = 0;
+
+ /**
+ * Switch the port when no torrents are running.
+ * @param port The new port
+ * @return true if we can, false if there are torrents running
+ */
+ virtual bool changePort(bt::Uint16 port) = 0;
+
+ /// Get the number of torrents running (including seeding torrents).
+ virtual bt::Uint32 getNumTorrentsRunning() const = 0;
+
+ /// Get the number of torrents not running.
+ virtual bt::Uint32 getNumTorrentsNotRunning() const = 0;
+
+ /**
+ * Load a torrent file. Pops up an error dialog
+ * if something goes wrong.
+ * @param file The torrent file
+ * @param savedir Dir to save the data
+ * @param silently Wether or not to do this silently
+ */
+ virtual bool load(const QString & file,const QString & savedir,bool silently) = 0;
+
+ /**
+ * Load a torrent file. Pops up an error dialog
+ * if something goes wrong. Will ask the user for a save location, or use
+ * the default.
+ * @param url The torrent file
+ */
+ virtual void load(const KURL& url) = 0;
+
+ /**
+ * Load a torrent file. Pops up an error dialog
+ * if something goes wrong. Will ask the user for a save location, or use
+ * the default. This will not popup a file selection dialog for multi file torrents.
+ * @param url The torrent file
+ */
+ virtual void loadSilently(const KURL& url) = 0;
+
+ /**
+ * Remove a download.This will delete all temp
+ * data from this TorrentControl And delete the
+ * TorrentControl itself. It can also potentially
+ * start a new download (when one is waiting to be downloaded).
+ * @param tc The torrent
+ * @param data_to Wether or not to delete the file data to
+ */
+ virtual void remove(TorrentInterface* tc,bool data_to) = 0;
+
+ /**
+ * Inserts IP range to be blocked into IPBlocklist
+ * @param ip QString reference to single IP or IP range. For example:
+ * single - 127.0.0.5
+ * range - 127.0.*.*
+ **/
+ virtual void addBlockedIP(QString& ip) = 0;
+
+ /**
+ * Removes IP range from IPBlocklist
+ * @param ip QString reference to single IP or IP range. For example:
+ * single - 127.0.0.5
+ * range - 127.0.*.*
+ **/
+ virtual void removeBlockedIP(QString& ip) = 0;
+
+ /**
+ * Find the next free torX dir.
+ * @return Path to the dir (including the torX part)
+ */
+ virtual QString findNewTorrentDir() const = 0;
+
+ /**
+ * Load an existing torrent, which has already a properly set up torX dir.
+ * @param tor_dir The torX dir
+ */
+ virtual void loadExistingTorrent(const QString & tor_dir) = 0;
+
+ /**
+ * Returns maximum allowed download speed.
+ */
+ virtual int getMaxDownloadSpeed() = 0;
+
+ /**
+ * Returns maximum allowed upload speed.
+ */
+ virtual int getMaxUploadSpeed() = 0;
+
+ /**
+ * Sets global paused state for all torrents (QueueManager) and stopps all torrents.
+ * No torrents will be automatically started/stopped.
+ */
+ virtual void setPausedState(bool pause) = 0;
+
+ /// Get the global share ratio limit
+ virtual float getGlobalMaxShareRatio() const = 0;
+
+ signals:
+ /**
+ * Seeing that when load returns the loading process may not have finished yet,
+ * and some code expects this. We emit this signal to notify that code of it.
+ * @param url The url which has been loaded
+ * @param success Wether or not it succeeded
+ * @param canceled Wether or not it was canceled by the user
+ */
+ void loadingFinished(const KURL & url,bool success,bool canceled);
+
+ /**
+ * A TorrentInterface was added
+ * @param tc
+ */
+ void torrentAdded(kt::TorrentInterface* tc);
+
+
+ /**
+ * A TorrentInterface was removed
+ * @param tc
+ */
+ void torrentRemoved(kt::TorrentInterface* tc);
+
+ /**
+ * A TorrentInterface has finished downloading.
+ * @param tc
+ */
+ void finished(kt::TorrentInterface* tc);
+
+ /**
+ * Torrent download is stopped by error
+ * @param tc TorrentInterface
+ * @param msg Error message
+ */
+ void torrentStoppedByError(kt::TorrentInterface* tc, QString msg);
+ };
+
+}
+
+#endif
diff --git a/libktorrent/interfaces/exitoperation.cpp b/libktorrent/interfaces/exitoperation.cpp
new file mode 100644
index 0000000..8eedb7a
--- /dev/null
+++ b/libktorrent/interfaces/exitoperation.cpp
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 "exitoperation.h"
+
+namespace kt
+{
+
+ ExitOperation::ExitOperation()
+ {}
+
+
+ ExitOperation::~ExitOperation()
+ {}
+
+ ExitJobOperation::ExitJobOperation(KIO::Job* j)
+ {
+ connect(j,SIGNAL(result(KIO::Job*)),this,SLOT(onResult( KIO::Job* )));
+ }
+
+ ExitJobOperation::~ExitJobOperation()
+ {
+ }
+
+ void ExitJobOperation::onResult(KIO::Job* )
+ {
+ operationFinished(this);
+ }
+
+}
+#include "exitoperation.moc"
diff --git a/libktorrent/interfaces/exitoperation.h b/libktorrent/interfaces/exitoperation.h
new file mode 100644
index 0000000..edaa2fa
--- /dev/null
+++ b/libktorrent/interfaces/exitoperation.h
@@ -0,0 +1,67 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 KTEXITOPERATION_H
+#define KTEXITOPERATION_H
+
+#include <qobject.h>
+#include <kio/job.h>
+
+namespace kt
+{
+
+ /**
+ * @author Joris Guisson <[email protected]>
+ *
+ * Object to derive from for operations which need to be performed at exit.
+ * The operation should emit the operationFinished signal when they are done.
+ *
+ * ExitOperation's can be used in combination with a WaitJob, to wait for a certain amount of time
+ * to give serveral ExitOperation's the time time to finish up.
+ */
+ class ExitOperation : public QObject
+ {
+ Q_OBJECT
+ public:
+ ExitOperation();
+ virtual ~ExitOperation();
+
+ /// wether or not we can do a deleteLater on the job after it has finished.
+ virtual bool deleteAllowed() const {return true;}
+ signals:
+ void operationFinished(kt::ExitOperation* opt);
+ };
+
+ /**
+ * Exit operation which waits for a KIO::Job
+ */
+ class ExitJobOperation : public ExitOperation
+ {
+ Q_OBJECT
+ public:
+ ExitJobOperation(KIO::Job* j);
+ virtual ~ExitJobOperation();
+
+ virtual bool deleteAllowed() const {return false;}
+ private slots:
+ virtual void onResult(KIO::Job* j);
+ };
+}
+
+#endif
diff --git a/libktorrent/interfaces/filetreediritem.cpp b/libktorrent/interfaces/filetreediritem.cpp
new file mode 100644
index 0000000..b294015
--- /dev/null
+++ b/libktorrent/interfaces/filetreediritem.cpp
@@ -0,0 +1,295 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 <kglobal.h>
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kmimetype.h>
+#include <util/functions.h>
+#include <interfaces/functions.h>
+#include <torrent/globals.h>
+#include "filetreediritem.h"
+#include "filetreeitem.h"
+#include "torrentfileinterface.h"
+#include <torrent/torrentfile.h>
+
+using namespace bt;
+
+namespace kt
+{
+
+ FileTreeDirItem::FileTreeDirItem(KListView* klv,const QString & name,FileTreeRootListener* rl)
+ : QCheckListItem(klv,QString::null,QCheckListItem::CheckBox),name(name),root_listener(rl)
+ {
+ parent = 0;
+ size = 0;
+ setPixmap(0,KGlobal::iconLoader()->loadIcon("folder",KIcon::Small));
+ setText(0,name);
+ setText(1,BytesToString(size));
+ setText(2,i18n("Yes"));
+ manual_change = true;
+ setOn(true);
+ manual_change = false;
+ }
+
+ FileTreeDirItem::FileTreeDirItem(FileTreeDirItem* parent,const QString & name)
+ : QCheckListItem(parent,QString::null,QCheckListItem::CheckBox),
+ name(name),parent(parent)
+ {
+ size = 0;
+ setPixmap(0,KGlobal::iconLoader()->loadIcon("folder",KIcon::Small));
+ setText(0,name);
+ setText(1,BytesToString(size));
+ setText(2,i18n("Yes"));
+ manual_change = true;
+ setOn(true);
+ manual_change = false;
+ }
+
+ FileTreeDirItem::~FileTreeDirItem()
+ {
+ }
+
+ void FileTreeDirItem::insert(const QString & path,kt::TorrentFileInterface & file)
+ {
+ size += file.getSize();
+ setText(1,BytesToString(size));
+ int p = path.find(bt::DirSeparator());
+ if (p == -1)
+ {
+ children.insert(path,newFileTreeItem(path,file));
+ }
+ else
+ {
+ QString subdir = path.left(p);
+ FileTreeDirItem* sd = subdirs.find(subdir);
+ if (!sd)
+ {
+ sd = newFileTreeDirItem(subdir);
+ subdirs.insert(subdir,sd);
+ }
+
+ sd->insert(path.mid(p+1),file);
+ }
+ }
+
+ void FileTreeDirItem::setAllChecked(bool on,bool keep_data)
+ {
+ if (!manual_change)
+ {
+ manual_change = true;
+ setOn(on);
+ manual_change = false;
+ }
+ // first set all the child items
+ bt::PtrMap<QString,FileTreeItem>::iterator i = children.begin();
+ while (i != children.end())
+ {
+ i->second->setChecked(on,keep_data);
+ i++;
+ }
+
+ // then recursivly move on to subdirs
+ bt::PtrMap<QString,FileTreeDirItem>::iterator j = subdirs.begin();
+ while (j != subdirs.end())
+ {
+ j->second->setAllChecked(on,keep_data);
+ j++;
+ }
+ }
+
+
+ void FileTreeDirItem::invertChecked()
+ {
+ // first set all the child items
+ bt::PtrMap<QString,FileTreeItem>::iterator i = children.begin();
+ while (i != children.end())
+ {
+ FileTreeItem* item = i->second;
+ item->setChecked(!item->isOn());
+ i++;
+ }
+
+ // then recursivly move on to subdirs
+ bt::PtrMap<QString,FileTreeDirItem>::iterator j = subdirs.begin();
+ while (j != subdirs.end())
+ {
+ j->second->invertChecked();
+ j++;
+ }
+ }
+
+ void FileTreeDirItem::stateChange(bool on)
+ {
+ if (!manual_change)
+ {
+ if (on)
+ {
+ setAllChecked(true);
+ }
+ else
+ {
+ switch (confirmationDialog())
+ {
+ case KEEP_DATA:
+ setAllChecked(false,true);
+ break;
+ case THROW_AWAY_DATA:
+ setAllChecked(false,false);
+ break;
+ case CANCELED:
+ default:
+ manual_change = true;
+ setOn(true);
+ manual_change = false;
+ return;
+ }
+ }
+ if (parent)
+ parent->childStateChange();
+ }
+ setText(2,on ? i18n("Yes") : i18n("No"));
+ }
+
+ Uint64 FileTreeDirItem::bytesToDownload() const
+ {
+ Uint64 tot = 0;
+ // first check all the child items
+ bt::PtrMap<QString,FileTreeItem>::const_iterator i = children.begin();
+ while (i != children.end())
+ {
+ const FileTreeItem* item = i->second;
+ tot += item->bytesToDownload();
+ i++;
+ }
+
+ // then recursivly move on to subdirs
+ bt::PtrMap<QString,FileTreeDirItem>::const_iterator j = subdirs.begin();
+ while (j != subdirs.end())
+ {
+ tot += j->second->bytesToDownload();
+ j++;
+ }
+ return tot;
+ }
+
+ bool FileTreeDirItem::allChildrenOn()
+ {
+ // first check all the child items
+ bt::PtrMap<QString,FileTreeItem>::iterator i = children.begin();
+ while (i != children.end())
+ {
+ FileTreeItem* item = i->second;
+ if (!item->isOn())
+ return false;
+ i++;
+ }
+
+ // then recursivly move on to subdirs
+ bt::PtrMap<QString,FileTreeDirItem>::iterator j = subdirs.begin();
+ while (j != subdirs.end())
+ {
+ if (!j->second->allChildrenOn())
+ return false;
+ j++;
+ }
+ return true;
+ }
+
+ void FileTreeDirItem::childStateChange()
+ {
+ // only set this dir on if all children are on
+ manual_change = true;
+ setOn(allChildrenOn());
+ manual_change = false;
+
+ if (parent)
+ parent->childStateChange();
+ else if (root_listener)
+ root_listener->treeItemChanged();
+
+ }
+
+ int FileTreeDirItem::compare(QListViewItem* i, int col, bool ascending) const
+ {
+ if (col == 1)
+ {
+ FileTreeDirItem* other = dynamic_cast<FileTreeDirItem*>(i);
+ if (!other)
+ return 0;
+ else
+ return (int)(size - other->size);
+ }
+ else
+ {
+ //return QCheckListItem::compare(i, col, ascending);
+ // case insensitive comparison
+ return QString::compare(text(col).lower(),i->text(col).lower());
+ }
+ }
+
+ TorrentFileInterface & FileTreeDirItem::findTorrentFile(QListViewItem* item)
+ {
+ // first check all the child items
+ TorrentFileInterface & nullfile = (TorrentFileInterface &)TorrentFile::null;
+ bt::PtrMap<QString,FileTreeItem>::iterator i = children.begin();
+ while (i != children.end())
+ {
+ FileTreeItem* file = i->second;
+ if (file == (FileTreeItem*)item)
+ return file->getTorrentFile();
+ i++;
+ }
+
+ // then recursivly move on to subdirs
+ bt::PtrMap<QString,FileTreeDirItem>::iterator j = subdirs.begin();
+ while (j != subdirs.end())
+ {
+ TorrentFileInterface & thefile = j->second->findTorrentFile(item);
+ if(!thefile.isNull())
+ return thefile;
+ j++;
+ }
+ return nullfile;
+ }
+
+ FileTreeItem* FileTreeDirItem::newFileTreeItem(const QString & name,TorrentFileInterface & file)
+ {
+ return new FileTreeItem(this,name,file);
+ }
+
+ FileTreeDirItem* FileTreeDirItem::newFileTreeDirItem(const QString & subdir)
+ {
+ return new FileTreeDirItem(this,subdir);
+ }
+
+ bt::ConfirmationResult FileTreeDirItem::confirmationDialog()
+ {
+ return bt::THROW_AWAY_DATA;
+ }
+
+ QString FileTreeDirItem::getPath() const
+ {
+ if (!parent)
+ return bt::DirSeparator();
+ else
+ return parent->getPath() + name + bt::DirSeparator();
+ }
+}
+
diff --git a/libktorrent/interfaces/filetreediritem.h b/libktorrent/interfaces/filetreediritem.h
new file mode 100644
index 0000000..00650f2
--- /dev/null
+++ b/libktorrent/interfaces/filetreediritem.h
@@ -0,0 +1,140 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 KTFILETREEDIRITEM_H
+#define KTFILETREEDIRITEM_H
+
+#include <klistview.h>
+#include <util/constants.h>
+#include <util/ptrmap.h>
+
+namespace kt
+{
+ using namespace bt;
+
+ class FileTreeItem;
+ class TorrentFileInterface;
+ class TorrentInterface;
+
+ class FileTreeRootListener
+ {
+ public:
+ /// An item in the file tree has changed his state
+ virtual void treeItemChanged() = 0;
+ };
+
+ /**
+ * @author Joris Guisson
+ *
+ * Directory item the file tree showing the files in a multifile torrent
+ */
+ class FileTreeDirItem : public QCheckListItem
+ {
+ protected:
+ QString name;
+ Uint64 size;
+ bt::PtrMap<QString,FileTreeItem> children;
+ bt::PtrMap<QString,FileTreeDirItem> subdirs;
+ FileTreeDirItem* parent;
+ bool manual_change;
+ FileTreeRootListener* root_listener;
+ public:
+ FileTreeDirItem(KListView* klv,const QString & name,FileTreeRootListener* rl = 0);
+ FileTreeDirItem(FileTreeDirItem* parent,const QString & name);
+ virtual ~FileTreeDirItem();
+
+ /// Get the path of the directory (if this is the root directory / will be returned)
+ QString getPath() const;
+
+ /**
+ * Recursively insert a TorrentFileInterface.
+ * @param path Path of file
+ * @param file File itself
+ */
+ void insert(const QString & path,kt::TorrentFileInterface & file);
+
+ /**
+ * Recursivly walk the tree to find the TorrentFile which
+ * is shown by a QListViewItem (which should be an FileTreeItem).
+ * If item can't be found or item is an FileTreeDirItem, a reference to
+ * TorrentFile::null will be returned. In which case the isNull() function
+ * of TorrentFile will return true
+ * @param item Pointer to the QListViewItem
+ * @return A reference to the TorrentFile
+ */
+ kt::TorrentFileInterface & findTorrentFile(QListViewItem* item);
+
+ /**
+ * Set all items checked or not.
+ * @param on true everything checked, false everything not checked
+ * @param keep_data In case of unchecking keep the data or not
+ */
+ void setAllChecked(bool on,bool keep_data = false);
+
+ /**
+ * Invert all items, checked items become unchecked and unchecked become checked.
+ */
+ void invertChecked();
+
+ /**
+ * Called by the child to notify the parent it's state has changed.
+ */
+ void childStateChange();
+
+ FileTreeDirItem* getParent() {return parent;}
+
+ /// Recusively get the total number of bytes to download
+ Uint64 bytesToDownload() const;
+
+ protected:
+ /**
+ * Can be overrided by subclasses, so they can use their own
+ * custom FileTreeItem's. Will be called in insert.
+ * @param name Name of the file
+ * @param file The TorrentFileInterface
+ * @return A newly created FileTreeItem
+ */
+ virtual FileTreeItem* newFileTreeItem(const QString & name,
+ TorrentFileInterface & file);
+
+
+ /**
+ * Can be overrided by subclasses, so they can use their own
+ * custom FileTreeDirItem's. Will be called in insert.
+ * @param subdir The name of the subdir
+ * @return A newly created FileTreeDirItem
+ */
+ virtual FileTreeDirItem* newFileTreeDirItem(const QString & subdir);
+
+
+ /**
+ * Subclasses should override this if they want to show a confirmation dialog.
+ * @return What to do (i.e. keep the data, get rid of it or do nothing
+ */
+ virtual bt::ConfirmationResult confirmationDialog();
+
+ private:
+ virtual void stateChange(bool on);
+ virtual int compare(QListViewItem* i, int col, bool ascending) const;
+ bool allChildrenOn();
+ };
+
+}
+
+#endif
diff --git a/libktorrent/interfaces/filetreeitem.cpp b/libktorrent/interfaces/filetreeitem.cpp
new file mode 100644
index 0000000..32f265c
--- /dev/null
+++ b/libktorrent/interfaces/filetreeitem.cpp
@@ -0,0 +1,182 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 <kglobal.h>
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kmimetype.h>
+#include <interfaces/functions.h>
+#include <torrent/globals.h>
+#include "filetreeitem.h"
+#include "filetreediritem.h"
+#include "torrentfileinterface.h"
+
+using namespace bt;
+
+namespace kt
+{
+
+ FileTreeItem::FileTreeItem(FileTreeDirItem* item,const QString & name,kt::TorrentFileInterface & file)
+ : QCheckListItem(item,QString::null,QCheckListItem::CheckBox),name(name),file(file)
+ {
+ parent = item;
+ manual_change = false;
+ init();
+ }
+
+ FileTreeItem::~FileTreeItem()
+ {
+ }
+
+ void FileTreeItem::setChecked(bool on,bool keep_data)
+ {
+ manual_change = true;
+ setOn(on);
+ manual_change = false;
+
+ if (!on)
+ {
+ if (keep_data)
+ file.setPriority(ONLY_SEED_PRIORITY);
+ else
+ file.setDoNotDownload(true);
+ }
+ else
+ {
+ if (file.getPriority() == ONLY_SEED_PRIORITY)
+ file.setPriority(NORMAL_PRIORITY);
+ else
+ file.setDoNotDownload(false);
+ }
+
+ updatePriorityText();
+ parent->childStateChange();
+ }
+
+ void FileTreeItem::updatePriorityText()
+ {
+ switch(file.getPriority())
+ {
+ case FIRST_PRIORITY:
+ setText(2,i18n("Yes, First"));
+ break;
+ case LAST_PRIORITY:
+ setText(2,i18n("Yes, Last"));
+ break;
+ case EXCLUDED:
+ case ONLY_SEED_PRIORITY:
+ setText(2,i18n("No"));
+ break;
+ case PREVIEW_PRIORITY:
+ break;
+ default:
+ setText(2,i18n("Yes"));
+ break;
+ }
+ }
+
+ void FileTreeItem::init()
+ {
+ manual_change = true;
+ if (file.doNotDownload() || file.getPriority() == ONLY_SEED_PRIORITY)
+ setOn(false);
+ else
+ setOn(true);
+ manual_change = false;
+ setText(0,name);
+ setText(1,BytesToString(file.getSize()));
+ updatePriorityText();
+ setPixmap(0,KMimeType::findByPath(name)->pixmap(KIcon::Small));
+ }
+
+ void FileTreeItem::stateChange(bool on)
+ {
+ if (manual_change)
+ {
+ updatePriorityText();
+ return;
+ }
+
+ if (!on)
+ {
+ switch (confirmationDialog())
+ {
+ case KEEP_DATA:
+ file.setPriority(ONLY_SEED_PRIORITY);
+ break;
+ case THROW_AWAY_DATA:
+ file.setDoNotDownload(true);
+ break;
+ case CANCELED:
+ default:
+ manual_change = true;
+ setOn(true);
+ manual_change = false;
+ return;
+ }
+ }
+ else
+ {
+ if (file.getPriority() == ONLY_SEED_PRIORITY)
+ file.setPriority(NORMAL_PRIORITY);
+ else
+ file.setDoNotDownload(false);
+
+ }
+
+ updatePriorityText();
+ parent->childStateChange();
+ }
+
+ int FileTreeItem::compare(QListViewItem* i, int col, bool ascending) const
+ {
+ if (col == 1)
+ {
+ FileTreeItem* other = dynamic_cast<FileTreeItem*>(i);
+ if (!other)
+ return 0;
+ else
+ return (int)(file.getSize() - other->file.getSize());
+ }
+ else
+ {
+ // lets sort case insensitive
+ return QString::compare(text(col).lower(),i->text(col).lower());
+ // QCheckListItem::compare(i, col, ascending);
+ }
+ }
+
+
+ ConfirmationResult FileTreeItem::confirmationDialog()
+ {
+ if (file.isPreExistingFile())
+ return KEEP_DATA;
+ else
+ return THROW_AWAY_DATA;
+ }
+
+ Uint64 FileTreeItem::bytesToDownload() const
+ {
+ if (file.doNotDownload())
+ return 0;
+ else
+ return file.getSize();
+ }
+
+}
diff --git a/libktorrent/interfaces/filetreeitem.h b/libktorrent/interfaces/filetreeitem.h
new file mode 100644
index 0000000..6f9f1b1
--- /dev/null
+++ b/libktorrent/interfaces/filetreeitem.h
@@ -0,0 +1,91 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 KTFILETREEITEM_H
+#define KTFILETREEITEM_H
+
+#include <klistview.h>
+#include <util/constants.h>
+
+using namespace bt;
+
+namespace kt
+{
+ class TorrentFileInterface;
+ class TorrentInterface;
+ class FileTreeDirItem;
+
+
+
+ /**
+ * @author Joris Guisson
+ *
+ * File item part of a tree which shows the files in a multifile torrent.
+ * This is derived from QCheckListItem, if the user checks or unchecks the box,
+ * wether or not to download a file will be changed.
+ */
+ class FileTreeItem : public QCheckListItem
+ {
+ protected:
+ QString name;
+ TorrentFileInterface & file;
+ FileTreeDirItem* parent;
+ bool manual_change;
+ public:
+ /**
+ * Constructor, set the parent, name and file
+ * @param item Parent item
+ * @param name Name of file
+ * @param file THe TorrentFileInterface
+ * @return
+ */
+ FileTreeItem(FileTreeDirItem* item,const QString & name,TorrentFileInterface & file);
+ virtual ~FileTreeItem();
+
+ /// Get a reference to the TorrentFileInterface
+ TorrentFileInterface & getTorrentFile() {return file;}
+
+ /**
+ * Set the box checked or not.
+ * @param on Checked or not
+ * @param keep_data In case of unchecking keep the data or not
+ */
+ void setChecked(bool on,bool keep_data = false);
+
+ /// Get the number of bytes to download in this file
+ Uint64 bytesToDownload() const;
+
+
+ private:
+ void init();
+ virtual void stateChange(bool on);
+ void updatePriorityText();
+
+ protected:
+ virtual int compare(QListViewItem* i, int col, bool ascending) const;
+
+ /**
+ * Subclasses should override this if they want to show a confirmation dialog.
+ * @return What to do (i.e. keep the data, get rid of it or do nothing
+ */
+ virtual bt::ConfirmationResult confirmationDialog();
+ };
+}
+
+#endif
diff --git a/libktorrent/interfaces/functions.cpp b/libktorrent/interfaces/functions.cpp
new file mode 100644
index 0000000..2c6286f
--- /dev/null
+++ b/libktorrent/interfaces/functions.cpp
@@ -0,0 +1,62 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 <qdatetime.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include "functions.h"
+
+using namespace bt;
+
+namespace kt
+{
+
+
+ QString BytesToString(Uint64 bytes,int precision)
+ {
+ KLocale* loc = KGlobal::locale();
+ if (bytes >= 1024 * 1024 * 1024)
+ return i18n("%1 GB").arg(loc->formatNumber(bytes / TO_GIG,precision < 0 ? 2 : precision));
+ else if (bytes >= 1024*1024)
+ return i18n("%1 MB").arg(loc->formatNumber(bytes / TO_MEG,precision < 0 ? 1 : precision));
+ else if (bytes >= 1024)
+ return i18n("%1 KB").arg(loc->formatNumber(bytes / TO_KB,precision < 0 ? 1 : precision));
+ else
+ return i18n("%1 B").arg(bytes);
+ }
+
+ QString KBytesPerSecToString(double speed,int precision)
+ {
+ KLocale* loc = KGlobal::locale();
+ return i18n("%1 KB/s").arg(loc->formatNumber(speed,precision));
+ }
+
+ QString DurationToString(Uint32 nsecs)
+ {
+ KLocale* loc = KGlobal::locale();
+ QTime t;
+ int ndays = nsecs / 86400;
+ t = t.addSecs(nsecs % 86400);
+ QString s = loc->formatTime(t,true,true);
+ if (ndays > 0)
+ s = i18n("1 day ","%n days ",ndays) + s;
+
+ return s;
+ }
+}
diff --git a/libktorrent/interfaces/functions.h b/libktorrent/interfaces/functions.h
new file mode 100644
index 0000000..1bf7178
--- /dev/null
+++ b/libktorrent/interfaces/functions.h
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 FUNCTIONS_H
+#define FUNCTIONS_H
+
+#include <qstring.h>
+#include <util/constants.h>
+
+namespace kt
+{
+ const double TO_KB = 1024.0;
+ const double TO_MEG = (1024.0 * 1024.0);
+ const double TO_GIG = (1024.0 * 1024.0 * 1024.0);
+
+ QString BytesToString(bt::Uint64 bytes,int precision = -1);
+ QString KBytesPerSecToString(double speed,int precision = 1);
+ QString DurationToString(bt::Uint32 nsecs);
+
+ template<class T> int CompareVal(T a,T b)
+ {
+ if (a < b)
+ return -1;
+ else if (a > b)
+ return 1;
+ else
+ return 0;
+ }
+}
+
+#endif
diff --git a/libktorrent/interfaces/guiinterface.cpp b/libktorrent/interfaces/guiinterface.cpp
new file mode 100644
index 0000000..8a87d90
--- /dev/null
+++ b/libktorrent/interfaces/guiinterface.cpp
@@ -0,0 +1,54 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 "guiinterface.h"
+#include "torrentinterface.h"
+
+namespace kt
+{
+
+ GUIInterface::GUIInterface()
+ {}
+
+
+ GUIInterface::~GUIInterface()
+ {}
+
+
+ void GUIInterface::notifyViewListeners(TorrentInterface* tc)
+ {
+ QPtrList<ViewListener>::iterator i = listeners.begin();
+ while (i != listeners.end())
+ {
+ ViewListener* vl = *i;
+ vl->currentTorrentChanged(tc);
+ i++;
+ }
+ }
+
+ void GUIInterface::addViewListener(ViewListener* vl)
+ {
+ listeners.append(vl);
+ }
+
+ void GUIInterface::removeViewListener(ViewListener* vl)
+ {
+ listeners.remove(vl);
+ }
+}
diff --git a/libktorrent/interfaces/guiinterface.h b/libktorrent/interfaces/guiinterface.h
new file mode 100644
index 0000000..a263bb6
--- /dev/null
+++ b/libktorrent/interfaces/guiinterface.h
@@ -0,0 +1,218 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 KTGUIINTERFACE_H
+#define KTGUIINTERFACE_H
+
+#include <qptrlist.h>
+
+class QWidget;
+class QIconSet;
+class QString;
+class KToolBar;
+class KProgress;
+
+namespace kt
+{
+ class PrefPageInterface;
+ class Plugin;
+ class TorrentInterface;
+ class GUIInterface;
+
+ enum Position
+ {
+ LEFT, ///< New widgets will be added to the left of the old
+ RIGHT, ///< New widgets will be added to the right of the old
+ ABOVE, ///< New widgets will be added above the old
+ BELOW ///< New widgets will be added below the old
+ };
+
+ /**
+ * Small interface for classes who want to know when
+ * current torrent in the gui changes.
+ */
+ class ViewListener
+ {
+ public:
+ ViewListener() {}
+ virtual ~ViewListener() {}
+
+ virtual void currentTorrentChanged(TorrentInterface* tc) = 0;
+ };
+
+ /**
+ * Plugins wanting to add closeable tabs, should implement this interface.
+ * That way they can be notified of close requests.
+ * Not providing this interface in addTabPage means the tab cannot be closed.
+ */
+ class CloseTabListener
+ {
+ public:
+ /// By default all tabs can be closed, but this can be overridden
+ virtual bool closeAllowed(QWidget* ) {return true;}
+
+ /// THe close button was pressed for this tab, please remove it from the GUI
+ virtual void tabCloseRequest(kt::GUIInterface* gui,QWidget* tab) = 0;
+ };
+
+ /**
+ * @author Joris Guisson
+ * @brief Interface to modify the GUI
+ *
+ * This interface allows plugins and others to modify the GUI.
+ */
+ class GUIInterface
+ {
+ QPtrList<ViewListener> listeners;
+ public:
+ GUIInterface();
+ virtual ~GUIInterface();
+
+
+ /// Add a view listener.
+ void addViewListener(ViewListener* vl);
+
+ /// Remove a view listener
+ void removeViewListener(ViewListener* vl);
+
+ /// Add a progress bar tot the status bar, if one is already present this will fail and return 0
+ virtual KProgress* addProgressBarToStatusBar() = 0;
+
+ /// Remove the progress bar from the status bar
+ virtual void removeProgressBarFromStatusBar(KProgress* p) = 0;
+
+ /**
+ * Add a new tab page to the GUI
+ * @param page The widget
+ * @param icon Icon for the tab
+ * @param caption Text on the tab
+ * @param ctl For closeable tabs this pointer should be set
+ */
+ virtual void addTabPage(QWidget* page,const QIconSet & icon,
+ const QString & caption,CloseTabListener* ctl = 0) = 0;
+
+ /**
+ * Remove a tab page, does nothing if the page
+ * isn't added. Does not delete the widget.
+ * @param page The page
+ */
+ virtual void removeTabPage(QWidget* page) = 0;
+
+ /**
+ * Add a page to the preference dialog.
+ * @param page The page
+ */
+ virtual void addPrefPage(PrefPageInterface* page) = 0;
+
+
+ /**
+ * Remove a page from the preference dialog.
+ * @param page The page
+ */
+ virtual void removePrefPage(PrefPageInterface* page) = 0;
+
+ /**
+ * Change the statusbar message.
+ * @param msg The new message
+ */
+ virtual void changeStatusbar(const QString& msg) = 0;
+
+ /**
+ * Merge the GUI of a plugin.
+ * @param p The Plugin
+ */
+ virtual void mergePluginGui(Plugin* p) = 0;
+
+ /**
+ * Remove the GUI of a plugin.
+ * @param p The Plugin
+ */
+ virtual void removePluginGui(Plugin* p) = 0;
+
+ /**
+ * Embed a widget in the view in the mainview.
+ * The view and the new widget will be separated by a separator.
+ * @param w The widget
+ * @param pos How the widget will be positioned against the already present widgets
+ */
+ virtual void addWidgetInView(QWidget* w,Position pos) = 0;
+
+ /**
+ * Remove a widget added with addWidgetInView.
+ * The widget will be reparented to 0.
+ * @param w The widget
+ */
+ virtual void removeWidgetFromView(QWidget* w) = 0;
+
+ /**
+ * Add a widget below the view.
+ * @param w The widget
+ * @param icon Name of icon to use
+ * @param caption The caption to use
+ */
+ virtual void addWidgetBelowView(QWidget* w,const QString & icon,const QString & caption) = 0;
+
+ /**
+ * Remove a widget, which was added below the view.
+ * @param w The widget
+ */
+ virtual void removeWidgetBelowView(QWidget* w) = 0;
+
+ enum ToolDock
+ {
+ DOCK_LEFT,
+ DOCK_RIGHT,
+ DOCK_BOTTOM
+ };
+
+ /**
+ * Add a tool widget.
+ * @param w The widget
+ * @param icon Name of icon to use
+ * @param caption The caption to use
+ * @param dock Where to dock the widget
+ */
+ virtual void addToolWidget(QWidget* w,const QString & icon,const QString & caption,ToolDock dock) = 0;
+
+ /**
+ * Remove a tool widget.
+ * @param w The widget
+ */
+ virtual void removeToolWidget(QWidget* w) = 0;
+
+ /// Get the current torrent.
+ virtual const TorrentInterface* getCurrentTorrent() const = 0;
+
+ /// Add a toolbar
+ virtual KToolBar* addToolBar(const char* name) = 0;
+
+ /// Remove a toolbar
+ virtual void removeToolBar(KToolBar* tb) = 0;
+
+ protected:
+ /**
+ * Notifies all view listeners of the change in the current downloading TorrentInterface
+ * @param tc Pointer to current TorrentInterface
+ */
+ void notifyViewListeners(TorrentInterface* tc);
+ };
+
+}
+
+#endif
diff --git a/libktorrent/interfaces/ipblockinginterface.cpp b/libktorrent/interfaces/ipblockinginterface.cpp
new file mode 100644
index 0000000..e92e24c
--- /dev/null
+++ b/libktorrent/interfaces/ipblockinginterface.cpp
@@ -0,0 +1,33 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 "ipblockinginterface.h"
+
+namespace kt
+{
+ IPBlockingInterface::IPBlockingInterface()
+ {}
+
+
+ IPBlockingInterface::~IPBlockingInterface()
+ {}
+}
+
+
diff --git a/libktorrent/interfaces/ipblockinginterface.h b/libktorrent/interfaces/ipblockinginterface.h
new file mode 100644
index 0000000..4054af9
--- /dev/null
+++ b/libktorrent/interfaces/ipblockinginterface.h
@@ -0,0 +1,48 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 IPBLOCKINGINTERFACE_H
+#define IPBLOCKINGINTERFACE_H
+
+class QString;
+
+namespace kt
+{
+ /**
+ * @author Ivan Vasic
+ * @brief Interface for IPBlocklist to communicate with IPBlockingPlugin
+ */
+ class IPBlockingInterface
+ {
+ public:
+ IPBlockingInterface();
+ virtual ~IPBlockingInterface();
+
+ /**
+ * This function checks if IP is listed in antip2p filter list.
+ * @return TRUE if IP should be blocked. FALSE otherwise
+ * @arg ip String representation of IP address.
+ */
+ virtual bool isBlockedIP(const QString& ip) = 0;
+
+ };
+}
+#endif
diff --git a/libktorrent/interfaces/logmonitorinterface.cpp b/libktorrent/interfaces/logmonitorinterface.cpp
new file mode 100644
index 0000000..df77a53
--- /dev/null
+++ b/libktorrent/interfaces/logmonitorinterface.cpp
@@ -0,0 +1,33 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 "logmonitorinterface.h"
+
+namespace kt
+{
+
+ LogMonitorInterface::LogMonitorInterface()
+ {}
+
+
+ LogMonitorInterface::~LogMonitorInterface()
+ {}
+
+
+}
diff --git a/libktorrent/interfaces/logmonitorinterface.h b/libktorrent/interfaces/logmonitorinterface.h
new file mode 100644
index 0000000..4fccb0e
--- /dev/null
+++ b/libktorrent/interfaces/logmonitorinterface.h
@@ -0,0 +1,50 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 KTLOGMONITORINTERFACE_H
+#define KTLOGMONITORINTERFACE_H
+
+class QString;
+
+namespace kt
+{
+
+ /**
+ * @author Joris Guisson
+ * @brief Interface for classes who which to receive which log messages are printed
+ *
+ * This class is an interface for all classes which want to know,
+ * what is written to the log.
+ */
+ class LogMonitorInterface
+ {
+ public:
+ LogMonitorInterface();
+ virtual ~LogMonitorInterface();
+
+ /**
+ * A line was written to the log file.
+ * @param line The line
+ */
+ virtual void message(const QString & line, unsigned int arg) = 0;
+ };
+
+}
+
+#endif
diff --git a/libktorrent/interfaces/monitorinterface.cpp b/libktorrent/interfaces/monitorinterface.cpp
new file mode 100644
index 0000000..d3d0c52
--- /dev/null
+++ b/libktorrent/interfaces/monitorinterface.cpp
@@ -0,0 +1,33 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 "monitorinterface.h"
+
+namespace kt
+{
+
+ MonitorInterface::MonitorInterface()
+ {}
+
+
+ MonitorInterface::~MonitorInterface()
+ {}
+
+
+}
diff --git a/libktorrent/interfaces/monitorinterface.h b/libktorrent/interfaces/monitorinterface.h
new file mode 100644
index 0000000..a199800
--- /dev/null
+++ b/libktorrent/interfaces/monitorinterface.h
@@ -0,0 +1,79 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 KTMONITORINTERFACE_H
+#define KTMONITORINTERFACE_H
+
+
+namespace kt
+{
+ class ChunkDownloadInterface;
+ class PeerInterface;
+
+ /**
+ * @author Joris Guisson
+ * @brief Interface for classes who want to monitor a TorrentInterface
+ *
+ * Classes who want to keep track of all peers currently connected for a given
+ * torrent and all chunks who are currently downloading can implement this interface.
+ */
+ class MonitorInterface
+ {
+ public:
+ MonitorInterface();
+ virtual ~MonitorInterface();
+
+ /**
+ * A peer has been added.
+ * @param peer The peer
+ */
+ virtual void peerAdded(kt::PeerInterface* peer) = 0;
+
+ /**
+ * A peer has been removed.
+ * @param peer The peer
+ */
+ virtual void peerRemoved(kt::PeerInterface* peer) = 0;
+
+ /**
+ * The download of a chunk has been started.
+ * @param cd The ChunkDownload
+ */
+ virtual void downloadStarted(kt::ChunkDownloadInterface* cd) = 0;
+
+ /**
+ * The download of a chunk has been stopped.
+ * @param cd The ChunkDownload
+ */
+ virtual void downloadRemoved(kt::ChunkDownloadInterface* cd) = 0;
+
+ /**
+ * The download has been stopped.
+ */
+ virtual void stopped() = 0;
+
+ /**
+ * The download has been deleted.
+ */
+ virtual void destroyed() = 0;
+ };
+
+}
+
+#endif
diff --git a/libktorrent/interfaces/peerinterface.cpp b/libktorrent/interfaces/peerinterface.cpp
new file mode 100644
index 0000000..a4ab246
--- /dev/null
+++ b/libktorrent/interfaces/peerinterface.cpp
@@ -0,0 +1,33 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 "peerinterface.h"
+
+namespace kt
+{
+
+ PeerInterface::PeerInterface()
+ {}
+
+
+ PeerInterface::~PeerInterface()
+ {}
+
+
+}
diff --git a/libktorrent/interfaces/peerinterface.h b/libktorrent/interfaces/peerinterface.h
new file mode 100644
index 0000000..f77d0f8
--- /dev/null
+++ b/libktorrent/interfaces/peerinterface.h
@@ -0,0 +1,91 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 KTPEERINTERFACE_H
+#define KTPEERINTERFACE_H
+
+#include <qstring.h>
+#include <util/constants.h>
+namespace kt
+{
+
+ /**
+ * @author Joris Guisson
+ * @brief Interface for a Peer
+ *
+ * This is the interface for a Peer, it allows other classes to
+ * get statistics about a Peer.
+ */
+ class PeerInterface
+ {
+ public:
+ PeerInterface();
+ virtual ~PeerInterface();
+
+ struct Stats
+ {
+ /// IP address of peer (dotted notation)
+ QString ip_address;
+ /// The client (Azureus, BitComet, ...)
+ QString client;
+ /// Download rate (bytes/s)
+ bt::Uint32 download_rate;
+ /// Upload rate (bytes/s)
+ bt::Uint32 upload_rate;
+ /// Choked or not
+ bool choked;
+ /// Snubbed or not (i.e. we haven't received a piece for a minute)
+ bool snubbed;
+ /// Percentage of file which the peer has
+ float perc_of_file;
+ /// Does this peer support DHT
+ bool dht_support;
+ /// Amount of data uploaded
+ bt::Uint64 bytes_uploaded;
+ /// Amount of data downloaded
+ bt::Uint64 bytes_downloaded;
+ /// Advanced choke algorithm score
+ double aca_score;
+ /// The evil flag is on when the peer has not choked us,
+ /// but has snubbed us and requests have timedout
+ bool evil;
+ /// Flag to indicate if this peer has an upload slot
+ bool has_upload_slot;
+ /// Wether or not this connection is encrypted
+ bool encrypted;
+ /// Number of upload requests queued
+ bt::Uint32 num_up_requests;
+ /// Number of outstanding download requests queued
+ bt::Uint32 num_down_requests;
+ /// Supports the fast extensions
+ bool fast_extensions;
+ /// Is this a peer on the local network
+ bool local;
+ /// Wether or not the peer supports the extension protocol
+ bool extension_protocol;
+ };
+
+ virtual const Stats & getStats() const = 0;
+
+ virtual void kill() = 0;
+ };
+
+}
+
+#endif
diff --git a/libktorrent/interfaces/peersource.cpp b/libktorrent/interfaces/peersource.cpp
new file mode 100644
index 0000000..18368b1
--- /dev/null
+++ b/libktorrent/interfaces/peersource.cpp
@@ -0,0 +1,64 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 "peersource.h"
+
+namespace kt
+{
+
+ PeerSource::PeerSource()
+ {}
+
+
+ PeerSource::~PeerSource()
+ {}
+
+ void PeerSource::completed()
+ {}
+
+ void PeerSource::manualUpdate()
+ {}
+
+ void PeerSource::aboutToBeDestroyed()
+ {}
+
+ void PeerSource::addPeer(const QString & ip,bt::Uint16 port,bool local)
+ {
+ PotentialPeer pp;
+ pp.ip = ip;
+ pp.port = port;
+ pp.local = local;
+ peers.append(pp);
+ }
+
+ bool PeerSource::takePotentialPeer(PotentialPeer & pp)
+ {
+ if (peers.count() > 0)
+ {
+ pp = peers.front();
+ peers.pop_front();
+ return true;
+ }
+ return false;
+ }
+
+
+
+}
+#include "peersource.moc"
diff --git a/libktorrent/interfaces/peersource.h b/libktorrent/interfaces/peersource.h
new file mode 100644
index 0000000..9c2b589
--- /dev/null
+++ b/libktorrent/interfaces/peersource.h
@@ -0,0 +1,118 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 KTPEERSOURCE_H
+#define KTPEERSOURCE_H
+
+#include <qobject.h>
+#include <qvaluelist.h>
+#include <util/constants.h>
+
+namespace bt
+{
+ class WaitJob;
+}
+
+namespace kt
+{
+ struct PotentialPeer
+ {
+ QString ip;
+ bt::Uint16 port;
+ bool local;
+
+ PotentialPeer() : port(0),local(false) {}
+ };
+
+ /**
+ * @author Joris Guisson <[email protected]>
+ *
+ * This class is the base class for all classes who which to provide potential peers
+ * for torrents. PeerSources should work independently and should emit a signal when they
+ * have peers ready.
+ */
+ class PeerSource : public QObject
+ {
+ Q_OBJECT
+ public:
+ PeerSource();
+ virtual ~PeerSource();
+
+
+
+ /**
+ * Take the first PotentialPeer from the list. The item
+ * is removed from the list.
+ * @param pp PotentialPeer struct to fill
+ * @return true If there was one available, false if not
+ */
+ bool takePotentialPeer(PotentialPeer & pp);
+
+ /**
+ * Add a peer to the list of peers.
+ * @param ip The ip
+ * @param port The port
+ * @param local Wether or not the peer is on the local network
+ */
+ void addPeer(const QString & ip,bt::Uint16 port,bool local = false);
+
+ public slots:
+ /**
+ * Start gathering peers.
+ */
+ virtual void start() = 0;
+
+ /**
+ * Stop gathering peers.
+ */
+ virtual void stop(bt::WaitJob* wjob = 0) = 0;
+
+ /**
+ * The torrent has finished downloading.
+ * This is optional and should be used by HTTP and UDP tracker sources
+ * to notify the tracker.
+ */
+ virtual void completed();
+
+ /**
+ * PeerSources wanting to implement a manual update, should implement this.
+ */
+ virtual void manualUpdate();
+
+ /**
+ * The source is about to be destroyed. Subclasses can override this
+ * to clean up some things.
+ */
+ virtual void aboutToBeDestroyed();
+ signals:
+ /**
+ * This signal should be emitted when a new batch of peers is ready.
+ * @param ps The PeerSource
+ */
+ void peersReady(kt::PeerSource* ps);
+
+
+ private:
+ /// List to keep the potential peers in.
+ QValueList<PotentialPeer> peers;
+ };
+
+}
+
+#endif
diff --git a/libktorrent/interfaces/plugin.cpp b/libktorrent/interfaces/plugin.cpp
new file mode 100644
index 0000000..6354985
--- /dev/null
+++ b/libktorrent/interfaces/plugin.cpp
@@ -0,0 +1,49 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 "plugin.h"
+
+namespace kt
+{
+
+ Plugin::Plugin(QObject *parent, const char* qt_name,const QStringList & /*args*/,
+ const QString & name,const QString & gui_name,const QString & author,
+ const QString & email,const QString & description,
+ const QString & icon)
+ : KParts::Plugin(parent,qt_name),
+ name(name),author(author),email(email),description(description),icon(icon),gui_name(gui_name)
+ {
+ core = 0;
+ gui = 0;
+ loaded = false;
+ }
+
+
+ Plugin::~Plugin()
+ {}
+
+ void Plugin::guiUpdate()
+ {
+ }
+
+ void Plugin::shutdown(bt::WaitJob* )
+ {
+ }
+}
+#include "plugin.moc"
diff --git a/libktorrent/interfaces/plugin.h b/libktorrent/interfaces/plugin.h
new file mode 100644
index 0000000..ac43fbc
--- /dev/null
+++ b/libktorrent/interfaces/plugin.h
@@ -0,0 +1,152 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 KTPLUGIN_H
+#define KTPLUGIN_H
+
+#include <ktversion.h>
+#include <kparts/plugin.h>
+
+namespace bt
+{
+ class WaitJob;
+}
+
+namespace kt
+{
+ class CoreInterface;
+ class GUIInterface;
+
+ /**
+ * @author Joris Guisson
+ * @brief Base class for all plugins
+ *
+ * This is the base class for all plugins. Plugins should implement
+ * the load and unload methods, any changes made in load must be undone in
+ * unload.
+ *
+ * It's also absolutely forbidden to do any complex initialization in the constructor
+ * (setting an int to 0 is ok, creating widgets isn't).
+ * Only the name, author and description may be set in the constructor.
+ */
+ class Plugin : public KParts::Plugin
+ {
+ Q_OBJECT
+ public:
+ /**
+ * Constructor, set the name of the plugin, the name and e-mail of the author and
+ * a short description of the plugin.
+ * @param name Name of plugin
+ * @param gui_name Name to display in GUI (i18n version of name)
+ * @param author Author of plugin
+ * @param mail E-mail address of author
+ * @param description What does the plugin do
+ * @param icon Name of the plugin's icon
+ */
+ Plugin(QObject *parent,const char* qt_name,const QStringList & args,
+ const QString & name,const QString & gui_name,const QString & author,
+ const QString & email,const QString & description,
+ const QString & icon);
+ virtual ~Plugin();
+
+ /**
+ * This gets called, when the plugin gets loaded by KTorrent.
+ * Any changes made here must be later made undone, when unload is
+ * called.
+ * Upon error a bt::Error should be thrown. And the plugin should remain
+ * in an uninitialized state. The Error contains an error message, which will
+ * get show to the user.
+ */
+ virtual void load() = 0;
+
+ /**
+ * Gets called when the plugin gets unloaded.
+ * Should undo anything load did.
+ */
+ virtual void unload() = 0;
+
+ /**
+ * For plugins who need to update something, the same time as the
+ * GUI updates.
+ */
+ virtual void guiUpdate();
+
+ /**
+ * This should be implemented by plugins who need finish of some stuff which might take some time.
+ * These operations must be finished or killed by a timeout before we can proceed with unloading the plugin.
+ * @param job The WaitJob which monitors the plugin
+ */
+ virtual void shutdown(bt::WaitJob* job);
+
+ const QString & getName() const {return name;}
+ const QString & getAuthor() const {return author;}
+ const QString & getEMailAddress() const {return email;}
+ const QString & getDescription() const {return description;}
+ const QString & getIcon() const {return icon;}
+ const QString & getGuiName() const {return gui_name;}
+
+ /// Get a pointer to the CoreInterface
+ CoreInterface* getCore() {return core;}
+
+ /// Get a const pointer to the CoreInterface
+ const CoreInterface* getCore() const {return core;}
+
+ /**
+ * Set the core, used by PluginManager to set the pointer
+ * to the core.
+ * @param c Pointer to the core
+ */
+ void setCore(CoreInterface* c) {core = c;}
+
+ /// Get a pointer to the CoreInterface
+ GUIInterface* getGUI() {return gui;}
+
+ /// Get a const pointer to the CoreInterface
+ const GUIInterface* getGUI() const {return gui;}
+
+ /**
+ * Set the core, used by PluginManager to set the pointer
+ * to the core.
+ * @param c Pointer to the core
+ */
+ void setGUI(GUIInterface* c) {gui = c;}
+
+ /// See if the plugin is loaded
+ bool isLoaded() const {return loaded;}
+
+ /// Check wether the plugin matches the version of KT
+ virtual bool versionCheck(const QString & version) const = 0;
+
+ private:
+ QString name;
+ QString author;
+ QString email;
+ QString description;
+ QString icon;
+ QString gui_name;
+ CoreInterface* core;
+ GUIInterface* gui;
+ bool loaded;
+
+ friend class PluginManager;
+ };
+
+}
+
+#endif
diff --git a/libktorrent/interfaces/prefpageinterface.cpp b/libktorrent/interfaces/prefpageinterface.cpp
new file mode 100644
index 0000000..b905f07
--- /dev/null
+++ b/libktorrent/interfaces/prefpageinterface.cpp
@@ -0,0 +1,32 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 "prefpageinterface.h"
+namespace kt
+{
+ PrefPageInterface::PrefPageInterface(const QString & name,const QString & header,
+ const QPixmap & pix)
+ : pixmap(pix),itemName(name),header(header)
+ {}
+
+
+ PrefPageInterface::~PrefPageInterface()
+ {}
+}
+
diff --git a/libktorrent/interfaces/prefpageinterface.h b/libktorrent/interfaces/prefpageinterface.h
new file mode 100644
index 0000000..7d4d6dc
--- /dev/null
+++ b/libktorrent/interfaces/prefpageinterface.h
@@ -0,0 +1,84 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 PREFPAGEINTERFACE_H
+#define PREFPAGEINTERFACE_H
+
+#include <qpixmap.h>
+
+class QWidget;
+
+namespace kt
+{
+ /**
+ * @author Ivan Vasic
+ * @brief Interface to add configuration dialog page.
+ *
+ * This interface allows plugins and others to add their own pages in Configuration dialog
+ */
+ class PrefPageInterface
+ {
+ public:
+ /**
+ * Constructor, set the name, header and pixmap
+ * @param name
+ * @param header
+ * @param pix
+ */
+ PrefPageInterface(const QString & name,const QString & header,const QPixmap & pix);
+ virtual ~PrefPageInterface();
+
+ const QString& getItemName() { return itemName; }
+ const QString& getHeader() { return header; }
+ const QPixmap& getPixmap() { return pixmap; }
+
+ /**
+ * Apply the changes that have been made in the
+ * pref page. If the settings the user gave isn't valid false should be returned.
+ * This will prevent the dialog from closing.
+ * @return true if the data validates, false otherwise
+ */
+ virtual bool apply() = 0;
+
+ /**
+ * Create the actual widget.
+ * @param parent The parent of the widget
+ */
+ virtual void createWidget(QWidget* parent)=0;
+
+ /**
+ * Update all data on the widget, gets called before
+ * the preference dialog gets shown.
+ */
+ virtual void updateData() = 0;
+
+ /// Delete the widget, gets called when the page gets removed.
+ virtual void deleteWidget() = 0;
+
+ private:
+ ///Used in IconList mode. You should prefer a pixmap with size 32x32 pixels
+ QPixmap pixmap;
+ ///String used in the list or as tab item name.
+ QString itemName;
+ ///Header text use in the list modes. Ignored in Tabbed mode. If empty, the item text is used instead.
+ QString header;
+ };
+}
+#endif
+
diff --git a/libktorrent/interfaces/torrentfileinterface.cpp b/libktorrent/interfaces/torrentfileinterface.cpp
new file mode 100644
index 0000000..4cca138
--- /dev/null
+++ b/libktorrent/interfaces/torrentfileinterface.cpp
@@ -0,0 +1,44 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 "torrentfileinterface.h"
+
+namespace kt
+{
+
+ TorrentFileInterface::TorrentFileInterface(const QString & path,Uint64 size)
+ : path(path),size(size),first_chunk(0),last_chunk(0),num_chunks_downloaded(0),
+ priority(NORMAL_PRIORITY),m_emitDlStatusChanged(true),preview(false)
+ {
+ preexisting = false;
+ }
+
+
+ TorrentFileInterface::~TorrentFileInterface()
+ {}
+
+ float TorrentFileInterface::getDownloadPercentage() const
+ {
+ Uint32 num = last_chunk - first_chunk + 1;
+ return 100.0f * (float)num_chunks_downloaded / num;
+ }
+}
+
+#include "torrentfileinterface.moc"
+
diff --git a/libktorrent/interfaces/torrentfileinterface.h b/libktorrent/interfaces/torrentfileinterface.h
new file mode 100644
index 0000000..430534c
--- /dev/null
+++ b/libktorrent/interfaces/torrentfileinterface.h
@@ -0,0 +1,131 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 KTTORRENTFILEINTERFACE_H
+#define KTTORRENTFILEINTERFACE_H
+
+#include <qobject.h>
+#include <qstring.h>
+#include <util/constants.h>
+
+namespace kt
+{
+ using bt::Uint32;
+ using bt::Uint64;
+ using bt::Priority;
+ using bt::PREVIEW_PRIORITY;
+ using bt::FIRST_PRIORITY;
+ using bt::NORMAL_PRIORITY;
+ using bt::LAST_PRIORITY;
+ using bt::EXCLUDED;
+
+ /**
+ * @author Joris Guisson
+ * @brief Interface for a file in a multifile torrent
+ *
+ * This class is the interface for a file in a multifile torrent.
+ */
+ class TorrentFileInterface : public QObject
+ {
+ Q_OBJECT
+ public:
+ /**
+ * Constructor, set the path and size.
+ * @param path The path
+ * @param size The size
+ */
+ TorrentFileInterface(const QString & path,Uint64 size);
+ virtual ~TorrentFileInterface();
+
+ /// Get the path of the file
+ QString getPath() const {return path;}
+
+ /// Get the size of the file
+ Uint64 getSize() const {return size;}
+
+ /// Get the index of the first chunk in which this file lies
+ Uint32 getFirstChunk() const {return first_chunk;}
+
+ /// Get the last chunk of the file
+ Uint32 getLastChunk() const {return last_chunk;}
+
+ /// See if the TorrentFile is null.
+ bool isNull() const {return path.isNull();}
+
+ /// Set wether we have to not download this file
+ virtual void setDoNotDownload(bool dnd) = 0;
+
+ /// Wether or not we have to not download this file
+ virtual bool doNotDownload() const = 0;
+
+ /// Checks if this file is multimedial
+ virtual bool isMultimedia() const = 0;
+
+ /// Gets the current priority of the torrent
+ virtual Priority getPriority() const {return priority;}
+
+ /// Sets the priority of the torrent
+ virtual void setPriority(Priority newpriority = NORMAL_PRIORITY) = 0;
+
+ /// Wheather to emit signal when dl status changes or not.
+ virtual void setEmitDownloadStatusChanged(bool show) = 0;
+
+ /// Emits signal dlStatusChanged. Use it only with FileSelectDialog!
+ virtual void emitDownloadStatusChanged() = 0;
+
+ /// Did this file exist before the torrent was loaded by KT
+ bool isPreExistingFile() const {return preexisting;}
+
+ /// Set wether this file is preexisting
+ void setPreExisting(bool pe) {preexisting = pe;}
+
+ /// Get the % of the file which is downloaded
+ float getDownloadPercentage() const;
+
+ /// See if preview is available
+ bool isPreviewAvailable() const {return preview;}
+
+ signals:
+ /**
+ * Emitted when the download percentage has been changed.
+ * @param p The new percentage
+ */
+ void downloadPercentageChanged(float p);
+
+ /**
+ * Emitted when the preview becomes available or not.
+ * @param available
+ */
+ void previewAvailable(bool available);
+
+ protected:
+ QString path;
+ Uint64 size;
+ Uint32 first_chunk;
+ Uint32 last_chunk;
+ Uint32 num_chunks_downloaded;
+ Priority priority;
+ bool preexisting;
+ bool m_emitDlStatusChanged;
+ bool preview;
+ };
+
+}
+
+#endif
diff --git a/libktorrent/interfaces/torrentinterface.cpp b/libktorrent/interfaces/torrentinterface.cpp
new file mode 100644
index 0000000..763bd55
--- /dev/null
+++ b/libktorrent/interfaces/torrentinterface.cpp
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 "torrentinterface.h"
+
+namespace kt
+{
+
+ float ShareRatio(const TorrentStats & stats)
+ {
+ if (stats.bytes_downloaded == 0)
+ return 0.0f;
+ else
+ return (float) stats.bytes_uploaded / (stats.bytes_downloaded /*+ stats.imported_bytes*/);
+ }
+
+
+ TorrentInterface::TorrentInterface()
+ {}
+
+
+ TorrentInterface::~TorrentInterface()
+ {}
+
+}
+
+#include "torrentinterface.moc"
diff --git a/libktorrent/interfaces/torrentinterface.h b/libktorrent/interfaces/torrentinterface.h
new file mode 100644
index 0000000..95d5766
--- /dev/null
+++ b/libktorrent/interfaces/torrentinterface.h
@@ -0,0 +1,509 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 KTTORRENTINTERFACE_H
+#define KTTORRENTINTERFACE_H
+
+#include <qobject.h>
+#include <util/constants.h>
+#include <interfaces/trackerslist.h>
+
+#include <kurl.h>
+
+namespace bt
+{
+ class BitSet;
+ class DataCheckerListener;
+ class SHA1Hash;
+ class WaitJob;
+ class PeerID;
+}
+
+namespace kt
+{
+ using bt::Uint32;
+ using bt::Uint64;
+
+ class MonitorInterface;
+ class TorrentFileInterface;
+ class PeerSource;
+
+ enum TorrentStatus
+ {
+ NOT_STARTED,
+ SEEDING_COMPLETE,
+ DOWNLOAD_COMPLETE,
+ SEEDING,
+ DOWNLOADING,
+ STALLED,
+ STOPPED,
+ ALLOCATING_DISKSPACE,
+ ERROR,
+ QUEUED,
+ CHECKING_DATA,
+ NO_SPACE_LEFT
+ };
+
+ enum TorrentStartResponse
+ {
+ START_OK,
+ USER_CANCELED,
+ NOT_ENOUGH_DISKSPACE,
+ MAX_SHARE_RATIO_REACHED,
+ BUSY_WITH_DATA_CHECK,
+ QM_LIMITS_REACHED // Max seeds or downloads reached
+ };
+
+ enum AutoStopReason
+ {
+ MAX_RATIO_REACHED,
+ MAX_SEED_TIME_REACHED
+ };
+
+ struct TorrentStats
+ {
+ /// The number of bytes imported (igore these for average speed)
+ Uint64 imported_bytes;
+ /// Total number of bytes downloaded.
+ Uint64 bytes_downloaded;
+ /// Total number of bytes uploaded.
+ Uint64 bytes_uploaded;
+ /// The number of bytes left (gets sent to the tracker)
+ Uint64 bytes_left;
+ /// The number of bytes left to download (bytes_left - excluded bytes)
+ Uint64 bytes_left_to_download;
+ /// total number of bytes in torrent
+ Uint64 total_bytes;
+ /// The total number of bytes which need to be downloaded
+ Uint64 total_bytes_to_download;
+ /// The download rate in bytes per sec
+ Uint32 download_rate;
+ /// The upload rate in bytes per sec
+ Uint32 upload_rate;
+ /// The number of peers we are connected to
+ Uint32 num_peers;
+ /// The number of chunks we are currently downloading
+ Uint32 num_chunks_downloading;
+ /// The total number of chunks
+ Uint32 total_chunks;
+ /// The number of chunks which have been downloaded
+ Uint32 num_chunks_downloaded;
+ /// Get the number of chunks which have been excluded
+ Uint32 num_chunks_excluded;
+ /// Get the number of chunks left
+ Uint32 num_chunks_left;
+ /// Size of each chunk
+ Uint32 chunk_size;
+ /// Total seeders in swarm
+ Uint32 seeders_total;
+ /// Num seeders connected to
+ Uint32 seeders_connected_to;
+ /// Total leechers in swarm
+ Uint32 leechers_total;
+ /// Num leechers connected to
+ Uint32 leechers_connected_to;
+ /// Status of the download
+ TorrentStatus status;
+ /// The status of the tracker
+ QString trackerstatus;
+ /// The number of bytes downloaded in this session
+ Uint64 session_bytes_downloaded;
+ /// The number of bytes uploaded in this session
+ Uint64 session_bytes_uploaded;
+ /// The number of bytes downloaded since the last started event, this gets sent to the tracker
+ Uint64 trk_bytes_downloaded;
+ /// The number of bytes upload since the last started event, this gets sent to the tracker
+ Uint64 trk_bytes_uploaded;
+ /// Name of the torrent
+ QString torrent_name;
+ /// Path of the dir or file where the data will get saved
+ QString output_path;
+ /// See if we are running
+ bool running;
+ /// See if the torrent has been started
+ bool started;
+ /// See if we are allowed to startup this torrent automatically.
+ bool autostart;
+ /// See if we have a multi file torrent
+ bool multi_file_torrent;
+ /// See if the torrent is stopped by error
+ bool stopped_by_error;
+ /// See if the download is completed
+ bool completed;
+ /// See if this torrent is controlled by user
+ bool user_controlled;
+ /// Maximum share ratio
+ float max_share_ratio;
+ /// Maximum seed time
+ float max_seed_time;
+ /// Private torrent (i.e. no use of DHT)
+ bool priv_torrent;
+ /// Number of corrupted chunks found since the last check
+ Uint32 num_corrupted_chunks;
+ };
+
+
+ struct DHTNode
+ {
+ QString ip;
+ bt::Uint16 port;
+ };
+
+ enum TorrentFeature
+ {
+ DHT_FEATURE,
+ UT_PEX_FEATURE // µTorrent peer exchange
+ };
+
+
+ /**
+ * @author Joris Guisson
+ * @brief Interface for an object which controls one torrent
+ *
+ * This class is the interface for an object which controls the
+ * up- and download of one torrent.
+ */
+ class TorrentInterface : public QObject
+ {
+ Q_OBJECT
+ public:
+ TorrentInterface();
+ virtual ~TorrentInterface();
+
+
+ /**
+ * Update the object, should be called periodically.
+ */
+ virtual void update() = 0;
+
+ /**
+ * Start the download of the torrent.
+ */
+ virtual void start() = 0;
+
+ /**
+ * Stop the download, closes all connections.
+ * @param user wether or not the user did this explicitly
+ * @param wjob WaitJob, used when KT is shutting down,
+ * so that we can wait for all stopped events to reach the tracker
+ */
+ virtual void stop(bool user,bt::WaitJob* wjob = 0) = 0;
+
+ /**
+ * Update the tracker, this should normally handled internally.
+ * We leave it public so that the user can do a manual announce.
+ */
+ virtual void updateTracker() = 0;
+
+ /// Get the torrent's statistics
+ const TorrentStats & getStats() const {return stats;}
+
+ /**
+ * Checks if torrent is multimedial and chunks needed for preview are downloaded
+ * @param start_chunk The index of starting chunk to check
+ * @param end_chunk The index of the last chunk to check
+ * In case of single torrent file defaults can be used (0,1)
+ **/
+ virtual bool readyForPreview(int start_chunk = 0, int end_chunk = 1) = 0;
+
+ /**
+ * Get the torX directory of this torrent. Temporary stuff like the index
+ * file get stored there.
+ */
+ virtual QString getTorDir() const = 0;
+
+ /// Get the data directory of this torrent
+ virtual QString getDataDir() const = 0;
+
+ /// Get a short error message
+ virtual QString getShortErrorMessage() const = 0;
+
+ /**
+ * Get the download running time of this torrent in seconds
+ * @return Uint32 - time in seconds
+ */
+ virtual Uint32 getRunningTimeDL() const = 0;
+
+ /**
+ * Get the upload running time of this torrent in seconds
+ * @return Uint32 - time in seconds
+ */
+ virtual Uint32 getRunningTimeUL() const = 0;
+
+ /**
+ * Change to a new data dir. If this fails
+ * we will fall back on the old directory.
+ * @param new_dir The new directory
+ * @return true upon succes
+ */
+ virtual bool changeDataDir(const QString & new_dir) = 0;
+
+ /**
+ * Change torrents output directory. If this fails we will fall back on the old directory.
+ * @param new_dir The new directory
+ * @param moveFiles Wheather to actually move the files or just change the directory without moving them.
+ * @return true upon success.
+ */
+ virtual bool changeOutputDir(const QString& new_dir, bool moveFiles = true) = 0;
+
+ /**
+ * Roll back the previous changeDataDir call.
+ * Does nothing if there was no previous changeDataDir call.
+ */
+ virtual void rollback() = 0;
+
+ /**
+ * Get a BitSet of the status of all Chunks
+ */
+ virtual const bt::BitSet & downloadedChunksBitSet() const = 0;
+
+ /**
+ * Get a BitSet of the availability of all Chunks
+ */
+ virtual const bt::BitSet & availableChunksBitSet() const = 0;
+
+ /**
+ * Get a BitSet of the excluded Chunks
+ */
+ virtual const bt::BitSet & excludedChunksBitSet() const = 0;
+
+ /**
+ * Get a bitset of only seed chunks
+ */
+ virtual const bt::BitSet & onlySeedChunksBitSet() const = 0;
+
+ /// Set the monitor
+ virtual void setMonitor(MonitorInterface* tmo) = 0;
+
+ /// Get the time to the next tracker update in seconds.
+ virtual Uint32 getTimeToNextTrackerUpdate() const = 0;
+
+ /// Get the number of files in a multifile torrent (0 if we do not have a multifile torrent)
+ virtual Uint32 getNumFiles() const = 0;
+
+ /**
+ * Get the index'th file of a multifile torrent
+ * @param index The index
+ * @return The TorrentFileInterface (isNull() will be true in case of error)
+ */
+ virtual TorrentFileInterface & getTorrentFile(Uint32 index) = 0;
+
+ ///Get a pointer to TrackersList object
+ virtual TrackersList* getTrackersList() = 0;
+
+ ///Get a pointer to TrackersList object
+ virtual const TrackersList* getTrackersList() const = 0;
+
+ ///Get the torrent queue number. Zero if not in queue
+ virtual int getPriority() const = 0;
+
+ ///Set the torrent queue number.
+ virtual void setPriority(int p) = 0;
+
+ /// Set the max share ratio
+ virtual void setMaxShareRatio(float ratio) = 0;
+
+ /// Get the max share ratio
+ virtual float getMaxShareRatio() const = 0;
+
+ /// Set the max seed time in hours (0 is no limit)
+ virtual void setMaxSeedTime(float hours) = 0;
+
+ /// Get the max seed time
+ virtual float getMaxSeedTime() const = 0;
+
+ /// Make a string of the current status
+ virtual QString statusToString() const = 0;
+
+ ///Is manual announce allowed?
+ virtual bool announceAllowed() = 0;
+
+
+ /**
+ * Returns estimated time left for finishing download. Returned value is in seconds.
+ * Uses TimeEstimator class to calculate this value.
+ */
+ virtual Uint32 getETA() = 0;
+
+ /**
+ * Verify the correctness of all data.
+ * @param lst The listener
+ * @param auto_import Wether or not this is an initial import
+ */
+ virtual void startDataCheck(bt::DataCheckerListener* lst,bool auto_import) = 0;
+
+ /**
+ * Data check has been finished, this should be called.
+ */
+ virtual void afterDataCheck() = 0;
+
+ /**
+ * Are we doing a data check on this torrent.
+ * @param finished This will be set to true if the data check is finished
+ */
+ virtual bool isCheckingData(bool & finished) const = 0;
+
+ /**
+ * Test all files and see if they are not missing.
+ * If so put them in a list
+ */
+ virtual bool hasMissingFiles(QStringList & sl) = 0;
+
+ /**
+ * Recreate missing files.
+ */
+ virtual void recreateMissingFiles() = 0;
+
+ /**
+ * Mark missing files as do not download.
+ */
+ virtual void dndMissingFiles() = 0;
+
+
+ /// Get the number of initial DHT nodes
+ virtual Uint32 getNumDHTNodes() const = 0;
+
+ /// Get a DHT node
+ virtual const DHTNode & getDHTNode(Uint32 i) const = 0;
+
+ /** Delete the data files of the torrent,
+ * they will be lost permanently
+ */
+ virtual void deleteDataFiles() = 0;
+
+ ///Checks if a seeding torrent has reached its maximum share ratio
+ virtual bool overMaxRatio() = 0;
+
+ /// Checks if a seeding torrent has reached it's max seed time
+ virtual bool overMaxSeedTime() = 0;
+
+ /// Handle an error
+ virtual void handleError(const QString & err) = 0;
+
+ /// Get the info_hash.
+ virtual const bt::SHA1Hash & getInfoHash() const = 0;
+
+ /**
+ * Add a new PeerSource
+ * @param ps
+ */
+ virtual void addPeerSource(PeerSource* ps) = 0;
+
+ /**
+ * Remove a nPeerSource
+ * @param ps
+ */
+ virtual void removePeerSource(PeerSource* ps) = 0;
+
+ /// Is a feature enabled
+ virtual bool isFeatureEnabled(TorrentFeature tf) = 0;
+
+ /// Disable or enable a feature
+ virtual void setFeatureEnabled(TorrentFeature tf,bool on) = 0;
+
+ /// Get our PeerID
+ virtual const bt::PeerID & getOwnPeerID() const = 0;
+
+ /// Set the traffic limits for this torrent
+ virtual void setTrafficLimits(Uint32 up,Uint32 down) = 0;
+
+ /// Get the traffic limits
+ virtual void getTrafficLimits(Uint32 & up,Uint32 & down) = 0;
+
+ /// Check if there is enough diskspace available for this torrent
+ virtual bool checkDiskSpace(bool emit_sig = true) = 0;
+
+ /// Are we in the process of moving files
+ virtual bool isMovingFiles() const = 0;
+ signals:
+ /**
+ * Emited when we have finished downloading.
+ * @param me The object who emitted the signal
+ */
+ void finished(kt::TorrentInterface* me);
+
+ /**
+ * Emited when a Torrent download is stopped by error
+ * @param me The object who emitted the signal
+ * @param msg Error message
+ */
+ void stoppedByError(kt::TorrentInterface* me, QString msg);
+
+ /**
+ * Emited when maximum share ratio for this torrent is changed
+ * @param me The object which emitted the signal.
+ */
+ void maxRatioChanged(kt::TorrentInterface* me);
+
+ /**
+ * Emited then torrent is stopped from seeding by KTorrent.
+ * Happens when torrent has reached maximum share ratio and maybe we'll add something more...
+ * @param me The object which emitted the signal.
+ */
+ void seedingAutoStopped(kt::TorrentInterface* me,kt::AutoStopReason reason);
+
+ /**
+ * Emitted just before the torrent is started, this should be used to do some
+ * checks on the files in the cache.
+ * @param me The torrent which emitted the signal
+ * @param ret The return value
+ */
+ void aboutToBeStarted(kt::TorrentInterface* me,bool & ret);
+
+ /**
+ * Emitted when missing files have been marked as dnd.
+ * The intention of this signal is to update the GUI.
+ * @param me The torrent which emitted the signal
+ */
+ void missingFilesMarkedDND(kt::TorrentInterface* me);
+
+ /**
+ * A corrupted chunk has been found during upload.
+ * @param me The torrent which emitted the signal
+ */
+ void corruptedDataFound(kt::TorrentInterface* me);
+
+ /**
+ * Disk is running out of space.
+ * @param me The torrent which emitted the signal
+ * @param toStop should this torrent be stopped or not
+ */
+ void diskSpaceLow(kt::TorrentInterface* me, bool toStop);
+
+ /**
+ * Torrent has been stopped
+ * @param me The torrent which emitted the signal
+ */
+ void torrentStopped(kt::TorrentInterface* me);
+
+ protected:
+ TorrentStats stats;
+ };
+
+
+ /**
+ * Calculates the share ratio of a torrent.
+ * @param stats The stats of the torrent
+ * @return The share ratio
+ */
+ float ShareRatio(const TorrentStats & stats);
+
+}
+
+#endif
diff --git a/libktorrent/interfaces/trackerslist.cpp b/libktorrent/interfaces/trackerslist.cpp
new file mode 100644
index 0000000..c119625
--- /dev/null
+++ b/libktorrent/interfaces/trackerslist.cpp
@@ -0,0 +1,51 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * 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 <torrent/torrent.h>
+#include "trackerslist.h"
+
+namespace kt
+{
+
+ TrackersList::TrackersList()
+ {
+ }
+
+
+ TrackersList::~TrackersList()
+ {
+ }
+
+ void TrackersList::merge(const bt::TrackerTier* first)
+ {
+ int tier = 1;
+ while (first)
+ {
+ KURL::List::const_iterator i = first->urls.begin();
+ while (i != first->urls.end())
+ {
+ addTracker(*i,true,tier);
+ i++;
+ }
+ tier++;
+ first = first->next;
+ }
+ }
+
+}
diff --git a/libktorrent/interfaces/trackerslist.h b/libktorrent/interfaces/trackerslist.h
new file mode 100644
index 0000000..55dc05e
--- /dev/null
+++ b/libktorrent/interfaces/trackerslist.h
@@ -0,0 +1,89 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Ivan Vasic *
+ * *
+ * 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 KTTRACKERSLIST_H
+#define KTTRACKERSLIST_H
+
+#include <kurl.h>
+
+namespace bt
+{
+ struct TrackerTier;
+}
+
+namespace kt
+{
+ /**
+ * @author Ivan Vasić <[email protected]>
+ *
+ * This interface is used to provide access to AnnounceList object which holds a list of available trackers for a torrent.
+ */
+ class TrackersList
+ {
+ public:
+ TrackersList();
+ virtual ~TrackersList();
+
+ /**
+ * Get the current tracker URL.
+ */
+ virtual KURL getTrackerURL() const = 0;
+
+ /**
+ * Gets a list of available trackers.
+ */
+ virtual KURL::List getTrackerURLs() = 0;
+
+ /**
+ * Adds a tracker URL to the list.
+ * @param url The URL
+ * @param custom Is it a custom tracker
+ * @param tier Which tier (or priority) the tracker has, tier 1 are
+ * the main trackers, tier 2 are backups ...
+ */
+ virtual void addTracker(KURL url, bool custom = true,int tier = 1) = 0;
+
+ /**
+ * Removes the tracker from the list.
+ * @param url - Tracker url.
+ */
+ virtual bool removeTracker(KURL url) = 0;
+
+ /**
+ * Sets the current tracker and does the announce.
+ * @param url - Tracker url.
+ */
+ virtual void setTracker(KURL url) = 0;
+
+ /**
+ * Restores the default tracker and does the announce.
+ */
+ virtual void restoreDefault() = 0;
+
+ /**
+ * Merge an other tracker list.
+ * @param first The first TrackerTier
+ */
+ void merge(const bt::TrackerTier* first);
+
+ };
+
+}
+
+#endif