Commit 9c86154a authored by jan.koester's avatar jan.koester
Browse files

colors

parent 037d6213
Loading
Loading
Loading
Loading
+22 −0
Changes for client/localapi.cpp: 22 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -345,6 +345,28 @@ void LocalApi::fetchPublishTargets() {
    });
}

void LocalApi::fetchThemeColors() {
    QJsonArray cmds;
    QJsonObject cmd;
    cmd["command"] = "get_theme_colors";
    cmds.append(cmd);

    _pub->apiRequest(cmds, [this](bool ok, const QJsonArray &resp) {
        if (!ok) {
            emit statusMessage("Failed to fetch theme colors");
            return;
        }
        for (int i = 0; i < resp.size(); ++i) {
            QJsonObject obj = resp.at(i).toObject();
            if (obj.contains("colors")) {
                emit themeColorsLoaded(QString::fromUtf8(QJsonDocument(obj["colors"].toObject()).toJson(QJsonDocument::Compact)));
                return;
            }
        }
        emit themeColorsLoaded("{}");
    });
}

void LocalApi::publishToTarget(const QString &target, const QString &paramsJson) {
    if (!_pub->isConfigured()) {
        emit publishCompleted(false, "Not connected");
+4 −0
Changes for client/localapi.h: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -71,6 +71,9 @@ public:
    Q_INVOKABLE void fetchAlbums();
    Q_INVOKABLE void fetchMedia(const QString &albumId);

    /* Theme colors (requires connection) */
    Q_INVOKABLE void fetchThemeColors();

    /* Publish (requires connection) */
    Q_INVOKABLE void fetchPublishTargets();
    Q_INVOKABLE void publishToTarget(const QString &target, const QString &paramsJson);
@@ -109,6 +112,7 @@ signals:
    void mediaLoaded(const QString &json);
    void publishTargetsLoaded(const QString &json);
    void publishCompleted(bool ok, const QString &msg);
    void themeColorsLoaded(const QString &json);
    void savedConnectionsChanged();

private:
+169 −0
Changes for client/qml/ConnectionPanel.qml: 169 added lines, 0 removed lines.
Original line number Diff line number Diff line
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Dialogs

ColumnLayout {
    id: connPanel
@@ -441,6 +442,131 @@ ColumnLayout {
        visible: text.length > 0
    }

    Rectangle { Layout.fillWidth: true; height: 1; color: Theme.border; visible: connected }

    /* ========== Preview Color Settings ========== */
    Label {
        text: qsTr("Preview Colors")
        font.bold: true; font.pixelSize: 13; color: Theme.textPrimary
        visible: connected
    }

    /* Color mode selector: none / theme / custom */
    ComboBox {
        id: colorModeCombo
        Layout.fillWidth: true
        visible: connected
        font.pixelSize: 13
        palette.text: Theme.textPrimary
        palette.buttonText: Theme.textPrimary
        textRole: "text"
        model: ListModel {
            id: colorModeModel
            ListElement { text: "None (server default)"; value: "none" }
            ListElement { text: "Theme (dark/light)";    value: "theme" }
            ListElement { text: "Custom RGBA";           value: "custom" }
        }
        background: Rectangle { color: Theme.bgTertiary; border.color: Theme.border; radius: Theme.radius }
        onActivated: function(index) {
            connPanel.colorMode = colorModeModel.get(index).value
            if (connPanel.colorMode === "theme" && connPanel.themeColorsDark.length === 0)
                localApi.fetchThemeColors()
            requestServerPreview()
        }
    }

    /* -- Theme mode: dark/light selector -- */
    ColumnLayout {
        Layout.fillWidth: true
        visible: connected && connPanel.colorMode === "theme"
        spacing: 4

        Label { text: qsTr("Scheme"); font.pixelSize: 11; color: Theme.textSecondary }

        ComboBox {
            id: themeSchemeCombo
            Layout.fillWidth: true
            font.pixelSize: 13
            palette.text: Theme.textPrimary
            palette.buttonText: Theme.textPrimary
            model: ["dark", "light"]
            background: Rectangle { color: Theme.bgTertiary; border.color: Theme.border; radius: Theme.radius }
            onActivated: requestServerPreview()
        }

        Label {
            text: qsTr("Background: ") + connPanel.currentThemeBg()
            font.pixelSize: 10; color: Theme.textMuted
            Layout.fillWidth: true; elide: Text.ElideRight
        }

        Rectangle {
            Layout.fillWidth: true; height: 20; radius: Theme.radius
            border.color: Theme.border
            color: connPanel.currentThemeBg()
        }
    }

    /* -- Custom mode: RGBA sliders -- */
    ColumnLayout {
        Layout.fillWidth: true
        visible: connected && connPanel.colorMode === "custom"
        spacing: 4

        Label { text: qsTr("Background Color"); font.pixelSize: 11; color: Theme.textSecondary }

        /* Color preview + hex display */
        RowLayout {
            Layout.fillWidth: true
            spacing: 6

            Rectangle {
                width: 32; height: 32; radius: Theme.radius
                border.color: Theme.border
                color: connPanel.customColor
            }

            Label {
                text: connPanel.customColor.toString()
                font.pixelSize: 12; font.family: "monospace"
                color: Theme.textPrimary
                Layout.fillWidth: true
            }
        }

        Label { text: "R: " + Math.round(redSlider.value); font.pixelSize: 10; color: Theme.textMuted }
        Slider {
            id: redSlider
            Layout.fillWidth: true
            from: 0; to: 255; value: 255; stepSize: 1
            onMoved: { updateCustomColor(); requestServerPreview() }
        }

        Label { text: "G: " + Math.round(greenSlider.value); font.pixelSize: 10; color: Theme.textMuted }
        Slider {
            id: greenSlider
            Layout.fillWidth: true
            from: 0; to: 255; value: 255; stepSize: 1
            onMoved: { updateCustomColor(); requestServerPreview() }
        }

        Label { text: "B: " + Math.round(blueSlider.value); font.pixelSize: 10; color: Theme.textMuted }
        Slider {
            id: blueSlider
            Layout.fillWidth: true
            from: 0; to: 255; value: 255; stepSize: 1
            onMoved: { updateCustomColor(); requestServerPreview() }
        }

        Label { text: qsTr("Transparency: ") + Math.round(alphaSlider.value * 100) + "%"; font.pixelSize: 10; color: Theme.textMuted }
        Slider {
            id: alphaSlider
            Layout.fillWidth: true
            from: 0.0; to: 1.0; value: 1.0; stepSize: 0.01
            onMoved: { updateCustomColor(); requestServerPreview() }
        }
    }

    Item { Layout.fillHeight: true }

    /* --- Publish targets data --- */
@@ -450,6 +576,36 @@ ColumnLayout {
    property string lastPublishTarget: ""
    property string lastPublishParamsJson: ""

    /* --- Color settings data --- */
    property string colorMode: "none"   // "none" | "theme" | "custom"
    property var themeColorsDark: ({})
    property var themeColorsLight: ({})
    property color customColor: Qt.rgba(1, 1, 1, 1)

    function currentThemeBg() {
        var scheme = themeSchemeCombo.currentText
        var colors = scheme === "light" ? connPanel.themeColorsLight : connPanel.themeColorsDark
        return colors["--blogi-bg"] || (scheme === "light" ? "#ebedF0" : "#232627")
    }

    function getColorOverrideCss() {
        if (connPanel.colorMode === "none")
            return ""
        if (connPanel.colorMode === "theme") {
            var scheme = themeSchemeCombo.currentText
            return "data-theme=\"" + scheme + "\""
        }
        if (connPanel.colorMode === "custom") {
            var c = connPanel.customColor
            return "style=\"background:" + c + ";\""
        }
        return ""
    }

    function updateCustomColor() {
        connPanel.customColor = Qt.rgba(redSlider.value / 255.0, greenSlider.value / 255.0, blueSlider.value / 255.0, alphaSlider.value)
    }

    function reloadList() {
        var raw = localApi.getSavedConnections()
        connPanel.connections = JSON.parse(raw)
@@ -507,6 +663,14 @@ ColumnLayout {
        if (!connected || connPanel.selectedTargetIndex < 0) return
        var t = connPanel.publishTargets[connPanel.selectedTargetIndex]
        var params = collectPublishParams()
        // Add color settings
        if (connPanel.colorMode === "theme") {
            params["_color_mode"] = "theme"
            params["_color_scheme"] = themeSchemeCombo.currentText
        } else if (connPanel.colorMode === "custom") {
            params["_color_mode"] = "custom"
            params["_color_custom"] = connPanel.customColor.toString()
        }
        localApi.renderPreviewOnServer(connPanel.mobileMode, t.name, JSON.stringify(params))
    }

@@ -591,6 +755,11 @@ ColumnLayout {
                requestServerPreview()
            }
        }
        function onThemeColorsLoaded(json) {
            var colors = JSON.parse(json)
            connPanel.themeColorsDark = colors.dark || {}
            connPanel.themeColorsLight = colors.light || {}
        }
        function onPublishCompleted(ok, msg) {
            if (ok) {
                publishStatusLabel.text = msg
+34 −1
Changes for src/blogi.cpp: 34 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -379,6 +379,14 @@ void blogi::Blogi::api(libhttppp::HttpRequest& curreq, const int tid){
                handled = true;
            }

            // Handle get_theme_colors: return dark/light CSS variable values
            if (!handled && command && strcmp(command, "get_theme_colors") == 0) {
                json_object *colors = PlgArgs->theme->getThemeColors(tid);
                json_object_object_add(single_response, "status", json_object_new_string("success"));
                json_object_object_add(single_response, "colors", colors);
                handled = true;
            }

            // Handle publish: route to the target plugin
            if (!handled && command && strcmp(command, "publish") == 0) {
                json_object *param_obj = nullptr;
@@ -2133,6 +2141,9 @@ RETRY_REQUEST:
                std::string publishTarget;
                std::string authid;
                std::string html;
                std::string colorMode;
                std::string colorScheme;
                std::string colorCustom;
                json_object *publishParams = nullptr;

                // Helper lambda to process key/value pairs from either source
@@ -2145,6 +2156,12 @@ RETRY_REQUEST:
                        authid=value;
                    }else if(key=="html"){
                        html=value;
                    }else if(key=="_color_mode"){
                        colorMode=value;
                    }else if(key=="_color_scheme"){
                        colorScheme=value;
                    }else if(key=="_color_custom"){
                        colorCustom=value;
                    }else if(!key.empty()){
                        if(!publishParams)
                            publishParams = json_object_new_object();
@@ -2246,7 +2263,23 @@ RETRY_REQUEST:
                        }
                    }

                    PlgArgs->theme->printSite(tid,out,&index,curreq.getRequestURL(),false);
                    // Apply color mode: set data-theme attribute or inject custom background
                    if(colorMode == "theme" && !colorScheme.empty()){
                        libhtmlpp::HtmlElement *htmlEl = index.getElementbyTag("html");
                        if(htmlEl)
                            htmlEl->setAttribute("data-theme", colorScheme);
                    }else if(colorMode == "custom" && !colorCustom.empty()){
                        libhtmlpp::HtmlElement *body = index.getElementbyTag("body");
                        if(body){
                            std::string existing = body->getAtributte("style");
                            if(!existing.empty())
                                existing += ";";
                            existing += "background:" + colorCustom;
                            body->setAttribute("style", existing);
                        }
                    }

                    PlgArgs->theme->printSite(tid,out,&index,curreq.getRequestURL(),authenticated);

                    libhttppp::HttpResponse curres;
                    curres.setState(HTTP200);
+45 −0
Changes for src/theme.cpp: 45 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -600,6 +600,51 @@ void blogi::Theme::injectThemeColors(const int tid, libhtmlpp::HtmlElement *inde
    head->appendChild(css.parse());
}

json_object* blogi::Theme::getThemeColors(const int tid){
    struct ColorVar { const char *dbSuffix; const char *cssVar; const char *darkDefault; const char *lightDefault; };
    ColorVar vars[] = {
        {"BG",           "--blogi-bg",            "#232627",  "rgba(235,237,240,1)"},
        {"SURFACE",      "--blogi-surface",       "#31363b",  "rgba(245,246,248,1)"},
        {"SURFACE_A",    "--blogi-surface-a",     "rgba(49,54,59,0.7)", "rgba(245,246,248,0.88)"},
        {"TEXT",         "--blogi-text",           "#eeeeee",  "rgba(44,62,80,1)"},
        {"TEXT_MUTED",   "--blogi-text-muted",     "#aaaaaa",  "rgba(127,140,141,1)"},
        {"ACCENT",       "--blogi-accent",        "#3ad43a",  "rgba(39,148,94,1)"},
        {"ACCENT_DARK",  "--blogi-accent-dark",   "#2ea82e",  "rgba(30,122,75,1)"},
        {"BORDER",       "--blogi-border",        "#3a3f44",  "rgba(220,225,230,1)"},
        {"BG_ALT",       "--blogi-bg-alt",        "#2a2e32",  "rgba(232,236,240,1)"},
        {"ERROR",        "--blogi-error",         "#F36947",  "rgba(231,76,60,1)"},
        {"ERROR_BG",     "--blogi-error-bg",      "#3d1f1a",  "rgba(253,236,234,1)"},
        {"ERROR_TEXT",   "--blogi-error-text",    "#ff9a8a",  "rgba(192,57,43,1)"},
        {"SUCCESS_BG",   "--blogi-success-bg",    "#1a3d1f",  "rgba(234,250,241,1)"},
        {"SUCCESS_TEXT", "--blogi-success-text",   "#8aff9a",  "rgba(39,174,96,1)"},
        {"NAV_ACTIVE",   "--blogi-nav-active",    "#3daee9",  "rgba(41,128,185,1)"},
        {"NAV_HOVER",    "--blogi-nav-hover",     "#232629",  "rgba(232,236,240,1)"},
        {"NAV_BORDER",   "--blogi-nav-border",    "#222529",  "rgba(189,195,199,1)"},
    };

    json_object *root = json_object_new_object();
    json_object *dark = json_object_new_object();
    json_object *light = json_object_new_object();

    for(auto &v : vars){
        std::string dval;
        try { getConfig(*_Config.TDatabase[tid], std::string("THEME_DARK_") + v.dbSuffix, dval); } catch(...) {}
        normalizeColor(dval);
        if(dval.empty()) dval = v.darkDefault;
        json_object_object_add(dark, v.cssVar, json_object_new_string(dval.c_str()));

        std::string lval;
        try { getConfig(*_Config.TDatabase[tid], std::string("THEME_LIGHT_") + v.dbSuffix, lval); } catch(...) {}
        normalizeColor(lval);
        if(lval.empty()) lval = v.lightDefault;
        json_object_object_add(light, v.cssVar, json_object_new_string(lval.c_str()));
    }

    json_object_object_add(root, "dark", dark);
    json_object_object_add(root, "light", light);
    return root;
}

json_object* blogi::Theme::SettingsTheme(const int tid, libhttppp::HttpRequest &req, const std::string &sessionid){
    bool saved = false;
    bool reset = false;
Loading