]> git.sur5r.net Git - minitube/blob - src/mainwindow.h
New upstream version 3.8
[minitube] / src / mainwindow.h
1 /* $BEGIN_LICENSE
2
3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
5
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Minitube 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 Minitube.  If not, see <http://www.gnu.org/licenses/>.
18
19 $END_LICENSE */
20
21 #ifndef MAINWINDOW_H
22 #define MAINWINDOW_H
23
24 #include <QtWidgets>
25
26 #include "media.h"
27
28 class View;
29 class HomeView;
30 class MediaView;
31 class DownloadView;
32
33 class SearchLineEdit;
34 class SearchParams;
35 class VideoSource;
36 class Suggestion;
37 class ToolbarMenu;
38
39 class MainWindow : public QMainWindow {
40     Q_OBJECT
41
42 public:
43     static MainWindow *instance();
44     MainWindow();
45
46     QSlider *getSeekSlider() { return seekSlider; }
47     QSlider *getVolumeSlider() { return volumeSlider; }
48
49     QLabel *getCurrentTimeLabel() { return currentTimeLabel; }
50     void readSettings();
51     void writeSettings();
52     static void printHelp();
53     QStackedWidget *getViews() { return views; }
54     MediaView *getMediaView() { return mediaView; }
55     HomeView *getHomeView() { return homeView; }
56     QAction *getRegionAction() { return regionAction; }
57     SearchLineEdit *getToolbarSearch() { return toolbarSearch; }
58
59     void setupAction(QAction *action);
60     QAction *getAction(const char *name);
61     void addNamedAction(const QByteArray &name, QAction *action);
62
63     QMenu *getMenu(const char *name);
64
65     void showActionsInStatusBar(const QVector<QAction *> &actions, bool show);
66     void setStatusBarVisibility(bool show);
67     void adjustStatusBarVisibility();
68
69     void hideToolbar();
70     void showToolbar();
71
72 #ifdef APP_ACTIVATION
73     void showActivationView();
74 #endif
75
76 public slots:
77     void showHome();
78     void showMedia(SearchParams *params);
79     void showMedia(VideoSource *videoSource);
80     void showRegionsView();
81     void restore();
82     void messageReceived(const QString &message);
83     void quit();
84     void suggestionAccepted(Suggestion *suggestion);
85     void search(const QString &query);
86     bool canGoBack() { return history.size() > 1; }
87     void goBack();
88     void showMessage(const QString &message);
89     void hideMessage();
90     void handleError(const QString &message);
91     bool isReallyFullScreen();
92     bool isCompact() { return compactModeActive; }
93     void missingKeyWarning();
94     void visitSite();
95     void setDefinitionMode(const QString &definitionName);
96
97 signals:
98     void currentTimeChanged(const QString &s);
99     void viewChanged();
100
101 protected:
102     void changeEvent(QEvent *e);
103     void closeEvent(QCloseEvent *e);
104     void showEvent(QShowEvent *e);
105     bool eventFilter(QObject *obj, QEvent *e);
106     void dragEnterEvent(QDragEnterEvent *e);
107     void dropEvent(QDropEvent *e);
108     void resizeEvent(QResizeEvent *e);
109     void leaveEvent(QEvent *e);
110     void enterEvent(QEvent *e);
111
112 private slots:
113     void lazyInit();
114     void donate();
115     void reportIssue();
116     void about();
117     void toggleFullscreen();
118     void updateUIForFullscreen();
119     void compactView(bool enable);
120     void stop();
121     void searchFocus();
122     void toggleDefinitionMode();
123     void clearRecentKeywords();
124
125     // media
126     void stateChanged(Media::State state);
127     void tick(qint64 time);
128
129     void volumeUp();
130     void volumeDown();
131     void toggleVolumeMute();
132     void volumeChanged(qreal newVolume);
133     void volumeMutedChanged(bool muted);
134
135     void updateDownloadMessage(const QString &);
136     void downloadsFinished();
137     void toggleDownloads(bool show);
138
139     void setManualPlay(bool enabled);
140     void floatOnTop(bool, bool showAction = true);
141     void showStopAfterThisInStatusBar(bool show);
142     void hideFullscreenUI();
143
144     void toggleMenuVisibility();
145     void toggleMenuVisibilityWithMessage();
146     void toggleToolbarMenu();
147
148 #ifdef APP_MAC_STORE
149     void rateOnAppStore();
150 #endif
151
152 private:
153     void initMedia();
154     void createActions();
155     void createMenus();
156     void createToolBar();
157     void createStatusBar();
158     void showView(View *view, bool transition = false);
159     static QString formatTime(qint64 duration);
160     bool confirmQuit();
161     bool needStatusBar();
162     void adjustMessageLabelPosition();
163
164     QHash<QByteArray, QAction *> actionMap;
165     QHash<QByteArray, QMenu *> menuMap;
166
167     // view mechanism
168     QStackedWidget *views;
169     QStack<View *> history;
170
171     // view widgets
172     HomeView *homeView;
173     MediaView *mediaView;
174     View *aboutView;
175     View *downloadView;
176     View *regionsView;
177     View *subscriptionImportView = nullptr;
178
179     // actions
180     QAction *backAct;
181     QAction *quitAct;
182     QAction *siteAct;
183     QAction *donateAct;
184     QAction *aboutAct;
185     QAction *searchFocusAct;
186
187     // media actions
188     QAction *skipBackwardAct;
189     QAction *skipAct;
190     QAction *pauseAct;
191     QAction *stopAct;
192     QAction *fullscreenAct;
193     QAction *compactViewAct;
194     QAction *webPageAct;
195     QAction *copyPageAct;
196     QAction *copyLinkAct;
197     QAction *volumeUpAct;
198     QAction *volumeDownAct;
199     QAction *volumeMuteAct;
200     QAction *findVideoPartsAct;
201
202     // playlist actions
203     QAction *removeAct;
204     QAction *moveDownAct;
205     QAction *moveUpAct;
206     QAction *fetchMoreAct;
207     QAction *clearAct;
208
209     // menus
210     QMenu *fileMenu;
211     QMenu *viewMenu;
212     QMenu *playlistMenu;
213     QMenu *helpMenu;
214
215     // toolbar & statusbar
216     QToolBar *mainToolBar;
217     SearchLineEdit *toolbarSearch;
218     QToolBar *statusToolBar;
219     QAction *regionAction;
220     QSlider *seekSlider;
221     QSlider *volumeSlider;
222     QLabel *currentTimeLabel;
223
224     bool fullScreenActive;
225     bool maximizedBeforeFullScreen;
226     bool menuVisibleBeforeFullScreen;
227     QTimer *fullscreenTimer;
228     bool compactModeActive;
229     bool menuVisibleBeforeCompactMode;
230     bool initialized;
231
232     QLabel *messageLabel;
233     QTimer *messageTimer;
234
235     ToolbarMenu *toolbarMenu;
236     QToolButton *toolbarMenuButton;
237
238     Media *media;
239 };
240
241 #endif