source: smplayer/trunk/src/baseguiplus.cpp@ 176

Last change on this file since 176 was 176, checked in by Silvan Scherrer, 9 years ago

smplayer: update trunk to version 16.4

  • Property svn:eol-style set to LF
File size: 18.1 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include "baseguiplus.h"
20#include "config.h"
21#include "myaction.h"
22#include "global.h"
23#include "images.h"
24#include "playlist.h"
25
26#ifdef Q_OS_WIN
27#include "favorites.h"
28#else
29#include "tvlist.h"
30#endif
31
32#include "widgetactions.h"
33
34#include <QMenu>
35#include <QCloseEvent>
36#include <QApplication>
37#include <QDesktopWidget>
38
39#if DOCK_PLAYLIST
40#include <QDockWidget>
41#include "playlistdock.h"
42#include "desktopinfo.h"
43
44#define PLAYLIST_ON_SIDES 1
45#endif
46
47using namespace Global;
48
49BaseGuiPlus::BaseGuiPlus( QWidget * parent, Qt::WindowFlags flags)
50 : BaseGui( parent, flags )
51{
52 // Initialize variables
53 mainwindow_visible = true;
54 //infowindow_visible = false;
55 trayicon_playlist_was_visible = false;
56 widgets_size = 0;
57#if DOCK_PLAYLIST
58 fullscreen_playlist_was_visible = false;
59 fullscreen_playlist_was_floating = false;
60 compact_playlist_was_visible = false;
61 ignore_playlist_events = false;
62#endif
63
64 mainwindow_pos = pos();
65
66 tray = new QSystemTrayIcon(this);
67
68 tray->setToolTip( "SMPlayer" );
69 connect( tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
70 this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
71
72 quitAct = new MyAction(QKeySequence("Ctrl+Q"), this, "quit");
73 connect( quitAct, SIGNAL(triggered()), this, SLOT(quit()) );
74 openMenu->addAction(quitAct);
75
76 showTrayAct = new MyAction(this, "show_tray_icon" );
77 showTrayAct->setCheckable(true);
78 connect( showTrayAct, SIGNAL(toggled(bool)),
79 tray, SLOT(setVisible(bool)) );
80
81#ifndef Q_OS_OS2
82 optionsMenu->addAction(showTrayAct);
83#else
84 trayAvailable();
85 connect( optionsMenu, SIGNAL(aboutToShow()),
86 this, SLOT(trayAvailable()) );
87#endif
88
89 showAllAct = new MyAction(this, "restore/hide");
90 connect( showAllAct, SIGNAL(triggered()),
91 this, SLOT(toggleShowAll()) );
92
93
94 context_menu = new QMenu(this);
95 context_menu->addAction(showAllAct);
96 context_menu->addSeparator();
97 context_menu->addAction(openFileAct);
98 context_menu->addMenu(recentfiles_menu);
99 context_menu->addAction(openDirectoryAct);
100 context_menu->addAction(openDVDAct);
101 context_menu->addAction(openURLAct);
102 context_menu->addMenu(favorites);
103#ifndef Q_OS_WIN
104 context_menu->addMenu(tvlist);
105 context_menu->addMenu(radiolist);
106#endif
107 context_menu->addSeparator();
108 context_menu->addAction(playOrPauseAct);
109 context_menu->addAction(stopAct);
110 context_menu->addSeparator();
111 context_menu->addAction(playPrevAct);
112 context_menu->addAction(playNextAct);
113 context_menu->addSeparator();
114 context_menu->addAction(showPlaylistAct);
115 context_menu->addAction(showPreferencesAct);
116 context_menu->addSeparator();
117 context_menu->addAction(quitAct);
118
119 tray->setContextMenu( context_menu );
120
121#if DOCK_PLAYLIST
122 // Playlistdock
123 playlistdock = new PlaylistDock(this);
124 playlistdock->setObjectName("playlistdock");
125 playlistdock->setFloating(false); // To avoid that the playlist is visible for a moment
126 playlistdock->setWidget(playlist);
127 playlistdock->setAllowedAreas(Qt::TopDockWidgetArea |
128 Qt::BottomDockWidgetArea
129#if PLAYLIST_ON_SIDES
130 | Qt::LeftDockWidgetArea |
131 Qt::RightDockWidgetArea
132#endif
133 );
134 addDockWidget(Qt::BottomDockWidgetArea, playlistdock);
135 playlistdock->hide();
136 playlistdock->setFloating(true); // Floating by default
137
138 connect( playlistdock, SIGNAL(closed()), this, SLOT(playlistClosed()) );
139#if USE_DOCK_TOPLEVEL_EVENT
140 connect( playlistdock, SIGNAL(topLevelChanged(bool)),
141 this, SLOT(dockTopLevelChanged(bool)) );
142#else
143 connect( playlistdock, SIGNAL(visibilityChanged(bool)),
144 this, SLOT(dockVisibilityChanged(bool)) );
145#endif // USE_DOCK_TOPLEVEL_EVENT
146
147 connect(this, SIGNAL(openFileRequested()), this, SLOT(showAll()));
148
149 ignore_playlist_events = false;
150#endif // DOCK_PLAYLIST
151
152 retranslateStrings();
153
154 loadConfig();
155}
156
157BaseGuiPlus::~BaseGuiPlus() {
158 saveConfig();
159 tray->hide();
160}
161
162bool BaseGuiPlus::startHidden() {
163#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
164 return false;
165#else
166 if ( (!showTrayAct->isChecked()) || (mainwindow_visible) )
167 return false;
168 else
169 return true;
170#endif
171}
172
173void BaseGuiPlus::closeEvent( QCloseEvent * e ) {
174 qDebug("BaseGuiPlus::closeEvent");
175 e->ignore();
176 closeWindow();
177}
178
179void BaseGuiPlus::closeWindow() {
180 qDebug("BaseGuiPlus::closeWindow");
181
182 if (tray->isVisible()) {
183 //e->ignore();
184 exitFullscreen();
185 showAll(false); // Hide windows
186 if (core->state() == Core::Playing) core->stop();
187
188 if (pref->balloon_count > 0) {
189 tray->showMessage( "SMPlayer",
190 tr("SMPlayer is still running here"),
191 QSystemTrayIcon::Information, 3000 );
192 pref->balloon_count--;
193 }
194
195 } else {
196 BaseGui::closeWindow();
197 }
198 //tray->hide();
199
200}
201
202void BaseGuiPlus::quit() {
203 qDebug("BaseGuiPlus::quit");
204 BaseGui::closeWindow();
205}
206
207void BaseGuiPlus::retranslateStrings() {
208 BaseGui::retranslateStrings();
209
210 tray->setIcon(Images::icon("logo", 22));
211
212 quitAct->change( Images::icon("exit"), tr("&Quit") );
213 showTrayAct->change( Images::icon("systray"), tr("S&how icon in system tray") );
214
215 updateShowAllAct();
216
217#if DOCK_PLAYLIST
218 playlistdock->setWindowTitle( tr("Playlist") );
219#endif
220}
221
222void BaseGuiPlus::updateShowAllAct() {
223 if (isVisible())
224 showAllAct->change( tr("&Hide") );
225 else
226 showAllAct->change( tr("&Restore") );
227}
228
229void BaseGuiPlus::saveConfig() {
230 qDebug("BaseGuiPlus::saveConfig");
231
232 QSettings * set = settings;
233
234 set->beginGroup( "base_gui_plus");
235
236 set->setValue( "show_tray_icon", showTrayAct->isChecked() );
237 set->setValue( "mainwindow_visible", isVisible() );
238
239 set->setValue( "trayicon_playlist_was_visible", trayicon_playlist_was_visible );
240 set->setValue( "widgets_size", widgets_size );
241#if DOCK_PLAYLIST
242 set->setValue( "fullscreen_playlist_was_visible", fullscreen_playlist_was_visible );
243 set->setValue( "fullscreen_playlist_was_floating", fullscreen_playlist_was_floating );
244 set->setValue( "compact_playlist_was_visible", compact_playlist_was_visible );
245 set->setValue( "ignore_playlist_events", ignore_playlist_events );
246#endif
247
248/*
249#if DOCK_PLAYLIST
250 set->setValue( "playlist_and_toolbars_state", saveState() );
251#endif
252*/
253
254 set->endGroup();
255}
256
257void BaseGuiPlus::loadConfig() {
258 qDebug("BaseGuiPlus::loadConfig");
259
260 QSettings * set = settings;
261
262 set->beginGroup( "base_gui_plus");
263
264 bool show_tray_icon = set->value( "show_tray_icon", false).toBool();
265 showTrayAct->setChecked( show_tray_icon );
266 //tray->setVisible( show_tray_icon );
267
268 mainwindow_visible = set->value("mainwindow_visible", true).toBool();
269
270 trayicon_playlist_was_visible = set->value( "trayicon_playlist_was_visible", trayicon_playlist_was_visible ).toBool();
271 widgets_size = set->value( "widgets_size", widgets_size ).toInt();
272#if DOCK_PLAYLIST
273 fullscreen_playlist_was_visible = set->value( "fullscreen_playlist_was_visible", fullscreen_playlist_was_visible ).toBool();
274 fullscreen_playlist_was_floating = set->value( "fullscreen_playlist_was_floating", fullscreen_playlist_was_floating ).toBool();
275 compact_playlist_was_visible = set->value( "compact_playlist_was_visible", compact_playlist_was_visible ).toBool();
276 ignore_playlist_events = set->value( "ignore_playlist_events", ignore_playlist_events ).toBool();
277#endif
278
279/*
280#if DOCK_PLAYLIST
281 restoreState( set->value( "playlist_and_toolbars_state" ).toByteArray() );
282#endif
283*/
284
285 set->endGroup();
286
287 updateShowAllAct();
288}
289
290
291void BaseGuiPlus::trayIconActivated(QSystemTrayIcon::ActivationReason reason) {
292 qDebug("DefaultGui::trayIconActivated: %d", reason);
293
294 updateShowAllAct();
295
296 if (reason == QSystemTrayIcon::Trigger) {
297 toggleShowAll();
298 }
299 else
300 if (reason == QSystemTrayIcon::MiddleClick) {
301 core->pause();
302 }
303}
304
305void BaseGuiPlus::toggleShowAll() {
306 // Ignore if tray is not visible
307 if (tray->isVisible()) {
308 showAll( !isVisible() );
309 }
310}
311
312void BaseGuiPlus::showAll() {
313 if (!isVisible()) showAll(true);
314}
315
316void BaseGuiPlus::showAll(bool b) {
317 if (!b) {
318 // Hide all
319#if DOCK_PLAYLIST
320 trayicon_playlist_was_visible = (playlistdock->isVisible() &&
321 playlistdock->isFloating() );
322 if (trayicon_playlist_was_visible)
323 playlistdock->hide();
324
325 /*
326 trayicon_playlist_was_visible = playlistdock->isVisible();
327 playlistdock->hide();
328 */
329#else
330 trayicon_playlist_was_visible = playlist->isVisible();
331 playlist_pos = playlist->pos();
332 playlist->hide();
333#endif
334
335 mainwindow_pos = pos();
336 hide();
337
338 /*
339 infowindow_visible = info_window->isVisible();
340 infowindow_pos = info_window->pos();
341 info_window->hide();
342 */
343 } else {
344 // Show all
345 move(mainwindow_pos);
346 show();
347
348#if DOCK_PLAYLIST
349 if (trayicon_playlist_was_visible) {
350 playlistdock->show();
351 }
352#else
353 if (trayicon_playlist_was_visible) {
354 playlist->move(playlist_pos);
355 playlist->show();
356 }
357#endif
358
359 /*
360 if (infowindow_visible) {
361 info_window->show();
362 info_window->move(infowindow_pos);
363 }
364 */
365 }
366 updateShowAllAct();
367}
368
369void BaseGuiPlus::resizeWindow(int w, int h) {
370 qDebug("BaseGuiPlus::resizeWindow: %d, %d", w, h);
371
372 if ( (tray->isVisible()) && (!isVisible()) ) showAll(true);
373
374 BaseGui::resizeWindow(w, h );
375}
376
377void BaseGuiPlus::updateMediaInfo() {
378 qDebug("BaseGuiPlus::updateMediaInfo");
379 BaseGui::updateMediaInfo();
380
381 tray->setToolTip( windowTitle() );
382}
383
384void BaseGuiPlus::setWindowCaption(const QString & title) {
385 tray->setToolTip( title );
386
387 BaseGui::setWindowCaption( title );
388}
389
390
391// Playlist stuff
392void BaseGuiPlus::aboutToEnterFullscreen() {
393 qDebug("BaseGuiPlus::aboutToEnterFullscreen");
394
395 BaseGui::aboutToEnterFullscreen();
396
397#if DOCK_PLAYLIST
398 playlistdock->setAllowedAreas(Qt::NoDockWidgetArea);
399
400 int playlist_screen = QApplication::desktop()->screenNumber(playlistdock);
401 int mainwindow_screen = QApplication::desktop()->screenNumber(this);
402 qDebug("BaseGuiPlus::aboutToEnterFullscreen: mainwindow screen: %d, playlist screen: %d", mainwindow_screen, playlist_screen);
403
404 fullscreen_playlist_was_visible = playlistdock->isVisible();
405 fullscreen_playlist_was_floating = playlistdock->isFloating();
406
407 ignore_playlist_events = true;
408
409 // Hide the playlist if it's in the same screen as the main window
410 if ((playlist_screen == mainwindow_screen) /* ||
411 (!fullscreen_playlist_was_floating) */ )
412 {
413 playlistdock->setFloating(true);
414 playlistdock->hide();
415 }
416#endif
417}
418
419void BaseGuiPlus::aboutToExitFullscreen() {
420 qDebug("BaseGuiPlus::aboutToExitFullscreen");
421
422 BaseGui::aboutToExitFullscreen();
423
424#if DOCK_PLAYLIST
425 playlistdock->setAllowedAreas(Qt::TopDockWidgetArea |
426 Qt::BottomDockWidgetArea
427 #if PLAYLIST_ON_SIDES
428 | Qt::LeftDockWidgetArea |
429 Qt::RightDockWidgetArea
430 #endif
431 );
432
433 if (fullscreen_playlist_was_visible) {
434 playlistdock->show();
435 }
436 playlistdock->setFloating( fullscreen_playlist_was_floating );
437 ignore_playlist_events = false;
438#endif
439}
440
441void BaseGuiPlus::aboutToEnterCompactMode() {
442#if DOCK_PLAYLIST
443 compact_playlist_was_visible = (playlistdock->isVisible() &&
444 !playlistdock->isFloating());
445 if (compact_playlist_was_visible)
446 playlistdock->hide();
447#endif
448
449 widgets_size = height() - panel->height();
450 qDebug("BaseGuiPlus::aboutToEnterCompactMode: widgets_size: %d", widgets_size);
451
452 BaseGui::aboutToEnterCompactMode();
453
454 if (pref->resize_method == Preferences::Always) {
455 resize( width(), height() - widgets_size );
456 }
457}
458
459void BaseGuiPlus::aboutToExitCompactMode() {
460 BaseGui::aboutToExitCompactMode();
461
462 if (pref->resize_method == Preferences::Always) {
463 resize( width(), height() + widgets_size );
464 }
465
466#if DOCK_PLAYLIST
467 if (compact_playlist_was_visible)
468 playlistdock->show();
469#endif
470}
471
472#if DOCK_PLAYLIST
473void BaseGuiPlus::showPlaylist(bool b) {
474 qDebug("BaseGuiPlus::showPlaylist: %d", b);
475 qDebug("BaseGuiPlus::showPlaylist (before): playlist visible: %d", playlistdock->isVisible());
476 qDebug("BaseGuiPlus::showPlaylist (before): playlist position: %d, %d", playlistdock->pos().x(), playlistdock->pos().y());
477 qDebug("BaseGuiPlus::showPlaylist (before): playlist size: %d x %d", playlistdock->size().width(), playlistdock->size().height());
478
479 if ( !b ) {
480 playlistdock->hide();
481 } else {
482 exitFullscreenIfNeeded();
483 playlistdock->show();
484
485 // Check if playlist is outside of the screen
486 if (playlistdock->isFloating()) {
487 if (!DesktopInfo::isInsideScreen(playlistdock)) {
488 qWarning("BaseGuiPlus::showPlaylist: playlist is outside of the screen");
489 playlistdock->move(0,0);
490 }
491 }
492 }
493 //updateWidgets();
494
495 qDebug("BaseGuiPlus::showPlaylist (after): playlist visible: %d", playlistdock->isVisible());
496 qDebug("BaseGuiPlus::showPlaylist (after): playlist position: %d, %d", playlistdock->pos().x(), playlistdock->pos().y());
497 qDebug("BaseGuiPlus::showPlaylist (after): playlist size: %d x %d", playlistdock->size().width(), playlistdock->size().height());
498
499}
500
501void BaseGuiPlus::playlistClosed() {
502 showPlaylistAct->setChecked(false);
503}
504
505#if !USE_DOCK_TOPLEVEL_EVENT
506void BaseGuiPlus::dockVisibilityChanged(bool visible) {
507 qDebug("BaseGuiPlus::dockVisibilityChanged: %d", visible);
508
509 if (!playlistdock->isFloating()) {
510 if (!visible) shrinkWindow(); else stretchWindow();
511 }
512}
513
514#else
515
516void BaseGuiPlus::dockTopLevelChanged(bool floating) {
517 qDebug("BaseGuiPlus::dockTopLevelChanged: %d", floating);
518
519 if (floating) shrinkWindow(); else stretchWindow();
520}
521#endif
522
523void BaseGuiPlus::stretchWindow() {
524 qDebug("BaseGuiPlus::stretchWindow");
525 if ((ignore_playlist_events) || (pref->resize_method!=Preferences::Always)) return;
526
527 qDebug("BaseGuiPlus::stretchWindow: dockWidgetArea: %d", (int) dockWidgetArea(playlistdock) );
528
529 if ( (dockWidgetArea(playlistdock) == Qt::TopDockWidgetArea) ||
530 (dockWidgetArea(playlistdock) == Qt::BottomDockWidgetArea) )
531 {
532 int new_height = height() + playlistdock->height();
533
534 //if (new_height > DesktopInfo::desktop_size(this).height())
535 // new_height = DesktopInfo::desktop_size(this).height() - 20;
536
537 qDebug("BaseGuiPlus::stretchWindow: stretching: new height: %d", new_height);
538 resize( width(), new_height );
539
540 //resizeWindow(core->mset.win_width, core->mset.win_height);
541 }
542
543 else
544
545 if ( (dockWidgetArea(playlistdock) == Qt::LeftDockWidgetArea) ||
546 (dockWidgetArea(playlistdock) == Qt::RightDockWidgetArea) )
547 {
548 int new_width = width() + playlistdock->width();
549
550 qDebug("BaseGuiPlus::stretchWindow: stretching: new width: %d", new_width);
551 resize( new_width, height() );
552 }
553}
554
555void BaseGuiPlus::shrinkWindow() {
556 qDebug("BaseGuiPlus::shrinkWindow");
557 if ((ignore_playlist_events) || (pref->resize_method!=Preferences::Always)) return;
558
559 qDebug("BaseGuiPlus::shrinkWindow: dockWidgetArea: %d", (int) dockWidgetArea(playlistdock) );
560
561 if ( (dockWidgetArea(playlistdock) == Qt::TopDockWidgetArea) ||
562 (dockWidgetArea(playlistdock) == Qt::BottomDockWidgetArea) )
563 {
564 int new_height = height() - playlistdock->height();
565 qDebug("DefaultGui::shrinkWindow: shrinking: new height: %d", new_height);
566 resize( width(), new_height );
567
568 //resizeWindow(core->mset.win_width, core->mset.win_height);
569 }
570
571 else
572
573 if ( (dockWidgetArea(playlistdock) == Qt::LeftDockWidgetArea) ||
574 (dockWidgetArea(playlistdock) == Qt::RightDockWidgetArea) )
575 {
576 int new_width = width() - playlistdock->width();
577
578 qDebug("BaseGuiPlus::shrinkWindow: shrinking: new width: %d", new_width);
579 resize( new_width, height() );
580 }
581}
582
583#endif
584
585// Convenience functions intended for other GUI's
586TimeSliderAction * BaseGuiPlus::createTimeSliderAction(QWidget * parent) {
587 TimeSliderAction * timeslider_action = new TimeSliderAction( parent );
588 timeslider_action->setObjectName("timeslider_action");
589
590#ifdef SEEKBAR_RESOLUTION
591 connect( timeslider_action, SIGNAL( posChanged(int) ),
592 core, SLOT(goToPosition(int)) );
593 connect( core, SIGNAL(positionChanged(int)),
594 timeslider_action, SLOT(setPos(int)) );
595#else
596 connect( timeslider_action, SIGNAL( posChanged(int) ),
597 core, SLOT(goToPos(int)) );
598 connect( core, SIGNAL(posChanged(int)),
599 timeslider_action, SLOT(setPos(int)) );
600#endif
601 connect( timeslider_action, SIGNAL( draggingPos(int) ),
602 this, SLOT(displayGotoTime(int)) );
603#if ENABLE_DELAYED_DRAGGING
604 timeslider_action->setDragDelay( pref->time_slider_drag_delay );
605
606 connect( timeslider_action, SIGNAL( delayedDraggingPos(int) ),
607 this, SLOT(goToPosOnDragging(int)) );
608#else
609 connect( timeslider_action, SIGNAL( draggingPos(int) ),
610 this, SLOT(goToPosOnDragging(int)) );
611#endif
612
613 connect(timeslider_action, SIGNAL(wheelUp()), core, SLOT(wheelUp()));
614 connect(timeslider_action, SIGNAL(wheelDown()), core, SLOT(wheelDown()));
615
616 connect(core, SIGNAL(newDuration(double)), timeslider_action, SLOT(setDuration(double)));
617
618 return timeslider_action;
619}
620
621VolumeSliderAction * BaseGuiPlus::createVolumeSliderAction(QWidget * parent) {
622 VolumeSliderAction * volumeslider_action = new VolumeSliderAction(parent);
623 volumeslider_action->setObjectName("volumeslider_action");
624
625 connect( volumeslider_action, SIGNAL( valueChanged(int) ),
626 core, SLOT( setVolume(int) ) );
627 connect( core, SIGNAL(volumeChanged(int)),
628 volumeslider_action, SLOT(setValue(int)) );
629
630 return volumeslider_action;
631}
632
633#ifdef Q_OS_OS2
634// we test if xcenter is available at all. if not disable the tray action. this is possible when xcenter is not opened or crashed
635void BaseGuiPlus::trayAvailable() {
636 if (!tray->isSystemTrayAvailable()) {
637 optionsMenu->removeAction(showTrayAct);
638 }
639 else {
640 optionsMenu->addAction(showTrayAct);
641 }
642}
643#endif
644
645#include "moc_baseguiplus.cpp"
Note: See TracBrowser for help on using the repository browser.