make the setings dialog adapt to the pages size
[trojita.git] / src / Gui / main.cpp
blob33f1e0b8f4a32de0155ba1de8b463507d514187b
1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <QApplication>
23 #include <QLibraryInfo>
24 #include <QSettings>
25 #include <QTranslator>
27 #include "AppVersion/SetCoreApplication.h"
28 #include "Common/Application.h"
29 #include "Common/MetaTypes.h"
30 #include "Common/SettingsNames.h"
31 #include "Gui/Util.h"
32 #include "Gui/Window.h"
34 #include "static_plugins.h"
36 int main(int argc, char **argv)
38 Common::registerMetaTypes();
40 QApplication app(argc, argv);
41 Q_INIT_RESOURCE(icons);
42 Q_INIT_RESOURCE(license);
44 QTranslator qtTranslator;
45 qtTranslator.load(QLatin1String("qt_") + QLocale::system().name(),
46 QLibraryInfo::location(QLibraryInfo::TranslationsPath));
47 app.installTranslator(&qtTranslator);
49 QLatin1String localeSuffix("/locale");
50 QString localeName(QLatin1String("trojita_common_") +
51 (qgetenv("KDE_LANG") == "x-test" ? QLatin1String("x_test") : QLocale::system().name()));
53 // The "installed to system" localization
54 QTranslator appSystemTranslator;
55 if (!Gui::Util::pkgDataDir().isEmpty()) {
56 appSystemTranslator.load(localeName, Gui::Util::pkgDataDir() + localeSuffix);
57 app.installTranslator(&appSystemTranslator);
60 // The "in the directory with the binary" localization
61 QTranslator appDirectoryTranslator;
62 appDirectoryTranslator.load(localeName, app.applicationDirPath() + localeSuffix);
63 app.installTranslator(&appDirectoryTranslator);
65 AppVersion::setGitVersion();
66 AppVersion::setCoreApplicationData();
67 app.setWindowIcon(QIcon(QLatin1String(":/icons/trojita.png")));
69 // Hack: support multiple "profiles"
70 QString profileName;
71 if (argc == 3 && argv[1] == QByteArray("--profile")) {
72 profileName = QString::fromLocal8Bit(argv[2]);
73 // We are abusing the env vars here. Yes, it's a hidden global. Yes, it's ugly.
74 // Take it or leave it, this is a time-limited hack.
75 // The env var is also in UTF-8. I like UTF-8.
76 qputenv("TROJITA_PROFILE", profileName.toUtf8());
77 } else {
78 #ifndef Q_OS_WIN32
79 unsetenv("TROJITA_PROFILE");
80 #else
81 putenv("TROJITA_PROFILE=");
82 #endif
84 QSettings settings(Common::Application::organization,
85 profileName.isEmpty() ? Common::Application::name : Common::Application::name + QLatin1Char('-') + profileName);
86 Gui::MainWindow win(&settings);
87 if ( settings.value(Common::SettingsNames::guiStartMinimized, QVariant(false)).toBool() ) {
88 if ( !settings.value(Common::SettingsNames::guiShowSystray, QVariant(true)).toBool() ) {
89 win.show();
90 win.setWindowState(Qt::WindowMinimized);
92 } else {
93 win.show();
95 return app.exec();