Pith - wedge_linux
wedge_linux/ConfigManager.cpp [3.1 kb]
Modified: 19:17:31 63 026 (21 May 026)
9 Days Ago
#include "ConfigManager.h"
#include <QJsonObject>
#include <QJsonDocument>
#include <QStandardPaths>
#include <QDir>
#include <QFile>
#include <QTextStream>
#include <QCoreApplication>

QString ConfigManager::getConfigPath() {
    QString path = QDir::homePath() + "/.config/wedge";
    QDir dir(path);
    if (!dir.exists()) dir.mkpath(".");
    return path;
}

void ConfigManager::saveNote(const NoteData &data) {
    QJsonObject json;
    json["content"] = data.content;
    json["x"] = data.x;
    json["y"] = data.y;
    json["width"] = data.width;
    json["height"] = data.height;
    json["bgColor"] = data.bgColor.name();
    json["textColor"] = data.textColor.name();
    json["focusColor"] = data.focusColor.name();
    json["fontFamily"] = data.fontFamily;
    json["fontSize"] = data.fontSize;
    json["lastModified"] = data.lastModified;
    json["autoStart"] = data.autoStart;
    json["hideTaskbar"] = data.hideTaskbar;

    QFile file(getConfigPath() + "/wedge.conf");
    if (file.open(QIODevice::WriteOnly)) {
        file.write(QJsonDocument(json).toJson());
    }
    updateAutoStart(data.autoStart);
}

NoteData ConfigManager::loadNote() {
    NoteData data;
    data.content = "";
    data.x = 100; data.y = 100; data.width = 350; data.height = 450;
    data.bgColor = QColor("#486860");
    data.textColor = QColor("#deddda");
    data.focusColor = QColor("#f6f5f4");
    data.fontFamily = "Sans-Serif";
    data.fontSize = 12;
    data.lastModified = QDateTime::currentSecsSinceEpoch();
    data.autoStart = false;
    data.hideTaskbar = false;

    QFile file(getConfigPath() + "/wedge.conf");
    if (file.open(QIODevice::ReadOnly)) {
        QJsonObject json = QJsonDocument::fromJson(file.readAll()).object();
        if (!json.isEmpty()) {
            data.content = json["content"].toString();
            data.x = json["x"].toInt();
            data.y = json["y"].toInt();
            data.width = json["width"].toInt();
            data.height = json["height"].toInt();
            data.bgColor = QColor(json["bgColor"].toString());
            data.textColor = QColor(json["textColor"].toString());
            data.focusColor = QColor(json["focusColor"].toString());
            data.fontFamily = json["fontFamily"].toString();
            data.fontSize = json["fontSize"].toInt();
            data.lastModified = json["lastModified"].toVariant().toLongLong();
            data.autoStart = json["autoStart"].toBool();
            data.hideTaskbar = json["hideTaskbar"].toBool();
        }
    }
    return data;
}

void ConfigManager::updateAutoStart(bool enable) {
    QString autostartPath = QDir::homePath() + "/.config/autostart";
    QDir().mkpath(autostartPath);
    QString desktopFile = autostartPath + "/wedge.desktop";

    if (enable) {
        QFile file(desktopFile);
        if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
            QTextStream out(&file);
            out << "[Desktop Entry]\nType=Application\nName=Wedge\n";
            out << "Exec=" << QCoreApplication::applicationFilePath() << "\n";
            out << "Icon=wedge\nComment=Wedge Notes\nTerminal=false\n";
        }
    } else {
        QFile::remove(desktopFile);
    }
}
Updates
Shim - Android 70.026.1
Wedge - Linux 68.026.1
Wedge - Android 68.026.1
Taper - Linux 64.026.1
Ayh Extension - Chrome 63.026.1
Dev
TVShow (227) 'CSA'
TVShow (228) 'APT'
TVProgram (83) 'BXT'
Miter Update(s)
Shim (Dictation)

Menu
Calendar
Project Tin (024/029)
Miter
RSS Feed
User Avatar
@vgmlr
=SUM(parts)