diff --git a/application/ChatCommand.cpp b/application/ChatCommand.cpp index 7588c0f..7f5d223 100644 --- a/application/ChatCommand.cpp +++ b/application/ChatCommand.cpp @@ -10,7 +10,9 @@ #include "Conversation.h" #include "MainWindow.h" +#include "ProtocolLooper.h" #include "TheApp.h" +#include "User.h" #undef B_TRANSLATION_CONTEXT diff --git a/application/ChatCommand.h b/application/ChatCommand.h index 644980a..0af8834 100644 --- a/application/ChatCommand.h +++ b/application/ChatCommand.h @@ -12,10 +12,11 @@ #include #include +#include "Maps.h" + class Conversation; class User; -typedef KeyMap UserMap; enum cmd_arg_type @@ -61,7 +62,4 @@ private: List fArgTypes; }; - -typedef KeyMap CommandMap; - #endif // CHAT_COMMAND_H diff --git a/application/Conversation.cpp b/application/Conversation.cpp index 01f26be..9f854bf 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -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(); -} diff --git a/application/Conversation.h b/application/Conversation.h index f892669..6e6e116 100644 --- a/application/Conversation.h +++ b/application/Conversation.h @@ -10,22 +10,18 @@ #include #include -#include - +#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 UserMap; -typedef KeyMap RoleMap; +class User; class Conversation : public Notifier, public Observer { @@ -79,6 +75,8 @@ public: BPath CachePath() { return fCachePath; } private: + typedef KeyMap RoleMap; + void _WarnUser(BString message); void _LogChatMessage(BMessage* msg); @@ -96,8 +94,6 @@ private: void _SortConversationList(); - Server* _GetServer(); - BMessenger fMessenger; ProtocolLooper* fLooper; ConversationView* fChatView; diff --git a/application/Maps.h b/application/Maps.h new file mode 100644 index 0000000..a29533a --- /dev/null +++ b/application/Maps.h @@ -0,0 +1,26 @@ +/* + * Copyright 2022, Jaidyn Levesque + * All rights reserved. Distributed under the terms of the MIT license. + */ +#ifndef _MAPS_H +#define _MAPS_H + +#include + +#include "libsupport/KeyMap.h" + +class ChatCommand; +class Command; +class Contact; +class Conversation; +class User; + + +// Defining some commonly-used KeyMaps +typedef KeyMap AccountInstances; +typedef KeyMap CommandMap; +typedef KeyMap ChatMap; +typedef KeyMap RosterMap; +typedef KeyMap UserMap; + +#endif // _MAPS_H diff --git a/application/ProtocolLooper.cpp b/application/ProtocolLooper.cpp index b1495ef..0c939d0 100644 --- a/application/ProtocolLooper.cpp +++ b/application/ProtocolLooper.cpp @@ -13,11 +13,13 @@ #include "ProtocolLooper.h" #include +#include #include #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() { diff --git a/application/ProtocolLooper.h b/application/ProtocolLooper.h index 46cf257..9851a65 100644 --- a/application/ProtocolLooper.h +++ b/application/ProtocolLooper.h @@ -11,10 +11,9 @@ #include #include -#include - #include "ChatProtocol.h" #include "ChatCommand.h" +#include "Maps.h" class Contact; class Conversation; @@ -23,11 +22,6 @@ class ConversationView; class User; -typedef KeyMap ChatMap; -typedef KeyMap RosterMap; -typedef KeyMap UserMap; - - class ProtocolLooper : public BLooper { public: ProtocolLooper(ChatProtocol* protocol, int64 instance); diff --git a/application/ProtocolManager.cpp b/application/ProtocolManager.cpp index ad174f8..d6d60f1 100644 --- a/application/ProtocolManager.cpp +++ b/application/ProtocolManager.cpp @@ -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; -} diff --git a/application/ProtocolManager.h b/application/ProtocolManager.h index 9c19ead..84d1b81 100644 --- a/application/ProtocolManager.h +++ b/application/ProtocolManager.h @@ -64,7 +64,6 @@ private: BEntry accountEntry, BHandler* target); MainWindow* _MainWin(); - Server* _Server(); AddOnMap fAddOnMap; ProtocolMap fProtocolMap; diff --git a/application/Server.cpp b/application/Server.cpp index 09dfd23..a4031bc 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -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() { diff --git a/application/Server.h b/application/Server.h index 73958fb..e0adab5 100644 --- a/application/Server.h +++ b/application/Server.h @@ -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 ProtocolLoopers; -typedef KeyMap AccountInstances; -typedef KeyMap 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 UserPopUpItems(); private: + typedef KeyMap BoolMap; + typedef KeyMap 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; diff --git a/application/StatusManager.cpp b/application/StatusManager.cpp index 64b6985..0ac4f98 100644 --- a/application/StatusManager.cpp +++ b/application/StatusManager.cpp @@ -11,10 +11,8 @@ #include #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(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(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; diff --git a/application/TheApp.cpp b/application/TheApp.cpp index 060efed..7707741 100644 --- a/application/TheApp.cpp +++ b/application/TheApp.cpp @@ -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); diff --git a/application/User.h b/application/User.h index b28d39a..aa231ec 100644 --- a/application/User.h +++ b/application/User.h @@ -14,8 +14,7 @@ #include #include -#include - +#include "Maps.h" #include "Notifier.h" #include "UserStatus.h" @@ -26,9 +25,6 @@ class ProtocolLooper; class UserPopUp; -typedef KeyMap ChatMap; - - class User : public Notifier { public: User(BString id, BMessenger msgn); diff --git a/application/Utils.h b/application/Utils.h index 6f0fc81..0975fd4 100644 --- a/application/Utils.h +++ b/application/Utils.h @@ -14,7 +14,7 @@ #include #include "AppConstants.h" -#include "Server.h" +#include "UserStatus.h" class BMenu; diff --git a/application/preferences/AppPreferences.cpp b/application/preferences/AppPreferences.cpp index 41f59e4..dcf354d 100644 --- a/application/preferences/AppPreferences.cpp +++ b/application/preferences/AppPreferences.cpp @@ -6,6 +6,8 @@ #include "AppPreferences.h" +#include + #include "Utils.h" diff --git a/application/views/AccountsMenu.cpp b/application/views/AccountsMenu.cpp index 747e514..d79b553 100644 --- a/application/views/AccountsMenu.cpp +++ b/application/views/AccountsMenu.cpp @@ -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); diff --git a/application/views/AccountsMenu.h b/application/views/AccountsMenu.h index f7422a9..d8b3e0a 100644 --- a/application/views/AccountsMenu.h +++ b/application/views/AccountsMenu.h @@ -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 diff --git a/application/views/ConversationListView.cpp b/application/views/ConversationListView.cpp index ecc2783..914bb9e 100644 --- a/application/views/ConversationListView.cpp +++ b/application/views/ConversationListView.cpp @@ -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 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; diff --git a/application/views/ConversationView.cpp b/application/views/ConversationView.cpp index a610a12..ba4571f 100644 --- a/application/views/ConversationView.cpp +++ b/application/views/ConversationView.cpp @@ -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" diff --git a/application/views/ConversationView.h b/application/views/ConversationView.h index bc88528..ca10f47 100644 --- a/application/views/ConversationView.h +++ b/application/views/ConversationView.h @@ -26,8 +26,6 @@ class UserListView; const uint32 kClearText = 'CVct'; -typedef KeyMap UInt16IntMap; - class ConversationView : public BGroupView, public Observer, public Notifier { public: @@ -54,6 +52,8 @@ public: float vertChat, float vertSend); private: + typedef KeyMap UInt16IntMap; + void _InitInterface(); bool _AppendOrEnqueueMessage(BMessage* msg); diff --git a/application/views/RosterView.cpp b/application/views/RosterView.cpp index aa1ddbe..5a54c00 100644 --- a/application/views/RosterView.cpp +++ b/application/views/RosterView.cpp @@ -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; diff --git a/application/views/RosterView.h b/application/views/RosterView.h index dd045ca..ab8be7c 100644 --- a/application/views/RosterView.h +++ b/application/views/RosterView.h @@ -14,18 +14,17 @@ #include -#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; diff --git a/application/views/SendTextView.cpp b/application/views/SendTextView.cpp index f37f1c7..63db1e9 100644 --- a/application/views/SendTextView.cpp +++ b/application/views/SendTextView.cpp @@ -9,9 +9,7 @@ #include #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)); diff --git a/application/views/StatusView.cpp b/application/views/StatusView.cpp index d94ad35..f2adee1 100644 --- a/application/views/StatusView.cpp +++ b/application/views/StatusView.cpp @@ -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(); diff --git a/application/views/StatusView.h b/application/views/StatusView.h index 5399494..7526dfd 100644 --- a/application/views/StatusView.h +++ b/application/views/StatusView.h @@ -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 diff --git a/application/views/UserListView.cpp b/application/views/UserListView.cpp index 2733b1c..9658e76 100644 --- a/application/views/UserListView.cpp +++ b/application/views/UserListView.cpp @@ -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 items = server->UserPopUpItems(); + BObjectList items = Server::Get()->UserPopUpItems(); BObjectList protoItems = fChat->GetProtocolLooper()->Protocol()->UserPopUpItems(); items.AddList(&protoItems); diff --git a/application/windows/AccountsWindow.cpp b/application/windows/AccountsWindow.cpp index 3438ff8..69b1dcf 100644 --- a/application/windows/AccountsWindow.cpp +++ b/application/windows/AccountsWindow.cpp @@ -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) diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index 9633d29..02e1149 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -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"); diff --git a/application/windows/MainWindow.h b/application/windows/MainWindow.h index c266b8f..8a44e87 100644 --- a/application/windows/MainWindow.h +++ b/application/windows/MainWindow.h @@ -9,7 +9,7 @@ #include -#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; diff --git a/application/windows/RoomListWindow.cpp b/application/windows/RoomListWindow.cpp index 3fe8286..df3fb7f 100644 --- a/application/windows/RoomListWindow.cpp +++ b/application/windows/RoomListWindow.cpp @@ -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"), diff --git a/application/windows/RoomListWindow.h b/application/windows/RoomListWindow.h index 716b048..74f9777 100644 --- a/application/windows/RoomListWindow.h +++ b/application/windows/RoomListWindow.h @@ -13,7 +13,6 @@ class BButton; class BColumnListView; class RoomListRow; -class Server; typedef KeyMap*> RowMap; @@ -21,10 +20,10 @@ typedef KeyMap*> 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; }; diff --git a/application/windows/RosterEditWindow.cpp b/application/windows/RosterEditWindow.cpp index 5143b17..63651d9 100644 --- a/application/windows/RosterEditWindow.cpp +++ b/application/windows/RosterEditWindow.cpp @@ -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)) diff --git a/application/windows/RosterEditWindow.h b/application/windows/RosterEditWindow.h index fbe7493..1e09db9 100644 --- a/application/windows/RosterEditWindow.h +++ b/application/windows/RosterEditWindow.h @@ -14,8 +14,6 @@ #include -#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; diff --git a/application/windows/RosterWindow.cpp b/application/windows/RosterWindow.cpp index 31441df..6eaa273 100644 --- a/application/windows/RosterWindow.cpp +++ b/application/windows/RosterWindow.cpp @@ -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)) diff --git a/application/windows/RosterWindow.h b/application/windows/RosterWindow.h index ae4856c..d0fe131 100644 --- a/application/windows/RosterWindow.h +++ b/application/windows/RosterWindow.h @@ -14,8 +14,6 @@ #include -#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; diff --git a/application/windows/TemplateWindow.cpp b/application/windows/TemplateWindow.cpp index 71179c8..eab4ca5 100644 --- a/application/windows/TemplateWindow.cpp +++ b/application/windows/TemplateWindow.cpp @@ -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; diff --git a/application/windows/TemplateWindow.h b/application/windows/TemplateWindow.h index 390e823..cdcefdd 100644 --- a/application/windows/TemplateWindow.h +++ b/application/windows/TemplateWindow.h @@ -10,7 +10,6 @@ #include #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;