diff --git a/src/application.cpp b/src/application.cpp index 357244d73..9b652dd37 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -27,13 +27,11 @@ Application::Application() // XXX SettingsManager::getInstance().updateWordTypeMask(); - - this->windowManager.load(); } Application::~Application() { - this->windowManager.save(); + this->save(); chatterino::SettingsManager::getInstance().save(); } @@ -49,4 +47,9 @@ int Application::run(QApplication &qtApp) return qtApp.exec(); } +void Application::save() +{ + this->windowManager.save(); +} + } // namespace chatterino diff --git a/src/application.hpp b/src/application.hpp index df27441cf..c6c69b51e 100644 --- a/src/application.hpp +++ b/src/application.hpp @@ -25,6 +25,9 @@ public: Resources resources; ChannelManager channelManager; IrcManager ircManager; + +private: + void save(); }; } // namespace chatterino diff --git a/src/widgets/helper/notebooktab.cpp b/src/widgets/helper/notebooktab.cpp index 0328c4caa..68a1051a9 100644 --- a/src/widgets/helper/notebooktab.cpp +++ b/src/widgets/helper/notebooktab.cpp @@ -1,6 +1,9 @@ #include "widgets/helper/notebooktab.hpp" #include "colorscheme.hpp" +#include "common.hpp" +#include "debug/log.hpp" #include "settingsmanager.hpp" +#include "util/helpers.hpp" #include "widgets/notebook.hpp" #include "widgets/textinputdialog.hpp" @@ -11,10 +14,13 @@ namespace chatterino { namespace widgets { -NotebookTab::NotebookTab(Notebook *_notebook) +NotebookTab::NotebookTab(Notebook *_notebook, const std::string &settingPrefix) : BaseWidget(_notebook) + , settingRoot(fS("{}/tab", settingPrefix)) , positionChangedAnimation(this, "pos") , notebook(_notebook) + , title(fS("{}/title", this->settingRoot), "") + , useDefaultBehaviour(fS("{}/useDefaultBehaviour", this->settingRoot), true) , menu(this) { this->calcSize(); @@ -49,26 +55,29 @@ NotebookTab::NotebookTab(Notebook *_notebook) } }); - this->menu.addAction("Close", [=]() { - this->notebook->removePage(this->page); + QAction *enableHighlightsOnNewMessageAction = + new QAction("Enable highlights on new message", &this->menu); + enableHighlightsOnNewMessageAction->setCheckable(true); - qDebug() << "lmoa"; - }); + this->menu.addAction("Close", [=]() { this->notebook->removePage(this->page); }); - this->menu.addAction("Enable highlights on new message", []() { - qDebug() << "TODO: Implement"; // + this->menu.addAction(enableHighlightsOnNewMessageAction); + + connect(enableHighlightsOnNewMessageAction, &QAction::toggled, [this](bool newValue) { + debug::Log("New value is {}", newValue); // }); } void NotebookTab::calcSize() { float scale = getDpiMultiplier(); + QString qTitle(qS(this->title)); if (SettingsManager::getInstance().hideTabX) { - this->resize(static_cast((fontMetrics().width(title) + 16) * scale), + this->resize(static_cast((fontMetrics().width(qTitle) + 16) * scale), static_cast(24 * scale)); } else { - this->resize(static_cast((fontMetrics().width(title) + 8 + 24) * scale), + this->resize(static_cast((fontMetrics().width(qTitle) + 8 + 24) * scale), static_cast(24 * scale)); } @@ -77,14 +86,14 @@ void NotebookTab::calcSize() } } -const QString &NotebookTab::getTitle() const +QString NotebookTab::getTitle() const { - return title; + return qS(this->title); } void NotebookTab::setTitle(const QString &newTitle) { - this->title = newTitle; + this->title = newTitle.toStdString(); this->calcSize(); } @@ -182,7 +191,7 @@ void NotebookTab::paintEvent(QPaintEvent *) int rectW = (SettingsManager::getInstance().hideTabX ? 0 : static_cast(16) * scale); QRect rect(0, 0, this->width() - rectW, this->height()); - painter.drawText(rect, title, QTextOption(Qt::AlignCenter)); + painter.drawText(rect, this->getTitle(), QTextOption(Qt::AlignCenter)); if (!SettingsManager::getInstance().hideTabX && (mouseOver || selected)) { QRect xRect = this->getXRect(); @@ -282,33 +291,5 @@ void NotebookTab::mouseMoveEvent(QMouseEvent *event) } } -void NotebookTab::load(const boost::property_tree::ptree &tree) -{ - // Load tab title - try { - QString newTitle = QString::fromStdString(tree.get("title")); - if (newTitle.isEmpty()) { - this->useDefaultBehaviour = true; - } else { - this->setTitle(newTitle); - this->useDefaultBehaviour = false; - } - } catch (boost::property_tree::ptree_error) { - } -} - -boost::property_tree::ptree NotebookTab::save() -{ - boost::property_tree::ptree tree; - - if (this->useDefaultBehaviour) { - tree.put("title", ""); - } else { - tree.put("title", this->getTitle().toStdString()); - } - - return tree; -} - } // namespace widgets } // namespace chatterino diff --git a/src/widgets/helper/notebooktab.hpp b/src/widgets/helper/notebooktab.hpp index 37eb8a050..2338a0019 100644 --- a/src/widgets/helper/notebooktab.hpp +++ b/src/widgets/helper/notebooktab.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include namespace chatterino { @@ -20,16 +20,18 @@ class NotebookTab : public BaseWidget { Q_OBJECT + std::string settingRoot; + public: enum HighlightStyle { HighlightNone, HighlightHighlighted, HighlightNewMessage }; - explicit NotebookTab(Notebook *_notebook); + explicit NotebookTab(Notebook *_notebook, const std::string &settingPrefix); void calcSize(); SplitContainer *page; - const QString &getTitle() const; + QString getTitle() const; void setTitle(const QString &newTitle); bool isSelected() const; void setSelected(bool value); @@ -63,10 +65,10 @@ private: Notebook *notebook; - QString title; + pajlada::Settings::Setting title; public: - bool useDefaultBehaviour = true; + pajlada::Settings::Setting useDefaultBehaviour; private: bool selected = false; @@ -85,10 +87,6 @@ private: return QRect(this->width() - static_cast(20 * scale), static_cast(4 * scale), static_cast(16 * scale), static_cast(16 * scale)); } - -public: - void load(const boost::property_tree::ptree &tree); - boost::property_tree::ptree save(); }; } // namespace widgets diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index 16b3fda0a..d26eb3cb9 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -15,14 +15,17 @@ #include #include #include +#include #include #include namespace chatterino { namespace widgets { -Notebook::Notebook(ChannelManager &_channelManager, Window *parent, bool _showButtons) +Notebook::Notebook(ChannelManager &_channelManager, Window *parent, bool _showButtons, + const std::string &settingPrefix) : BaseWidget(parent) + , settingRoot(fS("{}/notebook", settingPrefix)) , channelManager(_channelManager) , addButton(this) , settingsButton(this) @@ -42,12 +45,21 @@ Notebook::Notebook(ChannelManager &_channelManager, Window *parent, bool _showBu settingsManager.hidePreferencesButton.connectSimple([this](auto) { this->performLayout(); }); settingsManager.hideUserButton.connectSimple([this](auto) { this->performLayout(); }); + + this->loadContainers(); } -SplitContainer *Notebook::addPage(bool select) +SplitContainer *Notebook::addNewPage() { - auto tab = new NotebookTab(this); - auto page = new SplitContainer(this->channelManager, this, tab); + return this->addPage(CreateUUID().toStdString(), true); +} + +SplitContainer *Notebook::addPage(const std::string &uuid, bool select) +{ + std::string key = fS("{}/containers/{}", this->settingRoot, uuid); + + auto tab = new NotebookTab(this, key); + auto page = new SplitContainer(this->channelManager, this, tab, key); tab->show(); @@ -80,7 +92,7 @@ void Notebook::removePage(SplitContainer *page) this->pages.removeOne(page); if (this->pages.size() == 0) { - addPage(); + this->addNewPage(); } this->performLayout(); @@ -253,54 +265,25 @@ void Notebook::usersButtonClicked() void Notebook::addPageButtonClicked() { - QTimer::singleShot(80, [this] { this->addPage(true); }); + QTimer::singleShot(80, [this] { this->addNewPage(); }); } -void Notebook::load(const boost::property_tree::ptree &tree) +void Notebook::loadContainers() { - // Read a list of tabs - try { - BOOST_FOREACH (const boost::property_tree::ptree::value_type &v, tree.get_child("tabs.")) { - bool select = v.second.get("selected", false); + std::string containersKey = fS("{}/containers", this->settingRoot); - auto page = addPage(select); - auto tab = page->getTab(); - tab->load(v.second); - page->load(v.second); - } - } catch (boost::property_tree::ptree_error &) { - // can't read tabs - } + auto keys = pajlada::Settings::SettingManager::getObjectKeys(containersKey); - if (this->pages.size() == 0) { - // No pages saved, show default stuff - loadDefaults(); + for (const std::string &key : keys) { + this->addPage(key); } } -void Notebook::save(boost::property_tree::ptree &tree) +void Notebook::save() { - boost::property_tree::ptree tabs; - - // Iterate through all tabs and add them to our tabs property thing for (const auto &page : this->pages) { - boost::property_tree::ptree pTab = page->getTab()->save(); - - boost::property_tree::ptree pChats = page->save(); - - if (pChats.size() > 0) { - pTab.add_child("columns", pChats); - } - - tabs.push_back(std::make_pair("", pTab)); + page->save(); } - - tree.add_child("tabs", tabs); -} - -void Notebook::loadDefaults() -{ - addPage(); } } // namespace widgets diff --git a/src/widgets/notebook.hpp b/src/widgets/notebook.hpp index ba14d94e4..f3a574839 100644 --- a/src/widgets/notebook.hpp +++ b/src/widgets/notebook.hpp @@ -7,7 +7,6 @@ #include #include -#include namespace chatterino { @@ -21,12 +20,16 @@ class Notebook : public BaseWidget { Q_OBJECT + std::string settingRoot; + public: enum HighlightType { none, highlighted, newMessage }; - explicit Notebook(ChannelManager &_channelManager, Window *parent, bool showButtons); + explicit Notebook(ChannelManager &_channelManager, Window *parent, bool _showButtons, + const std::string &settingPrefix); - SplitContainer *addPage(bool select = false); + SplitContainer *addNewPage(); + SplitContainer *addPage(const std::string &uuid, bool select = false); void removePage(SplitContainer *page); void select(SplitContainer *page); @@ -69,10 +72,10 @@ private: bool showButtons; + void loadContainers(); + public: - void load(const boost::property_tree::ptree &tree); - void save(boost::property_tree::ptree &tree); - void loadDefaults(); + void save(); }; } // namespace widgets diff --git a/src/widgets/split.cpp b/src/widgets/split.cpp index 55f69702f..1c1ca32bd 100644 --- a/src/widgets/split.cpp +++ b/src/widgets/split.cpp @@ -47,9 +47,11 @@ inline void ezShortcut(Split *w, const char *key, T t) static int index = 0; -Split::Split(ChannelManager &_channelManager, SplitContainer *parent) +Split::Split(ChannelManager &_channelManager, SplitContainer *parent, const std::string &_uuid) : BaseWidget(parent) - , channelName("/chatWidgets/" + std::to_string(index++) + "/channelName") + , uuid(_uuid) + , settingRoot(fS("/splits/{}", this->uuid)) + , channelName(fS("{}/channelName", this->settingRoot)) , parentPage(*parent) , channelManager(_channelManager) , channel(_channelManager.emptyChannel) @@ -123,6 +125,11 @@ Split::~Split() this->channelNameUpdated(""); } +const std::string &Split::getUUID() const +{ + return this->uuid; +} + std::shared_ptr Split::getChannel() const { return this->channel; @@ -234,24 +241,6 @@ void Split::paintEvent(QPaintEvent *) painter.fillRect(this->rect(), this->colorScheme.ChatBackground); } -void Split::load(const boost::property_tree::ptree &tree) -{ - // load tab text - try { - this->channelName = tree.get("channelName"); - } catch (boost::property_tree::ptree_error) { - } -} - -boost::property_tree::ptree Split::save() -{ - boost::property_tree::ptree tree; - - tree.put("channelName", this->channelName.getValue()); - - return tree; -} - /// Slots void Split::doAddSplit() { @@ -280,8 +269,8 @@ void Split::doPopup() Window &window = WindowManager::instance->createWindow(); Split *split = new Split(this->channelManager, - static_cast(window.getNotebook().getSelectedPage())); - split->channelName = this->channelName.getValue(); + static_cast(window.getNotebook().getSelectedPage()), + this->uuid); window.getNotebook().getSelectedPage()->addToLayout(split); diff --git a/src/widgets/split.hpp b/src/widgets/split.hpp index 92086737a..1e481f715 100644 --- a/src/widgets/split.hpp +++ b/src/widgets/split.hpp @@ -15,7 +15,6 @@ #include #include #include -#include #include namespace chatterino { @@ -43,14 +42,18 @@ class Split : public BaseWidget Q_OBJECT + const std::string uuid; + const std::string settingRoot; + public: - Split(ChannelManager &_channelManager, SplitContainer *parent); + Split(ChannelManager &_channelManager, SplitContainer *parent, const std::string &_uuid); ~Split(); ChannelManager &channelManager; pajlada::Settings::Setting channelName; boost::signals2::signal channelChanged; + const std::string &getUUID() const; std::shared_ptr getChannel() const; std::shared_ptr &getChannelRef(); void setFlexSizeX(double x); @@ -63,8 +66,6 @@ public: bool hasFocus() const; void layoutMessages(); void updateGifEmotes(); - void load(const boost::property_tree::ptree &tree); - boost::property_tree::ptree save(); protected: virtual void paintEvent(QPaintEvent *) override; diff --git a/src/widgets/splitcontainer.cpp b/src/widgets/splitcontainer.cpp index 0c1c0fcf9..ac20cb938 100644 --- a/src/widgets/splitcontainer.cpp +++ b/src/widgets/splitcontainer.cpp @@ -1,5 +1,6 @@ #include "widgets/splitcontainer.hpp" #include "colorscheme.hpp" +#include "util/helpers.hpp" #include "widgets/helper/notebooktab.hpp" #include "widgets/notebook.hpp" #include "widgets/split.hpp" @@ -23,8 +24,12 @@ bool SplitContainer::isDraggingSplit = false; Split *SplitContainer::draggingSplit = nullptr; std::pair SplitContainer::dropPosition = std::pair(-1, -1); -SplitContainer::SplitContainer(ChannelManager &_channelManager, Notebook *parent, NotebookTab *_tab) +SplitContainer::SplitContainer(ChannelManager &_channelManager, Notebook *parent, NotebookTab *_tab, + const std::string &_settingPrefix) : BaseWidget(parent->colorScheme, parent) + , settingPrefix(_settingPrefix) + , settingRoot(fS("{}", this->settingPrefix)) + , chats(fS("{}/chats", this->settingRoot)) , channelManager(_channelManager) , tab(_tab) , dropPreview(this) @@ -44,6 +49,8 @@ SplitContainer::SplitContainer(ChannelManager &_channelManager, Notebook *parent this->ui.hbox.setSpacing(1); this->ui.hbox.setMargin(0); + this->loadSplits(); + this->refreshTitle(); } @@ -108,6 +115,7 @@ void SplitContainer::addToLayout(Split *widget, std::pair position) vbox->addWidget(widget); this->ui.hbox.addLayout(vbox, 1); + this->refreshCurrentFocusCoordinates(); return; } @@ -140,9 +148,12 @@ NotebookTab *SplitContainer::getTab() const return this->tab; } -void SplitContainer::addChat(bool openChannelNameDialog) +void SplitContainer::addChat(bool openChannelNameDialog, std::string chatUUID) { - Split *w = this->createChatWidget(); + if (chatUUID.empty()) { + chatUUID = CreateUUID().toStdString(); + } + Split *w = this->createChatWidget(chatUUID); if (openChannelNameDialog) { bool ret = w->showChangeChannelPopup("Open channel", true); @@ -418,9 +429,9 @@ std::pair SplitContainer::getChatPosition(const Split *chatWidget) return getWidgetPositionInLayout(layout, chatWidget); } -Split *SplitContainer::createChatWidget() +Split *SplitContainer::createChatWidget(const std::string &uuid) { - return new Split(this->channelManager, this); + return new Split(this->channelManager, this, uuid); } void SplitContainer::refreshTitle() @@ -454,81 +465,82 @@ void SplitContainer::refreshTitle() this->tab->setTitle(newTitle); } -void SplitContainer::load(const boost::property_tree::ptree &tree) +void SplitContainer::loadSplits() { - try { - int column = 0; - for (const auto &v : tree.get_child("columns.")) { - int row = 0; - for (const auto &innerV : v.second.get_child("")) { - auto widget = this->createChatWidget(); - widget->load(innerV.second); - addToLayout(widget, std::pair(column, row)); - ++row; - } - ++column; + const auto hboxes = this->chats.getValue(); + int column = 0; + for (const std::vector &hbox : hboxes) { + int row = 0; + for (const std::string &chatUUID : hbox) { + Split *split = this->createChatWidget(chatUUID); + + this->addToLayout(split, std::pair(column, row)); + + ++row; } - } catch (boost::property_tree::ptree_error &) { - // can't read tabs + ++column; } } -static void saveFromLayout(QLayout *layout, boost::property_tree::ptree &tree) +template +static void saveFromLayout(QLayout *layout, Container &container) { for (int i = 0; i < layout->count(); ++i) { auto item = layout->itemAt(i); auto innerLayout = item->layout(); if (innerLayout != nullptr) { - boost::property_tree::ptree innerLayoutTree; + std::vector vbox; - saveFromLayout(innerLayout, innerLayoutTree); - - if (innerLayoutTree.size() > 0) { - tree.push_back(std::make_pair("", innerLayoutTree)); + for (int j = 0; j < innerLayout->count(); ++j) { + auto innerItem = innerLayout->itemAt(j); + auto innerWidget = innerItem->widget(); + if (innerWidget == nullptr) { + assert(false); + continue; + } + Split *innerSplit = qobject_cast(innerWidget); + vbox.push_back(innerSplit->getUUID()); } - continue; - } + container.push_back(vbox); - auto widget = item->widget(); - - if (widget == nullptr) { - // This layoutitem does not manage a widget for some reason - continue; - } - - Split *chatWidget = qobject_cast(widget); - - if (chatWidget != nullptr) { - boost::property_tree::ptree chat = chatWidget->save(); - - tree.push_back(std::make_pair("", chat)); continue; } } } -boost::property_tree::ptree SplitContainer::save() +void SplitContainer::save() { - boost::property_tree::ptree tree; - auto layout = this->ui.hbox.layout(); - saveFromLayout(layout, tree); + std::vector> _chats; - /* - for (const auto &chat : this->chatWidgets) { - boost::property_tree::ptree child = chat->save(); + for (int i = 0; i < layout->count(); ++i) { + auto item = layout->itemAt(i); - // Set child position - child.put("position", "5,3"); + auto innerLayout = item->layout(); + if (innerLayout != nullptr) { + std::vector vbox; - tree.push_back(std::make_pair("", child)); + for (int j = 0; j < innerLayout->count(); ++j) { + auto innerItem = innerLayout->itemAt(j); + auto innerWidget = innerItem->widget(); + if (innerWidget == nullptr) { + assert(false); + continue; + } + Split *innerSplit = qobject_cast(innerWidget); + vbox.push_back(innerSplit->getUUID()); + } + + _chats.push_back(vbox); + + continue; + } } - */ - return tree; + this->chats = _chats; } } // namespace widgets diff --git a/src/widgets/splitcontainer.hpp b/src/widgets/splitcontainer.hpp index 8482e4d56..e5ed89ab8 100644 --- a/src/widgets/splitcontainer.hpp +++ b/src/widgets/splitcontainer.hpp @@ -11,8 +11,6 @@ #include #include #include -#include -#include namespace chatterino { @@ -24,8 +22,12 @@ class SplitContainer : public BaseWidget { Q_OBJECT + const std::string settingPrefix; + std::string settingRoot; + public: - SplitContainer(ChannelManager &_channelManager, Notebook *parent, NotebookTab *_tab); + SplitContainer(ChannelManager &_channelManager, Notebook *parent, NotebookTab *_tab, + const std::string &_settingPrefix); ChannelManager &channelManager; @@ -35,7 +37,7 @@ public: const std::vector &getChatWidgets() const; NotebookTab *getTab() const; - void addChat(bool openChannelNameDialog = false); + void addChat(bool openChannelNameDialog = false, std::string chatUUID = std::string()); static bool isDraggingSplit; static Split *draggingSplit; @@ -88,19 +90,22 @@ private: std::vector chatWidgets; std::vector dropRegions; + pajlada::Settings::Setting>> chats; + NotebookPageDropPreview dropPreview; void setPreviewRect(QPoint mousePos); std::pair getChatPosition(const Split *chatWidget); - Split *createChatWidget(); + Split *createChatWidget(const std::string &uuid); public: void refreshTitle(); - void load(const boost::property_tree::ptree &tree); - boost::property_tree::ptree save(); + void loadSplits(); + + void save(); }; } // namespace widgets diff --git a/src/widgets/window.cpp b/src/widgets/window.cpp index 5a5eb1b96..b800d17aa 100644 --- a/src/widgets/window.cpp +++ b/src/widgets/window.cpp @@ -14,14 +14,14 @@ namespace chatterino { namespace widgets { -Window::Window(const QString &_windowName, ChannelManager &_channelManager, +Window::Window(const QString &windowName, ChannelManager &_channelManager, ColorScheme &_colorScheme, bool _isMainWindow) : BaseWidget(_colorScheme, nullptr) - , windowName(_windowName) - , windowGeometry(this->windowName.toStdString()) + , settingRoot(fS("/windows/{}", windowName)) + , windowGeometry(this->settingRoot) , channelManager(_channelManager) , colorScheme(_colorScheme) - , notebook(this->channelManager, this, _isMainWindow) + , notebook(this->channelManager, this, _isMainWindow, this->settingRoot) , dpi(this->getDpiMultiplier()) { this->initAsWindow(); @@ -85,36 +85,6 @@ void Window::repaintVisibleChatWidgets(Channel *channel) } } -void Window::load(const boost::property_tree::ptree &tree) -{ - this->notebook.load(tree); - - loaded = true; -} - -boost::property_tree::ptree Window::save() -{ - boost::property_tree::ptree child; - - child.put("type", "main"); - - this->notebook.save(child); - - return child; -} - -void Window::loadDefaults() -{ - this->notebook.loadDefaults(); - - loaded = true; -} - -bool Window::isLoaded() const -{ - return loaded; -} - Notebook &Window::getNotebook() { return this->notebook; @@ -158,5 +128,10 @@ void Window::loadGeometry() } } +void Window::save() +{ + this->notebook.save(); +} + } // namespace widgets } // namespace chatterino diff --git a/src/widgets/window.hpp b/src/widgets/window.hpp index 7af3536d2..5fb7e4b25 100644 --- a/src/widgets/window.hpp +++ b/src/widgets/window.hpp @@ -9,7 +9,6 @@ //#include //#endif -#include #include #include @@ -22,11 +21,11 @@ class CompletionManager; namespace widgets { struct WindowGeometry { - WindowGeometry(const std::string &key) - : x(fS("/windows/{}/geometry/x", key)) - , y(fS("/windows/{}/geometry/y", key)) - , width(fS("/windows/{}/geometry/width", key)) - , height(fS("/windows/{}/geometry/height", key)) + WindowGeometry(const std::string &settingPrefix) + : x(fS("{}/geometry/x", settingPrefix)) + , y(fS("{}/geometry/y", settingPrefix)) + , width(fS("{}/geometry/width", settingPrefix)) + , height(fS("{}/geometry/height", settingPrefix)) { } @@ -40,22 +39,16 @@ class Window : public BaseWidget { Q_OBJECT - QString windowName; + std::string settingRoot; WindowGeometry windowGeometry; public: - explicit Window(const QString &_windowName, ChannelManager &_channelManager, + explicit Window(const QString &windowName, ChannelManager &_channelManager, ColorScheme &_colorScheme, bool isMainWindow); void repaintVisibleChatWidgets(Channel *channel = nullptr); - void load(const boost::property_tree::ptree &tree); - boost::property_tree::ptree save(); - void loadDefaults(); - - bool isLoaded() const; - Notebook &getNotebook(); void refreshWindowTitle(const QString &username); @@ -76,10 +69,12 @@ private: ColorScheme &colorScheme; Notebook notebook; - bool loaded = false; TitleBar titleBar; friend class Notebook; + +public: + void save(); }; } // namespace widgets diff --git a/src/windowmanager.cpp b/src/windowmanager.cpp index bb3719d1e..6311e12c5 100644 --- a/src/windowmanager.cpp +++ b/src/windowmanager.cpp @@ -7,7 +7,6 @@ #include #include #include -#include namespace chatterino { WindowManager *WindowManager::instance = nullptr; @@ -70,8 +69,6 @@ widgets::Window &WindowManager::createWindow() { auto *window = new widgets::Window("external", this->channelManager, this->colorScheme, false); - window->loadDefaults(); - this->windows.push_back(window); return *window; @@ -92,65 +89,15 @@ widgets::Window *WindowManager::windowAt(int index) return this->windows.at(index); } -void WindowManager::load() -{ - const auto &settingsPath = getSettingsPath(); - boost::property_tree::ptree tree; - - try { - boost::property_tree::read_json(settingsPath, tree); - } catch (const boost::property_tree::json_parser_error &ex) { - qDebug() << "Error using property_tree::readJson: " << QString::fromStdString(ex.message()); - - getMainWindow().loadDefaults(); - - return; - } - - // Read a list of windows - try { - BOOST_FOREACH (const boost::property_tree::ptree::value_type &v, - tree.get_child("windows.")) { - qDebug() << QString::fromStdString(v.first.data()); - const auto &type = v.second.get("type", "unknown"); - - if (type == "main") { - getMainWindow().load(v.second); - } else { - qDebug() << "Unhandled window type: " << type.c_str(); - } - } - } catch (boost::property_tree::ptree_error &) { - // can't read windows - } - - // if the main window was not loaded properly, load defaults - if (!getMainWindow().isLoaded()) { - getMainWindow().loadDefaults(); - } - - // If there are no windows, create a default main window -} - void WindowManager::save() { - auto &settingsPath = getSettingsPath(); - boost::property_tree::ptree tree; + assert(this->mainWindow); - // Create windows array - boost::property_tree::ptree windows; + this->mainWindow->save(); - { - // save main window - auto child = getMainWindow().save(); - windows.push_back(std::make_pair("", child)); + for (widgets::Window *window : this->windows) { + window->save(); } - - // TODO: iterate through rest of windows and add them to the "windows" ptree - - tree.add_child("windows", windows); - - boost::property_tree::write_json(settingsPath, tree); } } // namespace chatterino diff --git a/src/windowmanager.hpp b/src/windowmanager.hpp index 28b121d6d..befa39f72 100644 --- a/src/windowmanager.hpp +++ b/src/windowmanager.hpp @@ -31,7 +31,6 @@ public: int windowCount(); widgets::Window *windowAt(int index); - void load(); void save(); boost::signals2::signal repaintGifs;