]> git.sur5r.net Git - minitube/blob - src/mainwindow.h
New upstream version 3.1
[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 checkForUpdate();
115     void donate();
116     void reportIssue();
117     void about();
118     void toggleFullscreen();
119     void updateUIForFullscreen();
120     void compactView(bool enable);
121     void stop();
122     void searchFocus();
123     void toggleDefinitionMode();
124     void clearRecentKeywords();
125
126     // media
127     void stateChanged(Media::State state);
128     void tick(qint64 time);
129
130     void volumeUp();
131     void volumeDown();
132     void toggleVolumeMute();
133     void volumeChanged(qreal newVolume);
134     void volumeMutedChanged(bool muted);
135
136     void updateDownloadMessage(const QString &);
137     void downloadsFinished();
138     void toggleDownloads(bool show);
139
140     void setManualPlay(bool enabled);
141     void floatOnTop(bool, bool showAction = true);
142     void showStopAfterThisInStatusBar(bool show);
143     void hideFullscreenUI();
144
145     void toggleMenuVisibility();
146     void toggleMenuVisibilityWithMessage();
147     void toggleToolbarMenu();
148
149 #ifdef APP_MAC_STORE
150     void rateOnAppStore();
151 #endif
152
153 private:
154     void initMedia();
155     void createActions();
156     void createMenus();
157     void createToolBar();
158     void createStatusBar();
159     void showView(View *view, bool transition = false);
160     static QString formatTime(qint64 duration);
161     bool confirmQuit();
162     void simpleUpdateDialog(const QString &version);
163     bool needStatusBar();
164     void adjustMessageLabelPosition();
165
166     QHash<QByteArray, QAction *> actionMap;
167     QHash<QByteArray, QMenu *> menuMap;
168
169     // view mechanism
170     QStackedWidget *views;
171     QStack<View *> history;
172
173     // view widgets
174     HomeView *homeView;
175     MediaView *mediaView;
176     View *aboutView;
177     View *downloadView;
178     View *regionsView;
179
180     // actions
181     QAction *backAct;
182     QAction *quitAct;
183     QAction *siteAct;
184     QAction *donateAct;
185     QAction *aboutAct;
186     QAction *searchFocusAct;
187
188     // media actions
189     QAction *skipBackwardAct;
190     QAction *skipAct;
191     QAction *pauseAct;
192     QAction *stopAct;
193     QAction *fullscreenAct;
194     QAction *compactViewAct;
195     QAction *webPageAct;
196     QAction *copyPageAct;
197     QAction *copyLinkAct;
198     QAction *volumeUpAct;
199     QAction *volumeDownAct;
200     QAction *volumeMuteAct;
201     QAction *findVideoPartsAct;
202
203     // playlist actions
204     QAction *removeAct;
205     QAction *moveDownAct;
206     QAction *moveUpAct;
207     QAction *fetchMoreAct;
208     QAction *clearAct;
209
210     // menus
211     QMenu *fileMenu;
212     QMenu *viewMenu;
213     QMenu *playlistMenu;
214     QMenu *helpMenu;
215
216     // toolbar & statusbar
217     QToolBar *mainToolBar;
218     SearchLineEdit *toolbarSearch;
219     QToolBar *statusToolBar;
220     QAction *regionAction;
221     QSlider *seekSlider;
222     QSlider *volumeSlider;
223     QLabel *currentTimeLabel;
224
225     bool fullScreenActive;
226     bool maximizedBeforeFullScreen;
227     bool menuVisibleBeforeFullScreen;
228     QTimer *fullscreenTimer;
229     bool compactModeActive;
230     bool menuVisibleBeforeCompactMode;
231     bool initialized;
232
233     QLabel *messageLabel;
234     QTimer *messageTimer;
235
236     ToolbarMenu *toolbarMenu;
237     QToolButton *toolbarMenuButton;
238
239     Media *media;
240 };
241
242 #endif