mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Save chats and tabs in new settings system
This commit is contained in:
parent
42749538a7
commit
d8c01ce374
14 changed files with 187 additions and 293 deletions
|
@ -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
|
||||
|
|
|
@ -25,6 +25,9 @@ public:
|
|||
Resources resources;
|
||||
ChannelManager channelManager;
|
||||
IrcManager ircManager;
|
||||
|
||||
private:
|
||||
void save();
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -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<int>((fontMetrics().width(title) + 16) * scale),
|
||||
this->resize(static_cast<int>((fontMetrics().width(qTitle) + 16) * scale),
|
||||
static_cast<int>(24 * scale));
|
||||
} else {
|
||||
this->resize(static_cast<int>((fontMetrics().width(title) + 8 + 24) * scale),
|
||||
this->resize(static_cast<int>((fontMetrics().width(qTitle) + 8 + 24) * scale),
|
||||
static_cast<int>(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<int>(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<std::string>("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
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <QMenu>
|
||||
#include <QPropertyAnimation>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <pajlada/settings/setting.hpp>
|
||||
#include <pajlada/signals/connection.hpp>
|
||||
|
||||
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<std::string> title;
|
||||
|
||||
public:
|
||||
bool useDefaultBehaviour = true;
|
||||
pajlada::Settings::Setting<bool> useDefaultBehaviour;
|
||||
|
||||
private:
|
||||
bool selected = false;
|
||||
|
@ -85,10 +87,6 @@ private:
|
|||
return QRect(this->width() - static_cast<int>(20 * scale), static_cast<int>(4 * scale),
|
||||
static_cast<int>(16 * scale), static_cast<int>(16 * scale));
|
||||
}
|
||||
|
||||
public:
|
||||
void load(const boost::property_tree::ptree &tree);
|
||||
boost::property_tree::ptree save();
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
|
|
|
@ -15,14 +15,17 @@
|
|||
#include <QList>
|
||||
#include <QShortcut>
|
||||
#include <QStandardPaths>
|
||||
#include <QUuid>
|
||||
#include <QWidget>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
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<bool>("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
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include <QList>
|
||||
#include <QWidget>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
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
|
||||
|
|
|
@ -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<Channel> 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<std::string>("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<SplitContainer *>(window.getNotebook().getSelectedPage()));
|
||||
split->channelName = this->channelName.getValue();
|
||||
static_cast<SplitContainer *>(window.getNotebook().getSelectedPage()),
|
||||
this->uuid);
|
||||
|
||||
window.getNotebook().getSelectedPage()->addToLayout(split);
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include <QShortcut>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/signals2/connection.hpp>
|
||||
|
||||
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<std::string> channelName;
|
||||
boost::signals2::signal<void()> channelChanged;
|
||||
|
||||
const std::string &getUUID() const;
|
||||
std::shared_ptr<Channel> getChannel() const;
|
||||
std::shared_ptr<Channel> &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;
|
||||
|
|
|
@ -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<int, int> SplitContainer::dropPosition = std::pair<int, int>(-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<int, int> 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<int, int> 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<int, int>(column, row));
|
||||
++row;
|
||||
}
|
||||
++column;
|
||||
const auto hboxes = this->chats.getValue();
|
||||
int column = 0;
|
||||
for (const std::vector<std::string> &hbox : hboxes) {
|
||||
int row = 0;
|
||||
for (const std::string &chatUUID : hbox) {
|
||||
Split *split = this->createChatWidget(chatUUID);
|
||||
|
||||
this->addToLayout(split, std::pair<int, int>(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 <typename Container>
|
||||
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<std::string> 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<Split *>(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<Split *>(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<std::vector<std::string>> _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<std::string> 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<Split *>(innerWidget);
|
||||
vbox.push_back(innerSplit->getUUID());
|
||||
}
|
||||
|
||||
_chats.push_back(vbox);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return tree;
|
||||
this->chats = _chats;
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <QVector>
|
||||
#include <QWidget>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/signals2.hpp>
|
||||
|
||||
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<Split *> &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<Split *> chatWidgets;
|
||||
std::vector<DropRegion> dropRegions;
|
||||
|
||||
pajlada::Settings::Setting<std::vector<std::vector<std::string>>> chats;
|
||||
|
||||
NotebookPageDropPreview dropPreview;
|
||||
|
||||
void setPreviewRect(QPoint mousePos);
|
||||
|
||||
std::pair<int, int> 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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
//#include <platform/borderless/qwinwidget.h>
|
||||
//#endif
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/signals2.hpp>
|
||||
#include <pajlada/settings/setting.hpp>
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <QDebug>
|
||||
#include <QStandardPaths>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
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<std::string>("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
|
||||
|
|
|
@ -31,7 +31,6 @@ public:
|
|||
int windowCount();
|
||||
widgets::Window *windowAt(int index);
|
||||
|
||||
void load();
|
||||
void save();
|
||||
|
||||
boost::signals2::signal<void()> repaintGifs;
|
||||
|
|
Loading…
Reference in a new issue