21int main(
int argc,
char **argv)
23 QCoreApplication app(argc, argv);
25 QCoreApplication::setApplicationName(QStringLiteral(
"kwin-applywindowdecoration"));
26 QCoreApplication::setApplicationVersion(QStringLiteral(
"1.0"));
27 QCoreApplication::setOrganizationDomain(QStringLiteral(
"kde.org"));
28 KLocalizedString::setApplicationDomain(QByteArrayLiteral(
"kwin-applywindowdecoration"));
30 QCommandLineParser *parser =
new QCommandLineParser;
31 parser->addHelpOption();
32 parser->setApplicationDescription(i18n(
"This tool allows you to set the window decoration theme for the currently active session, without accidentally setting it to one that is either not available, or which is already set."));
33 parser->addPositionalArgument(QStringLiteral(
"theme"), i18n(
"The name of the window decoration theme you wish to set for KWin. Passing a full path will attempt to find a theme in that directory, and then apply that if one can be deduced."));
34 parser->addOption(QCommandLineOption(QStringLiteral(
"list-themes"), i18n(
"Show all the themes available on the system (and which is the current theme)")));
39 KWinDecorationSettings *settings =
new KWinDecorationSettings(&app);
40 QTextStream ts(stdout);
41 if (!parser->positionalArguments().isEmpty()) {
42 QString requestedTheme{parser->positionalArguments().constFirst()};
43 if (requestedTheme.endsWith(QStringLiteral(
"/*"))) {
48 requestedTheme.remove(requestedTheme.length() - 2, 2);
51 bool themeResolved{
true};
52 if (requestedTheme.contains(QStringLiteral(
"/"))) {
53 themeResolved =
false;
54 if (QFileInfo::exists(requestedTheme) && QFileInfo(requestedTheme).isDir()) {
57 QStringList splitTheme = requestedTheme.split(QStringLiteral(
"/"), Qt::SkipEmptyParts);
58 if (splitTheme.count() > 3 && splitTheme[splitTheme.count() - 3] == QStringLiteral(
"aurorae") && splitTheme[splitTheme.count() - 2] == QStringLiteral(
"themes")) {
60 QString file(QStringLiteral(
"aurorae/themes/%1/metadata.desktop").arg(splitTheme.last()));
61 QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, file);
62 if (!path.isEmpty() && path == QStringLiteral(
"%1/metadata.desktop").arg(requestedTheme)) {
63 requestedTheme = QString(
"__aurorae__svg__").append(splitTheme.last());
65 ts << i18n(
"Resolved %1 to the KWin Aurorae theme \"%2\", and will attempt to set that as your current theme.")
66 .arg(parser->positionalArguments().first(), requestedTheme)
71 ts << i18n(
"You attempted to pass a file path, but this could not be resolved to a theme, and we will have to abort, due to having no theme to set") << Qt::endl;
76 if (settings->theme() == requestedTheme) {
77 ts << i18n(
"The requested theme \"%1\" is already set as the window decoration theme.", requestedTheme) << Qt::endl;
79 }
else if (themeResolved) {
81 QStringList availableThemes;
82 for (
int i = 0; i < model->
rowCount(); ++i) {
84 if (requestedTheme == themeName) {
88 availableThemes << themeName;
93 if (settings->save()) {
95 QDBusMessage message = QDBusMessage::createSignal(QStringLiteral(
"/KWin"),
96 QStringLiteral(
"org.kde.KWin"),
97 QStringLiteral(
"reloadConfig"));
98 QDBusConnection::sessionBus().send(message);
99 ts << i18n(
"Successfully applied the cursor theme %1 to your current Plasma session",
103 ts << i18n(
"Failed to save your theme settings - the reason is unknown, but this is an unrecoverable error. You may find that simply trying again will work.");
107 ts << i18n(
"Could not find theme \"%1\". The theme should be one of the following options: %2", requestedTheme, availableThemes.join(QStringLiteral(
", "))) << Qt::endl;
111 }
else if (parser->isSet(QStringLiteral(
"list-themes"))) {
112 ts << i18n(
"You have the following KWin window decoration themes on your system:") << Qt::endl;
113 for (
int i = 0; i < model->
rowCount(); ++i) {
114 const QString displayName = model->
data(model->index(i), Qt::DisplayRole).toString();
116 if (settings->theme() == themeName) {
117 ts << QStringLiteral(
" * %1 (theme name: %2 - current theme for this Plasma session)").arg(displayName, themeName) << Qt::endl;
119 ts << QStringLiteral(
" * %1 (theme name: %2)").arg(displayName, themeName) << Qt::endl;
125 QTimer::singleShot(0, &app, [&app, &exitCode]() {