3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
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.
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.
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/>.
22 #if QT_VERSION >= 0x050000
25 #include <qtsingleapplication.h>
26 #include "constants.h"
27 #include "mainwindow.h"
28 #include "searchparams.h"
29 #include "iconutils.h"
34 #include "mac_startup.h"
37 int main(int argc, char **argv) {
41 // https://bugreports.qt-project.org/browse/QTBUG-32789
42 QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande");
45 QtSingleApplication app(argc, argv);
46 QString message = app.arguments().size() > 1 ? app.arguments().at(1) : QString();
47 if (message == QLatin1String("--help")) {
48 MainWindow::printHelp();
51 if (app.sendMessage(message))
54 app.setApplicationName(QLatin1String(Constants::NAME));
55 app.setOrganizationName(QLatin1String(Constants::ORG_NAME));
56 app.setOrganizationDomain(QLatin1String(Constants::ORG_DOMAIN));
58 app.setWheelScrollLines(1);
60 app.setAttribute(Qt::AA_DontShowIconsInMenus);
63 Extra::appSetup(&app);
65 QFile cssFile(":/style.css");
66 cssFile.open(QFile::ReadOnly);
67 QString styleSheet = QLatin1String(cssFile.readAll());
68 app.setStyleSheet(styleSheet);
72 QTranslator qtTranslator;
73 qtTranslator.load("qt_" + QLocale::system().name(),
74 QLibraryInfo::location(QLibraryInfo::TranslationsPath));
75 app.installTranslator(&qtTranslator);
79 QString dataDir = QLatin1String(PKGDATADIR);
84 QString localeDir = qApp->applicationDirPath() + "/../Resources/locale";
86 QString localeDir = qApp->applicationDirPath() + "/locale";
88 if (!QDir(localeDir).exists()) {
89 localeDir = dataDir + "/locale";
91 // qDebug() << "Using locale dir" << localeDir << locale;
92 QTranslator translator;
93 translator.load(QLocale::system(), QString(), QString(), localeDir);
94 app.installTranslator(&translator);
95 #if QT_VERSION < 0x050000
96 QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
102 // no window icon on Mac
105 if (QDir(dataDir).exists()) {
106 appIcon = IconUtils::icon(Constants::UNIX_NAME);
108 dataDir = qApp->applicationDirPath() + "/data";
109 const int iconSizes [] = { 16, 22, 32, 48, 64, 128, 256, 512 };
110 for (int i = 0; i < 8; i++) {
111 QString size = QString::number(iconSizes[i]);
112 QString png = dataDir + "/" + size + "x" + size + "/" +
113 Constants::UNIX_NAME + ".png";
114 appIcon.addFile(png, QSize(iconSizes[i], iconSizes[i]));
117 if (appIcon.isNull()) {
118 appIcon.addFile(":/images/app.png");
120 mainWin.setWindowIcon(appIcon);
123 mainWin.connect(&app, SIGNAL(messageReceived(const QString &)),
124 &mainWin, SLOT(messageReceived(const QString &)));
125 app.setActivationWindow(&mainWin, true);
127 // all string literals are UTF-8
128 // QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
130 // Seed random number generator
131 qsrand(QDateTime::currentDateTime().toTime_t());