1 /* This file is part of the KDE project
3 Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
15 #include <kio/netaccess.h>
20 #include "kget_export.h"
25 class TransferGroupHandler
;
26 class TransferTreeModel
;
29 * class TransferGroup:
31 * This class abstracts the concept of transfer group by means of which
32 * the user can sort his transfers into categories.
33 * By definition, we want each TransferGroup (transfer group) to be a JobQueue.
34 * Moreover this class calculates information such as:
35 * - the size obtained by the sum of all the transfer's size
36 * - the size obtained by the sum of all the transfer's processed size
37 * - the global progress percentage within the group
38 * - the global speed within the group
40 class KGET_EXPORT TransferGroup
: public JobQueue
46 // These flags respect the Model columns order
47 Gc_GroupName
= 0x00000001,
48 Gc_Status
= 0x00000002,
49 Gc_TotalSize
= 0x00000004,
50 Gc_Percent
= 0x00000008,
51 Gc_UploadSpeed
= 0x00000010,
52 Gc_DownloadSpeed
= 0x00000020,
54 Gc_ProcessedSize
= 0x00010000
57 typedef int ChangesFlags
;
59 TransferGroup(TransferTreeModel
* model
, Scheduler
* scheduler
, const QString
& name
=QString());
61 virtual ~TransferGroup();
64 * This function is reimplemented by JobQueue::setStatus
66 * @param queueStatus the new JobQueue status
68 void setStatus(Status queueStatus
);
71 * Appends a new transfer to the list of the transfers
73 * @param transfer the transfer to append
75 void append(Transfer
* transfer
);
78 * Prepends a new transfer to the list of the transfers
80 * @param transfer the transfer to prepend
82 void prepend(Transfer
* transfer
);
85 * inserts a transfer to the current group after the given transfer
87 * @param transfer The transfer to add in the current Group
88 * @param after The transfer after which to add the transfer
90 void insert(Transfer
* transfer
, Transfer
* after
);
93 * Removes the given transfer from the list of the transfers
95 * @param transfer the transfer to remove
97 void remove(Transfer
* transfer
);
100 * Moves a transfer in the list
102 * @param transfer The transfer to move. Note that this transfer can
103 * belong to other groups. In this situation this
104 * transfer is deleted from the previous group and
105 * moved inside this one.
106 * @param after The transfer after which we have to move the given one
108 void move(Transfer
* transfer
, Transfer
* after
);
111 * Finds the first transfer with source src
113 * @param src the url of the source location
115 * @return the transfer pointer if the transfer has been found. Otherwise
118 Transfer
* findTransfer(const KUrl
&src
);
121 * Finds the first transfer with destination dest
123 * @param dest the url of the destination location
125 * @return the transfer pointer if the transfer has been found, else return 0
127 Transfer
*findTransferByDestination(const KUrl
&dest
);
130 * @returns the Job in the queue at the given index i
132 Transfer
* operator[] (int i
) const;
134 /**Set the group name
135 * @param name group name
137 void setName(const QString
&name
) {m_name
=name
;}
140 * @return the group name
142 const QString
& name() {return m_name
;}
145 * @return the sum of the sizes of the transfers belonging to
148 int totalSize() const {return m_totalSize
;}
151 * @return the sum of the downloaded sizes of the transfers
152 * belonging to this group
154 int downloadedSize() const {return m_downloadedSize
;}
157 * @return the sum of the uploaded sizes of the transfers
158 * belonging to this group
160 int uploadedSize() const {return m_uploadedSize
;}
163 * @return the progress percentage
165 int percent() const {return m_percent
;}
168 * @return the sum of the download speeds of the running transfers
169 * belonging this group
174 * @return the sum of the download speeds of the running transfers
175 * belonging this group
180 * Set a default Folder for the group
181 * @param folder the new default folder
183 void setDefaultFolder(QString folder
) {m_defaultFolder
= folder
;}
186 * @return the groups default folder
188 QString
defaultFolder() {return m_defaultFolder
;}
191 * @return true if the group supports SpeedLimits
193 bool supportsSpeedLimits();
196 * Set a Download-Limit for the group
197 * @param limit the new download-limit
198 * @note if limit is 0, no download-limit is set
200 void setDownloadLimit(int dlLimit
, Transfer::SpeedLimit limit
);
203 * @return the group's Download-Limit
205 int downloadLimit(Transfer::SpeedLimit limit
) const;
208 * Set a Upload-Limit for the group
209 * @param limit the new upload-limit
210 * @note if limit is 0, no upload-limit is set
212 void setUploadLimit(int ulLimit
, Transfer::SpeedLimit limit
);
215 * @return the group's Upload-Limit
217 int uploadLimit(Transfer::SpeedLimit limit
) const;
220 * Set the group's icon
221 * @param name the icon's name
223 void setIconName(QString name
) {m_iconName
= name
;}
226 * @return the group's icon
228 QPixmap
pixmap() {return KIcon(m_iconName
).pixmap(32);}
231 * @return the handler associated with this group
233 TransferGroupHandler
* handler() const;
236 * @returns the TransferTreeModel that owns this group
238 TransferTreeModel
* model() {return m_model
;}
241 * Calculates the whole SpeedLimits
243 void calculateSpeedLimits();
246 * Calculates the DownloadLimits
248 void calculateDownloadLimit();
251 * Calculates the DownloadLimits
253 void calculateUploadLimit();
256 * Notifies that the given transfer has changed
258 * @param transfer The transfer that has changed
260 void transferChangedEvent(Transfer
* transfer
);
263 * Saves this group object to the given QDomNode
265 * @param n The QDomNode where the group will be saved
267 void save(QDomElement e
);
270 * Adds all the groups in the given QDomNode * to the group
272 * @param n The QDomNode where the group will look for the transfers to add
274 void load(const QDomElement
& e
);
277 TransferTreeModel
* m_model
;
278 TransferGroupHandler
* m_handler
;
283 int m_downloadedSize
;
290 int m_visibleDownloadLimit
;
291 int m_visibleUploadLimit
;
293 QString m_defaultFolder
;