Home · All Namespaces · All Classes · Functions · Coding Style · Plugins · File Structure

core/StelDownloadMgr.hpp

00001 /*
00002  * Stellarium
00003  * Copyright (C) 2008 Fabien Chereau
00004  * 
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 */
00019 
00020 #ifndef _STELDOWNLOADMGR_HPP_
00021 #define _STELDOWNLOADMGR_HPP_ 1
00022  
00023 #include <QObject>
00024 #include <QNetworkReply>
00025 
00026 class QProgressBar;
00027 class QDataStream;
00028 class QFile;
00029 
00034 class StelDownloadMgr : public QObject
00035 {
00036     Q_OBJECT
00037 public:
00038     StelDownloadMgr();
00039     ~StelDownloadMgr();
00040 
00052     void get(const QString& url, const QString& filePath, quint16 csum);
00053     // Overridden version, needed because the default parameter csum=0 can't
00054     // reliably set useChecksum to false - the actual checksum might be 0.
00055     void get(const QString& url, const QString& filePath);
00056 
00058     void abort();
00059 
00061     QString url() {return address;}
00062 
00064     QString errorString() {return reply ? reply->errorString() : QString();}
00065 
00067     QString name();
00068     
00073     bool blockQuit() {return inProgress && block;}
00074 
00081     void setBlockQuit(bool b) {block = b;}
00082     
00085     void setBarVisible(bool b) {barVisible = b;}
00086     
00090     void setBarFormat(const QString& format) {barFormat = format;}
00091 
00093     bool isDownloading() {return inProgress;}
00094 private:
00095     QString address;
00096     QString path;
00097     QNetworkReply* reply;
00098     QFile* target;
00099     bool useChecksum;
00100     quint16 checksum;
00101     QDataStream* stream;
00102     QProgressBar* progressBar;
00103     QString barFormat;
00104     qint64 received;
00105     qint64 total;
00106     bool barVisible;
00107     bool inProgress;
00108     bool block;
00109 
00110 private slots:
00111     void readData();
00112     void updateDownloadBar(qint64, qint64);
00113     void fin();
00114     void err(QNetworkReply::NetworkError);
00115 signals:
00123     void finished();
00124     
00132     void error(QNetworkReply::NetworkError code, QString errorString);
00133     
00135     void verifying();
00136     
00139     void badChecksum();
00140 };
00141 
00142 #endif // _STELDOWNLOADMGR_HPP_
00143 

Generated on Mon Feb 2 17:23:47 2009 for Stellarium by  doxygen 1.5.5