+
+/*
+ void MainWindow::setAutoplay(bool enabled) {
+ QSettings settings;
+ settings.setValue("autoplay", QVariant::fromValue(enabled));
+ }
+ */
+
+void MainWindow::updateDownloadMessage(QString message) {
+ The::globalActions()->value("downloads")->setText(message);
+}
+
+void MainWindow::downloadsFinished() {
+ The::globalActions()->value("downloads")->setText(tr("&Downloads"));
+ statusBar()->showMessage(tr("Downloads complete"));
+}
+
+void MainWindow::toggleDownloads(bool show) {
+
+ if (show) {
+ stopAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_MediaStop));
+ The::globalActions()->value("downloads")->setShortcuts(
+ QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_J)
+ << QKeySequence(Qt::Key_Escape));
+ } else {
+ The::globalActions()->value("downloads")->setShortcuts(
+ QList<QKeySequence>() << QKeySequence(Qt::CTRL + Qt::Key_J));
+ stopAct->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::Key_MediaStop));
+ }
+
+ if (!downloadView) {
+ downloadView = new DownloadView(this);
+ views->addWidget(downloadView);
+ }
+ 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<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"));
+ }
+
+}