From be1467f718e164ed6275651129aa530c69ff32c4 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 17 Nov 2020 17:01:09 +0100 Subject: [PATCH] Save collapsed categories --- src/main.cpp | 4 ++-- src/neochatconfig.kcfg | 3 ++- src/neochatconfig.kcfgc | 1 + src/roomlistmodel.cpp | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 833a016bb..2bca9f7eb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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("org.kde.neochat", 1, 0, "AccountListModel"); qmlRegisterType("org.kde.neochat", 1, 0, "RoomListModel"); qmlRegisterType("org.kde.neochat", 1, 0, "UserListModel"); diff --git a/src/neochatconfig.kcfg b/src/neochatconfig.kcfg index 03cfbe5df..0bae5ca7a 100644 --- a/src/neochatconfig.kcfg +++ b/src/neochatconfig.kcfg @@ -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" > + - + diff --git a/src/neochatconfig.kcfgc b/src/neochatconfig.kcfgc index 2261043b4..4ae997bdf 100644 --- a/src/neochatconfig.kcfgc +++ b/src/neochatconfig.kcfgc @@ -6,3 +6,4 @@ Mutators=true DefaultValueGetters=true GenerateProperties=true ParentInConstructor=true +Singleton=true diff --git a/src/roomlistmodel.cpp b/src/roomlistmodel.cpp index cbe321160..86ab8c592 100644 --- a/src/roomlistmodel.cpp +++ b/src/roomlistmodel.cpp @@ -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(); }