From 7c2362a851c279c6294b009efc552c4dad8e1178 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Wed, 4 Aug 2021 12:44:20 -0500 Subject: [PATCH] Add 'Room info' dialogue Fixes #55 --- application/AppMessages.h | 3 + application/Makefile | 1 + application/Server.cpp | 24 +++- .../windows/ConversationInfoWindow.cpp | 103 ++++++++++++++++++ application/windows/ConversationInfoWindow.h | 40 +++++++ application/windows/MainWindow.cpp | 1 - data/misc/Templates.rdef | 7 ++ 7 files changed, 172 insertions(+), 7 deletions(-) create mode 100644 application/windows/ConversationInfoWindow.cpp create mode 100644 application/windows/ConversationInfoWindow.h diff --git a/application/AppMessages.h b/application/AppMessages.h index dc8d43d..36b08dd 100644 --- a/application/AppMessages.h +++ b/application/AppMessages.h @@ -56,6 +56,9 @@ const uint32 APP_REQUEST_HELP = 'CYhm'; //! Display a "user info" window const uint32 APP_USER_INFO = 'CYuw'; +//! Display a "room info" window +const uint32 APP_ROOM_INFO = 'CYrw'; + //! Edit the contact roster const uint32 APP_EDIT_ROSTER = 'CYer'; diff --git a/application/Makefile b/application/Makefile index 47fc518..6b06179 100644 --- a/application/Makefile +++ b/application/Makefile @@ -76,6 +76,7 @@ SRCS = \ application/views/UserListView.cpp \ application/views/UserPopUp.cpp \ application/windows/AboutWindow.cpp \ + application/windows/ConversationInfoWindow.cpp \ application/windows/MainWindow.cpp \ application/windows/PreferencesWindow.cpp \ application/windows/RosterEditWindow.cpp \ diff --git a/application/Server.cpp b/application/Server.cpp index f208c45..543b94a 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -28,9 +28,10 @@ #include "Account.h" #include "AccountManager.h" #include "AppMessages.h" +#include "AppPreferences.h" #include "Cardie.h" #include "ChatProtocol.h" -#include "AppPreferences.h" +#include "ConversationInfoWindow.h" #include "ChatProtocolMessages.h" #include "Flags.h" #include "ImageCache.h" @@ -69,11 +70,13 @@ Server::Server() } // Loading room pop-up items - BMessage leave; - size_t leaveSize; - const void* leaveBuff = res.LoadResource(B_MESSAGE_TYPE, 1120, &leaveSize); - leave.Unflatten((const char*)leaveBuff); - fChatItems.AddItem(new BMessage(leave)); + for (int i = 0; i < 2; i++) { + size_t size; + BMessage temp; + const void* buff = res.LoadResource(B_MESSAGE_TYPE, 1120 + i, &size); + temp.Unflatten((const char*)buff); + fChatItems.AddItem(new BMessage(temp)); + } // Loading default chat commands for (int i = 0; i < 9; i++) { @@ -165,6 +168,15 @@ Server::Filter(BMessage* message, BHandler **target) accountManager->ReplicantStatusNotify(accountManager->Status()); break; } + case APP_ROOM_INFO: + { + Conversation* chat = _EnsureConversation(message); + if (chat != NULL) { + ConversationInfoWindow* win = new ConversationInfoWindow(chat); + win->Show(); + } + break; + } case APP_USER_INFO: { User* user = _EnsureUser(message); diff --git a/application/windows/ConversationInfoWindow.cpp b/application/windows/ConversationInfoWindow.cpp new file mode 100644 index 0000000..6ea4eaf --- /dev/null +++ b/application/windows/ConversationInfoWindow.cpp @@ -0,0 +1,103 @@ +/* + * Copyright 2021, Jaidyn Levesque + * All rights reserved. Distributed under the terms of the MIT license. + */ + +#include "ConversationInfoWindow.h" + +#include "Conversation.h" + +#include + +#include +#include +#include +#include +#include + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "ConversationInfoWindow" + + +ConversationInfoWindow::ConversationInfoWindow(Conversation* chat) + : + BWindow(BRect(200, 200, 300, 400), + B_TRANSLATE("Room information"), B_FLOATING_WINDOW, + B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), + fChat(chat) +{ + _InitInterface(); + CenterOnScreen(); + + chat->RegisterObserver(this); +} + + +ConversationInfoWindow::~ConversationInfoWindow() +{ + fChat->UnregisterObserver(this); +} + + +void +ConversationInfoWindow::_InitInterface() +{ + fIcon = new BitmapView("roomIcon"); + fIcon->SetBitmap(fChat->IconBitmap()); + + fNameLabel = new BStringView("nameLabel", fChat->GetName()); + fNameLabel->SetFont(be_bold_font); + + fIdLabel = new BTextView("idLabel", be_fixed_font, NULL, B_WILL_DRAW); + fIdLabel->SetWordWrap(false); + fIdLabel->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); + fIdLabel->MakeEditable(false); + _SetIdLabel(fChat->GetId()); + + fUserCountLabel = new BStringView("userCountLabel", ""); + _SetUserCountLabel(fChat->Users().CountItems()); + + // Centering is still my lyfeee + fNameLabel->SetExplicitAlignment(BAlignment(B_ALIGN_CENTER, B_ALIGN_TOP)); + fIdLabel->SetExplicitAlignment(BAlignment(B_ALIGN_CENTER, B_ALIGN_TOP)); + fUserCountLabel->SetExplicitAlignment(BAlignment(B_ALIGN_CENTER, B_ALIGN_TOP)); + + + BLayoutBuilder::Group<>(this, B_HORIZONTAL, 10) + .SetInsets(B_USE_DEFAULT_SPACING) + .AddGroup(B_VERTICAL) + .Add(fNameLabel) + .Add(fIdLabel) + .AddGlue() + .End() + .AddGroup(B_VERTICAL) + .AddGroup(B_VERTICAL) + .Add(fIcon) + .Add(fUserCountLabel) + .End() + .End(); +} + + +void +ConversationInfoWindow::_SetIdLabel(BString id) +{ + fIdLabel->SetText(id); + fIdLabel->SetExplicitMinSize( + BSize(be_fixed_font->StringWidth(id) + 5, B_SIZE_UNSET)); +} + + +void +ConversationInfoWindow::_SetUserCountLabel(int32 userCount) +{ + BStringFormat pmFormat(B_TRANSLATE("{0, plural," + "=1{One lonely user}" + "=2{Two partners}" + "other{# members}}")); + + BString label; + pmFormat.Format(label, userCount); + fUserCountLabel->SetText(label); +} diff --git a/application/windows/ConversationInfoWindow.h b/application/windows/ConversationInfoWindow.h new file mode 100644 index 0000000..2392f53 --- /dev/null +++ b/application/windows/ConversationInfoWindow.h @@ -0,0 +1,40 @@ +/* + * Copyright 2021, Jaidyn Levesque + * All rights reserved. Distributed under the terms of the MIT license. + */ +#ifndef _CONVERSATION_INFO_WINDOW_H +#define _CONVERSATION_INFO_WINDOW_H + +#include + +#include "Observer.h" + +class BStringView; +class BTextView; + +class BitmapView; +class Conversation; +class UrlTextView; + + +class ConversationInfoWindow : public BWindow, public Observer { +public: + ConversationInfoWindow(Conversation* chat); + ~ConversationInfoWindow(); + +// virtual void Observer +private: + void _InitInterface(); + + void _SetIdLabel(BString id); + void _SetUserCountLabel(int32 userCount); + + Conversation* fChat; + + BStringView* fNameLabel; + BStringView* fUserCountLabel; + BTextView* fIdLabel; + BitmapView* fIcon; +}; + +#endif // _CONVERSATION_INFO_WINDOW_H diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index b283daa..b32eba1 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include "AccountManager.h" diff --git a/data/misc/Templates.rdef b/data/misc/Templates.rdef index 67b3f06..ff69dac 100644 --- a/data/misc/Templates.rdef +++ b/data/misc/Templates.rdef @@ -117,6 +117,13 @@ resource(1106) message // Room pop-up menu items resource(1120) message +{ + "class" = "BMenuItem", + "_label" = "Room info…", + "_msg" = message('CYrw'), + bool "x_to_protocol" = false +}; +resource(1121) message { "class" = "BMenuItem", "_label" = "Leave chat",