summaryrefslogtreecommitdiffstats
path: root/src/fbgui/downloadmanager.h
blob: 2bd3adb52f2e6a18a1c522d7201cf076f22c2087 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Copyright (c) 2010,2011 - RZ Uni Freiburg
 * Copyright (c) 2010,2011 - OpenSLX Project
 *
 * This program/file is free software distributed under the GPL version 2.
 * See http://openslx.org/COPYING
 *
 * If you have any feedback please consult http://openslx.org/feedback and
 * send your feedback to feedback@openslx.org
 *
 * General information about OpenSLX can be found under http://openslx.org
 *
 *
 * 	   Class managing download requests:
 *		- provides queueing functionality
 *		- static info: filename, filesize
 *		- dynamic info: download progress, current speed
 *
 * \package fbgui 
 *
 */

#ifndef DOWNLOADMANAGER_H
#define DOWNLOADMANAGER_H

#include "fbgui.h"

extern bool debug;
extern QUrl baseURL;
extern QString binPath;
extern QString downloadPath;
extern int updateInterval;

class DownloadManager: public QObject
{
  Q_OBJECT

public:
  DownloadManager();
  ~DownloadManager();
  QTime time;

private:
  // checks for valid download directory, ran once in constructor
  void checkDownloadDirectory();
  // private control function for queueing mechanism.
  void processDownloadRequest(const QUrl& url);

  // base objects for downloading
  QNetworkAccessManager* _qnam;
  QQueue<QUrl> _downloadQueue;
  QNetworkReply* _currentDownload;
  QFile _outfile;
  QDir _downloadDir;
  // download progress variables
  int _currentProgress, _lastProgress;
  // download in progress flag
  bool _dip;
  // static counter
  static int _downloaded;

signals:
  // notify sends a message to the javascript interface to be evaluated there
  void notify(const QString& msg);
  // downloadInfo sends static information (name, size) to the interface.
  void downloadInfo(const QString& filename, const double& filesize);
  // updateProgress sends download progress information to the interface.
  void updateProgress(const int& percent, const double& speed, const QString& unit);
  // signal emitted when download queue is empty.
  void downloadQueueEmpty();

public slots:
  // public slots to receive download requests.
  void downloadFile(const QUrl& fileUrl);
  // convenience function
  void downloadFile(const QString& fileUrl);

private slots:
  // private slots to manage the downloading process
  void startNextDownload();
  void processMetaInfo();
  void downloadReady();
  void downloadProgress(qint64 bytesIn, qint64 bytesTotal);
  void downloadFinished();
};

#endif // DOWNLOADMANAGER_H