Use Server::Get(), clean up header usage

Instead of passing around pointers to the Server, Server::Get() returns
the server's pointer (simplifying some things a good bit).
As a result, headers have been cleaned up, and some redundant KeyMaps
have been placed in Maps.h.
This commit is contained in:
Jaidyn Ann 2022-02-23 15:42:46 -06:00
parent e092128200
commit dce82c2ba2
38 changed files with 165 additions and 199 deletions

View File

@ -10,7 +10,9 @@
#include "Conversation.h"
#include "MainWindow.h"
#include "ProtocolLooper.h"
#include "TheApp.h"
#include "User.h"
#undef B_TRANSLATION_CONTEXT

View File

@ -12,10 +12,11 @@
#include <libsupport/KeyMap.h>
#include <libsupport/List.h>
#include "Maps.h"
class Conversation;
class User;
typedef KeyMap<BString, User*> UserMap;
enum cmd_arg_type
@ -61,7 +62,4 @@ private:
List<int32> fArgTypes;
};
typedef KeyMap<BString, ChatCommand*> CommandMap;
#endif // CHAT_COMMAND_H

View File

@ -25,6 +25,7 @@
#include "NotifyMessage.h"
#include "ProtocolLooper.h"
#include "ProtocolManager.h"
#include "Role.h"
#include "Server.h"
#include "TheApp.h"
#include "Utils.h"
@ -186,7 +187,7 @@ Conversation::ImMessage(BMessage* msg)
BString name = CommandName(body);
BString args = CommandArgs(body);
ChatCommand* cmd = _GetServer()->CommandById(name, fLooper->GetInstance());
ChatCommand* cmd = Server::Get()->CommandById(name, fLooper->GetInstance());
if (cmd == NULL) {
if (name == "me")
@ -655,7 +656,7 @@ Conversation::_EnsureUser(BMessage* msg, bool implicit)
user = serverUser;
// Not anywhere; create user
else if (user == NULL) {
user = new User(id, _GetServer()->Looper());
user = new User(id, Server::Get()->Looper());
user->SetProtocolLooper(fLooper);
fLooper->AddUser(user);
}
@ -759,10 +760,3 @@ Conversation::_SortConversationList()
if (fUsers.CountItems() <= 2 || fUsers.CountItems() == 3)
((TheApp*)be_app)->GetMainWindow()->SortConversation(this);
}
Server*
Conversation::_GetServer()
{
return ((TheApp*)be_app)->GetMainWindow()->GetServer();
}

View File

