forked from CachyOS/kernel-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
142 lines (117 loc) · 4.62 KB
/
main.cpp
File metadata and controls
142 lines (117 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright (C) 2022-2025 Vladislav Nepogodin
//
// This file is part of CachyOS kernel manager.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "km-window.hpp"
#include <QApplication>
#include <QSharedMemory>
#include <QTranslator>
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-conversion"
#pragma clang diagnostic ignored "-Wimplicit-int-conversion"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wconversion"
#endif
#include <QLibraryInfo>
#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
namespace {
bool IsInstanceAlreadyRunning(QSharedMemory& memoryLock) noexcept {
if (!memoryLock.create(1)) {
memoryLock.attach();
memoryLock.detach();
if (!memoryLock.create(1)) {
return true;
}
}
return false;
}
/* Adopted from bitcoin-qt source code.
* Licensed under MIT
*/
/** Set up translations */
void initTranslations(QTranslator& qtTranslatorBase, QTranslator& qtTranslator, QTranslator& translatorBase, QTranslator& translator) noexcept {
// Remove old translators
QApplication::removeTranslator(&qtTranslatorBase);
QApplication::removeTranslator(&qtTranslator);
QApplication::removeTranslator(&translatorBase);
QApplication::removeTranslator(&translator);
// Get desired locale (e.g. "de_DE")
// 1) System default language
const auto lang_territory = QLocale::system().name();
// Convert to "de" only by truncating "_DE"
QString lang = lang_territory;
lang.truncate(lang_territory.lastIndexOf('_'));
// Load language files for configured locale:
// - First load the translator for the base language, without territory
// - Then load the more specific locale translator
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
const auto translation_path{QLibraryInfo::location(QLibraryInfo::TranslationsPath)};
#else
const auto translation_path{QLibraryInfo::path(QLibraryInfo::TranslationsPath)};
#endif
// Load e.g. qt_de.qm
if (qtTranslatorBase.load("qt_" + lang, translation_path)) {
QApplication::installTranslator(&qtTranslatorBase);
}
// Load e.g. qt_de_DE.qm
if (qtTranslator.load("qt_" + lang_territory, translation_path)) {
QApplication::installTranslator(&qtTranslator);
}
// Load e.g. cachyos-kernel-manager_de.qm (shortcut "de" needs to be defined in bitcoin.qrc)
if (translatorBase.load(lang, ":/translations/")) {
QApplication::installTranslator(&translatorBase);
}
// Load e.g. cachyos-kernel-manager_de_DE.qm (shortcut "de_DE" needs to be defined in bitcoin.qrc)
if (translator.load(lang_territory, ":/translations/")) {
QApplication::installTranslator(&translator);
}
}
} // namespace
auto main(int argc, char** argv) -> std::int32_t {
QSharedMemory sharedMemoryLock("CachyOS-KM-lock");
if (IsInstanceAlreadyRunning(sharedMemoryLock)) {
return -1;
}
/// 1. Basic Qt initialization (not dependent on parameters or configuration)
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
// Generate high-dpi pixmaps
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
/// 2. Application identification
QApplication::setOrganizationName("CachyOS");
QApplication::setOrganizationDomain("cachyos.org");
QApplication::setApplicationName("CachyOS-KM");
QApplication::setDesktopFileName("org.cachyos.KernelManager");
// Set application attributes
const QAppli
3982
cation app(argc, argv);
/// 3. Initialization of translations
QTranslator qtTranslatorBase;
QTranslator qtTranslator;
QTranslator translatorBase;
QTranslator translator;
initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
MainWindow w;
w.show();
return app.exec(); // NOLINT
}