mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
we now load and save chats as well
This commit is contained in:
parent
1c076b803e
commit
c0b4035e6a
5 changed files with 64 additions and 7 deletions
|
@ -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<std::string>("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
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <QFont>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -124,7 +124,8 @@ void
|
|||
NotebookPage::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (this->hbox.count() == 0 && event->button() == Qt::LeftButton) {
|
||||
addToLayout(new ChatWidget(), std::pair<int, int>(-1, -1));
|
||||
// "Add Chat" was clicked
|
||||
this->addToLayout(new ChatWidget(), std::pair<int, int>(-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<std::string>("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<int, int>(-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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue