diff --git a/application/Makefile b/application/Makefile index e640331..b4ad8b2 100644 --- a/application/Makefile +++ b/application/Makefile @@ -77,7 +77,6 @@ SRCS = \ application/views/UserListView.cpp \ application/views/UserPopUp.cpp \ application/windows/AboutWindow.cpp \ - application/windows/JoinWindow.cpp \ application/windows/MainWindow.cpp \ application/windows/PreferencesWindow.cpp \ application/windows/RosterEditWindow.cpp \ diff --git a/application/ProtocolTemplate.cpp b/application/ProtocolTemplate.cpp index 7ec861b..c5409a0 100644 --- a/application/ProtocolTemplate.cpp +++ b/application/ProtocolTemplate.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() { delete fTemplate; diff --git a/application/ProtocolTemplate.h b/application/ProtocolTemplate.h index 64544da..a51e30c 100644 --- a/application/ProtocolTemplate.h +++ b/application/ProtocolTemplate.h @@ -19,6 +19,7 @@ class ProtocolTemplate { public: ProtocolTemplate(CayaProtocol* protocol, const char* type); + ProtocolTemplate(BMessage pTemplate); ~ProtocolTemplate(); status_t InitCheck() const; diff --git a/application/windows/JoinWindow.cpp b/application/windows/JoinWindow.cpp deleted file mode 100644 index 5402518..0000000 --- a/application/windows/JoinWindow.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2021, Jaidyn Levesque - * All rights reserved. Distributed under the terms of the MIT license. - */ - -#include "JoinWindow.h" - -#include -#include -#include -#include -#include - -#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); -} diff --git a/application/windows/JoinWindow.h b/application/windows/JoinWindow.h deleted file mode 100644 index 181aa3b..0000000 --- a/application/windows/JoinWindow.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2021, Jaidyn Levesque - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef JOINWINDOW_H -#define JOINWINDOW_H - -#include - -#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 - diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index d53fa5e..714261e 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -26,7 +26,6 @@ #include "ConversationView.h" #include "DefaultItems.h" #include "EditingFilter.h" -#include "JoinWindow.h" #include "MainWindow.h" #include "NotifyMessage.h" #include "PreferencesWindow.h" @@ -136,8 +135,20 @@ MainWindow::MessageReceived(BMessage* message) } case CAYA_JOIN_ROOM: { - JoinWindow* win = new JoinWindow(new BMessenger(this), - fServer->GetAccounts()); + BMessage temp; + 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(); break; } diff --git a/application/windows/TemplateWindow.cpp b/application/windows/TemplateWindow.cpp index 02e2f1c..be4382b 100644 --- a/application/windows/TemplateWindow.cpp +++ b/application/windows/TemplateWindow.cpp @@ -59,7 +59,6 @@ TemplateWindow::TemplateWindow(const char* title, ProtocolTemplate* temp, _InitInterface(instance); CenterOnScreen(); - fTemplate = temp; fTemplate->Load(fTemplateView); fTemplateView->AttachedToWindow(); fTemplateView->MakeFocus(true);