1 /*****************************************************************************
2  * main_interface.hpp : Main Interface
3  ****************************************************************************
4  * Copyright (C) 2006-2010 VideoLAN and AUTHORS
5  * $Id: 5f60d2f3078fb7db81f4a5ccfb5cb849ecd4dbeb $
6  *
7  * Authors: Clément Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24 
25 #ifndef QVLC_MAIN_INTERFACE_H_
26 #define QVLC_MAIN_INTERFACE_H_
27 
28 #include "qt.hpp"
29 
30 #include "util/qvlcframe.hpp"
31 
32 #include <QSystemTrayIcon>
33 #include <QStackedWidget>
34 
35 #ifdef _WIN32
36 # include <shobjidl.h>
37 #endif
38 
39 class QSettings;
40 class QCloseEvent;
41 class QKeyEvent;
42 class QLabel;
43 class QEvent;
44 class VideoWidget;
45 class BackgroundWidget;
46 class PlaylistWidget;
47 class VisualSelector;
48 class ControlsWidget;
49 class InputControlsWidget;
50 class FullscreenControllerWidget;
51 class QVBoxLayout;
52 class QMenu;
53 class QSize;
54 class QScreen;
55 class QTimer;
56 class StandardPLPanel;
57 struct vout_window_t;
58 
59 class MainInterface : public QVLCMW
60 {
61     Q_OBJECT
62 
63     friend class PlaylistWidget;
64 
65 public:
66     /* tors */
67     MainInterface( intf_thread_t *);
68     virtual ~MainInterface();
69 
70     static const QEvent::Type ToolbarsNeedRebuild;
71 
72     /* Video requests from core */
73     bool getVideo( struct vout_window_t *,
74                    unsigned int i_width, unsigned int i_height, bool );
75     void releaseVideo( void );
76     int  controlVideo( int i_query, va_list args );
77 
78     /* Getters */
getSysTray()79     QSystemTrayIcon *getSysTray() { return sysTray; }
getSysTrayMenu()80     QMenu *getSysTrayMenu() { return systrayMenu; }
getFullscreenControllerWidget()81     FullscreenControllerWidget* getFullscreenControllerWidget() { return fullscreenControls; }
82     enum
83     {
84         CONTROLS_VISIBLE  = 0x1,
85         CONTROLS_HIDDEN   = 0x2,
86         CONTROLS_ADVANCED = 0x4,
87     };
88     enum
89     {
90         RAISE_NEVER,
91         RAISE_VIDEO,
92         RAISE_AUDIO,
93         RAISE_AUDIOVIDEO,
94     };
95     int getControlsVisibilityStatus();
isPlDocked()96     bool isPlDocked() { return ( b_plDocked != false ); }
isInterfaceFullScreen()97     bool isInterfaceFullScreen() { return b_interfaceFullScreen; }
isInterfaceAlwaysOnTop()98     bool isInterfaceAlwaysOnTop() { return b_interfaceOnTop; }
99     StandardPLPanel* getPlaylistView();
100 
101 protected:
dropEventPlay(QDropEvent * event,bool b_play)102     void dropEventPlay( QDropEvent* event, bool b_play ) { dropEventPlay(event, b_play, true); }
103     void dropEventPlay( QDropEvent *, bool, bool );
104     void changeEvent( QEvent * ) Q_DECL_OVERRIDE;
105     void dropEvent( QDropEvent *) Q_DECL_OVERRIDE;
106     void dragEnterEvent( QDragEnterEvent * ) Q_DECL_OVERRIDE;
107     void dragMoveEvent( QDragMoveEvent * ) Q_DECL_OVERRIDE;
108     void dragLeaveEvent( QDragLeaveEvent * ) Q_DECL_OVERRIDE;
109     void closeEvent( QCloseEvent *) Q_DECL_OVERRIDE;
110     void keyPressEvent( QKeyEvent *) Q_DECL_OVERRIDE;
111     void wheelEvent( QWheelEvent * ) Q_DECL_OVERRIDE;
112     bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE;
113     virtual void toggleUpdateSystrayMenuWhenVisible();
114     void resizeWindow(int width, int height);
115 
116 protected:
117     /* Main Widgets Creation */
118     void createMainWidget( QSettings* );
119     void createStatusBar();
120     void createPlaylist();
121     void createResumePanel( QWidget *w );
122 
123     /* Systray */
124     void createSystray();
125     void initSystray();
126     void handleSystray();
127 
128     /* Central StackWidget Management */
129     void showTab( QWidget *, bool video_closing = false );
130     void showVideo();
131     void restoreStackOldWidget( bool video_closing = false );
132 
133     /* */
134     void displayNormalView();
135     void setMinimalView( bool );
136     void setInterfaceFullScreen( bool );
137     void computeMinimumSize();
138 
139     /* */
140     QSettings           *settings;
141     QSystemTrayIcon     *sysTray;
142     QMenu               *systrayMenu;
143 
144     QString              input_name;
145     QVBoxLayout         *mainLayout;
146     ControlsWidget      *controls;
147     InputControlsWidget *inputC;
148     FullscreenControllerWidget *fullscreenControls;
149 
150     /* Widgets */
151     QStackedWidget      *stackCentralW;
152 
153     VideoWidget         *videoWidget;
154     BackgroundWidget    *bgWidget;
155     PlaylistWidget      *playlistWidget;
156     //VisualSelector      *visualSelector;
157 
158     /* resume panel */
159     QWidget             *resumePanel;
160     QTimer              *resumeTimer;
161     int64_t             i_resumeTime;
162 
163     /* Status Bar */
164     QLabel              *nameLabel;
165     QLabel              *cryptedLabel;
166 
167     /* Status and flags */
168     QWidget             *stackCentralOldWidget;
169     QPoint              lastWinPosition;
170     QSize               lastWinSize;  /// To restore the same window size when leaving fullscreen
171     QScreen             *lastWinScreen;
172 
173     QMap<QWidget *, QSize> stackWidgetsSizes;
174 
175     /* Flags */
176     unsigned             i_notificationSetting; /// Systray Notifications
177     bool                 b_autoresize;          ///< persistent resizable window
178     bool                 b_videoFullScreen;     ///< --fullscreen
179     bool                 b_hideAfterCreation;
180     bool                 b_minimalView;         ///< Minimal video
181     bool                 b_interfaceFullScreen;
182     bool                 b_interfaceOnTop;      ///keep UI on top
183     bool                 b_pauseOnMinimize;
184     bool                 b_maximizedView;
185     bool                 b_isWindowTiled;
186 #ifdef QT5_HAS_WAYLAND
187     bool                 b_hasWayland;
188 #endif
189     /* States */
190     bool                 playlistVisible;       ///< Is the playlist visible ?
191 //    bool                 videoIsActive;       ///< Having a video now / THEMIM->hasV
192 //    bool                 b_visualSelectorEnabled;
193     bool                 b_plDocked;            ///< Is the playlist docked ?
194 
195     bool                 b_hasPausedWhenMinimized;
196     bool                 b_statusbarVisible;
197 
198     static const Qt::Key kc[10]; /* easter eggs */
199     int i_kc_offset;
200 
201 public slots:
202     void dockPlaylist( bool b_docked = true );
203     void toggleMinimalView( bool );
204     void togglePlaylist();
205     void toggleUpdateSystrayMenu();
206     void showUpdateSystrayMenu();
207     void hideUpdateSystrayMenu();
208     void toggleAdvancedButtons();
209     void toggleInterfaceFullScreen();
210     void toggleFSC();
211     void setInterfaceAlwaysOnTop( bool );
212 
213     void setStatusBarVisibility(bool b_visible);
214     void setPlaylistVisibility(bool b_visible);
215 
216     /* Manage the Video Functions from the vout threads */
217     void getVideoSlot( struct vout_window_t *,
218                        unsigned i_width, unsigned i_height, bool, bool * );
219     void releaseVideoSlot( void );
220 
221     void emitBoss();
222     void emitRaise();
223 
224     virtual void reloadPrefs();
225     void toolBarConfUpdated();
226 
227 protected slots:
228     void debug();
229     void recreateToolbars();
230     void setName( const QString& );
231     void setVLCWindowsTitle( const QString& title = "" );
232     void handleSystrayClick( QSystemTrayIcon::ActivationReason );
233     void updateSystrayTooltipName( const QString& );
234     void updateSystrayTooltipStatus( int );
235     void showCryptedLabel( bool );
236 
237     void handleKeyPress( QKeyEvent * );
238 
239     void showBuffering( float );
240 
resizeStack(int w,int h)241     void resizeStack( int w, int h )
242     {
243         if( !isFullScreen() && !isMaximized() && !b_isWindowTiled )
244         {
245             if( b_minimalView )
246                 resizeWindow( w, h ); /* Oh yes, it shouldn't
247                                    be possible that size() - stackCentralW->size() < 0
248                                    since stackCentralW is contained in the QMW... */
249             else
250                 resizeWindow( width() - stackCentralW->width() + w, height() - stackCentralW->height() + h );
251         }
252         debug();
253     }
254 
255     void setVideoSize( unsigned int, unsigned int );
256     void videoSizeChanged( int, int );
257     virtual void setVideoFullScreen( bool );
258     void setHideMouse( bool );
259     void setVideoOnTop( bool );
260     void setBoss();
261     void setRaise();
262     void voutReleaseMouseEvents();
263 
264     void showResumePanel( int64_t);
265     void hideResumePanel();
266     void resumePlayback();
267     void onInputChanged( bool );
268 
269 signals:
270     void askGetVideo( struct vout_window_t *, unsigned, unsigned, bool,
271                       bool * );
272     void askReleaseVideo( );
273     void askVideoToResize( unsigned int, unsigned int );
274     void askVideoSetFullScreen( bool );
275     void askHideMouse( bool );
276     void askVideoOnTop( bool );
277     void minimalViewToggled( bool );
278     void fullscreenInterfaceToggled( bool );
279     void askToQuit();
280     void askBoss();
281     void askRaise();
282     void kc_pressed(); /* easter eggs */
283 };
284 
285 #endif
286