Merge branch 'master' of https://github.com/uowuo/abaddon into msys

This commit is contained in:
ouwou 2021-11-18 01:03:35 -05:00
commit 9c285a09e5
24 changed files with 68 additions and 77 deletions

View File

@ -23,8 +23,8 @@
Abaddon::Abaddon()
: m_settings(Platform::FindConfigFile())
, m_emojis(GetResPath("/emojis.bin"))
, m_discord(m_settings.GetUseMemoryDB()) { // stupid but easy
, m_discord(m_settings.GetUseMemoryDB()) // stupid but easy
, m_emojis(GetResPath("/emojis.bin")) {
LoadFromSettings();
// todo: set user agent for non-client(?)
@ -56,7 +56,6 @@ Abaddon::Abaddon()
Abaddon::~Abaddon() {
m_settings.Close();
StopDiscord();
}
Abaddon &Abaddon::Get() {
@ -268,7 +267,7 @@ void Abaddon::ShowUserMenu(const GdkEvent *event, Snowflake id, Snowflake guild_
if (guild.has_value() && user.has_value()) {
const auto roles = user->GetSortedRoles();
m_user_menu_roles->set_visible(roles.size() > 0);
for (const auto role : roles) {
for (const auto &role : roles) {
auto *item = Gtk::manage(new Gtk::MenuItem(role.Name));
if (role.Color != 0) {
Gdk::RGBA color;

View File

@ -61,7 +61,6 @@ void CellRendererPixbufAnimation::render_vfunc(const Cairo::RefPtr<Cairo::Contex
Gtk::CellRendererState flags) {
Gtk::Requisition minimum, natural;
get_preferred_size(widget, minimum, natural);
auto alloc = widget.get_allocation();
int xpad, ypad;
get_padding(xpad, ypad);
int pix_x = cell_area.get_x() + xpad;

View File

@ -16,8 +16,8 @@ ChannelList::ChannelList()
, m_menu_guild_leave("_Leave", true)
, m_menu_category_copy_id("_Copy ID", true)
, m_menu_channel_copy_id("_Copy ID", true)
, m_menu_dm_close("") // changes depending on if group or not
, m_menu_dm_copy_id("_Copy ID", true)
, m_menu_dm_close("") // changes depending on if group or not
, m_menu_thread_copy_id("_Copy ID", true)
, m_menu_thread_leave("_Leave", true)
, m_menu_thread_archive("_Archive", true)
@ -167,7 +167,6 @@ void ChannelList::UpdateListing() {
m_model->clear();
auto &discord = Abaddon::Get().GetDiscordClient();
auto &img = Abaddon::Get().GetImageManager();
const auto guild_ids = discord.GetUserSortedGuilds();
int sortnum = 0;
@ -185,10 +184,7 @@ void ChannelList::UpdateListing() {
}
void ChannelList::UpdateNewGuild(const GuildData &guild) {
auto &img = Abaddon::Get().GetImageManager();
auto iter = AddGuild(guild);
AddGuild(guild);
// update sort order
int sortnum = 0;
for (const auto guild_id : Abaddon::Get().GetDiscordClient().GetUserSortedGuilds()) {
@ -561,7 +557,7 @@ void ChannelList::UpdateChannelCategory(const ChannelData &channel) {
}
Gtk::TreeModel::iterator ChannelList::GetIteratorForGuildFromID(Snowflake id) {
for (const auto child : m_model->children()) {
for (const auto &child : m_model->children()) {
if (child[m_columns.m_id] == id)
return child;
}
@ -570,14 +566,14 @@ Gtk::TreeModel::iterator ChannelList::GetIteratorForGuildFromID(Snowflake id) {
Gtk::TreeModel::iterator ChannelList::GetIteratorForChannelFromID(Snowflake id) {
std::queue<Gtk::TreeModel::iterator> queue;
for (const auto child : m_model->children())
for (const auto child2 : child.children())
for (const auto &child : m_model->children())
for (const auto &child2 : child.children())
queue.push(child2);
while (!queue.empty()) {
auto item = queue.front();
if ((*item)[m_columns.m_id] == id) return item;
for (const auto child : item->children())
for (const auto &child : item->children())
queue.push(child);
queue.pop();
}
@ -1052,9 +1048,6 @@ void CellRendererChannels::get_preferred_height_for_width_vfunc_category(Gtk::Wi
}
void CellRendererChannels::render_vfunc_category(const Cairo::RefPtr<Cairo::Context> &cr, Gtk::Widget &widget, const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area, Gtk::CellRendererState flags) {
int available_xpad = background_area.get_width();
int available_ypad = background_area.get_height();
// todo: figure out how Gtk::Arrow is rendered because i like it better :^)
constexpr static int len = 5;
int x1, y1, x2, y2, x3, y3;

View File

@ -112,7 +112,7 @@ void ChatInputIndicator::ComputeTypingString() {
SetTypingString(typers[0].Username + " and " + typers[1].Username + " are typing...");
} else if (typers.size() > 2 && typers.size() <= MaxUsersInIndicator) {
Glib::ustring str;
for (int i = 0; i < typers.size() - 1; i++)
for (size_t i = 0; i < typers.size() - 1; i++)
str += typers[i].Username + ", ";
SetTypingString(str + "and " + typers[typers.size() - 1].Username + " are typing...");
} else { // size() > MaxUsersInIndicator

View File

@ -308,8 +308,6 @@ Gtk::Widget *ChatMessageItemContainer::CreateEmbedComponent(const EmbedData &emb
constexpr static int AuthorIconSize = 20;
if (embed.Author->ProxyIconURL.has_value()) {
auto &img = Abaddon::Get().GetImageManager();
auto *author_img = Gtk::manage(new LazyImage(*embed.Author->ProxyIconURL, AuthorIconSize, AuthorIconSize));
author_img->set_halign(Gtk::ALIGN_START);
author_img->set_valign(Gtk::ALIGN_START);

View File

@ -47,7 +47,7 @@ bool Completer::ProcessKeyPress(GdkEventKey *e) {
switch (e->keyval) {
case GDK_KEY_Down: {
if (m_entries.size() == 0) return true;
const int index = m_list.get_selected_row()->get_index();
const auto index = static_cast<size_t>(m_list.get_selected_row()->get_index());
if (index >= m_entries.size() - 1) return true;
m_list.select_row(*m_entries[index + 1]);
ScrollListBoxToSelected(m_list);
@ -55,7 +55,7 @@ bool Completer::ProcessKeyPress(GdkEventKey *e) {
return true;
case GDK_KEY_Up: {
if (m_entries.size() == 0) return true;
const int index = m_list.get_selected_row()->get_index();
const auto index = static_cast<size_t>(m_list.get_selected_row()->get_index());
if (index == 0) return true;
m_list.select_row(*m_entries[index - 1]);
ScrollListBoxToSelected(m_list);
@ -169,7 +169,7 @@ void Completer::CompleteEmojis(const Glib::ustring &term) {
const auto guild = discord.GetGuild(*channel->GuildID);
if (guild.has_value() && guild->Emojis.has_value())
for (const auto tmp : *guild->Emojis) {
for (const auto &tmp : *guild->Emojis) {
const auto emoji = *discord.GetEmoji(tmp.ID);
if (emoji.IsAnimated.has_value() && *emoji.IsAnimated) continue;
if (emoji.IsAvailable.has_value() && !*emoji.IsAvailable) continue;
@ -186,7 +186,7 @@ void Completer::CompleteEmojis(const Glib::ustring &term) {
for (const auto guild_id : discord.GetGuilds()) {
const auto guild = discord.GetGuild(guild_id);
if (!guild.has_value()) continue;
for (const auto tmp : *guild->Emojis) {
for (const auto &tmp : *guild->Emojis) {
const auto emoji = *discord.GetEmoji(tmp.ID);
const bool is_animated = emoji.IsAnimated.has_value() && *emoji.IsAnimated;
if (emoji.IsAvailable.has_value() && !*emoji.IsAvailable) continue;
@ -330,8 +330,8 @@ Glib::ustring Completer::GetTerm() {
}
CompleterEntry::CompleterEntry(const Glib::ustring &completion, int index)
: m_index(index)
, m_completion(completion)
: m_completion(completion)
, m_index(index)
, m_box(Gtk::ORIENTATION_HORIZONTAL) {
set_halign(Gtk::ALIGN_START);
get_style_context()->add_class("completer-entry");

View File

@ -185,9 +185,9 @@ bool FriendsList::ListFilterFunc(Gtk::ListBoxRow *row_) {
FriendsListAddComponent::FriendsListAddComponent()
: Gtk::Box(Gtk::ORIENTATION_VERTICAL)
, m_label("Add a Friend", Gtk::ALIGN_START)
, m_box(Gtk::ORIENTATION_HORIZONTAL)
, m_status("", Gtk::ALIGN_START)
, m_add("Add")
, m_status("", Gtk::ALIGN_START) {
, m_box(Gtk::ORIENTATION_HORIZONTAL) {
m_box.add(m_entry);
m_box.add(m_add);
m_box.add(m_status);
@ -241,9 +241,9 @@ bool FriendsListAddComponent::OnKeyPress(GdkEventKey *e) {
}
FriendsListFriendRow::FriendsListFriendRow(RelationshipType type, const UserData &data)
: Name(data.Username + "#" + data.Discriminator)
: ID(data.ID)
, Type(type)
, ID(data.ID)
, Name(data.Username + "#" + data.Discriminator)
, Status(Abaddon::Get().GetDiscordClient().GetUserStatus(data.ID))
, m_accept("Accept") {
auto *ev = Gtk::manage(new Gtk::EventBox);

View File

@ -3,9 +3,9 @@
ConfirmDialog::ConfirmDialog(Gtk::Window &parent)
: Gtk::Dialog("Confirm", parent, true)
, m_layout(Gtk::ORIENTATION_VERTICAL)
, m_bbox(Gtk::ORIENTATION_HORIZONTAL)
, m_ok("OK")
, m_cancel("Cancel") {
, m_cancel("Cancel")
, m_bbox(Gtk::ORIENTATION_HORIZONTAL) {
set_default_size(300, 50);
get_style_context()->add_class("app-window");
get_style_context()->add_class("app-popup");

View File

@ -3,9 +3,9 @@
EditMessageDialog::EditMessageDialog(Gtk::Window &parent)
: Gtk::Dialog("Edit Message", parent, true)
, m_layout(Gtk::ORIENTATION_VERTICAL)
, m_bbox(Gtk::ORIENTATION_HORIZONTAL)
, m_ok("OK")
, m_cancel("Cancel") {
, m_cancel("Cancel")
, m_bbox(Gtk::ORIENTATION_HORIZONTAL) {
set_default_size(300, 50);
get_style_context()->add_class("app-window");
get_style_context()->add_class("app-popup");

View File

@ -3,10 +3,10 @@
SetStatusDialog::SetStatusDialog(Gtk::Window &parent)
: Gtk::Dialog("Set Status", parent, true)
, m_layout(Gtk::ORIENTATION_VERTICAL)
, m_bbox(Gtk::ORIENTATION_HORIZONTAL)
, m_bottom(Gtk::ORIENTATION_HORIZONTAL)
, m_ok("OK")
, m_cancel("Cancel") {
, m_cancel("Cancel")
, m_bbox(Gtk::ORIENTATION_HORIZONTAL) {
set_default_size(300, 50);
get_style_context()->add_class("app-window");
get_style_context()->add_class("app-popup");

View File

@ -10,9 +10,9 @@ std::string trim(const std::string& str) {
TokenDialog::TokenDialog(Gtk::Window &parent)
: Gtk::Dialog("Set Token", parent, true)
, m_layout(Gtk::ORIENTATION_VERTICAL)
, m_bbox(Gtk::ORIENTATION_HORIZONTAL)
, m_ok("OK")
, m_cancel("Cancel") {
, m_cancel("Cancel")
, m_bbox(Gtk::ORIENTATION_HORIZONTAL) {
set_default_size(300, 50);
get_style_context()->add_class("app-window");
get_style_context()->add_class("app-popup");

View File

@ -1,5 +1,6 @@
#include "discord.hpp"
#include <cassert>
#include <cinttypes>
#include "../util.hpp"
#include "../abaddon.hpp"
@ -707,19 +708,20 @@ void DiscordClient::ModifyRoleColor(Snowflake guild_id, Snowflake role_id, Gdk::
void DiscordClient::ModifyRolePosition(Snowflake guild_id, Snowflake role_id, int position, sigc::slot<void(DiscordError code)> callback) {
const auto roles = GetGuild(guild_id)->FetchRoles();
if (position > roles.size()) return;
if (static_cast<size_t>(position) > roles.size()) return;
// gay and makes you send every role in between new and old position
size_t index_from = -1, index_to = -1;
constexpr auto IDX_MAX = ~size_t { 0 };
size_t index_from = IDX_MAX, index_to = IDX_MAX;
for (size_t i = 0; i < roles.size(); i++) {
const auto &role = roles[i];
if (role.ID == role_id)
index_from = i;
else if (role.Position == position)
index_to = i;
if (index_from != -1 && index_to != -1) break;
if (index_from != IDX_MAX && index_to != IDX_MAX) break;
}
if (index_from == -1 || index_to == -1) return;
if (index_from == IDX_MAX || index_to == IDX_MAX) return;
int dir;
size_t range_from, range_to;
@ -1276,11 +1278,11 @@ void DiscordClient::HandleGatewayMessage(std::string str) {
}
} break;
default:
printf("Unknown opcode %d\n", m.Opcode);
printf("Unknown opcode %d\n", static_cast<int>(m.Opcode));
break;
}
} catch (std::exception &e) {
fprintf(stderr, "error handling message (opcode %d): %s\n", m.Opcode, e.what());
fprintf(stderr, "error handling message (opcode %d): %s\n", static_cast<int>(m.Opcode), e.what());
}
}
@ -1320,7 +1322,7 @@ DiscordError DiscordClient::GetCodeFromResponse(const http::response_type &respo
void DiscordClient::ProcessNewGuild(GuildData &guild) {
if (guild.IsUnavailable) {
printf("guild (%lld) unavailable\n", static_cast<uint64_t>(guild.ID));
printf("guild (%" PRIu64 ") unavailable\n", static_cast<uint64_t>(guild.ID));
return;
}
@ -1375,7 +1377,7 @@ void DiscordClient::HandleGatewayReady(const GatewayMessage &msg) {
m_store.SetUser(user.ID, user);
if (data.MergedMembers.has_value()) {
for (int i = 0; i < data.MergedMembers->size(); i++) {
for (size_t i = 0; i < data.MergedMembers->size(); i++) {
const auto guild_id = data.Guilds[i].ID;
for (const auto &member : data.MergedMembers.value()[i]) {
m_store.SetGuildMember(guild_id, *member.UserID, member);
@ -1762,6 +1764,9 @@ void DiscordClient::HandleGatewayThreadCreate(const GatewayMessage &msg) {
ThreadCreateData data = msg.Data;
m_store.SetChannel(data.Channel.ID, data.Channel);
m_signal_thread_create.emit(data.Channel);
if (data.Channel.ThreadMember.has_value()) {
m_signal_added_to_thread.emit(data.Channel.ID);
}
}
void DiscordClient::HandleGatewayThreadDelete(const GatewayMessage &msg) {
@ -1975,7 +1980,7 @@ void DiscordClient::HandleGatewayGuildDelete(const GatewayMessage &msg) {
bool unavailable = msg.Data.contains("unavilable") && msg.Data.at("unavailable").get<bool>();
if (unavailable)
printf("guild %llu became unavailable\n", static_cast<uint64_t>(id));
printf("guild %" PRIu64 " became unavailable\n", static_cast<uint64_t>(id));
const auto guild = m_store.GetGuild(id);
if (!guild.has_value()) {

View File

@ -191,7 +191,8 @@ std::vector<Snowflake> GuildData::GetSortedChannels(Snowflake ignore) const {
std::vector<RoleData> GuildData::FetchRoles() const {
if (!Roles.has_value()) return {};
std::vector<RoleData> ret;
for (const auto thing : *Roles)
ret.reserve(Roles->size());
for (const auto &thing : *Roles)
ret.push_back(*Abaddon::Get().GetDiscordClient().GetRole(thing.ID));
std::sort(ret.begin(), ret.end(), [](const RoleData &a, const RoleData &b) -> bool {
return a.Position > b.Position;

View File

@ -142,7 +142,7 @@ void FileCacheWorkerThread::loop() {
m_cv.wait(lock);
}
static const auto concurrency = Abaddon::Get().GetSettings().GetCacheHTTPConcurrency();
static const auto concurrency = static_cast<size_t>(Abaddon::Get().GetSettings().GetCacheHTTPConcurrency());
if (m_handles.size() < concurrency) {
std::optional<QueueEntry> entry;
m_queue_mutex.lock();

View File

@ -7,9 +7,9 @@
GuildSettingsBansPane::GuildSettingsBansPane(Snowflake id)
: Gtk::Box(Gtk::ORIENTATION_VERTICAL)
, GuildID(id)
, m_model(Gtk::ListStore::create(m_columns))
, m_menu_unban("Unban")
, m_menu_copy_id("Copy ID")
, m_model(Gtk::ListStore::create(m_columns)) {
, m_menu_copy_id("Copy ID") {
signal_map().connect(sigc::mem_fun(*this, &GuildSettingsBansPane::OnMap));
set_name("guild-bans-pane");
set_hexpand(true);

View File

@ -7,8 +7,8 @@ GuildSettingsEmojisPane::GuildSettingsEmojisPane(Snowflake guild_id)
, GuildID(guild_id)
, m_model(Gtk::ListStore::create(m_columns))
, m_filter(Gtk::TreeModelFilter::create(m_model))
, m_menu_copy_id("Copy ID")
, m_menu_delete("Delete")
, m_menu_copy_id("Copy ID")
, m_menu_copy_emoji_url("Copy Emoji URL")
, m_menu_show_emoji("Open in Browser") {
signal_map().connect(sigc::mem_fun(*this, &GuildSettingsEmojisPane::OnMap));
@ -31,7 +31,6 @@ GuildSettingsEmojisPane::GuildSettingsEmojisPane(Snowflake guild_id)
m_menu.show_all();
auto &discord = Abaddon::Get().GetDiscordClient();
auto &img = Abaddon::Get().GetImageManager();
discord.signal_guild_emojis_update().connect(sigc::hide<0>(sigc::mem_fun(*this, &GuildSettingsEmojisPane::OnFetchEmojis)));

View File

@ -3,9 +3,9 @@
#include <filesystem>
GuildSettingsInfoPane::GuildSettingsInfoPane(Snowflake id)
: GuildID(id)
: m_guild_icon_label("Guild icon")
, m_guild_name_label("Guild name")
, m_guild_icon_label("Guild icon") {
, GuildID(id) {
auto &discord = Abaddon::Get().GetDiscordClient();
const auto guild = *discord.GetGuild(id);
const auto self_id = discord.GetUserData().ID;

View File

@ -49,7 +49,6 @@ void GuildSettingsInvitesPane::OnMap() {
}
void GuildSettingsInvitesPane::AppendInvite(const InviteData &invite) {
auto &discord = Abaddon::Get().GetDiscordClient();
auto row = *m_model->append();
row[m_columns.m_col_code] = invite.Code;
if (invite.Inviter.has_value())
@ -77,7 +76,6 @@ void GuildSettingsInvitesPane::OnInviteFetch(const std::optional<InviteData> &in
}
void GuildSettingsInvitesPane::OnInvitesFetch(const std::vector<InviteData> &invites) {
auto &discord = Abaddon::Get().GetDiscordClient();
for (const auto &invite : invites)
AppendInvite(invite);
}

View File

@ -3,10 +3,10 @@
GuildSettingsMembersPane::GuildSettingsMembersPane(Snowflake id)
: Gtk::Box(Gtk::ORIENTATION_VERTICAL)
, GuildID(id)
, m_layout(Gtk::ORIENTATION_HORIZONTAL)
, m_member_list(id)
, m_member_info(id)
, GuildID(id) {
, m_member_info(id) {
set_name("guild-members-pane");
set_hexpand(true);
set_vexpand(true);
@ -158,9 +158,9 @@ void GuildSettingsMembersListItem::UpdateColor() {
}
GuildSettingsMembersPaneInfo::GuildSettingsMembersPaneInfo(Snowflake guild_id)
: m_box(Gtk::ORIENTATION_VERTICAL)
, GuildID(guild_id)
, m_roles(guild_id) {
: GuildID(guild_id)
, m_roles(guild_id)
, m_box(Gtk::ORIENTATION_VERTICAL) {
get_style_context()->add_class("guild-members-pane-info");
const auto label = [](Gtk::Label &lbl) {

View File

@ -57,8 +57,8 @@ GuildSettingsRolesPaneRoles::GuildSettingsRolesPaneRoles(Snowflake guild_id)
auto &discord = Abaddon::Get().GetDiscordClient();
const auto num_rows = m_list.get_children().size();
const auto new_pos = num_rows - new_index - 1;
if (row->RoleID == GuildID) return true; // moving role @everyone
if (new_index == num_rows) return true; // trying to move row below @everyone
if (row->RoleID == GuildID) return true; // moving role @everyone
if (static_cast<size_t>(new_index) == num_rows) return true; // trying to move row below @everyone
// make sure it wont modify a neighbor role u dont have perms to modify
if (!discord.CanModifyRole(GuildID, row->RoleID)) return false;
const auto cb = [this](DiscordError code) {

View File

@ -3,14 +3,14 @@
GuildSettingsWindow::GuildSettingsWindow(Snowflake id)
: m_main(Gtk::ORIENTATION_VERTICAL)
, GuildID(id)
, m_pane_info(id)
, m_pane_bans(id)
, m_pane_invites(id)
, m_pane_audit_log(id)
, m_pane_members(id)
, m_pane_roles(id)
, m_pane_emojis(id) {
, m_pane_bans(id)
, m_pane_invites(id)
, m_pane_emojis(id)
, m_pane_audit_log(id)
, GuildID(id) {
auto &discord = Abaddon::Get().GetDiscordClient();
const auto guild = *discord.GetGuild(id);

View File

@ -179,7 +179,6 @@ void MainWindow::UpdateChatWindowContents() {
}
void MainWindow::UpdateChatActiveChannel(Snowflake id) {
auto &discord = Abaddon::Get().GetDiscordClient();
m_chat.SetActiveChannel(id);
m_members.SetActiveChannel(id);
m_channel_list.SetActiveChannel(id);

View File

@ -3,8 +3,8 @@
#include "../../abaddon.hpp"
ConnectionItem::ConnectionItem(const ConnectionData &conn)
: m_name(conn.Name)
, m_box(Gtk::ORIENTATION_HORIZONTAL) {
: m_box(Gtk::ORIENTATION_HORIZONTAL)
, m_name(conn.Name) {
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
try {
pixbuf = Gdk::Pixbuf::create_from_file(Abaddon::GetResPath("/" + conn.Type + ".png"), 32, 32);
@ -97,7 +97,7 @@ void ConnectionsContainer::SetConnections(const std::vector<ConnectionData> &con
"facebook"
};
for (int i = 0; i < connections.size(); i++) {
for (size_t i = 0; i < connections.size(); i++) {
const auto &conn = connections[i];
if (supported_services.find(conn.Type) == supported_services.end()) continue;
auto widget = Gtk::manage(new ConnectionItem(conn));

View File

@ -3,11 +3,11 @@
ThreadsWindow::ThreadsWindow(const ChannelData &channel)
: m_channel_id(channel.ID)
, m_filter_public(m_group, "Public")
, m_filter_private(m_group, "Private")
, m_box(Gtk::ORIENTATION_VERTICAL)
, m_active(channel, sigc::mem_fun(*this, &ThreadsWindow::ListFilterFunc))
, m_archived(channel, sigc::mem_fun(*this, &ThreadsWindow::ListFilterFunc))
, m_filter_public(m_group, "Public")
, m_filter_private(m_group, "Private") {
, m_archived(channel, sigc::mem_fun(*this, &ThreadsWindow::ListFilterFunc)) {
set_name("threads-window");
set_default_size(450, 375);
set_title("#" + *channel.Name + " - Threads");