ndgui/NetworkDiscovery

/home/niklas/workspace/fbgui/src/downloadmanager.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010,2011 - RZ Uni Freiburg
00003  * Copyright (c) 2010,2011 - OpenSLX Project
00004  *
00005  * This program/file is free software distributed under the GPL version 2.
00006  * See http://openslx.org/COPYING
00007  *
00008  * If you have any feedback please consult http://openslx.org/feedback and
00009  * send your feedback to feedback@openslx.org
00010  *
00011  * General information about OpenSLX can be found under http://openslx.org
00012  *
00013  *
00014  *         Class managing download requests:
00015  *              - provides queueing functionality
00016  *              - static info: filename, filesize
00017  *              - dynamic info: download progress, current speed
00018  *
00019  */
00020 
00021 #ifndef DOWNLOADMANAGER_H
00022 #define DOWNLOADMANAGER_H
00023 
00024 #include "fbgui.h"
00025 
00026 extern bool debug;
00027 extern QUrl baseURL;
00028 extern QString binPath;
00029 extern QString downloadPath;
00030 extern int updateInterval;
00031 
00032 class DownloadManager: public QObject {
00033 Q_OBJECT
00034 
00035 public:
00036    DownloadManager();
00037    ~DownloadManager();
00038    QTime time;
00039 
00040 private:
00041    // checks for valid download directory, ran once in constructor
00042    void checkDownloadDirectory();
00043    // private control function for queueing mechanism.
00044    void processDownloadRequest(const QUrl& url);
00045 
00046    // base objects for downloading
00047    QNetworkAccessManager* _qnam;
00048    QQueue<QUrl> _downloadQueue;
00049    QNetworkReply* _currentDownload;
00050    QFile _outfile;
00051    QDir _downloadDir;
00052    // download progress variables
00053    int _currentProgress, _lastProgress;
00054    // download in progress flag
00055    bool _dip;
00056    // static counter
00057    static int _downloaded;
00058 
00059 signals:
00060    // notify sends a message to the javascript interface to be evaluated there
00061    void notify(const QString& msg);
00062    // downloadInfo sends static information (name, size) to the interface.
00063    void downloadInfo(const QString& filename, const double& filesize);
00064    // updateProgress sends download progress information to the interface.
00065    void updateProgress(const int& percent, const double& speed, const QString& unit);
00066    // signal emitted when download queue is empty.
00067    void downloadQueueEmpty();
00068 
00069 public slots:
00070    // public slots to receive download requests.
00071    void downloadFile(const QUrl& fileUrl);
00072    // convenience function
00073    void downloadFile(const QString& fileUrl);
00074 
00075 private slots:
00076    // private slots to manage the downloading process
00077    void startNextDownload();
00078    void processMetaInfo();
00079    void downloadReady();
00080    void downloadProgress(qint64 bytesIn, qint64 bytesTotal);
00081    void downloadFinished();
00082 };
00083 
00084 #endif // DOWNLOADMANAGER_H
 All Classes Files Functions Variables Defines