]> git.sur5r.net Git - minitube/blobdiff - src/mainwindow.cpp
New upstream version 3.5
[minitube] / src / mainwindow.cpp
index abf71e5642f63ffaa0b497ee5222a9fcbb2e53cb..df79a99443f7aaded1bfe773f47bab9ab7996318 100644 (file)
@@ -48,7 +48,6 @@ $END_LICENSE */
 #endif
 #include "downloadmanager.h"
 #include "temporary.h"
-#include "updatechecker.h"
 #include "ytsuggester.h"
 #if defined(APP_MAC_SEARCHFIELD) && !defined(APP_MAC_QMACTOOLBAR)
 #include "searchlineedit_mac.h"
@@ -79,6 +78,9 @@ $END_LICENSE */
 #include "yt3.h"
 #include "ytregions.h"
 
+#include "invidious.h"
+#include "videoapi.h"
+
 #ifdef MEDIA_QTAV
 #include "mediaqtav.h"
 #endif
@@ -86,6 +88,10 @@ $END_LICENSE */
 #include "mediampv.h"
 #endif
 
+#ifdef UPDATER
+#include "updater.h"
+#endif
+
 namespace {
 MainWindow *mainWindowInstance;
 }
@@ -157,6 +163,12 @@ MainWindow::MainWindow()
     showHome();
 #endif
 
+    if (VideoAPI::impl() == VideoAPI::IV) {
+        Invidious::instance().initServers();
+    } else if (VideoAPI::impl() == VideoAPI::YT3) {
+        YT3::instance().initApiKeys();
+    }
+
     QTimer::singleShot(100, this, &MainWindow::lazyInit);
 }
 
@@ -216,7 +228,9 @@ void MainWindow::lazyInit() {
 
     ChannelAggregator::instance()->start();
 
-    checkForUpdate();
+#ifdef UPDATER
+    Updater::instance().checkWithoutUI();
+#endif
 
     initialized = true;
 }
@@ -653,6 +667,7 @@ void MainWindow::createActions() {
     action->setStatusTip(tr("Hide videos that may contain inappropriate content"));
     action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_K));
     action->setCheckable(true);
+    action->setVisible(VideoAPI::impl() == VideoAPI::YT3);
     actionMap.insert("safeSearch", action);
 
     action = new QAction(tr("Toggle &Menu Bar"), this);
@@ -769,6 +784,9 @@ void MainWindow::createMenus() {
 #endif
     helpMenu->addAction(getAction("reportIssue"));
     helpMenu->addAction(aboutAct);
+#ifdef UPDATER
+    helpMenu->addAction(Updater::instance().getAction());
+#endif
 
 #ifdef APP_MAC_STORE
     helpMenu->addSeparator();
@@ -1789,53 +1807,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
-    UpdateChecker *updateChecker = new UpdateChecker();
-    connect(updateChecker, &UpdateChecker::newVersion, this,
-            [this, updateChecker](const QString &version) {
-                updateChecker->deleteLater();
-                QSettings settings;
-                QString checkedVersion = settings.value("checkedVersion").toString();
-                if (checkedVersion == version) return;
-#ifdef APP_SIMPLEUPDATE
-                simpleUpdateDialog(version);
-#elif defined(APP_EXTRA) && !defined(APP_MAC)
-                UpdateDialog *dialog = new UpdateDialog(version, this);
-                dialog->show();
-#endif
-            });
-    updateChecker->checkForUpdate();
-    settings.setValue(updateCheckKey, unixTime);
-}
-
-void MainWindow::simpleUpdateDialog(const QString &version) {
-    QMessageBox msgBox(this);
-    msgBox.setIconPixmap(IconUtils::pixmap(":/images/64x64/app.png", devicePixelRatioF()));
-    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();
 }