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 "Conversation.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "ProtocolLooper.h"
#include "TheApp.h" #include "TheApp.h"
#include "User.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT

View File

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

View File

@ -25,6 +25,7 @@
#include "NotifyMessage.h" #include "NotifyMessage.h"
#include "ProtocolLooper.h" #include "ProtocolLooper.h"
#include "ProtocolManager.h" #include "ProtocolManager.h"
#include "Role.h"
#include "Server.h" #include "Server.h"
#include "TheApp.h" #include "TheApp.h"
#include "Utils.h" #include "Utils.h"
@ -186,7 +187,7 @@ Conversation::ImMessage(BMessage* msg)
BString name = CommandName(body); BString name = CommandName(body);
BString args = CommandArgs(body); BString args = CommandArgs(body);
ChatCommand* cmd = _GetServer()->CommandById(name, fLooper->GetInstance()); ChatCommand* cmd = Server::Get()->CommandById(name, fLooper->GetInstance());
if (cmd == NULL) { if (cmd == NULL) {
if (name == "me") if (name == "me")
@ -655,7 +656,7 @@ Conversation::_EnsureUser(BMessage* msg, bool implicit)
user = serverUser; user = serverUser;
// Not anywhere; create user // Not anywhere; create user
else if (user == NULL) { else if (user == NULL) {
user = new User(id, _GetServer()->Looper()); user = new User(id, Server::Get()->Looper());
user->SetProtocolLooper(fLooper); user->SetProtocolLooper(fLooper);
fLooper->AddUser(user); fLooper->AddUser(user);
} }
@ -759,10 +760,3 @@ Conversation::_SortConversationList()
if (fUsers.CountItems() <= 2 || fUsers.CountItems() == 3) if (fUsers.CountItems() <= 2 || fUsers.CountItems() == 3)
((TheApp*)be_app)->GetMainWindow()->SortConversation(this); ((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 <Path.h>
#include <StringList.h> #include <StringList.h>
#include <libsupport/KeyMap.h> #include "Maps.h"
#include "Notifier.h"
#include "Observer.h" #include "Observer.h"
#include "Role.h"
#include "Server.h"
#include "User.h"
class BBitmap; class BBitmap;
class Contact;
class ConversationItem; class ConversationItem;
class ConversationView; class ConversationView;
class ProtocolLooper; class ProtocolLooper;
class Role;
class Server; class Server;
class User;
typedef KeyMap<BString, User*> UserMap;
typedef KeyMap<BString, Role*> RoleMap;
class Conversation : public Notifier, public Observer { class Conversation : public Notifier, public Observer {
@ -79,6 +75,8 @@ public:
BPath CachePath() { return fCachePath; } BPath CachePath() { return fCachePath; }
private: private:
typedef KeyMap<BString, Role*> RoleMap;
void _WarnUser(BString message); void _WarnUser(BString message);
void _LogChatMessage(BMessage* msg); void _LogChatMessage(BMessage* msg);
@ -96,8 +94,6 @@ private:
void _SortConversationList(); void _SortConversationList();
Server* _GetServer();
BMessenger fMessenger; BMessenger fMessenger;
ProtocolLooper* fLooper; ProtocolLooper* fLooper;
ConversationView* fChatView; 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 "ProtocolLooper.h"
#include <Bitmap.h> #include <Bitmap.h>
#include <Catalog.h>
#include <String.h> #include <String.h>
#include "Account.h" #include "Account.h"
#include "AppMessages.h" #include "AppMessages.h"
#include "ChatProtocolMessages.h" #include "ChatProtocolMessages.h"
#include "Contact.h"
#include "Conversation.h" #include "Conversation.h"
#include "ConversationAccountItem.h" #include "ConversationAccountItem.h"
#include "ConversationView.h" #include "ConversationView.h"
@ -253,6 +255,10 @@ ProtocolLooper::LoadCommands()
} }
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Protocol system buffer"
void void
ProtocolLooper::_InitChatView() ProtocolLooper::_InitChatView()
{ {

View File

@ -11,10 +11,9 @@
#include <ObjectList.h> #include <ObjectList.h>
#include <String.h> #include <String.h>
#include <libsupport/KeyMap.h>
#include "ChatProtocol.h" #include "ChatProtocol.h"
#include "ChatCommand.h" #include "ChatCommand.h"
#include "Maps.h"
class Contact; class Contact;
class Conversation; class Conversation;
@ -23,11 +22,6 @@ class ConversationView;
class User; class User;
typedef KeyMap<BString, Conversation*> ChatMap;
typedef KeyMap<BString, Contact*> RosterMap;
typedef KeyMap<BString, User*> UserMap;
class ProtocolLooper : public BLooper { class ProtocolLooper : public BLooper {
public: public:
ProtocolLooper(ChatProtocol* protocol, int64 instance); 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! // If already active, don't double-dip!
bool active = false; bool active = false;
_Server()->GetActiveAccounts().ValueFor(BString(account), &active); Server::Get()->GetActiveAccounts().ValueFor(BString(account), &active);
if (active == true) if (active == true)
return; return;
@ -165,7 +165,7 @@ ProtocolManager::AddAccount(ChatProtocolAddOn* addOn, const char* account,
fProtocolMap.AddItem(instanceId, cayap); 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; bool active = false;
int64 instance int64 instance
= _Server()->GetActiveAccounts().ValueFor(BString(account), &active); = Server::Get()->GetActiveAccounts().ValueFor(BString(account), &active);
if (active == false) if (active == false)
return; return;
@ -214,7 +214,7 @@ ProtocolManager::ToggleAccount(ProtocolSettings* settings, const char* account)
{ {
bool active = false; bool active = false;
int64 instance int64 instance
= _Server()->GetActiveAccounts().ValueFor(BString(account), &active); = Server::Get()->GetActiveAccounts().ValueFor(BString(account), &active);
if (active == true) if (active == true)
DisableAccount(settings, account); DisableAccount(settings, account);
@ -280,11 +280,3 @@ ProtocolManager::_MainWin()
{ {
return ((TheApp*)be_app)->GetMainWindow(); 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); BEntry accountEntry, BHandler* target);
MainWindow* _MainWin(); MainWindow* _MainWin();
Server* _Server();
AddOnMap fAddOnMap; AddOnMap fAddOnMap;
ProtocolMap fProtocolMap; ProtocolMap fProtocolMap;

View File

@ -48,6 +48,9 @@
#define B_TRANSLATION_CONTEXT "Server" #define B_TRANSLATION_CONTEXT "Server"
Server* Server::fInstance = NULL;
Server::Server() Server::Server()
: :
BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE) 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 void
Server::Quit() Server::Quit()
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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