diff options
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/cellrendererpixbufanimation.cpp | 2 | ||||
-rw-r--r-- | src/components/cellrendererpixbufanimation.hpp | 2 | ||||
-rw-r--r-- | src/components/channels.cpp | 20 | ||||
-rw-r--r-- | src/components/channels.hpp | 2 | ||||
-rw-r--r-- | src/components/channelscellrenderer.cpp | 29 | ||||
-rw-r--r-- | src/components/channelscellrenderer.hpp | 4 | ||||
-rw-r--r-- | src/components/chatinputindicator.cpp | 6 | ||||
-rw-r--r-- | src/components/chatmessage.cpp | 57 | ||||
-rw-r--r-- | src/components/chatmessage.hpp | 19 | ||||
-rw-r--r-- | src/components/chatwindow.cpp | 5 | ||||
-rw-r--r-- | src/components/chatwindow.hpp | 2 | ||||
-rw-r--r-- | src/components/completer.cpp | 29 | ||||
-rw-r--r-- | src/components/completer.hpp | 2 | ||||
-rw-r--r-- | src/components/draglistbox.cpp | 4 | ||||
-rw-r--r-- | src/components/friendslist.cpp | 8 | ||||
-rw-r--r-- | src/components/lazyimage.cpp | 8 | ||||
-rw-r--r-- | src/components/lazyimage.hpp | 2 | ||||
-rw-r--r-- | src/components/memberlist.cpp | 8 | ||||
-rw-r--r-- | src/components/ratelimitindicator.cpp | 2 | ||||
-rw-r--r-- | src/components/statusindicator.cpp | 9 | ||||
-rw-r--r-- | src/components/statusindicator.hpp | 2 |
21 files changed, 103 insertions, 119 deletions
diff --git a/src/components/cellrendererpixbufanimation.cpp b/src/components/cellrendererpixbufanimation.cpp index 2658967..d6f1f01 100644 --- a/src/components/cellrendererpixbufanimation.cpp +++ b/src/components/cellrendererpixbufanimation.cpp @@ -10,8 +10,6 @@ CellRendererPixbufAnimation::CellRendererPixbufAnimation() property_ypad() = 2; } -CellRendererPixbufAnimation::~CellRendererPixbufAnimation() {} - Glib::PropertyProxy<Glib::RefPtr<Gdk::Pixbuf>> CellRendererPixbufAnimation::property_pixbuf() { return m_property_pixbuf.get_proxy(); } diff --git a/src/components/cellrendererpixbufanimation.hpp b/src/components/cellrendererpixbufanimation.hpp index f47e928..fe2141d 100644 --- a/src/components/cellrendererpixbufanimation.hpp +++ b/src/components/cellrendererpixbufanimation.hpp @@ -6,7 +6,7 @@ class CellRendererPixbufAnimation : public Gtk::CellRenderer { public: CellRendererPixbufAnimation(); - virtual ~CellRendererPixbufAnimation(); + ~CellRendererPixbufAnimation() override = default; Glib::PropertyProxy<Glib::RefPtr<Gdk::Pixbuf>> property_pixbuf(); Glib::PropertyProxy<Glib::RefPtr<Gdk::PixbufAnimation>> property_pixbuf_animation(); diff --git a/src/components/channels.cpp b/src/components/channels.cpp index 99bd07b..f0f7bcc 100644 --- a/src/components/channels.cpp +++ b/src/components/channels.cpp @@ -291,7 +291,7 @@ void ChannelList::UpdateChannel(Snowflake id) { auto channel = Abaddon::Get().GetDiscordClient().GetChannel(id); if (!iter || !channel.has_value()) return; if (channel->Type == ChannelType::GUILD_CATEGORY) return UpdateChannelCategory(*channel); - if (!IsTextChannel(channel->Type)) return; + if (!channel->IsText()) return; // refresh stuff that might have changed const bool is_orphan_TMP = !channel->ParentID.has_value(); @@ -399,7 +399,7 @@ void ChannelList::OnThreadListSync(const ThreadListSyncData &data) { queue.pop(); if ((*item)[m_columns.m_type] == RenderType::Thread) threads.push_back(static_cast<Snowflake>((*item)[m_columns.m_id])); - for (auto child : item->children()) + for (const auto& child : item->children()) queue.push(child); } @@ -580,7 +580,7 @@ Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) { if (thread.has_value()) threads[*thread->ParentID].push_back(*thread); } - const auto add_threads = [&](const ChannelData &channel, Gtk::TreeRow row) { + const auto add_threads = [&](const ChannelData &channel, const Gtk::TreeRow& row) { row[m_columns.m_expanded] = true; const auto it = threads.find(channel.ID); @@ -648,7 +648,7 @@ Gtk::TreeModel::iterator ChannelList::CreateThreadRow(const Gtk::TreeNodeChildre thread_row[m_columns.m_type] = RenderType::Thread; thread_row[m_columns.m_id] = channel.ID; thread_row[m_columns.m_name] = "- " + Glib::Markup::escape_text(*channel.Name); - thread_row[m_columns.m_sort] = channel.ID; + thread_row[m_columns.m_sort] = static_cast<int64_t>(channel.ID); thread_row[m_columns.m_nsfw] = false; return thread_iter; @@ -692,7 +692,7 @@ bool ChannelList::IsTextChannel(ChannelType type) { } // this should be unncessary but something is behaving strange so its just in case -void ChannelList::OnRowCollapsed(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path) { +void ChannelList::OnRowCollapsed(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path) const { (*iter)[m_columns.m_expanded] = false; } @@ -737,14 +737,14 @@ void ChannelList::AddPrivateChannels() { std::optional<UserData> top_recipient; const auto recipients = dm->GetDMRecipients(); - if (recipients.size() > 0) + if (!recipients.empty()) top_recipient = recipients[0]; auto iter = m_model->append(header_row->children()); auto row = *iter; row[m_columns.m_type] = RenderType::DM; row[m_columns.m_id] = dm_id; - row[m_columns.m_sort] = -(dm->LastMessageID.has_value() ? *dm->LastMessageID : dm_id); + row[m_columns.m_sort] = static_cast<int64_t>(-(dm->LastMessageID.has_value() ? *dm->LastMessageID : dm_id)); row[m_columns.m_icon] = img.GetPlaceholder(DMIconSize); if (dm->Type == ChannelType::DM && top_recipient.has_value()) @@ -781,7 +781,7 @@ void ChannelList::UpdateCreateDMChannel(const ChannelData &dm) { auto row = *iter; row[m_columns.m_type] = RenderType::DM; row[m_columns.m_id] = dm.ID; - row[m_columns.m_sort] = -(dm.LastMessageID.has_value() ? *dm.LastMessageID : dm.ID); + row[m_columns.m_sort] = static_cast<int64_t>(-(dm.LastMessageID.has_value() ? *dm.LastMessageID : dm.ID)); row[m_columns.m_icon] = img.GetPlaceholder(DMIconSize); if (dm.Type == ChannelType::DM && top_recipient.has_value()) @@ -817,7 +817,7 @@ void ChannelList::OnMessageCreate(const Message &msg) { if (!channel.has_value()) return; if (channel->Type == ChannelType::DM || channel->Type == ChannelType::GROUP_DM) { if (iter) - (*iter)[m_columns.m_sort] = -msg.ID; + (*iter)[m_columns.m_sort] = static_cast<int64_t>(-msg.ID); } if (channel->GuildID.has_value()) if ((iter = GetIteratorForGuildFromID(*channel->GuildID))) @@ -826,7 +826,7 @@ void ChannelList::OnMessageCreate(const Message &msg) { bool ChannelList::OnButtonPressEvent(GdkEventButton *ev) { if (ev->button == GDK_BUTTON_SECONDARY && ev->type == GDK_BUTTON_PRESS) { - if (m_view.get_path_at_pos(ev->x, ev->y, m_path_for_menu)) { + if (m_view.get_path_at_pos(static_cast<int>(ev->x), static_cast<int>(ev->y), m_path_for_menu)) { auto row = (*m_model->get_iter(m_path_for_menu)); switch (static_cast<RenderType>(row[m_columns.m_type])) { case RenderType::Guild: diff --git a/src/components/channels.hpp b/src/components/channels.hpp index a2553fd..d499f5b 100644 --- a/src/components/channels.hpp +++ b/src/components/channels.hpp @@ -84,7 +84,7 @@ protected: bool IsTextChannel(ChannelType type); - void OnRowCollapsed(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path); + void OnRowCollapsed(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path) const; void OnRowExpanded(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path); bool SelectionFunc(const Glib::RefPtr<Gtk::TreeModel> &model, const Gtk::TreeModel::Path &path, bool is_currently_selected); bool OnButtonPressEvent(GdkEventButton *ev); diff --git a/src/components/channelscellrenderer.cpp b/src/components/channelscellrenderer.cpp index 141556a..9afce8a 100644 --- a/src/components/channelscellrenderer.cpp +++ b/src/components/channelscellrenderer.cpp @@ -27,9 +27,6 @@ CellRendererChannels::CellRendererChannels() }); } -CellRendererChannels::~CellRendererChannels() { -} - Glib::PropertyProxy<RenderType> CellRendererChannels::property_type() { return m_property_type.get_proxy(); } @@ -212,7 +209,10 @@ void CellRendererChannels::render_vfunc_guild(const Cairo::RefPtr<Cairo::Context const double text_w = text_natural.width; const double text_h = text_natural.height; - Gdk::Rectangle text_cell_area(text_x, text_y, text_w, text_h); + Gdk::Rectangle text_cell_area(static_cast<int>(text_x), + static_cast<int>(text_y), + static_cast<int>(text_w), + static_cast<int>(text_h)); static const auto color = Gdk::RGBA(Abaddon::Get().GetSettings().ChannelColor); m_renderer_text.property_foreground_rgba() = color; @@ -231,7 +231,11 @@ void CellRendererChannels::render_vfunc_guild(const Cairo::RefPtr<Cairo::Context const auto cb = [this, &widget, anim, icon_x, icon_y, icon_w, icon_h] { if (m_pixbuf_anim_iters.at(anim)->advance()) - widget.queue_draw_area(icon_x, icon_y, icon_w, icon_h); + widget.queue_draw_area( + static_cast<int>(icon_x), + static_cast<int>(icon_y), + static_cast<int>(icon_w), + static_cast<int>(icon_h)); }; if ((hover_only && is_hovered) || !hover_only) @@ -264,12 +268,12 @@ void CellRendererChannels::render_vfunc_guild(const Cairo::RefPtr<Cairo::Context const auto y = background_area.get_y(); const auto w = background_area.get_width(); const auto h = background_area.get_height(); - cr->rectangle(x, y + h / 2 - 24 / 2, 3, 24); + cr->rectangle(x, y + h / 2.0 - 24.0 / 2.0, 3.0, 24.0); cr->fill(); } if (total_mentions < 1) return; - auto *paned = static_cast<Gtk::Paned *>(widget.get_ancestor(Gtk::Paned::get_type())); + auto *paned = dynamic_cast<Gtk::Paned *>(widget.get_ancestor(Gtk::Paned::get_type())); if (paned != nullptr) { const auto edge = std::min(paned->get_position(), background_area.get_width()); @@ -415,7 +419,7 @@ void CellRendererChannels::render_vfunc_channel(const Cairo::RefPtr<Cairo::Conte } if (unread_state < 1) return; - auto *paned = static_cast<Gtk::Paned *>(widget.get_ancestor(Gtk::Paned::get_type())); + auto *paned = dynamic_cast<Gtk::Paned *>(widget.get_ancestor(Gtk::Paned::get_type())); if (paned != nullptr) { const auto edge = std::min(paned->get_position(), cell_area.get_width()); @@ -487,7 +491,7 @@ void CellRendererChannels::render_vfunc_thread(const Cairo::RefPtr<Cairo::Contex } if (unread_state < 1) return; - auto *paned = static_cast<Gtk::Paned *>(widget.get_ancestor(Gtk::Paned::get_type())); + auto *paned = dynamic_cast<Gtk::Paned *>(widget.get_ancestor(Gtk::Paned::get_type())); if (paned != nullptr) { const auto edge = std::min(paned->get_position(), cell_area.get_width()); @@ -522,7 +526,7 @@ void CellRendererChannels::render_vfunc_dmheader(const Cairo::RefPtr<Cairo::Cont if (!Abaddon::Get().GetSettings().Unreads) return; - auto *paned = static_cast<Gtk::Paned *>(widget.get_ancestor(Gtk::Paned::get_type())); + auto *paned = dynamic_cast<Gtk::Paned *>(widget.get_ancestor(Gtk::Paned::get_type())); if (paned != nullptr) { const auto edge = std::min(paned->get_position(), background_area.get_width()); if (const auto unread = Abaddon::Get().GetDiscordClient().GetUnreadDMsCount(); unread > 0) @@ -587,7 +591,10 @@ void CellRendererChannels::render_vfunc_dm(const Cairo::RefPtr<Cairo::Context> & const double text_w = text_natural.width; const double text_h = text_natural.height; - Gdk::Rectangle text_cell_area(text_x, text_y, text_w, text_h); + Gdk::Rectangle text_cell_area(static_cast<int>(text_x), + static_cast<int>(text_y), + static_cast<int>(text_w), + static_cast<int>(text_h)); auto &discord = Abaddon::Get().GetDiscordClient(); const auto id = m_property_id.get_value(); diff --git a/src/components/channelscellrenderer.hpp b/src/components/channelscellrenderer.hpp index 95ff4fe..e2be9b2 100644 --- a/src/components/channelscellrenderer.hpp +++ b/src/components/channelscellrenderer.hpp @@ -18,7 +18,7 @@ enum class RenderType : uint8_t { class CellRendererChannels : public Gtk::CellRenderer { public: CellRendererChannels(); - virtual ~CellRendererChannels(); + ~CellRendererChannels() override = default; Glib::PropertyProxy<RenderType> property_type(); Glib::PropertyProxy<uint64_t> property_id(); @@ -106,7 +106,7 @@ protected: Gtk::CellRendererState flags); static void cairo_path_rounded_rect(const Cairo::RefPtr<Cairo::Context> &cr, double x, double y, double w, double h, double r); - void unread_render_mentions(const Cairo::RefPtr<Cairo::Context> &cr, Gtk::Widget &widget, int mentions, int edge, const Gdk::Rectangle &cell_area); + static void unread_render_mentions(const Cairo::RefPtr<Cairo::Context> &cr, Gtk::Widget &widget, int mentions, int edge, const Gdk::Rectangle &cell_area); private: Gtk::CellRendererText m_renderer_text; diff --git a/src/components/chatinputindicator.cpp b/src/components/chatinputindicator.cpp index ba794f3..b829c46 100644 --- a/src/components/chatinputindicator.cpp +++ b/src/components/chatinputindicator.cpp @@ -84,14 +84,14 @@ void ChatInputIndicator::OnMessageCreate(const Message &message) { void ChatInputIndicator::SetTypingString(const Glib::ustring &str) { m_label.set_text(str); - if (str == "") + if (str.empty()) m_img.hide(); else if (m_img.property_pixbuf_animation().get_value()) m_img.show(); } void ChatInputIndicator::ComputeTypingString() { - if (m_custom_markup != "") { + if (!m_custom_markup.empty()) { m_label.set_markup(m_custom_markup); m_img.hide(); return; @@ -104,7 +104,7 @@ void ChatInputIndicator::ComputeTypingString() { if (user.has_value()) typers.push_back(*user); } - if (typers.size() == 0) { + if (typers.empty()) { SetTypingString(""); } else if (typers.size() == 1) { SetTypingString(typers[0].Username + " is typing..."); diff --git a/src/components/chatmessage.cpp b/src/components/chatmessage.cpp index 823aaa6..4d6eec5 100644 --- a/src/components/chatmessage.cpp +++ b/src/components/chatmessage.cpp @@ -30,7 +30,7 @@ ChatMessageItemContainer *ChatMessageItemContainer::FromMessage(const Message &d if (data.Nonce.has_value()) container->Nonce = *data.Nonce; - if (data.Content.size() > 0 || data.Type != MessageType::DEFAULT) { + if (!data.Content.empty() || data.Type != MessageType::DEFAULT) { container->m_text_component = container->CreateTextComponent(data); container->AttachEventHandlers(*container->m_text_component); container->m_main.add(*container->m_text_component); @@ -78,7 +78,7 @@ ChatMessageItemContainer *ChatMessageItemContainer::FromMessage(const Message &d container->m_main.add(*widget); } - if (data.Reactions.has_value() && data.Reactions->size() > 0) { + if (data.Reactions.has_value() && !data.Reactions->empty()) { container->m_reactions_component = container->CreateReactionsComponent(data); container->m_main.add(*container->m_reactions_component); } @@ -114,7 +114,7 @@ void ChatMessageItemContainer::UpdateReactions() { } const auto data = Abaddon::Get().GetDiscordClient().GetMessage(ID); - if (data->Reactions.has_value() && data->Reactions->size() > 0) { + if (data->Reactions.has_value() && !data->Reactions->empty()) { m_reactions_component = CreateReactionsComponent(*data); m_reactions_component->show_all(); m_main.add(*m_reactions_component); @@ -150,7 +150,7 @@ void ChatMessageItemContainer::UpdateAttributes() { m_attrib_label->set_markup("<span color='#999999'>[edited]</span>"); } -void ChatMessageItemContainer::AddClickHandler(Gtk::Widget *widget, std::string url) { +void ChatMessageItemContainer::AddClickHandler(Gtk::Widget *widget, const std::string &url) { // clang-format off widget->signal_button_press_event().connect([url](GdkEventButton *event) -> bool { if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY) { @@ -224,13 +224,13 @@ void ChatMessageItemContainer::UpdateTextComponent(Gtk::TextView *tv) { } } break; case MessageType::RECIPIENT_ADD: { - if (data->Mentions.size() == 0) break; + if (data->Mentions.empty()) break; const auto &adder = Abaddon::Get().GetDiscordClient().GetUser(data->Author.ID); const auto &added = data->Mentions[0]; b->insert_markup(s, "<i><span color='#999999'><span color='#eeeeee'>" + adder->Username + "</span> added <span color='#eeeeee'>" + added.Username + "</span></span></i>"); } break; case MessageType::RECIPIENT_REMOVE: { - if (data->Mentions.size() == 0) break; + if (data->Mentions.empty()) break; const auto &adder = Abaddon::Get().GetDiscordClient().GetUser(data->Author.ID); const auto &added = data->Mentions[0]; if (adder->ID == added.ID) @@ -361,7 +361,7 @@ Gtk::Widget *ChatMessageItemContainer::CreateEmbedComponent(const EmbedData &emb if (embed.URL.has_value()) { AddPointerCursor(*title_ev); auto url = *embed.URL; - title_ev->signal_button_press_event().connect([this, url = std::move(url)](GdkEventButton *event) -> bool { + title_ev->signal_button_press_event().connect([url = std::move(url)](GdkEventButton *event) -> bool { if (event->button == GDK_BUTTON_PRIMARY) { LaunchBrowser(url); return true; @@ -389,7 +389,7 @@ Gtk::Widget *ChatMessageItemContainer::CreateEmbedComponent(const EmbedData &emb } // todo: handle inline fields - if (embed.Fields.has_value() && embed.Fields->size() > 0) { + if (embed.Fields.has_value() && !embed.Fields->empty()) { auto *flow = Gtk::manage(new Gtk::FlowBox); flow->set_orientation(Gtk::ORIENTATION_HORIZONTAL); flow->set_min_children_per_line(3); @@ -516,23 +516,6 @@ Gtk::Widget *ChatMessageItemContainer::CreateAttachmentComponent(const Attachmen return ev; } -Gtk::Widget *ChatMessageItemContainer::CreateStickerComponentDeprecated(const StickerData &data) { - auto *box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL)); - auto *imgw = Gtk::manage(new Gtk::Image); - box->add(*imgw); - auto &img = Abaddon::Get().GetImageManager(); - - if (data.FormatType == StickerFormatType::PNG || data.FormatType == StickerFormatType::APNG) { - auto cb = [this, imgw](const Glib::RefPtr<Gdk::Pixbuf> &pixbuf) { - imgw->property_pixbuf() = pixbuf; - }; - img.LoadFromURL(data.GetURL(), sigc::track_obj(cb, *imgw)); - } - - AttachEventHandlers(*box); - return box; -} - Gtk::Widget *ChatMessageItemContainer::CreateStickersComponent(const std::vector<StickerItem> &data) { auto *box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL)); @@ -608,7 +591,7 @@ Gtk::Widget *ChatMessageItemContainer::CreateReactionsComponent(const Message &d // image if (is_stock) { // unicode/stock const auto shortcode = emojis.GetShortCodeForPattern(reaction.Emoji.Name); - if (shortcode != "") + if (!shortcode.empty()) ev->set_tooltip_text(shortcode); const auto &pb = emojis.GetPixBuf(reaction.Emoji.Name); @@ -784,7 +767,7 @@ void ChatMessageItemContainer::HandleRoleMentions(const Glib::RefPtr<Gtk::TextBu } } -void ChatMessageItemContainer::HandleUserMentions(const Glib::RefPtr<Gtk::TextBuffer> &buf) { +void ChatMessageItemContainer::HandleUserMentions(const Glib::RefPtr<Gtk::TextBuffer> &buf) const { constexpr static const auto mentions_regex = R"(<@!?(\d+)>)"; static auto rgx = Glib::Regex::create(mentions_regex); @@ -861,7 +844,7 @@ void ChatMessageItemContainer::HandleCustomEmojis(Gtk::TextView &tv) { const auto mark_start = buf->create_mark(start_it, false); end_it.backward_char(); const auto mark_end = buf->create_mark(end_it, false); - const auto cb = [this, &tv, buf, mark_start, mark_end](const Glib::RefPtr<Gdk::PixbufAnimation> &pixbuf) { + const auto cb = [&tv, buf, mark_start, mark_end](const Glib::RefPtr<Gdk::PixbufAnimation> &pixbuf) { auto start_it = mark_start->get_iter(); auto end_it = mark_end->get_iter(); end_it.forward_char(); @@ -879,7 +862,7 @@ void ChatMessageItemContainer::HandleCustomEmojis(Gtk::TextView &tv) { const auto mark_start = buf->create_mark(start_it, false); end_it.backward_char(); const auto mark_end = buf->create_mark(end_it, false); - const auto cb = [this, buf, mark_start, mark_end](const Glib::RefPtr<Gdk::Pixbuf> &pixbuf) { + const auto cb = [buf, mark_start, mark_end](const Glib::RefPtr<Gdk::Pixbuf> &pixbuf) { auto start_it = mark_start->get_iter(); auto end_it = mark_end->get_iter(); end_it.forward_char(); @@ -902,7 +885,7 @@ void ChatMessageItemContainer::HandleEmojis(Gtk::TextView &tv) { if (Abaddon::Get().GetSettings().ShowCustomEmojis) HandleCustomEmojis(tv); } -void ChatMessageItemContainer::CleanupEmojis(Glib::RefPtr<Gtk::TextBuffer> buf) { +void ChatMessageItemContainer::CleanupEmojis(const Glib::RefPtr<Gtk::TextBuffer> &buf) { static auto rgx = Glib::Regex::create(R"(<a?:([\w\d_]+):(\d+)>)"); auto text = GetText(buf); @@ -922,9 +905,9 @@ void ChatMessageItemContainer::CleanupEmojis(Glib::RefPtr<Gtk::TextBuffer> buf) startpos = mend; const auto it = buf->erase(start_it, end_it); - const int alen = text.size(); + const int alen = static_cast<int>(text.size()); text = GetText(buf); - const int blen = text.size(); + const int blen = static_cast<int>(text.size()); startpos -= (alen - blen); buf->insert(it, new_term); @@ -933,7 +916,7 @@ void ChatMessageItemContainer::CleanupEmojis(Glib::RefPtr<Gtk::TextBuffer> buf) } } -void ChatMessageItemContainer::HandleChannelMentions(Glib::RefPtr<Gtk::TextBuffer> buf) { +void ChatMessageItemContainer::HandleChannelMentions(const Glib::RefPtr<Gtk::TextBuffer> &buf) { static auto rgx = Glib::Regex::create(R"(<#(\d+)>)"); Glib::ustring text = GetText(buf); @@ -990,12 +973,12 @@ bool ChatMessageItemContainer::OnClickChannel(GdkEventButton *ev) { return false; int x, y; - m_text_component->window_to_buffer_coords(Gtk::TEXT_WINDOW_WIDGET, ev->x, ev->y, x, y); + m_text_component->window_to_buffer_coords(Gtk::TEXT_WINDOW_WIDGET, static_cast<int>(ev->x), static_cast<int>(ev->y), x, y); Gtk::TextBuffer::iterator iter; m_text_component->get_iter_at_location(iter, x, y); const auto tags = iter.get_tags(); - for (auto tag : tags) { + for (const auto &tag : tags) { const auto it = m_channel_tagmap.find(tag); if (it != m_channel_tagmap.end()) { m_signal_action_channel_click.emit(it->second); @@ -1053,12 +1036,12 @@ bool ChatMessageItemContainer::OnLinkClick(GdkEventButton *ev) { return false; int x, y; - m_text_component->window_to_buffer_coords(Gtk::TEXT_WINDOW_WIDGET, ev->x, ev->y, x, y); + m_text_component->window_to_buffer_coords(Gtk::TEXT_WINDOW_WIDGET, static_cast<int>(ev->x), static_cast<int>(ev->y), x, y); Gtk::TextBuffer::iterator iter; m_text_component->get_iter_at_location(iter, x, y); const auto tags = iter.get_tags(); - for (auto tag : tags) { + for (const auto &tag : tags) { const auto it = m_link_tagmap.find(tag); if (it != m_link_tagmap.end()) { if (ev->button == GDK_BUTTON_PRIMARY) { diff --git a/src/components/chatmessage.hpp b/src/components/chatmessage.hpp index 5e213ee..86c3fea 100644 --- a/src/components/chatmessage.hpp +++ b/src/components/chatmessage.hpp @@ -19,14 +19,13 @@ public: void SetFailed(); protected: - void AddClickHandler(Gtk::Widget *widget, std::string); + static void AddClickHandler(Gtk::Widget *widget, const std::string &); Gtk::TextView *CreateTextComponent(const Message &data); // Message.Content void UpdateTextComponent(Gtk::TextView *tv); Gtk::Widget *CreateEmbedsComponent(const std::vector<EmbedData> &embeds); - Gtk::Widget *CreateEmbedComponent(const EmbedData &data); // Message.Embeds[0] + static Gtk::Widget *CreateEmbedComponent(const EmbedData &data); // Message.Embeds[0] Gtk::Widget *CreateImageComponent(const std::string &proxy_url, const std::string &url, int inw, int inh); Gtk::Widget *CreateAttachmentComponent(const AttachmentData &data); // non-image attachments - Gtk::Widget *CreateStickerComponentDeprecated(const StickerData &data); Gtk::Widget *CreateStickersComponent(const std::vector<StickerItem> &data); Gtk::Widget *CreateReactionsComponent(const Message &data); Gtk::Widget *CreateReplyComponent(const Message &data); @@ -35,14 +34,14 @@ protected: static bool IsEmbedImageOnly(const EmbedData &data); - void HandleRoleMentions(const Glib::RefPtr<Gtk::TextBuffer> &buf); - void HandleUserMentions(const Glib::RefPtr<Gtk::TextBuffer> &buf); - void HandleStockEmojis(Gtk::TextView &tv); - void HandleCustomEmojis(Gtk::TextView &tv); - void HandleEmojis(Gtk::TextView &tv); - void CleanupEmojis(Glib::RefPtr<Gtk::TextBuffer> buf); + static void HandleRoleMentions(const Glib::RefPtr<Gtk::TextBuffer> &buf); + void HandleUserMentions(const Glib::RefPtr<Gtk::TextBuffer> &buf) const; + static void HandleStockEmojis(Gtk::TextView &tv); + static void HandleCustomEmojis(Gtk::TextView &tv); + static void HandleEmojis(Gtk::TextView &tv); + static void CleanupEmojis(const Glib::RefPtr<Gtk::TextBuffer> &buf); - void HandleChannelMentions(Glib::RefPtr<Gtk::TextBuffer> buf); + void HandleChannelMentions(const Glib::RefPtr<Gtk::TextBuffer> &buf); void HandleChannelMentions(Gtk::TextView *tv); bool OnClickChannel(GdkEventButton *ev); diff --git a/src/components/chatwindow.cpp b/src/components/chatwindow.cpp index df2b6b8..582343d 100644 --- a/src/components/chatwindow.cpp +++ b/src/components/chatwindow.cpp @@ -1,5 +1,4 @@ #include "chatwindow.hpp" -#include "chatmessage.hpp" #include "abaddon.hpp" #include "chatinputindicator.hpp" #include "ratelimitindicator.hpp" @@ -134,7 +133,7 @@ void ChatWindow::AddNewHistory(const std::vector<Message> &msgs) { m_chat->PrependMessages(msgs.crbegin(), msgs.crend()); } -void ChatWindow::InsertChatInput(std::string text) { +void ChatWindow::InsertChatInput(const std::string &text) { m_input->InsertText(text); } @@ -159,7 +158,7 @@ bool ChatWindow::OnInputSubmit(const Glib::ustring &text) { if (!m_rate_limit_indicator->CanSpeak()) return false; - if (text.size() == 0) + if (text.empty()) return false; if (m_active_channel.IsValid()) diff --git a/src/components/chatwindow.hpp b/src/components/chatwindow.hpp index db0bfc4..0f40e88 100644 --- a/src/components/chatwindow.hpp +++ b/src/components/chatwindow.hpp @@ -25,7 +25,7 @@ public: void DeleteMessage(Snowflake id); // add [deleted] indicator void UpdateMessage(Snowflake id); // add [edited] indicator void AddNewHistory(const std::vector<Message> &msgs); // prepend messages - void InsertChatInput(std::string text); + void InsertChatInput(const std::string& text); Snowflake GetOldestListedMessage(); // oldest message that is currently in the ListBox void UpdateReactions(Snowflake id); void SetTopic(const std::string &text); diff --git a/src/components/completer.cpp b/src/components/completer.cpp index 327ef95..128bef2 100644 --- a/src/components/completer.cpp +++ b/src/components/completer.cpp @@ -1,4 +1,5 @@ #include <unordered_set> +#include <utility> #include "completer.hpp" #include "abaddon.hpp" #include "util.hpp" @@ -46,7 +47,7 @@ bool Completer::ProcessKeyPress(GdkEventKey *e) { switch (e->keyval) { case GDK_KEY_Down: { - if (m_entries.size() == 0) return true; + if (m_entries.empty()) return true; 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]); @@ -54,7 +55,7 @@ bool Completer::ProcessKeyPress(GdkEventKey *e) { } return true; case GDK_KEY_Up: { - if (m_entries.size() == 0) return true; + if (m_entries.empty()) return true; 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]); @@ -62,7 +63,7 @@ bool Completer::ProcessKeyPress(GdkEventKey *e) { } return true; case GDK_KEY_Return: { - if (m_entries.size() == 0) return true; + if (m_entries.empty()) return true; DoCompletion(m_list.get_selected_row()); } return true; @@ -74,11 +75,11 @@ bool Completer::ProcessKeyPress(GdkEventKey *e) { } void Completer::SetGetRecentAuthors(get_recent_authors_cb cb) { - m_recent_authors_cb = cb; + m_recent_authors_cb = std::move(cb); } void Completer::SetGetChannelID(get_channel_id_cb cb) { - m_channel_id_cb = cb; + m_channel_id_cb = std::move(cb); } bool Completer::IsShown() const { @@ -86,7 +87,7 @@ bool Completer::IsShown() const { } CompleterEntry *Completer::CreateEntry(const Glib::ustring &completion) { - auto entry = Gtk::manage(new CompleterEntry(completion, m_entries.size())); + auto entry = Gtk::manage(new CompleterEntry(completion, static_cast<int>(m_entries.size()))); m_entries.push_back(entry); entry->show_all(); m_list.add(*entry); @@ -152,7 +153,7 @@ void Completer::CompleteEmojis(const Glib::ustring &term) { const auto make_entry = [&](const Glib::ustring &name, const Glib::ustring &completion, const Glib::ustring &url = "", bool animated = false) -> CompleterEntry * { const auto entry = CreateEntry(completion); entry->SetText(name); - if (url == "") return entry; + if (url.empty()) return entry; if (animated) entry->SetAnimation(url); else @@ -173,8 +174,8 @@ void Completer::CompleteEmojis(const Glib::ustring &term) { const auto emoji = *discord.GetEmoji(tmp.ID); if (emoji.IsAnimated.has_value() && *emoji.IsAnimated) continue; if (emoji.IsAvailable.has_value() && !*emoji.IsAvailable) continue; - if (emoji.Roles.has_value() && emoji.Roles->size() > 0) continue; - if (term.size() > 0) + if (emoji.Roles.has_value() && !emoji.Roles->empty()) continue; + if (!term.empty()) if (!StringContainsCaseless(emoji.Name, term)) continue; if (i++ > MaxCompleterEntries) break; @@ -190,8 +191,8 @@ void Completer::CompleteEmojis(const Glib::ustring &term) { 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; - if (emoji.Roles.has_value() && emoji.Roles->size() > 0) continue; - if (term.size() > 0) + if (emoji.Roles.has_value() && !emoji.Roles->empty()) continue; + if (!term.empty()) if (!StringContainsCaseless(emoji.Name, term)) continue; if (i++ > MaxCompleterEntries) goto done; @@ -275,7 +276,7 @@ void Completer::OnTextBufferChanged() { default: break; } - if (m_entries.size() > 0) { + if (!m_entries.empty()) { m_list.select_row(*m_entries[0]); set_reveal_child(true); } else { @@ -329,8 +330,8 @@ Glib::ustring Completer::GetTerm() { return m_start.get_text(m_end); } -CompleterEntry::CompleterEntry(const Glib::ustring &completion, int index) - : m_completion(completion) +CompleterEntry::CompleterEntry(Glib::ustring completion, int index) + : m_completion(std::move(completion)) , m_index(index) , m_box(Gtk::ORIENTATION_HORIZONTAL) { set_halign(Gtk::ALIGN_START); diff --git a/src/components/completer.hpp b/src/components/completer.hpp index 6bd8be9..6906f02 100644 --- a/src/components/completer.hpp +++ b/src/components/completer.hpp @@ -8,7 +8,7 @@ constexpr static int CompleterImageSize = 24; class CompleterEntry : public Gtk::ListBoxRow { public: - CompleterEntry(const Glib::ustring &completion, int index); + CompleterEntry(Glib::ustring completion, int index); void SetTextColor(int color); // SetText will reset void SetText(const Glib::ustring &text); void SetImage(const Glib::RefPtr<Gdk::Pixbuf> &pb); diff --git a/src/components/draglistbox.cpp b/src/components/draglistbox.cpp index 492abc3..50bb5b0 100644 --- a/src/components/draglistbox.cpp +++ b/src/components/draglistbox.cpp @@ -102,7 +102,7 @@ bool DragListBox::scroll() { } void DragListBox::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext> &context, int x, int y, const Gtk::SelectionData &selection_data, guint info, guint time) { - int index = 0; + int index; if (m_hover_row != nullptr) { if (m_top) { index = m_hover_row->get_index() - 1; @@ -130,7 +130,7 @@ void DragListBox::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext> &co void DragListBox::add_draggable(Gtk::ListBoxRow *widget) { widget->drag_source_set(m_entries, Gdk::BUTTON1_MASK, Gdk::ACTION_MOVE); widget->signal_drag_begin().connect(sigc::bind<0>(sigc::mem_fun(*this, &DragListBox::row_drag_begin), widget)); - widget->signal_drag_data_get().connect([this, widget](const Glib::RefPtr<Gdk::DragContext> &context, Gtk::SelectionData &selection_data, guint info, guint time) { + widget->signal_drag_data_get().connect([widget](const Glib::RefPtr<Gdk::DragContext> &context, Gtk::SelectionData &selection_data, guint info, guint time) { selection_data.set("GTK_LIST_BOX_ROW", 32, reinterpret_cast<const guint8 *>(&widget), sizeof(&widget)); }); add(*widget); diff --git a/src/components/friendslist.cpp b/src/components/friendslist.cpp index 1331d19..b908359 100644 --- a/src/components/friendslist.cpp +++ b/src/components/friendslist.cpp @@ -133,7 +133,7 @@ void FriendsList::OnActionRemove(Snowflake id) { break; } if (Abaddon::Get().ShowConfirm(str, window)) { - const auto cb = [this, window](DiscordError code) { + const auto cb = [window](DiscordError code) { if (code == DiscordError::NONE) return; Gtk::MessageDialog dlg(*window, "Failed to remove user", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); dlg.set_position(Gtk::WIN_POS_CENTER); @@ -215,7 +215,7 @@ void FriendsListAddComponent::Submit() { if (hashpos == Glib::ustring::npos) return; const auto username = text.substr(0, hashpos); const auto discriminator = text.substr(hashpos + 1); - if (username.size() == 0 || discriminator.size() != 4) return; + if (username.empty() || discriminator.size() != 4) return; if (discriminator.find_first_not_of("0123456789") != Glib::ustring::npos) return; m_requesting = true; @@ -229,7 +229,9 @@ void FriendsListAddComponent::Submit() { m_label.set_text("Failed: "s + GetDiscordErrorDisplayString(code)); } }; - Abaddon::Get().GetDiscordClient().SendFriendRequest(username, std::stoul(discriminator), sigc::track_obj(cb, *this)); + Abaddon::Get().GetDiscordClient().SendFriendRequest(username, + static_cast<int>(std::stoul(discriminator)), + sigc::track_obj(cb, *this)); } bool FriendsListAddComponent::OnKeyPress(GdkEventKey *e) { diff --git a/src/components/lazyimage.cpp b/src/components/lazyimage.cpp index 49bbdeb..1f005f3 100644 --- a/src/components/lazyimage.cpp +++ b/src/components/lazyimage.cpp @@ -1,4 +1,6 @@ #include "lazyimage.hpp" + +#include <utility> #include "abaddon.hpp" LazyImage::LazyImage(int w, int h, bool use_placeholder) @@ -9,8 +11,8 @@ LazyImage::LazyImage(int w, int h, bool use_placeholder) signal_draw().connect(sigc::mem_fun(*this, &LazyImage::OnDraw)); } -LazyImage::LazyImage(const std::string &url, int w, int h, bool use_placeholder) - : m_url(url) +LazyImage::LazyImage(std::string url, int w, int h, bool use_placeholder) + : m_url(std::move(url)) , m_width(w) , m_height(h) { if (use_placeholder) @@ -27,7 +29,7 @@ void LazyImage::SetURL(const std::string &url) { } bool LazyImage::OnDraw(const Cairo::RefPtr<Cairo::Context> &context) { - if (!m_needs_request || m_url == "") return false; + if (!m_needs_request || m_url.empty()) return false; m_needs_request = false; if (m_animated) { diff --git a/src/components/lazyimage.hpp b/src/components/lazyimage.hpp index fae69df..4d5a216 100644 --- a/src/components/lazyimage.hpp +++ b/src/components/lazyimage.hpp @@ -5,7 +5,7 @@ class LazyImage : public Gtk::Image { public: LazyImage(int w, int h, bool use_placeholder = true); - LazyImage(const std::string &url, int w, int h, bool use_placeholder = true); + LazyImage(std::string url, int w, int h, bool use_placeholder = true); void SetAnimated(bool is_animated); void SetURL(const std::string &url); diff --git a/src/components/memberlist.cpp b/src/components/memberlist.cpp index 4f21700..4c95b63 100644 --- a/src/components/memberlist.cpp +++ b/src/components/memberlist.cpp @@ -151,7 +151,7 @@ void MemberList::UpdateMemberList() { if (!pos_role.has_value()) { roleless_users.push_back(id); continue; - }; + } pos_to_role[pos_role->Position] = *pos_role; pos_to_users[pos_role->Position].push_back(std::move(*user)); @@ -161,7 +161,7 @@ void MemberList::UpdateMemberList() { int num_rows = 0; const auto guild = *discord.GetGuild(m_guild_id); - auto add_user = [this, &user_to_color, &num_rows, guild](const UserData &data) -> bool { + auto add_user = [this, &num_rows, guild](const UserData &data) -> bool { if (num_rows++ > MaxMemberListRows) return false; auto *row = Gtk::manage(new MemberListUserRow(guild, data)); m_id_to_row[data.ID] = row; @@ -170,7 +170,7 @@ void MemberList::UpdateMemberList() { return true; }; - auto add_role = [this](std::string name) { + auto add_role = [this](const std::string &name) { auto *role_row = Gtk::manage(new Gtk::ListBoxRow); auto *role_lbl = Gtk::manage(new Gtk::Label); @@ -215,7 +215,7 @@ void MemberList::UpdateMemberList() { } void MemberList::AttachUserMenuHandler(Gtk::ListBoxRow *row, Snowflake id) { - row->signal_button_press_event().connect([this, row, id](GdkEventButton *e) -> bool { + row->signal_button_press_event().connect([this, id](GdkEventButton *e) -> bool { if (e->type == GDK_BUTTON_PRESS && e->button == GDK_BUTTON_SECONDARY) { Abaddon::Get().ShowUserMenu(reinterpret_cast<const GdkEvent *>(e), id, m_guild_id); return true; diff --git a/src/components/ratelimitindicator.cpp b/src/components/ratelimitindicator.cpp index ac4ef4b..820e395 100644 --- a/src/components/ratelimitindicator.cpp +++ b/src/components/ratelimitindicator.cpp @@ -66,7 +66,7 @@ int RateLimitIndicator::GetTimeLeft() const { if (sec_diff <= 0) return 0; else - return sec_diff; + return static_cast<int>(sec_diff); } int RateLimitIndicator::GetRateLimit() const { diff --git a/src/components/statusindicator.cpp b/src/components/statusindicator.cpp index 42eb170..4d7415c 100644 --- a/src/components/statusindicator.cpp +++ b/src/components/statusindicator.cpp @@ -2,10 +2,6 @@ #include "abaddon.hpp" static const constexpr int Diameter = 8; -static const auto OnlineColor = Gdk::RGBA("#43B581"); -static const auto IdleColor = Gdk::RGBA("#FAA61A"); -static const auto DNDColor = Gdk::RGBA("#982929"); -static const auto OfflineColor = Gdk::RGBA("#808080"); StatusIndicator::StatusIndicator(Snowflake user_id) : Glib::ObjectBase("statusindicator") @@ -26,9 +22,6 @@ StatusIndicator::StatusIndicator(Snowflake user_id) CheckStatus(); } -StatusIndicator::~StatusIndicator() { -} - void StatusIndicator::CheckStatus() { const auto status = Abaddon::Get().GetDiscordClient().GetUserStatus(m_id); const auto last_status = m_status; @@ -121,7 +114,7 @@ bool StatusIndicator::on_draw(const Cairo::RefPtr<Cairo::Context> &cr) { const auto color = get_style_context()->get_color(Gtk::STATE_FLAG_NORMAL); cr->set_source_rgb(color.get_red(), color.get_green(), color.get_blue()); - cr->arc(width / 2, height / 2, width / 3, 0.0, 2 * (4 * std::atan(1))); + cr->arc(width / 2.0, height / 2.0, width / 3.0, 0.0, 2 * (4 * std::atan(1))); cr->close_path(); cr->fill_preserve(); cr->stroke(); diff --git a/src/components/statusindicator.hpp b/src/components/statusindicator.hpp index b2cf0bd..ad9122b 100644 --- a/src/components/statusindicator.hpp +++ b/src/components/statusindicator.hpp @@ -6,7 +6,7 @@ class StatusIndicator : public Gtk::Widget { public: StatusIndicator(Snowflake user_id); - virtual ~StatusIndicator(); + ~StatusIndicator() override = default; protected: Gtk::SizeRequestMode get_request_mode_vfunc() const override; |