]> git.sur5r.net Git - minitube/blob - src/main.cpp
Imported Upstream version 2.3
[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 #if QT_VERSION >= 0x050000
23 #include <QtWidgets>
24 #endif
25 #include <qtsingleapplication.h>
26 #include "constants.h"
27 #include "mainwindow.h"
28 #include "searchparams.h"
29 #include "iconutils.h"
30 #ifdef APP_EXTRA
31 #include "extra.h"
32 #endif
33 #ifdef Q_OS_MAC
34 #include "mac_startup.h"
35 #endif
36
37 int main(int argc, char **argv) {
38
39 #ifdef Q_OS_MAC
40     mac::MacMain();
41     QFont::insertSubstitution(".Helvetica Neue DeskInterface", "Helvetica Neue");
42 #endif
43
44     QtSingleApplication app(argc, argv);
45     QString message = app.arguments().size() > 1 ? app.arguments().at(1) : QString();
46     if (message == QLatin1String("--help")) {
47         MainWindow::printHelp();
48         return 0;
49     }
50     if (app.sendMessage(message))
51         return 0;
52
53     app.setApplicationName(QLatin1String(Constants::NAME));
54     app.setOrganizationName(QLatin1String(Constants::ORG_NAME));
55     app.setOrganizationDomain(QLatin1String(Constants::ORG_DOMAIN));
56     app.setAttribute(Qt::AA_DontShowIconsInMenus);
57
58 #ifdef APP_EXTRA
59     Extra::appSetup(&app);
60 #else
61     QFile cssFile(":/style.css");
62     cssFile.open(QFile::ReadOnly);
63     QString styleSheet = QLatin1String(cssFile.readAll());
64     app.setStyleSheet(styleSheet);
65 #endif
66
67     // qt translations
68     QTranslator qtTranslator;
69     qtTranslator.load("qt_" + QLocale::system().name(),
70                       QLibraryInfo::location(QLibraryInfo::TranslationsPath));
71     app.installTranslator(&qtTranslator);
72
73     // app translations
74 #ifdef PKGDATADIR
75     QString dataDir = QLatin1String(PKGDATADIR);
76 #else
77     QString dataDir = "";
78 #endif
79 #ifdef APP_MAC
80     QString localeDir = qApp->applicationDirPath() + "/../Resources/locale";
81 #else
82     QString localeDir = qApp->applicationDirPath() + "/locale";
83 #endif
84     if (!QDir(localeDir).exists()) {
85         localeDir = dataDir + "/locale";
86     }
87     // qDebug() << "Using locale dir" << localeDir << locale;
88     QTranslator translator;
89     translator.load(QLocale::system(), QString(), QString(), localeDir);
90     app.installTranslator(&translator);
91 #if QT_VERSION < 0x050000
92     QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
93 #endif
94
95     MainWindow mainWin;
96     mainWin.show();
97
98     // no window icon on Mac
99 #ifndef APP_MAC
100     QIcon appIcon;
101     if (QDir(dataDir).exists()) {
102         appIcon = IconUtils::icon(Constants::UNIX_NAME);
103     } else {
104         dataDir = qApp->applicationDirPath() + "/data";
105         const int iconSizes [] = { 16, 22, 32, 48, 64, 128, 256, 512 };
106         for (int i = 0; i < 8; i++) {
107             QString size = QString::number(iconSizes[i]);
108             QString png = dataDir + "/" + size + "x" + size + "/" +
109                     Constants::UNIX_NAME + ".png";
110             appIcon.addFile(png, QSize(iconSizes[i], iconSizes[i]));
111         }
112     }
113     if (appIcon.isNull()) {
114         appIcon.addFile(":/images/app.png");
115     }
116     mainWin.setWindowIcon(appIcon);
117 #endif
118
119     mainWin.connect(&app, SIGNAL(messageReceived(const QString &)),
120                     &mainWin, SLOT(messageReceived(const QString &)));
121     app.setActivationWindow(&mainWin, true);
122
123     // all string literals are UTF-8
124     // QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
125
126     // Seed random number generator
127     qsrand(QDateTime::currentDateTime().toTime_t());
128
129     return app.exec();
130 }