@ -10,22 +10,18 @@
#include <Path.h>
#include <StringList.h>
#include <libsupport/KeyMap.h>
#include "Maps.h"
#include "Notifier.h"
#include "Observer.h"
#include "Role.h"
#include "Server.h"
#include "User.h"
class BBitmap;
class Contact;
class ConversationItem;
class ConversationView;
class ProtocolLooper;
class Role;
class Server;
typedef KeyMap<BString, User*> UserMap;
typedef KeyMap<BString, Role*> RoleMap;
class User;
class Conversation : public Notifier, public Observer {
@ -79,6 +75,8 @@ public:
BPath CachePath() { return fCachePath; }
private:
typedef KeyMap<BString, Role*> RoleMap;
void _WarnUser(BString message);
void _LogChatMessage(BMessage* msg);
@ -96,8 +94,6 @@ private:
void _SortConversationList();
Server* _GetServer();
BMessenger fMessenger;
ProtocolLooper* fLooper;
ConversationView* fChatView;

26
application/Maps.h Normal file
View File

@ -0,0 +1,26 @@
/*
* Copyright 2022, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef _MAPS_H
#define _MAPS_H
#include <String.h>
#include "libsupport/KeyMap.h"
class ChatCommand;
class Command;
class Contact;
class Conversation;
class User;
// Defining some commonly-used KeyMaps
typedef KeyMap<BString, bigtime_t> AccountInstances;
typedef KeyMap<BString, ChatCommand*> CommandMap;
typedef KeyMap<BString, Conversation*> ChatMap;
typedef KeyMap<BString, Contact*> RosterMap;
typedef KeyMap<BString, User*> UserMap;
#endif // _MAPS_H

View File

@ -13,11 +13,13 @@
#include "ProtocolLooper.h"
#include <Bitmap.h>
#include <Catalog.h>
#include <String.h>
#include "Account.h"
#include "AppMessages.h"
#include "ChatProtocolMessages.h"
#include "Contact.h"
#include "Conversation.h"
#include "ConversationAccountItem.h"
#include "ConversationView.h"
@ -253,6 +255,10 @@ ProtocolLooper::LoadCommands()
}
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Protocol system buffer"
void
ProtocolLooper::_InitChatView()
{

View File

@ -11,10 +11,9 @@
#include <ObjectList.h>
#include <String.h>
#include <libsupport/KeyMap.h>
#include "ChatProtocol.h"
#include "ChatCommand.h"
#include "Maps.h"
class Contact;
class Conversation;
@ -23,11 +22,6 @@ class ConversationView;
class User;
typedef KeyMap<BString, Conversation*> ChatMap;
typedef KeyMap<BString, Contact*> RosterMap;
typedef KeyMap<BString, User*> UserMap;
class ProtocolLooper : public BLooper {
public:
ProtocolLooper(ChatProtocol* protocol, int64 instance);

View File

@ -140,7 +140,7 @@ ProtocolManager::AddAccount(ChatProtocolAddOn* addOn, const char* account,
{
// If already active, don't double-dip!
bool active = false;
_Server()->GetActiveAccounts().ValueFor(BString(account), &active);
Server::Get()->GetActiveAccounts().ValueFor(BString(account), &active);
if (active == true)
return;
@ -165,7 +165,7 @@ ProtocolManager::AddAccount(ChatProtocolAddOn* addOn, const char* account,
fProtocolMap.AddItem(instanceId, cayap);
_Server()->AddProtocolLooper(instanceId, cayap);
Server::Get()->AddProtocolLooper(instanceId, cayap);
}
@ -189,7 +189,7 @@ ProtocolManager::DisableAccount(ProtocolSettings* settings, const char* account)
{
bool active = false;
int64 instance
= _Server()->GetActiveAccounts().ValueFor(BString(account), &active);
= Server::Get()->GetActiveAccounts().ValueFor(BString(account), &active);
if (active == false)
return;
@ -214,7 +214,7 @@ ProtocolManager::ToggleAccount(ProtocolSettings* settings, const char* account)
{
bool active = false;
int64 instance
= _Server()->GetActiveAccounts().ValueFor(BString(account), &active);
= Server::Get()->GetActiveAccounts().ValueFor(BString(account), &active);
if (active == true)
DisableAccount(settings, account);
@ -280,11 +280,3 @@ ProtocolManager::_MainWin()
{
return ((TheApp*)be_app)->GetMainWindow();
}
Server*
ProtocolManager::_Server()
{
MainWindow* win = _MainWin();
return win ? win->GetServer() : NULL;
}

View File

@ -64,7 +64,6 @@ private:
BEntry accountEntry, BHandler* target);
MainWindow* _MainWin();
Server* _Server();
AddOnMap fAddOnMap;
ProtocolMap fProtocolMap;

View File

@ -48,6 +48,9 @@
#define B_TRANSLATION_CONTEXT "Server"
Server* Server::fInstance = NULL;
Server::Server()
:
BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE)
@ -82,6 +85,15 @@ Server::Server()
}
Server*
Server::Get()
{
if (fInstance == NULL)
fInstance = new Server();
return fInstance;
}
void
Server::Quit()
{

View File

@ -1,6 +1,7 @@
/*
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
* Copyright 2021-2022, Jaidyn Levesque. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _SERVER_H
@ -25,14 +26,10 @@ class RosterItem;
class ProtocolLooper;
typedef KeyMap<bigtime_t, ProtocolLooper*> ProtocolLoopers;
typedef KeyMap<BString, bigtime_t> AccountInstances;
typedef KeyMap<BString, bool> BoolMap;
class Server: public BMessageFilter, public Notifier {
public:
Server();
static Server* Get();
void Quit();
void LoginAll();
void Login(ProtocolLooper* looper);
@ -70,6 +67,9 @@ public:
BObjectList<BMessage> UserPopUpItems();
private:
typedef KeyMap<BString, bool> BoolMap;
typedef KeyMap<bigtime_t, ProtocolLooper*> ProtocolLoopers;
ProtocolLooper* _LooperFromMessage(BMessage* message);
Contact* _EnsureContact(BMessage* message);
@ -87,6 +87,8 @@ private:
void _ReplicantStatusNotify(UserStatus status);
static Server* fInstance;
ProtocolLoopers fLoopers;
AccountInstances fAccounts;
BoolMap fAccountEnabled;

View File

@ -11,10 +11,8 @@
#include <stdio.h>
#include "ChatProtocolMessages.h"
#include "MainWindow.h"
#include "NotifyMessage.h"
#include "Server.h"
#include "TheApp.h"
static StatusManager* fInstance = NULL;
@ -52,14 +50,12 @@ StatusManager::SetNickname(BString nick, int64 instance)
msg->AddString("user_name", nick);
// Send message
TheApp* theApp = reinterpret_cast<TheApp*>(be_app);
MainWindow* win = theApp->GetMainWindow();
if (instance > -1) {
msg->AddInt64("instance", instance);
win->GetServer()->SendProtocolMessage(msg);
Server::Get()->SendProtocolMessage(msg);
}
else
win->GetServer()->SendAllProtocolMessage(msg);
Server::Get()->SendAllProtocolMessage(msg);
}
@ -91,15 +87,12 @@ StatusManager::SetStatus(UserStatus status, const char* str, int64 instance)
msg->AddString("message", str);
// Send message
TheApp* theApp = reinterpret_cast<TheApp*>(be_app);
MainWindow* win = theApp->GetMainWindow();
if (instance > -1) {
msg->AddInt64("instance", instance);
win->GetServer()->SendProtocolMessage(msg);
Server::Get()->SendProtocolMessage(msg);
}
else
win->GetServer()->SendAllProtocolMessage(msg);
Server::Get()->SendAllProtocolMessage(msg);
// Notify status change
fStatus = status;

View File

@ -89,7 +89,7 @@ TheApp::ReadyToRun()
if (win == false) {
BString msg(B_TRANSLATE("No protocols found!\nPlease make sure %app% was installed correctly."));
msg.ReplaceAll("%app%", APP_NAME);
msg.ReplaceAll("%app%", B_TRANSLATE_SYSTEM_NAME(APP_NAME));
BAlert* alert = new BAlert("", msg.String(), B_TRANSLATE("Ouch!"));
alert->Go();
PostMessage(B_QUIT_REQUESTED);

View File

@ -14,8 +14,7 @@
#include <Path.h>
#include <String.h>
#include <libsupport/KeyMap.h>
#include "Maps.h"
#include "Notifier.h"
#include "UserStatus.h"
@ -26,9 +25,6 @@ class ProtocolLooper;
class UserPopUp;
typedef KeyMap<BString, Conversation*> ChatMap;
class User : public Notifier {
public:
User(BString id, BMessenger msgn);

View File

@ -14,7 +14,7 @@
#include <Resources.h>
#include "AppConstants.h"
#include "Server.h"
#include "UserStatus.h"
class BMenu;

View File

@ -6,6 +6,8 @@
#include "AppPreferences.h"
#include <Path.h>
#include "Utils.h"

View File

@ -14,9 +14,7 @@
#include "AccountMenuItem.h"
#include "ImageCache.h"
#include "MainWindow.h"
#include "Server.h"
#include "TheApp.h"
#undef B_TRANSLATION_CONTEXT
@ -26,33 +24,23 @@
int64 AccountsMenu::fDefaultSelection = -1;
AccountsMenu::AccountsMenu(const char* name, BMessage msg, BMessage* allMsg,
Server* server)
AccountsMenu::AccountsMenu(const char* name, BMessage msg, BMessage* allMsg)
:
BPopUpMenu(name),
fAccountMessage(msg),
fAllMessage(allMsg),
fServer(server)
fAllMessage(allMsg)
{
_PopulateMenu();
SetRadioMode(true);
SetLabelFromMarked(true);
fServer->RegisterObserver(this);
}
AccountsMenu::AccountsMenu(const char* name, BMessage msg, BMessage* allMsg)
:
AccountsMenu(name, msg, allMsg,
((TheApp*)be_app)->GetMainWindow()->GetServer())
{
Server::Get()->RegisterObserver(this);
}
AccountsMenu::~AccountsMenu()
{
delete fAllMessage;
fServer->UnregisterObserver(this);
Server::Get()->UnregisterObserver(this);
}
@ -80,7 +68,7 @@ AccountsMenu::_PopulateMenu()
icon, 0, 0, false));
}
AccountInstances accounts = fServer->GetActiveAccounts();
AccountInstances accounts = Server::Get()->GetActiveAccounts();
// Add protocol item if not already in menu
for (int i = 0; i < accounts.CountItems(); i++) {
@ -98,7 +86,7 @@ AccountsMenu::_PopulateMenu()
if (FindItem(label.String()) != NULL)
continue;
ProtocolLooper* looper = fServer->GetProtocolLooper(instance);
ProtocolLooper* looper = Server::Get()->GetProtocolLooper(instance);
BBitmap* icon = _EnsureProtocolIcon(label.String(), looper);
BMessage* message = new BMessage(fAccountMessage);

View File

@ -10,13 +10,10 @@
#include "Observer.h"
class ProtocolLooper;
class Server;
class AccountsMenu : public BPopUpMenu, public Observer {
public:
AccountsMenu(const char* name, BMessage msg,
BMessage* allMsg, Server* server);
AccountsMenu(const char* name, BMessage msg,
BMessage* allMsg = NULL);
~AccountsMenu();
@ -37,7 +34,6 @@ private:
BMessage fAccountMessage;
BMessage* fAllMessage;
static int64 fDefaultSelection;
Server* fServer;
};
#endif // _ACCOUNTS_MENU_H

View File

@ -15,10 +15,10 @@
#include "Conversation.h"
#include "ConversationAccountItem.h"
#include "ConversationItem.h"
#include "Flags.h"
#include "MainWindow.h"
#include "ProtocolLooper.h"
#include "Server.h"
#include "TheApp.h"
#undef B_TRANSLATION_CONTEXT
@ -167,8 +167,7 @@ ConversationListView::RemoveConversation(Conversation* chat)
void
ConversationListView::AddAccount(int64 instance)
{
Server* server = ((TheApp*)be_app)->GetMainWindow()->GetServer();
ProtocolLooper* looper = server->GetProtocolLooper(instance);
ProtocolLooper* looper = Server::Get()->GetProtocolLooper(instance);
if (looper == NULL)
return;
AddItem(looper->GetListItem());
@ -190,7 +189,7 @@ ConversationListView::RemoveAccount(int64 instance)
}
}
if (CountItems() == 0)
((TheApp*)be_app)->GetMainWindow()->SetConversation(NULL);
((MainWindow*)Window())->SetConversation(NULL);
}
@ -215,7 +214,6 @@ ConversationListView::_ConversationPopUp()
Conversation* chat = item->GetConversation();
ProtocolLooper* looper = chat->GetProtocolLooper();
Server* server = ((TheApp*)be_app)->GetMainWindow()->GetServer();
_AddDefaultItems(menu, chat);
BObjectList<BMessage> items = looper->Protocol()->ChatPopUpItems();
@ -302,7 +300,7 @@ ConversationListView::_BlankPopUp()
{
bool enabled = false;
Server* server = ((TheApp*)be_app)->GetMainWindow()->GetServer();
Server* server = Server::Get();
if (server != NULL && server->GetAccounts().CountItems() > 0)
enabled = true;

View File

@ -24,8 +24,10 @@
#include "AppMessages.h"
#include "AppPreferences.h"
#include "ChatProtocolMessages.h"
#include "Contact.h"
#include "Conversation.h"
#include "NotifyMessage.h"
#include "ProtocolLooper.h"
#include "ProtocolManager.h"
#include "RenderView.h"
#include "SendTextView.h"

View File

@ -26,8 +26,6 @@ class UserListView;
const uint32 kClearText = 'CVct';
typedef KeyMap<uint16, int32> UInt16IntMap;
class ConversationView : public BGroupView, public Observer, public Notifier {
public:
@ -54,6 +52,8 @@ public:
float vertChat, float vertSend);
private:
typedef KeyMap<uint16, int32> UInt16IntMap;
void _InitInterface();
bool _AppendOrEnqueueMessage(BMessage* msg);

View File

@ -23,6 +23,7 @@
#include "ChatProtocolMessages.h"
#include "RosterItem.h"
#include "RosterListView.h"
#include "Server.h"
#undef B_TRANSLATION_CONTEXT
@ -32,11 +33,10 @@
const uint32 kSearchContact = 'RWSC';
RosterView::RosterView(const char* title, Server* server, bigtime_t account)
RosterView::RosterView(const char* title, bigtime_t account)
:
BGroupView(title, B_VERTICAL, B_USE_DEFAULT_SPACING),
fAccount(-1),
fServer(server),
fManualItem(new BStringItem("")),
fManualStr("Select user %user%" B_UTF8_ELLIPSIS)
{
@ -121,7 +121,7 @@ RosterView::ImMessage(BMessage* msg)
|| user_id.IsEmpty() == true)
return;
Contact* contact = fServer->ContactById(user_id, instance);
Contact* contact = Server::Get()->ContactById(user_id, instance);
if (contact == NULL)
return;
@ -189,7 +189,7 @@ RosterView::ImMessage(BMessage* msg)
|| msg->FindInt64("instance", &instance) != B_OK
|| user_id.IsEmpty() == true)
return;
Contact* contact = fServer->ContactById(user_id, instance);
Contact* contact = Server::Get()->ContactById(user_id, instance);
if (contact == NULL)
return;
RosterItem* rosterItem = contact->GetRosterItem();
@ -208,7 +208,7 @@ RosterView::ImMessage(BMessage* msg)
|| user_id.IsEmpty() == true)
return;
Contact* contact = fServer->ContactById(user_id, instance);
Contact* contact = Server::Get()->ContactById(user_id, instance);
if (contact == NULL)
return;
@ -268,9 +268,9 @@ RosterView::_RosterMap()
{
RosterMap contacts;
if (fAccount < 0)
contacts = fServer->Contacts();
contacts = Server::Get()->Contacts();
else {
ProtocolLooper* looper = fServer->GetProtocolLooper(fAccount);
ProtocolLooper* looper = Server::Get()->GetProtocolLooper(fAccount);
contacts = looper->Contacts();
}
return contacts;

View File

@ -14,18 +14,17 @@
#include <GroupView.h>
#include "Server.h"
#include "Maps.h"
class BStringItem;
class BTextControl;
class RosterItem;
class RosterListView;
class Server;
class RosterView : public BGroupView {
public:
RosterView(const char* title, Server* server, bigtime_t account = -1);
RosterView(const char* title, bigtime_t account = -1);
void MessageReceived(BMessage* message);
void ImMessage(BMessage* msg);
@ -46,7 +45,6 @@ public:
private:
RosterMap _RosterMap();
Server* fServer;
RosterListView* fListView;
BTextControl* fSearchBox;
bigtime_t fAccount;

View File

@ -9,9 +9,7 @@
#include <Window.h>
#include "AppMessages.h"
#include "MainWindow.h"
#include "Server.h"
#include "TheApp.h"
SendTextView::SendTextView(const char* name, ConversationView* convView)
@ -126,8 +124,7 @@ SendTextView::_CommandNames()
if (fCurrentIndex == 0) {
int64 instance = fChatView->GetConversation()->GetProtocolLooper()->GetInstance();
BStringList cmdNames;
CommandMap cmds =
((TheApp*)be_app)->GetMainWindow()->GetServer()->Commands(instance);
CommandMap cmds = Server::Get()->Commands(instance);
for (int i = 0; i < cmds.CountItems(); i++)
cmdNames.Add(cmds.KeyAt(i));

View File

@ -36,10 +36,9 @@ const int32 kSelectAccount = 'SVsa';
const int32 kSetNick = 'SVsn';
StatusView::StatusView(const char* name, Server* server)
StatusView::StatusView(const char* name)
:
BView(name, B_WILL_DRAW),
fServer(server),
fAccount(-1)
{
// Nick name
@ -85,7 +84,7 @@ StatusView::StatusView(const char* name, Server* server)
// Changing the account used
fAccountsMenu = new AccountsMenu("statusAccountsMenu",
BMessage(kSelectAccount), new BMessage(kSelectAccount), fServer);
BMessage(kSelectAccount), new BMessage(kSelectAccount));
fAccountsButton = new MenuButton("statusAccountsButton", "", new BMessage());
fAccountsButton->SetMenu(fAccountsMenu);
@ -195,9 +194,9 @@ StatusView::_SetToAccount()
{
int64 instance = fAccount;
if (instance == -1)
instance = fServer->GetActiveAccounts().ValueAt(0);
instance = Server::Get()->GetActiveAccounts().ValueAt(0);
ProtocolLooper* looper = fServer->GetProtocolLooper(instance);
ProtocolLooper* looper = Server::Get()->GetProtocolLooper(instance);
if (looper == NULL || looper->GetOwnContact() == NULL)
return;
Contact* contact = looper->GetOwnContact();

View File

@ -17,11 +17,10 @@ class AccountsMenu;
class BitmapView;
class EnterTextView;
class MenuButton;
class Server;
class StatusView : public BView, public Observer {
public:
StatusView(const char* name, Server* server);
StatusView(const char* name);
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* msg);
@ -45,8 +44,6 @@ private:
MenuButton* fAccountsButton;
AccountsMenu* fAccountsMenu;
int64 fAccount;
Server* fServer;
};
#endif // _STATUS_VIEW_H

View File

@ -13,11 +13,9 @@
#include "AppMessages.h"
#include "ChatProtocolMessages.h"
#include "Conversation.h"
#include "MainWindow.h"
#include "ProtocolLooper.h"
#include "Role.h"
#include "Server.h"
#include "TheApp.h"
#include "User.h"
#include "UserInfoWindow.h"
#include "UserItem.h"
@ -108,8 +106,7 @@ UserListView::_UserPopUp()
Role* selected_role = fChat->GetRole(selected_user->GetId());
Server* server = ((TheApp*)be_app)->GetMainWindow()->GetServer();
BObjectList<BMessage> items = server->UserPopUpItems();
BObjectList<BMessage> items = Server::Get()->UserPopUpItems();
BObjectList<BMessage> protoItems = fChat->GetProtocolLooper()->Protocol()->UserPopUpItems();
items.AddList(&protoItems);

View File

@ -27,9 +27,7 @@
#include "ChatProtocolMessages.h"
#include "ProtocolManager.h"
#include "ProtocolSettings.h"
#include "MainWindow.h"
#include "Server.h"
#include "TheApp.h"
#undef B_TRANSLATION_CONTEXT
@ -288,8 +286,7 @@ int64
AccountsWindow::_AccountInstance(const char* account)
{
bool found = false;
AccountInstances accs =
((TheApp*)be_app)->GetMainWindow()->GetServer()->GetAccounts();
AccountInstances accs = Server::Get()->GetAccounts();
int64 instance = accs.ValueFor(BString(account), &found);
if (found == false)

View File

@ -41,6 +41,7 @@
#include "RoomListWindow.h"
#include "RosterEditWindow.h"
#include "RosterWindow.h"
#include "Server.h"
#include "StatusManager.h"
#include "StatusView.h"
#include "TemplateWindow.h"
@ -59,12 +60,10 @@ MainWindow::MainWindow()
B_TRANSLATE_SYSTEM_NAME(APP_NAME), B_TITLED_WINDOW, 0),
fWorkspaceChanged(false),
fConversation(NULL),
fRosterWindow(NULL),
fServer(NULL)
fRosterWindow(NULL)
{
// Filter messages using Server
fServer = new Server();
AddFilter(fServer);
AddFilter(Server::Get());
_InitInterface();
@ -84,7 +83,7 @@ MainWindow::Start()
MessageReceived(new BMessage(APP_SHOW_ACCOUNTS));
// Login all accounts
fServer->LoginAll();
Server::Get()->LoginAll();
}
@ -115,7 +114,7 @@ MainWindow::QuitRequested()
_SaveWeights();
if (button_index == 0) {
fServer->Quit();
Server::Get()->Quit();
// ConversationViews will be removed by Server's deletion of Conversations,
// but some special views (protocol logs, the blank ConversationView)
@ -181,7 +180,7 @@ MainWindow::MessageReceived(BMessage* message)
newMsg->AddInt32("im_what", IM_CREATE_CHAT);
fRosterWindow = new RosterWindow(B_TRANSLATE("Invite contact to "
"chat" B_UTF8_ELLIPSIS), newMsg, new BMessenger(this), fServer);
"chat" B_UTF8_ELLIPSIS), newMsg, new BMessenger(this));
fRosterWindow->Show();
break;
}
@ -191,7 +190,7 @@ MainWindow::MessageReceived(BMessage* message)
createMsg->AddInt32("im_what", IM_CREATE_ROOM);
TemplateWindow* win = new TemplateWindow(B_TRANSLATE("Create room"),
"create_room", createMsg, fServer);
"create_room", createMsg);
win->Show();
break;
}
@ -201,7 +200,7 @@ MainWindow::MessageReceived(BMessage* message)
joinMsg->AddInt32("im_what", IM_JOIN_ROOM);
TemplateWindow* win = new TemplateWindow(B_TRANSLATE("Join a room"),
"join_room", joinMsg, fServer);
"join_room", joinMsg);
win->Show();
break;
}
@ -218,7 +217,7 @@ MainWindow::MessageReceived(BMessage* message)
ProtocolLooper* plooper = fConversation->GetProtocolLooper();
BLooper* looper = (BLooper*)plooper;
fRosterWindow = new RosterWindow(B_TRANSLATE("Invite contact to "
"chat" B_UTF8_ELLIPSIS), invite, new BMessenger(looper), fServer,
"chat" B_UTF8_ELLIPSIS), invite, new BMessenger(looper),
plooper->GetInstance());
fRosterWindow->Show();
@ -226,7 +225,7 @@ MainWindow::MessageReceived(BMessage* message)
}
case APP_ROOM_DIRECTORY:
{
RoomListWindow::Get(fServer)->Show();
RoomListWindow::Get()->Show();
break;
}
case APP_ROOM_SEARCH:
@ -246,7 +245,7 @@ MainWindow::MessageReceived(BMessage* message)
}
case APP_EDIT_ROSTER:
{
RosterEditWindow::Get(fServer)->Show();
RosterEditWindow::Get()->Show();
break;
}
case APP_MOVE_UP:
@ -340,7 +339,7 @@ MainWindow::ImMessage(BMessage* msg)
{
int64 instance;
if (msg->FindInt64("instance", &instance) == B_OK) {
ProtocolLooper* looper = fServer->GetProtocolLooper(instance);
ProtocolLooper* looper = Server::Get()->GetProtocolLooper(instance);
if (looper != NULL) {
Contact* contact = looper->GetOwnContact();
contact->RegisterObserver(fStatusView);
@ -375,7 +374,7 @@ MainWindow::ImMessage(BMessage* msg)
if (fRosterWindow != NULL)
fRosterWindow->PostMessage(msg);
if (RosterEditWindow::Check() == true)
RosterEditWindow::Get(fServer)->PostMessage(msg);
RosterEditWindow::Get()->PostMessage(msg);
break;
}
case IM_PROTOCOL_READY: {
@ -389,7 +388,7 @@ MainWindow::ImMessage(BMessage* msg)
}
case IM_ROOM_DIRECTORY:
if (RoomListWindow::Check() == true)
RoomListWindow::Get(fServer)->PostMessage(msg);
RoomListWindow::Get()->PostMessage(msg);
break;
case IM_PROTOCOL_DISABLE:
fStatusView->MessageReceived(msg);
@ -496,7 +495,7 @@ MainWindow::_InitInterface()
{
// Left side of window, Roomlist + Status
fListView = new ConversationListView("roomList");
fStatusView = new StatusView("statusView", fServer);
fStatusView = new StatusView("statusView");
fSplitView = new BSplitView(B_HORIZONTAL, 0);
BScrollView* listScroll = new BScrollView("roomListScroll", fListView,
@ -662,7 +661,8 @@ MainWindow::_ToggleMenuItems()
if (chatMenu == NULL || rosterMenu == NULL)
return;
bool enabled = (fServer != NULL && fServer->GetAccounts().CountItems() > 0);
Server* server = Server::Get();
bool enabled = (server != NULL && server->GetAccounts().CountItems() > 0);
for (int i = 0; i < chatMenu->CountItems(); i++)
chatMenu->ItemAt(i)->SetEnabled(enabled);
@ -683,7 +683,7 @@ ConversationItem*
MainWindow::_EnsureConversationItem(BMessage* msg)
{
BString chat_id = msg->FindString("chat_id");
Conversation* chat = fServer->ConversationById(chat_id, msg->FindInt64("instance"));
Conversation* chat = Server::Get()->ConversationById(chat_id, msg->FindInt64("instance"));
_EnsureConversationView(chat);
@ -775,7 +775,7 @@ MainWindow::_PopulateWithAccounts(BMenu* menu, ProtocolSettings* settings)
BString toggleLabel = B_TRANSLATE("Enable");
bool isActive = false;
int64 instance = fServer->GetActiveAccounts().ValueFor(*account, &isActive);
int64 instance = Server::Get()->GetActiveAccounts().ValueFor(*account, &isActive);
if (isActive == true)
toggleLabel = B_TRANSLATE("Disable");

View File

@ -9,7 +9,7 @@
#include <Window.h>
#include "Server.h"
#include "libsupport/KeyMap.h"
class BCardLayout;
class BLayoutItem;
@ -24,7 +24,6 @@ class ConversationView;
class ProtocolSettings;
class RosterItem;
class RosterWindow;
class Server;
class StatusView;
@ -47,8 +46,6 @@ public:
void RemoveConversation(Conversation* chat);
void SortConversation(Conversation* chat);
Server* GetServer() const { return fServer; }
private:
void _InitInterface();
@ -70,7 +67,6 @@ private:
ProtocolSettings* settings);
void _ReplaceMenu(const char* name, BMenu* newMenu);
Server* fServer;
RosterWindow* fRosterWindow;
bool fWorkspaceChanged;
BMenuBar* fMenuBar;

View File

@ -29,12 +29,11 @@ const uint32 kJoinRoom = 'join';
RoomListWindow* RoomListWindow::fInstance = NULL;
RoomListWindow::RoomListWindow(Server* server)
RoomListWindow::RoomListWindow()
:
BWindow(AppPreferences::Get()->RoomDirectoryRect,
B_TRANSLATE("Room directory"), B_FLOATING_WINDOW,
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS),
fServer(server),
fAccount(-1)
{
_InitInterface();
@ -42,7 +41,7 @@ RoomListWindow::RoomListWindow(Server* server)
BMessage* request = new BMessage(IM_MESSAGE);
request->AddInt32("im_what", IM_GET_ROOM_DIRECTORY);
server->SendAllProtocolMessage(request);
Server::Get()->SendAllProtocolMessage(request);
}
@ -61,10 +60,10 @@ RoomListWindow::~RoomListWindow()
RoomListWindow*
RoomListWindow::Get(Server* server)
RoomListWindow::Get()
{
if (fInstance == NULL)
fInstance = new RoomListWindow(server);
fInstance = new RoomListWindow();
return fInstance;
}
@ -147,7 +146,7 @@ RoomListWindow::MessageReceived(BMessage* msg)
if (row != NULL) {
BMessage* joinMsg = row->Message();
joinMsg->ReplaceInt32("im_what", IM_JOIN_ROOM);
fServer->SendProtocolMessage(joinMsg);
Server::Get()->SendProtocolMessage(joinMsg);
Quit();
}
break;
@ -179,7 +178,7 @@ RoomListWindow::_InitInterface()
fListView->AddColumn(users, kUserColumn);
AccountsMenu* accsMenu = new AccountsMenu("accounts", BMessage(kSelectAcc),
new BMessage(kSelectAll), fServer);
new BMessage(kSelectAll));
BMenuField* accsField = new BMenuField(NULL, accsMenu);
fJoinButton = new BButton("joinRoom", B_TRANSLATE("Join"),

View File

@ -13,7 +13,6 @@
class BButton;
class BColumnListView;
class RoomListRow;
class Server;
typedef KeyMap<int64, BObjectList<RoomListRow>*> RowMap;
@ -21,10 +20,10 @@ typedef KeyMap<int64, BObjectList<RoomListRow>*> RowMap;
class RoomListWindow : public BWindow {
public:
RoomListWindow(Server* server);
RoomListWindow();
~RoomListWindow();
static RoomListWindow* Get(Server* server);
static RoomListWindow* Get();
static bool Check();
virtual void MessageReceived(BMessage* msg);
@ -40,7 +39,6 @@ private:
RowMap fRows;
int64 fAccount;
Server* fServer;
static RoomListWindow* fInstance;
};

View File

@ -24,9 +24,12 @@
#include "AppMessages.h"
#include "AppPreferences.h"
#include "ChatProtocolMessages.h"
#include "Maps.h"
#include "ProtocolLooper.h"
#include "RosterItem.h"
#include "RosterListView.h"
#include "RosterView.h"
#include "Server.h"
#include "TemplateWindow.h"
@ -47,14 +50,13 @@ const char* kEditTitle = B_TRANSLATE("Editing contact");
RosterEditWindow* RosterEditWindow::fInstance = NULL;
RosterEditWindow::RosterEditWindow(Server* server)
RosterEditWindow::RosterEditWindow()
:
BWindow(BRect(0, 0, 300, 400), B_TRANSLATE("Roster"), B_FLOATING_WINDOW,
B_AUTO_UPDATE_SIZE_LIMITS),
fServer(server),
fEditingWindow(NULL)
{
fRosterView = new RosterView("buddyView", server);
fRosterView = new RosterView("buddyView");
fRosterView->SetInvocationMessage(new BMessage(kEditMember));
fRosterView->SetManualString(BString("Add %user% as contact"
B_UTF8_ELLIPSIS));
@ -104,10 +106,10 @@ RosterEditWindow::~RosterEditWindow()
RosterEditWindow*
RosterEditWindow::Get(Server* server)
RosterEditWindow::Get()
{
if (fInstance == NULL) {
fInstance = new RosterEditWindow(server);
fInstance = new RosterEditWindow();
}
return fInstance;
}
@ -172,7 +174,7 @@ RosterEditWindow::MessageReceived(BMessage* message)
fEditingWindow =
new TemplateWindow(title, "roster",
edit, fServer, instance);
edit, instance);
fEditingWindow->Show();
if (ritem == NULL) {
@ -188,7 +190,7 @@ RosterEditWindow::MessageReceived(BMessage* message)
add->AddInt32("im_what", IM_ROSTER_ADD_CONTACT);
TemplateWindow* win =
new TemplateWindow(B_TRANSLATE(kAddTitle), "roster",
add, fServer);
add);
win->Show();
break;
}
@ -216,7 +218,7 @@ RosterEditWindow::MessageReceived(BMessage* message)
}
case kSelAccount:
{
AccountInstances accounts = fServer->GetActiveAccounts();
AccountInstances accounts = Server::Get()->GetActiveAccounts();
int index = message->FindInt32("index") - 1;
if (index < 0 || index > (accounts.CountItems() - 1))

View File

@ -14,8 +14,6 @@
#include <Window.h>
#include "Server.h"
class BMenuField;
class RosterItem;
class RosterView;
@ -26,9 +24,9 @@ class TemplateWindow;
the server with contact info, once a contact is selected. */
class RosterEditWindow : public BWindow {
public:
RosterEditWindow(Server* server);
RosterEditWindow();
~RosterEditWindow();
static RosterEditWindow* Get(Server* server);
static RosterEditWindow* Get();
static bool Check();
void MessageReceived(BMessage* message);
@ -40,7 +38,6 @@ private:
BString fEditingUser;
TemplateWindow* fEditingWindow;
Server* fServer;
RosterView* fRosterView;
static RosterEditWindow* fInstance;

View File

@ -25,6 +25,7 @@
#include "RosterItem.h"
#include "RosterListView.h"
#include "RosterView.h"
#include "Server.h"
const uint32 kSendMessage = 'RWSM';
@ -33,20 +34,19 @@ const uint32 kSelNoAccount = 'RWNA';
RosterWindow::RosterWindow(const char* title, BMessage* selectMsg,
BMessenger* messenger, Server* server, bigtime_t instance)
BMessenger* messenger, bigtime_t instance)
:
BWindow(BRect(0, 0, 300, 400), title, B_FLOATING_WINDOW,
B_AUTO_UPDATE_SIZE_LIMITS),
fTarget(messenger),
fMessage(selectMsg),
fServer(server)
fMessage(selectMsg)
{
fRosterView = new RosterView("buddyView", server, instance),
fRosterView = new RosterView("buddyView", instance);
fRosterView->SetInvocationMessage(new BMessage(kSendMessage));
fOkButton = new BButton("OK", new BMessage(kSendMessage));
AccountInstances accounts = fServer->GetActiveAccounts();
AccountInstances accounts = Server::Get()->GetActiveAccounts();
// If a specific instance is given, disallow selecting other accounts
// In fact, don't even bother populating with them
@ -119,7 +119,7 @@ RosterWindow::MessageReceived(BMessage* message)
}
case kSelAccount:
{
AccountInstances accounts = fServer->GetActiveAccounts();
AccountInstances accounts = Server::Get()->GetActiveAccounts();
int index = message->FindInt32("index") - 1;
if (index < 0 || index > (accounts.CountItems() - 1))

View File

@ -14,8 +14,6 @@
#include <Window.h>
#include "Server.h"
class BMenuField;
class RosterItem;
class RosterView;
@ -26,7 +24,7 @@ class RosterView;
class RosterWindow : public BWindow {
public:
RosterWindow(const char* title, BMessage* selectMsg, BMessenger* messenger,
Server* server, bigtime_t instance = -1);
bigtime_t instance = -1);
void MessageReceived(BMessage* message);
@ -36,8 +34,6 @@ private:
BButton* fOkButton;
BMenuField* fAccountField;
Server* fServer;
RosterView* fRosterView;
BMessenger* fTarget;
BMessage* fMessage;

View File

@ -20,6 +20,7 @@
#include "AccountsMenu.h"
#include "ChatProtocolMessages.h"
#include "Server.h"
#include "TemplateView.h"
@ -33,11 +34,10 @@ const uint32 kAccSelected = 'JWas';
TemplateWindow::TemplateWindow(const char* title, const char* templateType,
BMessage* msg, Server* server, bigtime_t instance)
BMessage* msg, bigtime_t instance)
:
BWindow(BRect(0, 0, 400, 100), title, B_FLOATING_WINDOW,
B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
fServer(server),
fSelectedAcc(instance),
fTemplate(NULL),
fTemplateType(templateType),
@ -51,11 +51,10 @@ TemplateWindow::TemplateWindow(const char* title, const char* templateType,
TemplateWindow::TemplateWindow(const char* title, ProtocolTemplate* temp,
BMessage* msg, Server* server, bigtime_t instance)
BMessage* msg, bigtime_t instance)
:
BWindow(BRect(0, 0, 400, 100), title, B_FLOATING_WINDOW,
B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
fServer(server),
fSelectedAcc(-1),
fTemplate(temp),
fMessage(msg)
@ -99,7 +98,7 @@ TemplateWindow::MessageReceived(BMessage* msg)
break;
}
ProtocolLooper* looper = fServer->GetProtocolLooper(fSelectedAcc);
ProtocolLooper* looper = Server::Get()->GetProtocolLooper(fSelectedAcc);
if (looper == NULL)
break;
looper->PostMessage(settings);
@ -131,7 +130,7 @@ void
TemplateWindow::_InitInterface(bigtime_t instance)
{
fTemplateView = new TemplateView("template");
AccountInstances accounts = fServer->GetActiveAccounts();
AccountInstances accounts = Server::Get()->GetActiveAccounts();
if (instance > -1) {
BMenu* accountMenu = new BMenu("accountMenu");
@ -185,7 +184,7 @@ TemplateWindow::_LoadTemplate()
if (fTemplateType.IsEmpty() == true)
return;
ProtocolLooper* looper = fServer->GetProtocolLooper(fSelectedAcc);
ProtocolLooper* looper = Server::Get()->GetProtocolLooper(fSelectedAcc);
if (looper == NULL)
return;

View File

@ -10,7 +10,6 @@
#include <Window.h>
#include "ProtocolTemplate.h"
#include "Server.h"
class BAlert;
class BMenu;
@ -26,12 +25,12 @@ public:
* via ChatProtocol::SettingsTemplate() */
TemplateWindow(const char* title,
const char* templateType, BMessage* msg,
Server* server, bigtime_t instance = -1);
bigtime_t instance = -1);
/*! Use only the given template. */
TemplateWindow(const char* title,
ProtocolTemplate* temp, BMessage* msg,
Server* server, bigtime_t instance = -1);
bigtime_t instance = -1);
virtual void MessageReceived(BMessage* msg);
@ -41,7 +40,6 @@ private:
void _InitInterface(bigtime_t instance);
void _LoadTemplate();
Server* fServer;
int64 fSelectedAcc;
BMenuField* fMenuField;