Tabs are now loaded and saved (no chats yet)

This commit is contained in:
Rasmus Karlsson
2017-01-28 22:35:23 +01:00
parent 6fb4305162
commit 1c076b803e
11 changed files with 236 additions and 18 deletions
+31
View File
@@ -3,7 +3,9 @@
#include "widgets/chatwidget.h"
#include "widgets/notebook.h"
#include <QDebug>
#include <QPalette>
#include <boost/foreach.hpp>
namespace chatterino {
namespace widgets {
@@ -68,5 +70,34 @@ MainWindow::repaintVisibleChatWidgets(Channel *channel)
}
}
}
void
MainWindow::load(const boost::property_tree::ptree &tree)
{
this->notebook.load(tree);
this->loaded = true;
}
boost::property_tree::ptree
MainWindow::save()
{
boost::property_tree::ptree child;
child.put("type", "main");
this->notebook.save(child);
return child;
}
void
MainWindow::loadDefaults()
{
this->notebook.loadDefaults();
this->loaded = true;
}
} // namespace widgets
} // namespace chatterino
+17 -2
View File
@@ -4,6 +4,7 @@
#include "widgets/notebook.h"
#include <QMainWindow>
#include <boost/property_tree/ptree.hpp>
namespace chatterino {
namespace widgets {
@@ -19,8 +20,22 @@ public:
void layoutVisibleChatWidgets(Channel *channel = NULL);
void repaintVisibleChatWidgets(Channel *channel = NULL);
void load(const boost::property_tree::ptree &tree);
boost::property_tree::ptree save();
void loadDefaults();
bool
isLoaded() const
{
return this->loaded;
}
private:
bool loaded = false;
};
}
}
} // namespace widgets
} // namespace chatterino
#endif // MAINWINDOW_H
+49 -2
View File
@@ -5,10 +5,14 @@
#include "widgets/notebooktab.h"
#include "widgets/settingsdialog.h"
#include <QDebug>
#include <QFile>
#include <QFormLayout>
#include <QLayout>
#include <QList>
#include <QStandardPaths>
#include <QWidget>
#include <boost/foreach.hpp>
namespace chatterino {
namespace widgets {
@@ -35,8 +39,6 @@ Notebook::Notebook(QWidget *parent)
this->userButton.icon = NotebookButton::IconUser;
this->addButton.resize(24, 24);
this->addPage();
}
NotebookPage *
@@ -191,5 +193,50 @@ Notebook::addPageButtonClicked()
{
addPage(true);
}
void
Notebook::load(const boost::property_tree::ptree &tree)
{
// 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<bool>("selected", false);
auto page = this->addPage(select);
auto tab = page->tab;
tab->load(v.second);
page->load(v.second);
}
} catch (boost::property_tree::ptree_error &) {
// can't read tabs
}
if (this->pages.size() == 0) {
// No pages saved, show default stuff
this->loadDefaults();
}
}
void
Notebook::save(boost::property_tree::ptree &tree)
{
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->tab->save();
tabs.push_back(std::make_pair("", pTab));
}
tree.add_child("tabs", tabs);
}
void
Notebook::loadDefaults()
{
this->addPage();
}
} // namespace widgets
} // namespace chatterino
+9 -2
View File
@@ -7,6 +7,7 @@
#include <QList>
#include <QWidget>
#include <boost/property_tree/ptree.hpp>
namespace chatterino {
namespace widgets {
@@ -54,8 +55,14 @@ private:
NotebookButton userButton;
NotebookPage *selectedPage;
public:
void load(const boost::property_tree::ptree &tree);
void save(boost::property_tree::ptree &tree);
void loadDefaults();
};
}
}
} // namespace widgets
} // namespace chatterino
#endif // NOTEBOOK_H
+14 -4
View File
@@ -3,11 +3,13 @@
#include "widgets/chatwidget.h"
#include "widgets/notebooktab.h"
#include <QDebug>
#include <QHBoxLayout>
#include <QMimeData>
#include <QPainter>
#include <QVBoxLayout>
#include <QWidget>
#include <boost/foreach.hpp>
namespace chatterino {
namespace widgets {
@@ -73,9 +75,8 @@ NotebookPage::removeFromLayout(ChatWidget *widget)
}
void
NotebookPage::addToLayout(
ChatWidget *widget,
std::pair<int, int> position = std::pair<int, int>(-1, -1))
NotebookPage::addToLayout(ChatWidget *widget, std::pair<int, int> position =
std::pair<int, int>(-1, -1))
{
this->chatWidgets.push_back(widget);
@@ -239,5 +240,14 @@ NotebookPage::paintEvent(QPaintEvent *)
ColorScheme::getInstance().TabSelectedBackground);
}
}
void
NotebookPage::load(const boost::property_tree::ptree &v)
{
const std::string &tabName = v.get<std::string>("name", "UNNAMED");
qDebug() << "tab name :" << tabName.c_str();
}
}
} // namespace widgets
} // namespace chatterino
+7 -2
View File
@@ -12,6 +12,7 @@
#include <QVBoxLayout>
#include <QVector>
#include <QWidget>
#include <boost/property_tree/ptree.hpp>
namespace chatterino {
namespace widgets {
@@ -70,8 +71,12 @@ protected:
private:
void setPreviewRect(QPoint mousePos);
public:
void load(const boost::property_tree::ptree &v);
};
}
}
} // namespace widgets
} // namespace chatterino
#endif // NOTEBOOKPAGE_H
+21
View File
@@ -203,5 +203,26 @@ NotebookTab::mouseMoveEvent(QMouseEvent *event)
}
}
}
void
NotebookTab::load(const boost::property_tree::ptree &tree)
{
// Load tab text
try {
this->setText(QString::fromStdString(tree.get<std::string>("text")));
} catch (boost::property_tree::ptree_error) {
}
}
boost::property_tree::ptree
NotebookTab::save()
{
boost::property_tree::ptree tree;
tree.put("text", this->getText().toStdString());
return tree;
}
} // namespace widgets
} // namespace chatterino
+8 -2
View File
@@ -3,6 +3,7 @@
#include <QPropertyAnimation>
#include <QWidget>
#include <boost/property_tree/ptree.hpp>
namespace chatterino {
namespace widgets {
@@ -117,8 +118,13 @@ private slots:
calcSize();
update();
}
public:
void load(const boost::property_tree::ptree &tree);
boost::property_tree::ptree save();
};
}
}
} // namespace widgets
} // namespace chatterino
#endif // NOTEBOOKTAB_H