Something went wrong. Try again.
Bring Windows XP themes to your KDE Plasma environment! xplasma.hotsocket.fyi
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079// SPDX-License-Identifier: GPL-3.0-or-later#include "app/apply.h"
#include "app/colors.h"#include "app/controls.h"#include "app/forks.h"#include "app/gtk.h"#include "app/icons.h"#include "app/media.h"#include "app/overrides.h"#include "app/package.h"#include "app/panel.h"#include "app/pointers.h"#include "app/project.h"#include "app/paths.h"#include "app/qttarget.h"#include "app/sounds.h"#include "app/startmenu.h"#include "app/state.h"#include "app/xptext.h"#include "core/schema.h"
#include <QCoreApplication>#include <QDir>#include <QDirIterator>#include <QElapsedTimer>#include <QFile>#include <QFileInfo>#include <QStandardPaths>#include <QJsonArray>#include <QJsonDocument>#include <QJsonObject>#include <QMap>#include <QRegularExpression>#include <QSaveFile>#include <QSet>#include <QThread>#include <QUrl>
#include <cstdio>#include <fcntl.h>
namespace xpl {
namespace {
bool fail(QString *error, const QString &message){ if (error) *error = message; return false;}
QString share(const QString &relative){ return paths::localShare() + QLatin1Char('/') + relative;}
// A package directory built under `from` moved into place at `to` (`from`// is gone after). Put beside the old one, then swapped for it in one step:// whatever is watching (every app, for an icon theme in use) never finds it// missing or half there.bool install(const QString &from, const QString &to, QString *error){ const QString fresh = to + QLatin1String(".xplasma-new"); QDir(fresh).removeRecursively(); QDir().mkpath(QFileInfo(fresh).absolutePath()); // Moved in one rename: it's staged on the same filesystem (paths:: // staging()). Copied file by file only if a destination is elsewhere (a // symlink to another disk). (An icon theme is some 4000 files: copying // them took 13 s.) if (!QDir().rename(from, fresh)) { QDir().mkpath(fresh); QDirIterator it(from, QDir::Files, QDirIterator::Subdirectories); while (it.hasNext()) { const QString file = it.next(); const QString target = fresh + file.mid(from.size()); QDir().mkpath(QFileInfo(target).absolutePath()); if (!QFile::copy(file, target)) { QDir(fresh).removeRecursively(); return fail(error, QStringLiteral("can't install %1").arg(to + file.mid(from.size()))); } } QDir(from).removeRecursively(); }#ifdef RENAME_EXCHANGE const QByteArray a = QFile::encodeName(fresh), b = QFile::encodeName(to); if (QFileInfo(to).isDir() && ::renameat2(AT_FDCWD, a.constData(), AT_FDCWD, b.constData(), RENAME_EXCHANGE) == 0) { QDir(fresh).removeRecursively(); // (the old one, now) return true; }#endif QDir(to).removeRecursively(); // (none there, or a filesystem that can't swap) if (!QDir().rename(fresh, to)) { QDir(fresh).removeRecursively(); return fail(error, QStringLiteral("can't install %1").arg(to)); } return true;}
bool ours(const QString &metadata){ QFile f(metadata); if (!f.open(QIODevice::ReadOnly)) return false; const QByteArray text = f.readAll().toLower(); return text.contains("xplasma") || text.contains("xp2plasma"); // (X-Xp2plasma-Icon-Theme, too)}
QString resourceText(const QString &path){ QFile f(path); return f.open(QIODevice::ReadOnly) ? QString::fromUtf8(f.readAll()) : QString();}
void report(const ApplyOptions &o, const QString &line){ if (o.progress) o.progress(line);}
void notice(const ApplyOptions &o, const QString &text){ if (o.notice) o.notice(text); else report(o, text);}
const QStringList kDecorationGroup{QStringLiteral("org.kde.kdecoration2")};constexpr const char *kDecorationPlugin = "fyi.hotsocket.xplasma.decoration";// State's settings: the decoration is the next login's (applyDecoration).constexpr const char *kDecorationAtLoginKey = "decorationAtLogin";
void useDecoration(Session &session){ session.writeConfig(QStringLiteral("kwinrc"), kDecorationGroup, QStringLiteral("library"), QLatin1String(kDecorationPlugin)); session.deleteConfig(QStringLiteral("kwinrc"), kDecorationGroup, QStringLiteral("theme"));}
// The decoration plugin KWin draws with now, as it says (its support// information's "Plugin:" under Decoration); empty if there's no KWin to ask.QString kwinDecoration(Session &session){ const auto info = session.query(QStringLiteral("org.kde.KWin"), QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"), QStringLiteral("supportInformation")); if (!info) return QString(); const QString text = info->toString(); static const QRegularExpression plugin(QStringLiteral("^Plugin: (\\S+)$"), QRegularExpression::MultilineOption); const auto m = plugin.match(text, qMax<qsizetype>(0, text.indexOf(QLatin1String("\nDecoration\n")))); return m.hasMatch() ? m.captured(1) : QStringLiteral("?");}
// KWin: XPlasma's own window decoration (src/decoration), drawing the look// xplasmarc names -- KWin reconfigured, and every window's borders drawn// anew in it. A KWin started before XPlasma's plugin folder was on its path// (the first apply after an install) can't find it until the next login:// the borders it had are put back meanwhile. One that loaded an older build// keeps it until then. Either way the user is told. (The borders put back are// for this session only: kwinrc is the decoration's again at the next login,// before KWin starts -- decorationAtLogin.)void applyDecoration(Session &session, State &state, const ApplyOptions &o){ QString why; if (!qtstyle::installDecoration(&why)) { report(o, QStringLiteral(" window borders stay as they were: %1").arg(why)); return; } const QString kwinrc = QStringLiteral("kwinrc"); const QString wasLibrary = session.readConfig(kwinrc, kDecorationGroup, QStringLiteral("library")); const QString wasTheme = session.readConfig(kwinrc, kDecorationGroup, QStringLiteral("theme")); useDecoration(session); session.reconfigureKWin(); // (Until KWin says which it took: what comes next mustn't catch it // half-way.) QString taken; QElapsedTimer clock; clock.start(); do { taken = kwinDecoration(session); if (taken.isEmpty() || taken == QLatin1String(kDecorationPlugin)) break; QThread::msleep(200); } while (clock.elapsed() < 3000); const QString logOut = QStringLiteral("Please log out and back in to apply the new window decorations."); if (!taken.isEmpty() && taken != QLatin1String(kDecorationPlugin)) { for (const auto &[key, value] : {std::pair(QStringLiteral("library"), wasLibrary), std::pair(QStringLiteral("theme"), wasTheme)}) { if (value.isEmpty()) session.deleteConfig(kwinrc, kDecorationGroup, key); else session.writeConfig(kwinrc, kDecorationGroup, key, value); } session.reconfigureKWin(); state.settings.insert(QLatin1String(kDecorationAtLoginKey), true); notice(o, logOut); return; } state.settings.remove(QLatin1String(kDecorationAtLoginKey)); // XPlasma's Aurorae themes, and Aurorae's title-shadow override, are done // with (an older XPlasma's window borders). for (const QString &p : generatedPackages()) if (p.startsWith(share(QStringLiteral("aurorae/themes/")))) QDir(p).removeRecursively(); overrides::removeTitleShadows(share(QStringLiteral("kwin/aurorae/aurorae.qml"))); if (qtstyle::decorationChangedSinceLogin()) notice(o, logOut);}
// KWin off XPlasma's decoration (reset), before the look it reads goes.void revertDecoration(Session &session){ if (session.readConfig(QStringLiteral("kwinrc"), kDecorationGroup, QStringLiteral("library")) != QLatin1String(kDecorationPlugin)) return; session.writeConfig(QStringLiteral("kwinrc"), kDecorationGroup, QStringLiteral("library"), QStringLiteral("org.kde.breeze")); session.writeConfig(QStringLiteral("kwinrc"), kDecorationGroup, QStringLiteral("theme"), QStringLiteral("Breeze")); session.reconfigureKWin();}
// KWin rules for XPlasma's own windows that XP gave no minimize or maximize// box: the copy dialog (plasmashell's, titled "Copying..." and the like), the// editor (XPlasma Properties and its dialogs, and Date and Time Properties,// property sheets on XP), and xplasma-service's questions (message boxes).// Wayland has no way for a window to say so itself. With neither box, the// decoration shows Close alone, as XP does. Other rules are left as they are.const QString kRulesFile = QStringLiteral("kwinrulesrc");using Rule = QList<std::pair<QString, QString>>;const Rule kNoBoxes{ {QStringLiteral("types"), QStringLiteral("33")}, // normal, dialog {QStringLiteral("minimize"), QStringLiteral("false")}, {QStringLiteral("minimizerule"), QStringLiteral("2")}, // force {QStringLiteral("maximizehoriz"), QStringLiteral("false")}, {QStringLiteral("maximizehorizrule"), QStringLiteral("2")}, {QStringLiteral("maximizevert"), QStringLiteral("false")}, {QStringLiteral("maximizevertrule"), QStringLiteral("2")},};const QList<std::pair<QString, Rule>> kRules{ {QStringLiteral("xplasma-copy-dialog"), Rule{{QStringLiteral("Description"), QStringLiteral("XPlasma: XP's copy dialog (Close only)")}, {QStringLiteral("wmclass"), QStringLiteral("org.kde.plasmashell")}, {QStringLiteral("wmclassmatch"), QStringLiteral("1")}, // exact {QStringLiteral("title"), QStringLiteral("\\.\\.\\.$")}, {QStringLiteral("titlematch"), QStringLiteral("3")}} // regular expression + kNoBoxes}, {QStringLiteral("xplasma-display-properties"), Rule{{QStringLiteral("Description"), QStringLiteral("XPlasma: XPlasma Properties, Date and Time Properties (Close only)")}, {QStringLiteral("wmclass"), QStringLiteral("^fyi\\.hotsocket\\.xplasma(\\.datetime)?$")}, {QStringLiteral("wmclassmatch"), QStringLiteral("3")}} // regular expression + kNoBoxes}, // (Asked over System Settings, where the scale was just changed: kept // above it, as a window can't keep itself on Wayland.) {QStringLiteral("xplasma-service"), Rule{{QStringLiteral("Description"), QStringLiteral("XPlasma: its questions, as the display's scale changes (on top, Close only)")}, {QStringLiteral("wmclass"), QStringLiteral("fyi.hotsocket.xplasma.service")}, {QStringLiteral("wmclassmatch"), QStringLiteral("1")}, // exact {QStringLiteral("above"), QStringLiteral("true")}, {QStringLiteral("aboverule"), QStringLiteral("2")}} // force + kNoBoxes},};
QStringList ruleIds(Session &session){ const QString list = session.readConfig(kRulesFile, {QStringLiteral("General")}, QStringLiteral("rules")); return list.isEmpty() ? QStringList() : list.split(QLatin1Char(','));}
void setRuleIds(Session &session, const QStringList &ids){ session.writeConfig(kRulesFile, {QStringLiteral("General")}, QStringLiteral("rules"), ids.join(QLatin1Char(',')), false); session.writeConfig(kRulesFile, {QStringLiteral("General")}, QStringLiteral("count"), QString::number(ids.size()), false);}
void installWindowRules(Session &session){ QStringList ids = ruleIds(session); for (const auto &[id, rule] : kRules) { for (const auto &[key, value] : rule) session.writeConfig(kRulesFile, {id}, key, value, false); if (!ids.contains(id)) ids << id; } setRuleIds(session, ids);}
void removeWindowRules(Session &session){ QStringList ids = ruleIds(session); for (const auto &[id, rule] : kRules) { ids.removeAll(id); for (const auto &[key, value] : rule) session.deleteConfig(kRulesFile, {id}, key, false); } setRuleIds(session, ids);}
// KWin's script that moves XPlasma's dialogs with their window// (src/app/kwin-script): a window can't move another on Wayland. XPlasma's// windows only; enabled in kwinrc and loaded now, not at the next login.constexpr const char *kDialogScript = "fyi.hotsocket.xplasma.dialogs";
QString dialogScriptDir(){ return share(QStringLiteral("kwin/scripts/")) + QLatin1String(kDialogScript);}
void installDialogScript(Session &session, const ApplyOptions &o){ Package pkg(dialogScriptDir()); const QString root = QStringLiteral(":/kwin-script/"); QDirIterator it(root.chopped(1), QDir::Files, QDirIterator::Subdirectories); while (it.hasNext()) { const QString file = it.next(); QFile f(file); if (f.open(QIODevice::ReadOnly)) pkg.write(file.mid(root.size()), f.readAll()); } if (!pkg.ok()) { report(o, QStringLiteral(" dialogs stay where they open: %1").arg(pkg.error())); return; } session.writeConfig(QStringLiteral("kwinrc"), {QStringLiteral("Plugins")}, QLatin1String(kDialogScript) + QLatin1String("Enabled"), QStringLiteral("true")); // (Unloaded first: an older copy running takes the new one.) const QString kwin = QStringLiteral("org.kde.KWin"), path = QStringLiteral("/Scripting"), iface = QStringLiteral("org.kde.kwin.Scripting"); session.call(kwin, path, iface, QStringLiteral("unloadScript"), {QLatin1String(kDialogScript)}); session.call(kwin, path, iface, QStringLiteral("start"));}
void removeDialogScript(Session &session){ session.deleteConfig(QStringLiteral("kwinrc"), {QStringLiteral("Plugins")}, QLatin1String(kDialogScript) + QLatin1String("Enabled")); session.call(QStringLiteral("org.kde.KWin"), QStringLiteral("/Scripting"), QStringLiteral("org.kde.kwin.Scripting"), QStringLiteral("unloadScript"), {QLatin1String(kDialogScript)}); QDir(dialogScriptDir()).removeRecursively();}
// The fonts, and the running session told: the platform theme only re-reads// them on refreshFonts, the signal the Fonts settings send.void applyFonts(Session &session, const QList<ConfigValue> &fonts){ for (const ConfigValue &v : fonts) session.writeConfig(v.file, v.group.split(QLatin1Char('/')), v.key, v.value); session.signal(QStringLiteral("/KDEPlatformTheme"), QStringLiteral("org.kde.KDEPlatformTheme"), QStringLiteral("refreshFonts")); session.reconfigureKWin();}
// This XPlasma's editor (XPlasma Properties, Date and Time Properties),// beside this program; or whichever is on the PATH.QString editorPath(){ const QString beside = QCoreApplication::applicationDirPath() + QLatin1String("/xplasma-edit"); return QFileInfo(beside).isExecutable() ? beside : QStringLiteral("xplasma-edit");}
// The same for xplasma-service.QString servicePath(){ const QString beside = QCoreApplication::applicationDirPath() + QLatin1String("/xplasma-service"); return QFileInfo(beside).isExecutable() ? beside : QStringLiteral("xplasma-service");}
// Plasma's helper that switches the icon theme: in its libexec, wherever the// distribution keeps that -- found beside Plasma's own tools first.QString iconHelper(){ QStringList candidates; const QString tool = QStandardPaths::findExecutable(QStringLiteral("plasma-apply-colorscheme")); if (!tool.isEmpty()) { const QDir prefix(QFileInfo(tool).canonicalPath() + QLatin1String("/..")); candidates << prefix.filePath(QStringLiteral("libexec/plasma-changeicons")) << prefix.filePath(QStringLiteral("lib/libexec/plasma-changeicons")) << prefix.filePath(QStringLiteral("lib64/libexec/plasma-changeicons")); // (Debian's multiarch: lib/x86_64-linux-gnu/libexec) for (const QString &triplet : QDir(prefix.filePath(QStringLiteral("lib"))).entryList({QStringLiteral("*-linux-*")}, QDir::Dirs)) candidates << prefix.filePath(QStringLiteral("lib/%1/libexec/plasma-changeicons").arg(triplet)); } candidates << QStringLiteral("/usr/lib/plasma-changeicons") << QStringLiteral("/usr/lib64/plasma-changeicons") << QStringLiteral("/usr/libexec/plasma-changeicons"); for (const QString &p : std::as_const(candidates)) if (QFileInfo(p).isExecutable()) return p; return QString();}
} // namespace
// The system's applications, as desktop file ids (a subfolder's joined on// with "-", as the spec has it) to their files -- the first found, the// user's own before the system's.QVariantMap desktopFiles(){ QVariantMap files; for (const QString &root : QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation)) { QDirIterator it(root, {QStringLiteral("*.desktop")}, QDir::Files, QDirIterator::Subdirectories); while (it.hasNext()) { const QString path = it.next(); const QString id = path.mid(root.size() + 1).replace(QLatin1Char('/'), QLatin1Char('-')); if (!files.contains(id)) files.insert(id, path); } } return files;}
QString scriptFrom(const QString &name, const QVariantMap &values){ QString text = resourceText(QStringLiteral(":/scripts/") + name + QLatin1String(".js")); for (auto it = values.begin(); it != values.end(); ++it) { const QJsonValue v = QJsonValue::fromVariant(it.value()); QString json; if (v.isObject()) json = QString::fromUtf8(QJsonDocument(v.toObject()).toJson(QJsonDocument::Compact)); else if (v.isArray()) json = QString::fromUtf8(QJsonDocument(v.toArray()).toJson(QJsonDocument::Compact)); else // (a scalar, as JSON: wrap it in an array and take it out again) json = QString::fromUtf8(QJsonDocument(QJsonArray{v}).toJson(QJsonDocument::Compact)).mid(1).chopped(1); text.replace(QLatin1String("${") + it.key() + QLatin1Char('}'), json); } return text;}
QStringList generatedPackages(const QStringList &keep){ QStringList found; const struct { QString dir; QStringList meta; } kinds[] = { {share(QStringLiteral("aurorae/themes")), {QStringLiteral("metadata.json"), QStringLiteral("metadata.desktop")}}, {share(QStringLiteral("plasma/desktoptheme")), {QStringLiteral("metadata.json"), QStringLiteral("metadata.desktop")}}, {share(QStringLiteral("icons")), {QStringLiteral("xplasma-icons.json"), QStringLiteral("xp2plasma-icons.json")}}, }; for (const auto &k : kinds) for (const QFileInfo &pkg : QDir(k.dir).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) { if (keep.contains(pkg.absoluteFilePath()) || pkg.isSymLink()) continue; for (const QString &m : k.meta) if (ours(pkg.filePath() + QLatin1Char('/') + m)) { found << pkg.absoluteFilePath(); break; } } for (const QFileInfo &f : QDir(share(QStringLiteral("color-schemes"))).entryInfoList({QStringLiteral("*.colors")}, QDir::Files)) if (!keep.contains(f.absoluteFilePath()) && ours(f.absoluteFilePath())) found << f.absoluteFilePath(); return found;}
// KSvg's elements cache (~/.cache/ksvg-elements) started with the size// variants ("16-16-shadow-center") of the theme's SVGs in `widgets`: KSvg// learns them only as it parses an SVG, after the first process to draw one// has already chosen what to draw -- and after an apply that process is the// shell (the check box's box, button.svg's 16px shadow, came up without it).// Each SVG's group carries its file's time, as KSvg keeps it.static void primeSizeHints(const QString &widgets, const QString &cacheFile){ static const QRegularExpression element(QStringLiteral("<image id=\"([^\"]+)\"[^>]*? width=\"(\\d+)\" height=\"(\\d+)\"")); static const QRegularExpression variant(QStringLiteral("^(\\d+)-(\\d+)-(.+)$")); QString out; for (const QFileInfo &svg : QDir(widgets).entryInfoList({QStringLiteral("*.svg")}, QDir::Files, QDir::Name)) { QFile f(svg.absoluteFilePath()); if (!f.open(QIODevice::ReadOnly)) continue; const QString text = QString::fromUtf8(f.readAll()); QMap<QString, QString> sizes; // element -> "WxH," for it and each variant QSet<QString> varied; for (auto it = element.globalMatch(text); it.hasNext();) { const auto m = it.next(); QString id = m.captured(1); if (const auto v = variant.match(id); v.hasMatch()) { id = v.captured(3); varied << id; } sizes[id] += m.captured(2) + QLatin1Char('x') + m.captured(3) + QLatin1Char(','); } if (varied.isEmpty()) continue; out += QLatin1Char('[') + svg.absoluteFilePath() + QStringLiteral("]\nLastModified=") + QString::number(svg.lastModified().toSecsSinceEpoch()) + QLatin1Char('\n'); for (const QString &id : std::as_const(varied)) out += id + QLatin1Char('=') + sizes.value(id) + QLatin1Char('\n'); out += QLatin1Char('\n'); } if (out.isEmpty()) return; QDir().mkpath(QFileInfo(cacheFile).absolutePath()); QSaveFile f(cacheFile); if (f.open(QIODevice::WriteOnly) && f.write(out.toUtf8()) >= 0) f.commit(); // (a cache: failing to prime it isn't failing)}
static std::optional<QJsonObject> appliedStartTheme(const QString &lookId){ QFile f(paths::data() + QLatin1String("/start/") + lookId + QLatin1String("/theme.json")); if (!f.open(QIODevice::ReadOnly)) return std::nullopt; const QJsonDocument doc = QJsonDocument::fromJson(f.readAll()); return doc.isObject() ? std::optional(doc.object()) : std::nullopt;}
bool previewStartButton(Session &session, const Look &look, QString *error){ const State state = State::load(); auto theme = appliedStartTheme(look.id); if (!theme || look.classic() || state.appliedKind != QLatin1String("style") || state.style != look.stylePath || state.variant != look.variant) return fail(error, QStringLiteral("%1 isn't the look applied").arg(look.name)); const StartButtonExtras extras = StartButtonExtras::fromJson(state.settings.value(QLatin1String(kStartButtonKey)).toObject()); const auto flag = media::startFlag(error); if (!flag) return false; const auto button = startButton(look, *flag, extras, error); if (!button) return false; // (Beside the applied theme, each preview under a new name: no image // cache shows an old one.) const QDir dir(paths::data() + QLatin1String("/start/") + look.id + QLatin1String("/preview")); QDir(dir.path()).removeRecursively(); QDir().mkpath(dir.path()); static int serial = 0; const QString stamp = QString::number(++serial); QJsonObject images{{QStringLiteral("width"), button->normal.width()}, {QStringLiteral("height"), button->normal.height()}}; for (const auto &[state, image] : {std::pair("normal", &button->normal), std::pair("hover", &button->hover), std::pair("pressed", &button->pressed)}) { const QString file = dir.filePath(QStringLiteral("button-%1-%2.png").arg(stamp, QLatin1String(state))); if (!image->convertToFormat(QImage::Format_ARGB32).save(file)) return fail(error, QStringLiteral("can't write %1").arg(file)); images.insert(QLatin1String(state), QUrl::fromLocalFile(file).toString()); } theme->insert(QStringLiteral("button"), images); session.script(scriptFrom(QStringLiteral("start-theme"), {{QStringLiteral("START"), QLatin1String(kStartPlasmoidId)}, {QStringLiteral("THEME"), theme->toVariantMap()}})); return true;}
void endStartButtonPreview(Session &session, const QString &lookId){ const QString preview = paths::data() + QLatin1String("/start/") + lookId + QLatin1String("/preview"); if (!QFileInfo::exists(preview)) return; if (const auto theme = appliedStartTheme(lookId)) session.script(scriptFrom(QStringLiteral("start-theme"), {{QStringLiteral("START"), QLatin1String(kStartPlasmoidId)}, {QStringLiteral("THEME"), theme->toVariantMap()}})); QDir(preview).removeRecursively();}
bool applyStartButton(Session &session, const Look &look, QString *error){ const StartButtonExtras extras = StartButtonExtras::fromJson(State::load().settings.value(QLatin1String(kStartButtonKey)).toObject()); const QString startDir = paths::data() + QLatin1String("/start/") + look.id; QDir(startDir).removeRecursively(); const QJsonObject theme = writeStartTheme(look, startDir, error, extras); if (theme.isEmpty()) return false; session.script(scriptFrom(QStringLiteral("start-theme"), {{QStringLiteral("START"), QLatin1String(kStartPlasmoidId)}, {QStringLiteral("THEME"), theme.toVariantMap()}})); return true;}
bool applyWidgets(Session &session, const Look &look, const std::function<void(const QString &)> &progress, QString *error){ State state = State::load(); QStringList log; const bool ok = qtstyle::apply(session, look, state, &log, error); for (const QString &line : std::as_const(log)) if (progress) progress(QStringLiteral(" ") + line); state.save(); return ok;}
// "[A][B C][D]" -> {"A", "B C", "D"}static QStringList configGroups(const QString &header){ return header.trimmed().mid(1).chopped(1).split(QLatin1String("]["));}
void settleTaskbars(Session &session, int height){ auto lines = [](const QString &name) { QFile f(paths::config() + QLatin1Char('/') + name); return f.open(QIODevice::ReadOnly) ? QString::fromUtf8(f.readAll()).split(QLatin1Char('\n')) : QStringList(); }; // The bottom panels (location 4), from the layout. QSet<QString> bottom; QString containment; bool panel = false, atBottom = false; auto finish = [&] { if (!containment.isEmpty() && panel && atBottom) bottom.insert(containment); }; for (const QString &line : lines(QStringLiteral("plasma-org.kde.plasma.desktop-appletsrc"))) { if (line.startsWith(QLatin1Char('['))) { finish(); const QStringList g = configGroups(line); containment = g.size() == 2 && g.at(0) == QLatin1String("Containments") ? g.at(1) : QString(); panel = atBottom = false; } else if (!containment.isEmpty()) { panel |= line.trimmed() == QLatin1String("plugin=org.kde.panel"); atBottom |= line.trimmed() == QLatin1String("location=4"); } } finish(); // Their views, as the shell keeps them: per panel, its defaults, and per // screen size (HorizontalNNNN). const QString file = QStringLiteral("plasmashellrc"); QSet<QString> seen; for (const QString &line : lines(file)) { if (!line.startsWith(QLatin1String("[PlasmaViews][Panel "))) continue; const QStringList g = configGroups(line); if (g.size() < 2 || !bottom.contains(g.at(1).mid(6)) || seen.contains(g.join(QLatin1Char('/')))) continue; seen.insert(g.join(QLatin1Char('/'))); const QString sub = g.value(2); if (sub == QLatin1String("Defaults")) { session.writeConfig(file, g, QStringLiteral("thickness"), QString::number(height), false); continue; } if (!sub.isEmpty() && !sub.startsWith(QLatin1String("Horizontal"))) continue; session.writeConfig(file, g, QStringLiteral("floating"), QStringLiteral("0"), false); session.writeConfig(file, g, QStringLiteral("alignment"), QStringLiteral("1"), false); // Qt::AlignLeft if (!sub.isEmpty()) { session.writeConfig(file, g, QStringLiteral("panelLengthMode"), QStringLiteral("0"), false); // fill session.writeConfig(file, g, QStringLiteral("panelOpacity"), QStringLiteral("1"), false); // opaque } }}
QStringList cannotTake(Session &session, bool taskbar, std::optional<forks::Choice> *chosen){ // (Widgets this Plasma builds in come from XPlasma's builds of them, if // one for this Plasma loads here.) QStringList cannot; QString why; if (taskbar && !overrides::checkPanelWidgets(share(QStringLiteral("plasma/plasmoids")), &why)) cannot << why.split(QLatin1Char('\n')); if (const QStringList builtIn = overrides::builtInPanelWidgets(); taskbar && !builtIn.isEmpty()) { const auto builds = forks::choose(forks::runningPlasma(session), builtIn, &why); if (!builds) cannot << why; if (chosen) *chosen = builds; } if (!overrides::checkDesktopMenu(share(QStringLiteral("plasma/plasmoids")), &why)) cannot << why.split(QLatin1Char('\n')); return cannot;}
bool decorationAtLogin(Session &session, State &state){ if (!state.settings.value(QLatin1String(kDecorationAtLoginKey)).toBool()) return false; state.settings.remove(QLatin1String(kDecorationAtLoginKey)); if (!QFileInfo::exists(qtstyle::installedDecoration())) return false; // (reset since) useDecoration(session); return true;}
Adjustments appliedAdjustments(const State &state){ Adjustments a; a.tint = TintSpec::parse(state.settings.value(QLatin1String(kTintKey)).toString()).value_or(TintSpec()); a.overrides = Overrides::parse(state.settings.value(QLatin1String(kOverridesKey)).toString()).value_or(Overrides()); return a;}
bool lookOutdated(const State &state){ return !state.appliedKind.isEmpty() && state.settings.value(QLatin1String(kAppliedWithKey)).toInt() < project::kVersion;}
bool applyLook(Session &session, const Look &look, const ApplyOptions &o, QString *error){ // The whole XP look or none of it: what this Plasma can't take is known // before anything changes. std::optional<forks::Choice> builds; if (const QStringList cannot = cannotTake(session, o.taskbar, &builds); !cannot.isEmpty()) return fail(error, QStringLiteral("this Plasma can't take the whole XP look yet, so nothing was changed:\n ") + cannot.join(QStringLiteral("\n "))); State state = State::load(); // (Each file written once, here, and the packages renamed into place.) const QString build = paths::staging() + QLatin1Char('/') + look.id; QDir(build).removeRecursively();
// --- generate ------------------------------------------------------------ // (Each step's line before it: the last one showing is what's running.) report(o, QStringLiteral("Generating %1 ...").arg(look.name)); if (o.taskbar) report(o, QStringLiteral(" the taskbar and Start menu")); const QString panel = o.taskbar ? writePanelTheme(look, build + QLatin1String("/desktoptheme"), error) : QString(); if (o.taskbar && panel.isEmpty()) return false; const QString startDir = paths::data() + QLatin1String("/start/") + look.id; QJsonObject startTheme; if (o.taskbar) { QDir(startDir).removeRecursively(); startTheme = writeStartTheme(look, startDir, error, StartButtonExtras::fromJson(state.settings.value(QLatin1String(kStartButtonKey)).toObject())); if (startTheme.isEmpty()) return false; } QString iconTheme; bool iconsCurrent = false; // (the installed one is this look's already) if (o.icons) { QString previous = state.settings.value(QStringLiteral("previousIconTheme")).toString(); const QString current = session.readConfig(QStringLiteral("kdeglobals"), {QStringLiteral("Icons")}, QStringLiteral("Theme")); if (previous.isEmpty() && current != QLatin1String(kIconThemeId) && current != QLatin1String("xp2plasma-icons")) previous = current.isEmpty() ? QStringLiteral("breeze") : current; if (!previous.isEmpty()) state.settings.insert(QStringLiteral("previousIconTheme"), previous); QString why; // (the tray's icons XP has no art for, in the tray's text colour) const QColor trayGlyphs = panelArt(look).trayTextColour; const auto drawn = spinIcons(look); // Made once: again only if something it's made from has changed // (its key), or everything is asked for. if (!o.regenerate && iconThemeKey(previous, trayGlyphs, drawn) == writtenIconThemeKey(share(QStringLiteral("icons/")) + QLatin1String(kIconThemeId))) { iconsCurrent = true; report(o, QStringLiteral(" the icons: as they were, kept")); } else { report(o, QStringLiteral(" the icons")); iconTheme = writeIconTheme(build + QLatin1String("/icons"), previous, trayGlyphs, &why, drawn); if (iconTheme.isEmpty()) report(o, QStringLiteral(" no XP icons: %1").arg(why)); } }
// --- install --------------------------------------------------------------- if (o.cancel && *o.cancel) { QDir(build).removeRecursively(); return fail(error, QStringLiteral("cancelled; nothing was changed")); } report(o, QStringLiteral("Installing ...")); report(o, QStringLiteral(" the colour scheme")); const QString colorsDest = share(QStringLiteral("color-schemes/")) + look.id + QLatin1String(".colors"); const QString panelDest = share(QStringLiteral("plasma/desktoptheme/")) + look.id + QLatin1String("-taskbar"); const QString iconsDest = share(QStringLiteral("icons/")) + QLatin1String(kIconThemeId); QDir().mkpath(QFileInfo(colorsDest).absolutePath()); { QSaveFile f(colorsDest); if (!f.open(QIODevice::WriteOnly) || f.write(colorScheme(look.system, look.id, {panelArt(look).panelColour, panelArt(look).textColour})) < 0 || !f.commit()) return fail(error, QStringLiteral("%1: %2").arg(colorsDest, f.errorString())); } if (o.taskbar) { report(o, QStringLiteral(" the taskbar, Start menu and clock")); // (The Plasma theme itself goes in with the shell down: below.) if (!installStartPlasmoid(share(QStringLiteral("plasma/plasmoids")), error) || !installClockPlasmoid(share(QStringLiteral("plasma/plasmoids")), error)) return false; QString why; if (!overrides::installPanelWidgets(share(QStringLiteral("plasma/plasmoids")), &why)) for (const QString &line : why.split(QLatin1Char('\n'))) report(o, QStringLiteral(" left as Plasma's own: %1").arg(line)); if (builds) { report(o, QStringLiteral(" Plasma's %1 as XPlasma builds them (Plasma %2)") .arg(QStringList(builds->plugins.keys()).join(QStringLiteral(", ")), builds->series)); if (!forks::install(session, *builds, state, error)) return false; } else { forks::remove(state); // (none wanted: an older Plasma's, if any, go) } } if (!iconTheme.isEmpty()) { report(o, QStringLiteral(" the icons")); if (!install(iconTheme, iconsDest, error)) return false; } QString why; // XP's Properties on the desktop's menu: this XPlasma's editor. const QString editor = QCoreApplication::applicationDirPath() + QLatin1String("/xplasma-edit"); if (!QFileInfo(editor).isExecutable()) report(o, QStringLiteral(" no XPlasma Properties on the desktop: %1 isn't there").arg(editor)); else if (!overrides::installDesktopMenu(share(QStringLiteral("plasma/plasmoids")), editor, &why)) report(o, QStringLiteral(" no XPlasma Properties on the desktop: %1").arg(why)); // Other looks' packages go: one of each at a time. (An older XPlasma's // window borders, Aurorae themes, only once KWin has the decoration: // applyDecoration.) for (const QString &stale : generatedPackages({colorsDest, panelDest, iconsDest})) { if (stale.startsWith(share(QStringLiteral("aurorae/themes/")))) continue; if (QFileInfo(stale).isDir()) QDir(stale).removeRecursively(); else QFile::remove(stale); }
// --- apply ------------------------------------------------------------------- report(o, QStringLiteral("Applying ...")); // XP's text first: the shell restarts below, and reads fontconfig anew. report(o, QStringLiteral(" text, colours and fonts")); if (!xptext::apply(session, state, &why)) report(o, QStringLiteral(" text stays as it was: %1").arg(why)); // Fonts: XP's and the user's folders (moved from before release 6 if // they still need to be), and the style's own while it's the one applied. paths::makeUserFolders(); if (!xptext::setLibraryFonts(&why)) report(o, QStringLiteral(" XP's and your fonts folders aren't set: %1").arg(why)); if (!xptext::setThemeFonts(look.classic() ? QStringList() : xptext::fontFolders(look.stylePath), &why)) report(o, QStringLiteral(" the style's own fonts aren't available: %1").arg(why)); // And kept to the display's scale from now, not from the next login // (xplasma-service: one per session, so a second start just ends). session.startDetached({servicePath()}); installWindowRules(session); installDialogScript(session, o); // (Its name forgotten first: plasma-apply-colorscheme won't apply the // scheme that's already current -- a look applied again, regenerated.) session.writeConfig(QStringLiteral("kdeglobals"), {QStringLiteral("General")}, QStringLiteral("ColorScheme"), QString(), false); if (!session.run({QStringLiteral("plasma-apply-colorscheme"), look.id}).ok()) report(o, QStringLiteral(" plasma-apply-colorscheme failed")); applyFonts(session, fontSettings(look.system)); // The window borders after the colours and fonts, which have KWin make // every window's anew: its last change, waited for. (The look they draw, // as the widget style's, xplasmarc names.) report(o, QStringLiteral(" window borders")); if (!qtstyle::publishLook(session, look, &why)) report(o, QStringLiteral(" window borders stay as they were: %1").arg(why)); else applyDecoration(session, state, o); if (o.widgets) { report(o, QStringLiteral(" Qt and GTK apps")); QStringList log; if (!qtstyle::apply(session, look, state, &log, &why)) report(o, QStringLiteral(" Qt apps keep their style: %1").arg(why)); // (GTK's too: a failure there isn't the look's.) if (!gtk::apply(session, look, state, &log, &why)) report(o, QStringLiteral(" GTK apps keep their theme: %1").arg(why)); for (const QString &line : std::as_const(log)) report(o, QStringLiteral(" ") + line); } if (o.taskbar) { report(o, QStringLiteral(" the taskbar")); const QString panelId = look.id + QLatin1String("-taskbar"); // A running plasmashell neither finds a theme package that appeared // after it started nor re-reads the current one's SVGs, and caches // them by the theme's name (another colour of the same style came up // in the old one's art): it restarts, its caches gone while it's down. // The theme is switched while it's down too: switched under a running // shell, KSvg's change notice has crashed it (KSvg::ImageSet:: // imageSetChanged, into code already unloaded). report(o, QStringLiteral("Restarting Plasma's shell for the taskbar ...")); // The theme's files go in while it's down as well: re-applied, the // look's theme is the current one, and its files rewritten under a // running shell crashed it the same way (Debian 13, Plasma 6.3). QString panelError; bool panelInstalled = true; session.restartPlasmaShell([&] { panelInstalled = install(panel, panelDest, &panelError); session.run({QStringLiteral("plasma-apply-desktoptheme"), panelId}); const QString cache = paths::home() + QLatin1String("/.cache/"); QFile::remove(cache + QLatin1String("plasma_theme_") + panelId + QLatin1String(".kcache")); QFile::remove(cache + QLatin1String("ksvg-elements")); primeSizeHints(panelDest + QLatin1String("/widgets"), cache + QLatin1String("ksvg-elements")); settleTaskbars(session, panelArt(look).height); }); if (!panelInstalled) return fail(error, panelError); // (Again through the running shell, for panels it hadn't saved yet.) session.script(scriptFrom(QStringLiteral("panel"), {{QStringLiteral("HEIGHT"), panelArt(look).height}})); // The clock in the style's clock font (Classic: the status font). LogFont clock = look.system.metrics.statusFont; if (!look.classic()) { const QString spec = look.renderer->property({QStringLiteral("clock"), 0, 0, QStringLiteral("traynotify")}, u"font") .value_or(QStringLiteral("Tahoma, 8")); const QStringList parts = spec.split(QLatin1Char(',')); clock = LogFont::fromPoints(parts.value(0).trimmed(), parts.value(1).trimmed().toInt(), spec.contains(QLatin1String("bold"), Qt::CaseInsensitive)); } // The task buttons in TaskBand::Toolbar's font (Classic, and a style // without one: Plasma's own, the family left empty). QString taskFamily; int taskPoints = 0, taskWeight = 400; bool taskItalic = false; if (const auto spec = look.classic() ? std::nullopt : look.renderer->property({QStringLiteral("toolbar"), 0, 0, QStringLiteral("taskband")}, u"font")) { const QStringList parts = spec->split(QLatin1Char(',')); taskFamily = parts.value(0).trimmed(); taskPoints = parts.value(1).trimmed().toInt(); taskWeight = spec->contains(QLatin1String("bold"), Qt::CaseInsensitive) ? 700 : 400; taskItalic = spec->contains(QLatin1String("italic"), Qt::CaseInsensitive); } report(o, QStringLiteral(" the taskbar's layout")); const auto layout = session.script(scriptFrom(QStringLiteral("layout"), {{QStringLiteral("START"), QLatin1String(kStartPlasmoidId)}, {QStringLiteral("THEME"), startTheme.toVariantMap()}, {QStringLiteral("CLOCK_FAMILY"), clock.face}, {QStringLiteral("CLOCK_POINTS"), clock.points()}, {QStringLiteral("CLOCK_WEIGHT"), clock.weight}, {QStringLiteral("TASK_FAMILY"), taskFamily}, {QStringLiteral("TASK_POINTS"), taskPoints}, {QStringLiteral("TASK_WEIGHT"), taskWeight}, {QStringLiteral("TASK_ITALIC"), taskItalic}, {QStringLiteral("CLOCK"), QLatin1String(kClockPlasmoidId)}, {QStringLiteral("DESKTOP_FILES"), desktopFiles()}, {QStringLiteral("CLOCK_COLOR"), panelArt(look).trayTextColour.name()}, {QStringLiteral("CLOCK_COMMAND"), overrides::launchCommand(editorPath(), {QStringLiteral("--date-time")})}}), &why); if (!layout) { report(o, QStringLiteral(" the panel wasn't rearranged: %1").arg(why)); } else { const QJsonObject result = QJsonDocument::fromJson(layout->toUtf8()).object(); for (const QJsonValue &line : result.value(QStringLiteral("log")).toArray()) report(o, QStringLiteral(" ") + line.toString()); // Plasma's scripting can't reorder a panel: its AppletOrder is // written with the shell down (it saves its own on the way out). QList<std::pair<QString, QString>> orders; for (const QJsonValue &p : result.value(QStringLiteral("panels")).toArray()) { QStringList ids; for (const QJsonValue &id : p.toObject().value(QStringLiteral("order")).toArray()) ids << QString::number(id.toInt()); const QString panelNumber = QString::number(p.toObject().value(QStringLiteral("panel")).toInt()); const QString wanted = ids.join(QLatin1Char(';')); if (session.readConfig(QStringLiteral("plasma-org.kde.plasma.desktop-appletsrc"), {QStringLiteral("Containments"), panelNumber, QStringLiteral("General")}, QStringLiteral("AppletOrder")) != wanted) orders.append({panelNumber, wanted}); } if (!orders.isEmpty()) { report(o, QStringLiteral("Restarting Plasma's shell for the taskbar's order ...")); session.restartPlasmaShell([&] { for (const auto &[panelNumber, order] : orders) session.writeConfig(QStringLiteral("plasma-org.kde.plasma.desktop-appletsrc"), {QStringLiteral("Containments"), panelNumber, QStringLiteral("General")}, QStringLiteral("AppletOrder"), order, false); }); } } } if (o.wallpaper) { report(o, QStringLiteral(" the wallpaper")); applyWallpaper(session, *o.wallpaper, o.progress); } // (Switched to unless it's on already: switching has every app reload // its icons.) if (!iconTheme.isEmpty() || (iconsCurrent && session.readConfig(QStringLiteral("kdeglobals"), {QStringLiteral("Icons")}, QStringLiteral("Theme")) != QLatin1String(kIconThemeId))) { report(o, QStringLiteral(" the icons")); const QString helper = iconHelper(); if (helper.isEmpty()) report(o, QStringLiteral(" Plasma's icon helper isn't here; the XP icons are installed but not switched on")); else session.run({helper, QLatin1String(kIconThemeId)}); }
// XP's sounds, as XP had them from the start: the first time, unless // they've been turned off. (A failure there isn't the look's.) if (o.sounds && sounds::wantedWithLook(state)) { report(o, QStringLiteral(" sounds: Windows Default")); if (!sounds::apply(session, state, sounds::defaultScheme(), &why)) report(o, QStringLiteral(" XP's sounds stay off: %1").arg(why)); }
state.appliedKind = look.classic() ? QStringLiteral("classic") : QStringLiteral("style"); state.style = look.stylePath; state.variant = look.variant; state.scheme = look.classic() ? look.system.name : QString(); state.themeFile = o.themeFile; state.settings.remove(QLatin1String(kTintKey)); state.settings.remove(QLatin1String(kOverridesKey)); if (!look.classic() && !look.adjust.tint.isIdentity()) state.settings.insert(QLatin1String(kTintKey), look.adjust.tint.toString()); if (!look.classic() && !look.adjust.overrides.isEmpty()) state.settings.insert(QLatin1String(kOverridesKey), look.adjust.overrides.toJson()); state.settings.insert(QLatin1String(kAppliedWithKey), project::kVersion); state.save(); QDir(build).removeRecursively(); // (emptied by the installs: what's left of it) report(o, QStringLiteral("Done.")); return true;}
void applyWallpaper(Session &session, const Wallpaper &w, const std::function<void(const QString &)> &progress){ session.script(scriptFrom(QStringLiteral("wallpaper"), {{QStringLiteral("IMAGE"), w.image.isEmpty() ? QVariant::fromValue(nullptr) : QVariant(QUrl::fromLocalFile(w.image).toString())}, {QStringLiteral("FILL"), w.fill ? QVariant(*w.fill) : QVariant::fromValue(nullptr)}, {QStringLiteral("COLOUR"), w.colour.name()}})); if (progress) progress(w.image.isEmpty() ? QStringLiteral("Desktop: %1").arg(w.colour.name()) : QStringLiteral("Wallpaper: %1").arg(QFileInfo(w.image).fileName()));}
bool resetDesktop(Session &session, const std::function<void(const QString &)> &progress, QString *error){ auto say = [&](const QString &line) { if (progress) progress(line); }; State state = State::load(); QStringList log; say(QStringLiteral("Taking XPlasma's widget style off ...")); revertDecoration(session); state.settings.remove(QLatin1String(kDecorationAtLoginKey)); qtstyle::revert(session, state, &log); gtk::revert(session, state, &log); for (const QString &line : std::as_const(log)) say(QStringLiteral(" ") + line); overrides::removeTitleShadows(share(QStringLiteral("kwin/aurorae/aurorae.qml"))); removeWindowRules(session); removeDialogScript(session); // Plasma's own widgets back, in a shell of their own, before Plasma's // layout is: the running shell has XPlasma's loaded, and given the // default panel it would load Plasma's beside them -- with builds of // them, the same QML module registered twice, which Qt won't survive. session.restartPlasmaShell([&] { overrides::removePanelWidgets(share(QStringLiteral("plasma/plasmoids"))); overrides::removeDesktopMenu(share(QStringLiteral("plasma/plasmoids"))); forks::remove(state); });
say(QStringLiteral("Clearing the XP fonts ...")); xptext::revert(session, state); pointers::revert(session, state); sounds::revert(session, state); for (const ConfigValue &v : fontSettings(ClassicScheme())) session.deleteConfig(v.file, v.group.split(QLatin1Char('/')), v.key); session.signal(QStringLiteral("/KDEPlatformTheme"), QStringLiteral("org.kde.KDEPlatformTheme"), QStringLiteral("refreshFonts"));
// Plasma's own tool does the heavy lifting: the global theme (borders, // colours, Plasma style, widget style, icons) and the default panel. const QString lookAndFeel = QStringLiteral("org.kde.breeze.desktop"); say(QStringLiteral("Applying %1 with the default panel ...").arg(lookAndFeel)); const host::Result r = session.run({QStringLiteral("plasma-apply-lookandfeel"), QStringLiteral("-a"), lookAndFeel, QStringLiteral("--resetLayout")}); if (!r.ok()) return fail(error, QStringLiteral("plasma-apply-lookandfeel failed: %1").arg(QString::fromUtf8(r.err).trimmed())); session.waitForPlasmaShell(); // (it may restart the shell itself)
// The wallpaper from the global theme's own defaults, set outright. for (const QString &root : paths::systemData()) { QFile defaults(root + QLatin1String("/plasma/look-and-feel/") + lookAndFeel + QLatin1String("/contents/defaults")); if (!defaults.open(QIODevice::ReadOnly)) continue; QString section, image; for (const QString &line : QString::fromUtf8(defaults.readAll()).split(QLatin1Char('\n'))) { if (line.startsWith(QLatin1Char('['))) section = line.trimmed(); else if (section == QLatin1String("[Wallpaper]") && line.startsWith(QLatin1String("Image="))) image = line.mid(6).trimmed(); } const QString path = image.startsWith(QLatin1Char('/')) ? image : root + QLatin1String("/wallpapers/") + (image.isEmpty() ? QStringLiteral("Next") : image); if (QFileInfo::exists(path)) { session.script(scriptFrom(QStringLiteral("wallpaper"), {{QStringLiteral("IMAGE"), path}, {QStringLiteral("FILL"), QVariant::fromValue(nullptr)}, {QStringLiteral("COLOUR"), QStringLiteral("#000000")}})); say(QStringLiteral("Wallpaper: %1").arg(QFileInfo(path).fileName())); } break; }
// The icons the user had. const QString previousIcons = state.settings.value(QStringLiteral("previousIconTheme")).toString(); if (const QString helper = iconHelper(); !helper.isEmpty() && !previousIcons.isEmpty()) session.run({helper, previousIcons}); state.settings.remove(QStringLiteral("previousIconTheme"));
say(QStringLiteral("Removing XPlasma's packages ...")); const QStringList packages = generatedPackages(); for (const QString &p : packages) { if (QFileInfo(p).isDir()) QDir(p).removeRecursively(); else QFile::remove(p); } const QString start = share(QStringLiteral("plasma/plasmoids/")) + QLatin1String(kStartPlasmoidId); QDir(start).removeRecursively(); QDir(share(QStringLiteral("plasma/plasmoids/")) + QLatin1String(kClockPlasmoidId)).removeRecursively(); QDir(paths::data() + QLatin1String("/start")).removeRecursively(); say(QStringLiteral(" %1 removed").arg(packages.size() + 1));
state.appliedKind.clear(); state.style.clear(); state.variant.clear(); state.scheme.clear(); state.themeFile.clear(); state.settings.remove(QLatin1String(kAppliedWithKey)); state.save(); session.reconfigureKWin(); say(QStringLiteral("The desktop is Plasma's default again.")); return true;}
} // namespace xpl