#include "mac_startup.h"
#include "macfullscreen.h"
#include "macsupport.h"
+#include "macutils.h"
#endif
#ifndef Q_WS_X11
#include "extra.h"
#include "demostartupview.h"
#endif
#include "temporary.h"
+#ifdef APP_MAC
+#include "searchlineedit_mac.h"
+#else
+#include "searchlineedit.h"
+#endif
+
+static MainWindow *singleton = 0;
+
+MainWindow* MainWindow::instance() {
+ if (!singleton) singleton = new MainWindow();
+ return singleton;
+}
MainWindow::MainWindow() :
aboutView(0),
m_fullscreen(false),
updateChecker(0) {
+ singleton = this;
+
// views mechanism
history = new QStack<QWidget*>();
views = new QStackedWidget(this);
views->addWidget(searchView);
mediaView = new MediaView(this);
+ mediaView->setEnabled(false);
views->addWidget(mediaView);
- toolbarSearch = new SearchLineEdit(this);
- toolbarSearch->setMinimumWidth(toolbarSearch->fontInfo().pixelSize()*15);
- toolbarSearch->setSuggester(new YouTubeSuggest(this));
- connect(toolbarSearch, SIGNAL(search(const QString&)), this, SLOT(startToolbarSearch(const QString&)));
-
// build ui
createActions();
createMenus();
connect(&shortcuts, SIGNAL(PlayPause()), pauseAct, SLOT(trigger()));
connect(&shortcuts, SIGNAL(Stop()), this, SLOT(stop()));
connect(&shortcuts, SIGNAL(Next()), skipAct, SLOT(trigger()));
+ connect(&shortcuts, SIGNAL(Previous()), skipBackwardAct, SLOT(trigger()));
+ // connect(&shortcuts, SIGNAL(StopAfter()), The::globalActions()->value("stopafterthis"), SLOT(toggle()));
connect(DownloadManager::instance(), SIGNAL(statusMessageChanged(QString)),
SLOT(updateDownloadMessage(QString)));
delete history;
}
+void MainWindow::changeEvent(QEvent* event) {
+#ifdef APP_MAC
+ if (event->type() == QEvent::WindowStateChange) {
+ The::globalActions()->value("minimize")->setEnabled(!isMinimized());
+ }
+#endif
+ QMainWindow::changeEvent(event);
+}
+
bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
#ifdef Q_WS_X11
if (event->type() == QEvent::MouseMove && this->m_fullscreen) {
actions->insert("stop", stopAct);
connect(stopAct, SIGNAL(triggered()), this, SLOT(stop()));
+ skipBackwardAct = new QAction(
+ QtIconLoader::icon("media-skip-backward"),
+ tr("P&revious"), this);
+ skipBackwardAct->setStatusTip(tr("Go back to the previous track"));
+ skipBackwardAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
+#if QT_VERSION >= 0x040600
+ skipBackwardAct->setPriority(QAction::LowPriority);
+#endif
+ skipBackwardAct->setEnabled(false);
+ actions->insert("previous", skipBackwardAct);
+ connect(skipBackwardAct, SIGNAL(triggered()), mediaView, SLOT(skipBackward()));
+
skipAct = new QAction(QtIconLoader::icon("media-skip-forward"), tr("S&kip"), this);
skipAct->setStatusTip(tr("Skip to the next video"));
skipAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_Right) << QKeySequence(Qt::Key_MediaNext));
#ifdef APP_MAC
fsShortcuts << QKeySequence(Qt::CTRL + Qt::META + Qt::Key_F);
#else
- fsShortcuts << QKeySequence(Qt::Key_F11);
+ fsShortcuts << QKeySequence(Qt::Key_F11) << QKeySequence(Qt::ALT + Qt::Key_Return);
#endif
fullscreenAct->setShortcuts(fsShortcuts);
fullscreenAct->setShortcutContext(Qt::ApplicationShortcut);
actions->insert("fullscreen", fullscreenAct);
connect(fullscreenAct, SIGNAL(triggered()), this, SLOT(fullscreen()));
- compactViewAct = new QAction(tr("&Compact mode"), this);
+ compactViewAct = new QAction(tr("&Compact Mode"), this);
compactViewAct->setStatusTip(tr("Hide the playlist and the toolbar"));
#ifdef APP_MAC
compactViewAct->setShortcut(QKeySequence(Qt::CTRL + Qt::META + Qt::Key_C));
actions->insert("compactView", compactViewAct);
connect(compactViewAct, SIGNAL(toggled(bool)), this, SLOT(compactView(bool)));
- webPageAct = new QAction(tr("Open the &YouTube page"), this);
+ webPageAct = new QAction(tr("Open the &YouTube Page"), this);
webPageAct->setStatusTip(tr("Go to the YouTube video page and pause playback"));
webPageAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Y));
webPageAct->setEnabled(false);
actions->insert("webpage", webPageAct);
connect(webPageAct, SIGNAL(triggered()), mediaView, SLOT(openWebPage()));
- copyPageAct = new QAction(tr("Copy the YouTube &link"), this);
+ copyPageAct = new QAction(tr("Copy the YouTube &Link"), this);
copyPageAct->setStatusTip(tr("Copy the current video YouTube link to the clipboard"));
copyPageAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L));
copyPageAct->setEnabled(false);
actions->insert("pagelink", copyPageAct);
connect(copyPageAct, SIGNAL(triggered()), mediaView, SLOT(copyWebPage()));
- copyLinkAct = new QAction(tr("Copy the video stream &URL"), this);
+ copyLinkAct = new QAction(tr("Copy the Video Stream &URL"), this);
copyLinkAct->setStatusTip(tr("Copy the current video stream URL to the clipboard"));
copyLinkAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U));
copyLinkAct->setEnabled(false);
actions->insert("videolink", copyLinkAct);
connect(copyLinkAct, SIGNAL(triggered()), mediaView, SLOT(copyVideoLink()));
- findVideoPartsAct = new QAction(tr("Find video &parts"), this);
+ findVideoPartsAct = new QAction(tr("Find Video &Parts"), this);
findVideoPartsAct->setStatusTip(tr("Find other video parts hopefully in the right order"));
findVideoPartsAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
findVideoPartsAct->setEnabled(false);
actions->insert("moveDown", moveDownAct);
connect(moveDownAct, SIGNAL(triggered()), mediaView, SLOT(moveDownSelected()));
- clearAct = new QAction(tr("&Clear recent searches"), this);
+ clearAct = new QAction(tr("&Clear Recent Searches"), this);
clearAct->setMenuRole(QAction::ApplicationSpecificRole);
clearAct->setShortcuts(QList<QKeySequence>()
<< QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Delete)
quitAct = new QAction(tr("&Quit"), this);
quitAct->setMenuRole(QAction::QuitRole);
- quitAct->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Ctrl+Q")) << QKeySequence(Qt::CTRL + Qt::Key_W));
+ quitAct->setShortcut(QKeySequence(QKeySequence::Quit));
quitAct->setStatusTip(tr("Bye"));
actions->insert("quit", quitAct);
- connect(quitAct, SIGNAL(triggered()), this, SLOT(close()));
+ connect(quitAct, SIGNAL(triggered()), SLOT(quit()));
siteAct = new QAction(tr("&Website"), this);
siteAct->setShortcut(QKeySequence::HelpContents);
connect(siteAct, SIGNAL(triggered()), this, SLOT(visitSite()));
#if !defined(APP_MAC) && !defined(APP_WIN)
- donateAct = new QAction(tr("Make a &donation"), this);
+ donateAct = new QAction(tr("Make a &Donation"), this);
donateAct->setStatusTip(tr("Please support the continued development of %1").arg(Constants::NAME));
actions->insert("donate", donateAct);
connect(donateAct, SIGNAL(triggered()), this, SLOT(donate()));
addAction(searchFocusAct);
volumeUpAct = new QAction(this);
- volumeUpAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_Plus) << QKeySequence(Qt::Key_VolumeUp));
+ volumeUpAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_Plus));
actions->insert("volume-up", volumeUpAct);
connect(volumeUpAct, SIGNAL(triggered()), this, SLOT(volumeUp()));
addAction(volumeUpAct);
volumeDownAct = new QAction(this);
- volumeDownAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_Minus) << QKeySequence(Qt::Key_VolumeDown));
+ volumeDownAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_Minus));
actions->insert("volume-down", volumeDownAct);
connect(volumeDownAct, SIGNAL(triggered()), this, SLOT(volumeDown()));
addAction(volumeDownAct);
volumeMuteAct = new QAction(this);
volumeMuteAct->setIcon(QtIconLoader::icon("audio-volume-high"));
volumeMuteAct->setStatusTip(tr("Mute volume"));
- volumeMuteAct->setShortcuts(QList<QKeySequence>()
- << QKeySequence(tr("Ctrl+M"))
- << QKeySequence(Qt::Key_VolumeMute));
+ volumeMuteAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_E));
actions->insert("volume-mute", volumeMuteAct);
connect(volumeMuteAct, SIGNAL(triggered()), SLOT(volumeMute()));
addAction(volumeMuteAct);
QAction *action;
- /*
- action = new QAction(tr("&Autoplay"), this);
- action->setStatusTip(tr("Automatically start playing videos"));
- action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
+ action = new QAction(QtIconLoader::icon("media-playback-start"), tr("&Manually Start Playing"), this);
+ action->setStatusTip(tr("Manually start playing videos"));
+ action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B));
action->setCheckable(true);
- connect(action, SIGNAL(toggled(bool)), SLOT(setAutoplay(bool)));
- actions->insert("autoplay", action);
- */
+ connect(action, SIGNAL(toggled(bool)), SLOT(setManualPlay(bool)));
+ actions->insert("manualplay", action);
action = new QAction(tr("&Downloads"), this);
action->setStatusTip(tr("Show details about video downloads"));
actions->insert("email", action);
connect(action, SIGNAL(triggered()), mediaView, SLOT(shareViaEmail()));
+ action = new QAction(tr("&Close"), this);
+ action->setShortcut(QKeySequence(QKeySequence::Close));
+ actions->insert("close", action);
+ connect(action, SIGNAL(triggered()), SLOT(close()));
+
+ action = new QAction(QtIconLoader::icon("go-top"), tr("&Float on Top"), this);
+ action->setCheckable(true);
+ actions->insert("ontop", action);
+ connect(action, SIGNAL(toggled(bool)), SLOT(floatOnTop(bool)));
+
+ action = new QAction(QtIconLoader::icon("media-playback-stop"), tr("&Stop After This Video"), this);
+ action->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Escape));
+ action->setCheckable(true);
+ action->setEnabled(false);
+ actions->insert("stopafterthis", action);
+ connect(action, SIGNAL(toggled(bool)), SLOT(showStopAfterThisInStatusBar(bool)));
+
// common action properties
foreach (QAction *action, actions->values()) {
action->setAutoRepeat(false);
// set to something more meaningful then the toolbar text
- // HELP! how to remove tooltips altogether?!
if (!action->statusTip().isEmpty())
action->setToolTip(action->statusTip());
QMap<QString, QMenu*> *menus = The::globalMenus();
fileMenu = menuBar()->addMenu(tr("&Application"));
- // menus->insert("file", fileMenu);
+#ifdef APP_DEMO
+ QAction* action = new QAction(tr("Buy %1...").arg(Constants::NAME), this);
+ action->setMenuRole(QAction::ApplicationSpecificRole);
+ connect(action, SIGNAL(triggered()), SLOT(buy()));
+ fileMenu->addAction(action);
+#endif
fileMenu->addAction(clearAct);
#ifndef APP_MAC
fileMenu->addSeparator();
QMenu* playbackMenu = menuBar()->addMenu(tr("&Playback"));
menus->insert("playback", playbackMenu);
- playbackMenu->addAction(stopAct);
playbackMenu->addAction(pauseAct);
+ playbackMenu->addAction(stopAct);
+ playbackMenu->addAction(The::globalActions()->value("stopafterthis"));
+ playbackMenu->addSeparator();
playbackMenu->addAction(skipAct);
+ playbackMenu->addAction(skipBackwardAct);
+ playbackMenu->addSeparator();
+ playbackMenu->addAction(The::globalActions()->value("manualplay"));
#ifdef APP_MAC
MacSupport::dockMenu(playbackMenu);
#endif
menus->insert("view", viewMenu);
viewMenu->addAction(fullscreenAct);
viewMenu->addAction(compactViewAct);
+ viewMenu->addSeparator();
+ viewMenu->addAction(The::globalActions()->value("ontop"));
QMenu* shareMenu = menuBar()->addMenu(tr("&Share"));
menus->insert("share", shareMenu);
shareMenu->addAction(The::globalActions()->value("facebook"));
shareMenu->addAction(The::globalActions()->value("email"));
+#ifdef APP_MAC
+ MacSupport::windowMenu(this);
+#endif
+
helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(siteAct);
#if !defined(APP_MAC) && !defined(APP_WIN)
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 YouTubeSuggest(this));
+ connect(toolbarSearch, SIGNAL(search(const QString&)), this, SLOT(startToolbarSearch(const QString&)));
+ connect(toolbarSearch, SIGNAL(suggestionAccepted(const QString&)), SLOT(startToolbarSearch(const QString&)));
toolbarSearch->setStatusTip(searchFocusAct->statusTip());
+#ifdef APP_MAC
+ mainToolBar->addWidget(searchWrapper);
+#else
mainToolBar->addWidget(toolbarSearch);
-
- mainToolBar->addWidget(new Spacer());
+ Spacer* spacer = new Spacer();
+ // spacer->setWidth(4);
+ mainToolBar->addWidget(spacer);
+#endif
addToolBar(mainToolBar);
}
void MainWindow::createStatusBar() {
- QToolBar *toolBar = new QToolBar(this);
+ QToolBar* toolBar = new QToolBar(this);
+ statusToolBar = toolBar;
toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
toolBar->setIconSize(QSize(16, 16));
toolBar->addAction(The::globalActions()->value("downloads"));
- // toolBar->addAction(The::globalActions()->value("autoplay"));
toolBar->addAction(The::globalActions()->value("definition"));
statusBar()->addPermanentWidget(toolBar);
statusBar()->show();
}
+void MainWindow::showStopAfterThisInStatusBar(bool show) {
+ QAction* action = The::globalActions()->value("stopafterthis");
+ showActionInStatusBar(action, show);
+}
+
+void MainWindow::showActionInStatusBar(QAction* action, bool show) {
+ if (show) {
+ statusToolBar->insertAction(statusToolBar->actions().first(), action);
+ } else {
+ statusToolBar->removeAction(action);
+ }
+}
+
void MainWindow::readSettings() {
QSettings settings;
restoreGeometry(settings.value("geometry").toByteArray());
setDefinitionMode(settings.value("definition", VideoDefinition::getDefinitionNames().first()).toString());
audioOutput->setVolume(settings.value("volume", 1).toDouble());
audioOutput->setMuted(settings.value("volumeMute").toBool());
+ The::globalActions()->value("manualplay")->setChecked(settings.value("manualplay", false).toBool());
}
void MainWindow::writeSettings() {
settings.setValue("volume", audioOutput->volume());
settings.setValue("volumeMute", audioOutput->isMuted());
+ settings.setValue("manualplay", The::globalActions()->value("manualplay")->isChecked());
mediaView->saveSplitterState();
}
View* oldView = dynamic_cast<View *> (views->currentWidget());
if (oldView) {
oldView->disappear();
+ views->currentWidget()->setEnabled(false);
}
// call show method on the new view
View* newView = dynamic_cast<View *> (widget);
if (newView) {
+ widget->setEnabled(true);
newView->appear();
QMap<QString,QVariant> metadata = newView->metadata();
QString windowTitle = metadata.value("title").toString();
findVideoPartsAct->setEnabled(widget == mediaView);
toolbarSearch->setEnabled(widget == searchView || widget == mediaView || widget == downloadView);
+ if (widget == searchView) {
+ skipAct->setEnabled(false);
+ The::globalActions()->value("previous")->setEnabled(false);
+ The::globalActions()->value("download")->setEnabled(false);
+ The::globalActions()->value("stopafterthis")->setEnabled(false);
+ }
+
The::globalActions()->value("twitter")->setEnabled(widget == mediaView);
The::globalActions()->value("facebook")->setEnabled(widget == mediaView);
The::globalActions()->value("email")->setEnabled(widget == mediaView);
aboutAct->setEnabled(widget != aboutView);
- The::globalActions()->value("download")->setEnabled(widget == mediaView);
The::globalActions()->value("downloads")->setChecked(widget == downloadView);
// toolbar only for the mediaView
}
void MainWindow::quit() {
+#ifdef APP_MAC
+ if (!confirmQuit()) {
+ return;
+ }
+#endif
writeSettings();
Temporary::deleteAll();
qApp->quit();
}
void MainWindow::closeEvent(QCloseEvent *event) {
+#ifdef APP_MAC
+ mac::closeWindow(winId());
+ event->ignore();
+#else
+ if (!confirmQuit()) {
+ event->ignore();
+ return;
+ }
+ quit();
+ QWidget::closeEvent(event);
+#endif
+}
+
+bool MainWindow::confirmQuit() {
if (DownloadManager::instance()->activeItems() > 0) {
- QMessageBox msgBox;
+ QMessageBox msgBox(this);
msgBox.setIconPixmap(QPixmap(":/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);
+ // make it a "sheet" on the Mac
+ msgBox.setWindowModality(Qt::WindowModal);
msgBox.addButton(tr("Close and cancel download"), QMessageBox::RejectRole);
QPushButton *waitButton = msgBox.addButton(tr("Wait for download to finish"), QMessageBox::ActionRole);
msgBox.exec();
if (msgBox.clickedButton() == waitButton) {
- event->ignore();
- return;
+ return false;
}
-
}
- quit();
- QWidget::closeEvent(event);
+ return true;
}
void MainWindow::showSearch() {
}
void MainWindow::showMedia(SearchParams *searchParams) {
- if (toolbarSearch->text().isEmpty() && !searchParams->keywords().isEmpty()) {
- toolbarSearch->lineEdit()->setText(searchParams->keywords());
- }
mediaView->search(searchParams);
showWidget(mediaView);
}
pauseAct->setIcon(QtIconLoader::icon("media-playback-pause"));
pauseAct->setText(tr("&Pause"));
pauseAct->setStatusTip(tr("Pause playback") + " (" + pauseAct->shortcut().toString(QKeySequence::NativeText) + ")");
- skipAct->setEnabled(true);
// stopAct->setEnabled(true);
break;
case Phonon::StoppedState:
pauseAct->setEnabled(false);
- skipAct->setEnabled(false);
// stopAct->setEnabled(false);
break;
case Phonon::PausedState:
- skipAct->setEnabled(true);
pauseAct->setEnabled(true);
pauseAct->setIcon(QtIconLoader::icon("media-playback-start"));
pauseAct->setText(tr("&Play"));
case Phonon::BufferingState:
case Phonon::LoadingState:
- skipAct->setEnabled(true);
pauseAct->setEnabled(false);
currentTime->clear();
totalTime->clear();
void MainWindow::fullscreen() {
+ /*
+ if (compactViewAct->isChecked())
+ compactView(false);
+ */
+
#ifdef Q_WS_MAC
WId handle = winId();
if (mac::CanGoFullScreen(handle)) {
+ mainToolBar->setVisible(true);
mac::ToggleFullScreen(handle);
return;
}
statusBar()->showMessage(tr("Your privacy is now safe"));
}
-/*
- void MainWindow::setAutoplay(bool enabled) {
- QSettings settings;
- settings.setValue("autoplay", QVariant::fromValue(enabled));
- }
- */
+void MainWindow::setManualPlay(bool enabled) {
+ QSettings settings;
+ settings.setValue("manualplay", QVariant::fromValue(enabled));
+ showActionInStatusBar(The::globalActions()->value("manualplay"), enabled);
+}
void MainWindow::updateDownloadMessage(QString message) {
The::globalActions()->value("downloads")->setText(message);
}
}
+
+void MainWindow::floatOnTop(bool onTop) {
+ showActionInStatusBar(The::globalActions()->value("ontop"), onTop);
+#ifdef APP_MAC
+ mac::floatOnTop(winId(), onTop);
+ return;
+#endif
+ if (onTop) {
+ setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
+ show();
+ } else {
+ setWindowFlags(windowFlags() ^ Qt::WindowStaysOnTopHint);
+ show();
+ }
+}
+
+void MainWindow::messageReceived(const QString &message) {
+ if (!message.isEmpty()) {
+ SearchParams *searchParams = new SearchParams();
+ searchParams->setKeywords(message);
+ showMedia(searchParams);
+ }
+}