]> git.sur5r.net Git - minitube/blobdiff - src/main.cpp
Imported Upstream version 2.3
[minitube] / src / main.cpp
index 399e6f081a940dc60d929e79ef22c65d1fe49b04..382d91a97923a50e11ea41f011718fb7c5243edf 100644 (file)
@@ -1,67 +1,44 @@
+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Minitube is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+
 #include <QtGui>
+#if QT_VERSION >= 0x050000
+#include <QtWidgets>
+#endif
 #include <qtsingleapplication.h>
 #include "constants.h"
 #include "mainwindow.h"
 #include "searchparams.h"
-#include "utils.h"
-#ifndef Q_WS_X11
+#include "iconutils.h"
+#ifdef APP_EXTRA
 #include "extra.h"
 #endif
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
 #include "mac_startup.h"
 #endif
 
-#ifdef Q_WS_X11
-QString getThemeName() {
-    QString themeName;
-
-    QProcess process;
-    process.start("dconf",
-                  QStringList() << "read" << "/org/gnome/desktop/interface/gtk-theme");
-    if (process.waitForFinished()) {
-        themeName = process.readAllStandardOutput();
-        themeName = themeName.trimmed();
-        themeName.remove('\'');
-        if (!themeName.isEmpty()) return themeName;
-    }
-
-    QString rcPaths = QString::fromLocal8Bit(qgetenv("GTK2_RC_FILES"));
-    if (!rcPaths.isEmpty()) {
-        QStringList paths = rcPaths.split(QLatin1String(":"));
-        foreach (const QString &rcPath, paths) {
-            if (!rcPath.isEmpty()) {
-                QFile rcFile(rcPath);
-                if (rcFile.exists() && rcFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
-                    QTextStream in(&rcFile);
-                    while(!in.atEnd()) {
-                        QString line = in.readLine();
-                        if (line.contains(QLatin1String("gtk-theme-name"))) {
-                            line = line.right(line.length() - line.indexOf(QLatin1Char('=')) - 1);
-                            line.remove(QLatin1Char('\"'));
-                            line = line.trimmed();
-                            themeName = line;
-                            break;
-                        }
-                    }
-                }
-            }
-            if (!themeName.isEmpty())
-                break;
-        }
-    }
-
-    // Fall back to gconf
-    if (themeName.isEmpty())
-        themeName = QGtkStyle::getGConfString(QLatin1String("/desktop/gnome/interface/gtk_theme"));
-
-    return themeName;
-}
-#endif
-
 int main(int argc, char **argv) {
 
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
     mac::MacMain();
+    QFont::insertSubstitution(".Helvetica Neue DeskInterface", "Helvetica Neue");
 #endif
 
     QtSingleApplication app(argc, argv);
@@ -76,18 +53,11 @@ int main(int argc, char **argv) {
     app.setApplicationName(QLatin1String(Constants::NAME));
     app.setOrganizationName(QLatin1String(Constants::ORG_NAME));
     app.setOrganizationDomain(QLatin1String(Constants::ORG_DOMAIN));
-    app.setWheelScrollLines(1);
     app.setAttribute(Qt::AA_DontShowIconsInMenus);
 
-#ifndef Q_WS_X11
+#ifdef APP_EXTRA
     Extra::appSetup(&app);
 #else
-    bool isGtk = app.style()->metaObject()->className() == QLatin1String("QGtkStyle");
-    if (isGtk) {
-        app.setProperty("gtk", isGtk);
-        QString themeName = getThemeName();
-        app.setProperty("style", themeName);
-    }
     QFile cssFile(":/style.css");
     cssFile.open(QFile::ReadOnly);
     QString styleSheet = QLatin1String(cssFile.readAll());
@@ -106,36 +76,37 @@ int main(int argc, char **argv) {
 #else
     QString dataDir = "";
 #endif
+#ifdef APP_MAC
+    QString localeDir = qApp->applicationDirPath() + "/../Resources/locale";
+#else
     QString localeDir = qApp->applicationDirPath() + "/locale";
+#endif
     if (!QDir(localeDir).exists()) {
         localeDir = dataDir + "/locale";
     }
     // qDebug() << "Using locale dir" << localeDir << locale;
     QTranslator translator;
-    translator.load(QLocale::system(), localeDir);
+    translator.load(QLocale::system(), QString(), QString(), localeDir);
     app.installTranslator(&translator);
+#if QT_VERSION < 0x050000
     QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
+#endif
 
     MainWindow mainWin;
-    mainWin.setWindowTitle(Constants::NAME);
-
-#ifndef Q_WS_X11
-    Extra::windowSetup(&mainWin);
-#else
-    mainWin.setProperty("style", app.property("style"));
-#endif
+    mainWin.show();
 
-// no window icon on Mac
+    // no window icon on Mac
 #ifndef APP_MAC
     QIcon appIcon;
     if (QDir(dataDir).exists()) {
-        appIcon = Utils::icon(Constants::UNIX_NAME);
+        appIcon = IconUtils::icon(Constants::UNIX_NAME);
     } else {
         dataDir = qApp->applicationDirPath() + "/data";
         const int iconSizes [] = { 16, 22, 32, 48, 64, 128, 256, 512 };
         for (int i = 0; i < 8; i++) {
             QString size = QString::number(iconSizes[i]);
-            QString png = dataDir + "/" + size + "x" + size + "/" + Constants::UNIX_NAME + ".png";
+            QString png = dataDir + "/" + size + "x" + size + "/" +
+                    Constants::UNIX_NAME + ".png";
             appIcon.addFile(png, QSize(iconSizes[i], iconSizes[i]));
         }
     }
@@ -145,26 +116,13 @@ int main(int argc, char **argv) {
     mainWin.setWindowIcon(appIcon);
 #endif
 
-    mainWin.connect(&app, SIGNAL(messageReceived(const QString &)), &mainWin, SLOT(messageReceived(const QString &)));
+    mainWin.connect(&app, SIGNAL(messageReceived(const QString &)),
+                    &mainWin, SLOT(messageReceived(const QString &)));
     app.setActivationWindow(&mainWin, true);
 
     // all string literals are UTF-8
     // QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
 
-    if (app.arguments().size() > 1) {
-        QString query = app.arguments().at(1);
-        if (query.startsWith(QLatin1String("--"))) {
-            mainWin.messageReceived(query);
-            return 0;
-        } else {
-            SearchParams *searchParams = new SearchParams();
-            searchParams->setKeywords(query);
-            mainWin.showMedia(searchParams);
-        }
-    }
-
-    mainWin.show();
-
     // Seed random number generator
     qsrand(QDateTime::currentDateTime().toTime_t());