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