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