Save collapsed categories

This commit is contained in:
Carl Schwan
2020-11-17 17:01:09 +01:00
parent f98834bb03
commit be1467f718
4 changed files with 19 additions and 3 deletions

View File

@@ -60,11 +60,11 @@ int main(int argc, char *argv[])
app.setWindowIcon(QIcon(":/assets/img/icon.png"));
Clipboard clipboard;
NeoChatConfig config;
auto config = NeoChatConfig::self();
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "Controller", &Controller::instance());
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "Clipboard", &clipboard);
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "Config", &config);
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "Config", config);
qmlRegisterType<AccountListModel>("org.kde.neochat", 1, 0, "AccountListModel");
qmlRegisterType<RoomListModel>("org.kde.neochat", 1, 0, "RoomListModel");
qmlRegisterType<UserListModel>("org.kde.neochat", 1, 0, "UserListModel");

View File

@@ -3,8 +3,9 @@
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="neochatrc" />
<group name="General">
<entry name="CollapsedSections" type="StringList">
<entry name="CollapsedSections" type="IntList">
<label>Collapsed sections in the room list</label>
</entry>
<entry name="OpenRoom" type="String">

View File

@@ -6,3 +6,4 @@ Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
Singleton=true

View File

@@ -7,6 +7,7 @@
#include "user.h"
#include "utils.h"
#include "neochatconfig.h"
#include "events/roomevent.h"
@@ -20,6 +21,10 @@
RoomListModel::RoomListModel(QObject *parent)
: QAbstractListModel(parent)
{
const auto collaposedSections = NeoChatConfig::collapsedSections();
for (auto collapsedSection : collaposedSections) {
m_categoryVisibility[collapsedSection] = false;
}
}
RoomListModel::~RoomListModel()
@@ -311,6 +316,15 @@ QString RoomListModel::categoryName(int section) const
void RoomListModel::setCategoryVisible(int category, bool visible)
{
beginResetModel();
auto collaposedSections = NeoChatConfig::collapsedSections();
if (visible) {
collaposedSections.removeAll(category);
} else {
collaposedSections.push_back(category);
}
NeoChatConfig::setCollapsedSections(collaposedSections);
NeoChatConfig::self()->save();
m_categoryVisibility[category] = visible;
endResetModel();
}