/* * Initialize plugin menus. * This function is called after ts3plugin_init and ts3plugin_registerPluginID. A pluginID is required for plugin menus to work. * Both ts3plugin_registerPluginID and ts3plugin_freeMemory must be implemented to use menus. * If plugin menus are not used by a plugin, do not implement this function or return NULL. */ void ts3plugin_initMenus(struct PluginMenuItem*** menuItems, char** menuIcon) { /* * Create the menus * There are three types of menu items: * - PLUGIN_MENU_TYPE_CLIENT: Client context menu * - PLUGIN_MENU_TYPE_CHANNEL: Channel context menu * - PLUGIN_MENU_TYPE_GLOBAL: "Plugins" menu in menu bar of main window * * Menu IDs are used to identify the menu item when ts3plugin_onMenuItemEvent is called * * The menu text is required, max length is 128 characters * * The icon is optional, max length is 128 characters. When not using icons, just pass an empty string. * Icons are loaded from a subdirectory in the TeamSpeak client plugins folder. The subdirectory must be named like the * plugin filename, without dll/so/dylib suffix * e.g. for "test_plugin.dll", icon "1.png" is loaded from <TeamSpeak 3 Client install dir>\plugins\test_plugin\1.png */ BEGIN_CREATE_MENUS(7); /* IMPORTANT: Number of menu items must be correct! */ CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_CLIENT, MENU_ID_CLIENT_1, "Client item 1", "1.png"); CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_CLIENT, MENU_ID_CLIENT_2, "Client item 2", "2.png"); CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_CHANNEL, MENU_ID_CHANNEL_1, "Channel item 1", "1.png"); CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_CHANNEL, MENU_ID_CHANNEL_2, "Channel item 2", "2.png"); CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_CHANNEL, MENU_ID_CHANNEL_3, "Channel item 3", "3.png"); CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_GLOBAL, MENU_ID_GLOBAL_1, "Global item 1", "1.png"); CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_GLOBAL, MENU_ID_GLOBAL_2, "Global item 2", "2.png"); END_CREATE_MENUS; /* Includes an assert checking if the number of menu items matched */ /* * Specify an optional icon for the plugin. This icon is used for the plugins submenu within context and main menus * If unused, set menuIcon to NULL */ *menuIcon = (char*)malloc(PLUGIN_MENU_BUFSZ * sizeof(char)); _strcpy(*menuIcon, PLUGIN_MENU_BUFSZ, "t.png"); /* * Menus can be enabled or disabled with: ts3Functions.setPluginMenuEnabled(pluginID, menuID, 0|1); * Test it with plugin command: /test enablemenu <menuID> <0|1> * Menus are enabled by default. Please note that shown menus will not automatically enable or disable when calling this function to * ensure Qt menus are not modified by any thread other the UI thread. The enabled or disable state will change the next time a * menu is displayed. */ /* For example, this would disable MENU_ID_GLOBAL_2: */ /* ts3Functions.setPluginMenuEnabled(pluginID, MENU_ID_GLOBAL_2, 0); */ /* All memory allocated in this function will be automatically released by the TeamSpeak client later by calling ts3plugin_freeMemory */ }
void TSContextMenu::onInitMenus(PluginMenuItem*** menuItems, char **menuIcon) { m_isInit=true; /* * Create the menus * There are three types of menu items: * - PLUGIN_MENU_TYPE_CLIENT: Client context menu * - PLUGIN_MENU_TYPE_CHANNEL: Channel context menu * - PLUGIN_MENU_TYPE_GLOBAL: "Plugins" menu in menu bar of main window * * Menu IDs are used to identify the menu item when ts3plugin_onMenuItemEvent is called * * The menu text is required, max length is 128 characters * * The icon is optional, max length is 128 characters. When not using icons, just pass an empty string. * Icons are loaded from a subdirectory in the TeamSpeak client plugins folder. The subdirectory must be named like the * plugin filename, without dll/so/dylib suffix * e.g. for "test_plugin.dll", icon "1.png" is loaded from <TeamSpeak 3 Client install dir>\plugins\test_plugin\1.png */ // TSLogging::Print(QString("(TSContextMenu::onInitMenu): %1").arg(m_Items.size()),LogLevel_DEBUG); int amount = m_Items.size(); BEGIN_CREATE_MENUS(amount); /* IMPORTANT: Number of menu items must be correct! */ for (int i = 0; i < amount; ++i) CREATE_MENU_ITEM(m_Items.takeFirst()); END_CREATE_MENUS; /* Includes an assert checking if the number of menu items matched */ /* * Specify an optional icon for the plugin. This icon is used for the plugins submenu within context and main menus * If unused, set menuIcon to NULL */ if (!m_MainIcon.isEmpty()) { *menuIcon = (char*)malloc(PLUGIN_MENU_BUFSZ * sizeof(char)); qstrncpy(*menuIcon, m_MainIcon.toLatin1().constData(), PLUGIN_MENU_BUFSZ); } emit MenusInitialized(); }