summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2022-07-23 18:34:33 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2022-07-23 18:34:33 -0400
commit59acd0f82f500d743ca4be7324f913903c8de237 (patch)
treec828789a7fdcd89d4b4e541d5810734af993062d /src/components
parent544ae6f915da175c489e4293d1d5b51e5fdde4f7 (diff)
downloadabaddon-portaudio-59acd0f82f500d743ca4be7324f913903c8de237.tar.gz
abaddon-portaudio-59acd0f82f500d743ca4be7324f913903c8de237.zip
handle max message payload + show filename label
Diffstat (limited to 'src/components')
-rw-r--r--src/components/chatinput.cpp32
-rw-r--r--src/components/chatinput.hpp1
-rw-r--r--src/components/chatwindow.cpp15
3 files changed, 40 insertions, 8 deletions
diff --git a/src/components/chatinput.cpp b/src/components/chatinput.cpp
index fc5ef38..04ba0d9 100644
--- a/src/components/chatinput.cpp
+++ b/src/components/chatinput.cpp
@@ -2,7 +2,6 @@
#include "abaddon.hpp"
#include "constants.hpp"
#include <filesystem>
-#include <utility>
ChatInputText::ChatInputText() {
get_style_context()->add_class("message-input");
@@ -96,6 +95,8 @@ ChatInputAttachmentContainer::ChatInputAttachmentContainer()
: m_box(Gtk::ORIENTATION_HORIZONTAL) {
get_style_context()->add_class("attachment-container");
+ m_box.set_halign(Gtk::ALIGN_START);
+
add(m_box);
m_box.show();
@@ -194,16 +195,25 @@ ChatInputAttachmentContainer::type_signal_emptied ChatInputAttachmentContainer::
ChatInputAttachmentItem::ChatInputAttachmentItem(const Glib::RefPtr<Gio::File> &file)
: m_file(file)
, m_img(Gtk::make_managed<Gtk::Image>())
- , m_type(ChatSubmitParams::ExtantFile) {
+ , m_type(ChatSubmitParams::ExtantFile)
+ , m_box(Gtk::ORIENTATION_VERTICAL) {
get_style_context()->add_class("attachment-item");
set_size_request(AttachmentItemSize, AttachmentItemSize);
- m_box.set_halign(Gtk::ALIGN_CENTER);
+ set_halign(Gtk::ALIGN_START);
+ m_box.set_hexpand(true);
+ m_box.set_halign(Gtk::ALIGN_FILL);
m_box.set_valign(Gtk::ALIGN_CENTER);
m_box.add(*m_img);
+ m_box.add(m_label);
add(m_box);
show_all_children();
+ m_label.set_max_width_chars(0); // will constrain to given size
+ m_label.set_ellipsize(Pango::ELLIPSIZE_MIDDLE);
+ m_label.set_margin_start(7);
+ m_label.set_margin_end(7);
+
m_img->property_icon_name() = "document-send-symbolic";
m_img->property_icon_size() = Gtk::ICON_SIZE_DIALOG; // todo figure out how to not use this weird property??? i dont know how icons work (screw your theme)
@@ -217,7 +227,9 @@ ChatInputAttachmentItem::ChatInputAttachmentItem(const Glib::RefPtr<Gio::File> &
: m_file(file)
, m_img(Gtk::make_managed<Gtk::Image>())
, m_type(is_extant ? ChatSubmitParams::ExtantFile : ChatSubmitParams::PastedImage)
- , m_filename("unknown.png") {
+ , m_filename("unknown.png")
+ , m_label("unknown.png")
+ , m_box(Gtk::ORIENTATION_VERTICAL) {
get_style_context()->add_class("attachment-item");
int outw, outh;
@@ -225,12 +237,20 @@ ChatInputAttachmentItem::ChatInputAttachmentItem(const Glib::RefPtr<Gio::File> &
m_img->property_pixbuf() = pb->scale_simple(outw, outh, Gdk::INTERP_BILINEAR);
set_size_request(AttachmentItemSize, AttachmentItemSize);
- m_box.set_halign(Gtk::ALIGN_CENTER);
+ set_halign(Gtk::ALIGN_START);
+ m_box.set_hexpand(true);
+ m_box.set_halign(Gtk::ALIGN_FILL);
m_box.set_valign(Gtk::ALIGN_CENTER);
m_box.add(*m_img);
+ m_box.add(m_label);
add(m_box);
show_all_children();
+ m_label.set_max_width_chars(0); // will constrain to given size
+ m_label.set_ellipsize(Pango::ELLIPSIZE_MIDDLE);
+ m_label.set_margin_start(7);
+ m_label.set_margin_end(7);
+
if (is_extant)
SetFilenameFromFile();
@@ -262,6 +282,7 @@ void ChatInputAttachmentItem::RemoveIfTemp() {
void ChatInputAttachmentItem::SetFilenameFromFile() {
auto info = m_file->query_info(G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
m_filename = info->get_attribute_string(G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
+ m_label.set_text(m_filename);
}
void ChatInputAttachmentItem::SetupMenu() {
@@ -275,6 +296,7 @@ void ChatInputAttachmentItem::SetupMenu() {
const auto name = Abaddon::Get().ShowTextPrompt("Enter new filename for attachment", "Enter filename", m_filename);
if (name.has_value()) {
m_filename = *name;
+ m_label.set_text(m_filename);
UpdateTooltip();
}
});
diff --git a/src/components/chatinput.hpp b/src/components/chatinput.hpp
index 2b88fd1..d8484b8 100644
--- a/src/components/chatinput.hpp
+++ b/src/components/chatinput.hpp
@@ -24,6 +24,7 @@ private:
Gtk::MenuItem m_menu_set_filename;
Gtk::Box m_box;
+ Gtk::Label m_label;
Gtk::Image *m_img = nullptr;
Glib::RefPtr<Gio::File> m_file;
diff --git a/src/components/chatwindow.cpp b/src/components/chatwindow.cpp
index 38e0247..b68ceba 100644
--- a/src/components/chatwindow.cpp
+++ b/src/components/chatwindow.cpp
@@ -250,11 +250,20 @@ bool ChatWindow::OnInputSubmit(ChatSubmitParams data) {
int restriction = std::max(nitro_restriction, guild_restriction);
+ goffset total_size = 0;
for (const auto &attachment : data.Attachments) {
const auto info = attachment.File->query_info();
- if (info && info->get_size() > restriction) {
- m_input->IndicateTooLarge();
- return false;
+ if (info) {
+ const auto size = info->get_size();
+ if (size > restriction) {
+ m_input->IndicateTooLarge();
+ return false;
+ }
+ total_size += size;
+ if (total_size > MaxMessagePayloadSize) {
+ m_input->IndicateTooLarge();
+ return false;
+ }
}
}