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 MPCIMPORTWINDOW_HPP 22 #define MPCIMPORTWINDOW_HPP 23 24 #include <QObject> 25 #include <QNetworkAccessManager> 26 #include <QNetworkReply> 27 #include <QStandardItemModel> 28 #include "StelDialog.hpp" 29 30 #include "SolarSystemEditor.hpp" 31 32 class Ui_mpcImportWindow; 33 34 /*! \brief Window for importing orbital elements from the Minor Planet Center. 35 \author Bogdan Marinov 36 */ 37 class MpcImportWindow : public StelDialog 38 { 39 Q_OBJECT 40 public: 41 enum ImportType { 42 MpcComets, 43 MpcMinorPlanets 44 }; 45 46 MpcImportWindow(); 47 virtual ~MpcImportWindow(); 48 49 public slots: 50 void retranslate(); 51 52 signals: 53 void objectsImported(); 54 55 private slots: 56 //Radio buttons for type 57 void switchImportType(bool checked); 58 59 //File 60 void selectFile(); 61 62 //Download 63 void pasteClipboardURL(); 64 void bookmarkSelected(QString); 65 66 //Buttons for the list tab 67 void acquireObjectData(); 68 void abortDownload(); 69 70 //Online search 71 void sendQuery(); 72 void sendQueryToUrl(QUrl url); 73 void abortQuery(); 74 void updateCountdown(); 75 void resetNotFound(); 76 77 //Network 78 void updateDownloadProgress(qint64 bytesReceived, qint64 bytesTotal); 79 void updateQueryProgress(qint64 bytesReceived, qint64 bytesTotal); 80 void downloadComplete(QNetworkReply * reply); 81 void receiveQueryReply(QNetworkReply * reply); 82 void readQueryReply(QNetworkReply * reply); 83 84 //! Marks (checks) all items in the results lists 85 void markAll(); 86 //! Unmarks (unchecks) all items in the results lists 87 void unmarkAll(); 88 89 //! process the marked items 90 void addObjects(); 91 void discardObjects(); 92 93 //! resets the dialog to the state it should be in immediately after createDialogContent();. 94 void resetDialog(); 95 96 private: 97 SolarSystemEditor * ssoManager; 98 QList<SsoElements> candidatesForAddition; 99 QList<SsoElements> candidatesForUpdate; 100 QStandardItemModel * candidateObjectsModel; 101 102 ImportType importType; 103 104 void updateTexts(); 105 106 //! wrapper for the single object function to allow multiple formats. 107 SsoElements readElementsFromString(QString elements); 108 //! wrapper for the file function to allow multiple formats 109 QList<SsoElements> readElementsFromFile(ImportType type, QString filePath); 110 111 void populateBookmarksList(); 112 113 //! Load list dialog with acquired objects and separate existing from new objects 114 void populateCandidateObjects(QList<SsoElements>); 115 void enableInterface(bool enable); 116 117 //Downloading 118 QNetworkAccessManager * networkManager; 119 QNetworkReply * downloadReply; 120 QNetworkReply * queryReply; 121 class StelProgressController * downloadProgressBar; 122 class StelProgressController * queryProgressBar; 123 void startDownload(QString url); 124 void deleteDownloadProgressBar(); 125 void deleteQueryProgressBar(); 126 127 typedef QHash<QString,QString> Bookmarks; 128 QHash<ImportType, Bookmarks> bookmarks; 129 void loadBookmarks(); 130 void loadBookmarksGroup(QVariantMap source, Bookmarks & bookmarkGroup); 131 void saveBookmarks(); 132 void saveBookmarksGroup(Bookmarks & bookmarkGroup, QVariantMap & output); 133 134 //Online search 135 QString query; 136 int countdown; 137 QTimer * countdownTimer; 138 void startCountdown(); 139 void resetCountdown(); 140 141 protected: 142 virtual void createDialogContent(); 143 Ui_mpcImportWindow * ui; 144 }; 145 146 #endif // MPCIMPORTWINDOW_HPP 147