diff --git a/application/CayaProtocolMessages.h b/application/CayaProtocolMessages.h index 26f5871..9cc172b 100644 --- a/application/CayaProtocolMessages.h +++ b/application/CayaProtocolMessages.h @@ -396,7 +396,14 @@ enum im_what_code { // Requires: String "_label", Message "_msg", String "class" = "BMenuItem" // Bool "x_to_protocol", int32 "x_perms" // Allowed: int64 "instance" - IM_REGISTER_CHATLIST_ITEM = 1102 + IM_REGISTER_CHATLIST_ITEM = 1102, + + //! Register a "Protocol" menu item →Caya + // Just an archived BMenuItem with extra slots; it adds a menu item to + // the menubar's "Protocol" menu. + // Requires: String "_label", Message "_msg", String "class" = "BMenuItem" + // Bool "x_to_protocol", int64 "instance" + IM_REGISTER_MENUBAR_ITEM = 1103 }; diff --git a/application/ProtocolLooper.cpp b/application/ProtocolLooper.cpp index 7436a7d..34450e6 100644 --- a/application/ProtocolLooper.cpp +++ b/application/ProtocolLooper.cpp @@ -192,6 +192,20 @@ ProtocolLooper::AddChatPopUpItem(BMessage* archived) } +BObjectList +ProtocolLooper::MenuBarItems() const +{ + return fMenuItems; +} + + +void +ProtocolLooper::AddMenuBarItem(BMessage* archived) +{ + fMenuItems.AddItem(archived); +} + + BString ProtocolLooper::GetOwnId() { diff --git a/application/ProtocolLooper.h b/application/ProtocolLooper.h index e452832..bdf2f1b 100644 --- a/application/ProtocolLooper.h +++ b/application/ProtocolLooper.h @@ -61,6 +61,10 @@ public: ChatPopUpItems() const; void AddChatPopUpItem(BMessage* archived); + BObjectList + MenuBarItems() const; + void AddMenuBarItem(BMessage* archived); + BString GetOwnId(); void SetOwnId(BString user_id); @@ -82,6 +86,7 @@ private: CommandMap fCommands; BObjectList fUserItems; BObjectList fChatItems; + BObjectList fMenuItems; ConversationAccountItem* fListItem; diff --git a/application/Server.cpp b/application/Server.cpp index 255ea12..cc4aa7c 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -550,6 +550,13 @@ Server::ImMessage(BMessage* msg) looper->AddChatPopUpItem(new BMessage(*msg)); break; } + case IM_REGISTER_MENUBAR_ITEM: + { + ProtocolLooper* looper = _LooperFromMessage(msg); + if (looper != NULL) + looper->AddMenuBarItem(new BMessage(*msg)); + break; + } case IM_PROTOCOL_READY: { // Ready notification diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index 3fd8646..f2a5021 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -348,6 +348,36 @@ MainWindow::SetConversation(Conversation* chat) fRightView->SetItemWeight(0, weightChat, true); fRightView->SetItemWeight(1, weightSend, true); } + + // Remove "Protocol" menu + BMenuItem* chatMenuItem = fMenuBar->FindItem("Protocol"); + BMenu* chatMenu; + if (chatMenuItem != NULL && (chatMenu = chatMenuItem->Submenu()) != NULL) + fMenuBar->RemoveItem(chatMenu); + + // Add and populate "Protocol" menu, if appropriate + if (fConversation != NULL) { + ProtocolLooper* looper = fConversation->GetProtocolLooper(); + BObjectList menuItems = looper->MenuBarItems(); + for (int i = 0; i < menuItems.CountItems(); i++) { + BMessage* itemMsg = menuItems.ItemAt(i); + BMessage* msg = new BMessage(*itemMsg); + BMessage toSend; + msg->FindMessage("_msg", &toSend); + toSend.AddString("chat_id", fConversation->GetId()); + toSend.AddInt64("instance", looper->GetInstance()); + msg->ReplaceMessage("_msg", &toSend); + + BMenuItem* item = new BMenuItem(msg); + if (item == NULL) + continue; + if (msg->GetBool("x_to_protocol", true) == true) + item->SetTarget(looper); + else + item->SetTarget(this); + chatMenu->AddItem(item); + } + } }