Stellarium 0.11.3
Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · 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., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, 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 #include "StelSkyLayer.hpp"
00028 
00029 class QIODevice;
00030 class StelCore;
00031 
00034 class MultiLevelJsonBase : public StelSkyLayer
00035 {
00036     Q_OBJECT
00037 
00038     friend class JsonLoadThread;
00039 
00040 public:
00042     MultiLevelJsonBase(MultiLevelJsonBase* parent=NULL);
00043 
00046     void initFromUrl(const QString& url);
00047 
00050     void initFromQVariantMap(const QVariantMap& map);
00051 
00053     ~MultiLevelJsonBase();
00054 
00056     QString getShortName() const {return shortName;}
00057 
00059     bool hasErrorOccured() const {return errorOccured;}
00060 
00062     int getLevel() const {return parent()==NULL ? 0 : (qobject_cast<MultiLevelJsonBase*>(parent()))->getLevel()+1;}
00063 
00066     QVariantMap toQVariantMap() const;
00067 
00070     void scheduleChildsDeletion();
00071 
00072 private slots:
00074     void downloadFinished();
00076     void jsonLoadFinished();
00077 
00078 protected:
00081     virtual void loadFromQVariantMap(const QVariantMap& map)=0;
00082 
00084     bool isDeletionScheduled() const {return timeWhenDeletionScheduled>0.;}
00085 
00087     QString shortName;
00088 
00090     QString baseUrl;
00091 
00093     QString contructorUrl;
00094 
00096     QList<MultiLevelJsonBase*> subTiles;
00097 
00099     bool errorOccured;
00100 
00101     void updatePercent(int tot, int numToBeLoaded);
00102 
00104     void deleteUnusedSubTiles();
00105 
00107     bool downloading;
00108 
00110     void cancelDeletion();
00111 
00113     static QVariantMap loadFromJSON(QIODevice& input, bool qZcompressed=false, bool gzCompressed=false);
00114 
00115 private:
00117     QString getBaseUrl() const {return baseUrl;}
00118 
00119     // Used to download remote JSON files if needed
00120     class QNetworkReply* httpReply;
00121 
00122     // The delay after which a scheduled deletion will occur
00123     float deletionDelay;
00124 
00125     class JsonLoadThread* loadThread;
00126 
00127     // Time at which deletion was first scheduled
00128     double timeWhenDeletionScheduled;
00129 
00130     // The temporary map filled in a thread
00131     QVariantMap temporaryResultMap;
00132 
00133     bool loadingState;
00134     int lastPercent;
00135 
00137     static class QNetworkAccessManager* networkAccessManager;
00138 
00139     static QNetworkAccessManager& getNetworkAccessManager();
00140 };
00141 
00142 #endif // _MULTILEVELJSONBASE_HPP_
Generated on Thu May 31 10:37:18 2012 for Stellarium by  doxygen 1.6.3