summaryrefslogtreecommitdiffstats
path: root/apps/ktorrent/groups/groupmanager.h
blob: d988b703419050ddd4ea302012fdb896da033d56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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