1 /* This file is part of the KDE project
3 Copyright (C) 2004 Dario Massarin <nekkar@libero.it>
4 Copyright (C) 2008 Lukas Appelhans <l.appelhans@gmx.de>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
16 #include "kget_export.h"
22 #include <kio/global.h>
26 class TransferHandler
;
27 class TransferFactory
;
30 class TransferTreeModel
;
33 class KGET_EXPORT Transfer
: public Job
35 friend class TransferHandler
;
36 friend class TransferTreeModel
;
41 * Here we define the flags that should be shared by all the transfers.
42 * A transfer should also be able to define additional flags, in the future.
47 // These flags respect the Model columns order NOTE: The model only checks the last 8 bits, so all values which need to be updated by the model should look like: 0x000000xx
48 Tc_FileName
= 0x00000001,
49 Tc_Status
= 0x00000002,
50 Tc_TotalSize
= 0x00000004,
51 Tc_Percent
= 0x00000008,
52 Tc_DownloadSpeed
= 0x00000010,
53 Tc_RemainingTime
= 0x00000020,
55 Tc_UploadSpeed
= 0x00000100,
56 Tc_UploadLimit
= 0x00000200,
57 Tc_DownloadLimit
= 0x00000400,
58 Tc_CanResume
= 0x00000800,
59 Tc_DownloadedSize
= 0x00001000,
60 Tc_UploadedSize
= 0x00002000,
62 Tc_Group
= 0x00008000,
63 Tc_Selection
= 0x00010000
75 VisibleSpeedLimit
= 0x01,
76 InvisibleSpeedLimit
= 0x02
78 typedef int ChangesFlags
;
80 Transfer(TransferGroup
* parent
, TransferFactory
* factory
,
81 Scheduler
* scheduler
, const KUrl
& src
, const KUrl
& dest
,
82 const QDomElement
* e
= 0);
86 const KUrl
& source() const {return m_source
;}
87 const KUrl
& dest() const {return m_dest
;}
90 KIO::filesize_t
totalSize() const {return m_totalSize
;}
91 KIO::filesize_t
downloadedSize() const {return m_downloadedSize
;}
92 KIO::filesize_t
uploadedSize() const {return m_uploadedSize
;}
93 QString
statusText() const {return m_statusText
;}
94 QPixmap
statusPixmap() const {return m_statusPixmap
;}
96 int percent() const {return m_percent
;}
97 int downloadSpeed() const {return m_downloadSpeed
;}
98 int uploadSpeed() const {return m_uploadSpeed
;}
99 virtual int remainingTime() const {return KIO::calculateRemainingSeconds(totalSize(), downloadedSize(), downloadSpeed());}
100 virtual int elapsedTime() const;
102 virtual bool supportsSpeedLimits() const {return false;}
105 * Set the Transfer's UploadLimit
106 * @note this is not displayed in any GUI, use setVisibleUploadLimit(int) instead
107 * @param visibleUlLimit upload Limit
109 void setUploadLimit(int ulLimit
, SpeedLimit limit
);
112 * Set the Transfer's UploadLimit, which are displayed in the GUI
113 * @note this is not displayed in any GUI, use setVisibleDownloadLimit(int) instead
114 * @param visibleUlLimit upload Limit
116 void setDownloadLimit(int dlLimit
, SpeedLimit limit
);
119 * @return the UploadLimit, which is invisible in the GUI
121 int uploadLimit(SpeedLimit limit
) const;
124 * @return the DownloadLimit, which is invisible in the GUI
126 int downloadLimit(SpeedLimit limit
) const;
129 * Set the maximum share-ratio
130 * @param ratio the new maximum share-ratio
132 void setMaximumShareRatio(double ratio
);
135 * @return the maximum share-ratio
137 double maximumShareRatio() {return m_ratio
;}
140 * Recalculate the share ratio
142 void checkShareRatio();
144 // --- Job virtual functions ---
145 virtual void setDelay(int seconds
);
146 virtual void delayTimerEvent();
149 bool isSelected() const {return m_isSelected
;}
154 const QStringList
log() const;
157 * Set Transfer history
159 void setLog(const QString
& message
, LogLevel level
= info
);
162 * Defines the order between transfers
164 bool operator<(const Transfer
& t2
) const;
169 TransferGroup
* group() const {return (TransferGroup
*) m_jobQueue
;}
172 * @return the associated TransferHandler
174 TransferHandler
* handler();
177 * @returns the TransferTreeModel that owns this group
179 TransferTreeModel
* model();
182 * @returns a pointer to the TransferFactory object
184 TransferFactory
* factory() const {return m_factory
;}
188 * Sets the NepomukHandler for the transfer
189 * @param handler the new NepomukHandler
191 void setNepomukHandler(NepomukHandler
*handler
) {m_nepomukHandler
= handler
;}
194 * @returns a pointer to the NepomukHandler of this transfer
196 NepomukHandler
* nepomukHandler() const {return m_nepomukHandler
;}
200 * Saves this transfer to the given QDomNode
202 * @param n The pointer to the QDomNode where the transfer will be saved
203 * @return The created QDomElement
205 virtual void save(const QDomElement
&element
);
208 //Function used to load and save the transfer's info from xml
209 virtual void load(const QDomElement
&e
);
212 * Sets the Job status to jobStatus, the status text to text and
213 * the status pixmap to pix.
215 void setStatus(Job::Status jobStatus
, const QString
&text
, const QPixmap
&pix
);
218 * Makes the TransferHandler associated with this transfer know that
219 * a change in this transfer has occurred.
221 * @param change: the TransferChange flags to be set
223 virtual void setTransferChange(ChangesFlags change
, bool postEvent
=false);
226 * Function used to set the SpeedLimits to the transfer
228 virtual void setSpeedLimits(int uploadLimit
, int downloadLimit
) {Q_UNUSED(uploadLimit
) Q_UNUSED(downloadLimit
) }
230 // --- Transfer information ---
235 KIO::filesize_t m_totalSize
;
236 KIO::filesize_t m_downloadedSize
;
237 KIO::filesize_t m_uploadedSize
;
248 int m_visibleUploadLimit
;
249 int m_visibleDownloadLimit
;
250 int m_runningSeconds
;
253 QString m_statusText
;
254 QPixmap m_statusPixmap
;
257 TransferHandler
* m_handler
;
258 TransferFactory
* m_factory
;
260 NepomukHandler
* m_nepomukHandler
;