Replace JoinWindow with a TemplateWindow
This commit is contained in:
parent
f4342d9310
commit
b1254494cb
|
@ -77,7 +77,6 @@ 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/JoinWindow.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 \
|
||||||
|
|
|
@ -43,6 +43,15 @@ ProtocolTemplate::ProtocolTemplate(CayaProtocol* protocol, const char* type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ProtocolTemplate::ProtocolTemplate(BMessage pTemplate)
|
||||||
|
:
|
||||||
|
fProtocol(NULL),
|
||||||
|
fTemplate(new BMessage())
|
||||||
|
{
|
||||||
|
*fTemplate = pTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ProtocolTemplate::~ProtocolTemplate()
|
ProtocolTemplate::~ProtocolTemplate()
|
||||||
{
|
{
|
||||||
delete fTemplate;
|
delete fTemplate;
|
||||||
|
|
|
@ -19,6 +19,7 @@ class ProtocolTemplate {
|
||||||
public:
|
public:
|
||||||
ProtocolTemplate(CayaProtocol* protocol,
|
ProtocolTemplate(CayaProtocol* protocol,
|
||||||
const char* type);
|
const char* type);
|
||||||
|
ProtocolTemplate(BMessage pTemplate);
|
||||||
~ProtocolTemplate();
|
~ProtocolTemplate();
|
||||||
|
|
||||||
status_t InitCheck() const;
|
status_t InitCheck() const;
|
||||||
|
|
|
@ -1,98 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "JoinWindow.h"
|
|
||||||
|
|
||||||
#include <Alert.h>
|
|
||||||
#include <Button.h>
|
|
||||||
#include <LayoutBuilder.h>
|
|
||||||
#include <Messenger.h>
|
|
||||||
#include <StringView.h>
|
|
||||||
|
|
||||||
#include "CayaProtocolMessages.h"
|
|
||||||
#include "CayaUtils.h"
|
|
||||||
|
|
||||||
|
|
||||||
const uint32 kJoinRoom = 'JWjr';
|
|
||||||
const uint32 kAccSelected = 'JWas';
|
|
||||||
|
|
||||||
|
|
||||||
JoinWindow::JoinWindow(BMessenger* messenger, AccountInstances accounts)
|
|
||||||
:
|
|
||||||
BWindow(BRect(0, 0, 400, 100), "Join a room", B_FLOATING_WINDOW, 0),
|
|
||||||
fTarget(messenger),
|
|
||||||
fAccounts(accounts),
|
|
||||||
fSelectedAcc(0)
|
|
||||||
{
|
|
||||||
_InitInterface();
|
|
||||||
CenterOnScreen();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
JoinWindow::MessageReceived(BMessage* msg)
|
|
||||||
{
|
|
||||||
switch (msg->what)
|
|
||||||
{
|
|
||||||
case kAccSelected:
|
|
||||||
{
|
|
||||||
int32 index;
|
|
||||||
if (msg->FindInt32("index", &index) == B_OK)
|
|
||||||
fSelectedAcc = index;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case kJoinRoom:
|
|
||||||
{
|
|
||||||
BString roomId = fTextBox->Text();
|
|
||||||
BString selected = fMenuField->Menu()->ItemAt(fSelectedAcc)->Label();
|
|
||||||
int64 instanceId = fAccounts.ValueFor(selected);
|
|
||||||
|
|
||||||
if (roomId.IsEmpty() == true) {
|
|
||||||
BAlert* alert = new BAlert("No room ID", "You can't join a room "
|
|
||||||
"with no name― you need to specify a room ID.", "OK", "", "",
|
|
||||||
B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_IDEA_ALERT);
|
|
||||||
alert->Go();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BMessage* joinMsg = new BMessage(IM_MESSAGE);
|
|
||||||
joinMsg->AddInt32("im_what", IM_JOIN_ROOM);
|
|
||||||
joinMsg->AddInt64("instance", instanceId);
|
|
||||||
joinMsg->AddString("chat_id", roomId);
|
|
||||||
fTarget->SendMessage(joinMsg);
|
|
||||||
|
|
||||||
Quit();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
BWindow::MessageReceived(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
JoinWindow::_InitInterface()
|
|
||||||
{
|
|
||||||
BButton* join = new BButton("Join", new BMessage(kJoinRoom));
|
|
||||||
fTextBox = new BTextControl("Room ID:", "", NULL);
|
|
||||||
fMenuField = new BMenuField("accountMenuField", NULL,
|
|
||||||
CreateAccountMenu(fAccounts, BMessage(kAccSelected)));
|
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
|
||||||
.SetInsets(B_USE_DEFAULT_SPACING)
|
|
||||||
.Add(fTextBox)
|
|
||||||
.AddGroup(B_HORIZONTAL)
|
|
||||||
.Add(fMenuField)
|
|
||||||
.AddGlue()
|
|
||||||
.Add(new BButton("Cancel", new BMessage(B_QUIT_REQUESTED)))
|
|
||||||
.Add(join)
|
|
||||||
.End()
|
|
||||||
.End();
|
|
||||||
|
|
||||||
fTextBox->MakeFocus(true);
|
|
||||||
join->MakeDefault(true);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
|
||||||
*/
|
|
||||||
#ifndef JOINWINDOW_H
|
|
||||||
#define JOINWINDOW_H
|
|
||||||
|
|
||||||
#include <Window.h>
|
|
||||||
|
|
||||||
#include "Server.h"
|
|
||||||
|
|
||||||
class BMenu;
|
|
||||||
class BMenuField;
|
|
||||||
class BMessenger;
|
|
||||||
class BTextControl;
|
|
||||||
|
|
||||||
|
|
||||||
/* A window used to specify a room to join. */
|
|
||||||
class JoinWindow : public BWindow {
|
|
||||||
public:
|
|
||||||
JoinWindow(BMessenger* messenger, AccountInstances accounts);
|
|
||||||
|
|
||||||
void MessageReceived(BMessage* message);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void _InitInterface();
|
|
||||||
|
|
||||||
BMessenger* fTarget;
|
|
||||||
AccountInstances fAccounts;
|
|
||||||
|
|
||||||
BMenuField* fMenuField;
|
|
||||||
BTextControl* fTextBox;
|
|
||||||
|
|
||||||
int32 fSelectedAcc;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // JOINWINDOW_H
|
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include "ConversationView.h"
|
#include "ConversationView.h"
|
||||||
#include "DefaultItems.h"
|
#include "DefaultItems.h"
|
||||||
#include "EditingFilter.h"
|
#include "EditingFilter.h"
|
||||||
#include "JoinWindow.h"
|
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "NotifyMessage.h"
|
#include "NotifyMessage.h"
|
||||||
#include "PreferencesWindow.h"
|
#include "PreferencesWindow.h"
|
||||||
|
@ -136,8 +135,20 @@ MainWindow::MessageReceived(BMessage* message)
|
||||||
}
|
}
|
||||||
case CAYA_JOIN_ROOM:
|
case CAYA_JOIN_ROOM:
|
||||||
{
|
{
|
||||||
JoinWindow* win = new JoinWindow(new BMessenger(this),
|
BMessage temp;
|
||||||
fServer->GetAccounts());
|
BMessage roomId;
|
||||||
|
roomId.AddString("name", "chat_id");
|
||||||
|
roomId.AddString("description", "Room ID:");
|
||||||
|
roomId.AddString("error", "You can't join an addressless room! "
|
||||||
|
"Please enter a valid room ID.");
|
||||||
|
roomId.AddInt32("type", 'CSTR');
|
||||||
|
temp.AddMessage("setting", &roomId);
|
||||||
|
|
||||||
|
BMessage* joinMsg = new BMessage(IM_MESSAGE);
|
||||||
|
joinMsg->AddInt32("im_what", IM_JOIN_ROOM);
|
||||||
|
|
||||||
|
TemplateWindow* win = new TemplateWindow("Join a room",
|
||||||
|
new ProtocolTemplate(temp), joinMsg, fServer);
|
||||||
win->Show();
|
win->Show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,6 @@ TemplateWindow::TemplateWindow(const char* title, ProtocolTemplate* temp,
|
||||||
_InitInterface(instance);
|
_InitInterface(instance);
|
||||||
CenterOnScreen();
|
CenterOnScreen();
|
||||||
|
|
||||||
fTemplate = temp;
|
|
||||||
fTemplate->Load(fTemplateView);
|
fTemplate->Load(fTemplateView);
|
||||||
fTemplateView->AttachedToWindow();
|
fTemplateView->AttachedToWindow();
|
||||||
fTemplateView->MakeFocus(true);
|
fTemplateView->MakeFocus(true);
|
||||||
|
|
Ŝarĝante…
Reference in New Issue