Add 'Room info' dialogue

Fixes #55
This commit is contained in:
Jaidyn Ann 2021-08-04 12:44:20 -05:00
parent d3f775d8b8
commit 7c2362a851
7 changed files with 172 additions and 7 deletions

View File

@ -56,6 +56,9 @@ const uint32 APP_REQUEST_HELP = 'CYhm';
//! Display a "user info" window //! Display a "user info" window
const uint32 APP_USER_INFO = 'CYuw'; const uint32 APP_USER_INFO = 'CYuw';
//! Display a "room info" window
const uint32 APP_ROOM_INFO = 'CYrw';
//! Edit the contact roster //! Edit the contact roster
const uint32 APP_EDIT_ROSTER = 'CYer'; const uint32 APP_EDIT_ROSTER = 'CYer';

View File

@ -76,6 +76,7 @@ SRCS = \
application/views/UserListView.cpp \ application/views/UserListView.cpp \
application/views/UserPopUp.cpp \ application/views/UserPopUp.cpp \
application/windows/AboutWindow.cpp \ application/windows/AboutWindow.cpp \
application/windows/ConversationInfoWindow.cpp \
application/windows/MainWindow.cpp \ application/windows/MainWindow.cpp \
application/windows/PreferencesWindow.cpp \ application/windows/PreferencesWindow.cpp \
application/windows/RosterEditWindow.cpp \ application/windows/RosterEditWindow.cpp \

View File

@ -28,9 +28,10 @@
#include "Account.h" #include "Account.h"
#include "AccountManager.h" #include "AccountManager.h"
#include "AppMessages.h" #include "AppMessages.h"
#include "AppPreferences.h"
#include "Cardie.h" #include "Cardie.h"
#include "ChatProtocol.h" #include "ChatProtocol.h"
#include "AppPreferences.h" #include "ConversationInfoWindow.h"
#include "ChatProtocolMessages.h" #include "ChatProtocolMessages.h"
#include "Flags.h" #include "Flags.h"
#include "ImageCache.h" #include "ImageCache.h"
@ -69,11 +70,13 @@ Server::Server()
} }
// Loading room pop-up items // Loading room pop-up items
BMessage leave; for (int i = 0; i < 2; i++) {
size_t leaveSize; size_t size;
const void* leaveBuff = res.LoadResource(B_MESSAGE_TYPE, 1120, &leaveSize); BMessage temp;
leave.Unflatten((const char*)leaveBuff); const void* buff = res.LoadResource(B_MESSAGE_TYPE, 1120 + i, &size);
fChatItems.AddItem(new BMessage(leave)); temp.Unflatten((const char*)buff);
fChatItems.AddItem(new BMessage(temp));
}
// Loading default chat commands // Loading default chat commands
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
@ -165,6 +168,15 @@ Server::Filter(BMessage* message, BHandler **target)
accountManager->ReplicantStatusNotify(accountManager->Status()); accountManager->ReplicantStatusNotify(accountManager->Status());
break; break;
} }
case APP_ROOM_INFO:
{
Conversation* chat = _EnsureConversation(message);
if (chat != NULL) {
ConversationInfoWindow* win = new ConversationInfoWindow(chat);
win->Show();
}
break;
}
case APP_USER_INFO: case APP_USER_INFO:
{ {
User* user = _EnsureUser(message); User* user = _EnsureUser(message);

View File

@ -0,0 +1,103 @@
/*
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "ConversationInfoWindow.h"
#include "Conversation.h"
#include <libinterface/BitmapView.h>
#include <Catalog.h>
#include <LayoutBuilder.h>
#include <StringFormat.h>
#include <StringView.h>
#include <TextView.h>
#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);
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef _CONVERSATION_INFO_WINDOW_H
#define _CONVERSATION_INFO_WINDOW_H
#include <Window.h>
#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

View File

@ -15,7 +15,6 @@
#include <Catalog.h> #include <Catalog.h>
#include <LayoutBuilder.h> #include <LayoutBuilder.h>
#include <MenuBar.h> #include <MenuBar.h>
#include <ScrollView.h>
#include <TranslationUtils.h> #include <TranslationUtils.h>
#include "AccountManager.h" #include "AccountManager.h"

View File

@ -117,6 +117,13 @@ resource(1106) message
// Room pop-up menu items // Room pop-up menu items
resource(1120) message resource(1120) message
{
"class" = "BMenuItem",
"_label" = "Room info…",
"_msg" = message('CYrw'),
bool "x_to_protocol" = false
};
resource(1121) message
{ {
"class" = "BMenuItem", "class" = "BMenuItem",
"_label" = "Leave chat", "_label" = "Leave chat",