diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 02:37:40 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 02:37:40 +0000 |
commit | 9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0 (patch) | |
tree | d088b5210e77d9fa91d954d8550e00e372b47378 /apps/ktorrent/groups | |
download | ktorrent-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 'apps/ktorrent/groups')
37 files changed, 2521 insertions, 0 deletions
diff --git a/apps/ktorrent/groups/Makefile.am b/apps/ktorrent/groups/Makefile.am new file mode 100644 index 0000000..c1c3308 --- /dev/null +++ b/apps/ktorrent/groups/Makefile.am @@ -0,0 +1,15 @@ +INCLUDES = -I$(srcdir)/../../../libktorrent $(all_includes) +METASOURCES = AUTO +libgroups_la_LDFLAGS = $(all_libraries) +noinst_LTLIBRARIES = libgroups.la +noinst_HEADERS = activedownloadsgroup.h activegroup.h activeuploadsgroup.h \ + allgroup.h downloadgroup.h group.h groupmanager.h groupview.h \ + inactivedownloadsgroup.h inactivegroup.h inactiveuploadsgroup.h queueddownloadsgroup.h \ + queueduploadsgroup.h torrentdrag.h torrentgroup.h uploadgroup.h userdownloadsgroup.h \ + useruploadsgroup.h +libgroups_la_SOURCES = activedownloadsgroup.cpp activegroup.cpp \ + activeuploadsgroup.cpp allgroup.cpp downloadgroup.cpp group.cpp groupmanager.cpp groupview.cpp \ + inactivedownloadsgroup.cpp inactivegroup.cpp inactiveuploadsgroup.cpp queueddownloadsgroup.cpp \ + queueduploadsgroup.cpp torrentdrag.cpp torrentgroup.cpp uploadgroup.cpp userdownloadsgroup.cpp \ + useruploadsgroup.cpp +KDE_CXXFLAGS = $(USE_EXCEPTIONS) $(USE_RTTI) diff --git a/apps/ktorrent/groups/activedownloadsgroup.cpp b/apps/ktorrent/groups/activedownloadsgroup.cpp new file mode 100644 index 0000000..e4dd02f --- /dev/null +++ b/apps/ktorrent/groups/activedownloadsgroup.cpp @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "activedownloadsgroup.h" + +#include <klocale.h> +#include <interfaces/torrentinterface.h> + +namespace kt +{ + ActiveDownloadsGroup::ActiveDownloadsGroup() + : Group(i18n("Active downloads"),DOWNLOADS_ONLY_GROUP) + { + setIconByName("down"); + } + + + ActiveDownloadsGroup::~ActiveDownloadsGroup() + {} + +} + +bool kt::ActiveDownloadsGroup::isMember(TorrentInterface * tor) +{ + if (!tor) + return false; + + const kt::TorrentStats& s = tor->getStats(); + + return s.running && !s.completed; +} + + diff --git a/apps/ktorrent/groups/activedownloadsgroup.h b/apps/ktorrent/groups/activedownloadsgroup.h new file mode 100644 index 0000000..de62493 --- /dev/null +++ b/apps/ktorrent/groups/activedownloadsgroup.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef ACTIVEDOWNLOADSGROUP_H +#define ACTIVEDOWNLOADSGROUP_H + +#include "group.h" + +namespace kt +{ + class TorrentInterface; + + /** + * Group for active downloads. + * @author Ivan Vasic <ivasic@gmail.com> + */ + + class ActiveDownloadsGroup : public Group + { + + public: + ActiveDownloadsGroup(); + virtual ~ActiveDownloadsGroup(); + + virtual bool isMember(TorrentInterface* tor); + + }; +} +#endif diff --git a/apps/ktorrent/groups/activegroup.cpp b/apps/ktorrent/groups/activegroup.cpp new file mode 100644 index 0000000..48a60ae --- /dev/null +++ b/apps/ktorrent/groups/activegroup.cpp @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "activegroup.h" + +#include <klocale.h> +#include <interfaces/torrentinterface.h> + +namespace kt +{ + +ActiveGroup::ActiveGroup() + : Group(i18n("Active torrents"),MIXED_GROUP) +{ + setIconByName("metacontact_online"); +} + + +ActiveGroup::~ActiveGroup() +{} + +} + +bool kt::ActiveGroup::isMember(TorrentInterface * tor) +{ + if(!tor) + return false; + + const kt::TorrentStats& s = tor->getStats(); + return s.running; +} + + diff --git a/apps/ktorrent/groups/activegroup.h b/apps/ktorrent/groups/activegroup.h new file mode 100644 index 0000000..73e2aef --- /dev/null +++ b/apps/ktorrent/groups/activegroup.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef ACTIVEGROUP_H +#define ACTIVEGROUP_H + +#include "group.h" + +namespace kt +{ + class TorrentInterface; + + /** + * Group for active torrents. + * @author Ivan Vasic <ivasic@gmail.com> + */ + + class ActiveGroup : public Group + { + + public: + ActiveGroup(); + virtual ~ActiveGroup(); + + virtual bool isMember(TorrentInterface* tor); + + }; +} +#endif diff --git a/apps/ktorrent/groups/activeuploadsgroup.cpp b/apps/ktorrent/groups/activeuploadsgroup.cpp new file mode 100644 index 0000000..aa50e97 --- /dev/null +++ b/apps/ktorrent/groups/activeuploadsgroup.cpp @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "activeuploadsgroup.h" + +#include <klocale.h> +#include <interfaces/torrentinterface.h> + +namespace kt +{ + + ActiveUploadsGroup::ActiveUploadsGroup() + : Group(i18n("Active uploads"), UPLOADS_ONLY_GROUP) + { + setIconByName("up"); + } + + + ActiveUploadsGroup::~ActiveUploadsGroup() + {} + +} + +bool kt::ActiveUploadsGroup::isMember(TorrentInterface * tor) +{ + if (!tor) + return false; + + const kt::TorrentStats& s = tor->getStats(); + + return s.running && s.completed; +} + + diff --git a/apps/ktorrent/groups/activeuploadsgroup.h b/apps/ktorrent/groups/activeuploadsgroup.h new file mode 100644 index 0000000..02fd468 --- /dev/null +++ b/apps/ktorrent/groups/activeuploadsgroup.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef ACTIVEUPLOADSGROUP_H +#define ACTIVEUPLOADSGROUP_H + +#include "group.h" + +namespace kt +{ + class TorrentInterface; + + /** + * Group for active uploads. + * @author Ivan Vasic <ivasic@gmail.com> + */ + + class ActiveUploadsGroup : public Group + { + + public: + ActiveUploadsGroup(); + virtual ~ActiveUploadsGroup(); + + virtual bool isMember(TorrentInterface* tor); + + }; +} +#endif diff --git a/apps/ktorrent/groups/allgroup.cpp b/apps/ktorrent/groups/allgroup.cpp new file mode 100644 index 0000000..eba5391 --- /dev/null +++ b/apps/ktorrent/groups/allgroup.cpp @@ -0,0 +1,41 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include <klocale.h> +#include "allgroup.h" + +namespace kt +{ + + AllGroup::AllGroup() : Group(i18n("All Torrents"),MIXED_GROUP) + { + setIconByName("folder"); + } + + + AllGroup::~AllGroup() + {} + + + bool AllGroup::isMember(TorrentInterface* tor) + { + return tor != 0; + } + +} diff --git a/apps/ktorrent/groups/allgroup.h b/apps/ktorrent/groups/allgroup.h new file mode 100644 index 0000000..399691b --- /dev/null +++ b/apps/ktorrent/groups/allgroup.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTALLGROUP_H +#define KTALLGROUP_H + +#include <group.h> + +namespace kt +{ + + /** + @author Joris Guisson <joris.guisson@gmail.com> + */ + class AllGroup : public Group + { + public: + AllGroup(); + virtual ~AllGroup(); + + virtual bool isMember(TorrentInterface* tor); + + }; + +} + +#endif diff --git a/apps/ktorrent/groups/downloadgroup.cpp b/apps/ktorrent/groups/downloadgroup.cpp new file mode 100644 index 0000000..085eb77 --- /dev/null +++ b/apps/ktorrent/groups/downloadgroup.cpp @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include <klocale.h> +#include <interfaces/torrentinterface.h> +#include "downloadgroup.h" + +namespace kt +{ + + DownloadGroup::DownloadGroup() : Group(i18n("Downloads"),DOWNLOADS_ONLY_GROUP) + { + setIconByName("down"); + } + + + DownloadGroup::~DownloadGroup() + {} + + + bool DownloadGroup::isMember(TorrentInterface* tor) + { + if (!tor) + return false; + + return !tor->getStats().completed; + } + +} diff --git a/apps/ktorrent/groups/downloadgroup.h b/apps/ktorrent/groups/downloadgroup.h new file mode 100644 index 0000000..959f74b --- /dev/null +++ b/apps/ktorrent/groups/downloadgroup.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTDOWNLOADGROUP_H +#define KTDOWNLOADGROUP_H + +#include <group.h> + +namespace kt +{ + + /** + @author Joris Guisson <joris.guisson@gmail.com> + */ + class DownloadGroup : public Group + { + public: + DownloadGroup(); + virtual ~DownloadGroup(); + + virtual bool isMember(TorrentInterface* tor); + + }; + +} + +#endif diff --git a/apps/ktorrent/groups/group.cpp b/apps/ktorrent/groups/group.cpp new file mode 100644 index 0000000..b8441a7 --- /dev/null +++ b/apps/ktorrent/groups/group.cpp @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include <kiconloader.h> +#include <kglobal.h> +#include "group.h" + +namespace kt +{ + + Group::Group(const QString & name,int flags) : name(name),flags(flags) + {} + + + Group::~Group() + {} + + void Group::save(bt::BEncoder*) + { + } + + void Group::load(bt::BDictNode* ) + { + } + + void Group::setIconByName(const QString & in) + { + icon_name = in; + icon = KGlobal::iconLoader()->loadIcon(in,KIcon::Small); + } + + void Group::rename(const QString & nn) + { + name = nn; + } + + void Group::torrentRemoved(TorrentInterface* ) + {} + + void Group::removeTorrent(TorrentInterface* ) + {} + + void Group::addTorrent(TorrentInterface* ) + {} +} diff --git a/apps/ktorrent/groups/group.h b/apps/ktorrent/groups/group.h new file mode 100644 index 0000000..e1fa7ab --- /dev/null +++ b/apps/ktorrent/groups/group.h @@ -0,0 +1,133 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTGROUP_H +#define KTGROUP_H + +#include <qstring.h> +#include <qpixmap.h> + +namespace bt +{ + class BEncoder; + class BDictNode; +} + +namespace kt +{ + class TorrentInterface; + + /** + * @author Joris Guisson <joris.guisson@gmail.com> + * + * Base class for all groups. Subclasses should only implement the + * isMember function, but can also provide save and load + * functionality. + */ + class Group + { + protected: + QString name; + QPixmap icon; + QString icon_name; + int flags; + public: + enum Properties + { + UPLOADS_ONLY_GROUP = 1, + DOWNLOADS_ONLY_GROUP = 2, + MIXED_GROUP = 3, + CUSTOM_GROUP = 4 + }; + /** + * Create a new group. + * @param name The name of the group + * @param flags Properties of the group + */ + Group(const QString & name,int flags); + virtual ~Group(); + + /// See if this is a standard group. + bool isStandardGroup() const {return !(flags & CUSTOM_GROUP);} + + /// Get the group flags + int groupFlags() const {return flags;} + + /** + * Rename the group. + * @param nn The new name + */ + void rename(const QString & nn); + + /** + * Set the group icon by name. + * @param in The icon name + */ + void setIconByName(const QString & in); + + /// Get the name of the group + const QString & groupName() const {return name;} + + /// Get the icon of the group + const QPixmap & groupIcon() const {return icon;} + + /** + * Save the torrents.The torrents should be save in a bencoded file. + * @param enc The BEncoder + */ + virtual void save(bt::BEncoder* enc); + + + /** + * Load the torrents of the group from a BDictNode. + * @param n The BDictNode + */ + virtual void load(bt::BDictNode* n); + + + /** + * Test if a torrent is a member of this group. + * @param tor The torrent + */ + virtual bool isMember(TorrentInterface* tor) = 0; + + /** + * The torrent has been removed and is about to be deleted. + * Subclasses should make sure that they don't have dangling + * pointers to this torrent. + * @param tor The torrent + */ + virtual void torrentRemoved(TorrentInterface* tor); + + /** + * Subclasses should implement this, if they want to have torrents added to them. + * @param tor The torrent + */ + virtual void addTorrent(TorrentInterface* tor); + + /** + * Subclasses should implement this, if they want to have torrents removed from them. + * @param tor The torrent + */ + virtual void removeTorrent(TorrentInterface* tor); + }; + +} + +#endif diff --git a/apps/ktorrent/groups/groupmanager.cpp b/apps/ktorrent/groups/groupmanager.cpp new file mode 100644 index 0000000..b6a84c4 --- /dev/null +++ b/apps/ktorrent/groups/groupmanager.cpp @@ -0,0 +1,221 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include <util/log.h> +#include <util/file.h> +#include <util/fileops.h> +#include <util/error.h> +#include <torrent/bnode.h> +#include <torrent/bdecoder.h> +#include <torrent/bencoder.h> +#include "groupmanager.h" +#include "torrentgroup.h" +#include "allgroup.h" +#include "downloadgroup.h" +#include "uploadgroup.h" +#include "torrentgroup.h" +#include "queueddownloadsgroup.h" +#include "queueduploadsgroup.h" +#include "userdownloadsgroup.h" +#include "useruploadsgroup.h" +#include "inactivegroup.h" +#include "inactivedownloadsgroup.h" +#include "inactiveuploadsgroup.h" +#include "activegroup.h" +#include "activedownloadsgroup.h" +#include "activeuploadsgroup.h" + +using namespace bt; + +namespace kt +{ + + GroupManager::GroupManager() + { + setAutoDelete(true); + default_groups.setAutoDelete(true); + + Group* g = new AllGroup(); + default_groups.insert(g->groupName(),g); + + g = new UploadGroup(); + default_groups.insert(g->groupName(),g); + + g = new DownloadGroup(); + default_groups.insert(g->groupName(),g); + + g = new QueuedDownloadsGroup(); + default_groups.insert(g->groupName(),g); + + g = new QueuedUploadsGroup(); + default_groups.insert(g->groupName(),g); + + g = new UserDownloadsGroup(); + default_groups.insert(g->groupName(),g); + + g = new UserUploadsGroup(); + default_groups.insert(g->groupName(),g); + + g = new ActiveGroup(); + default_groups.insert(g->groupName(),g); + + g = new ActiveUploadsGroup(); + default_groups.insert(g->groupName(),g); + + g = new ActiveDownloadsGroup(); + default_groups.insert(g->groupName(),g); + + g = new InactiveGroup(); + default_groups.insert(g->groupName(),g); + + g = new InactiveUploadsGroup(); + default_groups.insert(g->groupName(),g); + + g = new InactiveDownloadsGroup(); + default_groups.insert(g->groupName(),g); + } + + + GroupManager::~GroupManager() + { + } + + + Group* GroupManager::newGroup(const QString & name) + { + if (find(name)) + return 0; + + Group* g = new TorrentGroup(name); + insert(name,g); + return g; + } + + bool GroupManager::canRemove(const Group* g) const + { + return default_groups.find(g->groupName()) == 0; + } + + + void GroupManager::saveGroups(const QString & fn) + { + bt::File fptr; + if (!fptr.open(fn,"wb")) + { + bt::Out() << "Cannot open " << fn << " : " << fptr.errorString() << bt::endl; + return; + } + + try + { + bt::BEncoder enc(&fptr); + + enc.beginList(); + for (iterator i = begin();i != end();i++) + { + i->second->save(&enc); + } + enc.end(); + } + catch (bt::Error & err) + { + bt::Out() << "Error : " << err.toString() << endl; + return; + } + } + + + + void GroupManager::loadGroups(const QString & fn) + { + bt::File fptr; + if (!fptr.open(fn,"rb")) + { + bt::Out() << "Cannot open " << fn << " : " << fptr.errorString() << bt::endl; + return; + } + try + { + Uint32 fs = bt::FileSize(fn); + QByteArray data(fs); + fptr.read(data.data(),fs); + + BDecoder dec(data,false); + bt::BNode* n = dec.decode(); + if (!n || n->getType() != bt::BNode::LIST) + throw bt::Error("groups file corrupt"); + + BListNode* ln = (BListNode*)n; + for (Uint32 i = 0;i < ln->getNumChildren();i++) + { + BDictNode* dn = ln->getDict(i); + if (!dn) + continue; + + TorrentGroup* g = new TorrentGroup("dummy"); + + try + { + g->load(dn); + } + catch (...) + { + delete g; + throw; + } + + if (!find(g->groupName())) + insert(g->groupName(),g); + else + delete g; + } + } + catch (bt::Error & err) + { + bt::Out() << "Error : " << err.toString() << endl; + return; + } + } + + void GroupManager::torrentRemoved(TorrentInterface* ti) + { + for (iterator i = begin(); i != end();i++) + { + i->second->torrentRemoved(ti); + } + } + + void GroupManager::renameGroup(const QString & old_name,const QString & new_name) + { + Group* g = find(old_name); + if (!g) + return; + + setAutoDelete(false); + erase(old_name); + g->rename(new_name); + insert(new_name,g); + setAutoDelete(true); + } + + Group* GroupManager::findDefault(const QString & name) + { + return default_groups.find(name); + } +} diff --git a/apps/ktorrent/groups/groupmanager.h b/apps/ktorrent/groups/groupmanager.h new file mode 100644 index 0000000..d988b70 --- /dev/null +++ b/apps/ktorrent/groups/groupmanager.h @@ -0,0 +1,132 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTGROUPMANAGER_H +#define KTGROUPMANAGER_H + +#include <qstring.h> +#include <klocale.h> +#include <util/ptrmap.h> + + +namespace kt +{ + class Group; + class TorrentInterface; + + /** + * @author Joris Guisson <joris.guisson@gmail.com> + * + * Manages all user created groups and the standard groups. + */ + class GroupManager : public bt::PtrMap<QString,Group> + { + bt::PtrMap<QString,Group> default_groups; + + public: + GroupManager(); + virtual ~GroupManager(); + + /** + * Create a new user created group. + * @param name Name of the group + * @return Pointer to the group or NULL, if another group already exists with the same name. + */ + Group* newGroup(const QString & name); + + /// Get the group off all torrents + Group* allGroup() {return findDefault(i18n("All Torrents"));} + + /// Get the group of downloads + Group* downloadGroup() {return findDefault(i18n("Downloads"));} + + /// Get the group of seeds + Group* uploadGroup() {return findDefault(i18n("Uploads"));} + + /// Get the group of queued downloads + Group* queuedDownloadsGroup() { return findDefault(i18n("Queued downloads")); } + + /// Get the group of queued seeds + Group* queuedUploadsGroup() { return findDefault(i18n("Queued uploads")); } + + /// Get the group of user controlled downloads + Group* userDownloadsGroup() { return findDefault(i18n("User downloads")); } + + /// Get the group of user controlled seeds + Group* userUploadsGroup() { return findDefault(i18n("User uploads")); } + + /// Get the group of inactive torrents + Group* inactiveGroup() { return findDefault(i18n("Inactive torrents")); } + + /// Get the group of inactive downloads + Group* inactiveDownloadsGroup() { return findDefault(i18n("Inactive downloads")); } + + /// Get the group of inactive uploads + Group* inactiveUploadsGroup() { return findDefault(i18n("Inactive uploads")); } + + /// Get the group of inactive torrents + Group* activeGroup() { return findDefault(i18n("Active torrents")); } + + /// Get the group of inactive downloads + Group* activeDownloadsGroup() { return findDefault(i18n("Active downloads")); } + + /// Get the group of inactive uploads + Group* activeUploadsGroup() { return findDefault(i18n("Active uploads")); } + + /// Find a default group by the given name + Group* findDefault(const QString & name); + + /** + * Save the groups to a file. + * @param fn The filename + */ + void saveGroups(const QString & fn); + + /** + * Load the groups from a file + * @param fn The filename + */ + void loadGroups(const QString & fn); + + /** + * See if we can remove a group. + * @param g The group + * @return true on any user created group, false on the standard ones + */ + bool canRemove(const Group* g) const; + + /** + * A torrent has been removed. This function checks all groups and + * removes the torrent from it. + * @param ti The torrent + */ + void torrentRemoved(TorrentInterface* ti); + + /** + * Rename a group. + * @param old_name The old name + * @param new_name The new name + */ + void renameGroup(const QString & old_name,const QString & new_name); + + }; + +} + +#endif diff --git a/apps/ktorrent/groups/groupview.cpp b/apps/ktorrent/groups/groupview.cpp new file mode 100644 index 0000000..3d0751f --- /dev/null +++ b/apps/ktorrent/groups/groupview.cpp @@ -0,0 +1,360 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include <klocale.h> +#include <kglobal.h> +#include <kiconloader.h> +#include <kpopupmenu.h> +#include <kaction.h> +#include <kmessagebox.h> +#include <kinputdialog.h> +#include <kstandarddirs.h> +#include <kpopupmenu.h> +#include <qheader.h> +#include <util/log.h> +#include <interfaces/torrentinterface.h> +#include "groupview.h" +#include "group.h" +#include "groupmanager.h" +#include "torrentgroup.h" +#include "../viewmanager.h" +#include "../ktorrentview.h" + + +using namespace bt; + +namespace kt +{ + GroupViewItem::GroupViewItem(GroupView* parent,Group* g) : KListViewItem(parent),gview(parent) + { + setText(0,g->groupName()); + setPixmap(0,g->groupIcon()); + } + + GroupViewItem::GroupViewItem(GroupView* gview,KListViewItem* parent,Group* g) : KListViewItem(parent),gview(gview) + { + setText(0,g->groupName()); + setPixmap(0,g->groupIcon()); + } + + GroupViewItem::~GroupViewItem() + { + } + + int GroupViewItem::compare(QListViewItem* i,int ,bool ) const + { + if (text(1).isNull() && i->text(1).isNull()) + return QString::compare(text(0),i->text(0)); + else + return QString::compare(text(1),i->text(1)); + } + + GroupView::GroupView(ViewManager* view,KActionCollection* col,QWidget *parent, const char *name) + : KListView(parent, name),view(view),custom_root(0) + { + setFullWidth(true); + setRootIsDecorated(true); + setAcceptDrops(true); + setDropHighlighter(true); + setDropVisualizer(true); + addColumn(i18n("Groups")); + header()->hide(); + + gman = new GroupManager(); + + current = gman->allGroup(); + + connect(this,SIGNAL(clicked(QListViewItem*)),this,SLOT(onExecuted( QListViewItem* ))); + connect(this,SIGNAL(contextMenu(KListView*,QListViewItem*,const QPoint & )), + this,SLOT(showContextMenu( KListView*, QListViewItem*, const QPoint& ))); + connect(this,SIGNAL(dropped(QDropEvent*,QListViewItem*)), + this,SLOT(onDropped( QDropEvent*, QListViewItem* ))); + + current_item = 0; + menu = 0; + createMenu(col); + save_file = KGlobal::dirs()->saveLocation("data","ktorrent") + "groups"; + GroupViewItem* all = addGroup(gman->allGroup(),0); + GroupViewItem* dwnld = addGroup(gman->downloadGroup(),all); + GroupViewItem* upld = addGroup(gman->uploadGroup(),all); + GroupViewItem* inactive = addGroup(gman->inactiveGroup(), all); + GroupViewItem* active = addGroup(gman->activeGroup(), all); + addGroup(gman->queuedDownloadsGroup(), dwnld); + addGroup(gman->queuedUploadsGroup(), upld); + addGroup(gman->userDownloadsGroup(), dwnld); + addGroup(gman->userUploadsGroup(), upld); + addGroup(gman->inactiveDownloadsGroup(), inactive); + addGroup(gman->inactiveUploadsGroup(), inactive); + addGroup(gman->activeDownloadsGroup(), active); + addGroup(gman->activeUploadsGroup(), active); + + custom_root = new KListViewItem(all,i18n("Custom Groups")); + custom_root->setPixmap(0,KGlobal::iconLoader()->loadIcon("folder",KIcon::Small)); + setOpen(custom_root,true); + } + + + GroupView::~GroupView() + { + delete gman; + } + + void GroupView::saveGroups() + { + gman->saveGroups(save_file); + } + + void GroupView::loadGroups() + { + // load the groups from the groups file + gman->loadGroups(save_file); + for (GroupManager::iterator i = gman->begin();i != gman->end();i++) + { + addGroup(i->second,custom_root); + } + sort(); + } + + void GroupView::createMenu(KActionCollection* col) + { + menu = new KPopupMenu(this); + + new_group = new KAction(i18n("New Group"),"filenew",0, + this, SLOT(addGroup()),col, "New Group"); + + edit_group = new KAction(i18n("Edit Name"),"edit",0, + this, SLOT(editGroupName()),col,"Edit Group Name"); + + remove_group = new KAction(i18n("Remove Group"),"remove",0, + this, SLOT(removeGroup()),col,"Remove Group"); + + open_in_new_tab = new KAction(i18n("Open Tab"),"fileopen",0, + this,SLOT(openView()),col,"Open Tab"); + + open_in_new_tab->plug(menu); + menu->insertSeparator(); + new_group->plug(menu); + edit_group->plug(menu); + remove_group->plug(menu); + } + + void GroupView::addGroup() + { + QString name = KInputDialog::getText(QString::null,i18n("Please enter the group name.")); + + if (name.isNull() || name.length() == 0) + return; + + if (gman->find(name)) + { + KMessageBox::error(this,i18n("The group %1 already exists.").arg(name)); + return; + } + + addGroup(gman->newGroup(name),custom_root); + saveGroups(); + sort(); + } + + void GroupView::removeGroup() + { + if (!current_item) + return; + + Group* g = groups.find(current_item); + if (!g) + return; + + groupRemoved(g); + if (g == current) + { + current = gman->allGroup(); + currentGroupChanged(current); + } + + groups.erase(current_item); + gman->erase(g->groupName()); + delete current_item; + current_item = 0; + saveGroups(); + } + + void GroupView::editGroupName() + { + if (!current_item) + return; + + Group* g = groups.find(current_item); + if (!g) + return; + + QString name = KInputDialog::getText(QString::null,i18n("Please enter the new group name."),g->groupName()); + + if (name.isNull() || name.length() == 0) + return; + + if (g->groupName() == name) + return; + + if (gman->find(name)) + { + KMessageBox::error(this,i18n("The group %1 already exists.").arg(name)); + } + else + { + gman->renameGroup(g->groupName(),name); + current_item->setText(0,name); + groupRenamed(g); + saveGroups(); + sort(); + } + } + + GroupViewItem* GroupView::addGroup(Group* g,KListViewItem* parent) + { + GroupViewItem* li = 0; + if (parent) + { + li = new GroupViewItem(this,parent,g); + } + else + { + li = new GroupViewItem(this,g); + li->setText(1,g->groupName()); + } + + groups.insert(li,g); + if (custom_root && custom_root->childCount() == 1 && custom_root == parent) + setOpen(custom_root,true); + + return li; + } + + void GroupView::showContextMenu(KListView* ,QListViewItem* item,const QPoint & p) + { + current_item = dynamic_cast<GroupViewItem*>(item); + + Group* g = 0; + if (current_item) + g = groups.find(current_item); + + if (!g ||!gman->canRemove(g)) + { + edit_group->setEnabled(false); + remove_group->setEnabled(false); + } + else + { + edit_group->setEnabled(true); + remove_group->setEnabled(true); + } + + open_in_new_tab->setEnabled(g != 0); + + menu->popup(p); + } + + void GroupView::onExecuted(QListViewItem* item) + { + if (!item) return; + + GroupViewItem* li = dynamic_cast<GroupViewItem*>(item); + if (!li) + return; + + Group* g = groups.find(li); + if (g) + { + current = g; + currentGroupChanged(g); + } + } + + void GroupView::onDropped(QDropEvent* e,QListViewItem *after) + { + GroupViewItem* li = dynamic_cast<GroupViewItem*>(after); + if (!li) + return; + + TorrentGroup* g = dynamic_cast<TorrentGroup*>(groups.find(li)); + if (g) + { + QValueList<TorrentInterface*> sel; + view->getSelection(sel); + QValueList<TorrentInterface*>::iterator i = sel.begin(); + while (i != sel.end()) + { + g->add(*i); + i++; + } + saveGroups(); + } + } + + bool GroupView::acceptDrag(QDropEvent* event) const + { + return event->provides("application/x-ktorrent-drag-object"); + } + + void GroupView::onTorrentRemoved(kt::TorrentInterface* tc) + { + gman->torrentRemoved(tc); + saveGroups(); + } + + void GroupView::updateGroupsSubMenu(KPopupMenu* gsm) + { + gsm->clear(); + for (GroupManager::iterator i = gman->begin();i != gman->end();i++) + { + gsm->insertItem(i->first); + } + } + + void GroupView::onGroupsSubMenuItemActivated(KTorrentView* v,const QString & group) + { + Group* g = gman->find(group); + if (g) + { + v->addSelectionToGroup(g); + saveGroups(); + } + } + + const Group* GroupView::findGroup(const QString & name) const + { + Group* g = gman->find(name); + if (!g) + g = gman->findDefault(name); + + return g; + } + + void GroupView::openView() + { + if (!current_item) + return; + + Group* g = groups.find(current_item); + if (g) + openNewTab(g); + } +} + +#include "groupview.moc" diff --git a/apps/ktorrent/groups/groupview.h b/apps/ktorrent/groups/groupview.h new file mode 100644 index 0000000..de5befb --- /dev/null +++ b/apps/ktorrent/groups/groupview.h @@ -0,0 +1,125 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTGROUPVIEW_H +#define KTGROUPVIEW_H + +#include <klistview.h> +#include <util/ptrmap.h> + +class KPopupMenu; +class KActionCollection; +class ViewManager; +class KTorrentView; + +namespace kt +{ + class Group; + class GroupView; + class GroupManager; + class TorrentInterface; + + class GroupViewItem : public KListViewItem + { + Group* g; + GroupView* gview; + public: + GroupViewItem(GroupView* parent,Group* g); + GroupViewItem(GroupView* gview,KListViewItem* parent,Group* g); + virtual ~GroupViewItem(); + + virtual int compare(QListViewItem* i,int col,bool ascending) const; + }; + + /** + @author Joris Guisson <joris.guisson@gmail.com> + */ + class GroupView : public KListView + { + Q_OBJECT + public: + GroupView(ViewManager* view,KActionCollection* col,QWidget *parent = 0, const char *name = 0); + virtual ~GroupView(); + + /// Get the current group + Group* currentGroup() {return current;} + + /// Save all groups + void saveGroups(); + + /// Load groups + void loadGroups(); + + /// Find a group by its name + const Group* findGroup(const QString & name) const; + + GroupManager* groupManager() const { return gman; } + + public slots: + void onTorrentRemoved(kt::TorrentInterface* tc); + + /// Update a groups sub menu + void updateGroupsSubMenu(KPopupMenu* gsm); + + /// An item was activated in the groups sub menu of a KTorrentView + void onGroupsSubMenuItemActivated(KTorrentView* v,const QString & group); + + private slots: + void onExecuted(QListViewItem* item); + void showContextMenu(KListView* ,QListViewItem* item,const QPoint & p); + void addGroup(); + void removeGroup(); + void editGroupName(); + void onDropped(QDropEvent* e,QListViewItem *after); + virtual bool acceptDrag(QDropEvent* event) const; + void openView(); + + + signals: + void currentGroupChanged(kt::Group* g); + void groupRenamed(kt::Group* g); + void openNewTab(kt::Group* g); + void groupRemoved(kt::Group* g); + + private: + void createMenu(KActionCollection* col); + GroupViewItem* addGroup(Group* g,KListViewItem* parent); + + private: + ViewManager* view; + KListViewItem* custom_root; + bt::PtrMap<GroupViewItem*,Group> groups; + GroupManager* gman; + QString save_file; + + Group* current; + + GroupViewItem* current_item; + KPopupMenu* menu; + KAction* new_group; + KAction* edit_group; + KAction* remove_group; + KAction* open_in_new_tab; + + friend class GroupViewItem; + }; + +} + +#endif diff --git a/apps/ktorrent/groups/inactivedownloadsgroup.cpp b/apps/ktorrent/groups/inactivedownloadsgroup.cpp new file mode 100644 index 0000000..b383160 --- /dev/null +++ b/apps/ktorrent/groups/inactivedownloadsgroup.cpp @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "inactivedownloadsgroup.h" + +#include <klocale.h> +#include <interfaces/torrentinterface.h> + +namespace kt +{ + + InactiveDownloadsGroup::InactiveDownloadsGroup() + : Group(i18n("Inactive downloads"), DOWNLOADS_ONLY_GROUP) + { + setIconByName("down"); + } + + + InactiveDownloadsGroup::~InactiveDownloadsGroup() + {} + +} + +bool kt::InactiveDownloadsGroup::isMember(TorrentInterface * tor) +{ + if (!tor) + return false; + + const kt::TorrentStats& s = tor->getStats(); + + return !s.running && !s.completed; +} + + diff --git a/apps/ktorrent/groups/inactivedownloadsgroup.h b/apps/ktorrent/groups/inactivedownloadsgroup.h new file mode 100644 index 0000000..4b80ca6 --- /dev/null +++ b/apps/ktorrent/groups/inactivedownloadsgroup.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef INACTIVEDOWNLOADSGROUP_H +#define INACTIVEDOWNLOADSGROUP_H + +#include "group.h" + +namespace kt +{ + class TorrentInterface; + + /** + * Group for inactive downloads. + * @author Ivan Vasic <ivasic@gmail.com> + */ + + class InactiveDownloadsGroup : public Group + { + + public: + InactiveDownloadsGroup(); + virtual ~InactiveDownloadsGroup(); + + virtual bool isMember(TorrentInterface* tor); + + }; +} +#endif diff --git a/apps/ktorrent/groups/inactivegroup.cpp b/apps/ktorrent/groups/inactivegroup.cpp new file mode 100644 index 0000000..3270697 --- /dev/null +++ b/apps/ktorrent/groups/inactivegroup.cpp @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "inactivegroup.h" + +#include <klocale.h> +#include <interfaces/torrentinterface.h> + +namespace kt +{ + +InactiveGroup::InactiveGroup() + : Group(i18n("Inactive torrents"),MIXED_GROUP) +{ + setIconByName("metacontact_offline"); +} + + +InactiveGroup::~InactiveGroup() +{} + +} + +bool kt::InactiveGroup::isMember(TorrentInterface * tor) +{ + if(!tor) + return false; + + const kt::TorrentStats& s = tor->getStats(); + return !s.running; +} + + diff --git a/apps/ktorrent/groups/inactivegroup.h b/apps/ktorrent/groups/inactivegroup.h new file mode 100644 index 0000000..027138f --- /dev/null +++ b/apps/ktorrent/groups/inactivegroup.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef INACTIVEGROUP_H +#define INACTIVEGROUP_H + +#include "group.h" + +namespace kt +{ + class TorrentInterface; + + /** + * Group for inactive torrents. + * @author Ivan Vasic <ivasic@gmail.com> + */ + + class InactiveGroup : public Group + { + + public: + InactiveGroup(); + virtual ~InactiveGroup(); + + virtual bool isMember(TorrentInterface* tor); + + }; +} +#endif diff --git a/apps/ktorrent/groups/inactiveuploadsgroup.cpp b/apps/ktorrent/groups/inactiveuploadsgroup.cpp new file mode 100644 index 0000000..8110a1a --- /dev/null +++ b/apps/ktorrent/groups/inactiveuploadsgroup.cpp @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "inactiveuploadsgroup.h" + +#include <klocale.h> +#include <interfaces/torrentinterface.h> + +namespace kt +{ + + InactiveUploadsGroup::InactiveUploadsGroup() + : Group(i18n("Inactive uploads"), UPLOADS_ONLY_GROUP) + { + setIconByName("up"); + } + + + InactiveUploadsGroup::~InactiveUploadsGroup() + {} + +} + +bool kt::InactiveUploadsGroup::isMember(TorrentInterface * tor) +{ + if (!tor) + return false; + + const kt::TorrentStats& s = tor->getStats(); + + return !s.running && s.completed; +} + + diff --git a/apps/ktorrent/groups/inactiveuploadsgroup.h b/apps/ktorrent/groups/inactiveuploadsgroup.h new file mode 100644 index 0000000..78e1840 --- /dev/null +++ b/apps/ktorrent/groups/inactiveuploadsgroup.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2007 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef INACTIVEUPLOADSGROUP_H +#define INACTIVEUPLOADSGROUP_H + +#include "group.h" + +namespace kt +{ + class TorrentInterface; + + /** + * Group for inactive uploads. + * @author Ivan Vasic <ivasic@gmail.com> + */ + + class InactiveUploadsGroup : public Group + { + + public: + InactiveUploadsGroup(); + virtual ~InactiveUploadsGroup(); + + virtual bool isMember(TorrentInterface* tor); + + }; +} +#endif diff --git a/apps/ktorrent/groups/queueddownloadsgroup.cpp b/apps/ktorrent/groups/queueddownloadsgroup.cpp new file mode 100644 index 0000000..c182472 --- /dev/null +++ b/apps/ktorrent/groups/queueddownloadsgroup.cpp @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "queueddownloadsgroup.h" + +#include <klocale.h> +#include <interfaces/torrentinterface.h> + +namespace kt +{ + + QueuedDownloadsGroup::QueuedDownloadsGroup() + : Group(i18n("Queued downloads"),DOWNLOADS_ONLY_GROUP) + { + setIconByName("ktqueuemanager"); + } + + + QueuedDownloadsGroup::~QueuedDownloadsGroup() + {} +} + +bool kt::QueuedDownloadsGroup::isMember(TorrentInterface* tor) +{ + if(!tor) + return false; + + const kt::TorrentStats& s = tor->getStats(); + + return !s.user_controlled && !s.completed; +} diff --git a/apps/ktorrent/groups/queueddownloadsgroup.h b/apps/ktorrent/groups/queueddownloadsgroup.h new file mode 100644 index 0000000..3e436a5 --- /dev/null +++ b/apps/ktorrent/groups/queueddownloadsgroup.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTQUEUEDDOWNLOADSGROUP_H +#define KTQUEUEDDOWNLOADSGROUP_H + +#include <group.h> + +namespace kt +{ + class TorrentInterface; + + /** + * Torrents that are queued and in downloading phase. + * @author Ivan Vasic <ivasic@gmail.com> + */ + class QueuedDownloadsGroup : public Group + { + public: + QueuedDownloadsGroup(); + virtual ~QueuedDownloadsGroup(); + + virtual bool isMember(TorrentInterface* tor); + }; + +} + +#endif diff --git a/apps/ktorrent/groups/queueduploadsgroup.cpp b/apps/ktorrent/groups/queueduploadsgroup.cpp new file mode 100644 index 0000000..8c346a4 --- /dev/null +++ b/apps/ktorrent/groups/queueduploadsgroup.cpp @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "queueduploadsgroup.h" + +#include <klocale.h> +#include <interfaces/torrentinterface.h> + +namespace kt +{ + + QueuedUploadsGroup::QueuedUploadsGroup() + : Group(i18n("Queued uploads"),UPLOADS_ONLY_GROUP) + { + setIconByName("ktqueuemanager"); + } + + + QueuedUploadsGroup::~QueuedUploadsGroup() + {} +} + +bool kt::QueuedUploadsGroup::isMember(TorrentInterface* tor) +{ + if(!tor) + return false; + + const kt::TorrentStats& s = tor->getStats(); + + return !s.user_controlled && s.completed; +} diff --git a/apps/ktorrent/groups/queueduploadsgroup.h b/apps/ktorrent/groups/queueduploadsgroup.h new file mode 100644 index 0000000..675da62 --- /dev/null +++ b/apps/ktorrent/groups/queueduploadsgroup.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTQUEUEDUPLOADSGROUP_H +#define KTQUEUEDUPLOADSGROUP_H + +#include <group.h> + +namespace kt +{ + class TorrentInterface; + + /** + * Torrents that are queued and in seeding phase. + * @author Ivan Vasic <ivasic@gmail.com> + */ + class QueuedUploadsGroup : public Group + { + public: + QueuedUploadsGroup(); + virtual ~QueuedUploadsGroup(); + + virtual bool isMember(TorrentInterface* tor); + }; + +} + +#endif diff --git a/apps/ktorrent/groups/torrentdrag.cpp b/apps/ktorrent/groups/torrentdrag.cpp new file mode 100644 index 0000000..fc7b366 --- /dev/null +++ b/apps/ktorrent/groups/torrentdrag.cpp @@ -0,0 +1,37 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include <kiconloader.h> +#include <kglobal.h> +#include "torrentdrag.h" + +namespace kt +{ + + TorrentDrag::TorrentDrag(QWidget* src, const char *name) : QStoredDrag("application/x-ktorrent-drag-object",src, name) + { + setPixmap(KGlobal::iconLoader()->loadIcon("player_playlist",KIcon::Small)); + } + + + TorrentDrag::~TorrentDrag() + {} + +} +#include "torrentdrag.moc" diff --git a/apps/ktorrent/groups/torrentdrag.h b/apps/ktorrent/groups/torrentdrag.h new file mode 100644 index 0000000..a926347 --- /dev/null +++ b/apps/ktorrent/groups/torrentdrag.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTTORRENTDRAG_H +#define KTTORRENTDRAG_H + +#include <qdragobject.h> + +namespace kt +{ + + + /** + @author Joris Guisson <joris.guisson@gmail.com> + */ + class TorrentDrag : public QStoredDrag + { + Q_OBJECT + public: + TorrentDrag(QWidget* src,const char *name = 0); + virtual ~TorrentDrag(); + + }; + +} + +#endif diff --git a/apps/ktorrent/groups/torrentgroup.cpp b/apps/ktorrent/groups/torrentgroup.cpp new file mode 100644 index 0000000..efb09a9 --- /dev/null +++ b/apps/ktorrent/groups/torrentgroup.cpp @@ -0,0 +1,147 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include <util/log.h> +#include <util/error.h> +#include <util/sha1hash.h> +#include <torrent/bencoder.h> +#include <torrent/bnode.h> +#include <interfaces/torrentinterface.h> +#include "torrentgroup.h" + +using namespace bt; + +namespace kt +{ + + TorrentGroup::TorrentGroup(const QString& name): Group(name,MIXED_GROUP|CUSTOM_GROUP) + { + setIconByName("player_playlist"); + } + + + TorrentGroup::~TorrentGroup() + {} + + + bool TorrentGroup::isMember(TorrentInterface* tor) + { + if (torrents.count(tor) > 0) + return true; + + + if (!hashes.empty()) + { + if (hashes.count(tor->getInfoHash())) + { + /* bt::Out(SYS_GEN|LOG_DEBUG) << + QString("TG %1 : Torrent %2 from hashes list").arg(groupName()).arg(tor->getStats().torrent_name) << endl; + */ + hashes.erase(tor->getInfoHash()); + torrents.insert(tor); + return true; + } + } + return false; + } + + void TorrentGroup::add(TorrentInterface* tor) + { + torrents.insert(tor); + } + + void TorrentGroup::remove(TorrentInterface* tor) + { + torrents.erase(tor); + } + + void TorrentGroup::save(bt::BEncoder* enc) + { + enc->beginDict(); + enc->write("name"); enc->write(name.local8Bit()); + enc->write("icon"); enc->write(icon_name.local8Bit()); + enc->write("hashes"); enc->beginList(); + std::set<TorrentInterface*>::iterator i = torrents.begin(); + while (i != torrents.end()) + { + TorrentInterface* tc = *i; + // write the info hash, because that will be unique for each torrent + const bt::SHA1Hash & h = tc->getInfoHash(); + enc->write(h.getData(),20); + i++; + } + std::set<bt::SHA1Hash>::iterator j = hashes.begin(); + while (j != hashes.end()) + { + enc->write(j->getData(),20); + j++; + } + enc->end(); + enc->end(); + } + + void TorrentGroup::load(bt::BDictNode* dn) + { + BValueNode* vn = dn->getValue("name"); + if (!vn || vn->data().getType() != bt::Value::STRING) + throw bt::Error("invalid or missing name"); + + QByteArray tmp = vn->data().toByteArray(); + name = QString::fromLocal8Bit(tmp.data(),tmp.size()); + + vn = dn->getValue("icon"); + if (!vn || vn->data().getType() != bt::Value::STRING) + throw bt::Error("invalid or missing icon"); + + tmp = vn->data().toByteArray(); + setIconByName(QString::fromLocal8Bit(tmp.data(),tmp.size())); + + BListNode* ln = dn->getList("hashes"); + if (!ln) + return; + + for (Uint32 i = 0;i < ln->getNumChildren();i++) + { + vn = ln->getValue(i); + if (!vn || vn->data().getType() != bt::Value::STRING) + continue; + + QByteArray ba = vn->data().toByteArray(); + if (ba.size() != 20) + continue; + + hashes.insert(SHA1Hash((const Uint8*)ba.data())); + } + } + + void TorrentGroup::torrentRemoved(TorrentInterface* tor) + { + torrents.erase(tor); + } + + void TorrentGroup::removeTorrent(TorrentInterface* tor) + { + torrents.erase(tor); + } + + void TorrentGroup::addTorrent(TorrentInterface* tor) + { + torrents.insert(tor); + } +} diff --git a/apps/ktorrent/groups/torrentgroup.h b/apps/ktorrent/groups/torrentgroup.h new file mode 100644 index 0000000..40989fd --- /dev/null +++ b/apps/ktorrent/groups/torrentgroup.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTTORRENTGROUP_H +#define KTTORRENTGROUP_H + +#include <set> +#include <group.h> +#include <util/sha1hash.h> + + +namespace kt +{ + class TorrentInterface; + + /** + @author Joris Guisson <joris.guisson@gmail.com> + */ + class TorrentGroup : public Group + { + std::set<TorrentInterface*> torrents; + std::set<bt::SHA1Hash> hashes; + public: + TorrentGroup(const QString& name); + virtual ~TorrentGroup(); + + virtual bool isMember(TorrentInterface* tor); + virtual void save(bt::BEncoder* enc); + virtual void load(bt::BDictNode* n); + virtual void torrentRemoved(TorrentInterface* tor); + virtual void removeTorrent(TorrentInterface* tor); + virtual void addTorrent(TorrentInterface* tor); + + void add(TorrentInterface* tor); + void remove(TorrentInterface* tor); + }; + +} + +#endif diff --git a/apps/ktorrent/groups/uploadgroup.cpp b/apps/ktorrent/groups/uploadgroup.cpp new file mode 100644 index 0000000..9baca6d --- /dev/null +++ b/apps/ktorrent/groups/uploadgroup.cpp @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include <klocale.h> +#include <interfaces/torrentinterface.h> +#include "uploadgroup.h" + +namespace kt +{ + + UploadGroup::UploadGroup() : Group(i18n("Uploads"),UPLOADS_ONLY_GROUP) + { + setIconByName("up"); + } + + + UploadGroup::~UploadGroup() + {} + + + bool UploadGroup::isMember(TorrentInterface* tor) + { + if (!tor) + return false; + + return tor->getStats().completed; + } + +} diff --git a/apps/ktorrent/groups/uploadgroup.h b/apps/ktorrent/groups/uploadgroup.h new file mode 100644 index 0000000..f90a5bd --- /dev/null +++ b/apps/ktorrent/groups/uploadgroup.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTUPLOADGROUP_H +#define KTUPLOADGROUP_H + +#include <group.h> + +namespace kt +{ + + /** + @author Joris Guisson <joris.guisson@gmail.com> + */ + class UploadGroup : public Group + { + public: + UploadGroup(); + virtual ~UploadGroup(); + + virtual bool isMember(TorrentInterface* tor); + + }; + +} + +#endif diff --git a/apps/ktorrent/groups/userdownloadsgroup.cpp b/apps/ktorrent/groups/userdownloadsgroup.cpp new file mode 100644 index 0000000..6a4960b --- /dev/null +++ b/apps/ktorrent/groups/userdownloadsgroup.cpp @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "userdownloadsgroup.h" + +#include <klocale.h> +#include <interfaces/torrentinterface.h> + +namespace kt +{ + + UserDownloadsGroup::UserDownloadsGroup() + : Group(i18n("User downloads"),DOWNLOADS_ONLY_GROUP) + { + setIconByName("userconfig"); + } + + + UserDownloadsGroup::~UserDownloadsGroup() + {} +} + +bool kt::UserDownloadsGroup::isMember(TorrentInterface* tor) +{ + if(!tor) + return false; + + const kt::TorrentStats& s = tor->getStats(); + + return s.user_controlled && !s.completed; +} diff --git a/apps/ktorrent/groups/userdownloadsgroup.h b/apps/ktorrent/groups/userdownloadsgroup.h new file mode 100644 index 0000000..a77e7ac --- /dev/null +++ b/apps/ktorrent/groups/userdownloadsgroup.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTUSERDOWNLOADSGROUP_H +#define KTUSERDOWNLOADSGROUP_H + +#include <group.h> + +namespace kt +{ + class TorrentInterface; + + /** + * Torrents that are user controlled and in downloading phase. + * @author Ivan Vasic <ivasic@gmail.com> + */ + class UserDownloadsGroup : public Group + { + public: + UserDownloadsGroup(); + virtual ~UserDownloadsGroup(); + + virtual bool isMember(TorrentInterface* tor); + }; + +} + +#endif diff --git a/apps/ktorrent/groups/useruploadsgroup.cpp b/apps/ktorrent/groups/useruploadsgroup.cpp new file mode 100644 index 0000000..d0e78bd --- /dev/null +++ b/apps/ktorrent/groups/useruploadsgroup.cpp @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "useruploadsgroup.h" + +#include <klocale.h> +#include <interfaces/torrentinterface.h> + +namespace kt +{ + + UserUploadsGroup::UserUploadsGroup() + : Group(i18n("User uploads"),UPLOADS_ONLY_GROUP) + { + setIconByName("userconfig"); + } + + + UserUploadsGroup::~UserUploadsGroup() + {} +} + +bool kt::UserUploadsGroup::isMember(TorrentInterface* tor) +{ + if(!tor) + return false; + + const kt::TorrentStats& s = tor->getStats(); + + return s.user_controlled && s.completed; +} diff --git a/apps/ktorrent/groups/useruploadsgroup.h b/apps/ktorrent/groups/useruploadsgroup.h new file mode 100644 index 0000000..9286c88 --- /dev/null +++ b/apps/ktorrent/groups/useruploadsgroup.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2006 by Ivan Vasić * + * ivasic@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef KTUSERUPLOADSGROUP_H +#define KTUSERUPLOADSGROUP_H + +#include <group.h> + +namespace kt +{ + class TorrentInterface; + + /** + * Torrents that are user controlled and in seeding phase. + * @author Ivan Vasic <ivasic@gmail.com> + */ + class UserUploadsGroup : public Group + { + public: + UserUploadsGroup(); + virtual ~UserUploadsGroup(); + + virtual bool isMember(TorrentInterface* tor); + }; + +} + +#endif |