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

core/MultiLevelJsonBase.hpp

00001 /*
00002  * Copyright (C) 2008 Fabien Chereau
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  */
00018 
00019 #ifndef _MULTILEVELJSONBASE_HPP_
00020 #define _MULTILEVELJSONBASE_HPP_
00021 
00022 #include <QList>
00023 #include <QString>
00024 #include <QVariantMap>
00025 #include <QNetworkReply>
00026 
00027 class QIODevice;
00028 class StelCore;
00029 
00031 class MultiLevelJsonBase : public QObject
00032 {
00033     Q_OBJECT
00034     
00035     friend class JsonLoadThread;
00036     
00037 public:
00039     MultiLevelJsonBase(MultiLevelJsonBase* parent=NULL);
00040     
00043     void initFromUrl(const QString& url);
00044     
00047     void initFromQVariantMap(const QVariantMap& map);
00048     
00050     ~MultiLevelJsonBase();
00051     
00053     QString getShortName() const {return shortName;}
00054     
00056     bool hasErrorOccured() const {return errorOccured;}
00057     
00059     int getLevel() const {return parent()==NULL ? 0 : (qobject_cast<MultiLevelJsonBase*>(parent()))->getLevel()+1;}
00060     
00063     QVariantMap toQVariantMap() const;
00064     
00066     void scheduleChildsDeletion();
00067     
00068 signals:
00071     void loadingStateChanged(bool b);
00072     
00075     void percentLoadedChanged(int percentage);
00076         
00077 private slots:
00079     void downloadFinished();
00081     void jsonLoadFinished();
00082 
00083 protected:
00085     bool isDeletionScheduled() const {return timeWhenDeletionScheduled>0.;}
00086     
00088     QString shortName;
00089     
00091     QString baseUrl;
00092     
00094     QString contructorUrl;
00095     
00097     QVariantList subTilesUrls;
00098     
00100     QList<MultiLevelJsonBase*> subTiles;
00101     
00103     bool errorOccured;
00104     
00106     virtual void loadFromQVariantMap(const QVariantMap& map)=0;
00107     
00108     void updatePercent(int tot, int numToBeLoaded);
00109     
00111     void deleteUnusedSubTiles();
00112     
00114     bool downloading;
00115     
00117     void cancelDeletion();
00118     
00120     static QVariantMap loadFromJSON(QIODevice& input, bool qZcompressed=false, bool gzCompressed=false);
00121     
00122 private:
00124     QString getBaseUrl() const {return baseUrl;}
00125     
00126     // Used to download remote JSON files if needed
00127     class QNetworkReply* httpReply;
00128     
00129     // The delay after which a scheduled deletion will occur
00130     float deletionDelay;
00131     
00132     class JsonLoadThread* loadThread;
00133             
00134     // Time at which deletion was first scheduled
00135     double timeWhenDeletionScheduled;
00136     
00137     // The temporary map filled in a thread
00138     QVariantMap temporaryResultMap;
00139     
00140     bool loadingState;
00141     int lastPercent;
00142     
00144     static class QNetworkAccessManager* networkAccessManager;
00145     
00146     static QNetworkAccessManager& getNetworkAccessManager();
00147 };
00148 
00149 #endif // _MULTILEVELJSONBASE_HPP_

Generated on Mon Mar 9 16:16:15 2009 for Stellarium by  doxygen 1.5.5