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
11 #ifndef TRANSFERGROUPHANDLER_H
12 #define TRANSFERGROUPHANDLER_H
16 #include "transfergroup.h"
17 #include "kget_export.h"
22 class QObjectInterface
;
23 class TransferGroupObserver
;
24 class TransferHandler
;
27 class KGET_EXPORT TransferGroupHandler
29 friend class TransferGroup
;
30 friend class TransferTreeModel
;
34 typedef TransferGroup::ChangesFlags ChangesFlags
;
36 TransferGroupHandler(TransferGroup
* group
, Scheduler
* scheduler
);
38 ~TransferGroupHandler();
41 * Adds an observer to this TransferGroup
43 * @param observer The new observer that should be added
45 void addObserver(TransferGroupObserver
* observer
);
48 * Removes an observer from this TransferGroup
50 * @param observer The observer that should be removed
52 void delObserver(TransferGroupObserver
* observer
);
55 * These are all JobQueue-related functions
59 JobQueue::Status
status() const {return m_group
->status();}
62 * Moves a list of transfers belonging to this group to a new position,
63 * after the transfer named "after". All the transfers must belong to
66 * @param transfers The transfers to be be moved
67 * @param after The transfer after which the given transfers should be moved
69 void move(QList
<TransferHandler
*> transfers
, TransferHandler
* after
);
72 * Sets the maximum number of jobs belonging to this queue that
73 * should executed simultaneously by the scheduler
75 * @param n The maximum number of jobs
77 void setMaxSimultaneousJobs(int n
);
80 * @returns the Job in the queue at the given index i
82 TransferHandler
* operator[] (int i
);
85 * @returns the number of Transfers owned by this object
87 int size() {return m_group
->size();}
90 * @param name group name
92 void setName(const QString
&name
);
95 * @return the group name
97 const QString
& name() {return m_group
->name();}
100 * @return the sum of the sizes of the transfers belonging to
103 int totalSize() const {return m_group
->totalSize();}
106 * @return the sum of the processed sizes of the transfers
107 * belonging to this group
109 int processedSize() const {return m_group
->processedSize();}
112 * @return the progress percentage
114 int percent() const {return m_group
->percent();}
117 * @return the sum of the download speeds of the running transfers
118 * belonging this group
120 int speed() const {return m_group
->speed();}
123 * @returns the data associated to this TransferGroup item. This is
124 * necessary to make the interview model/view work
126 QVariant
data(int column
);
129 * @returns the number of columns associated to the group's data
131 int columnCount() const {return 5;}
134 * Returns the changes flags
136 * @param observer The observer that makes this request
138 ChangesFlags
changesFlags(TransferGroupObserver
* observer
);
141 * Resets the changes flags for a given TransferObserver
143 * @param observer The observer that makes this request
145 void resetChangesFlags(TransferGroupObserver
* observer
);
148 * @returns the index for the given transfer. If the transfer can't
149 * be found, it returns -1
151 int indexOf(TransferHandler
* transfer
);
154 * @returns a list containing all the transfers belonging to this group.
156 const QList
<TransferHandler
*> transfers();
159 * @returns a pointer to a QObjectInterface object which is a QObject
160 * by means of which you can connect signals and slots for this
163 const QList
<QAction
*> & actions();
166 * @returns a KMenu for this transfer group.
171 * @returns a pointer to a QObjectInterface object which is a QObject
172 * by means of which you can connect signals and slots for this
175 QObjectInterface
* qObject();
179 * Sets a change flag in the ChangesFlags variable.
181 * @param change The TransferChange flag to be set
182 * @param postEvent if false the handler will not post an event to the
183 * observers, if true the handler will post an event to the observers
185 void setGroupChange(ChangesFlags change
, bool postEvent
=false);
188 * Posts a TransferGroupChangedEvent to all the observers
190 void postGroupChangedEvent();
193 * Posts an addedTransferEvent to all the observers
195 * @param transfer the transfer that has been added to the group
196 * @param after the transfer after which it has been added
198 void postAddedTransferEvent(Transfer
* transfer
, Transfer
* after
);
201 * Posts an removedTransferEvent to all the observers
203 * @param transfer the transfer that has been removed from the group
205 void postRemovedTransferEvent(Transfer
* transfer
);
208 * Posts an movedTransferEvent to all the observers
210 * @param transfer the transfer that has been removed from the group
211 * @param after the transfer after which the it has been moved
213 void postMovedTransferEvent(Transfer
* transfer
, Transfer
* after
);
216 * Posts a deleteEvent to all the observers
218 void postDeleteEvent();
221 * Creates all the QActions
223 void createActions();
225 TransferGroup
* m_group
;
226 Scheduler
* m_scheduler
;
228 QObjectInterface
* m_qobject
;
229 QList
<QAction
*> m_actions
;
231 QList
<TransferGroupObserver
*> m_observers
;
232 QMap
<TransferGroupObserver
*, ChangesFlags
> m_changesFlags
;
236 class QObjectInterface
: public QObject
240 QObjectInterface(TransferGroupHandler
* handler
);
243 void slotStart(); //Starts the download process
244 void slotStop(); //Stops the download process
249 TransferGroupHandler
* m_handler
;