* Paint a styled progressbar instead of our home-brown one.
[kdenetwork.git] / kget / core / transfergrouphandler.h
blob0f93ce9be784c7235fbe865021e820c6443f5006
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
8 of the License.
9 */
11 #ifndef TRANSFERGROUPHANDLER_H
12 #define TRANSFERGROUPHANDLER_H
14 #include <QVariant>
16 #include "transfergroup.h"
17 #include "kget_export.h"
19 class QAction;
20 class KMenu;
22 class QObjectInterface;
23 class TransferGroupObserver;
24 class TransferHandler;
25 class Scheduler;
27 class KGET_EXPORT TransferGroupHandler
29 friend class TransferGroup;
30 friend class TransferTreeModel;
32 public:
34 typedef TransferGroup::ChangesFlags ChangesFlags;
36 TransferGroupHandler(TransferGroup * group, Scheduler * scheduler);
38 ~TransferGroupHandler();
40 /**
41 * Adds an observer to this TransferGroup
43 * @param observer The new observer that should be added
45 void addObserver(TransferGroupObserver * observer);
47 /**
48 * Removes an observer from this TransferGroup
50 * @param observer The observer that should be removed
52 void delObserver(TransferGroupObserver * observer);
54 /**
55 * These are all JobQueue-related functions
57 void start();
58 void stop();
59 JobQueue::Status status() const {return m_group->status();}
61 /**
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
64 * this group
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);
71 /**
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);
79 /**
80 * @returns the Job in the queue at the given index i
82 TransferHandler * operator[] (int i);
84 /**
85 * @returns the number of Transfers owned by this object
87 int size() {return m_group->size();}
89 /**Set the group name
90 * @param name group name
92 void setName(const QString &name);
94 /**
95 * @return the group name
97 const QString & name() {return m_group->name();}
99 /**
100 * @return the sum of the sizes of the transfers belonging to
101 * this group
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
161 * transfer group.
163 const QList<QAction *> & actions();
166 * @returns a KMenu for this transfer group.
168 KMenu * popupMenu();
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
173 * transfer group.
175 QObjectInterface * qObject();
177 private:
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
238 Q_OBJECT
239 public:
240 QObjectInterface(TransferGroupHandler * handler);
242 public slots:
243 void slotStart(); //Starts the download process
244 void slotStop(); //Stops the download process
246 signals:
248 private:
249 TransferGroupHandler * m_handler;
252 #endif