Stellarium 0.12.3
MpcImportWindow.hpp
1 /*
2  * Solar System editor plug-in for Stellarium
3  *
4  * Copyright (C) 2010-2011 Bogdan Marinov
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
19  */
20 
21 #ifndef _MPC_IMPORT_WINDOW_
22 #define _MPC_IMPORT_WINDOW_
23 
24 #include <QObject>
25 #include <QNetworkAccessManager>
26 #include <QNetworkReply>
27 #include <QProgressBar>
28 #include <QStandardItemModel>
29 #include "StelDialog.hpp"
30 
31 #include "SolarSystemEditor.hpp"
32 
33 class Ui_mpcImportWindow;
34 
39 {
40  Q_OBJECT
41 public:
42  enum ImportType {
43  MpcComets,
44  MpcMinorPlanets
45  };
46 
48  virtual ~MpcImportWindow();
49 
50 public slots:
51  void retranslate();
52 
53 signals:
54  void objectsImported();
55 
56 private slots:
57  //Radio buttons for type
58  void switchImportType(bool checked);
59 
60  //File
61  void selectFile();
62 
63  //Download
64  void pasteClipboardURL();
65  void bookmarkSelected(QString);
66 
67  //Buttons for the list tab
68  void acquireObjectData();
69  void abortDownload();
70 
71  //Online search
72  void sendQuery();
73  void sendQueryToUrl(QUrl url);
74  void abortQuery();
75  void updateCountdown();
76  void resetNotFound();
77 
78  //Network
79  void updateDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
80  void updateQueryProgress(qint64 bytesReceived, qint64 bytesTotal);
81  void downloadComplete(QNetworkReply * reply);
82  void receiveQueryReply(QNetworkReply * reply);
83  void readQueryReply(QNetworkReply * reply);
84 
86  void markAll();
88  void unmarkAll();
89  void addObjects();
90  void discardObjects();
91 
93  void resetDialog();
94 
95 private:
96  SolarSystemEditor * ssoManager;
97  QList<SsoElements> candidatesForAddition;
98  QList<SsoElements> candidatesForUpdate;
99  QStandardItemModel * candidateObjectsModel;
100 
101  ImportType importType;
102 
103  void updateTexts();
104 
106  SsoElements readElementsFromString(QString elements);
108  QList<SsoElements> readElementsFromFile(ImportType type, QString filePath);
109 
110  void populateBookmarksList();
111  //void populateCandidateObjects();
112  void populateCandidateObjects(QList<SsoElements>);
113  void enableInterface(bool enable);
114 
115  //Downloading
116  QNetworkAccessManager * networkManager;
117  QNetworkReply * downloadReply;
118  QNetworkReply * queryReply;
119  QProgressBar * downloadProgressBar;
120  QProgressBar * queryProgressBar;
121  void startDownload(QString url);
122  void deleteDownloadProgressBar();
123  void deleteQueryProgressBar();
124 
125  typedef QHash<QString,QString> Bookmarks;
126  QHash<ImportType, Bookmarks> bookmarks;
127  void loadBookmarks();
128  void loadBookmarksGroup(QVariantMap source, Bookmarks & bookmarkGroup);
129  void saveBookmarks();
130  void saveBookmarksGroup(Bookmarks & bookmarkGroup, QVariantMap & output);
131 
132  //Online search
133  QString query;
134  int countdown;
135  QTimer * countdownTimer;
136  void startCountdown();
137  void resetCountdown();
138 
139 protected:
140  virtual void createDialogContent();
141  Ui_mpcImportWindow * ui;
142 };
143 
144 #endif //_MPC_IMPORT_WINDOW_