2010-05-07 04:47:10 -05:00
|
|
|
/*
|
2011-12-03 16:38:03 -06:00
|
|
|
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
|
|
|
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
|
2021-06-15 23:29:38 -05:00
|
|
|
* Copyright 2021, Jaidyn Levesque. All rights reserved.
|
2010-05-07 04:47:10 -05:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Andrea Anzani, andrea.anzani@gmail.com
|
|
|
|
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
2021-06-15 23:29:38 -05:00
|
|
|
* Jaidyn Levesque, jadedctrl@teknik.io
|
2010-05-07 04:47:10 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Application.h>
|
|
|
|
#include <Alert.h>
|
2021-05-25 13:57:53 -05:00
|
|
|
#include <LayoutBuilder.h>
|
|
|
|
#include <MenuBar.h>
|
2010-05-07 04:47:10 -05:00
|
|
|
#include <ScrollView.h>
|
|
|
|
#include <TranslationUtils.h>
|
|
|
|
|
2011-12-14 17:36:27 -06:00
|
|
|
#include "AccountManager.h"
|
2010-05-16 16:02:50 -05:00
|
|
|
#include "CayaMessages.h"
|
2010-05-22 09:18:11 -05:00
|
|
|
#include "CayaPreferences.h"
|
2021-05-30 12:30:26 -05:00
|
|
|
#include "CayaProtocolMessages.h"
|
2021-05-27 11:15:30 -05:00
|
|
|
#include "ConversationItem.h"
|
|
|
|
#include "ConversationListView.h"
|
2021-05-28 22:26:32 -05:00
|
|
|
#include "ConversationView.h"
|
2021-06-15 23:29:38 -05:00
|
|
|
#include "DefaultItems.h"
|
2021-05-29 15:47:54 -05:00
|
|
|
#include "EditingFilter.h"
|
2021-06-01 21:43:19 -05:00
|
|
|
#include "JoinWindow.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
#include "MainWindow.h"
|
2021-05-30 12:30:26 -05:00
|
|
|
#include "NotifyMessage.h"
|
Explicitly tie Conversations, Contacts, and Users to their ProtocolLoopers
Previously, all Conversations/Contacts/Users were stored in the Server,
each in their respective KeyMaps, identified solely by their
identifiers. This leads to the glaring problem of overlap― if the user
has multiple accounts, some users/rooms might be used or present in multiple
accounts at the same time.
Now, each accounts' Contacts, Conversations, and Users are stored in
its ProtocolLooper, making this overlap impossible. An oversight of only
allowing one user identifier to be stored (fMySelf) in Server was also fixed
this way.
This is the bulk of the work required for multi-account support― now,
the user can join the same XMPP room on two seperate accounts, and it
works perfectly.
2021-06-10 15:16:43 -05:00
|
|
|
#include "PreferencesWindow.h"
|
2011-12-14 17:36:27 -06:00
|
|
|
#include "ReplicantStatusView.h"
|
2021-05-26 07:48:25 -05:00
|
|
|
#include "RosterWindow.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
#include "Server.h"
|
|
|
|
#include "StatusView.h"
|
|
|
|
|
2012-09-25 16:45:29 -05:00
|
|
|
|
2010-05-19 17:28:26 -05:00
|
|
|
const uint32 kLogin = 'LOGI';
|
2010-05-12 13:15:21 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
MainWindow::MainWindow()
|
2010-05-19 17:28:26 -05:00
|
|
|
:
|
2021-06-01 22:12:01 -05:00
|
|
|
BWindow(BRect(0, 0, 600, 400), "Caya", B_TITLED_WINDOW, 0),
|
2021-05-30 17:12:41 -05:00
|
|
|
fWorkspaceChanged(false),
|
2021-05-30 20:45:24 -05:00
|
|
|
fConversation(NULL),
|
2021-06-12 16:13:52 -05:00
|
|
|
fRosterWindow(NULL),
|
|
|
|
fServer(NULL)
|
2010-05-22 09:18:11 -05:00
|
|
|
{
|
2021-05-30 12:30:26 -05:00
|
|
|
_InitInterface();
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
// Filter messages using Server
|
|
|
|
fServer = new Server();
|
|
|
|
AddFilter(fServer);
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2021-06-15 23:29:38 -05:00
|
|
|
// Register default commands & items
|
|
|
|
DefaultCommands(this);
|
|
|
|
DefaultUserPopUpItems(this);
|
2021-06-16 04:33:06 -05:00
|
|
|
DefaultChatPopUpItems(this);
|
2021-06-15 23:29:38 -05:00
|
|
|
|
2021-05-30 12:30:26 -05:00
|
|
|
// Also through the editing filter (enter to send)
|
|
|
|
AddCommonFilter(new EditingFilter(fSendView));
|
|
|
|
fSendView->MakeFocus(true);
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
CenterOnScreen();
|
2011-12-14 17:36:27 -06:00
|
|
|
|
|
|
|
//TODO check for errors here
|
2012-03-03 20:27:16 -06:00
|
|
|
ReplicantStatusView::InstallReplicant();
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
void
|
|
|
|
MainWindow::Start()
|
|
|
|
{
|
|
|
|
// Login all accounts
|
|
|
|
fServer->LoginAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
bool
|
|
|
|
MainWindow::QuitRequested()
|
|
|
|
{
|
2015-10-01 23:17:54 -05:00
|
|
|
int32 button_index = 0;
|
|
|
|
if(!CayaPreferences::Item()->DisableQuitConfirm)
|
|
|
|
{
|
2021-05-26 07:48:25 -05:00
|
|
|
BAlert* alert = new BAlert("Closing", "Are you sure you want to quit?",
|
|
|
|
"Yes", "No", NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING,
|
|
|
|
B_WARNING_ALERT);
|
2015-10-01 23:17:54 -05:00
|
|
|
alert->SetShortcut(0, B_ESCAPE);
|
|
|
|
button_index = alert->Go();
|
|
|
|
}
|
|
|
|
|
2015-09-29 03:59:40 -05:00
|
|
|
if(button_index == 0) {
|
|
|
|
fServer->Quit();
|
|
|
|
CayaPreferences::Get()->Save();
|
|
|
|
ReplicantStatusView::RemoveReplicant();
|
|
|
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
|
|
|
return true;
|
2021-06-11 17:24:04 -05:00
|
|
|
} else
|
2015-09-29 03:59:40 -05:00
|
|
|
return false;
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
MainWindow::MessageReceived(BMessage* message)
|
|
|
|
{
|
2010-05-16 16:02:50 -05:00
|
|
|
switch (message->what) {
|
2012-06-07 11:46:07 -05:00
|
|
|
case CAYA_SHOW_SETTINGS:
|
|
|
|
{
|
Explicitly tie Conversations, Contacts, and Users to their ProtocolLoopers
Previously, all Conversations/Contacts/Users were stored in the Server,
each in their respective KeyMaps, identified solely by their
identifiers. This leads to the glaring problem of overlap― if the user
has multiple accounts, some users/rooms might be used or present in multiple
accounts at the same time.
Now, each accounts' Contacts, Conversations, and Users are stored in
its ProtocolLooper, making this overlap impossible. An oversight of only
allowing one user identifier to be stored (fMySelf) in Server was also fixed
this way.
This is the bulk of the work required for multi-account support― now,
the user can join the same XMPP room on two seperate accounts, and it
works perfectly.
2021-06-10 15:16:43 -05:00
|
|
|
PreferencesWindow* win = new PreferencesWindow();
|
|
|
|
win->Show();
|
2010-05-07 04:47:10 -05:00
|
|
|
break;
|
|
|
|
}
|
2021-05-26 07:48:25 -05:00
|
|
|
|
|
|
|
case CAYA_NEW_CHAT:
|
2012-06-07 11:46:07 -05:00
|
|
|
{
|
2021-06-08 21:43:30 -05:00
|
|
|
BMessage* newMsg = new BMessage(IM_MESSAGE);
|
|
|
|
newMsg->AddInt32("im_what", IM_CREATE_CHAT);
|
|
|
|
|
2021-05-30 17:12:41 -05:00
|
|
|
fRosterWindow = new RosterWindow("Invite contact to chat"
|
2021-06-08 21:43:30 -05:00
|
|
|
B_UTF8_ELLIPSIS, newMsg, new BMessenger(this), fServer);
|
2021-05-30 17:12:41 -05:00
|
|
|
fRosterWindow->Show();
|
2010-05-16 16:02:50 -05:00
|
|
|
break;
|
|
|
|
}
|
2011-12-14 17:36:27 -06:00
|
|
|
|
2021-06-01 21:43:19 -05:00
|
|
|
case CAYA_JOIN_CHAT:
|
|
|
|
{
|
|
|
|
JoinWindow* win = new JoinWindow(new BMessenger(this),
|
|
|
|
fServer->GetAccounts());
|
|
|
|
win->Show();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-06-08 21:43:30 -05:00
|
|
|
case CAYA_SEND_INVITE:
|
|
|
|
{
|
|
|
|
if (fConversation == NULL)
|
|
|
|
break;
|
|
|
|
BString chat_id = fConversation->GetId();
|
|
|
|
|
|
|
|
BMessage* invite = new BMessage(IM_MESSAGE);
|
|
|
|
invite->AddInt32("im_what", IM_ROOM_SEND_INVITE);
|
|
|
|
invite->AddString("chat_id", chat_id);
|
|
|
|
|
|
|
|
BLooper* looper = (BLooper*)fConversation->GetProtocolLooper();
|
|
|
|
fRosterWindow = new RosterWindow("Invite contact to chat"
|
|
|
|
B_UTF8_ELLIPSIS, invite, new BMessenger(looper), fServer);
|
|
|
|
|
|
|
|
fRosterWindow->Show();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-05-30 20:45:24 -05:00
|
|
|
case CAYA_MOVE_UP:
|
|
|
|
{
|
|
|
|
if (fConversation == NULL)
|
2021-06-08 21:43:30 -05:00
|
|
|
break;
|
2021-05-30 20:45:24 -05:00
|
|
|
|
2021-06-11 17:24:04 -05:00
|
|
|
int32 index = fListView->ConversationIndexOf(fConversation);
|
2021-05-30 20:45:24 -05:00
|
|
|
if (index > 0)
|
2021-06-11 17:24:04 -05:00
|
|
|
fListView->SelectConversation(index - 1);
|
2021-05-30 20:45:24 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CAYA_MOVE_DOWN:
|
|
|
|
{
|
|
|
|
if (fConversation == NULL)
|
2021-06-08 21:43:30 -05:00
|
|
|
break;
|
2021-05-30 20:45:24 -05:00
|
|
|
|
2021-06-11 17:24:04 -05:00
|
|
|
int32 index = fListView->ConversationIndexOf(fConversation);
|
|
|
|
int32 count = fListView->CountConversations();
|
2021-05-30 20:45:24 -05:00
|
|
|
if (index < (count - 1))
|
2021-06-11 17:24:04 -05:00
|
|
|
fListView->SelectConversation(index + 1);
|
2021-05-30 20:45:24 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-14 17:36:27 -06:00
|
|
|
case CAYA_REPLICANT_STATUS_SET:
|
|
|
|
{
|
|
|
|
int32 status;
|
|
|
|
message->FindInt32("status", &status);
|
|
|
|
AccountManager* accountManager = AccountManager::Get();
|
|
|
|
accountManager->SetStatus((CayaStatus)status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CAYA_REPLICANT_SHOW_WINDOW:
|
|
|
|
{
|
|
|
|
if (LockLooper()) {
|
|
|
|
SetWorkspaces(B_CURRENT_WORKSPACE);
|
|
|
|
|
|
|
|
if ((IsMinimized() || IsHidden())
|
|
|
|
|| fWorkspaceChanged) {
|
|
|
|
Minimize(false);
|
|
|
|
Show();
|
|
|
|
fWorkspaceChanged = false;
|
|
|
|
} else if ((!IsMinimized() || !IsHidden())
|
|
|
|
|| (!fWorkspaceChanged)) {
|
|
|
|
Minimize(true);
|
|
|
|
}
|
|
|
|
UnlockLooper();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-05-29 15:47:54 -05:00
|
|
|
case CAYA_CHAT:
|
|
|
|
{
|
|
|
|
message->AddString("body", fSendView->Text());
|
|
|
|
fChatView->MessageReceived(message);
|
|
|
|
fSendView->SetText("");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-06-12 16:13:52 -05:00
|
|
|
case CAYA_DISABLE_ACCOUNT:
|
|
|
|
_ToggleMenuItems();
|
|
|
|
break;
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
case IM_MESSAGE:
|
|
|
|
ImMessage(message);
|
|
|
|
break;
|
|
|
|
case IM_ERROR:
|
|
|
|
ImError(message);
|
|
|
|
break;
|
2010-05-12 13:57:19 -05:00
|
|
|
case B_ABOUT_REQUESTED:
|
|
|
|
be_app->PostMessage(message);
|
|
|
|
break;
|
2011-12-14 17:36:27 -06:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
default:
|
|
|
|
BWindow::MessageReceived(message);
|
2010-05-22 09:18:11 -05:00
|
|
|
}
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
|
|
|
MainWindow::ImMessage(BMessage* msg)
|
2010-05-22 09:18:11 -05:00
|
|
|
{
|
2010-05-07 04:47:10 -05:00
|
|
|
int32 im_what = msg->FindInt32("im_what");
|
2010-05-16 16:02:50 -05:00
|
|
|
switch (im_what) {
|
2010-05-07 04:47:10 -05:00
|
|
|
case IM_OWN_CONTACT_INFO:
|
2010-05-19 15:37:26 -05:00
|
|
|
fStatusView->SetName(msg->FindString("name"));
|
2010-05-30 03:51:19 -05:00
|
|
|
break;
|
|
|
|
case IM_OWN_AVATAR_SET:
|
|
|
|
{
|
2010-05-07 04:47:10 -05:00
|
|
|
entry_ref ref;
|
2010-05-30 03:51:19 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
if (msg->FindRef("ref", &ref) == B_OK) {
|
|
|
|
BBitmap* bitmap = BTranslationUtils::GetBitmap(&ref);
|
2010-05-30 03:51:19 -05:00
|
|
|
fStatusView->SetAvatarIcon(bitmap);
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-06-04 16:32:18 -05:00
|
|
|
case IM_ROOM_JOINED:
|
2021-06-02 16:53:03 -05:00
|
|
|
case IM_ROOM_PARTICIPANTS:
|
2021-05-27 11:15:30 -05:00
|
|
|
case IM_MESSAGE_RECEIVED:
|
|
|
|
case IM_MESSAGE_SENT:
|
|
|
|
case IM_CHAT_CREATED:
|
|
|
|
{
|
|
|
|
_EnsureConversationItem(msg);
|
|
|
|
break;
|
|
|
|
}
|
2021-06-04 16:32:18 -05:00
|
|
|
case IM_ROOM_LEFT:
|
|
|
|
{
|
|
|
|
ConversationItem* item = _EnsureConversationItem(msg);
|
|
|
|
if (item == NULL)
|
|
|
|
break;
|
|
|
|
|
2021-06-11 20:33:28 -05:00
|
|
|
delete item->GetConversation();
|
2021-06-04 16:32:18 -05:00
|
|
|
break;
|
|
|
|
}
|
2021-05-30 17:12:41 -05:00
|
|
|
case IM_AVATAR_SET:
|
|
|
|
case IM_CONTACT_INFO:
|
|
|
|
case IM_EXTENDED_CONTACT_INFO:
|
|
|
|
case IM_STATUS_SET:
|
Explicitly tie Conversations, Contacts, and Users to their ProtocolLoopers
Previously, all Conversations/Contacts/Users were stored in the Server,
each in their respective KeyMaps, identified solely by their
identifiers. This leads to the glaring problem of overlap― if the user
has multiple accounts, some users/rooms might be used or present in multiple
accounts at the same time.
Now, each accounts' Contacts, Conversations, and Users are stored in
its ProtocolLooper, making this overlap impossible. An oversight of only
allowing one user identifier to be stored (fMySelf) in Server was also fixed
this way.
This is the bulk of the work required for multi-account support― now,
the user can join the same XMPP room on two seperate accounts, and it
works perfectly.
2021-06-10 15:16:43 -05:00
|
|
|
fRosterWindow->PostMessage(msg);
|
2021-05-30 17:12:41 -05:00
|
|
|
break;
|
2021-06-12 16:13:52 -05:00
|
|
|
|
|
|
|
case IM_PROTOCOL_READY:
|
|
|
|
_ToggleMenuItems();
|
|
|
|
break;
|
2010-05-07 04:47:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-29 15:47:54 -05:00
|
|
|
void
|
2021-05-30 12:30:26 -05:00
|
|
|
MainWindow::ImError(BMessage* msg)
|
2021-05-29 15:47:54 -05:00
|
|
|
{
|
2021-05-30 12:30:26 -05:00
|
|
|
const char* error = NULL;
|
|
|
|
const char* detail = msg->FindString("detail");
|
2021-05-29 15:47:54 -05:00
|
|
|
|
2021-05-30 12:30:26 -05:00
|
|
|
if (msg->FindString("error", &error) != B_OK)
|
|
|
|
return;
|
2021-05-29 15:47:54 -05:00
|
|
|
|
2021-05-30 12:30:26 -05:00
|
|
|
// Format error message
|
|
|
|
BString errMsg(error);
|
|
|
|
if (detail)
|
|
|
|
errMsg << "\n" << detail;
|
|
|
|
|
|
|
|
BAlert* alert = new BAlert("Error", errMsg.String(), "OK", NULL, NULL,
|
|
|
|
B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
|
|
|
alert->Go();
|
2021-05-29 15:47:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
void
|
|
|
|
MainWindow::ObserveInteger(int32 what, int32 val)
|
|
|
|
{
|
|
|
|
switch (what) {
|
|
|
|
case INT_ACCOUNT_STATUS:
|
|
|
|
fStatusView->SetStatus((CayaStatus)val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-27 11:15:30 -05:00
|
|
|
void
|
2021-05-30 12:30:26 -05:00
|
|
|
MainWindow::WorkspaceActivated(int32 workspace, bool active)
|
2021-05-27 11:15:30 -05:00
|
|
|
{
|
2021-05-30 12:30:26 -05:00
|
|
|
if (active)
|
|
|
|
fWorkspaceChanged = false;
|
2021-05-27 11:15:30 -05:00
|
|
|
else
|
2021-05-30 12:30:26 -05:00
|
|
|
fWorkspaceChanged = true;
|
2021-05-27 11:15:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-14 17:36:27 -06:00
|
|
|
void
|
2021-05-30 12:30:26 -05:00
|
|
|
MainWindow::SetConversation(Conversation* chat)
|
2011-12-14 17:36:27 -06:00
|
|
|
{
|
2021-05-30 13:45:08 -05:00
|
|
|
// Save current size of chat and textbox
|
|
|
|
float weightChat = fRightView->ItemWeight(0);
|
|
|
|
float weightSend = fRightView->ItemWeight(1);
|
|
|
|
|
2021-05-30 12:30:26 -05:00
|
|
|
fRightView->RemoveChild(fRightView->FindView("chatView"));
|
|
|
|
fRightView->RemoveChild(fRightView->FindView("fSendScroll"));
|
|
|
|
|
2021-05-30 20:45:24 -05:00
|
|
|
if (chat != NULL) {
|
2021-05-30 12:30:26 -05:00
|
|
|
fChatView = chat->GetView();
|
2021-05-30 20:45:24 -05:00
|
|
|
fConversation = chat;
|
2021-06-06 18:06:46 -05:00
|
|
|
|
|
|
|
BString title(chat->GetName());
|
|
|
|
title << " ― Caya";
|
|
|
|
SetTitle(title.String());
|
2021-05-30 20:45:24 -05:00
|
|
|
}
|
2021-06-06 18:06:46 -05:00
|
|
|
else
|
|
|
|
SetTitle("Caya");
|
2021-05-30 12:30:26 -05:00
|
|
|
|
|
|
|
fRightView->AddChild(fChatView, 9);
|
|
|
|
fRightView->AddChild(fSendScroll, 1);
|
2021-05-30 13:45:08 -05:00
|
|
|
|
|
|
|
// Apply saved chat and textbox size to new views
|
|
|
|
if (weightChat * weightSend != 0) {
|
|
|
|
fRightView->SetItemWeight(0, weightChat, true);
|
|
|
|
fRightView->SetItemWeight(1, weightSend, true);
|
|
|
|
}
|
2021-05-30 12:30:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-11 20:33:28 -05:00
|
|
|
void
|
|
|
|
MainWindow::RemoveConversation(Conversation* chat)
|
|
|
|
{
|
|
|
|
int32 index = fListView->ConversationIndexOf(chat);
|
|
|
|
if (index > 0)
|
|
|
|
index--;
|
|
|
|
|
|
|
|
fListView->RemoveConversation(chat);
|
|
|
|
|
|
|
|
if (fListView->CountConversations() == 0) {
|
|
|
|
fChatView = new ConversationView();
|
|
|
|
SetConversation(NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fListView->SelectConversation(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-30 12:30:26 -05:00
|
|
|
void
|
|
|
|
MainWindow::_InitInterface()
|
|
|
|
{
|
|
|
|
// Left side of window, Roomlist + Status
|
|
|
|
fListView = new ConversationListView("roomList");
|
|
|
|
fStatusView = new StatusView("statusView");
|
|
|
|
|
|
|
|
// Right-side of window, Chat + Textbox
|
|
|
|
fRightView = new BSplitView(B_VERTICAL, 0);
|
|
|
|
fChatView = new ConversationView();
|
|
|
|
fSendView = new BTextView("fSendView");
|
|
|
|
fSendScroll = new BScrollView("fSendScroll", fSendView,
|
|
|
|
B_WILL_DRAW, false, true);
|
|
|
|
fSendView->SetWordWrap(true);
|
|
|
|
|
|
|
|
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
2021-06-12 16:13:52 -05:00
|
|
|
.Add((fMenuBar = _CreateMenuBar()))
|
2021-05-30 12:30:26 -05:00
|
|
|
.AddGroup(B_HORIZONTAL)
|
|
|
|
.SetInsets(5, 5, 0, 10)
|
|
|
|
.AddSplit(B_HORIZONTAL, 0)
|
|
|
|
.AddGroup(B_VERTICAL)
|
|
|
|
.Add(fListView, 1)
|
|
|
|
.Add(fStatusView)
|
|
|
|
.End()
|
|
|
|
.Add(fRightView, 5)
|
|
|
|
.End()
|
|
|
|
.End()
|
|
|
|
.End();
|
|
|
|
|
|
|
|
SetConversation(NULL);
|
2021-06-12 16:13:52 -05:00
|
|
|
_ToggleMenuItems();
|
2021-05-30 12:30:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BMenuBar*
|
|
|
|
MainWindow::_CreateMenuBar()
|
|
|
|
{
|
|
|
|
BMenuBar* menuBar = new BMenuBar("MenuBar");
|
|
|
|
|
2021-05-31 10:50:43 -05:00
|
|
|
// Program
|
2021-05-30 12:30:26 -05:00
|
|
|
BMenu* programMenu = new BMenu("Program");
|
|
|
|
programMenu->AddItem(new BMenuItem("About" B_UTF8_ELLIPSIS,
|
|
|
|
new BMessage(B_ABOUT_REQUESTED)));
|
|
|
|
programMenu->AddItem(new BMenuItem("Preferences" B_UTF8_ELLIPSIS,
|
|
|
|
new BMessage(CAYA_SHOW_SETTINGS), ',', B_COMMAND_KEY));
|
|
|
|
programMenu->AddItem(new BSeparatorItem());
|
|
|
|
programMenu->AddItem(new BMenuItem("Quit",
|
|
|
|
new BMessage(B_QUIT_REQUESTED), 'Q', B_COMMAND_KEY));
|
|
|
|
programMenu->SetTargetForItems(this);
|
|
|
|
|
2021-05-31 10:50:43 -05:00
|
|
|
// Chat
|
2021-05-30 12:30:26 -05:00
|
|
|
BMenu* chatMenu = new BMenu("Chat");
|
2021-06-12 16:13:52 -05:00
|
|
|
BMenuItem* joinRoom = new BMenuItem("Join room" B_UTF8_ELLIPSIS,
|
|
|
|
new BMessage(CAYA_JOIN_CHAT), 'J', B_COMMAND_KEY);
|
2021-05-31 10:50:43 -05:00
|
|
|
BMenuItem* invite = new BMenuItem("Invite user" B_UTF8_ELLIPSIS,
|
|
|
|
new BMessage(CAYA_SEND_INVITE), 'I', B_COMMAND_KEY);
|
2021-06-12 16:13:52 -05:00
|
|
|
|
|
|
|
BMenuItem* newChat = new BMenuItem("New chat" B_UTF8_ELLIPSIS,
|
|
|
|
new BMessage(CAYA_NEW_CHAT), 'M', B_COMMAND_KEY);
|
2021-06-01 21:43:19 -05:00
|
|
|
BMenuItem* newRoom = new BMenuItem("New room" B_UTF8_ELLIPSIS,
|
|
|
|
new BMessage(), 'N', B_COMMAND_KEY);
|
2021-05-31 10:50:43 -05:00
|
|
|
|
2021-06-12 16:13:52 -05:00
|
|
|
chatMenu->AddItem(joinRoom);
|
2021-06-01 21:43:19 -05:00
|
|
|
chatMenu->AddSeparatorItem();
|
2021-06-12 16:13:52 -05:00
|
|
|
chatMenu->AddItem(newChat);
|
2021-06-01 21:43:19 -05:00
|
|
|
chatMenu->AddItem(newRoom);
|
2021-05-31 10:50:43 -05:00
|
|
|
chatMenu->AddSeparatorItem();
|
|
|
|
chatMenu->AddItem(invite);
|
2021-05-30 12:30:26 -05:00
|
|
|
chatMenu->SetTargetForItems(this);
|
|
|
|
|
2021-05-31 10:50:43 -05:00
|
|
|
// Window
|
2021-05-30 20:45:24 -05:00
|
|
|
BMenu* windowMenu = new BMenu("Window");
|
|
|
|
windowMenu->AddItem(new BMenuItem("Up",
|
|
|
|
new BMessage(CAYA_MOVE_UP), B_UP_ARROW, B_COMMAND_KEY));
|
|
|
|
windowMenu->AddItem(new BMenuItem("Down",
|
|
|
|
new BMessage(CAYA_MOVE_DOWN), B_DOWN_ARROW, B_COMMAND_KEY));
|
2021-05-31 10:50:43 -05:00
|
|
|
windowMenu->SetTargetForItems(this);
|
2021-05-30 20:45:24 -05:00
|
|
|
|
2021-05-30 12:30:26 -05:00
|
|
|
menuBar->AddItem(programMenu);
|
|
|
|
menuBar->AddItem(chatMenu);
|
2021-05-30 20:45:24 -05:00
|
|
|
menuBar->AddItem(windowMenu);
|
2021-06-12 16:13:52 -05:00
|
|
|
|
2021-05-30 12:30:26 -05:00
|
|
|
return menuBar;
|
2011-12-14 17:36:27 -06:00
|
|
|
}
|
2021-05-26 07:48:25 -05:00
|
|
|
|
|
|
|
|
2021-06-12 16:13:52 -05:00
|
|
|
void
|
|
|
|
MainWindow::_ToggleMenuItems()
|
|
|
|
{
|
|
|
|
BMenuItem* chatMenuItem = fMenuBar->FindItem("Chat");
|
|
|
|
BMenu* chatMenu = chatMenuItem->Submenu();
|
|
|
|
if (chatMenuItem == NULL || chatMenu == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool enabled = false;
|
|
|
|
if (fServer != NULL && fServer->GetAccounts().CountItems() > 0)
|
|
|
|
enabled = true;
|
|
|
|
|
|
|
|
for (int i = 0; i < chatMenu->CountItems(); i++)
|
|
|
|
chatMenu->ItemAt(i)->SetEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-27 11:15:30 -05:00
|
|
|
ConversationItem*
|
|
|
|
MainWindow::_EnsureConversationItem(BMessage* msg)
|
|
|
|
{
|
|
|
|
ChatMap chats = fServer->Conversations();
|
|
|
|
|
|
|
|
BString chat_id = msg->FindString("chat_id");
|
Explicitly tie Conversations, Contacts, and Users to their ProtocolLoopers
Previously, all Conversations/Contacts/Users were stored in the Server,
each in their respective KeyMaps, identified solely by their
identifiers. This leads to the glaring problem of overlap― if the user
has multiple accounts, some users/rooms might be used or present in multiple
accounts at the same time.
Now, each accounts' Contacts, Conversations, and Users are stored in
its ProtocolLooper, making this overlap impossible. An oversight of only
allowing one user identifier to be stored (fMySelf) in Server was also fixed
this way.
This is the bulk of the work required for multi-account support― now,
the user can join the same XMPP room on two seperate accounts, and it
works perfectly.
2021-06-10 15:16:43 -05:00
|
|
|
Conversation* chat = fServer->ConversationById(chat_id, msg->FindInt64("instance"));
|
2021-06-11 17:24:04 -05:00
|
|
|
ConversationItem* item = chat->GetListItem();
|
2021-05-27 11:15:30 -05:00
|
|
|
|
|
|
|
if (chat != NULL) {
|
2021-06-11 17:24:04 -05:00
|
|
|
if (fListView->HasItem(item))
|
|
|
|
fListView->InvalidateItem(fListView->IndexOf(item));
|
|
|
|
else if (item != NULL)
|
|
|
|
fListView->AddConversation(chat);
|
2021-05-30 20:45:24 -05:00
|
|
|
|
2021-06-11 17:24:04 -05:00
|
|
|
if (fListView->CountConversations() == 1)
|
|
|
|
fListView->SelectConversation(0);
|
2021-05-27 11:15:30 -05:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|