X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2FMainWindow.cpp;h=137ee6f46550b0bb7c7c613402864e68119d7458;hb=57c25e20a8f10a98a18dbc2b64ce55cf87d4fd7c;hp=1ef752bd424d60008f45786f3d787c00b85f73af;hpb=e536746e91459fb3a7735f36caee77f299c765e2;p=minitube diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp old mode 100755 new mode 100644 index 1ef752b..137ee6f --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -9,17 +9,29 @@ #ifdef Q_WS_X11 #include "gnomeglobalshortcutbackend.h" #endif -#ifdef APP_MAC -// #include "local/mac/mac_startup.h" +#ifdef Q_WS_MAC +#include "mac_startup.h" +#include "macfullscreen.h" +#include "macsupport.h" +#endif +#ifndef Q_WS_X11 +#include "extra.h" #endif #include "downloadmanager.h" +#include "youtubesuggest.h" +#include "updatechecker.h" +#ifdef APP_DEMO +#include "demostartupview.h" +#endif +#include "temporary.h" MainWindow::MainWindow() : aboutView(0), downloadView(0), mediaObject(0), audioOutput(0), - m_fullscreen(false) { + m_fullscreen(false), + updateChecker(0) { // views mechanism history = new QStack(); @@ -28,7 +40,7 @@ MainWindow::MainWindow() : // views searchView = new SearchView(this); - connect(searchView, SIGNAL(search(QString)), this, SLOT(showMedia(QString))); + connect(searchView, SIGNAL(search(SearchParams*)), this, SLOT(showMedia(SearchParams*))); views->addWidget(searchView); mediaView = new MediaView(this); @@ -36,7 +48,8 @@ MainWindow::MainWindow() : toolbarSearch = new SearchLineEdit(this); toolbarSearch->setMinimumWidth(toolbarSearch->fontInfo().pixelSize()*15); - connect(toolbarSearch, SIGNAL(search(const QString&)), searchView, SLOT(watch(const QString&))); + toolbarSearch->setSuggester(new YouTubeSuggest(this)); + connect(toolbarSearch, SIGNAL(search(const QString&)), this, SLOT(startToolbarSearch(const QString&))); // build ui createActions(); @@ -61,7 +74,13 @@ MainWindow::MainWindow() : readSettings(); // show the initial view - showWidget(searchView); +#ifdef APP_DEMO + QWidget *demoStartupView = new DemoStartupView(this); + views->addWidget(demoStartupView); + showWidget(demoStartupView); +#else + showSearch(); +#endif // Global shortcuts GlobalShortcuts &shortcuts = GlobalShortcuts::instance(); @@ -69,8 +88,8 @@ MainWindow::MainWindow() : if (GnomeGlobalShortcutBackend::IsGsdAvailable()) shortcuts.setBackend(new GnomeGlobalShortcutBackend(&shortcuts)); #endif -#ifdef APP_MAC - // mac::MacSetup(); +#ifdef Q_WS_MAC + mac::MacSetup(); #endif connect(&shortcuts, SIGNAL(PlayPause()), pauseAct, SLOT(trigger())); connect(&shortcuts, SIGNAL(Stop()), this, SLOT(stop())); @@ -80,6 +99,11 @@ MainWindow::MainWindow() : SLOT(updateDownloadMessage(QString))); connect(DownloadManager::instance(), SIGNAL(finished()), SLOT(downloadsFinished())); + + setAcceptDrops(true); + + QTimer::singleShot(0, this, SLOT(checkForUpdate())); + } MainWindow::~MainWindow() { @@ -87,13 +111,25 @@ MainWindow::~MainWindow() { } bool MainWindow::eventFilter(QObject *obj, QEvent *event) { +#ifdef Q_WS_X11 + if (event->type() == QEvent::MouseMove && this->m_fullscreen) { + QMouseEvent *mouseEvent = static_cast (event); + int x = mouseEvent->pos().x(); + int y = mouseEvent->pos().y(); + + if (y < 0 && (obj == this->mainToolBar || !(y <= 10-this->mainToolBar->height() && y >= 0-this->mainToolBar->height() ))) + this->mainToolBar->setVisible(false); + if (x < 0) + this->mediaView->setPlaylistVisible(false); + } +#endif + if (event->type() == QEvent::ToolTip) { // kill tooltips return true; - } else { - // standard event processing - return QObject::eventFilter(obj, event); } + // standard event processing + return QObject::eventFilter(obj, event); } void MainWindow::createActions() { @@ -123,7 +159,13 @@ void MainWindow::createActions() { fullscreenAct = new QAction(QtIconLoader::icon("view-fullscreen"), tr("&Full Screen"), this); fullscreenAct->setStatusTip(tr("Go full screen")); - fullscreenAct->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Return)); + QList fsShortcuts; +#ifdef APP_MAC + fsShortcuts << QKeySequence(Qt::CTRL + Qt::META + Qt::Key_F); +#else + fsShortcuts << QKeySequence(Qt::Key_F11); +#endif + fullscreenAct->setShortcuts(fsShortcuts); fullscreenAct->setShortcutContext(Qt::ApplicationShortcut); #if QT_VERSION >= 0x040600 fullscreenAct->setPriority(QAction::LowPriority); @@ -133,7 +175,11 @@ void MainWindow::createActions() { compactViewAct = new QAction(tr("&Compact mode"), this); compactViewAct->setStatusTip(tr("Hide the playlist and the toolbar")); - compactViewAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Return)); +#ifdef APP_MAC + compactViewAct->setShortcut(QKeySequence(Qt::CTRL + Qt::META + Qt::Key_C)); +#else + compactViewAct->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C)); +#endif compactViewAct->setCheckable(true); compactViewAct->setChecked(false); compactViewAct->setEnabled(false); @@ -161,6 +207,13 @@ void MainWindow::createActions() { actions->insert("videolink", copyLinkAct); connect(copyLinkAct, SIGNAL(triggered()), mediaView, SLOT(copyVideoLink())); + 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); + connect(findVideoPartsAct, SIGNAL(triggered()), mediaView, SLOT(findVideoParts())); + actions->insert("findVideoParts", findVideoPartsAct); + removeAct = new QAction(tr("&Remove"), this); removeAct->setStatusTip(tr("Remove the selected videos from the playlist")); removeAct->setShortcuts(QList() << QKeySequence("Del") << QKeySequence("Backspace")); @@ -182,7 +235,7 @@ void MainWindow::createActions() { actions->insert("moveDown", moveDownAct); connect(moveDownAct, SIGNAL(triggered()), mediaView, SLOT(moveDownSelected())); - clearAct = new QAction(tr("&Clear recent keywords"), this); + clearAct = new QAction(tr("&Clear recent searches"), this); clearAct->setMenuRole(QAction::ApplicationSpecificRole); clearAct->setShortcuts(QList() << QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Delete) @@ -201,18 +254,20 @@ void MainWindow::createActions() { siteAct = new QAction(tr("&Website"), this); siteAct->setShortcut(QKeySequence::HelpContents); - siteAct->setStatusTip(tr("%1 on the Web").arg(Constants::APP_NAME)); + siteAct->setStatusTip(tr("%1 on the Web").arg(Constants::NAME)); actions->insert("site", siteAct); connect(siteAct, SIGNAL(triggered()), this, SLOT(visitSite())); +#if !defined(APP_MAC) && !defined(APP_WIN) donateAct = new QAction(tr("Make a &donation"), this); - donateAct->setStatusTip(tr("Please support the continued development of %1").arg(Constants::APP_NAME)); + donateAct->setStatusTip(tr("Please support the continued development of %1").arg(Constants::NAME)); actions->insert("donate", donateAct); connect(donateAct, SIGNAL(triggered()), this, SLOT(donate())); +#endif aboutAct = new QAction(tr("&About"), this); aboutAct->setMenuRole(QAction::AboutRole); - aboutAct->setStatusTip(tr("Info about %1").arg(Constants::APP_NAME)); + aboutAct->setStatusTip(tr("Info about %1").arg(Constants::NAME)); actions->insert("about", aboutAct); connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); @@ -283,7 +338,9 @@ void MainWindow::createActions() { action = new QAction(tr("&Download"), this); action->setStatusTip(tr("Download the current video")); +#ifndef APP_NO_DOWNLOADS action->setShortcut(QKeySequence::Save); +#endif action->setIcon(QtIconLoader::icon("go-down")); action->setEnabled(false); #if QT_VERSION >= 0x040600 @@ -292,6 +349,23 @@ void MainWindow::createActions() { connect(action, SIGNAL(triggered()), mediaView, SLOT(downloadVideo())); actions->insert("download", action); + QString shareTip = tr("Share the current video using %1"); + + action = new QAction("&Twitter", this); + action->setStatusTip(shareTip.arg("Twitter")); + actions->insert("twitter", action); + connect(action, SIGNAL(triggered()), mediaView, SLOT(shareViaTwitter())); + + action = new QAction("&Facebook", this); + action->setStatusTip(shareTip.arg("Facebook")); + actions->insert("facebook", action); + connect(action, SIGNAL(triggered()), mediaView, SLOT(shareViaFacebook())); + + action = new QAction(tr("&Email"), this); + action->setStatusTip(shareTip.arg(tr("Email"))); + actions->insert("email", action); + connect(action, SIGNAL(triggered()), mediaView, SLOT(shareViaEmail())); + // common action properties foreach (QAction *action, actions->values()) { @@ -331,6 +405,15 @@ void MainWindow::createMenus() { #endif fileMenu->addAction(quitAct); + QMenu* playbackMenu = menuBar()->addMenu(tr("&Playback")); + menus->insert("playback", playbackMenu); + playbackMenu->addAction(stopAct); + playbackMenu->addAction(pauseAct); + playbackMenu->addAction(skipAct); +#ifdef APP_MAC + MacSupport::dockMenu(playbackMenu); +#endif + playlistMenu = menuBar()->addMenu(tr("&Playlist")); menus->insert("playlist", playlistMenu); playlistMenu->addAction(removeAct); @@ -338,28 +421,35 @@ void MainWindow::createMenus() { playlistMenu->addAction(moveUpAct); playlistMenu->addAction(moveDownAct); - viewMenu = menuBar()->addMenu(tr("&Video")); - menus->insert("video", viewMenu); - viewMenu->addAction(stopAct); - viewMenu->addAction(pauseAct); - viewMenu->addAction(skipAct); - viewMenu->addSeparator(); - viewMenu->addAction(The::globalActions()->value("download")); - viewMenu->addSeparator(); - viewMenu->addAction(webPageAct); - viewMenu->addAction(copyPageAct); - viewMenu->addAction(copyLinkAct); - viewMenu->addSeparator(); - viewMenu->addAction(compactViewAct); - viewMenu->addAction(fullscreenAct); -#ifdef APP_MAC - extern void qt_mac_set_dock_menu(QMenu *); - qt_mac_set_dock_menu(viewMenu); + QMenu* videoMenu = menuBar()->addMenu(tr("&Video")); + menus->insert("video", videoMenu); + videoMenu->addAction(findVideoPartsAct); + videoMenu->addSeparator(); + videoMenu->addAction(webPageAct); +#ifndef APP_NO_DOWNLOADS + videoMenu->addSeparator(); + videoMenu->addAction(The::globalActions()->value("download")); + videoMenu->addAction(copyLinkAct); #endif + QMenu* viewMenu = menuBar()->addMenu(tr("&View")); + menus->insert("view", viewMenu); + viewMenu->addAction(fullscreenAct); + viewMenu->addAction(compactViewAct); + + QMenu* shareMenu = menuBar()->addMenu(tr("&Share")); + menus->insert("share", shareMenu); + shareMenu->addAction(copyPageAct); + shareMenu->addSeparator(); + shareMenu->addAction(The::globalActions()->value("twitter")); + shareMenu->addAction(The::globalActions()->value("facebook")); + shareMenu->addAction(The::globalActions()->value("email")); + helpMenu = menuBar()->addMenu(tr("&Help")); helpMenu->addAction(siteAct); +#if !defined(APP_MAC) && !defined(APP_WIN) helpMenu->addAction(donateAct); +#endif helpMenu->addAction(aboutAct); } @@ -376,15 +466,23 @@ void MainWindow::createToolBars() { mainToolBar->setFloatable(false); mainToolBar->setMovable(false); -#ifdef APP_MAC +#if defined(APP_MAC) | defined(APP_WIN) mainToolBar->setIconSize(QSize(32, 32)); #endif mainToolBar->addAction(stopAct); mainToolBar->addAction(pauseAct); mainToolBar->addAction(skipAct); - mainToolBar->addAction(fullscreenAct); + + bool addFullScreenAct = true; +#ifdef Q_WS_MAC + addFullScreenAct = !mac::CanGoFullScreen(winId()); +#endif + if (addFullScreenAct) mainToolBar->addAction(fullscreenAct); + +#ifndef APP_NO_DOWNLOADS mainToolBar->addAction(The::globalActions()->value("download")); +#endif mainToolBar->addWidget(new Spacer()); @@ -396,16 +494,12 @@ void MainWindow::createToolBars() { mainToolBar->addWidget(new Spacer()); seekSlider = new Phonon::SeekSlider(this); -#ifdef Q_WS_X11 - seekSlider->setDisabled(true); -#endif seekSlider->setIconVisible(false); seekSlider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); mainToolBar->addWidget(seekSlider); - mainToolBar->addWidget(new Spacer()); - /* + mainToolBar->addWidget(new Spacer()); slider = new QSlider(this); slider->setOrientation(Qt::Horizontal); slider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); @@ -445,11 +539,6 @@ void MainWindow::createToolBars() { } void MainWindow::createStatusBar() { - - // remove ugly borders on OSX - // also remove excessive spacing - statusBar()->setStyleSheet("::item{border:0 solid} QToolBar {padding:0;spacing:0;margin:0}"); - QToolBar *toolBar = new QToolBar(this); toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); toolBar->setIconSize(QSize(16, 16)); @@ -457,7 +546,6 @@ void MainWindow::createStatusBar() { // toolBar->addAction(The::globalActions()->value("autoplay")); toolBar->addAction(The::globalActions()->value("definition")); statusBar()->addPermanentWidget(toolBar); - statusBar()->show(); } @@ -465,8 +553,7 @@ void MainWindow::readSettings() { QSettings settings; restoreGeometry(settings.value("geometry").toByteArray()); #ifdef APP_MAC - if (!isMaximized()) - move(x(), y() + 10); + MacSupport::fixGeometry(this); #endif setDefinitionMode(settings.value("definition", VideoDefinition::getDefinitionNames().first()).toString()); audioOutput->setVolume(settings.value("volume", 1).toDouble()); @@ -513,16 +600,22 @@ void MainWindow::showWidget ( QWidget* widget ) { QString windowTitle = metadata.value("title").toString(); if (windowTitle.length()) windowTitle += " - "; - setWindowTitle(windowTitle + Constants::APP_NAME); + setWindowTitle(windowTitle + Constants::NAME); statusBar()->showMessage((metadata.value("description").toString())); } stopAct->setEnabled(widget == mediaView); - fullscreenAct->setEnabled(widget == mediaView); compactViewAct->setEnabled(widget == mediaView); webPageAct->setEnabled(widget == mediaView); copyPageAct->setEnabled(widget == mediaView); copyLinkAct->setEnabled(widget == mediaView); + findVideoPartsAct->setEnabled(widget == mediaView); + toolbarSearch->setEnabled(widget == searchView || widget == mediaView || widget == downloadView); + + 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); @@ -538,25 +631,13 @@ void MainWindow::showWidget ( QWidget* widget ) { QWidget *oldWidget = views->currentWidget(); views->setCurrentWidget(widget); -#ifdef APP_MAC - // crossfade only on OSX - // where we can be sure of video performance - fadeInWidget(oldWidget, widget); +#ifndef Q_WS_X11 + Extra::fadeInWidget(oldWidget, widget); #endif history->push(widget); } -void MainWindow::fadeInWidget(QWidget *oldWidget, QWidget *newWidget) { - if (faderWidget) faderWidget->close(); - if (!oldWidget || !newWidget) { - // qDebug() << "no widgets"; - return; - } - faderWidget = new FaderWidget(newWidget); - faderWidget->start(QPixmap::grabWidget(oldWidget)); -} - void MainWindow::about() { if (!aboutView) { aboutView = new AboutView(this); @@ -579,6 +660,7 @@ void MainWindow::donate() { void MainWindow::quit() { writeSettings(); + Temporary::deleteAll(); qApp->quit(); } @@ -586,8 +668,8 @@ void MainWindow::closeEvent(QCloseEvent *event) { if (DownloadManager::instance()->activeItems() > 0) { QMessageBox msgBox; 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::APP_NAME)); - msgBox.setInformativeText(tr("If you close %1 now, this download will be cancelled.").arg(Constants::APP_NAME)); + 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); msgBox.addButton(tr("Close and cancel download"), QMessageBox::RejectRole); @@ -611,9 +693,10 @@ void MainWindow::showSearch() { totalTime->clear(); } -void MainWindow::showMedia(QString query) { - SearchParams *searchParams = new SearchParams(); - searchParams->setKeywords(query); +void MainWindow::showMedia(SearchParams *searchParams) { + if (toolbarSearch->text().isEmpty() && !searchParams->keywords().isEmpty()) { + toolbarSearch->lineEdit()->setText(searchParams->keywords()); + } mediaView->search(searchParams); showWidget(mediaView); } @@ -626,7 +709,9 @@ void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState case Phonon::ErrorState: if (mediaObject->errorType() == Phonon::FatalError) { - statusBar()->showMessage(tr("Fatal error: %1").arg(mediaObject->errorString())); + // 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())); } else { statusBar()->showMessage(tr("Error: %1").arg(mediaObject->errorString())); } @@ -675,58 +760,51 @@ void MainWindow::stop() { showSearch(); } -void MainWindow::fullscreen() { +void MainWindow::resizeEvent(QResizeEvent*) { +#ifdef Q_WS_MAC + if (mac::CanGoFullScreen(winId())) { + bool isFullscreen = mac::IsFullScreen(winId()); + if (isFullscreen != m_fullscreen) { + m_fullscreen = isFullscreen; + updateUIForFullscreen(); + } + } +#endif +} - // No compact view action when in full screen - compactViewAct->setVisible(m_fullscreen); - compactViewAct->setChecked(false); +void MainWindow::fullscreen() { - // Also no Youtube action since it opens a new window - webPageAct->setVisible(m_fullscreen); - copyPageAct->setVisible(m_fullscreen); - copyLinkAct->setVisible(m_fullscreen); +#ifdef Q_WS_MAC + WId handle = winId(); + if (mac::CanGoFullScreen(handle)) { + mac::ToggleFullScreen(handle); + return; + } +#endif - stopAct->setVisible(m_fullscreen); + m_fullscreen = !m_fullscreen; - // workaround: prevent focus on the search bar - // it steals the Space key needed for Play/Pause - toolbarSearch->setEnabled(m_fullscreen); + if (m_fullscreen) { + // Enter full screen - // Hide anything but the video - mediaView->setPlaylistVisible(m_fullscreen); - statusBar()->setVisible(m_fullscreen); + m_maximized = isMaximized(); -#ifndef APP_MAC - menuBar()->setVisible(m_fullscreen); -#endif + // save geometry now, if the user quits when in full screen + // geometry won't be saved + writeSettings(); -#ifdef APP_MAC - // make the actions work when video is fullscreen (on the Mac) - QMap *actions = The::globalActions(); - foreach (QAction *action, actions->values()) { - if (m_fullscreen) { - action->setShortcutContext(Qt::WindowShortcut); - } else { - action->setShortcutContext(Qt::ApplicationShortcut); - } - } +#ifdef Q_WS_MAC + MacSupport::enterFullScreen(this, views); +#else + mainToolBar->hide(); + showFullScreen(); #endif - if (m_fullscreen) { - + } else { // Exit full screen - // use setShortcuts instead of setShortcut - // the latter seems not to work - fullscreenAct->setShortcuts(QList() << QKeySequence(Qt::ALT + Qt::Key_Return)); - fullscreenAct->setText(tr("&Full Screen")); - stopAct->setShortcuts(QList() << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::Key_MediaStop)); - -#ifdef APP_MAC - setCentralWidget(views); - views->showNormal(); - show(); - mediaView->setFocus(); +#ifdef Q_WS_MAC + MacSupport::exitFullScreen(this, views); #else mainToolBar->show(); if (m_maximized) showMaximized(); @@ -736,65 +814,104 @@ void MainWindow::fullscreen() { // Make sure the window has focus activateWindow(); - } else { + } - // Enter full screen + updateUIForFullscreen(); - stopAct->setShortcuts(QList() << QKeySequence(Qt::Key_MediaStop)); - fullscreenAct->setShortcuts(QList() << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::ALT + Qt::Key_Return)); - fullscreenAct->setText(tr("Exit &Full Screen")); - m_maximized = isMaximized(); +} - // save geometry now, if the user quits when in full screen - // geometry won't be saved - writeSettings(); +void MainWindow::updateUIForFullscreen() { + static QList fsShortcuts; + static QString fsText; -#ifdef APP_MAC - hide(); - views->setParent(0); - QTimer::singleShot(0, views, SLOT(showFullScreen())); -#else - mainToolBar->hide(); - showFullScreen(); + if (m_fullscreen) { + fsShortcuts = fullscreenAct->shortcuts(); + fsText = fullscreenAct->text(); + fullscreenAct->setShortcuts(QList(fsShortcuts) + << QKeySequence(Qt::Key_Escape)); + fullscreenAct->setText(tr("Leave &Full Screen")); + } else { + fullscreenAct->setShortcuts(fsShortcuts); + fullscreenAct->setText(fsText); + } + + // No compact view action when in full screen + compactViewAct->setVisible(!m_fullscreen); + compactViewAct->setChecked(false); + + // Hide anything but the video + mediaView->setPlaylistVisible(!m_fullscreen); + statusBar()->setVisible(!m_fullscreen); + +#ifndef APP_MAC + menuBar()->setVisible(!m_fullscreen); #endif + if (m_fullscreen) { + stopAct->setShortcuts(QList() << QKeySequence(Qt::Key_MediaStop)); + } else { + stopAct->setShortcuts(QList() << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::Key_MediaStop)); } - m_fullscreen = !m_fullscreen; +#ifdef Q_WS_MAC + MacSupport::fullScreenActions(The::globalActions()->values(), m_fullscreen); +#endif + if (views->currentWidget() == mediaView) + mediaView->setFocus(); } void MainWindow::compactView(bool enable) { - mediaView->setPlaylistVisible(!enable); - statusBar()->setVisible(!enable); + static QList compactShortcuts; + static QList stopShortcuts; + + /* + const static QString key = "compactGeometry"; + QSettings settings; + */ #ifndef APP_MAC menuBar()->setVisible(!enable); #endif if (enable) { - stopAct->setShortcuts(QList() << QKeySequence(Qt::Key_MediaStop)); - compactViewAct->setShortcuts( - QList() << QKeySequence(Qt::CTRL + Qt::Key_Return) - << QKeySequence(Qt::Key_Escape)); + /* + writeSettings(); + restoreGeometry(settings.value(key).toByteArray()); + */ + + compactShortcuts = compactViewAct->shortcuts(); + stopShortcuts = stopAct->shortcuts(); + + QList newStopShortcuts(stopShortcuts); + newStopShortcuts.removeAll(QKeySequence(Qt::Key_Escape)); + stopAct->setShortcuts(newStopShortcuts); + compactViewAct->setShortcuts(QList(compactShortcuts) << QKeySequence(Qt::Key_Escape)); // ensure focus does not end up to the search box // as it would steal the Space shortcut mediaView->setFocus(); } else { - compactViewAct->setShortcuts(QList() << QKeySequence(Qt::CTRL + Qt::Key_Return)); - stopAct->setShortcuts(QList() << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::Key_MediaStop)); + /* + settings.setValue(key, saveGeometry()); + readSettings(); + */ + + compactViewAct->setShortcuts(compactShortcuts); + stopAct->setShortcuts(stopShortcuts); } + mainToolBar->setVisible(!enable); + mediaView->setPlaylistVisible(!enable); + statusBar()->setVisible(!enable); + } void MainWindow::searchFocus() { QWidget *view = views->currentWidget(); - if (view == mediaView) { - toolbarSearch->selectAll(); - toolbarSearch->setFocus(); - } + toolbarSearch->selectAll(); + toolbarSearch->setFocus(); } void MainWindow::initPhonon() { @@ -817,7 +934,9 @@ void MainWindow::initPhonon() { void MainWindow::tick(qint64 time) { if (time <= 0) { - currentTime->clear(); + // 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; } @@ -883,7 +1002,7 @@ void MainWindow::volumeChanged(qreal newVolume) { // automatically unmute when volume changes if (volumeSlider->audioOutput()->isMuted()) volumeSlider->audioOutput()->setMuted(false); - statusBar()->showMessage(tr("Volume at %1%").arg(newVolume*100)); + statusBar()->showMessage(tr("Volume at %1%").arg((int)(newVolume*100))); } void MainWindow::volumeMutedChanged(bool muted) { @@ -932,7 +1051,9 @@ void MainWindow::showFullscreenPlaylist(bool show) { void MainWindow::clearRecentKeywords() { QSettings settings; settings.remove("recentKeywords"); + settings.remove("recentChannels"); searchView->updateRecentKeywords(); + searchView->updateRecentChannels(); statusBar()->showMessage(tr("Your privacy is now safe")); } @@ -972,3 +1093,115 @@ void MainWindow::toggleDownloads(bool show) { if (show) showWidget(downloadView); else goBack(); } + +void MainWindow::startToolbarSearch(QString query) { + + query = query.trimmed(); + + // check for empty query + if (query.length() == 0) { + return; + } + + SearchParams *searchParams = new SearchParams(); + searchParams->setKeywords(query); + + // go! + showMedia(searchParams); +} + +void MainWindow::dragEnterEvent(QDragEnterEvent *event) { + if (event->mimeData()->hasFormat("text/uri-list")) { + QList urls = event->mimeData()->urls(); + if (urls.isEmpty()) + return; + QUrl url = urls.first(); + QString videoId = YouTubeSearch::videoIdFromUrl(url.toString()); + if (!videoId.isNull()) + event->acceptProposedAction(); + } +} + +void MainWindow::dropEvent(QDropEvent *event) { + QList urls = event->mimeData()->urls(); + if (urls.isEmpty()) + return; + QUrl url = urls.first(); + QString videoId = YouTubeSearch::videoIdFromUrl(url.toString()); + if (!videoId.isNull()) { + setWindowTitle(url.toString()); + SearchParams *searchParams = new SearchParams(); + searchParams->setKeywords(videoId); + showMedia(searchParams); + } +} + +void MainWindow::checkForUpdate() { + static const QString updateCheckKey = "updateCheck"; + + // check every 24h + QSettings settings; + uint unixTime = QDateTime::currentDateTime().toTime_t(); + int lastCheck = settings.value(updateCheckKey).toInt(); + int secondsSinceLastCheck = unixTime - lastCheck; + // qDebug() << "secondsSinceLastCheck" << unixTime << lastCheck << secondsSinceLastCheck; + if (secondsSinceLastCheck < 86400) return; + + // check it out + if (updateChecker) delete updateChecker; + updateChecker = new UpdateChecker(); + connect(updateChecker, SIGNAL(newVersion(QString)), + this, SLOT(gotNewVersion(QString))); + updateChecker->checkForUpdate(); + settings.setValue(updateCheckKey, unixTime); + +} + +void MainWindow::gotNewVersion(QString version) { + if (updateChecker) { + delete updateChecker; + updateChecker = 0; + } + +#if defined(APP_DEMO) || defined(APP_MAC_STORE) + return; +#endif + + QSettings settings; + QString checkedVersion = settings.value("checkedVersion").toString(); + if (checkedVersion == version) return; + + QMessageBox msgBox(this); + msgBox.setIconPixmap(QPixmap(":/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); + // make it a "sheet" on the Mac + msgBox.setWindowModality(Qt::WindowModal); + + QPushButton* laterButton = 0; + QPushButton* updateButton = 0; + +#if defined(APP_MAC) || defined(APP_WIN) + msgBox.setInformativeText( + tr("To get the updated version, download %1 again from the link you received via email and reinstall.") + .arg(Constants::NAME) + ); + laterButton = msgBox.addButton(tr("Remind me later"), QMessageBox::RejectRole); + msgBox.addButton(QMessageBox::Ok); +#else + msgBox.addButton(QMessageBox::Close); + updateButton = msgBox.addButton(tr("Update"), QMessageBox::AcceptRole); +#endif + + msgBox.exec(); + + if (msgBox.clickedButton() != laterButton) { + settings.setValue("checkedVersion", version); + } + + if (updateButton && msgBox.clickedButton() == updateButton) { + QDesktopServices::openUrl(QUrl(QLatin1String(Constants::WEBSITE) + "#download")); + } + +}