00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00127 class QNetworkReply* httpReply;
00128
00129
00130 float deletionDelay;
00131
00132 class JsonLoadThread* loadThread;
00133
00134
00135 double timeWhenDeletionScheduled;
00136
00137
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_