1 /*
2     SPDX-FileCopyrightText: 2012 Samikshan Bairagya <samikshan@gmail.com>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <QString>
10 #include <QWidget>
11 
12 #include <memory>
13 
14 class QNetworkAccessManager;
15 class QQmlContext;
16 class QQuickItem;
17 class QQuickView;
18 
19 class ModelManager;
20 class ObsConditions;
21 class SkyObject;
22 class SkyObjItem;
23 
24 /**
25  * @class WIView
26  * @brief Manages the QML user interface for What's Interesting. WIView is used to display the
27  * QML UI using a QQuickView. It acts on all signals emitted by the UI and manages the data
28  * sent to the UI for display.
29  *
30  * @author Samikshan Bairagya
31  */
32 class WIView : public QWidget
33 {
34     Q_OBJECT
35   public:
36     /**
37      * @brief Constructor - Store QML components as QObject pointers.
38      * Connect signals from various QML components into public slots.
39      * Displays the user interface for What's Interesting
40      */
41     explicit WIView(QWidget *parent = nullptr);
42 
43     virtual ~WIView() override = default;
44 
45     /** Load details-view for selected sky-object */
46     void loadDetailsView(SkyObjItem *soitem, int index);
47 
48     /** Updates sky-object list models */
49     void updateModel(ObsConditions& obs);
50 
getWIBaseView()51     inline QQuickView *getWIBaseView() const { return m_BaseView; }
52 
53   public slots:
54 
55     /**
56      * @brief public slot - Act upon signal emitted when category of sky-object is selected
57      * from category selection view of the QML UI.
58      * @param model Category selected
59      */
60     void onCategorySelected(QString model);
61 
62     /**
63      * @brief public slot - Act upon signal emitted when an item is selected from list of sky-objects.
64      * Display details-view for the skyobject selected.
65      * @param index       Index of item in the list of skyobjects.
66      */
67     void onSoListItemClicked(int index);
68 
69     /** public slot - Show details-view for next sky-object from list of current sky-objects's category. */
70     void onNextObjClicked();
71 
72     /**
73      * @brief public slot - Show details-view for previous sky-object from list of current sky-objects's
74      * category.
75      */
76     void onPrevObjClicked();
77 
78     /** public slot - Slew map to current sky-object in the details view. */
79     void onCenterButtonClicked();
80 
81     /** public slot - Slew map to current sky-object in the details view. */
82     void onSlewTelescopeButtonClicked();
83 
84     /** public slot - Open Details Dialog to show more details for current sky-object. */
85     void onDetailsButtonClicked();
86 
87     /** public slot - Open WI settings dialog. */
88     void onSettingsIconClicked();
89 
onInspectIconClicked(bool checked)90     void onInspectIconClicked(bool checked) { inspectOnClick = checked; }
91 
92     /** public slot - Reload list of visible sky-objects. */
93     void onReloadIconClicked();
94 
95     void onVisibleIconClicked(bool checked);
96 
97     void onFavoriteIconClicked(bool checked);
98 
99     void onUpdateIconClicked();
100 
101     void updateWikipediaDescription(SkyObjItem *soitem);
102     void loadObjectDescription(SkyObjItem *soitem);
103     void tryToUpdateWikipediaInfo(SkyObjItem *soitem, QString name);
104     void loadObjectInfoBox(SkyObjItem *soitem);
105     void saveImageURL(SkyObjItem *soitem, QString imageURL);
106     void saveInfoURL(SkyObjItem *soitem, QString infoURL);
107     void saveObjectInfoBoxText(SkyObjItem *soitem, QString type, QString infoText);
108     void downloadWikipediaImage(SkyObjItem *soitem, QString imageURL);
109     void inspectSkyObject(const QString& name);
110     void inspectSkyObjectOnClick(SkyObject *obj);
111     void inspectSkyObject(SkyObject *obj);
inspectOnClickIsActive()112     bool inspectOnClickIsActive() { return inspectOnClick; }
113     void updateObservingConditions();
114     void tryToUpdateWikipediaInfoInModel(bool onlyMissing);
115     void refreshListView();
116     void updateProgress(double value);
117     void setProgressBarVisible(bool visible);
118     void setNightVisionOn(bool on);
119 
120   private:
121     QString getWikipediaName(SkyObjItem *soitem);
122 
123     QQuickItem *m_BaseObj { nullptr };
124     QQuickItem *m_ViewsRowObj { nullptr };
125     QQuickItem *m_CategoryTitle { nullptr };
126     QQuickItem *m_SoListObj { nullptr };
127     QQuickItem *m_DetailsViewObj { nullptr };
128     QQuickItem *m_ProgressBar { nullptr };
129     QQuickItem *m_loadingMessage { nullptr };
130     QQuickItem *m_NextObj { nullptr };
131     QQuickItem *m_PrevObj { nullptr };
132     QQuickItem *m_CenterButtonObj { nullptr };
133     QQuickItem *m_SlewTelescopeButtonObj { nullptr };
134     QQuickItem *m_DetailsButtonObj { nullptr };
135     QQuickItem *inspectIconObj { nullptr };
136     QQuickItem *visibleIconObj { nullptr };
137     QQuickItem *favoriteIconObj { nullptr };
138     QQmlContext *m_Ctxt { nullptr };
139     QObject *infoBoxText { nullptr };
140     QObject *descTextObj { nullptr };
141     QObject *nightVision { nullptr };
142     QObject *autoTrackCheckbox { nullptr };
143     QObject *autoCenterCheckbox { nullptr };
144 
145     QQuickView *m_BaseView { nullptr };
146     ObsConditions *m_Obs { nullptr };
147     std::unique_ptr<ModelManager> m_ModManager;
148     /// Current sky object item.
149     SkyObjItem *m_CurSoItem { nullptr };
150     /// Created sky object item on-demand
151     std::unique_ptr<SkyObjItem> trackedItem;
152     /// Index of current sky-object item in Details view.
153     int m_CurIndex { 0 };
154     /// Currently selected category from WI QML view
155     QString m_CurrentObjectListName;
156     std::unique_ptr<QNetworkAccessManager> manager;
157     bool inspectOnClick { false };
158 };
159