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 QFont::insertSubstitution(".Helvetica Neue DeskInterface", "Helvetica Neue");
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();
50 if (app.sendMessage(message))
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);
59 Extra::appSetup(&app);
61 QFile cssFile(":/style.css");
62 cssFile.open(QFile::ReadOnly);
63 QString styleSheet = QLatin1String(cssFile.readAll());
64 app.setStyleSheet(styleSheet);
68 QTranslator qtTranslator;
69 qtTranslator.load("qt_" + QLocale::system().name(),
70 QLibraryInfo::location(QLibraryInfo::TranslationsPath));
71 app.installTranslator(&qtTranslator);
75 QString dataDir = QLatin1String(PKGDATADIR);
80 QString localeDir = qApp->applicationDirPath() + "/../Resources/locale";
82 QString localeDir = qApp->applicationDirPath() + "/locale";
84 if (!QDir(localeDir).exists()) {
85 localeDir = dataDir + "/locale";
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"));
98 // no window icon on Mac
101 if (QDir(dataDir).exists()) {
102 appIcon = IconUtils::icon(Constants::UNIX_NAME);
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]));
113 if (appIcon.isNull()) {
114 appIcon.addFile(":/images/app.png");
116 mainWin.setWindowIcon(appIcon);
119 mainWin.connect(&app, SIGNAL(messageReceived(const QString &)),
120 &mainWin, SLOT(messageReceived(const QString &)));
121 app.setActivationWindow(&mainWin, true);
123 // all string literals are UTF-8
124 // QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
126 // Seed random number generator
127 qsrand(QDateTime::currentDateTime().toTime_t());