#ifdef Q_WS_X11
#include "gnomeglobalshortcutbackend.h"
#endif
-#ifdef APP_MAC_STORE
-#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<QWidget*>();
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();
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()));
SLOT(updateDownloadMessage(QString)));
connect(DownloadManager::instance(), SIGNAL(finished()),
SLOT(downloadsFinished()));
+
+ setAcceptDrops(true);
+
+ QTimer::singleShot(0, this, SLOT(checkForUpdate()));
+
}
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<QMouseEvent*> (event);
int x = mouseEvent->pos().x();
if (x < 0)
this->mediaView->setPlaylistVisible(false);
}
+#endif
if (event->type() == QEvent::ToolTip) {
// kill tooltips
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<QKeySequence> 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);
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);
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>() << QKeySequence("Del") << QKeySequence("Backspace"));
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()));
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
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()) {
#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);
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)
mainToolBar = new QToolBar(this);
#if QT_VERSION < 0x040600 | defined(APP_MAC)
mainToolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
-#elif defined(APP_WIN)
- mainToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
- mainToolBar->setStyleSheet(
- "QToolBar {"
- "background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #fafcfd, stop:.5 #e6f0fa, stop:.51 #dde9f7, stop:1 #dde9f7);"
- "border: 0;"
- "border-bottom: 1px solid #a0afc3;"
- "}");
#else
mainToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle);
#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());
}
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;border:0}");
-
QToolBar *toolBar = new QToolBar(this);
toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
toolBar->setIconSize(QSize(16, 16));
// toolBar->addAction(The::globalActions()->value("autoplay"));
toolBar->addAction(The::globalActions()->value("definition"));
statusBar()->addPermanentWidget(toolBar);
-
statusBar()->show();
}
QSettings settings;
restoreGeometry(settings.value("geometry").toByteArray());
#ifdef APP_MAC
- if (!isMaximized())
-#ifdef QT_MAC_USE_COCOA
- move(x(), y() + 10);
-#else
- move(x(), y() + mainToolBar->height() + 8);
-#endif
+ MacSupport::fixGeometry(this);
#endif
setDefinitionMode(settings.value("definition", VideoDefinition::getDefinitionNames().first()).toString());
audioOutput->setVolume(settings.value("volume", 1).toDouble());
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);
QWidget *oldWidget = views->currentWidget();
views->setCurrentWidget(widget);
-#if defined(APP_MAC) || defined(APP_WIN)
- // 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);
void MainWindow::quit() {
writeSettings();
+ Temporary::deleteAll();
qApp->quit();
}
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);
}
void MainWindow::showMedia(SearchParams *searchParams) {
+ if (toolbarSearch->text().isEmpty() && !searchParams->keywords().isEmpty()) {
+ toolbarSearch->lineEdit()->setText(searchParams->keywords());
+ }
mediaView->search(searchParams);
showWidget(mediaView);
}
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()));
}
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<QString, QAction*> *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>() << QKeySequence(Qt::ALT + Qt::Key_Return));
- fullscreenAct->setText(tr("&Full Screen"));
- stopAct->setShortcuts(QList<QKeySequence>() << 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();
// Make sure the window has focus
activateWindow();
- } else {
+ }
- // Enter full screen
+ updateUIForFullscreen();
- stopAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_MediaStop));
- fullscreenAct->setShortcuts(QList<QKeySequence>() << 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<QKeySequence> 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<QKeySequence>(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>() << QKeySequence(Qt::Key_MediaStop));
+ } else {
+ stopAct->setShortcuts(QList<QKeySequence>() << 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<QKeySequence> compactShortcuts;
+ static QList<QKeySequence> stopShortcuts;
+
+ /*
+ const static QString key = "compactGeometry";
+ QSettings settings;
+ */
#ifndef APP_MAC
menuBar()->setVisible(!enable);
#endif
if (enable) {
- stopAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_MediaStop));
- compactViewAct->setShortcuts(
- QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_Return)
- << QKeySequence(Qt::Key_Escape));
+ /*
+ writeSettings();
+ restoreGeometry(settings.value(key).toByteArray());
+ */
+
+ compactShortcuts = compactViewAct->shortcuts();
+ stopShortcuts = stopAct->shortcuts();
+
+ QList<QKeySequence> newStopShortcuts(stopShortcuts);
+ newStopShortcuts.removeAll(QKeySequence(Qt::Key_Escape));
+ stopAct->setShortcuts(newStopShortcuts);
+ compactViewAct->setShortcuts(QList<QKeySequence>(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>() << QKeySequence(Qt::CTRL + Qt::Key_Return));
- stopAct->setShortcuts(QList<QKeySequence>() << 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() {
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;
}
// 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) {
// go!
showMedia(searchParams);
}
+
+void MainWindow::dragEnterEvent(QDragEnterEvent *event) {
+ if (event->mimeData()->hasFormat("text/uri-list")) {
+ QList<QUrl> 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<QUrl> 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"));
+ }
+
+}