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,
|
IM_SPECIAL_TO_PROTOCOL = 1000,
|
||||||
|
|
||||||
//! Special message forwarded from protocol
|
//! 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
|
#endif // _CAYA_PROTOCOL_MESSAGES_H
|
||||||
|
|
|
@ -146,12 +146,7 @@ ProtocolManager::_LoadAccounts(const char* image_path, CayaProtocolAddOn* addOn,
|
||||||
bool firstDone = false;
|
bool firstDone = false;
|
||||||
|
|
||||||
while (dir.GetNextEntry(&entry) == B_OK) {
|
while (dir.GetNextEntry(&entry) == B_OK) {
|
||||||
// if (firstDone == false) {
|
|
||||||
_LoadAccount(addOn, entry, target);
|
_LoadAccount(addOn, entry, target);
|
||||||
// firstDone = true;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// _LoadAccount(image_path, entry, protoIndex, target);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -466,6 +466,23 @@ Server::ImMessage(BMessage* msg)
|
||||||
|
|
||||||
break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -14,7 +14,10 @@
|
||||||
#include "Conversation.h"
|
#include "Conversation.h"
|
||||||
#include "ConversationAccountItem.h"
|
#include "ConversationAccountItem.h"
|
||||||
#include "ConversationItem.h"
|
#include "ConversationItem.h"
|
||||||
|
#include "MainWindow.h"
|
||||||
#include "ProtocolLooper.h"
|
#include "ProtocolLooper.h"
|
||||||
|
#include "Server.h"
|
||||||
|
#include "TheApp.h"
|
||||||
|
|
||||||
|
|
||||||
const uint32 kOpenSelectedChat = 'CVos';
|
const uint32 kOpenSelectedChat = 'CVos';
|
||||||
|
@ -182,11 +185,19 @@ ConversationListView::_ConversationPopUp()
|
||||||
BPopUpMenu*
|
BPopUpMenu*
|
||||||
ConversationListView::_BlankPopUp()
|
ConversationListView::_BlankPopUp()
|
||||||
{
|
{
|
||||||
BPopUpMenu* menu = new BPopUpMenu("blankPopUp");
|
bool enabled = false;
|
||||||
menu->AddItem(new BMenuItem("New chat" B_UTF8_ELLIPSIS,
|
|
||||||
new BMessage(CAYA_NEW_CHAT), 'M', B_COMMAND_KEY));
|
|
||||||
menu->SetTargetForItems(Window());
|
|
||||||
|
|
||||||
|
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;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,6 +139,8 @@ UserListView::_BlankPopUp()
|
||||||
|
|
||||||
BMenuItem* invite = new BMenuItem("Invite user…" B_UTF8_ELLIPSIS,
|
BMenuItem* invite = new BMenuItem("Invite user…" B_UTF8_ELLIPSIS,
|
||||||
new BMessage(CAYA_SEND_INVITE), 'I', B_COMMAND_KEY);
|
new BMessage(CAYA_SEND_INVITE), 'I', B_COMMAND_KEY);
|
||||||
|
if (fChat == NULL)
|
||||||
|
invite->SetEnabled(false);
|
||||||
|
|
||||||
menu->AddItem(invite);
|
menu->AddItem(invite);
|
||||||
menu->SetTargetForItems(Window());
|
menu->SetTargetForItems(Window());
|
||||||
|
|
|
@ -42,7 +42,8 @@ MainWindow::MainWindow()
|
||||||
BWindow(BRect(0, 0, 600, 400), "Caya", B_TITLED_WINDOW, 0),
|
BWindow(BRect(0, 0, 600, 400), "Caya", B_TITLED_WINDOW, 0),
|
||||||
fWorkspaceChanged(false),
|
fWorkspaceChanged(false),
|
||||||
fConversation(NULL),
|
fConversation(NULL),
|
||||||
fRosterWindow(NULL)
|
fRosterWindow(NULL),
|
||||||
|
fServer(NULL)
|
||||||
{
|
{
|
||||||
_InitInterface();
|
_InitInterface();
|
||||||
|
|
||||||
|
@ -200,6 +201,10 @@ MainWindow::MessageReceived(BMessage* message)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case CAYA_DISABLE_ACCOUNT:
|
||||||
|
_ToggleMenuItems();
|
||||||
|
break;
|
||||||
|
|
||||||
case IM_MESSAGE:
|
case IM_MESSAGE:
|
||||||
ImMessage(message);
|
ImMessage(message);
|
||||||
break;
|
break;
|
||||||
|
@ -258,6 +263,10 @@ MainWindow::ImMessage(BMessage* msg)
|
||||||
case IM_STATUS_SET:
|
case IM_STATUS_SET:
|
||||||
fRosterWindow->PostMessage(msg);
|
fRosterWindow->PostMessage(msg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case IM_PROTOCOL_READY:
|
||||||
|
_ToggleMenuItems();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +378,7 @@ MainWindow::_InitInterface()
|
||||||
fSendView->SetWordWrap(true);
|
fSendView->SetWordWrap(true);
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
||||||
.Add(_CreateMenuBar())
|
.Add((fMenuBar = _CreateMenuBar()))
|
||||||
.AddGroup(B_HORIZONTAL)
|
.AddGroup(B_HORIZONTAL)
|
||||||
.SetInsets(5, 5, 0, 10)
|
.SetInsets(5, 5, 0, 10)
|
||||||
.AddSplit(B_HORIZONTAL, 0)
|
.AddSplit(B_HORIZONTAL, 0)
|
||||||
|
@ -383,6 +392,7 @@ MainWindow::_InitInterface()
|
||||||
.End();
|
.End();
|
||||||
|
|
||||||
SetConversation(NULL);
|
SetConversation(NULL);
|
||||||
|
_ToggleMenuItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -404,17 +414,19 @@ MainWindow::_CreateMenuBar()
|
||||||
|
|
||||||
// Chat
|
// Chat
|
||||||
BMenu* chatMenu = new BMenu("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,
|
BMenuItem* invite = new BMenuItem("Invite user" B_UTF8_ELLIPSIS,
|
||||||
new BMessage(CAYA_SEND_INVITE), 'I', B_COMMAND_KEY);
|
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,
|
BMenuItem* newRoom = new BMenuItem("New room" B_UTF8_ELLIPSIS,
|
||||||
new BMessage(), 'N', B_COMMAND_KEY);
|
new BMessage(), 'N', B_COMMAND_KEY);
|
||||||
newRoom->SetEnabled(false);
|
|
||||||
|
|
||||||
chatMenu->AddItem(new BMenuItem("Join room" B_UTF8_ELLIPSIS,
|
chatMenu->AddItem(joinRoom);
|
||||||
new BMessage(CAYA_JOIN_CHAT), 'J', B_COMMAND_KEY));
|
|
||||||
chatMenu->AddSeparatorItem();
|
chatMenu->AddSeparatorItem();
|
||||||
chatMenu->AddItem(new BMenuItem("New chat" B_UTF8_ELLIPSIS,
|
chatMenu->AddItem(newChat);
|
||||||
new BMessage(CAYA_NEW_CHAT), 'M', B_COMMAND_KEY));
|
|
||||||
chatMenu->AddItem(newRoom);
|
chatMenu->AddItem(newRoom);
|
||||||
chatMenu->AddSeparatorItem();
|
chatMenu->AddSeparatorItem();
|
||||||
chatMenu->AddItem(invite);
|
chatMenu->AddItem(invite);
|
||||||
|
@ -431,10 +443,28 @@ MainWindow::_CreateMenuBar()
|
||||||
menuBar->AddItem(programMenu);
|
menuBar->AddItem(programMenu);
|
||||||
menuBar->AddItem(chatMenu);
|
menuBar->AddItem(chatMenu);
|
||||||
menuBar->AddItem(windowMenu);
|
menuBar->AddItem(windowMenu);
|
||||||
|
|
||||||
return menuBar;
|
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*
|
ConversationItem*
|
||||||
MainWindow::_EnsureConversationItem(BMessage* msg)
|
MainWindow::_EnsureConversationItem(BMessage* msg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "Observer.h"
|
#include "Observer.h"
|
||||||
|
|
||||||
|
//class BMenubar;
|
||||||
class BSplitView;
|
class BSplitView;
|
||||||
class BTextView;
|
class BTextView;
|
||||||
|
|
||||||
|
@ -49,6 +50,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void _InitInterface();
|
void _InitInterface();
|
||||||
BMenuBar* _CreateMenuBar();
|
BMenuBar* _CreateMenuBar();
|
||||||
|
void _ToggleMenuItems();
|
||||||
|
|
||||||
ConversationItem*
|
ConversationItem*
|
||||||
_EnsureConversationItem(BMessage* msg);
|
_EnsureConversationItem(BMessage* msg);
|
||||||
|
@ -56,6 +58,7 @@ private:
|
||||||
Server* fServer;
|
Server* fServer;
|
||||||
RosterWindow* fRosterWindow;
|
RosterWindow* fRosterWindow;
|
||||||
bool fWorkspaceChanged;
|
bool fWorkspaceChanged;
|
||||||
|
BMenuBar* fMenuBar;
|
||||||
|
|
||||||
// Left panel, chat list
|
// Left panel, chat list
|
||||||
ConversationListView* fListView;
|
ConversationListView* fListView;
|
||||||
|
|
|
@ -1138,12 +1138,6 @@ JabberHandler::onConnect()
|
||||||
msg.AddInt32("status", CAYA_ONLINE);
|
msg.AddInt32("status", CAYA_ONLINE);
|
||||||
_SendMessage(&msg);
|
_SendMessage(&msg);
|
||||||
|
|
||||||
// Notify our online status
|
|
||||||
BString content(fUsername);
|
|
||||||
content << " has logged in!";
|
|
||||||
_Notify(B_INFORMATION_NOTIFICATION, "Connected",
|
|
||||||
content.String());
|
|
||||||
|
|
||||||
fVCardManager->fetchVCard(fJid, this);
|
fVCardManager->fetchVCard(fJid, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1235,6 +1229,13 @@ JabberHandler::handleRoster(const gloox::Roster& roster)
|
||||||
_SendMessage(&msg);
|
_SendMessage(&msg);
|
||||||
fVCardManager->fetchVCard(gloox::JID(jid), this);
|
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