Commit 7b767a0a authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Store state data in separate config file

For migrating the old data we can utilize the KConfigGroup::moveValuesTo method.
For the state config a new kcfg file is added.

Relates to https://phabricator.kde.org/T12549.

BUG: 441575
parent e966debe
Pipeline #114986 passed with stage
in 1 minute and 53 seconds
......@@ -214,6 +214,7 @@ ki18n_wrap_ui(konversation_SRCS
)
kconfig_add_kcfg_files(konversation_SRCS config/preferences_base.kcfgc)
kconfig_add_kcfg_files(konversation_SRCS config/konversation_state.kcfgc)
ecm_qt_declare_logging_category(konversation_SRCS
HEADER konversation_log.h
......
......@@ -27,6 +27,7 @@
#include "awaymanager.h"
#include "konversation_log.h"
#include "config-konversation.h"
#include "konversation_state.h"
#include <KIO/JobUiDelegate>
#include <KIO/OpenUrlJob>
......@@ -84,6 +85,7 @@ Application::~Application()
stashQueueRates();
Preferences::self()->save(); // FIXME i can't figure out why this isn't in saveOptions --argonel
KonversationState::self()->save();
saveOptions(false);
// Delete m_dccTransferManager here as its destructor depends on the main loop being in tact which it
......
......@@ -20,16 +20,6 @@
<label></label>
<whatsthis></whatsthis>
</entry>
<entry key="TreeSplitterSizes" type="IntList">
<default></default>
<label></label>
<whatsthis></whatsthis>
</entry>
<entry key="TopicSplitterSizes" type="IntList">
<default></default>
<label></label>
<whatsthis></whatsthis>
</entry>
<entry key="TextFont" type="Font">
<default code="true">QFontDatabase::systemFont(QFontDatabase::GeneralFont)</default>
<label></label>
......@@ -139,11 +129,6 @@
<label></label>
<whatsthis></whatsthis>
</entry>
<entry key="ChannelSplitterSizes" type="IntList">
<default></default>
<label></label>
<whatsthis></whatsthis>
</entry>
<entry key="BackgroundImage" type="Url">
<default></default>
<label></label>
......
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
<kcfgfile name="konversationrc" stateConfig="true" />
<group name="Appearance">
<entry key="TreeSplitterSizes" type="IntList">
<default />
<label />
<whatsthis />
</entry>
<entry key="TopicSplitterSizes" type="IntList">
<default />
<label />
<whatsthis />
</entry>
<entry key="ChannelSplitterSizes" type="IntList">
<default />
<label />
<whatsthis />
</entry>
</group>
</kcfg>
ClassName=KonversationState
File=konversation_state.kcfg
GlobalEnums=true
Mutators=true
SetUserTexts=true
Singleton=true
MemberVariables=private
ItemAccessors=true
......@@ -23,6 +23,7 @@
#include "notificationhandler.h"
#include "viewcontainer.h"
#include "konversation_log.h"
#include "konversation_state.h"
#include <kwidgetsaddons_version.h>
#include <KAuthorized>
......@@ -2054,13 +2055,13 @@ void Channel::showEvent(QShowEvent*)
void Channel::syncSplitters()
{
QList<int> vertSizes = Preferences::self()->topicSplitterSizes();
QList<int> horizSizes = Preferences::self()->channelSplitterSizes();
QList<int> vertSizes = KonversationState::self()->topicSplitterSizes();
QList<int> horizSizes = KonversationState::self()->channelSplitterSizes();
if (vertSizes.isEmpty())
{
vertSizes = { m_topicButton->height(), (height() - m_topicButton->height()) };
Preferences::self()->setTopicSplitterSizes(vertSizes);
KonversationState::self()->setTopicSplitterSizes(vertSizes);
}
if (horizSizes.isEmpty())
......@@ -2069,7 +2070,7 @@ void Channel::syncSplitters()
// tested with 8pt and 10pt DejaVu Sans and Droid Sans.
int listWidth = fontMetrics().averageCharWidth() * 17 + 20;
horizSizes = { (width() - listWidth), listWidth };
Preferences::self()->setChannelSplitterSizes(horizSizes);
KonversationState::self()->setChannelSplitterSizes(horizSizes);
}
m_vertSplitter->setSizes(vertSizes);
......@@ -2648,16 +2649,16 @@ bool Channel::eventFilter(QObject* watched, QEvent* e)
{
if (!topicSplitterHidden && !channelSplitterHidden)
{
Preferences::self()->setChannelSplitterSizes(m_horizSplitter->sizes());
Preferences::self()->setTopicSplitterSizes(m_vertSplitter->sizes());
KonversationState::self()->setChannelSplitterSizes(m_horizSplitter->sizes());
KonversationState::self()->setTopicSplitterSizes(m_vertSplitter->sizes());
}
if (!topicSplitterHidden && channelSplitterHidden)
{
Preferences::self()->setTopicSplitterSizes(m_vertSplitter->sizes());
KonversationState::self()->setTopicSplitterSizes(m_vertSplitter->sizes());
}
if (!channelSplitterHidden && topicSplitterHidden)
{
Preferences::self()->setChannelSplitterSizes(m_horizSplitter->sizes());
KonversationState::self()->setChannelSplitterSizes(m_horizSplitter->sizes());
}
}
......
......@@ -47,6 +47,7 @@
MainWindow::MainWindow() : KXmlGuiWindow(nullptr)
{
setStateConfigGroup(QStringLiteral("MainWindow"));
IrcContextMenus::setupUi(this);
m_hasDirtySettings = false;
......
......@@ -33,6 +33,7 @@
#include "viewtree.h"
#include "viewspringloader.h"
#include "konversation_log.h"
#include "konversation_state.h"
#include <KMessageBox>
#include <KIO/OpenUrlJob>
......@@ -43,6 +44,7 @@
#include <KToggleAction>
#include <KSelectAction>
#include <KWindowSystem>
#include <KSharedConfig>
#include <QModelIndex>
#include <QSplitter>
......@@ -119,6 +121,11 @@ ViewContainer::ViewContainer(MainWindow* window) : QAbstractItemModel(window)
, m_insertCharDialog(nullptr)
, m_queryViewCount(0)
{
// move existing entries to their new location
KConfigGroup appearanceStateConfig = KSharedConfig::openStateConfig()->group("Appearance");
KConfigGroup appearanceGrp = KSharedConfig::openConfig()->group("Appearance");
appearanceGrp.moveValuesTo({"TreeSplitterSizes", "TopicSplitterSizes", "ChannelSplitterSizes"}, appearanceStateConfig);
m_viewSpringLoader = new ViewSpringLoader(this);
images = Application::instance()->images();
......@@ -181,7 +188,7 @@ void ViewContainer::initializeSplitterSizes()
{
if (m_viewTree && !m_viewTree->isHidden())
{
QList<int> sizes = Preferences::self()->treeSplitterSizes();
QList<int> sizes = KonversationState::self()->treeSplitterSizes();
if (sizes.isEmpty())
sizes << 145 << (m_window->width() - 145); // FIXME: Make DPI-aware.
......@@ -195,7 +202,7 @@ void ViewContainer::saveSplitterSizes()
{
if (!m_saveSplitterSizesLock)
{
Preferences::self()->setTreeSplitterSizes(m_viewTreeSplitter->sizes());
KonversationState::self()->setTreeSplitterSizes(m_viewTreeSplitter->sizes());
m_saveSplitterSizesLock = false;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment