1 /* This file is part of the KDE project
3 Copyright (C) 2004 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 "kget_export.h"
20 #include <kio/global.h>
24 class TransferHandler
;
25 class TransferFactory
;
28 class TransferTreeModel
;
30 class KGET_EXPORT Transfer
: public Job
32 friend class TransferHandler
;
33 friend class TransferTreeModel
;
38 * Here we define the flags that should be shared by all the transfers.
39 * A transfer should also be able to define additional flags, in the future.
44 // These flags respect the Model columns order
45 Tc_FileName
= 0x00000001,
46 Tc_Status
= 0x00000002,
47 Tc_TotalSize
= 0x00000004,
48 Tc_Percent
= 0x00000008,
49 Tc_DownloadSpeed
= 0x00000010,
50 Tc_UploadSpeed
= 0x00000016,
52 Tc_UploadLimit
= 0x00000100,
53 Tc_DownloadLimit
= 0x00000200,
54 Tc_CanResume
= 0x00000400,
55 Tc_DownloadedSize
= 0x00000800,
56 Tc_UploadedSize
= 0x00001000,
58 Tc_Group
= 0x00004000,
59 Tc_Selection
= 0x00006000
68 typedef int ChangesFlags
;
70 Transfer(TransferGroup
* parent
, TransferFactory
* factory
,
71 Scheduler
* scheduler
, const KUrl
& src
, const KUrl
& dest
,
72 const QDomElement
* e
= 0);
76 const KUrl
& source() const {return m_source
;}
77 const KUrl
& dest() const {return m_dest
;}
80 KIO::filesize_t
totalSize() const {return m_totalSize
;}
81 KIO::filesize_t
downloadedSize() const {return m_downloadedSize
;}
82 KIO::filesize_t
uploadedSize() const {return m_uploadedSize
;}
83 QString
statusText() const {return m_statusText
;}
84 QPixmap
statusPixmap() const {return m_statusPixmap
;}
86 int percent() const {return m_percent
;}
87 int downloadSpeed() const {return m_downloadSpeed
;}
88 int uploadSpeed() const {return m_uploadSpeed
;}
90 virtual bool supportsSpeedLimits() const {return false;}
93 * Set the Transfer's UploadLimit
94 * @note this is not displayed in any GUI, use setVisibleUploadLimit(int) instead
95 * @param visibleUlLimit upload Limit
97 virtual void setUploadLimit(int ulLimit
) {Q_UNUSED(ulLimit
);}
100 * Set the Transfer's UploadLimit, which are displayed in the GUI
101 * @note this is not displayed in any GUI, use setVisibleDownloadLimit(int) instead
102 * @param visibleUlLimit upload Limit
104 virtual void setDownloadLimit(int dlLimit
) {Q_UNUSED(dlLimit
);}
107 * @return the UploadLimit, which is invisible in the GUI
109 int uploadLimit() const {return m_ulLimit
;}
112 * @return the DownloadLimit, which is invisible in the GUI
114 int downloadLimit() const {return m_dlLimit
;}
117 * Set the Transfer's UploadLimit, which are displayed in the GUI
118 * @note use this, when a user changes the UploadLimit manually
119 * @param visibleUlLimit upload Limit
121 void setVisibleUploadLimit(int visibleUlLimit
);
124 * Set the Transfer's UploadLimit, which are displayed in the GUI
125 * @note use this, when a user changes the UploadLimit manually
126 * @param visibleUlLimit upload Limit
128 void setVisibleDownloadLimit(int visibleDlLimit
);
131 * @return the visible UploadLimit
133 int visibleUploadLimit() const {return m_visibleUlLimit
;}
136 * @return the visible DownloadLimit
138 int visibleDownloadLimit() const {return m_visibleDlLimit
;}
141 * Set the maximum share-ratio
142 * @param ratio the new maximum share-ratio
144 void setMaximumShareRatio(double ratio
);
147 * @return the maximum share-ratio
149 double maximumShareRatio() {return m_ratio
;}
152 * Recalculate the share ratio
154 void checkShareRatio();
156 // --- Job virtual functions ---
157 virtual void setDelay(int seconds
);
158 virtual void delayTimerEvent();
161 bool isSelected() const {return m_isSelected
;}
166 const QStringList
log() const;
169 * Set Transfer history
171 void setLog(const QString
& message
, LogLevel level
= info
);
174 * Defines the order between transfers
176 bool operator<(const Transfer
& t2
) const;
181 TransferGroup
* group() const {return (TransferGroup
*) m_jobQueue
;}
184 * @return the associated TransferHandler
186 TransferHandler
* handler();
189 * @returns the TransferTreeModel that owns this group
191 TransferTreeModel
* model();
194 * @returns a pointer to the TransferFactory object
196 TransferFactory
* factory() const {return m_factory
;}
199 * Saves this transfer to the given QDomNode
201 * @param n The pointer to the QDomNode where the transfer will be saved
202 * @return The created QDomElement
204 virtual void save(const QDomElement
&element
);
207 //Function used to load and save the transfer's info from xml
208 virtual void load(const QDomElement
&e
);
211 * Sets the Job status to jobStatus, the status text to text and
212 * the status pixmap to pix.
214 void setStatus(Job::Status jobStatus
, const QString
&text
, const QPixmap
&pix
);
217 * Makes the TransferHandler associated with this transfer know that
218 * a change in this transfer has occurred.
220 * @param change: the TransferChange flags to be set
222 virtual void setTransferChange(ChangesFlags change
, bool postEvent
=false);
224 // --- Transfer information ---
229 KIO::filesize_t m_totalSize
;
230 KIO::filesize_t m_downloadedSize
;
231 KIO::filesize_t m_uploadedSize
;
242 int m_visibleUlLimit
;
243 int m_visibleDlLimit
;
246 QString m_statusText
;
247 QPixmap m_statusPixmap
;
249 TransferHandler
* m_handler
;
250 TransferFactory
* m_factory
;