]> git.sur5r.net Git - minitube/blob - src/main.cpp
Imported Upstream version 2.1.5
[minitube] / src / main.cpp
1 /* $BEGIN_LICENSE
2
3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
5
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
18
19 $END_LICENSE */
20
21 #include <QtGui>
22 #include <qtsingleapplication.h>
23 #include "constants.h"
24 #include "mainwindow.h"
25 #include "searchparams.h"
26 #include "utils.h"
27 #ifdef APP_EXTRA
28 #include "extra.h"
29 #endif
30 #ifdef Q_WS_MAC
31 #include "mac_startup.h"
32 #endif
33
34 int main(int argc, char **argv) {
35
36 #ifdef Q_WS_MAC
37     mac::MacMain();
38     // https://bugreports.qt-project.org/browse/QTBUG-32789
39     QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande");
40 #endif
41
42     QtSingleApplication app(argc, argv);
43     QString message = app.arguments().size() > 1 ? app.arguments().at(1) : QString();
44     if (message == QLatin1String("--help")) {
45         MainWindow::printHelp();
46         return 0;
47     }
48     if (app.sendMessage(message))
49         return 0;
50
51     app.setApplicationName(QLatin1String(Constants::NAME));
52     app.setOrganizationName(QLatin1String(Constants::ORG_NAME));
53     app.setOrganizationDomain(QLatin1String(Constants::ORG_DOMAIN));
54 #ifndef APP_WIN
55     app.setWheelScrollLines(1);
56 #endif
57     app.setAttribute(Qt::AA_DontShowIconsInMenus);
58
59 #ifdef APP_EXTRA
60     Extra::appSetup(&app);
61 #else
62     QFile cssFile(":/style.css");
63     cssFile.open(QFile::ReadOnly);
64     QString styleSheet = QLatin1String(cssFile.readAll());
65     app.setStyleSheet(styleSheet);
66 #endif
67
68     // qt translations
69     QTranslator qtTranslator;
70     qtTranslator.load("qt_" + QLocale::system().name(),
71                       QLibraryInfo::location(QLibraryInfo::TranslationsPath));
72     app.installTranslator(&qtTranslator);
73
74     // app translations
75 #ifdef PKGDATADIR
76     QString dataDir = QLatin1String(PKGDATADIR);
77 #else
78     QString dataDir = "";
79 #endif
80 #ifdef APP_MAC
81     QString localeDir = qApp->applicationDirPath() + "/../Resources/locale";
82 #else
83     QString localeDir = qApp->applicationDirPath() + "/locale";
84 #endif
85     if (!QDir(localeDir).exists()) {
86         localeDir = dataDir + "/locale";
87     }
88     // qDebug() << "Using locale dir" << localeDir << locale;
89     QTranslator translator;
90     translator.load(QLocale::system(), QString(), QString(), localeDir);
91     app.installTranslator(&translator);
92     QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
93
94     MainWindow mainWin;
95     mainWin.show();
96
97     // no window icon on Mac
98 #ifndef APP_MAC
99     QIcon appIcon;
100     if (QDir(dataDir).exists()) {
101         appIcon = Utils::icon(Constants::UNIX_NAME);
102     } else {
103         dataDir = qApp->applicationDirPath() + "/data";
104         const int iconSizes [] = { 16, 22, 32, 48, 64, 128, 256, 512 };
105         for (int i = 0; i < 8; i++) {
106             QString size = QString::number(iconSizes[i]);
107             QString png = dataDir + "/" + size + "x" + size + "/" +
108                     Constants::UNIX_NAME + ".png";
109             appIcon.addFile(png, QSize(iconSizes[i], iconSizes[i]));
110         }
111     }
112     if (appIcon.isNull()) {
113         appIcon.addFile(":/images/app.png");
114     }
115     mainWin.setWindowIcon(appIcon);
116 #endif
117
118     mainWin.connect(&app, SIGNAL(messageReceived(const QString &)),
119                     &mainWin, SLOT(messageReceived(const QString &)));
120     app.setActivationWindow(&mainWin, true);
121
122     // all string literals are UTF-8
123     // QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
124
125     // Seed random number generator
126     qsrand(QDateTime::currentDateTime().toTime_t());
127
128     return app.exec();
129 }