diff --git a/src/discord/Attachment.hpp b/src/discord/Attachment.hpp index b11f18c..e3231c1 100644 --- a/src/discord/Attachment.hpp +++ b/src/discord/Attachment.hpp @@ -47,7 +47,7 @@ class Attachment return m_previewWidth != m_width || m_previewHeight != m_height; } - bool IsImage() + bool IsImage() const { return m_contentType == ContentType::PNG || diff --git a/src/discord/LocalSettings.cpp b/src/discord/LocalSettings.cpp index 004959b..9abae70 100644 --- a/src/discord/LocalSettings.cpp +++ b/src/discord/LocalSettings.cpp @@ -92,6 +92,15 @@ bool LocalSettings::Load() if (j.contains("UserScale")) m_userScale = int(j["UserScale"]); + if (j.contains("ShowAttachmentImages")) + m_bShowAttachmentImages = j["ShowAttachmentImages"]; + + if (j.contains("ShowEmbedImages")) + m_bShowEmbedImages = j["ShowEmbedImages"]; + + if (j.contains("ShowEmbedContent")) + m_bShowEmbedContent = j["ShowEmbedContent"]; + if (m_bSaveWindowSize) { if (j.contains("WindowWidth")) @@ -148,6 +157,9 @@ bool LocalSettings::Save() j["WatermarkAlignment"] = int(m_imageAlignment); j["UserScale"] = m_userScale; j["AddExtraHeaders"] = m_bAddExtraHeaders; + j["ShowAttachmentImages"] = m_bShowAttachmentImages; + j["ShowEmbedImages"] = m_bShowEmbedImages; + j["ShowEmbedContent"] = m_bShowEmbedContent; if (m_bSaveWindowSize) { j["WindowWidth"] = m_width; diff --git a/src/discord/LocalSettings.hpp b/src/discord/LocalSettings.hpp index 0a6b60e..ad57273 100644 --- a/src/discord/LocalSettings.hpp +++ b/src/discord/LocalSettings.hpp @@ -151,6 +151,24 @@ class LocalSettings void SetCompactMemberList(bool b) { m_bCompactMemberList = b; } + bool ShowAttachmentImages() const { + return m_bShowAttachmentImages; + } + bool ShowEmbedImages() const { + return m_bShowEmbedImages; + } + bool ShowEmbedContent() const { + return m_bShowEmbedContent; + } + void SetShowAttachmentImages(bool b) { + m_bShowAttachmentImages = b; + } + void SetShowEmbedImages(bool b) { + m_bShowEmbedImages = b; + } + void SetShowEmbedContent(bool b) { + m_bShowEmbedContent = b; + } private: std::string m_token; @@ -171,6 +189,9 @@ class LocalSettings bool m_bShowScrollBarOnGuildList = false; bool m_bCompactMemberList = false; bool m_bAddExtraHeaders = true; + bool m_bShowAttachmentImages = true; + bool m_bShowEmbedImages = true; + bool m_bShowEmbedContent = true; time_t m_remindUpdatesOn = 0; int m_width = 1000; int m_height = 700; diff --git a/src/resource.rc b/src/resource.rc index 465e891..b0668f6 100644 --- a/src/resource.rc +++ b/src/resource.rc @@ -667,12 +667,12 @@ BEGIN "Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | WS_TABSTOP,12,18,236,18 GROUPBOX "Display Images",IDC_STATIC,6,43,248,41 CONTROL "When uploaded directly to Discord",IDC_IMAGES_WHEN_UPLOADED, - "Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,12,55,236,10 + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,55,236,10 CONTROL "When posted as links in chat",IDC_IMAGES_WHEN_EMBEDDED, - "Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,12,68,236,10 + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,68,236,10 GROUPBOX "Embed Settings",IDC_STATIC,6,90,248,27 CONTROL "Show embeds and preview links in chat",IDC_SHOW_EMBEDS, - "Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,12,101,236,10 + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,101,236,10 END IDD_DIALOG_WINDOWSETTINGS DIALOGEX 0, 0, 260, 242 diff --git a/src/windows/MessageList.cpp b/src/windows/MessageList.cpp index 7a4ff75..8046dc7 100644 --- a/src/windows/MessageList.cpp +++ b/src/windows/MessageList.cpp @@ -227,10 +227,18 @@ void RichEmbedItem::Measure(HDC hdc, RECT& messageRect, bool isCompact) int maxImgWidth = std::max(int(rcItem.right - rcItem.left), 10); // Calculate the embedded image. - if (m_pEmbed->m_bHasThumbnail) - m_thumbnailSize = EnsureMaximumSize(m_pEmbed->m_thumbnailWidth, m_pEmbed->m_thumbnailHeight, maxImgWidth, maxHeight); - else if (m_pEmbed->m_bHasImage) - m_imageSize = EnsureMaximumSize(m_pEmbed->m_imageWidth, m_pEmbed->m_imageHeight, maxImgWidth, maxHeight); + if (GetLocalSettings()->ShowEmbedImages()) + { + if (m_pEmbed->m_bHasThumbnail) + m_thumbnailSize = EnsureMaximumSize(m_pEmbed->m_thumbnailWidth, m_pEmbed->m_thumbnailHeight, maxImgWidth, maxHeight); + else if (m_pEmbed->m_bHasImage) + m_imageSize = EnsureMaximumSize(m_pEmbed->m_imageWidth, m_pEmbed->m_imageHeight, maxImgWidth, maxHeight); + } + else + { + m_thumbnailSize = { 0, 0 }; + m_imageSize = { 0, 0 }; + } sz.cx = std::max({ sz.cx, m_imageSize.cx, m_thumbnailSize.cx }); sz.cy = m_providerSize.cy; @@ -330,25 +338,27 @@ void RichEmbedItem::Draw(HDC hdc, RECT& messageRect, MessageList* pList) DrawText(hdc, m_description.GetWrapped(), -1, &rcText, DT_WORDBREAK | DT_WORD_ELLIPSIS); sizeY += m_descriptionSize.cy; } - if (m_thumbnailSize.cy) { - m_thumbnailResourceID = GetAvatarCache()->MakeIdentifier(m_pEmbed->m_thumbnailUrl); - GetAvatarCache()->AddImagePlace(m_thumbnailResourceID, eImagePlace::ATTACHMENTS, m_pEmbed->m_thumbnailProxiedUrl); - bool hasAlpha = false; - HBITMAP hbm = GetAvatarCache()->GetBitmapSpecial(m_pEmbed->m_thumbnailUrl, hasAlpha); - if (sizeY) sizeY += gap; - m_thumbnailRect = { rc.left, rc.top + sizeY, rc.left + m_thumbnailSize.cx, rc.top + sizeY + m_thumbnailSize.cy }; - DrawImageSpecial(hdc, hbm, m_thumbnailRect, hasAlpha); - sizeY += m_thumbnailSize.cy; - } - if (m_imageSize.cy) { - m_imageResourceID = GetAvatarCache()->MakeIdentifier(m_pEmbed->m_imageUrl); - GetAvatarCache()->AddImagePlace(m_imageResourceID, eImagePlace::ATTACHMENTS, m_pEmbed->m_imageProxiedUrl); - bool hasAlpha = false; - HBITMAP hbm = GetAvatarCache()->GetBitmapSpecial(m_pEmbed->m_imageUrl, hasAlpha); - if (sizeY) sizeY += gap; - m_imageRect = { rc.left, rc.top + sizeY, rc.left + m_imageSize.cx, rc.top + sizeY + m_imageSize.cy }; - DrawImageSpecial(hdc, hbm, m_imageRect, hasAlpha); - sizeY += m_imageSize.cy; + if (GetLocalSettings()->ShowEmbedImages()) { + if (m_thumbnailSize.cy) { + m_thumbnailResourceID = GetAvatarCache()->MakeIdentifier(m_pEmbed->m_thumbnailUrl); + GetAvatarCache()->AddImagePlace(m_thumbnailResourceID, eImagePlace::ATTACHMENTS, m_pEmbed->m_thumbnailProxiedUrl); + bool hasAlpha = false; + HBITMAP hbm = GetAvatarCache()->GetBitmapSpecial(m_pEmbed->m_thumbnailUrl, hasAlpha); + if (sizeY) sizeY += gap; + m_thumbnailRect = { rc.left, rc.top + sizeY, rc.left + m_thumbnailSize.cx, rc.top + sizeY + m_thumbnailSize.cy }; + DrawImageSpecial(hdc, hbm, m_thumbnailRect, hasAlpha); + sizeY += m_thumbnailSize.cy; + } + if (m_imageSize.cy) { + m_imageResourceID = GetAvatarCache()->MakeIdentifier(m_pEmbed->m_imageUrl); + GetAvatarCache()->AddImagePlace(m_imageResourceID, eImagePlace::ATTACHMENTS, m_pEmbed->m_imageProxiedUrl); + bool hasAlpha = false; + HBITMAP hbm = GetAvatarCache()->GetBitmapSpecial(m_pEmbed->m_imageUrl, hasAlpha); + if (sizeY) sizeY += gap; + m_imageRect = { rc.left, rc.top + sizeY, rc.left + m_imageSize.cx, rc.top + sizeY + m_imageSize.cy }; + DrawImageSpecial(hdc, hbm, m_imageRect, hasAlpha); + sizeY += m_imageSize.cy; + } } if (m_footerSize.cy) { SelectObject(hdc, g_ReplyTextFont); @@ -2684,6 +2694,9 @@ void MessageList::DrawMessage(HDC hdc, MessageItem& item, RECT& msgRect, RECT& c auto& embedVec = item.m_embedData; size_t sz = embedVec.size(); + if (!GetLocalSettings()->ShowEmbedContent()) + sz = 0; + embedRect.right = msgRect.right - ScaleByDPI(10); embedRect.top = embedRect.bottom; @@ -2745,8 +2758,12 @@ void MessageList::DrawMessage(HDC hdc, MessageItem& item, RECT& msgRect, RECT& c case ContentType::JPEG: case ContentType::WEBP: { - DrawImageAttachment(hdc, paintRect, attachItem, attachRect); - break; + if (GetLocalSettings()->ShowAttachmentImages()) + { + DrawImageAttachment(hdc, paintRect, attachItem, attachRect); + break; + } + // FALLTHROUGH } default: { @@ -4079,11 +4096,14 @@ void MessageList::AdjustHeightInfo(const MessageItem& msg, int& height, int& tex // also figure out embed size embedheight = 0; - for (auto& emb : msg.m_embedData) + if (GetLocalSettings()->ShowEmbedContent()) { - int inc = emb.m_size.cy + ScaleByDPI(5); - height += inc; - embedheight += inc; + for (auto& emb : msg.m_embedData) + { + int inc = emb.m_size.cy + ScaleByDPI(5); + height += inc; + embedheight += inc; + } } // also figure out attachment size @@ -4092,7 +4112,7 @@ void MessageList::AdjustHeightInfo(const MessageItem& msg, int& height, int& tex { // XXX improve? int inc = 0; - if (att.m_contentType == ContentType::BLOB) + if (!GetLocalSettings()->ShowAttachmentImages() || !att.IsImage()) inc = ATTACHMENT_HEIGHT + ATTACHMENT_GAP; else inc = att.m_previewHeight + ATTACHMENT_GAP; @@ -4370,8 +4390,11 @@ void MessageList::DetermineMessageMeasurements(MessageItem& mi, HDC _hdc, LPRECT ); const bool isCompact = IsCompact(); - for (auto& embed : mi.m_embedData) - embed.Measure(hdc, rect, isCompact); + + if (GetLocalSettings()->ShowEmbedContent()) { + for (auto& embed : mi.m_embedData) + embed.Measure(hdc, rect, isCompact); + } AdjustHeightInfo(mi, mi.m_height, mi.m_textHeight, mi.m_authHeight, mi.m_replyHeight, mi.m_attachHeight, mi.m_embedHeight); diff --git a/src/windows/OptionsDialog.cpp b/src/windows/OptionsDialog.cpp index 706cb45..5addf81 100644 --- a/src/windows/OptionsDialog.cpp +++ b/src/windows/OptionsDialog.cpp @@ -226,6 +226,13 @@ void WINAPI OnChildDialogInit(HWND hwndDlg) break; } + case PG_CHAT: + { + CheckDlgButton(hwndDlg, IDC_IMAGES_WHEN_UPLOADED, GetLocalSettings()->ShowAttachmentImages() ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_IMAGES_WHEN_EMBEDDED, GetLocalSettings()->ShowEmbedImages() ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_SHOW_EMBEDS, GetLocalSettings()->ShowEmbedContent() ? BST_CHECKED : BST_UNCHECKED); + break; + } case PG_WINDOW: { CheckDlgButton(hwndDlg, IDC_SAVE_WINDOW_SIZE, GetLocalSettings()->GetSaveWindowSize() ? BST_CHECKED : BST_UNCHECKED); @@ -439,6 +446,18 @@ INT_PTR CALLBACK ChildDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa GetLocalSettings()->SetDisableFormatting(IsDlgButtonChecked(hWnd, IDC_DISABLE_FORMATTING)); SendMessage(g_Hwnd, WM_RECALCMSGLIST, 0, 0); break; + case IDC_IMAGES_WHEN_UPLOADED: + GetLocalSettings()->SetShowAttachmentImages(IsDlgButtonChecked(hWnd, IDC_IMAGES_WHEN_UPLOADED)); + SendMessage(g_Hwnd, WM_RECALCMSGLIST, 0, 0); + break; + case IDC_IMAGES_WHEN_EMBEDDED: + GetLocalSettings()->SetShowEmbedImages(IsDlgButtonChecked(hWnd, IDC_IMAGES_WHEN_EMBEDDED)); + SendMessage(g_Hwnd, WM_RECALCMSGLIST, 0, 0); + break; + case IDC_SHOW_EMBEDS: + GetLocalSettings()->SetShowEmbedContent(IsDlgButtonChecked(hWnd, IDC_SHOW_EMBEDS)); + SendMessage(g_Hwnd, WM_RECALCMSGLIST, 0, 0); + break; } break; }