Merge branch 'master' into unread

This commit is contained in:
ouwou
2022-01-02 00:07:32 -05:00
4 changed files with 44 additions and 20 deletions

View File

@@ -388,7 +388,11 @@ void Abaddon::SaveState() {
}
void Abaddon::LoadState() {
if (!GetSettings().SaveState) return;
if (!GetSettings().SaveState) {
// call with empty data to purge the temporary table
m_main_window->GetChannelList()->UseExpansionState({});
return;
}
const auto data = ReadWholeFile(GetStateCachePath("/state.json"));
if (data.empty()) return;

View File

@@ -278,7 +278,6 @@ void ChannelList::UpdateChannel(Snowflake id) {
}
void ChannelList::UpdateCreateChannel(const ChannelData &channel) {
;
if (channel.Type == ChannelType::GUILD_CATEGORY) return (void)UpdateCreateChannelCategory(channel);
if (channel.Type == ChannelType::DM || channel.Type == ChannelType::GROUP_DM) return UpdateCreateDMChannel(channel);
if (channel.Type != ChannelType::GUILD_TEXT && channel.Type != ChannelType::GUILD_NEWS) return;
@@ -451,11 +450,11 @@ void ChannelList::UseExpansionState(const ExpansionStateRoot &root) {
auto recurse = [this](auto &self, const ExpansionStateRoot &root) -> void {
// and these are only channels
for (const auto &[id, state] : root.Children) {
if (const auto iter = GetIteratorForChannelFromID(id)) {
if (const auto iter = m_tmp_channel_map.find(id); iter != m_tmp_channel_map.end()) {
if (state.IsExpanded)
m_view.expand_row(m_model->get_path(iter), false);
m_view.expand_row(m_model->get_path(iter->second), false);
else
m_view.collapse_row(m_model->get_path(iter));
m_view.collapse_row(m_model->get_path(iter->second));
}
self(self, state.Children);
@@ -473,6 +472,8 @@ void ChannelList::UseExpansionState(const ExpansionStateRoot &root) {
recurse(recurse, state.Children);
}
m_tmp_channel_map.clear();
}
ExpansionStateRoot ChannelList::GetExpansionState() const {
@@ -553,7 +554,7 @@ Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) {
if (it == threads.end()) return;
for (const auto &thread : it->second)
CreateThreadRow(row.children(), thread);
m_tmp_channel_map[thread.ID] = CreateThreadRow(row.children(), thread);
};
for (const auto &channel : orphan_channels) {
@@ -564,6 +565,7 @@ Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) {
channel_row[m_columns.m_sort] = *channel.Position + OrphanChannelSortOffset;
channel_row[m_columns.m_nsfw] = channel.NSFW();
add_threads(channel, channel_row);
m_tmp_channel_map[channel.ID] = channel_row;
}
for (const auto &[category_id, channels] : categories) {
@@ -575,6 +577,7 @@ Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) {
cat_row[m_columns.m_name] = Glib::Markup::escape_text(*category->Name);
cat_row[m_columns.m_sort] = *category->Position;
cat_row[m_columns.m_expanded] = true;
m_tmp_channel_map[category_id] = cat_row;
// m_view.expand_row wont work because it might not have channels
for (const auto &channel : channels) {
@@ -585,6 +588,7 @@ Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) {
channel_row[m_columns.m_sort] = *channel.Position;
channel_row[m_columns.m_nsfw] = channel.NSFW();
add_threads(channel, channel_row);
m_tmp_channel_map[channel.ID] = channel_row;
}
}

View File

@@ -138,6 +138,10 @@ protected:
Snowflake m_active_channel;
// (GetIteratorForChannelFromID is rather slow)
// only temporary since i dont want to worry about maintaining this map
std::unordered_map<Snowflake, Gtk::TreeModel::iterator> m_tmp_channel_map;
public:
typedef sigc::signal<void, Snowflake> type_signal_action_channel_item_select;
typedef sigc::signal<void, Snowflake> type_signal_action_guild_leave;

View File

@@ -1,18 +1,18 @@
#include "platform.hpp"
#include "util.hpp"
#include <string>
#include <fstream>
#include <filesystem>
#include <config.h>
#include <filesystem>
#include <fstream>
#include <string>
using namespace std::literals::string_literals;
#if defined(_WIN32) && defined(_MSC_VER)
#include <Windows.h>
#include <Shlwapi.h>
#include <ShlObj_core.h>
#include <pango/pangocairo.h>
#include <pango/pangofc-fontmap.h>
#include <ShlObj_core.h>
#include <Shlwapi.h>
#include <Windows.h>
#pragma comment(lib, "Shlwapi.lib")
bool Platform::SetupFonts() {
using namespace std::string_literals;
@@ -107,17 +107,29 @@ std::string Platform::FindResourceFolder() {
}
std::string Platform::FindConfigFile() {
const auto x = std::getenv("ABADDON_CONFIG");
if (x != nullptr)
return x;
const auto cfg = std::getenv("ABADDON_CONFIG");
if (cfg != nullptr) return cfg;
const auto home_env = std::getenv("HOME");
if (home_env != nullptr) {
const auto home_path = home_env + "/.config/abaddon/abaddon.ini"s;
for (auto path : { "./abaddon.ini"s, home_path }) {
if (util::IsFile(path)) return path;
// use config present in cwd first
if (util::IsFile("./abaddon.ini"))
return "./abaddon.ini";
if (const auto home_env = std::getenv("HOME")) {
// use ~/.config if present
if (auto home_path = home_env + "/.config/abaddon/abaddon.ini"s; util::IsFile(home_path)) {
return home_path;
}
// fallback to ~/.config if the directory exists/can be created
std::error_code ec;
const auto home_path = home_env + "/.config/abaddon"s;
if (!util::IsFolder(home_path))
std::filesystem::create_directories(home_path, ec);
if (util::IsFolder(home_path))
return home_path + "/abaddon.ini";
}
// fallback to cwd if cant find + cant make in ~/.config
puts("can't find configuration file!");
return "./abaddon.ini";
}