wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
ThemeHandler.cpp
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
5
7
9 : BaseHandler(mainWindow, validator)
10{
11}
12
13QJsonObject ThemeHandler::handleCommand(const QString &command, const QJsonObject &params, const QJsonValue &requestId)
14{
15 if (command == "get_theme") {
16 return handleGetTheme(params, requestId);
17 } else if (command == "set_theme") {
18 return handleSetTheme(params, requestId);
19 } else if (command == "get_effective_theme") {
20 return handleGetEffectiveTheme(params, requestId);
21 } else {
22 return createErrorResponse(QString("Unknown theme command: %1").arg(command),
24 }
25}
26
27QJsonObject ThemeHandler::handleGetTheme(const QJsonObject &, const QJsonValue &requestId)
28{
29 QJsonObject result;
30 result["theme"] = themeToString(ThemeManager::theme());
31 return createSuccessResponse(result, requestId);
32}
33
34QJsonObject ThemeHandler::handleSetTheme(const QJsonObject &params, const QJsonValue &requestId)
35{
36 if (!validateParameters(params, {"theme"})) {
37 return createErrorResponse("Missing required parameter: theme", requestId, JsonRpcError::InvalidParams);
38 }
39
40 const QString themeStr = params["theme"].toString().toLower();
41 Theme theme;
42
43 if (themeStr == "light") {
44 theme = Theme::Light;
45 } else if (themeStr == "dark") {
46 theme = Theme::Dark;
47 } else if (themeStr == "system") {
48 theme = Theme::System;
49 } else {
50 return createErrorResponse(QString("Invalid theme: '%1'. Expected 'light', 'dark', or 'system'.").arg(themeStr),
52 }
53
55
56 QJsonObject result;
57 result["theme"] = themeToString(theme);
58 return createSuccessResponse(result, requestId);
59}
60
61QJsonObject ThemeHandler::handleGetEffectiveTheme(const QJsonObject &, const QJsonValue &requestId)
62{
63 QJsonObject result;
64 result["effective_theme"] = themeToString(ThemeManager::effectiveTheme());
65 return createSuccessResponse(result, requestId);
66}
67
68QString ThemeHandler::themeToString(Theme theme) const
69{
70 switch (theme) {
71 case Theme::Light:
72 return "light";
73 case Theme::Dark:
74 return "dark";
75 case Theme::System:
76 return "system";
77 }
78 Q_UNREACHABLE();
79}
Theme management types and singleton ThemeManager.
Theme
Enumeration of available application themes.
QJsonObject createSuccessResponse(const QJsonObject &result={}, const QJsonValue &requestId=QJsonValue()) const
BaseHandler(MainWindow *mainWindow, const MCPValidator *validator)
QJsonObject createErrorResponse(const QString &error, const QJsonValue &requestId=QJsonValue(), int code=JsonRpcError::InternalError) const
bool validateParameters(const QJsonObject &params, const QStringList &required) const
JSON Schema validator for MCP commands and responses using native json-schema-validator.
The top-level application window hosting the tab bar, menus, element palette, and editor.
Definition MainWindow.h:47
ThemeHandler(MainWindow *mainWindow, const MCPValidator *validator)
QJsonObject handleCommand(const QString &command, const QJsonObject &params, const QJsonValue &requestId) override
static Theme theme()
Returns the currently active theme.
static void setTheme(const Theme theme)
Switches the application to theme and emits themeChanged().
static Theme effectiveTheme()
Returns the effective theme (Light or Dark), resolving System to the OS preference.
constexpr int MethodNotFound
The requested method does not exist or is unavailable.
constexpr int ValidationError
Semantic validation failure (e.g. port index out of range, enum value not allowed).
constexpr int InvalidParams
Invalid method parameters (missing required, wrong type, etc.).