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; version 2
15 #include <kio/netaccess.h>
18 #include "kget_export.h"
23 class TransferGroupHandler
;
24 class TransferTreeModel
;
27 * class TransferGroup:
29 * This class abstracts the concept of transfer group by means of which
30 * the user can sort his transfers into categories.
31 * By definition, we want each TransferGroup (transfer group) to be a JobQueue.
32 * Moreover this class calculates information such as:
33 * - the size obtained by the sum of all the transfer's size
34 * - the size obtained by the sum of all the transfer's processed size
35 * - the global progress percentage within the group
36 * - the global speed within the group
38 class KGET_EXPORT TransferGroup
: public JobQueue
44 Gc_Status
= 0x00000001,
45 Gc_TotalSize
= 0x00000002,
46 Gc_ProcessedSize
= 0x00000004,
47 Gc_Percent
= 0x00000008,
51 typedef int ChangesFlags
;
53 TransferGroup(TransferTreeModel
* model
, Scheduler
* scheduler
, const QString
& name
=QString());
55 virtual ~TransferGroup();
58 * This function is reimplemented by JobQueue::setStatus
60 * @param queueStatus the new JobQueue status
62 void setStatus(Status queueStatus
);
65 * Appends a new transfer to the list of the transfers
67 * @param transfer the transfer to append
69 void append(Transfer
* transfer
);
72 * Prepends a new transfer to the list of the transfers
74 * @param transfer the transfer to prepend
76 void prepend(Transfer
* transfer
);
79 * inserts a transfer to the current group after the given transfer
81 * @param transfer The transfer to add in the current Group
82 * @param after The transfer after which to add the transfer
84 void insert(Transfer
* transfer
, Transfer
* after
);
87 * Removes the given transfer from the list of the transfers
89 * @param transfer the transfer to remove
91 void remove(Transfer
* transfer
);
94 * Moves a transfer in the list
96 * @param transfer The transfer to move. Note that this transfer can
97 * belong to other groups. In this situation this
98 * transfer is deleted from the previous group and
99 * moved inside this one.
100 * @param after The transfer after which we have to move the given one
102 void move(Transfer
* transfer
, Transfer
* after
);
105 * Finds the first transfer with source src
107 * @param src the url of the source location
109 * @return the transfer pointer if the transfer has been found. Otherwise
112 Transfer
* findTransfer(const KUrl
&src
);
115 * Finds the first transfer with destination dest
117 * @param dest the url of the destination location
119 * @return the transfer pointer if the transfer has been found, else return 0
121 Transfer
*findTransferByDestination(const KUrl
&dest
);
124 * @returns the Job in the queue at the given index i
126 Transfer
* operator[] (int i
) const;
128 /**Set the group name
129 * @param name group name
131 void setName(const QString
&name
) {m_name
=name
;}
134 * @return the group name
136 const QString
& name() {return m_name
;}
139 * @return the sum of the sizes of the transfers belonging to
142 int totalSize() const {return m_totalSize
;}
145 * @return the sum of the processed sizes of the transfers
146 * belonging to this group
148 int processedSize() const {return m_processedSize
;}
151 * @return the progress percentage
153 int percent() const {return m_percent
;}
156 * @return the sum of the download speeds of the running transfers
157 * belonging this group
159 int speed() const {return m_speed
;}
162 * @return the handler associated with this group
164 TransferGroupHandler
* handler();
167 * @returns the TransferTreeModel that owns this group
169 TransferTreeModel
* model() {return m_model
;}
172 * Notifies that the given transfer has changed
174 * @param transfer The transfer that has changed
176 void transferChangedEvent(Transfer
* transfer
);
179 * Saves this group object to the given QDomNode
181 * @param n The QDomNode where the group will be saved
183 void save(QDomElement e
);
186 * Adds all the groups in the given QDomNode * to the group
188 * @param n The QDomNode where the group will look for the transfers to add
190 void load(const QDomElement
& e
);
193 TransferTreeModel
* m_model
;
194 TransferGroupHandler
* m_handler
;