• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kget

  • sources
  • kde-4.12
  • kdenetwork
  • kget
  • core
datasourcefactory.h
Go to the documentation of this file.
1 /* This file is part of the KDE project
2 
3  Copyright (C) 2008 Lukas Appelhans <l.appelhans@gmx.de>
4  Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>
5 
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.
10 */
11 #ifndef DATASOURCEFACTORY_H
12 #define DATASOURCEFACTORY_H
13 
14 #include "kget_export.h"
15 
16 #include "transferdatasource.h"
17 #include "job.h"
18 
19 #include <kio/job.h>
20 
21 #include <QtXml/QDomElement>
22 
23 class BitSet;
24 class KioDownload;
25 class TransferDataSource;
26 class QTimer;
27 class Signature;
28 class Verifier;
29 
30 namespace KIO
31 {
32  class FileJob;
33 }
34 
38 class KGET_EXPORT DataSourceFactory : public QObject
39 {
40  Q_OBJECT
41 
42  public:
48  explicit DataSourceFactory(QObject *parent, const KUrl &dest = KUrl(), KIO::filesize_t size = 0, KIO::fileoffset_t segSize = 512000);
49 
50  ~DataSourceFactory();
51 
55  Transfer::Capabilities capabilities() const {return m_capabilities;}
56 
62  void deinit();
63 
67  bool isValid() const;
68 
69  void start();
70  void stop();
71  KIO::filesize_t size() const {return m_size;}
72  KIO::filesize_t downloadedSize() const {return m_downloadedSize;}
73  ulong currentSpeed() const {return m_speed;}
74  ulong percent() const {return m_percent;}
75 
76  KUrl dest() const {return m_dest;}
77 
81  int maxMirrorsUsed() const {return m_maxMirrorsUsed;}
82 
87  void setMaxMirrorsUsed(int maxMirrorsUsed) {m_maxMirrorsUsed = maxMirrorsUsed;}
88 
100  void addMirror(const KUrl &url, bool used, int numParalellConnections = 1);
101 
112  void addMirror(const KUrl &url, int numParalellConnections = 1);
113 
120  void removeMirror(const KUrl &url);
121 
128  void setMirrors(const QHash<KUrl, QPair<bool, int> > &mirrors);
129 
134  QHash<KUrl, QPair<bool, int> > mirrors() const;
135 
141  bool doDownload() const {return m_doDownload;}
142 
148  void setDoDownload(bool doDownload);
149 
150  bool setNewDestination(const KUrl &newDest);
151 
152  Job::Status status() const {return m_status;}
153 
159  bool downloadInitialized() const {return m_downloadInitialized;}
160 
166  void repair();
167 
168  Verifier *verifier();
169  Signature *signature();
170 
171  Q_SIGNALS:
172  void capabilitiesChanged();
173  void dataSourceFactoryChange(Transfer::ChangesFlags change);
174  void log(const QString &message, Transfer::LogLevel logLevel);
175 
176  public slots:
177  void save(const QDomElement &element);
178  void load(const QDomElement *e);
179 
180  private slots:
181  void slotUpdateCapabilities();
182 
183  void slotRemovedFile();
184 
189  void findFileSize();
190 
191  void slotFoundFileSize(TransferDataSource *source, KIO::filesize_t fileSize, const QPair<int,int> &segmentRange);
192 
193  void assignSegments(TransferDataSource *source);
197  void brokenSegments(TransferDataSource *source, const QPair<int, int> &segmentRange);
198  void finishedSegment(TransferDataSource *source, int segmentNumber, bool connectionFinished = true);
199 
203  void broken(TransferDataSource *source, TransferDataSource::Error error);
208  void slotFreeSegments(TransferDataSource *source, QPair<int, int> segmentRange);
209  void slotWriteData(KIO::fileoffset_t offset, const QByteArray &data, bool &worked);
210  void slotOffset(KIO::Job *job, KIO::filesize_t offset);
211  void slotDataWritten(KIO::Job *job, KIO::filesize_t offset);
212  void slotPercent(KJob *job, ulong percent);
213  void open(KIO::Job *job);
214  void speedChanged();
218  void startMove();
219  void slotPutJobDestroyed(QObject *job);
220  void newDestResult(KJob *job);
221 
222  void slotRepair(const QList<KIO::fileoffset_t> &offsets, KIO::filesize_t length);
223 
224  void slotFinishedDownload(TransferDataSource *source, KIO::filesize_t size);
225 
226  void slotUrlChanged(const KUrl &, const KUrl &);
227 
228  private:
235  void addMirror(const KUrl &url, bool used, int numParalellConnections, bool usedDefined);
236 
241  bool assignNeeded() const;
242 
243  bool checkLocalFile();
244 
245  void init();
246  void killPutJob();
247  void changeStatus(Job::Status status);
248 
249  private:
250  Transfer::Capabilities m_capabilities;
251  KUrl m_dest;
252  KUrl m_newDest;
253  KIO::filesize_t m_size;
254  KIO::filesize_t m_downloadedSize;
255  QList<KIO::filesize_t> m_prevDownloadedSizes;
256  KIO::fileoffset_t m_segSize;
257  ulong m_speed;
258  ulong m_percent;
259 
263  QHash<KIO::fileoffset_t, QByteArray> m_cache;
264 
265  KIO::filesize_t m_tempOffset;
266  QByteArray m_tempData;
267 
268  BitSet *m_startedChunks;
269  BitSet *m_finishedChunks;
270  KIO::FileJob* m_putJob;
271  bool m_doDownload;
272  bool m_open;
276  bool m_blocked;
281  bool m_startTried;
282  bool m_findFilesizeTried;
283 
284  bool m_assignTried;
285  bool m_movingFile;
286 
287  bool m_finished;
288 
293  bool m_downloadInitialized;
294 
298  bool m_sizeInitiallyDefined;
299 
303  bool m_sizeFoundOnFinish;
304 
305  int m_maxMirrorsUsed;
306  QHash<KUrl, TransferDataSource*> m_sources;
307  QList<KUrl> m_unusedUrls;
308  QList<int> m_unusedConnections;
309  QTimer *m_speedTimer;
310  Job::Status m_status;
311  Job::Status m_statusBeforeMove;
312 
313  Verifier *m_verifier;
314  Signature *m_signature;
315 };
316 
317 #endif
Transfer::ChangesFlags
int ChangesFlags
Definition: transfer.h:100
TransferDataSource::Error
Error
Definition: transferdatasource.h:33
Job::Status
Status
The status property describes the current job status.
Definition: job.h:42
DataSourceFactory::size
KIO::filesize_t size() const
Definition: datasourcefactory.h:71
Transfer::LogLevel
LogLevel
Definition: transfer.h:81
DataSourceFactory::percent
ulong percent() const
Definition: datasourcefactory.h:74
DataSourceFactory
This class manages multiple DataSources and saves the received data to the file.
Definition: datasourcefactory.h:38
DataSourceFactory::maxMirrorsUsed
int maxMirrorsUsed() const
The maximum number of mirrors that will be used for downloading, default is 3.
Definition: datasourcefactory.h:81
TransferDataSource
This Class is an interface for inter-plugins data change.
Definition: transferdatasource.h:26
QObject
DataSourceFactory::capabilities
Transfer::Capabilities capabilities() const
The capabilities the DataSourceFactory supports.
Definition: datasourcefactory.h:55
DataSourceFactory::setMaxMirrorsUsed
void setMaxMirrorsUsed(int maxMirrorsUsed)
Change the maximum number off mirrors that will be used for downloading, if the download started alre...
Definition: datasourcefactory.h:87
DataSourceFactory::downloadedSize
KIO::filesize_t downloadedSize() const
Definition: datasourcefactory.h:72
kget_export.h
DataSourceFactory::downloadInitialized
bool downloadInitialized() const
Definition: datasourcefactory.h:159
transferdatasource.h
BitSet
Simple implementation of a BitSet.
Definition: bitset.h:32
job.h
DataSourceFactory::dest
KUrl dest() const
Definition: datasourcefactory.h:76
Verifier
Definition: verifier.h:68
DataSourceFactory::currentSpeed
ulong currentSpeed() const
Definition: datasourcefactory.h:73
Signature
Class to verify signatures.
Definition: signature.h:38
KGET_EXPORT
#define KGET_EXPORT
Definition: kget_export.h:24
DataSourceFactory::doDownload
bool doDownload() const
Returns whether the datasourcefactory should download the file or not, true by default.
Definition: datasourcefactory.h:141
DataSourceFactory::status
Job::Status status() const
Definition: datasourcefactory.h:152
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal