diff --git a/widgets/chatwidget.cpp b/widgets/chatwidget.cpp index 184271374..e2d941bcb 100644 --- a/widgets/chatwidget.cpp +++ b/widgets/chatwidget.cpp @@ -83,5 +83,27 @@ ChatWidget::paintEvent(QPaintEvent *) painter.fillRect(this->rect(), ColorScheme::getInstance().ChatBackground); } + +void +ChatWidget::load(const boost::property_tree::ptree &tree) +{ + // Load tab text + try { + this->setChannelName( + QString::fromStdString(tree.get("channelName"))); + } catch (boost::property_tree::ptree_error) { + } } + +boost::property_tree::ptree +ChatWidget::save() +{ + boost::property_tree::ptree tree; + + tree.put("channelName", this->getChannelName().toStdString()); + + return tree; } + +} // namespace widgets +} // namespace chatterino diff --git a/widgets/chatwidget.h b/widgets/chatwidget.h index cff83f8c5..5b1782d3c 100644 --- a/widgets/chatwidget.h +++ b/widgets/chatwidget.h @@ -10,6 +10,7 @@ #include #include #include +#include namespace chatterino { namespace widgets { @@ -56,8 +57,13 @@ private: ChatWidgetHeader header; ChatWidgetView view; ChatWidgetInput input; + +public: + void load(const boost::property_tree::ptree &tree); + boost::property_tree::ptree save(); }; -} -} + +} // namespace widgets +} // namespace chatterino #endif // CHATWIDGET_H diff --git a/widgets/notebook.cpp b/widgets/notebook.cpp index 10fe76843..c850cfad5 100644 --- a/widgets/notebook.cpp +++ b/widgets/notebook.cpp @@ -226,6 +226,13 @@ Notebook::save(boost::property_tree::ptree &tree) // Iterate through all tabs and add them to our tabs property thing for (const auto &page : this->pages) { boost::property_tree::ptree pTab = page->tab->save(); + + boost::property_tree::ptree pChats = page->save(); + + if (pChats.size() > 0) { + pTab.add_child("chats", pChats); + } + tabs.push_back(std::make_pair("", pTab)); } diff --git a/widgets/notebookpage.cpp b/widgets/notebookpage.cpp index d2e1582b7..015ee4be4 100644 --- a/widgets/notebookpage.cpp +++ b/widgets/notebookpage.cpp @@ -124,7 +124,8 @@ void NotebookPage::mouseReleaseEvent(QMouseEvent *event) { if (this->hbox.count() == 0 && event->button() == Qt::LeftButton) { - addToLayout(new ChatWidget(), std::pair(-1, -1)); + // "Add Chat" was clicked + this->addToLayout(new ChatWidget(), std::pair(-1, -1)); setCursor(QCursor(Qt::ArrowCursor)); } @@ -242,11 +243,31 @@ NotebookPage::paintEvent(QPaintEvent *) } void -NotebookPage::load(const boost::property_tree::ptree &v) +NotebookPage::load(const boost::property_tree::ptree &tree) { - const std::string &tabName = v.get("name", "UNNAMED"); + try { + BOOST_FOREACH (const boost::property_tree::ptree::value_type &v, + tree.get_child("chats.")) { + auto widget = new ChatWidget(); + widget->load(v.second); + this->addToLayout(widget, std::pair(-1, -1)); + } + } catch (boost::property_tree::ptree_error &) { + // can't read tabs + } +} - qDebug() << "tab name :" << tabName.c_str(); +boost::property_tree::ptree +NotebookPage::save() +{ + boost::property_tree::ptree tree; + + for (const auto &chat : this->chatWidgets) { + boost::property_tree::ptree child = chat->save(); + tree.push_back(std::make_pair("", child)); + } + + return tree; } } // namespace widgets diff --git a/widgets/notebookpage.h b/widgets/notebookpage.h index 926635233..c7e7f35f5 100644 --- a/widgets/notebookpage.h +++ b/widgets/notebookpage.h @@ -73,7 +73,8 @@ private: void setPreviewRect(QPoint mousePos); public: - void load(const boost::property_tree::ptree &v); + void load(const boost::property_tree::ptree &tree); + boost::property_tree::ptree save(); }; } // namespace widgets