Disable some menu items when no account is active
When no accounts are active, all items in the Menubar->Chat menu are disabled, and some other menu items related to starting/managing chats are disabled in other views. One new message was added to the API― IM_PROTOCOL_READY, which tells Caya that a given protocol has logged in and is ready to receive messages (rather than just sending). This is currently done in XMPP after the roster is loaded, which be a process that stalls the protocol for a few seconds. IM_PROTOCOL_READY should only be sent after those initial, potentially time-heavy operations.
This commit is contained in:
parent
fe2f2ecad2
commit
9cd4ce18e1
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
BPopUpMenu* menu = new BPopUpMenu("blankPopUp");
|
||||
menu->AddItem(new BMenuItem("New chat" B_UTF8_ELLIPSIS,
|
||||
new BMessage(CAYA_NEW_CHAT), 'M', B_COMMAND_KEY));
|
||||
menu->SetTargetForItems(Window());
|
||||
bool enabled = false;
|
||||
|
||||
Server* server = ((TheApp*)be_app)->GetMainWindow()->GetServer();
|
||||
if (server != NULL && server->GetAccounts().CountItems() > 0)
|
||||
enabled = true;
|
||||
|
||||
BPopUpMenu* menu = new BPopUpMenu("blankPopUp");
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Ŝarĝante…
Reference in New Issue