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 #include <qtsingleapplication.h>
23 #include "constants.h"
24 #include "mainwindow.h"
25 #include "searchparams.h"
31 #include "mac_startup.h"
34 int main(int argc, char **argv) {
38 // https://bugreports.qt-project.org/browse/QTBUG-32789
39 QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande");
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();
48 if (app.sendMessage(message))
51 app.setApplicationName(QLatin1String(Constants::NAME));
52 app.setOrganizationName(QLatin1String(Constants::ORG_NAME));
53 app.setOrganizationDomain(QLatin1String(Constants::ORG_DOMAIN));
55 app.setWheelScrollLines(1);
57 app.setAttribute(Qt::AA_DontShowIconsInMenus);
60 Extra::appSetup(&app);
62 QFile cssFile(":/style.css");
63 cssFile.open(QFile::ReadOnly);
64 QString styleSheet = QLatin1String(cssFile.readAll());
65 app.setStyleSheet(styleSheet);
69 QTranslator qtTranslator;
70 qtTranslator.load("qt_" + QLocale::system().name(),
71 QLibraryInfo::location(QLibraryInfo::TranslationsPath));
72 app.installTranslator(&qtTranslator);
76 QString dataDir = QLatin1String(PKGDATADIR);
80 QString localeDir = qApp->applicationDirPath() + "/locale";
81 if (!QDir(localeDir).exists()) {
82 localeDir = dataDir + "/locale";
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"));
93 // no window icon on Mac
96 if (QDir(dataDir).exists()) {
97 appIcon = Utils::icon(Constants::UNIX_NAME);
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]));
108 if (appIcon.isNull()) {
109 appIcon.addFile(":/images/app.png");
111 mainWin.setWindowIcon(appIcon);
114 mainWin.connect(&app, SIGNAL(messageReceived(const QString &)),
115 &mainWin, SLOT(messageReceived(const QString &)));
116 app.setActivationWindow(&mainWin, true);
118 // all string literals are UTF-8
119 // QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
121 // Seed random number generator
122 qsrand(QDateTime::currentDateTime().toTime_t());