()
+ << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::Key_MediaStop));
}
#ifdef Q_OS_MAC
- MacSupport::fullScreenActions(The::globalActions()->values(), fullscreenFlag);
+ MacSupport::fullScreenActions(actionMap, fullScreenActive);
#endif
- if (views->currentWidget() == mediaView)
- mediaView->setFocus();
+ if (views->currentWidget() == mediaView) mediaView->setFocus();
- if (fullscreenFlag) {
- hideMouse();
+ if (fullScreenActive) {
+ if (views->currentWidget() == mediaView) hideFullscreenUI();
} else {
- mouseTimer->stop();
+ fullscreenTimer->stop();
unsetCursor();
}
}
@@ -1321,26 +1424,65 @@ void MainWindow::updateUIForFullscreen() {
bool MainWindow::isReallyFullScreen() {
#ifdef Q_OS_MAC
WId handle = winId();
- if (mac::CanGoFullScreen(handle)) return mac::IsFullScreen(handle);
- else return isFullScreen();
+ if (mac::CanGoFullScreen(handle))
+ return mac::IsFullScreen(handle);
+ else
+ return isFullScreen();
#else
return isFullScreen();
#endif
}
+void MainWindow::missingKeyWarning() {
+ static bool shown = false;
+ if (shown) return;
+ shown = true;
+ QMessageBox msgBox(this);
+ msgBox.setIconPixmap(IconUtils::pixmap(":/images/64x64/app.png", devicePixelRatioF()));
+ msgBox.setText(QString("%1 was built without a Google API key.").arg(Constants::NAME));
+ msgBox.setInformativeText(QString("It won't work unless you enter one."
+ "In alternative you can get %1 from the developer site.")
+ .arg(Constants::NAME));
+ msgBox.setModal(true);
+ msgBox.setWindowModality(Qt::WindowModal);
+ msgBox.addButton(QMessageBox::Close);
+ QPushButton *enterKeyButton =
+ msgBox.addButton(QString("Enter API key..."), QMessageBox::AcceptRole);
+ QPushButton *devButton = msgBox.addButton(QString("Get from %1").arg(Constants::WEBSITE),
+ QMessageBox::AcceptRole);
+ QPushButton *helpButton = msgBox.addButton(QMessageBox::Help);
+
+ msgBox.exec();
+
+ if (msgBox.clickedButton() == helpButton) {
+ QDesktopServices::openUrl(QUrl("https://github.com/flaviotordini/minitube/blob/master/"
+ "README.md#google-api-key"));
+ } else if (msgBox.clickedButton() == enterKeyButton) {
+ bool ok;
+ QString text = QInputDialog::getText(this, QString(), "Google API key:", QLineEdit::Normal,
+ QString(), &ok);
+ if (ok && !text.isEmpty()) {
+ QSettings settings;
+ settings.setValue("googleApiKey", text);
+ YT3::instance().initApiKeys();
+ }
+ } else if (msgBox.clickedButton() == devButton) {
+ QDesktopServices::openUrl(QUrl(Constants::WEBSITE));
+ }
+ shown = false;
+}
+
void MainWindow::compactView(bool enable) {
- m_compact = enable;
+ setUpdatesEnabled(false);
+
+ compactModeActive = enable;
static QList compactShortcuts;
static QList stopShortcuts;
- const static QString key = "compactGeometry";
+ const QString key = "compactGeometry";
QSettings settings;
-#ifndef APP_MAC
- menuBar()->setVisible(!enable);
-#endif
-
if (enable) {
setMinimumSize(320, 180);
#ifdef Q_OS_MAC
@@ -1351,14 +1493,14 @@ void MainWindow::compactView(bool enable) {
if (settings.contains(key))
restoreGeometry(settings.value(key).toByteArray());
else
- resize(320, 180);
+ resize(480, 270);
#ifdef APP_MAC_QMACTOOLBAR
mac::showToolBar(winId(), !enable);
#else
mainToolBar->setVisible(!enable);
#endif
- mediaView->setPlaylistVisible(!enable);
+ mediaView->setSidebarVisibility(!enable);
statusBar()->hide();
compactShortcuts = compactViewAct->shortcuts();
@@ -1367,25 +1509,28 @@ void MainWindow::compactView(bool enable) {
QList newStopShortcuts(stopShortcuts);
newStopShortcuts.removeAll(QKeySequence(Qt::Key_Escape));
stopAct->setShortcuts(newStopShortcuts);
- compactViewAct->setShortcuts(QList(compactShortcuts) << QKeySequence(Qt::Key_Escape));
+ 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 {
+ settings.setValue(key, saveGeometry());
+
// unset minimum size
setMinimumSize(0, 0);
+
#ifdef Q_OS_MAC
mac::SetupFullScreenWindow(winId());
#endif
- settings.setValue(key, saveGeometry());
#ifdef APP_MAC_QMACTOOLBAR
mac::showToolBar(winId(), !enable);
#else
mainToolBar->setVisible(!enable);
#endif
- mediaView->setPlaylistVisible(!enable);
+ mediaView->setSidebarVisibility(!enable);
if (needStatusBar()) setStatusBarVisibility(true);
readSettings();
@@ -1397,9 +1542,26 @@ void MainWindow::compactView(bool enable) {
// auto float on top
floatOnTop(enable, false);
-#ifdef Q_OS_MAC
+#ifdef APP_MAC
mac::compactMode(winId(), enable);
+#else
+ if (enable) {
+ menuVisibleBeforeCompactMode = menuBar()->isVisible();
+ menuBar()->hide();
+ } else {
+ menuBar()->setVisible(menuVisibleBeforeCompactMode);
+ }
#endif
+
+ setUpdatesEnabled(true);
+}
+
+void MainWindow::toggleToolbarMenu() {
+ if (!toolbarMenu) toolbarMenu = new ToolbarMenu(this);
+ if (toolbarMenu->isVisible())
+ toolbarMenu->hide();
+ else
+ toolbarMenu->show();
}
void MainWindow::searchFocus() {
@@ -1407,138 +1569,119 @@ void MainWindow::searchFocus() {
toolbarSearch->setFocus();
}
-#ifdef APP_PHONON
-void MainWindow::initPhonon() {
- // Phonon initialization
- if (mediaObject) delete mediaObject;
- if (audioOutput) delete audioOutput;
- mediaObject = new Phonon::MediaObject(this);
- mediaObject->setTickInterval(100);
- connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
- 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);
+void MainWindow::initMedia() {
+#ifdef MEDIA_QTAV
+ qFatal("QtAV has a showstopper bug. Audio stops randomly. See bug "
+ "https://github.com/wang-bin/QtAV/issues/1184");
+ media = new MediaQtAV(this);
+#elif defined MEDIA_MPV
+ media = new MediaMPV();
+#else
+ qFatal("No media backend defined");
#endif
+ media->init();
+ media->setUserAgent(HttpUtils::stealthUserAgent());
QSettings settings;
- audioOutput->setVolume(settings.value("volume", 1.).toReal());
- // audioOutput->setMuted(settings.value("volumeMute").toBool());
-
- mediaObject->stop();
+ qreal volume = settings.value("volume", 1.).toReal();
+ media->setVolume(volume);
+
+ connect(media, &Media::error, this, &MainWindow::handleError);
+ connect(media, &Media::stateChanged, this, &MainWindow::stateChanged);
+ connect(media, &Media::positionChanged, this, &MainWindow::tick);
+
+ connect(seekSlider, &QSlider::sliderMoved, this, [this](int value) {
+ // value : maxValue = posit ion : duration
+ qint64 ms = (value * media->duration()) / seekSlider->maximum();
+ qDebug() << "Seeking to" << ms;
+ media->seek(ms);
+ if (media->state() == Media::PausedState) media->play();
+ });
+ connect(seekSlider, &QSlider::sliderPressed, this, [this]() {
+ // value : maxValue = position : duration
+ qint64 ms = (seekSlider->value() * media->duration()) / seekSlider->maximum();
+ media->seek(ms);
+ if (media->state() == Media::PausedState) media->play();
+ });
+ connect(media, &Media::started, this, [this]() { seekSlider->setValue(0); });
+
+ connect(media, &Media::volumeChanged, this, &MainWindow::volumeChanged);
+ connect(media, &Media::volumeMutedChanged, this, &MainWindow::volumeMutedChanged);
+ connect(volumeSlider, &QSlider::sliderMoved, this, [this](int value) {
+ qreal volume = (qreal)value / volumeSlider->maximum();
+ media->setVolume(volume);
+ });
+ connect(volumeSlider, &QSlider::sliderPressed, this, [this]() {
+ qreal volume = (qreal)volumeSlider->value() / volumeSlider->maximum();
+ media->setVolume(volume);
+ });
+
+ mediaView->setMedia(media);
}
-#endif
void MainWindow::tick(qint64 time) {
- const QString s = formatTime(time);
- if (s != currentTime->text()) {
- currentTime->setText(s);
- emit currentTimeChanged(s);
+#ifdef APP_MAC
+ bool isDown = seekSlider->property("down").isValid();
+#else
+ bool isDown = seekSlider->isSliderDown();
+#endif
+ if (!isDown && media->state() == Media::PlayingState) {
+ // value : maxValue = position : duration
+ qint64 duration = media->duration();
+ if (duration <= 0) return;
+ int value = (seekSlider->maximum() * media->position()) / duration;
+ seekSlider->setValue(value);
}
- // remaining time
-#ifdef APP_PHONON
- const qint64 remainingTime = mediaObject->remainingTime();
- currentTime->setStatusTip(tr("Remaining time: %1").arg(formatTime(remainingTime)));
-
-#ifndef APP_PHONON_SEEK
- const qint64 totalTime = mediaObject->totalTime();
- slider->blockSignals(true);
- // qWarning() << totalTime << time << time * 100 / totalTime;
- if (totalTime > 0 && time > 0 && !slider->isSliderDown() && mediaObject->state() == Phonon::PlayingState)
- slider->setValue(time * slider->maximum() / totalTime);
- slider->blockSignals(false);
-#endif
-
-#endif
-}
+ const QString s = formatTime(time);
+ if (s != currentTimeLabel->text()) {
+ currentTimeLabel->setText(s);
+ emit currentTimeChanged(s);
-void MainWindow::totalTimeChanged(qint64 time) {
- if (time <= 0) {
- // totalTime->clear();
- return;
+ // remaining time
+ const qint64 remainingTime = media->remainingTime();
+ currentTimeLabel->setStatusTip(tr("Remaining time: %1").arg(formatTime(remainingTime)));
}
- // totalTime->setText(formatTime(time));
-
- /*
- slider->blockSignals(true);
- slider->setMaximum(time/1000);
- slider->blockSignals(false);
- */
}
QString MainWindow::formatTime(qint64 duration) {
duration /= 1000;
QString res;
- int seconds = (int) (duration % 60);
+ int seconds = (int)(duration % 60);
duration /= 60;
- int minutes = (int) (duration % 60);
+ int minutes = (int)(duration % 60);
duration /= 60;
- int hours = (int) (duration % 24);
- if (hours == 0)
- return res.sprintf("%02d:%02d", minutes, seconds);
+ 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() {
-#ifdef APP_PHONON
- qreal newVolume = volumeSlider->audioOutput()->volume() + .1;
- if (newVolume > volumeSlider->maximumVolume())
- newVolume = volumeSlider->maximumVolume();
- volumeSlider->audioOutput()->setVolume(newVolume);
-#endif
+ qreal newVolume = media->volume() + .1;
+ if (newVolume > 1.) newVolume = 1.;
+ media->setVolume(newVolume);
}
void MainWindow::volumeDown() {
-#ifdef APP_PHONON
- qreal newVolume = volumeSlider->audioOutput()->volume() - .1;
- if (newVolume < 0.)
- newVolume = 0.;
- volumeSlider->audioOutput()->setVolume(newVolume);
-#endif
+ qreal newVolume = media->volume() - .1;
+ if (newVolume < 0) newVolume = 0;
+ media->setVolume(newVolume);
}
-void MainWindow::volumeMute() {
-#ifdef APP_PHONON
- 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::toggleVolumeMute() {
+ bool muted = media->volumeMuted();
+ media->setVolumeMuted(!muted);
}
void MainWindow::volumeChanged(qreal newVolume) {
-#ifdef APP_PHONON
// automatically unmute when volume changes
- if (volumeSlider->audioOutput()->isMuted()) volumeSlider->audioOutput()->setMuted(false);
-
- bool isZero = volumeSlider->property("zero").toBool();
- bool styleChanged = false;
- if (newVolume == 0. && !isZero) {
- volumeSlider->setProperty("zero", true);
- styleChanged = true;
- } else if (newVolume > 0. && isZero) {
- volumeSlider->setProperty("zero", false);
- styleChanged = true;
- }
- if (styleChanged) {
- QSlider* volumeQSlider = volumeSlider->findChild();
- style()->unpolish(volumeQSlider);
- style()->polish(volumeQSlider);
- }
-#endif
- showMessage(tr("Volume at %1%").arg((int)(newVolume*100)));
+ if (media->volumeMuted()) media->setVolumeMuted(false);
+ showMessage(tr("Volume at %1%").arg((int)(newVolume * 100)));
+ // newVolume : 1.0 = x : 1000
+ int value = newVolume * volumeSlider->maximum();
+ volumeSlider->blockSignals(true);
+ volumeSlider->setValue(value);
+ volumeSlider->blockSignals(false);
}
void MainWindow::volumeMutedChanged(bool muted) {
@@ -1549,30 +1692,24 @@ void MainWindow::volumeMutedChanged(bool muted) {
volumeMuteAct->setIcon(IconUtils::icon("audio-volume-high"));
showMessage(tr("Volume is unmuted"));
}
-#ifdef APP_LINUX
- QToolButton *volumeMuteButton = qobject_cast(mainToolBar->widgetForAction(volumeMuteAct));
- volumeMuteButton->setIcon(volumeMuteButton->icon().pixmap(16));
-#endif
}
void MainWindow::setDefinitionMode(const QString &definitionName) {
- QAction *definitionAct = The::globalActions()->value("definition");
+ QAction *definitionAct = getAction("definition");
definitionAct->setText(definitionName);
- definitionAct->setStatusTip(tr("Maximum video definition set to %1").arg(definitionAct->text())
- + " (" + definitionAct->shortcut().toString(QKeySequence::NativeText) + ")");
+ definitionAct->setStatusTip(
+ tr("Maximum video definition set to %1").arg(definitionAct->text()) + " (" +
+ definitionAct->shortcut().toString(QKeySequence::NativeText) + ")");
showMessage(definitionAct->statusTip());
- QSettings settings;
- settings.setValue("definition", definitionName);
+ YT3::instance().setMaxVideoDefinition(definitionName);
+ if (views->currentWidget() == mediaView) {
+ mediaView->reloadCurrentVideo();
+ }
}
void MainWindow::toggleDefinitionMode() {
- const QString definitionName = QSettings().value("definition").toString();
- const QList& definitions = VideoDefinition::getDefinitions();
- const VideoDefinition& currentDefinition = VideoDefinition::getDefinitionFor(definitionName);
- if (currentDefinition.isEmpty()) {
- setDefinitionMode(definitions.first().getName());
- return;
- }
+ const QVector &definitions = VideoDefinition::getDefinitions();
+ const VideoDefinition ¤tDefinition = YT3::instance().maxVideoDefinition();
int index = definitions.indexOf(currentDefinition);
if (index != definitions.size() - 1) {
@@ -1580,20 +1717,9 @@ void MainWindow::toggleDefinitionMode() {
} else {
index = 0;
}
- // TODO: pass a VideoDefinition instead of QString.
setDefinitionMode(definitions.at(index).getName());
}
-void MainWindow::showFullscreenToolbar(bool show) {
- if (!fullscreenFlag) return;
- mainToolBar->setVisible(show);
-}
-
-void MainWindow::showFullscreenPlaylist(bool show) {
- if (!fullscreenFlag) return;
- mediaView->setPlaylistVisible(show);
-}
-
void MainWindow::clearRecentKeywords() {
QSettings settings;
settings.remove("recentKeywords");
@@ -1603,45 +1729,49 @@ void MainWindow::clearRecentKeywords() {
searchView->updateRecentKeywords();
searchView->updateRecentChannels();
}
- QAbstractNetworkCache *cache = The::networkAccessManager()->cache();
- if (cache) cache->clear();
+ HttpUtils::clearCaches();
showMessage(tr("Your privacy is now safe"));
}
void MainWindow::setManualPlay(bool enabled) {
QSettings settings;
settings.setValue("manualplay", QVariant::fromValue(enabled));
- showActionInStatusBar(The::globalActions()->value("manualplay"), enabled);
+ if (views->currentWidget() == homeView &&
+ homeView->currentWidget() == homeView->getSearchView())
+ return;
+ showActionsInStatusBar({getAction("manualplay")}, enabled);
}
void MainWindow::updateDownloadMessage(const QString &message) {
- The::globalActions()->value("downloads")->setText(message);
+ getAction("downloads")->setText(message);
}
void MainWindow::downloadsFinished() {
- The::globalActions()->value("downloads")->setText(tr("&Downloads"));
+ getAction("downloads")->setText(tr("&Downloads"));
showMessage(tr("Downloads complete"));
}
void MainWindow::toggleDownloads(bool show) {
-
if (show) {
stopAct->setShortcuts(QList() << QKeySequence(Qt::Key_MediaStop));
- The::globalActions()->value("downloads")->setShortcuts(
- QList() << QKeySequence(Qt::CTRL + Qt::Key_J)
- << QKeySequence(Qt::Key_Escape));
+ getAction("downloads")
+ ->setShortcuts(QList() << QKeySequence(Qt::CTRL + Qt::Key_J)
+ << QKeySequence(Qt::Key_Escape));
} else {
- The::globalActions()->value("downloads")->setShortcuts(
- QList() << QKeySequence(Qt::CTRL + Qt::Key_J));
- stopAct->setShortcuts(QList() << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::Key_MediaStop));
+ getAction("downloads")
+ ->setShortcuts(QList() << QKeySequence(Qt::CTRL + Qt::Key_J));
+ stopAct->setShortcuts(QList()
+ << QKeySequence(Qt::Key_Escape) << QKeySequence(Qt::Key_MediaStop));
}
if (!downloadView) {
downloadView = new DownloadView(this);
views->addWidget(downloadView);
}
- if (show) showWidget(downloadView);
- else goBack();
+ if (show)
+ showView(downloadView);
+ else
+ goBack();
}
void MainWindow::suggestionAccepted(Suggestion *suggestion) {
@@ -1649,8 +1779,8 @@ void MainWindow::suggestionAccepted(Suggestion *suggestion) {
}
void MainWindow::search(const QString &query) {
- QString q = query.trimmed();
- if (q.length() == 0) return;
+ QString q = query.simplified();
+ if (q.isEmpty()) return;
SearchParams *searchParams = new SearchParams();
searchParams->setKeywords(q);
showMedia(searchParams);
@@ -1660,10 +1790,9 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *e) {
if (e->mimeData()->hasFormat("text/uri-list")) {
QList urls = e->mimeData()->urls();
if (urls.isEmpty()) return;
- QUrl url = urls.first();
+ const QUrl &url = urls.at(0);
QString videoId = YTSearch::videoIdFromUrl(url.toString());
- if (!videoId.isEmpty())
- e->acceptProposedAction();
+ if (!videoId.isEmpty()) e->acceptProposedAction();
}
}
@@ -1671,9 +1800,8 @@ void MainWindow::dropEvent(QDropEvent *e) {
if (!toolbarSearch->isEnabled()) return;
QList urls = e->mimeData()->urls();
- if (urls.isEmpty())
- return;
- QUrl url = urls.first();
+ if (urls.isEmpty()) return;
+ const QUrl &url = urls.at(0);
QString videoId = YTSearch::videoIdFromUrl(url.toString());
if (!videoId.isEmpty()) {
setWindowTitle(url.toString());
@@ -1683,65 +1811,6 @@ void MainWindow::dropEvent(QDropEvent *e) {
}
}
-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(const QString &version) {
- if (updateChecker) {
- delete updateChecker;
- updateChecker = 0;
- }
-
- QSettings settings;
- QString checkedVersion = settings.value("checkedVersion").toString();
- if (checkedVersion == version) return;
-
-#ifdef APP_EXTRA
-#ifndef APP_MAC
- UpdateDialog *dialog = new UpdateDialog(version, this);
- dialog->show();
-#endif
-#else
- simpleUpdateDialog(version);
-#endif
-}
-
-void MainWindow::simpleUpdateDialog(const QString &version) {
- QMessageBox msgBox(this);
- msgBox.setIconPixmap(
- 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);
- msgBox.setWindowModality(Qt::WindowModal);
- msgBox.addButton(QMessageBox::Close);
- QPushButton* laterButton = msgBox.addButton(tr("Remind me later"), QMessageBox::RejectRole);
- QPushButton* updateButton = msgBox.addButton(tr("Update"), QMessageBox::AcceptRole);
- msgBox.exec();
- if (msgBox.clickedButton() != laterButton) {
- QSettings settings;
- settings.setValue("checkedVersion", version);
- }
- if (msgBox.clickedButton() == updateButton) visitSite();
-}
-
bool MainWindow::needStatusBar() {
return !statusToolBar->actions().isEmpty();
}
@@ -1754,11 +1823,10 @@ void MainWindow::adjustMessageLabelPosition() {
}
void MainWindow::floatOnTop(bool onTop, bool showAction) {
- if (showAction) showActionInStatusBar(The::globalActions()->value("ontop"), onTop);
+ if (showAction) showActionsInStatusBar({getAction("ontop")}, onTop);
#ifdef APP_MAC
mac::floatOnTop(winId(), onTop);
- return;
-#endif
+#else
if (onTop) {
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
show();
@@ -1766,18 +1834,12 @@ void MainWindow::floatOnTop(bool onTop, bool showAction) {
setWindowFlags(windowFlags() ^ Qt::WindowStaysOnTopHint);
show();
}
-}
-
-void MainWindow::adjustWindowSizeChanged(bool enabled) {
- QSettings settings;
- settings.setValue("adjustWindowSize", enabled);
- if (enabled && views->currentWidget() == mediaView)
- mediaView->adjustWindowSize();
+#endif
}
void MainWindow::restore() {
#ifdef APP_MAC
- mac::uncloseWindow(window()->winId());
+ mac::uncloseWindow(winId());
#endif
}
@@ -1789,8 +1851,8 @@ void MainWindow::messageReceived(const QString &message) {
} else if (message == QLatin1String("--previous")) {
if (skipBackwardAct->isEnabled()) skipBackwardAct->trigger();
} else if (message == QLatin1String("--stop-after-this")) {
- The::globalActions()->value("stopafterthis")->toggle();
- } else if (message.startsWith("--")) {
+ getAction("stopafterthis")->toggle();
+ } else if (message.startsWith("--")) {
MainWindow::printHelp();
} else if (!message.isEmpty()) {
SearchParams *searchParams = new SearchParams();
@@ -1799,14 +1861,39 @@ void MainWindow::messageReceived(const QString &message) {
}
}
-void MainWindow::hideMouse() {
+void MainWindow::hideFullscreenUI() {
+ if (views->currentWidget() != mediaView) return;
setCursor(Qt::BlankCursor);
- mediaView->setPlaylistVisible(false);
+
+ QPoint p = mapFromGlobal(QCursor::pos());
+ const int x = p.x();
+
+ if (x > mediaView->getSidebar()->width()) mediaView->setSidebarVisibility(false);
+
#ifndef APP_MAC
- mainToolBar->setVisible(false);
+ const int y = p.y();
+ bool shouldHideToolbar = !toolbarSearch->hasFocus() && y > mainToolBar->height();
+ if (shouldHideToolbar) mainToolBar->setVisible(false);
#endif
}
+void MainWindow::toggleMenuVisibility() {
+ bool show = !menuBar()->isVisible();
+ menuBar()->setVisible(show);
+}
+
+void MainWindow::toggleMenuVisibilityWithMessage() {
+ bool show = !menuBar()->isVisible();
+ menuBar()->setVisible(show);
+ if (!show) {
+ QMessageBox msgBox(this);
+ msgBox.setText(tr("You can still access the menu bar by pressing the ALT key"));
+ msgBox.setModal(true);
+ msgBox.setWindowModality(Qt::WindowModal);
+ msgBox.exec();
+ }
+}
+
#ifdef APP_MAC_STORE
void MainWindow::rateOnAppStore() {
QDesktopServices::openUrl(QUrl("macappstore://userpub.itunes.apple.com"
@@ -1830,6 +1917,30 @@ void MainWindow::printHelp() {
std::cout << msg.toLocal8Bit().data();
}
+void MainWindow::setupAction(QAction *action) {
+ // never autorepeat.
+ // unexperienced users tend to keep keys pressed for a "long" time
+ action->setAutoRepeat(false);
+
+ // show keyboard shortcuts in the status bar
+ if (!action->shortcut().isEmpty())
+ action->setStatusTip(action->statusTip() + QLatin1String(" (") +
+ action->shortcut().toString(QKeySequence::NativeText) +
+ QLatin1String(")"));
+}
+
+QAction *MainWindow::getAction(const char *name) {
+ return actionMap.value(QByteArray::fromRawData(name, strlen(name)));
+}
+
+void MainWindow::addNamedAction(const QByteArray &name, QAction *action) {
+ actionMap.insert(name, action);
+}
+
+QMenu *MainWindow::getMenu(const char *name) {
+ return menuMap.value(QByteArray::fromRawData(name, strlen(name)));
+}
+
void MainWindow::showMessage(const QString &message) {
if (!isVisible()) return;
#ifdef APP_MAC
@@ -1837,47 +1948,51 @@ void MainWindow::showMessage(const QString &message) {
#endif
if (statusBar()->isVisible())
statusBar()->showMessage(message, 60000);
- else {
+ else if (isActiveWindow()) {
messageLabel->setText(message);
- messageLabel->resize(messageLabel->sizeHint());
- adjustMessageLabelPosition();
- messageLabel->show();
+ QSize size = messageLabel->sizeHint();
+ // round width to avoid flicker with fast changing messages (e.g. volume
+ // changes)
+ int w = size.width() + 10;
+ const int multiple = 15;
+ w = w + multiple / 2;
+ w -= w % multiple;
+ size.setWidth(w);
+ messageLabel->resize(size);
+ if (messageLabel->isHidden()) {
+ adjustMessageLabelPosition();
+ messageLabel->show();
+ }
messageTimer->start();
}
}
-#ifdef APP_ACTIVATION
-void MainWindow::showActivationView(bool transition) {
- QWidget *activationView = ActivationView::instance();
- if (views->currentWidget() == activationView) {
- buy();
- return;
+void MainWindow::hideMessage() {
+ if (messageLabel->isVisible()) {
+ messageLabel->hide();
+ messageLabel->clear();
}
- views->addWidget(activationView);
- showWidget(activationView, transition);
-}
-
-void MainWindow::showActivationDialog() {
- QTimer::singleShot(0, new ActivationDialog(this), SLOT(show()));
}
-void MainWindow::buy() {
- Extra::buy();
+void MainWindow::handleError(const QString &message) {
+ qWarning() << message;
+ showMessage(message);
}
-void MainWindow::hideBuyAction() {
- QAction *action = The::globalActions()->value("buy");
- action->setVisible(false);
- action->setEnabled(false);
+#ifdef APP_ACTIVATION
+void MainWindow::showActivationView() {
+ View *activationView = ActivationView::instance();
+ views->addWidget(activationView);
+ if (views->currentWidget() != activationView) showView(activationView);
}
#endif
void MainWindow::showRegionsView() {
if (!regionsView) {
regionsView = new RegionsView(this);
- connect(regionsView, SIGNAL(regionChanged()),
- homeView->getStandardFeedsView(), SLOT(load()));
+ connect(regionsView, SIGNAL(regionChanged()), homeView->getStandardFeedsView(),
+ SLOT(load()));
views->addWidget(regionsView);
}
- showWidget(regionsView);
+ showView(regionsView);
}