From 41776fbd023df1c4a70ffa46e8f81c6aea9f7b7f Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 7 Jul 2022 03:09:54 -0400 Subject: add upload progress bar --- res/css/main.css | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'res/css/main.css') diff --git a/res/css/main.css b/res/css/main.css index 1035b37..a3d0421 100644 --- a/res/css/main.css +++ b/res/css/main.css @@ -323,3 +323,18 @@ .channel-tab-switcher tab > button:hover { background-color: alpha(#ff0000, 0.5); } + +.message-progress { + border: none; +} + +.message-progress trough { + border: none; + background-color: transparent; +} + +.message-progress progress { + border: none; + background-color: #dd3300; + margin-left: 1px; +} -- cgit v1.2.3 From 02ce353c6d35af004dc1b6f5ae9f68fbb8540b54 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 9 Jul 2022 01:57:56 -0400 Subject: check nitro size restriction + fix replying border --- res/css/main.css | 5 +++++ src/components/chatinput.cpp | 17 +++++++++++++++++ src/components/chatinput.hpp | 4 ++++ src/components/chatwindow.cpp | 24 +++++++++++++++++++++--- src/constants.hpp | 5 +++++ 5 files changed, 52 insertions(+), 3 deletions(-) (limited to 'res/css/main.css') diff --git a/res/css/main.css b/res/css/main.css index a3d0421..142dede 100644 --- a/res/css/main.css +++ b/res/css/main.css @@ -102,12 +102,17 @@ background-color: #242424; color: #adadad; border-radius: 15px; + border: 1px solid transparent; } .message-input.replying { border: 1px solid #026FB9; } +.message-input.bad-input { + border: 1px solid #dd3300; +} + .message-input { padding: 0px 0px 0px 5px; } diff --git a/src/components/chatinput.cpp b/src/components/chatinput.cpp index b71a234..fc5ef38 100644 --- a/src/components/chatinput.cpp +++ b/src/components/chatinput.cpp @@ -392,6 +392,23 @@ void ChatInput::AddAttachment(const Glib::RefPtr &file) { } } +void ChatInput::IndicateTooLarge() { + m_input.get_style_context()->add_class("bad-input"); + const auto cb = [this] { + m_input.get_style_context()->remove_class("bad-input"); + }; + Glib::signal_timeout().connect_seconds_once(sigc::track_obj(cb, *this), 2); +} + +void ChatInput::StartReplying() { + m_input.grab_focus(); + m_input.get_style_context()->add_class("replying"); +} + +void ChatInput::StopReplying() { + m_input.get_style_context()->remove_class("replying"); +} + bool ChatInput::AddFileAsImageAttachment(const Glib::RefPtr &file) { try { const auto read_stream = file->read(); diff --git a/src/components/chatinput.hpp b/src/components/chatinput.hpp index 625161a..2b88fd1 100644 --- a/src/components/chatinput.hpp +++ b/src/components/chatinput.hpp @@ -102,6 +102,10 @@ public: Glib::RefPtr GetBuffer(); bool ProcessKeyPress(GdkEventKey *event); void AddAttachment(const Glib::RefPtr &file); + void IndicateTooLarge(); + + void StartReplying(); + void StopReplying(); private: bool AddFileAsImageAttachment(const Glib::RefPtr &file); diff --git a/src/components/chatwindow.cpp b/src/components/chatwindow.cpp index 5cbeea1..61d3712 100644 --- a/src/components/chatwindow.cpp +++ b/src/components/chatwindow.cpp @@ -4,6 +4,7 @@ #include "ratelimitindicator.hpp" #include "chatinput.hpp" #include "chatlist.hpp" +#include "constants.hpp" #ifdef WITH_LIBHANDY #include "channeltabswitcherhandy.hpp" #endif @@ -222,6 +223,24 @@ Snowflake ChatWindow::GetActiveChannel() const { } bool ChatWindow::OnInputSubmit(ChatSubmitParams data) { + int restriction = BaseAttachmentSizeLimit; + const auto nitro = Abaddon::Get().GetDiscordClient().GetUserData().PremiumType; + if (!nitro.has_value() || nitro == EPremiumType::None) { + restriction = BaseAttachmentSizeLimit; + } else if (nitro == EPremiumType::NitroClassic) { + restriction = NitroClassicAttachmentSizeLimit; + } else if (nitro == EPremiumType::Nitro) { + restriction = NitroAttachmentSizeLimit; + } + + 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 (!m_rate_limit_indicator->CanSpeak()) return false; @@ -255,8 +274,7 @@ void ChatWindow::StartReplying(Snowflake message_id) { const auto author = discord.GetUser(message.Author.ID); m_replying_to = message_id; m_is_replying = true; - m_input->grab_focus(); - m_input->get_style_context()->add_class("replying"); + m_input->StartReplying(); if (author.has_value()) m_input_indicator->SetCustomMarkup("Replying to " + author->GetEscapedBoldString()); else @@ -266,7 +284,7 @@ void ChatWindow::StartReplying(Snowflake message_id) { void ChatWindow::StopReplying() { m_is_replying = false; m_replying_to = Snowflake::Invalid; - m_input->get_style_context()->remove_class("replying"); + m_input->StopReplying(); m_input_indicator->ClearCustom(); } diff --git a/src/constants.hpp b/src/constants.hpp index 30de2ae..9b2413d 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -3,3 +3,8 @@ constexpr static uint64_t SnowflakeSplitDifference = 600; constexpr static int MaxMessagesForChatCull = 50; // this has to be 50 (for now) cuz that magic number is used in a couple other places and i dont feel like replacing them constexpr static int AttachmentItemSize = 128; +constexpr static int BaseAttachmentSizeLimit = 8 * 1024 * 1024; +constexpr static int NitroClassicAttachmentSizeLimit = 50 * 1024 * 1024; +constexpr static int NitroAttachmentSizeLimit = 100 * 1024 * 1024; +constexpr static int BoostLevel2AttachmentSizeLimit = 50 * 1024 * 1024; +constexpr static int BoostLevel3AttachmentSizeLimit = 100 * 1024 * 1024; -- cgit v1.2.3 From 111399cf4a161b8bca2ab938e79b943af4aa4d3d Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 14 Jul 2022 03:13:27 -0400 Subject: move progress bar so it doesnt conflict with other stuff --- res/css/main.css | 1 + 1 file changed, 1 insertion(+) (limited to 'res/css/main.css') diff --git a/res/css/main.css b/res/css/main.css index 142dede..968296d 100644 --- a/res/css/main.css +++ b/res/css/main.css @@ -331,6 +331,7 @@ .message-progress { border: none; + margin-bottom: -8px; } .message-progress trough { -- cgit v1.2.3 From 3487353fc79abb32481282be9d3ba4d54730b1e2 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sun, 7 Aug 2022 02:14:26 -0400 Subject: css tweaks --- res/css/main.css | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'res/css/main.css') diff --git a/res/css/main.css b/res/css/main.css index 968296d..6d693bd 100644 --- a/res/css/main.css +++ b/res/css/main.css @@ -101,10 +101,15 @@ .message-input, .message-input textview, .message-input textview text { background-color: #242424; color: #adadad; - border-radius: 15px; + border-radius: 3px; border: 1px solid transparent; } +.message-input { + border: 1px solid #444444; + margin-right: 15px; +} + .message-input.replying { border: 1px solid #026FB9; } -- cgit v1.2.3 From 344f2694141aa0cc8fc214dfd8ce2011df1a8079 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sun, 7 Aug 2022 02:16:20 -0400 Subject: add file picker to chat input --- res/css/main.css | 6 ++- src/components/chatinput.cpp | 104 ++++++++++++++++++++++++++++++++++++++++--- src/components/chatinput.hpp | 26 ++++++++++- 3 files changed, 128 insertions(+), 8 deletions(-) (limited to 'res/css/main.css') diff --git a/res/css/main.css b/res/css/main.css index 6d693bd..3765498 100644 --- a/res/css/main.css +++ b/res/css/main.css @@ -118,8 +118,12 @@ border: 1px solid #dd3300; } +.message-input-browse-icon { + color: #b9bbbe; +} + .message-input { - padding: 0px 0px 0px 5px; + padding: 0px 0px 0px 30px; } .members { diff --git a/src/components/chatinput.cpp b/src/components/chatinput.cpp index 13e2550..7ecd4de 100644 --- a/src/components/chatinput.cpp +++ b/src/components/chatinput.cpp @@ -91,6 +91,95 @@ ChatInputText::type_signal_image_paste ChatInputText::signal_image_paste() { return m_signal_image_paste; } +ChatInputTextContainer::ChatInputTextContainer() { + // triple hack !!! + auto cb = [this](GdkEventKey *e) -> bool { + return event(reinterpret_cast(e)); + }; + m_input.signal_key_press_event().connect(cb, false); + + m_upload_img.property_icon_name() = "document-send-symbolic"; + m_upload_img.property_icon_size() = Gtk::ICON_SIZE_LARGE_TOOLBAR; + m_upload_img.get_style_context()->add_class("message-input-browse-icon"); + + AddPointerCursor(m_upload_ev); + + m_upload_ev.signal_button_press_event().connect([this](GdkEventButton *ev) -> bool { + if (ev->button == GDK_BUTTON_PRIMARY) { + ShowFileChooser(); + return true; + } + return false; + }); + + m_upload_ev.add(m_upload_img); + add_overlay(m_upload_ev); + add(m_input); + + show_all_children(); + + // stop the overlay from using (start) padding + signal_get_child_position().connect(sigc::mem_fun(*this, &ChatInputTextContainer::GetChildPosition), false); +} + +void ChatInputTextContainer::ShowFileChooser() { + auto dlg = Gtk::FileChooserNative::create("Choose file", Gtk::FILE_CHOOSER_ACTION_OPEN); + dlg->set_select_multiple(true); + dlg->set_modal(true); + + dlg->signal_response().connect([this, dlg](int response) { + if (response == Gtk::RESPONSE_ACCEPT) { + for (const auto &file : dlg->get_files()) { + m_signal_add_attachment.emit(file); + } + } + }); + + auto filter_all = Gtk::FileFilter::create(); + filter_all->set_name("All files (*.*)"); + filter_all->add_pattern("*.*"); + dlg->add_filter(filter_all); + + dlg->run(); +} + +ChatInputText &ChatInputTextContainer::Get() { + return m_input; +} + +bool ChatInputTextContainer::GetChildPosition(Gtk::Widget *child, Gdk::Rectangle &pos) { + Gtk::Allocation main_alloc; + { + auto *grandchild = m_input.get_child(); + int x, y; + if (grandchild->translate_coordinates(m_input, 0, 0, x, y)) { + main_alloc.set_x(x); + main_alloc.set_y(y); + } else { + main_alloc.set_x(0); + main_alloc.set_y(0); + } + main_alloc.set_width(grandchild->get_allocated_width()); + main_alloc.set_height(grandchild->get_allocated_height()); + } + + Gtk::Requisition min, req; + child->get_preferred_size(min, req); + + // yummy hardcoded values + pos.set_x(5); + pos.set_width(std::max(min.width, std::min(main_alloc.get_width(), req.width))); + + pos.set_y(12); + pos.set_height(std::max(min.height, std::min(main_alloc.get_height(), req.height))); + + return true; +} + +ChatInputTextContainer::type_signal_add_attachment ChatInputTextContainer::signal_add_attachment() { + return m_signal_add_attachment; +} + ChatInputAttachmentContainer::ChatInputAttachmentContainer() : m_box(Gtk::ORIENTATION_HORIZONTAL) { get_style_context()->add_class("attachment-container"); @@ -336,12 +425,15 @@ ChatInputAttachmentItem::type_signal_item_removed ChatInputAttachmentItem::signa ChatInput::ChatInput() : Gtk::Box(Gtk::ORIENTATION_VERTICAL) { - m_input.signal_escape().connect([this] { + m_input.signal_add_attachment().connect(sigc::mem_fun(*this, &ChatInput::AddAttachment)); + + m_input.Get().signal_escape().connect([this] { m_attachments.Clear(); m_attachments_revealer.set_reveal_child(false); m_signal_escape.emit(); }); - m_input.signal_submit().connect([this](const Glib::ustring &input) -> bool { + + m_input.Get().signal_submit().connect([this](const Glib::ustring &input) -> bool { ChatSubmitParams data; data.Message = input; data.Attachments = m_attachments.GetAttachments(); @@ -362,7 +454,7 @@ ChatInput::ChatInput() add(m_input); show_all_children(); - m_input.signal_image_paste().connect([this](const Glib::RefPtr &pb) { + m_input.Get().signal_image_paste().connect([this](const Glib::RefPtr &pb) { const bool can_attach_files = m_signal_check_permission.emit(Permission::ATTACH_FILES); if (can_attach_files && m_attachments.AddImage(pb)) @@ -381,15 +473,15 @@ ChatInput::ChatInput() } void ChatInput::InsertText(const Glib::ustring &text) { - m_input.InsertText(text); + m_input.Get().InsertText(text); } Glib::RefPtr ChatInput::GetBuffer() { - return m_input.GetBuffer(); + return m_input.Get().GetBuffer(); } bool ChatInput::ProcessKeyPress(GdkEventKey *event) { - return m_input.ProcessKeyPress(event); + return m_input.Get().ProcessKeyPress(event); } void ChatInput::AddAttachment(const Glib::RefPtr &file) { diff --git a/src/components/chatinput.hpp b/src/components/chatinput.hpp index d8484b8..82ea2fd 100644 --- a/src/components/chatinput.hpp +++ b/src/components/chatinput.hpp @@ -95,6 +95,30 @@ private: type_signal_image_paste m_signal_image_paste; }; +// file upload, text +class ChatInputTextContainer : public Gtk::Overlay { +public: + ChatInputTextContainer(); + + // not proxying everythign lol!! + ChatInputText &Get(); + +private: + void ShowFileChooser(); + bool GetChildPosition(Gtk::Widget *child, Gdk::Rectangle &pos); + + Gtk::EventBox m_upload_ev; + Gtk::Image m_upload_img; + ChatInputText m_input; + +public: + using type_signal_add_attachment = sigc::signal>; + type_signal_add_attachment signal_add_attachment(); + +private: + type_signal_add_attachment m_signal_add_attachment; +}; + class ChatInput : public Gtk::Box { public: ChatInput(); @@ -113,7 +137,7 @@ private: Gtk::Revealer m_attachments_revealer; ChatInputAttachmentContainer m_attachments; - ChatInputText m_input; + ChatInputTextContainer m_input; public: using type_signal_submit = sigc::signal; -- cgit v1.2.3 From 955b9239b9eac748d3e5ac4dc56864c906c81393 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Mon, 8 Aug 2022 00:40:20 -0400 Subject: hide browse icon when not in channel with perms --- res/css/main.css | 7 ++++++- src/components/chatinput.cpp | 17 +++++++++++++++++ src/components/chatinput.hpp | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) (limited to 'res/css/main.css') diff --git a/res/css/main.css b/res/css/main.css index 3765498..9398d48 100644 --- a/res/css/main.css +++ b/res/css/main.css @@ -122,7 +122,12 @@ color: #b9bbbe; } -.message-input { +/* i dont think theres a way to circumvent having to do this to adjust around the browse icon */ +.message-input:not(.with-browser-icon) { + padding: 0px 0px 0px 5px; +} + +.message-input.with-browse-icon { padding: 0px 0px 0px 30px; } diff --git a/src/components/chatinput.cpp b/src/components/chatinput.cpp index 75dda8d..87892e0 100644 --- a/src/components/chatinput.cpp +++ b/src/components/chatinput.cpp @@ -149,6 +149,14 @@ ChatInputText &ChatInputTextContainer::Get() { return m_input; } +void ChatInputTextContainer::ShowChooserIcon() { + m_upload_ev.show(); +} + +void ChatInputTextContainer::HideChooserIcon() { + m_upload_ev.hide(); +} + bool ChatInputTextContainer::GetChildPosition(Gtk::Widget *child, Gdk::Rectangle &pos) { Gtk::Allocation main_alloc; { @@ -470,6 +478,8 @@ ChatInput::ChatInput() m_attachments.signal_emptied().connect([this] { m_attachments_revealer.set_reveal_child(false); }); + + SetActiveChannel(Snowflake::Invalid); } void ChatInput::InsertText(const Glib::ustring &text) { @@ -526,6 +536,13 @@ void ChatInput::IndicateTooLarge() { void ChatInput::SetActiveChannel(Snowflake id) { m_active_channel = id; + if (CanAttachFiles()) { + m_input.Get().get_style_context()->add_class("with-browse-icon"); + m_input.ShowChooserIcon(); + } else { + m_input.Get().get_style_context()->remove_class("with-browse-icon"); + m_input.HideChooserIcon(); + } } void ChatInput::StartReplying() { diff --git a/src/components/chatinput.hpp b/src/components/chatinput.hpp index f6c4358..807f958 100644 --- a/src/components/chatinput.hpp +++ b/src/components/chatinput.hpp @@ -103,6 +103,9 @@ public: // not proxying everythign lol!! ChatInputText &Get(); + void ShowChooserIcon(); + void HideChooserIcon(); + private: void ShowFileChooser(); bool GetChildPosition(Gtk::Widget *child, Gdk::Rectangle &pos); -- cgit v1.2.3 From f60cea2216dd9677cb9105364cdaa778a0c187db Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Wed, 10 Aug 2022 00:03:04 -0400 Subject: control icon pos in css --- res/css/main.css | 2 ++ src/components/chatinput.cpp | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'res/css/main.css') diff --git a/res/css/main.css b/res/css/main.css index 9398d48..ace3b0b 100644 --- a/res/css/main.css +++ b/res/css/main.css @@ -120,6 +120,8 @@ .message-input-browse-icon { color: #b9bbbe; + margin-left: 5px; + margin-top: 11px; } /* i dont think theres a way to circumvent having to do this to adjust around the browse icon */ diff --git a/src/components/chatinput.cpp b/src/components/chatinput.cpp index 87892e0..2466965 100644 --- a/src/components/chatinput.cpp +++ b/src/components/chatinput.cpp @@ -176,11 +176,10 @@ bool ChatInputTextContainer::GetChildPosition(Gtk::Widget *child, Gdk::Rectangle Gtk::Requisition min, req; child->get_preferred_size(min, req); - // yummy hardcoded values - pos.set_x(5); + // let css move it around + pos.set_x(0); + pos.set_y(0); pos.set_width(std::max(min.width, std::min(main_alloc.get_width(), req.width))); - - pos.set_y(12); pos.set_height(std::max(min.height, std::min(main_alloc.get_height(), req.height))); return true; -- cgit v1.2.3