]> git.sur5r.net Git - minitube/blob - src/main.cpp
fe894e6ceee24e2105b49295c3d462b358684082
[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     QString localeDir = qApp->applicationDirPath() + "/locale";
81     if (!QDir(localeDir).exists()) {
82         localeDir = dataDir + "/locale";
83     }
84     // qDebug() << "Using locale dir" << localeDir << locale;
85     QTranslator translator;
86     translator.load(QLocale::system(), QString(), QString(), localeDir);
87     app.installTranslator(&translator);
88     QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
89
90     MainWindow mainWin;
91     mainWin.show();
92
93     // no window icon on Mac
94 #ifndef APP_MAC
95     QIcon appIcon;
96     if (QDir(dataDir).exists()) {
97         appIcon = Utils::icon(Constants::UNIX_NAME);
98     } else {
99         dataDir = qApp->applicationDirPath() + "/data";
100         const int iconSizes [] = { 16, 22, 32, 48, 64, 128, 256, 512 };
101         for (int i = 0; i < 8; i++) {
102             QString size = QString::number(iconSizes[i]);
103             QString png = dataDir + "/" + size + "x" + size + "/" +
104                     Constants::UNIX_NAME + ".png";
105             appIcon.addFile(png, QSize(iconSizes[i], iconSizes[i]));
106         }
107     }
108     if (appIcon.isNull()) {
109         appIcon.addFile(":/images/app.png");
110     }
111     mainWin.setWindowIcon(appIcon);
112 #endif
113
114     mainWin.connect(&app, SIGNAL(messageReceived(const QString &)),
115                     &mainWin, SLOT(messageReceived(const QString &)));
116     app.setActivationWindow(&mainWin, true);
117
118     // all string literals are UTF-8
119     // QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
120
121     // Seed random number generator
122     qsrand(QDateTime::currentDateTime().toTime_t());
123
124     return app.exec();
125 }