#include "searchparams.h"
#include "videosource.h"
#include "ytsearch.h"
-#ifdef Q_OS_LINUX
+#ifdef APP_LINUX
#include "gnomeglobalshortcutbackend.h"
#endif
#ifdef Q_OS_MAC
#include "ytsuggester.h"
#include "updatechecker.h"
#include "temporary.h"
-#ifdef APP_MAC
+#if defined(APP_MAC_SEARCHFIELD) && !defined(APP_MAC_QMACTOOLBAR)
#include "searchlineedit_mac.h"
#else
#include "searchlineedit.h"
#endif
+#ifdef APP_MAC_QMACTOOLBAR
+#include "mactoolbar.h"
+#endif
#include <iostream>
#ifdef APP_EXTRA
#include "extra.h"
#include "videoareawidget.h"
#include "jsfunctions.h"
#include "seekslider.h"
+#ifdef APP_YT3
+#include "yt3.h"
+#endif
+namespace {
static MainWindow *singleton = 0;
+}
MainWindow* MainWindow::instance() {
- if (!singleton) singleton = new MainWindow();
return singleton;
}
aboutView(0),
downloadView(0),
regionsView(0),
+ mainToolBar(0),
#ifdef APP_PHONON
mediaObject(0),
audioOutput(0),
#endif
- m_fullscreen(false),
- m_compact(false) {
+ fullscreenFlag(false),
+ m_compact(false),
+ initialized(false) {
singleton = this;
+#ifdef APP_EXTRA
+ Extra::windowSetup(this);
+#endif
+
// views mechanism
- history = new QStack<QWidget*>();
views = new QStackedWidget();
views->hide();
setCentralWidget(views);
+ messageLabel = new QLabel();
+ messageLabel->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
+ messageLabel->setStyleSheet("padding:5px;border:1px solid #808080;background:palette(window)");
+ messageLabel->hide();
+ adjustMessageLabelPosition();
+ messageTimer = new QTimer(this);
+ messageTimer->setInterval(5000);
+ messageTimer->setSingleShot(true);
+ connect(messageTimer, SIGNAL(timeout()), messageLabel, SLOT(hide()));
+ connect(messageTimer, SIGNAL(timeout()), messageLabel, SLOT(clear()));
+
// views
homeView = new HomeView();
views->addWidget(homeView);
views->widget(i)->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
setMinimumWidth(0);
+ views->show();
+
// show the initial view
showHome(false);
showActivationView(false);
#endif
- views->show();
-
-#ifdef APP_EXTRA
- Extra::windowSetup(this);
-#endif
-
- qApp->processEvents();
- QTimer::singleShot(50, this, SLOT(lazyInit()));
-}
-
-MainWindow::~MainWindow() {
- delete history;
+ QTimer::singleShot(0, this, SLOT(lazyInit()));
}
void MainWindow::lazyInit() {
// Global shortcuts
GlobalShortcuts &shortcuts = GlobalShortcuts::instance();
-#ifdef Q_OS_LINUX
+#ifdef APP_LINUX
if (GnomeGlobalShortcutBackend::IsGsdAvailable())
shortcuts.setBackend(new GnomeGlobalShortcutBackend(&shortcuts));
#endif
JsFunctions::instance();
- checkForUpdate();
+ // Hack to give focus to searchlineedit
+ QMetaObject::invokeMethod(views->currentWidget(), "appear");
+ View* view = qobject_cast<View *> (views->currentWidget());
+ QString desc = view->metadata().value("description").toString();
+ if (!desc.isEmpty()) showMessage(desc);
+
+#ifdef APP_INTEGRITY
+ if (!Extra::integrityCheck()) {
+ deleteLater();
+ return;
+ }
+#endif
ChannelAggregator::instance()->start();
+
+ checkForUpdate();
+
+ initialized = true;
}
-void MainWindow::changeEvent(QEvent* event) {
+void MainWindow::changeEvent(QEvent *e) {
#ifdef APP_MAC
- if (event->type() == QEvent::WindowStateChange) {
+ if (e->type() == QEvent::WindowStateChange) {
The::globalActions()->value("minimize")->setEnabled(!isMinimized());
}
#endif
- QMainWindow::changeEvent(event);
+ QMainWindow::changeEvent(e);
}
-bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
-
- if (m_fullscreen && event->type() == QEvent::MouseMove) {
+bool MainWindow::eventFilter(QObject *obj, QEvent *e) {
- QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
- const int x = mouseEvent->pos().x();
- const QString className = QString(obj->metaObject()->className());
+ if (fullscreenFlag && e->type() == QEvent::MouseMove) {
+ const char *className = obj->metaObject()->className();
const bool isHoveringVideo =
(className == QLatin1String("QGLWidget")) ||
(className == QLatin1String("VideoAreaWidget"));
// qDebug() << obj << mouseEvent->pos() << isHoveringVideo << mediaView->isPlaylistVisible();
- if (mediaView->isPlaylistVisible()) {
- if (isHoveringVideo && x > 5) mediaView->setPlaylistVisible(false);
- } else {
- if (isHoveringVideo && x >= 0 && x < 5) mediaView->setPlaylistVisible(true);
- }
+ if (isHoveringVideo) {
+ QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (e);
+ const int x = mouseEvent->pos().x();
+
+ if (mediaView->isPlaylistVisible()) {
+ if (x > 5) mediaView->setPlaylistVisible(false);
+ } else {
+ if (x >= 0 && x < 5) mediaView->setPlaylistVisible(true);
+ }
#ifndef APP_MAC
- const int y = mouseEvent->pos().y();
- if (mainToolBar->isVisible()) {
- if (isHoveringVideo && y > 5) mainToolBar->setVisible(false);
- } else {
- if (isHoveringVideo && y >= 0 && y < 5) mainToolBar->setVisible(true);
- }
+ const int y = mouseEvent->pos().y();
+ if (mainToolBar->isVisible()) {
+ if (y > 5) mainToolBar->setVisible(false);
+ } else {
+ if (y >= 0 && y < 5) mainToolBar->setVisible(true);
+ }
#endif
+ }
+
// show the normal cursor
unsetCursor();
// then hide it again after a few seconds
mouseTimer->start();
-
}
- if (event->type() == QEvent::ToolTip) {
+ if (e->type() == QEvent::ToolTip) {
// kill tooltips
return true;
}
// standard event processing
- return QMainWindow::eventFilter(obj, event);
+ return QMainWindow::eventFilter(obj, e);
}
void MainWindow::createActions() {
actions->insert("skip", skipAct);
connect(skipAct, SIGNAL(triggered()), mediaView, SLOT(skip()));
- pauseAct = new QAction(IconUtils::icon("media-playback-pause"), tr("&Pause"), this);
- pauseAct->setStatusTip(tr("Pause playback"));
+ pauseAct = new QAction(IconUtils::icon("media-playback-start"), tr("&Play"), this);
+ pauseAct->setStatusTip(tr("Resume playback"));
pauseAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_Space) << QKeySequence(Qt::Key_MediaPlay));
pauseAct->setEnabled(false);
actions->insert("pause", pauseAct);
addAction(volumeMuteAct);
QAction *definitionAct = new QAction(this);
-#ifdef Q_OS_LINUX
+#ifdef APP_LINUX
definitionAct->setIcon(IconUtils::tintedIcon("video-display", QColor(0, 0, 0),
- QList<QSize>() << QSize(16, 16)));
+ QList<QSize>() << QSize(16, 16)));
#else
definitionAct->setIcon(IconUtils::icon("video-display"));
#endif
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_J));
action->setCheckable(true);
action->setIcon(IconUtils::icon("document-save"));
- action->setVisible(false);
connect(action, SIGNAL(toggled(bool)), SLOT(toggleDownloads(bool)));
actions->insert("downloads", action);
actions->insert("ontop", action);
connect(action, SIGNAL(toggled(bool)), SLOT(floatOnTop(bool)));
+ action = new QAction(tr("&Adjust Window Size"), this);
+ action->setCheckable(true);
+ actions->insert("adjustwindowsize", action);
+ connect(action, SIGNAL(toggled(bool)), SLOT(adjustWindowSizeChanged(bool)));
+
action = new QAction(IconUtils::icon("media-playback-stop"), tr("&Stop After This Video"), this);
action->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Escape));
action->setCheckable(true);
}
void MainWindow::createMenus() {
-
QHash<QString, QMenu*> *menus = The::globalMenus();
fileMenu = menuBar()->addMenu(tr("&Application"));
viewMenu->addAction(fullscreenAct);
viewMenu->addAction(compactViewAct);
viewMenu->addSeparator();
+ viewMenu->addAction(The::globalActions()->value("adjustwindowsize"));
+ viewMenu->addSeparator();
viewMenu->addAction(The::globalActions()->value("ontop"));
QMenu* shareMenu = menuBar()->addMenu(tr("&Share"));
void MainWindow::createToolBars() {
- setUnifiedTitleAndToolBarOnMac(true);
+ // Create widgets
+
+ currentTime = new QLabel("00:00");
+ currentTime->setFont(FontUtils::small());
+
+#ifdef APP_PHONON_SEEK
+ seekSlider = new Phonon::SeekSlider();
+ seekSlider->setTracking(true);
+ seekSlider->setIconVisible(false);
+ seekSlider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
+#else
+ slider = new SeekSlider(this);
+ slider->setEnabled(false);
+ slider->setTracking(false);
+ slider->setMaximum(1000);
+ slider->setOrientation(Qt::Horizontal);
+ slider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
+#endif
+
+#ifdef APP_PHONON
+ volumeSlider = new Phonon::VolumeSlider();
+ volumeSlider->setMuteVisible(false);
+ // qDebug() << volumeSlider->children();
+ // status tip for the volume slider
+ QSlider* volumeQSlider = volumeSlider->findChild<QSlider*>();
+ if (volumeQSlider)
+ volumeQSlider->setStatusTip(tr("Press %1 to raise the volume, %2 to lower it").arg(
+ volumeUpAct->shortcut().toString(QKeySequence::NativeText), volumeDownAct->shortcut().toString(QKeySequence::NativeText)));
+ // this makes the volume slider smaller
+ volumeSlider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+#endif
+
+#if defined(APP_MAC_SEARCHFIELD) && !defined(APP_MAC_QMACTOOLBAR)
+ SearchWrapper* searchWrapper = new SearchWrapper(this);
+ toolbarSearch = searchWrapper->getSearchLineEdit();
+#else
+ toolbarSearch = new SearchLineEdit(this);
+#endif
+ toolbarSearch->setMinimumWidth(toolbarSearch->fontInfo().pixelSize()*15);
+ toolbarSearch->setSuggester(new YTSuggester(this));
+ connect(toolbarSearch, SIGNAL(search(const QString&)), SLOT(search(const QString&)));
+ connect(toolbarSearch, SIGNAL(suggestionAccepted(Suggestion*)), SLOT(suggestionAccepted(Suggestion*)));
+ toolbarSearch->setStatusTip(searchFocusAct->statusTip());
+
+ // Add widgets to toolbar
+
+#ifdef APP_MAC_QMACTOOLBAR
+ currentTime->hide();
+ toolbarSearch->hide();
+ volumeSlider->hide();
+ seekSlider->hide();
+ MacToolbar::instance().createToolbar(this);
+ return;
+#endif
mainToolBar = new QToolBar(this);
mainToolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
mainToolBar->setFloatable(false);
mainToolBar->setMovable(false);
-
#if defined(APP_MAC) | defined(APP_WIN)
mainToolBar->setIconSize(QSize(32, 32));
#endif
mainToolBar->addAction(stopAct);
mainToolBar->addAction(pauseAct);
mainToolBar->addAction(skipAct);
-
mainToolBar->addAction(The::globalActions()->value("related-videos"));
mainToolBar->addAction(The::globalActions()->value("download"));
if (addFullScreenAct) mainToolBar->addAction(fullscreenAct);
mainToolBar->addWidget(new Spacer());
-
- QFont smallerFont = FontUtils::small();
- currentTime = new QLabel(mainToolBar);
- currentTime->setFont(smallerFont);
mainToolBar->addWidget(currentTime);
-
mainToolBar->addWidget(new Spacer());
-
#ifdef APP_PHONON_SEEK
- seekSlider = new Phonon::SeekSlider(this);
- seekSlider->setTracking(true);
- seekSlider->setIconVisible(false);
- seekSlider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
mainToolBar->addWidget(seekSlider);
#else
- slider = new SeekSlider(this);
- slider->setEnabled(false);
- slider->setTracking(false);
- slider->setMaximum(1000);
- slider->setOrientation(Qt::Horizontal);
- slider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
mainToolBar->addWidget(slider);
#endif
mainToolBar->addWidget(new Spacer());
mainToolBar->addAction(volumeMuteAct);
+#ifdef APP_LINUX
+ QToolButton *volumeMuteButton = qobject_cast<QToolButton *>(mainToolBar->widgetForAction(volumeMuteAct));
+ volumeMuteButton->setIcon(volumeMuteButton->icon().pixmap(16));
+#endif
#ifdef APP_PHONON
- volumeSlider = new Phonon::VolumeSlider(this);
- volumeSlider->setMuteVisible(false);
- // qDebug() << volumeSlider->children();
- // status tip for the volume slider
- QSlider* volumeQSlider = volumeSlider->findChild<QSlider*>();
- if (volumeQSlider)
- volumeQSlider->setStatusTip(tr("Press %1 to raise the volume, %2 to lower it").arg(
- volumeUpAct->shortcut().toString(QKeySequence::NativeText), volumeDownAct->shortcut().toString(QKeySequence::NativeText)));
- // this makes the volume slider smaller
- volumeSlider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
mainToolBar->addWidget(volumeSlider);
#endif
mainToolBar->addWidget(new Spacer());
-#ifdef APP_MAC
- SearchWrapper* searchWrapper = new SearchWrapper(this);
- toolbarSearch = searchWrapper->getSearchLineEdit();
-#else
- toolbarSearch = new SearchLineEdit(this);
-#endif
- toolbarSearch->setMinimumWidth(toolbarSearch->fontInfo().pixelSize()*15);
- toolbarSearch->setSuggester(new YTSuggester(this));
- connect(toolbarSearch, SIGNAL(search(const QString&)), SLOT(search(const QString&)));
- connect(toolbarSearch, SIGNAL(suggestionAccepted(Suggestion*)), SLOT(suggestionAccepted(Suggestion*)));
- toolbarSearch->setStatusTip(searchFocusAct->statusTip());
-#ifdef APP_MAC
+#if defined(APP_MAC_SEARCHFIELD) && !defined(APP_MAC_QMACTOOLBAR)
mainToolBar->addWidget(searchWrapper);
#else
mainToolBar->addWidget(toolbarSearch);
statusToolBar = new QToolBar(this);
statusToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
statusToolBar->setIconSize(QSize(16, 16));
- statusToolBar->addAction(The::globalActions()->value("downloads"));
- regionButton = new QToolButton(this);
- regionButton->setStatusTip(tr("Choose your content location"));
- regionButton->setIconSize(QSize(16, 16));
- regionButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
- regionAction = statusToolBar->addWidget(regionButton);
- regionAction->setVisible(false);
+ regionAction = new QAction(this);
+ regionAction->setStatusTip(tr("Choose your content location"));
QAction *localAction = The::globalActions()->value("local-region");
if (!localAction->text().isEmpty()) {
- regionButton->setPopupMode(QToolButton::InstantPopup);
QMenu *regionMenu = new QMenu(this);
regionMenu->addAction(The::globalActions()->value("worldwide-region"));
regionMenu->addAction(localAction);
QAction *moreRegionsAction = The::globalActions()->value("more-region");
regionMenu->addAction(moreRegionsAction);
connect(moreRegionsAction, SIGNAL(triggered()), SLOT(showRegionsView()));
- regionButton->setMenu(regionMenu);
+ regionAction->setMenu(regionMenu);
} else {
- connect(regionButton, SIGNAL(clicked()), SLOT(showRegionsView()));
+ connect(regionAction, SIGNAL(triggered()), SLOT(showRegionsView()));
}
/* Stupid code that generates the QRC items
qDebug() << QString("<file>flags/%1.png</file>").arg(r.id.toLower());
*/
- statusToolBar->addAction(The::globalActions()->value("definition"));
-
statusBar()->addPermanentWidget(statusToolBar);
- statusBar()->show();
}
void MainWindow::showStopAfterThisInStatusBar(bool show) {
#endif
if (show) {
statusToolBar->insertAction(statusToolBar->actions().first(), action);
+ if (statusBar()->isHidden() && !fullscreenFlag)
+ setStatusBarVisibility(true);
} else {
statusToolBar->removeAction(action);
+ if (statusBar()->isVisible() && !needStatusBar())
+ setStatusBarVisibility(false);
}
}
+void MainWindow::setStatusBarVisibility(bool show) {
+ statusBar()->setVisible(show);
+ if (views->currentWidget() == mediaView)
+ QTimer::singleShot(0, mediaView, SLOT(maybeAdjustWindowSize()));
+}
+
+void MainWindow::adjustStatusBarVisibility() {
+ setStatusBarVisibility(needStatusBar());
+}
+
void MainWindow::readSettings() {
QSettings settings;
if (settings.contains("geometry")) {
MacSupport::fixGeometry(this);
#endif
} else {
- setGeometry(100, 100, 1000, 500);
+ const QRect desktopSize = qApp->desktop()->availableGeometry();
+ int w = qMin(2000, desktopSize.width());
+ int h = qMin(w / 3, desktopSize.height());
+ setGeometry(
+ QStyle::alignedRect(
+ Qt::LeftToRight,
+ Qt::AlignTop,
+ QSize(w, h),
+ desktopSize)
+ );
}
- setDefinitionMode(settings.value("definition", VideoDefinition::getDefinitionNames().first()).toString());
+ const VideoDefinition& firstDefinition = VideoDefinition::getDefinitions().first();
+ setDefinitionMode(settings.value("definition", firstDefinition.getName()).toString());
The::globalActions()->value("manualplay")->setChecked(settings.value("manualplay", false).toBool());
+ The::globalActions()->value("adjustwindowsize")->setChecked(settings.value("adjustWindowSize", true).toBool());
}
void MainWindow::writeSettings() {
QSettings settings;
- settings.setValue("geometry", saveGeometry());
+ if (!isReallyFullScreen())
+ settings.setValue("geometry", saveGeometry());
mediaView->saveSplitterState();
#ifdef APP_PHONON
}
void MainWindow::goBack() {
- if ( history->size() > 1 ) {
- history->pop();
- QWidget *widget = history->pop();
+ if (history.size() > 1) {
+ history.pop();
+ QWidget *widget = history.pop();
showWidget(widget);
}
}
void MainWindow::showWidget(QWidget* widget, bool transition) {
+ Q_UNUSED(transition);
if (compactViewAct->isChecked())
compactViewAct->toggle();
- setUpdatesEnabled(false);
-
// call hide method on the current view
- View* oldView = dynamic_cast<View *> (views->currentWidget());
+ View* oldView = qobject_cast<View *> (views->currentWidget());
if (oldView) {
oldView->disappear();
views->currentWidget()->setEnabled(false);
} else qDebug() << "Cannot cast view";
+ const bool isMediaView = widget == mediaView;
+
+ stopAct->setEnabled(isMediaView);
+ compactViewAct->setEnabled(isMediaView);
+ toolbarSearch->setEnabled(widget == homeView || isMediaView || widget == downloadView);
+
+ aboutAct->setEnabled(widget != aboutView);
+ The::globalActions()->value("downloads")->setChecked(widget == downloadView);
+
+ QWidget *oldWidget = views->currentWidget();
+ if (oldWidget)
+ oldWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
+
+ views->setCurrentWidget(widget);
+ widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+
// call show method on the new view
- View* newView = dynamic_cast<View *> (widget);
+ View* newView = qobject_cast<View *> (widget);
if (newView) {
widget->setEnabled(true);
QHash<QString,QVariant> metadata = newView->metadata();
+
QString title = metadata.value("title").toString();
if (title.isEmpty()) title = Constants::NAME;
else title += QLatin1String(" - ") + Constants::NAME;
setWindowTitle(title);
- QString desc = metadata.value("description").toString();
- if (!desc.isEmpty()) showMessage(desc);
- newView->appear();
+
+ statusToolBar->setUpdatesEnabled(false);
// dynamic view actions
foreach (QAction* action, viewActions)
foreach (QAction* action, viewActions)
showActionInStatusBar(action, true);
- }
-
- const bool isMediaView = widget == mediaView;
-
- stopAct->setEnabled(isMediaView);
- compactViewAct->setEnabled(isMediaView);
- toolbarSearch->setEnabled(widget == homeView || isMediaView || widget == downloadView);
-
- aboutAct->setEnabled(widget != aboutView);
- The::globalActions()->value("downloads")->setChecked(widget == downloadView);
-
- QWidget *oldWidget = views->currentWidget();
- if (oldWidget)
- oldWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
+ newView->appear();
- views->setCurrentWidget(widget);
- widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ adjustStatusBarVisibility();
+ messageLabel->hide();
- setUpdatesEnabled(true);
+ statusToolBar->setUpdatesEnabled(true);
-#ifdef APP_EXTRA
- // if (transition && (oldWidget != mediaView || !mediaView->getVideoArea()->isVideoShown()))
- if (transition)
- Extra::fadeInWidget(oldWidget, widget);
-#endif
+ /*
+ QString desc = metadata.value("description").toString();
+ if (!desc.isEmpty()) showMessage(desc);
+ */
+ }
- history->push(widget);
+ history.push(widget);
}
void MainWindow::about() {
void MainWindow::visitSite() {
QUrl url(Constants::WEBSITE);
- statusBar()->showMessage(QString(tr("Opening %1").arg(url.toString())));
+ showMessage(QString(tr("Opening %1").arg(url.toString())));
QDesktopServices::openUrl(url);
}
void MainWindow::donate() {
QUrl url(QString(Constants::WEBSITE) + "#donate");
- statusBar()->showMessage(QString(tr("Opening %1").arg(url.toString())));
+ showMessage(QString(tr("Opening %1").arg(url.toString())));
QDesktopServices::openUrl(url);
}
}
#endif
// do not save geometry when in full screen or in compact mode
- if (!m_fullscreen && !compactViewAct->isChecked()) {
+ if (!fullscreenFlag && !compactViewAct->isChecked()) {
writeSettings();
}
- mediaView->stop();
+ // mediaView->stop();
Temporary::deleteAll();
ChannelAggregator::instance()->stop();
ChannelAggregator::instance()->cleanup();
qApp->quit();
}
-void MainWindow::closeEvent(QCloseEvent *event) {
+void MainWindow::closeEvent(QCloseEvent *e) {
#ifdef APP_MAC
mac::closeWindow(winId());
- event->ignore();
+ e->ignore();
#else
if (!confirmQuit()) {
- event->ignore();
+ e->ignore();
return;
}
- QWidget::closeEvent(event);
+ QWidget::closeEvent(e);
quit();
+#endif
+ messageLabel->hide();
+}
+
+void MainWindow::showEvent(QShowEvent *e) {
+ QWidget::showEvent(e);
+#ifdef APP_MAC
+ restore();
#endif
}
bool MainWindow::confirmQuit() {
if (DownloadManager::instance()->activeItems() > 0) {
QMessageBox msgBox(this);
- msgBox.setIconPixmap(QPixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ msgBox.setIconPixmap(IconUtils::pixmap(":/images/app.png").scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
msgBox.setText(tr("Do you want to exit %1 with a download in progress?").arg(Constants::NAME));
msgBox.setInformativeText(tr("If you close %1 now, this download will be cancelled.").arg(Constants::NAME));
msgBox.setModal(true);
if (mediaObject->errorType() == Phonon::FatalError) {
// Do not display because we try to play incomplete video files and sometimes trigger this
// We retry automatically (in MediaView) so no need to show it
- // statusBar()->showMessage(tr("Fatal error: %1").arg(mediaObject->errorString()));
+ // showMessage(tr("Fatal error: %1").arg(mediaObject->errorString()));
} else {
- statusBar()->showMessage(tr("Error: %1").arg(mediaObject->errorString()));
+ showMessage(tr("Error: %1").arg(mediaObject->errorString()));
}
break;
case Phonon::StoppedState:
pauseAct->setEnabled(false);
+ pauseAct->setIcon(IconUtils::icon("media-playback-start"));
+ pauseAct->setText(tr("&Play"));
+ pauseAct->setStatusTip(tr("Resume playback") + " (" + pauseAct->shortcut().toString(QKeySequence::NativeText) + ")");
// stopAct->setEnabled(false);
break;
break;
case Phonon::BufferingState:
+ pauseAct->setEnabled(false);
+ pauseAct->setIcon(IconUtils::icon("content-loading"));
+ pauseAct->setText(tr("&Loading..."));
+ pauseAct->setStatusTip(QString());
+ break;
+
case Phonon::LoadingState:
pauseAct->setEnabled(false);
currentTime->clear();
mediaView->stop();
}
-void MainWindow::resizeEvent(QResizeEvent*) {
-#ifdef Q_OS_MAC
- if (mac::CanGoFullScreen(winId())) {
+void MainWindow::resizeEvent(QResizeEvent *e) {
+ Q_UNUSED(e);
+#ifdef APP_MAC
+ if (initialized && mac::CanGoFullScreen(winId())) {
bool isFullscreen = mac::IsFullScreen(winId());
- if (isFullscreen != m_fullscreen) {
+ if (isFullscreen != fullscreenFlag) {
if (compactViewAct->isChecked()) {
compactViewAct->setChecked(false);
compactView(false);
}
- m_fullscreen = isFullscreen;
+ fullscreenFlag = isFullscreen;
updateUIForFullscreen();
}
}
#endif
+#ifdef APP_MAC_QMACTOOLBAR
+ toolbarSearch->move(width() - toolbarSearch->width() - 13, -38);
+#endif
+ adjustMessageLabelPosition();
+}
+
+void MainWindow::moveEvent(QMoveEvent *e) {
+ Q_UNUSED(e);
+ adjustMessageLabelPosition();
}
void MainWindow::fullscreen() {
if (compactViewAct->isChecked())
compactViewAct->toggle();
-#ifdef Q_OS_MAC
+#ifdef APP_MAC
WId handle = winId();
if (mac::CanGoFullScreen(handle)) {
- mainToolBar->setVisible(true);
+ if (mainToolBar) mainToolBar->setVisible(true);
mac::ToggleFullScreen(handle);
return;
}
#endif
- m_fullscreen = !m_fullscreen;
+ fullscreenFlag = !fullscreenFlag;
- if (m_fullscreen) {
+ if (fullscreenFlag) {
// Enter full screen
m_maximized = isMaximized();
// geometry won't be saved
writeSettings();
-#ifdef Q_OS_MAC
+#ifdef APP_MAC
MacSupport::enterFullScreen(this, views);
#else
- mainToolBar->hide();
+ if (mainToolBar) mainToolBar->hide();
showFullScreen();
#endif
} else {
// Exit full screen
-#ifdef Q_OS_MAC
+#ifdef APP_MAC
MacSupport::exitFullScreen(this, views);
#else
- mainToolBar->show();
+ if (mainToolBar) mainToolBar->show();
if (m_maximized) showMaximized();
else showNormal();
#endif
static QList<QKeySequence> fsShortcuts;
static QString fsText;
- if (m_fullscreen) {
+ if (fullscreenFlag) {
fsShortcuts = fullscreenAct->shortcuts();
fsText = fullscreenAct->text();
+ if (fsText.isEmpty()) qDebug() << "[taking Empty!]";
fullscreenAct->setShortcuts(QList<QKeySequence>(fsShortcuts)
<< QKeySequence(Qt::Key_Escape));
fullscreenAct->setText(tr("Leave &Full Screen"));
fullscreenAct->setIcon(IconUtils::icon("view-restore"));
+ setStatusBarVisibility(false);
} else {
fullscreenAct->setShortcuts(fsShortcuts);
+ if (fsText.isEmpty()) fsText = "[Empty!]";
fullscreenAct->setText(fsText);
fullscreenAct->setIcon(IconUtils::icon("view-fullscreen"));
+
+ if (needStatusBar()) setStatusBarVisibility(true);
}
// No compact view action when in full screen
- compactViewAct->setVisible(!m_fullscreen);
+ compactViewAct->setVisible(!fullscreenFlag);
compactViewAct->setChecked(false);
// Hide anything but the video
- mediaView->setPlaylistVisible(!m_fullscreen);
- statusBar()->setVisible(!m_fullscreen);
+ mediaView->setPlaylistVisible(!fullscreenFlag);
+ if (mainToolBar) mainToolBar->setVisible(!fullscreenFlag);
#ifndef APP_MAC
- menuBar()->setVisible(!m_fullscreen);
+ menuBar()->setVisible(!fullscreenFlag);
#endif
- if (m_fullscreen) {
+ if (fullscreenFlag) {
stopAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_MediaStop));
} else {
stopAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::Key_MediaStop));
}
#ifdef Q_OS_MAC
- MacSupport::fullScreenActions(The::globalActions()->values(), m_fullscreen);
+ MacSupport::fullScreenActions(The::globalActions()->values(), fullscreenFlag);
#endif
if (views->currentWidget() == mediaView)
mediaView->setFocus();
- if (m_fullscreen) {
+ if (fullscreenFlag) {
hideMouse();
} else {
mouseTimer->stop();
else
resize(320, 180);
+#ifdef APP_MAC_QMACTOOLBAR
+ mac::showToolBar(winId(), !enable);
+#else
mainToolBar->setVisible(!enable);
+#endif
mediaView->setPlaylistVisible(!enable);
- statusBar()->setVisible(!enable);
+ statusBar()->hide();
compactShortcuts = compactViewAct->shortcuts();
stopShortcuts = stopAct->shortcuts();
mac::SetupFullScreenWindow(winId());
#endif
settings.setValue(key, saveGeometry());
+#ifdef APP_MAC_QMACTOOLBAR
+ mac::showToolBar(winId(), !enable);
+#else
mainToolBar->setVisible(!enable);
+#endif
mediaView->setPlaylistVisible(!enable);
- statusBar()->setVisible(!enable);
+ if (needStatusBar()) setStatusBarVisibility(true);
+
readSettings();
compactViewAct->setShortcuts(compactShortcuts);
}
// auto float on top
- floatOnTop(enable);
+ floatOnTop(enable, false);
#ifdef Q_OS_MAC
mac::compactMode(winId(), enable);
mediaObject = new Phonon::MediaObject(this);
mediaObject->setTickInterval(100);
connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
- this, SLOT(stateChanged(Phonon::State, Phonon::State)));
- connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
- connect(mediaObject, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64)));
+ SLOT(stateChanged(Phonon::State, Phonon::State)));
+ connect(mediaObject, SIGNAL(tick(qint64)), SLOT(tick(qint64)));
+ connect(mediaObject, SIGNAL(totalTimeChanged(qint64)), SLOT(totalTimeChanged(qint64)));
+
+ audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this);
+ connect(audioOutput, SIGNAL(volumeChanged(qreal)), SLOT(volumeChanged(qreal)));
+ connect(audioOutput, SIGNAL(mutedChanged(bool)), SLOT(volumeMutedChanged(bool)));
+ Phonon::createPath(mediaObject, audioOutput);
+ volumeSlider->setAudioOutput(audioOutput);
+
#ifdef APP_PHONON_SEEK
seekSlider->setMediaObject(mediaObject);
#endif
- audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this);
- connect(audioOutput, SIGNAL(volumeChanged(qreal)), this, SLOT(volumeChanged(qreal)));
- connect(audioOutput, SIGNAL(mutedChanged(bool)), this, SLOT(volumeMutedChanged(bool)));
- volumeSlider->setAudioOutput(audioOutput);
- Phonon::createPath(mediaObject, audioOutput);
+
QSettings settings;
- audioOutput->setVolume(settings.value("volume", 1).toDouble());
+ audioOutput->setVolume(settings.value("volume", 1.).toReal());
// audioOutput->setMuted(settings.value("volumeMute").toBool());
+
+ mediaObject->stop();
}
#endif
void MainWindow::tick(qint64 time) {
- if (time <= 0) {
- // the "if" is important because tick is continually called
- // and we don't want to paint the toolbar every 100ms
- if (!currentTime->text().isEmpty()) currentTime->clear();
- return;
+ const QString s = formatTime(time);
+ if (s != currentTime->text()) {
+ currentTime->setText(s);
+ emit currentTimeChanged(s);
}
- currentTime->setText(formatTime(time));
-
// remaining time
#ifdef APP_PHONON
const qint64 remainingTime = mediaObject->remainingTime();
slider->setMaximum(time/1000);
slider->blockSignals(false);
*/
-
}
-QString MainWindow::formatTime(qint64 time) {
- QTime displayTime;
- displayTime = displayTime.addMSecs(time);
- QString timeString;
- // 60 * 60 * 1000 = 3600000
- if (time > 3600000)
- timeString = displayTime.toString("h:mm:ss");
- else
- timeString = displayTime.toString("m:ss");
- return timeString;
+QString MainWindow::formatTime(qint64 duration) {
+ duration /= 1000;
+ QString res;
+ int seconds = (int) (duration % 60);
+ duration /= 60;
+ int minutes = (int) (duration % 60);
+ duration /= 60;
+ int hours = (int) (duration % 24);
+ if (hours == 0)
+ return res.sprintf("%02d:%02d", minutes, seconds);
+ return res.sprintf("%02d:%02d:%02d", hours, minutes, seconds);
}
void MainWindow::volumeUp() {
void MainWindow::volumeMute() {
#ifdef APP_PHONON
- volumeSlider->audioOutput()->setMuted(!volumeSlider->audioOutput()->isMuted());
+ bool muted = volumeSlider->audioOutput()->isMuted();
+ volumeSlider->audioOutput()->setMuted(!muted);
+ qApp->processEvents();
+ if (muted && volumeSlider->audioOutput()->volume() == 0) {
+ volumeSlider->audioOutput()->setVolume(volumeSlider->maximumVolume());
+ }
+ qDebug() << volumeSlider->audioOutput()->isMuted() << volumeSlider->audioOutput()->volume();
#endif
}
void MainWindow::volumeChanged(qreal newVolume) {
#ifdef APP_PHONON
// automatically unmute when volume changes
- if (volumeSlider->audioOutput()->isMuted())
- volumeSlider->audioOutput()->setMuted(false);
+ if (volumeSlider->audioOutput()->isMuted()) volumeSlider->audioOutput()->setMuted(false);
bool isZero = volumeSlider->property("zero").toBool();
bool styleChanged = false;
style()->polish(volumeQSlider);
}
#endif
- statusBar()->showMessage(tr("Volume at %1%").arg((int)(newVolume*100)));
+ showMessage(tr("Volume at %1%").arg((int)(newVolume*100)));
}
void MainWindow::volumeMutedChanged(bool muted) {
if (muted) {
volumeMuteAct->setIcon(IconUtils::icon("audio-volume-muted"));
- statusBar()->showMessage(tr("Volume is muted"));
+ showMessage(tr("Volume is muted"));
} else {
volumeMuteAct->setIcon(IconUtils::icon("audio-volume-high"));
- statusBar()->showMessage(tr("Volume is unmuted"));
+ showMessage(tr("Volume is unmuted"));
}
+#ifdef APP_LINUX
+ QToolButton *volumeMuteButton = qobject_cast<QToolButton *>(mainToolBar->widgetForAction(volumeMuteAct));
+ volumeMuteButton->setIcon(volumeMuteButton->icon().pixmap(16));
+#endif
}
-void MainWindow::setDefinitionMode(QString definitionName) {
+void MainWindow::setDefinitionMode(const QString &definitionName) {
QAction *definitionAct = The::globalActions()->value("definition");
definitionAct->setText(definitionName);
definitionAct->setStatusTip(tr("Maximum video definition set to %1").arg(definitionAct->text())
+ " (" + definitionAct->shortcut().toString(QKeySequence::NativeText) + ")");
- statusBar()->showMessage(definitionAct->statusTip());
+ showMessage(definitionAct->statusTip());
QSettings settings;
settings.setValue("definition", definitionName);
}
void MainWindow::toggleDefinitionMode() {
- QSettings settings;
- QString currentDefinition = settings.value("definition").toString();
- QStringList definitionNames = VideoDefinition::getDefinitionNames();
- int currentIndex = definitionNames.indexOf(currentDefinition);
- int nextIndex = 0;
- if (currentIndex != definitionNames.size() - 1) {
- nextIndex = currentIndex + 1;
+ const QString definitionName = QSettings().value("definition").toString();
+ const QList<VideoDefinition>& definitions = VideoDefinition::getDefinitions();
+ const VideoDefinition& currentDefinition = VideoDefinition::getDefinitionFor(definitionName);
+ if (currentDefinition.isEmpty()) {
+ setDefinitionMode(definitions.first().getName());
+ return;
}
- QString nextDefinition = definitionNames.at(nextIndex);
- setDefinitionMode(nextDefinition);
+
+ int index = definitions.indexOf(currentDefinition);
+ if (index != definitions.size() - 1) {
+ index++;
+ } else {
+ index = 0;
+ }
+ // TODO: pass a VideoDefinition instead of QString.
+ setDefinitionMode(definitions.at(index).getName());
}
void MainWindow::showFullscreenToolbar(bool show) {
- if (!m_fullscreen) return;
+ if (!fullscreenFlag) return;
mainToolBar->setVisible(show);
}
void MainWindow::showFullscreenPlaylist(bool show) {
- if (!m_fullscreen) return;
+ if (!fullscreenFlag) return;
mediaView->setPlaylistVisible(show);
}
showActionInStatusBar(The::globalActions()->value("manualplay"), enabled);
}
-void MainWindow::updateDownloadMessage(QString message) {
+void MainWindow::updateDownloadMessage(const QString &message) {
The::globalActions()->value("downloads")->setText(message);
}
void MainWindow::downloadsFinished() {
The::globalActions()->value("downloads")->setText(tr("&Downloads"));
- statusBar()->showMessage(tr("Downloads complete"));
+ showMessage(tr("Downloads complete"));
}
void MainWindow::toggleDownloads(bool show) {
showMedia(searchParams);
}
-void MainWindow::dragEnterEvent(QDragEnterEvent *event) {
- if (event->mimeData()->hasFormat("text/uri-list")) {
- QList<QUrl> urls = event->mimeData()->urls();
+void MainWindow::dragEnterEvent(QDragEnterEvent *e) {
+ if (e->mimeData()->hasFormat("text/uri-list")) {
+ QList<QUrl> urls = e->mimeData()->urls();
if (urls.isEmpty()) return;
QUrl url = urls.first();
QString videoId = YTSearch::videoIdFromUrl(url.toString());
if (!videoId.isEmpty())
- event->acceptProposedAction();
+ e->acceptProposedAction();
}
}
-void MainWindow::dropEvent(QDropEvent *event) {
+void MainWindow::dropEvent(QDropEvent *e) {
if (!toolbarSearch->isEnabled()) return;
- QList<QUrl> urls = event->mimeData()->urls();
+ QList<QUrl> urls = e->mimeData()->urls();
if (urls.isEmpty())
return;
QUrl url = urls.first();
settings.setValue(updateCheckKey, unixTime);
}
-void MainWindow::gotNewVersion(QString version) {
+void MainWindow::gotNewVersion(const QString &version) {
if (updateChecker) {
delete updateChecker;
updateChecker = 0;
QString checkedVersion = settings.value("checkedVersion").toString();
if (checkedVersion == version) return;
-#ifdef APP_SIMPLEUPDATE
- simpleUpdateDialog(version);
-#elif defined(APP_ACTIVATION) && !defined(APP_MAC)
+#ifdef APP_EXTRA
+#ifndef APP_MAC
UpdateDialog *dialog = new UpdateDialog(version, this);
dialog->show();
#endif
+#else
+ simpleUpdateDialog(version);
+#endif
}
-void MainWindow::simpleUpdateDialog(QString version) {
+void MainWindow::simpleUpdateDialog(const QString &version) {
QMessageBox msgBox(this);
msgBox.setIconPixmap(
- QPixmap(":/images/app.png")
+ IconUtils::pixmap(":/images/app.png")
.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
msgBox.setText(tr("%1 version %2 is now available.").arg(Constants::NAME, version));
msgBox.setModal(true);
if (msgBox.clickedButton() == updateButton) visitSite();
}
-void MainWindow::floatOnTop(bool onTop) {
- showActionInStatusBar(The::globalActions()->value("ontop"), onTop);
+bool MainWindow::needStatusBar() {
+ return !statusToolBar->actions().isEmpty();
+}
+
+void MainWindow::adjustMessageLabelPosition() {
+ if (messageLabel->parent() == this)
+ messageLabel->move(0, height() - messageLabel->height());
+ else
+ messageLabel->move(mapToGlobal(QPoint(0, height() - messageLabel->height())));
+}
+
+void MainWindow::floatOnTop(bool onTop, bool showAction) {
+ if (showAction) showActionInStatusBar(The::globalActions()->value("ontop"), onTop);
#ifdef APP_MAC
mac::floatOnTop(winId(), onTop);
return;
}
}
+void MainWindow::adjustWindowSizeChanged(bool enabled) {
+ QSettings settings;
+ settings.setValue("adjustWindowSize", enabled);
+ if (enabled && views->currentWidget() == mediaView)
+ mediaView->adjustWindowSize();
+}
+
void MainWindow::restore() {
#ifdef APP_MAC
mac::uncloseWindow(window()->winId());
std::cout << msg.toLocal8Bit().data();
}
-void MainWindow::showMessage(QString message) {
- statusBar()->showMessage(message, 60000);
+void MainWindow::showMessage(const QString &message) {
+ if (!isVisible()) return;
+#ifdef APP_MAC
+ if (!mac::isVisible(winId())) return;
+#endif
+ if (statusBar()->isVisible())
+ statusBar()->showMessage(message, 60000);
+ else {
+ messageLabel->setText(message);
+ messageLabel->resize(messageLabel->sizeHint());
+ adjustMessageLabelPosition();
+ messageLabel->show();
+ messageTimer->start();
+ }
}
#ifdef APP_ACTIVATION