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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/**
* SPDX-FileCopyrightText: 2009 Ben Cooksley <bcooksley@kde.org>
*
* This file was sourced from the System Settings package
* SPDX-FileCopyrightText: 2005 Benjamin C Meyer <ben+systempreferences at meyerhome dot net>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <KAboutData>
#include <KCrash>
#include <QApplication>
#include <QCommandLineParser>
#include <QSurfaceFormat>
#include <KDBusService>
#include <KLocalizedString>
#include <KPluginMetaData>
#include <KWindowSystem>
#include <iostream>
#include "SettingsBase.h"
#include "kcmmetadatahelpers.h"
int main(int argc, char *argv[])
{
auto format = QSurfaceFormat::defaultFormat();
format.setOption(QSurfaceFormat::ResetNotification);
QSurfaceFormat::setDefaultFormat(format);
// Make sure the binary name is either kinfocenter or systemsettings,
// Anything else will just be considered as "systemsettings"
const QString executableName = QString::fromUtf8(argv[0]);
QString binaryName = QStringLiteral("systemsettings");
SidebarMode::ApplicationMode mode = SidebarMode::SystemSettings;
if (executableName.endsWith(QLatin1String("kinfocenter"))) {
binaryName = QStringLiteral("kinfocenter");
mode = SidebarMode::InfoCenter;
}
// exec is systemsettings, but we need the QPT to use the right config from the qApp constructor
// which is before KAboutData::setApplicationData
QCoreApplication::setApplicationName(binaryName);
QApplication application(argc, argv);
// The ki18n application domain must be set before we make any i18n() calls.
KLocalizedString::setApplicationDomain(QByteArrayLiteral("systemsettings"));
KAboutData aboutData;
if (mode == SidebarMode::InfoCenter) {
// About data
aboutData = KAboutData(QStringLiteral("kinfocenter"),
i18n("Info Center"),
QStringLiteral(PROJECT_VERSION),
i18n("Centralized and convenient overview of system information."),
KAboutLicense::GPL,
i18n("(c) 2009, Ben Cooksley"));
aboutData.setDesktopFileName(QStringLiteral("org.kde.kinfocenter"));
application.setWindowIcon(QIcon::fromTheme(QStringLiteral("hwinfo")));
} else {
aboutData = KAboutData(QStringLiteral("systemsettings"),
i18n("System Settings"),
QStringLiteral(PROJECT_VERSION),
i18n("Central configuration center by KDE."),
KAboutLicense::GPL,
i18n("(c) 2009, Ben Cooksley"));
if (qEnvironmentVariableIsSet("KDE_FULL_SESSION")) {
aboutData.setDesktopFileName(QStringLiteral("systemsettings"));
} else {
aboutData.setDesktopFileName(QStringLiteral("kdesystemsettings"));
}
application.setWindowIcon(QIcon::fromTheme(QStringLiteral("preferences-system")));
}
aboutData.addAuthor(i18n("Ben Cooksley"), i18n("Maintainer"), QStringLiteral("bcooksley@kde.org"));
aboutData.addAuthor(i18n("Marco Martin"), i18n("Author"), QStringLiteral("mart@kde.org"));
aboutData.addAuthor(i18n("Mathias Soeken"), i18n("Developer"), QStringLiteral("msoeken@informatik.uni-bremen.de"));
aboutData.addAuthor(i18n("Will Stephenson"), i18n("Internal module representation, internal module model"), QStringLiteral("wstephenson@kde.org"));
KAboutData::setApplicationData(aboutData);
QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
QCommandLineParser parser;
parser.addOption(QCommandLineOption(QStringLiteral("list"), i18n("List all possible modules")));
parser.addPositionalArgument(QStringLiteral("module"), i18n("Configuration module to open"));
parser.addOption(QCommandLineOption(QStringLiteral("args"), i18n("Arguments for the module"), QStringLiteral("arguments")));
aboutData.setupCommandLine(&parser);
parser.process(application);
aboutData.processCommandLine(&parser);
if (parser.isSet(QStringLiteral("list"))) {
std::cout << i18n("The following modules are available:").toLocal8Bit().data() << std::endl;
auto source = mode == SidebarMode::InfoCenter ? MetaDataSource::KInfoCenter : MetaDataSource::SystemSettings;
const auto modules = findKCMsMetaData(source) << findExternalKCMModules(source);
int maxLen = 0;
for (const auto &metaData : modules) {
const int len = metaData.pluginId().length();
if (len > maxLen) {
maxLen = len;
}
}
for (const auto &metaData : modules) {
QString entry(QStringLiteral("%1 - %2"));
entry = entry.arg(metaData.pluginId().leftJustified(maxLen, QLatin1Char(' ')),
!metaData.description().isEmpty() ? metaData.description() : i18n("No description available"));
std::cout << entry.toLocal8Bit().data() << std::endl;
}
return 0;
}
if (parser.positionalArguments().count() > 1) {
std::cerr << "Only one module argument may be passed" << std::endl;
return -1;
}
const QStringList args = parser.value(QStringLiteral("args")).split(QRegularExpression(QStringLiteral(" +")), Qt::SkipEmptyParts);
QString startupModule;
if (parser.positionalArguments().count() == 1) {
startupModule = parser.positionalArguments().constFirst();
}
if (!args.isEmpty() && startupModule.isEmpty()) {
std::cerr << "Arguments may only be passed when specifying a module" << std::endl;
return -1;
}
KDBusService service(KDBusService::Unique);
KCrash::initialize();
auto mainWindow = new SettingsBase(mode, startupModule, args);
QObject::connect(&service, &KDBusService::activateRequested, mainWindow, [mainWindow](const QStringList &arguments) {
// We can't use startupModule and args from above since they come from the existing instance, so we need to parse arguments.
// We don't need to do the error checking again though.
QCommandLineParser parser;
parser.addPositionalArgument(QStringLiteral("module"), i18n("Configuration module to open"));
parser.addOption(QCommandLineOption(QStringLiteral("args"), i18n("Arguments for the module"), QStringLiteral("arguments")));
parser.parse(arguments);
const QStringList args = parser.value(QStringLiteral("args")).split(QRegularExpression(QStringLiteral(" +")), Qt::SkipEmptyParts);
QString startupModule;
if (parser.positionalArguments().count() == 1) {
startupModule = parser.positionalArguments().constFirst();
}
if (!startupModule.isEmpty()) {
mainWindow->setStartupModule(startupModule);
mainWindow->setStartupModuleArgs(args);
mainWindow->reloadStartupModule();
}
KWindowSystem::updateStartupId(mainWindow->windowHandle());
KWindowSystem::activateWindow(mainWindow->windowHandle());
});
return application.exec();
}
|