Use KSharedConfig::openStateConfig() instead of using a "data" file

This function will automatically create a "neochatstarerc" for us, and
KConfig will decide the best place for us to place our state. It won't
always be in AppDataLocation.
This commit is contained in:
Joshua Goins
2023-10-19 16:35:05 -04:00
committed by Tobias Fella
parent 26fd26f9fd
commit 83b7e7d121
5 changed files with 27 additions and 17 deletions

View File

@@ -11,12 +11,13 @@
#include <KConfig>
#include <KConfigGroup>
#include <KSharedConfig>
ServerListModel::ServerListModel(QObject *parent)
: QAbstractListModel(parent)
{
KConfig dataResource(QStringLiteral("data"), KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
KConfigGroup serverGroup(&dataResource, QStringLiteral("Servers"));
const auto stateConfig = KSharedConfig::openStateConfig();
const KConfigGroup serverGroup = stateConfig->group(QStringLiteral("Servers"));
QString domain = Controller::instance().activeConnection()->domain();
@@ -91,8 +92,8 @@ int ServerListModel::rowCount(const QModelIndex &parent) const
void ServerListModel::checkServer(const QString &url)
{
KConfig dataResource(QStringLiteral("data"), KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
KConfigGroup serverGroup(&dataResource, QStringLiteral("Servers"));
const auto stateConfig = KSharedConfig::openStateConfig();
const KConfigGroup serverGroup = stateConfig->group(QStringLiteral("Servers"));
if (!serverGroup.hasKey(url)) {
if (Quotient::isJobPending(m_checkServerJob)) {
@@ -108,8 +109,8 @@ void ServerListModel::checkServer(const QString &url)
void ServerListModel::addServer(const QString &url)
{
KConfig dataResource(QStringLiteral("data"), KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
KConfigGroup serverGroup(&dataResource, QStringLiteral("Servers"));
const auto stateConfig = KSharedConfig::openStateConfig();
KConfigGroup serverGroup = stateConfig->group(QStringLiteral("Servers"));
if (!serverGroup.hasKey(url)) {
Server newServer = Server{
@@ -125,17 +126,21 @@ void ServerListModel::addServer(const QString &url)
}
serverGroup.writeEntry(url, url);
stateConfig->sync();
}
void ServerListModel::removeServerAtIndex(int row)
{
KConfig dataResource(QStringLiteral("data"), KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
KConfigGroup serverGroup(&dataResource, QStringLiteral("Servers"));
const auto stateConfig = KSharedConfig::openStateConfig();
KConfigGroup serverGroup = stateConfig->group(QStringLiteral("Servers"));
serverGroup.deleteEntry(data(index(row), UrlRole).toString());
beginRemoveRows(QModelIndex(), row, row);
m_servers.removeAt(row);
endRemoveRows();
stateConfig->sync();
}
QHash<int, QByteArray> ServerListModel::roleNames() const

View File

@@ -6,7 +6,7 @@
using namespace Qt::Literals::StringLiterals;
RoomLastMessageProvider::RoomLastMessageProvider()
: m_config(KSharedConfig::openConfig(u"data"_s, KConfig::SimpleConfig, QStandardPaths::AppDataLocation))
: m_config(KSharedConfig::openStateConfig())
, m_configGroup(KConfigGroup(m_config, u"EventCache"_s))
{
}

View File

@@ -28,12 +28,12 @@ RoomManager::RoomManager(QObject *parent)
: QObject(parent)
, m_currentRoom(nullptr)
, m_lastCurrentRoom(nullptr)
, m_config(KConfig(QStringLiteral("data"), KConfig::SimpleConfig, QStandardPaths::AppDataLocation))
, m_config(KSharedConfig::openStateConfig())
, m_messageEventModel(new MessageEventModel(this))
, m_messageFilterModel(new MessageFilterModel(this, m_messageEventModel))
, m_mediaMessageFilterModel(new MediaMessageFilterModel(this, m_messageFilterModel))
{
m_lastRoomConfig = m_config.group(QStringLiteral("LastOpenRoom"));
m_lastRoomConfig = m_config->group(QStringLiteral("LastOpenRoom"));
connect(this, &RoomManager::currentRoomChanged, this, [this]() {
m_messageEventModel->setRoom(m_currentRoom);

View File

@@ -3,8 +3,8 @@
#pragma once
#include <KConfig>
#include <KConfigGroup>
#include <KSharedConfig>
#include <QObject>
#include <QQmlEngine>
#include <Quotient/room.h>
@@ -371,7 +371,7 @@ private:
NeoChatRoom *m_currentRoom;
NeoChatRoom *m_lastCurrentRoom;
QString m_arg;
KConfig m_config;
KSharedConfig::Ptr m_config;
KConfigGroup m_lastRoomConfig;
QPointer<ChatDocumentHandler> m_chatDocumentHandler;

View File

@@ -13,6 +13,7 @@
#include <KWindowSystem>
#endif
#include <KSharedConfig>
#include <QStandardPaths>
WindowController &WindowController::instance()
@@ -35,18 +36,22 @@ QWindow *WindowController::window() const
void WindowController::restoreGeometry()
{
KConfig dataResource(QStringLiteral("data"), KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
KConfigGroup windowGroup(&dataResource, QStringLiteral("Window"));
const auto stateConfig = KSharedConfig::openStateConfig();
const KConfigGroup windowGroup = stateConfig->group(QStringLiteral("Window"));
KWindowConfig::restoreWindowSize(m_window, windowGroup);
KWindowConfig::restoreWindowPosition(m_window, windowGroup);
}
void WindowController::saveGeometry()
{
KConfig dataResource(QStringLiteral("data"), KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
KConfigGroup windowGroup(&dataResource, QStringLiteral("Window"));
const auto stateConfig = KSharedConfig::openStateConfig();
KConfigGroup windowGroup = stateConfig->group(QStringLiteral("Window"));
KWindowConfig::saveWindowPosition(m_window, windowGroup);
KWindowConfig::saveWindowSize(m_window, windowGroup);
stateConfig->sync();
}
void WindowController::showAndRaiseWindow(const QString &startupId)