diff --git a/application/CayaProtocolMessages.h b/application/CayaProtocolMessages.h index 594d653..48a1ebb 100644 --- a/application/CayaProtocolMessages.h +++ b/application/CayaProtocolMessages.h @@ -333,7 +333,10 @@ enum im_what_code { IM_SPECIAL_TO_PROTOCOL = 1000, //! Special message forwarded from protocol - IM_SPECIAL_FROM_PROTOCOL = 1001 + IM_SPECIAL_FROM_PROTOCOL = 1001, + + //! Protocol is ready to receive messages + IM_PROTOCOL_READY = 1002 }; #endif // _CAYA_PROTOCOL_MESSAGES_H diff --git a/application/ProtocolManager.cpp b/application/ProtocolManager.cpp index 88abffe..749cb7b 100644 --- a/application/ProtocolManager.cpp +++ b/application/ProtocolManager.cpp @@ -146,12 +146,7 @@ ProtocolManager::_LoadAccounts(const char* image_path, CayaProtocolAddOn* addOn, bool firstDone = false; while (dir.GetNextEntry(&entry) == B_OK) { -// if (firstDone == false) { _LoadAccount(addOn, entry, target); -// firstDone = true; -// } -// else -// _LoadAccount(image_path, entry, protoIndex, target); } } diff --git a/application/Server.cpp b/application/Server.cpp index 3792fdd..7b7c6d3 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -466,6 +466,23 @@ Server::ImMessage(BMessage* msg) break; } + case IM_PROTOCOL_READY: + { + ProtocolLooper* looper = _LooperFromMessage(msg); + if (looper == NULL) + break; + + BString content("%user% has connected!"); + content.ReplaceAll("%user%", looper->Protocol()->GetName()); + + BNotification notification(B_INFORMATION_NOTIFICATION); + notification.SetGroup(BString("Caya")); + notification.SetTitle("Connected"); + notification.SetContent(content); + notification.SetIcon(looper->Protocol()->Icon()); + notification.Send(); + break; + } default: break; diff --git a/application/views/ConversationListView.cpp b/application/views/ConversationListView.cpp index 2fdd5af..35f40cd 100644 --- a/application/views/ConversationListView.cpp +++ b/application/views/ConversationListView.cpp @@ -14,7 +14,10 @@ #include "Conversation.h" #include "ConversationAccountItem.h" #include "ConversationItem.h" +#include "MainWindow.h" #include "ProtocolLooper.h" +#include "Server.h" +#include "TheApp.h" const uint32 kOpenSelectedChat = 'CVos'; @@ -182,11 +185,19 @@ ConversationListView::_ConversationPopUp() BPopUpMenu* ConversationListView::_BlankPopUp() { + bool enabled = false; + + Server* server = ((TheApp*)be_app)->GetMainWindow()->GetServer(); + if (server != NULL && server->GetAccounts().CountItems() > 0) + enabled = true; + BPopUpMenu* menu = new BPopUpMenu("blankPopUp"); - menu->AddItem(new BMenuItem("New chat" B_UTF8_ELLIPSIS, - new BMessage(CAYA_NEW_CHAT), 'M', B_COMMAND_KEY)); + BMenuItem* newChat = new BMenuItem("New chat" B_UTF8_ELLIPSIS, + new BMessage(CAYA_NEW_CHAT), 'M', B_COMMAND_KEY); + newChat->SetEnabled(enabled); + + menu->AddItem(newChat); menu->SetTargetForItems(Window()); - return menu; } diff --git a/application/views/UserListView.cpp b/application/views/UserListView.cpp index 8d44115..3da7e69 100644 --- a/application/views/UserListView.cpp +++ b/application/views/UserListView.cpp @@ -139,6 +139,8 @@ UserListView::_BlankPopUp() BMenuItem* invite = new BMenuItem("Invite user…" B_UTF8_ELLIPSIS, new BMessage(CAYA_SEND_INVITE), 'I', B_COMMAND_KEY); + if (fChat == NULL) + invite->SetEnabled(false); menu->AddItem(invite); menu->SetTargetForItems(Window()); diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index 7c744c0..ad289ce 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -42,7 +42,8 @@ MainWindow::MainWindow() BWindow(BRect(0, 0, 600, 400), "Caya", B_TITLED_WINDOW, 0), fWorkspaceChanged(false), fConversation(NULL), - fRosterWindow(NULL) + fRosterWindow(NULL), + fServer(NULL) { _InitInterface(); @@ -200,6 +201,10 @@ MainWindow::MessageReceived(BMessage* message) break; } + case CAYA_DISABLE_ACCOUNT: + _ToggleMenuItems(); + break; + case IM_MESSAGE: ImMessage(message); break; @@ -258,6 +263,10 @@ MainWindow::ImMessage(BMessage* msg) case IM_STATUS_SET: fRosterWindow->PostMessage(msg); break; + + case IM_PROTOCOL_READY: + _ToggleMenuItems(); + break; } } @@ -369,7 +378,7 @@ MainWindow::_InitInterface() fSendView->SetWordWrap(true); BLayoutBuilder::Group<>(this, B_VERTICAL) - .Add(_CreateMenuBar()) + .Add((fMenuBar = _CreateMenuBar())) .AddGroup(B_HORIZONTAL) .SetInsets(5, 5, 0, 10) .AddSplit(B_HORIZONTAL, 0) @@ -383,6 +392,7 @@ MainWindow::_InitInterface() .End(); SetConversation(NULL); + _ToggleMenuItems(); } @@ -404,17 +414,19 @@ MainWindow::_CreateMenuBar() // Chat BMenu* chatMenu = new BMenu("Chat"); + BMenuItem* joinRoom = new BMenuItem("Join room" B_UTF8_ELLIPSIS, + new BMessage(CAYA_JOIN_CHAT), 'J', B_COMMAND_KEY); BMenuItem* invite = new BMenuItem("Invite user" B_UTF8_ELLIPSIS, new BMessage(CAYA_SEND_INVITE), 'I', B_COMMAND_KEY); + + BMenuItem* newChat = new BMenuItem("New chat" B_UTF8_ELLIPSIS, + new BMessage(CAYA_NEW_CHAT), 'M', B_COMMAND_KEY); BMenuItem* newRoom = new BMenuItem("New room" B_UTF8_ELLIPSIS, new BMessage(), 'N', B_COMMAND_KEY); - newRoom->SetEnabled(false); - chatMenu->AddItem(new BMenuItem("Join room" B_UTF8_ELLIPSIS, - new BMessage(CAYA_JOIN_CHAT), 'J', B_COMMAND_KEY)); + chatMenu->AddItem(joinRoom); chatMenu->AddSeparatorItem(); - chatMenu->AddItem(new BMenuItem("New chat" B_UTF8_ELLIPSIS, - new BMessage(CAYA_NEW_CHAT), 'M', B_COMMAND_KEY)); + chatMenu->AddItem(newChat); chatMenu->AddItem(newRoom); chatMenu->AddSeparatorItem(); chatMenu->AddItem(invite); @@ -431,10 +443,28 @@ MainWindow::_CreateMenuBar() menuBar->AddItem(programMenu); menuBar->AddItem(chatMenu); menuBar->AddItem(windowMenu); + return menuBar; } +void +MainWindow::_ToggleMenuItems() +{ + BMenuItem* chatMenuItem = fMenuBar->FindItem("Chat"); + BMenu* chatMenu = chatMenuItem->Submenu(); + if (chatMenuItem == NULL || chatMenu == NULL) + return; + + bool enabled = false; + if (fServer != NULL && fServer->GetAccounts().CountItems() > 0) + enabled = true; + + for (int i = 0; i < chatMenu->CountItems(); i++) + chatMenu->ItemAt(i)->SetEnabled(enabled); +} + + ConversationItem* MainWindow::_EnsureConversationItem(BMessage* msg) { diff --git a/application/windows/MainWindow.h b/application/windows/MainWindow.h index 3f98278..5d432ff 100644 --- a/application/windows/MainWindow.h +++ b/application/windows/MainWindow.h @@ -11,6 +11,7 @@ #include "Observer.h" +//class BMenubar; class BSplitView; class BTextView; @@ -49,6 +50,7 @@ public: private: void _InitInterface(); BMenuBar* _CreateMenuBar(); + void _ToggleMenuItems(); ConversationItem* _EnsureConversationItem(BMessage* msg); @@ -56,6 +58,7 @@ private: Server* fServer; RosterWindow* fRosterWindow; bool fWorkspaceChanged; + BMenuBar* fMenuBar; // Left panel, chat list ConversationListView* fListView; diff --git a/protocols/xmpp/JabberHandler.cpp b/protocols/xmpp/JabberHandler.cpp index a946999..6e56b3f 100644 --- a/protocols/xmpp/JabberHandler.cpp +++ b/protocols/xmpp/JabberHandler.cpp @@ -1138,12 +1138,6 @@ JabberHandler::onConnect() msg.AddInt32("status", CAYA_ONLINE); _SendMessage(&msg); - // Notify our online status - BString content(fUsername); - content << " has logged in!"; - _Notify(B_INFORMATION_NOTIFICATION, "Connected", - content.String()); - fVCardManager->fetchVCard(fJid, this); } @@ -1235,6 +1229,13 @@ JabberHandler::handleRoster(const gloox::Roster& roster) _SendMessage(&msg); fVCardManager->fetchVCard(gloox::JID(jid), this); } + + // This is a safe spot to say "READY", since this is called immediately + // after logging in, whether the user has friends in the roster or not― + // especially since loading all the users from the roster can take a while. + BMessage readyMsg(IM_MESSAGE); + readyMsg.AddInt32("im_what", IM_PROTOCOL_READY); + _SendMessage(&readyMsg); }