]> git.sur5r.net Git - minitube/blob - src/mainwindow.h
e377a2fe3fd5bd8bec8af55161382a42c8a5bd77
[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 #ifdef APP_PHONON
26 #include <phonon/audiooutput.h>
27 #include <phonon/volumeslider.h>
28 #include <phonon/mediaobject.h>
29 #include <phonon/seekslider.h>
30 #endif
31
32 class HomeView;
33 class MediaView;
34 class DownloadView;
35
36 class SearchLineEdit;
37 class UpdateChecker;
38 class SearchParams;
39 class VideoSource;
40 class Suggestion;
41 class ToolbarMenu;
42
43 class MainWindow : public QMainWindow {
44
45     Q_OBJECT
46
47 public:
48     static MainWindow* instance();
49     MainWindow();
50 #ifdef APP_PHONON_SEEK
51     Phonon::SeekSlider* getSeekSlider() { return seekSlider; }
52 #else
53     QSlider* getSlider() { return slider; }
54 #endif
55 #ifdef APP_PHONON
56     Phonon::AudioOutput* getAudioOutput() { return audioOutput; }
57     Phonon::VolumeSlider *getVolumeSlider() { return volumeSlider; }
58 #endif
59     QLabel *getCurrentTimeLabel() { return currentTimeLabel; }
60     void readSettings();
61     void writeSettings();
62     static void printHelp();
63     QStackedWidget *getViews() { return views; }
64     MediaView* getMediaView() { return mediaView; }
65     HomeView* getHomeView() { return homeView; }
66     QAction* getRegionAction() { return regionAction; }
67     SearchLineEdit *getToolbarSearch() { return toolbarSearch; }
68
69     QAction *getAction(const char *name);
70     void addNamedAction(const QByteArray &name, QAction *action);
71
72     QMenu *getMenu(const char *name);
73
74     void showActionInStatusBar(QAction*, bool show);
75     void setStatusBarVisibility(bool show);
76     void adjustStatusBarVisibility();
77
78     void hideToolbar();
79     void showToolbar();
80
81 #ifdef APP_ACTIVATION
82     void showActivationView();
83 #endif
84
85 public slots:
86     void showHome();
87     void showMedia(SearchParams *params);
88     void showMedia(VideoSource *videoSource);
89     void showRegionsView();
90     void restore();
91     void messageReceived(const QString &message);
92     void quit();
93     void suggestionAccepted(Suggestion *suggestion);
94     void search(const QString &query);
95     bool canGoBack() { return history.size() > 1; }
96     void goBack();
97     void showMessage(const QString &message);
98     void hideMessage();
99     bool isReallyFullScreen();
100     bool isCompact() { return compactModeActive; }
101     void missingKeyWarning();
102     void visitSite();
103
104 signals:
105     void currentTimeChanged(const QString &s);
106     void viewChanged();
107
108 protected:
109     void changeEvent(QEvent *e);
110     void closeEvent(QCloseEvent *e);
111     void showEvent(QShowEvent *e);
112     bool eventFilter(QObject *obj, QEvent *e);
113     void dragEnterEvent(QDragEnterEvent *e);
114     void dropEvent(QDropEvent *e);
115     void resizeEvent(QResizeEvent *e);
116     void moveEvent(QMoveEvent *e);
117     void leaveEvent(QEvent *e);
118     void enterEvent(QEvent *e);
119
120 private slots:
121     void lazyInit();
122     void checkForUpdate();
123     void gotNewVersion(const QString &version);
124     void donate();
125     void reportIssue();
126     void about();
127     void toggleFullscreen();
128     void updateUIForFullscreen();
129     void compactView(bool enable);
130     void stop();
131 #ifdef APP_PHONON
132     void stateChanged(Phonon::State newState, Phonon::State oldState);
133 #endif
134     void searchFocus();
135     void tick(qint64 time);
136     void totalTimeChanged(qint64 time);
137     void setDefinitionMode(const QString &definitionName);
138     void toggleDefinitionMode();
139     void clearRecentKeywords();
140
141     void volumeUp();
142     void volumeDown();
143     void volumeMute();
144     void volumeMutedChanged(bool muted);
145
146     void updateDownloadMessage(const QString &);
147     void downloadsFinished();
148     void toggleDownloads(bool show);
149
150     void setManualPlay(bool enabled);
151     void floatOnTop(bool, bool showAction = true);
152     void showStopAfterThisInStatusBar(bool show);
153     void hideFullscreenUI();
154
155     void toggleMenuVisibility();
156     void toggleMenuVisibilityWithMessage();
157     void toggleToolbarMenu();
158
159 #ifdef APP_MAC_STORE
160     void rateOnAppStore();
161 #endif
162
163 private:
164 #ifdef APP_PHONON
165     void initPhonon();
166 #endif
167     void createActions();
168     void createMenus();
169     void createToolBars();
170     void createStatusBar();
171     void showWidget(QWidget*, bool transition = true);
172     static QString formatTime(qint64 duration);
173     bool confirmQuit();
174     void simpleUpdateDialog(const QString &version);
175     bool needStatusBar();
176     void adjustMessageLabelPosition();
177
178     UpdateChecker *updateChecker;
179
180     QHash<QByteArray, QAction*> actionMap;
181     QHash<QByteArray, QMenu*> menuMap;
182
183     // view mechanism
184     QStackedWidget *views;
185     QStack<QWidget*> history;
186     // QVector<QAction*> viewActions;
187
188     // view widgets
189     HomeView *homeView;
190     MediaView *mediaView;
191     QWidget *aboutView;
192     QWidget *downloadView;
193     QWidget *regionsView;
194
195     // actions
196     QAction *backAct;
197     QAction *quitAct;
198     QAction *siteAct;
199     QAction *donateAct;
200     QAction *aboutAct;
201     QAction *searchFocusAct;
202
203     // media actions
204     QAction *skipBackwardAct;
205     QAction *skipAct;
206     QAction *pauseAct;
207     QAction *stopAct;
208     QAction *fullscreenAct;
209     QAction *compactViewAct;
210     QAction *webPageAct;
211     QAction *copyPageAct;
212     QAction *copyLinkAct;
213     QAction *volumeUpAct;
214     QAction *volumeDownAct;
215     QAction *volumeMuteAct;
216     QAction *findVideoPartsAct;
217
218     // playlist actions
219     QAction *removeAct;
220     QAction *moveDownAct;
221     QAction *moveUpAct;
222     QAction *fetchMoreAct;
223     QAction *clearAct;
224
225     // menus
226     QMenu *fileMenu;
227     QMenu *viewMenu;
228     QMenu *playlistMenu;
229     QMenu *helpMenu;
230
231     // toolbar & statusbar
232     QToolBar *mainToolBar;
233     SearchLineEdit *toolbarSearch;
234     QToolBar *statusToolBar;
235     QAction *regionAction;
236
237     // phonon
238 #ifdef APP_PHONON
239 #ifdef APP_PHONON_SEEK
240     Phonon::SeekSlider *seekSlider;
241 #else
242     QSlider *slider;
243 #endif
244     Phonon::VolumeSlider *volumeSlider;
245     Phonon::MediaObject *mediaObject;
246     Phonon::AudioOutput *audioOutput;
247 #endif
248     QLabel *currentTimeLabel;
249
250     bool fullScreenActive;
251     bool maximizedBeforeFullScreen;
252     bool menuVisibleBeforeFullScreen;
253     QTimer *fullscreenTimer;
254     bool compactModeActive;
255     bool menuVisibleBeforeCompactMode;
256     bool initialized;
257
258     QLabel *messageLabel;
259     QTimer *messageTimer;
260
261     ToolbarMenu *toolbarMenu;
262     QToolButton *toolbarMenuButton;
263 };
264
265 #endif