]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Use individual arguments for the components of opening a menu and opening a specific...
authorVMware, Inc <>
Mon, 26 Sep 2011 18:25:58 +0000 (11:25 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Mon, 26 Sep 2011 18:25:58 +0000 (11:25 -0700)
Rather than having the library do all the serialization to a DynBuf (containing an ASCII
representation sent over the backdoor) return the individual items in their original form
and defer the serialization to the plugin which is more acquainted with the transport
requirements.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/services/plugins/unity/ghIntegration/ghIntegration.cpp
open-vm-tools/services/plugins/unity/ghIntegration/ghIntegration.h
open-vm-tools/services/plugins/unity/ghIntegration/ghIntegrationInt.h
open-vm-tools/services/plugins/unity/ghIntegration/platform.cc
open-vm-tools/services/plugins/unity/ghiTclo.cpp

index 685ed1ee3930c31b5ccdeac6dfbb5aaa930c6ec7..1cc438d1ab8f8f34604aaec009c8cc066e6ef126 100644 (file)
@@ -204,7 +204,6 @@ GHI_GetBinaryHandlers(const char *pathUtf8)   // IN: full path to the executable
 {
    return GHIPlatformGetBinaryHandlers(ghiPlatformData, pathUtf8);
 }
-#endif // !OPEN_VM_TOOLS && !__FreeBSD__ && !sun && !__APPLE__
 
 
 /*
@@ -227,12 +226,12 @@ GHI_GetBinaryHandlers(const char *pathUtf8)   // IN: full path to the executable
  *----------------------------------------------------------------------------
  */
 
-Bool
-GHI_OpenStartMenuTree(const char *rootUtf8,     // IN: root of the tree
-                     uint32 flags,             // IN: flags from VMX
-                     DynBuf *buf)              // OUT: number of items
+Bool GHI_OpenStartMenuTree(const char *rootUtf8,        // IN:
+                           uint32 flags,                // IN:
+                           uint32 &handle,              // OUT: handle for menu
+                           uint32 &numItems)            // OUT: number of items in menu
 {
-   return GHIPlatformOpenStartMenuTree(ghiPlatformData, rootUtf8, flags, buf);
+   return GHIPlatformOpenStartMenuTree(ghiPlatformData, rootUtf8, flags, handle, numItems);
 }
 
 
@@ -256,11 +255,15 @@ GHI_OpenStartMenuTree(const char *rootUtf8,     // IN: root of the tree
  */
 
 Bool
-GHI_GetStartMenuItem(uint32 handle,       // IN: tree handle
-                     uint32 itemIndex,    // IN: the index of the item in the tree
-                     DynBuf *buf)         // OUT: item
+GHI_GetStartMenuItem(uint32 handle,            // IN: tree handle
+                     uint32 itemIndex,         // IN: the index of the item in the tree
+                     Bool &isSubmenu,          // OUT: True if this item is a submenu
+                     utf::string &menuPath,    // OUT: Path to the submenu (if this item is a submenu)
+                     utf::string &itemPathURI, // OUT: URI for the item (empty if this is a submenu)
+                     utf::string &itemName)    // OUT: The name/label for the item
 {
-   return GHIPlatformGetStartMenuItem(ghiPlatformData, handle, itemIndex, buf);
+   return GHIPlatformGetStartMenuItem(ghiPlatformData, handle, itemIndex,
+                                      isSubmenu, menuPath, itemPathURI, itemName);
 }
 
 
@@ -286,6 +289,7 @@ GHI_CloseStartMenuTree(uint32 handle)     // IN: handle to the tree to be closed
 {
    return GHIPlatformCloseStartMenuTree(ghiPlatformData, handle);
 }
+#endif // !OPEN_VM_TOOLS && !__FreeBSD__ && !sun && !__APPLE__
 
 
 /*
index bfb994152b4016aefd4467f91c12db854cf15c70..6f099309a26d873ec8cf00b8477cdbf7c7d85673 100644 (file)
@@ -28,7 +28,9 @@
 #if defined(__cplusplus)
 #if !defined(OPEN_VM_TOOLS) && !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__)
 #include "appUtilFileTypes.h"
+#include "stringxx/string.hh"
 #endif // !OPEN_VM_TOOLS && !__FREEBSD__ && !sun && !__APPLE__
+
 #include <vector>
 #include <string>
 #include <list>
@@ -55,10 +57,6 @@ Bool GHI_IsSupported(void);
 void GHI_Init(GMainLoop *mainLoop, const char **envp, GHIHostCallbacks hostCallbacks);
 void GHI_Cleanup(void);
 
-Bool GHI_OpenStartMenuTree(const char *rootUtf8, uint32 flags, DynBuf *buf);
-Bool GHI_GetStartMenuItem(uint32 handle, uint32 itemIndex, DynBuf *buf);
-Bool GHI_CloseStartMenuTree(uint32 handle);
-
 Bool GHI_ShellOpen(const char *fileURIUtf8);
 Bool GHI_ShellAction(const char *actionURI,
                      const char *targetURI,
@@ -112,6 +110,17 @@ typedef struct GHIBinaryIconInfo {
 } GHIBinaryIconInfo;
 
 Bool GHI_GetBinaryInfo(const char *pathUriUtf8, std::string &friendlyName, std::list<GHIBinaryIconInfo> &iconList);
+
+#if !defined(OPEN_VM_TOOLS) && !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__)
+Bool GHI_OpenStartMenuTree(const char *rootUtf8, uint32 flags, uint32 &handle, uint32 &numItems);
+Bool GHI_GetStartMenuItem(uint32 handle,
+                          uint32 itemIndex,
+                          Bool &isSubmenu,
+                          utf::string &menuPath,
+                          utf::string &itemPathURI,
+                          utf::string &itemName);
+Bool GHI_CloseStartMenuTree(uint32 handle);
+#endif // !OPEN_VM_TOOLS && !__FreeBSD__ && !sun && !__APPLE__
 #endif // __cplusplus
 
 #endif // _GH_INTEGRATION_H_
index 014e70fba8a94d07d364d03864e2601a9129560c..a8d51826788da88d2673ac4e910c2bd484bc0318 100644 (file)
@@ -42,16 +42,6 @@ typedef struct _GHIPlatform GHIPlatform;
 Bool GHIPlatformIsSupported(void);
 GHIPlatform *GHIPlatformInit(GMainLoop *mainLoop, const char **envp, GHIHostCallbacks hostcallbacks);
 void GHIPlatformCleanup(GHIPlatform *ghip);
-Bool GHIPlatformOpenStartMenuTree(GHIPlatform *ghip,
-                                  const char *rootUtf8,
-                                  uint32 flags,
-                                  DynBuf *buf);
-Bool GHIPlatformGetStartMenuItem(GHIPlatform *ghip,
-                                 uint32 handle,
-                                 uint32 itemIndex,
-                                 DynBuf *buf);
-Bool GHIPlatformCloseStartMenuTree(GHIPlatform *ghip,
-                                   uint32 handle);
 Bool GHIPlatformShellOpen(GHIPlatform *ghip,
                           const char *fileUtf8);
 Bool GHIPlatformShellAction(GHIPlatform *ghip,
@@ -128,6 +118,21 @@ void GHIPlatformUnregisterNotifyIconCallback(vmware::tools::NotifyIconCallback *
 
 #if !defined(OPEN_VM_TOOLS)  && !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__)
 const FileTypeList& GHIPlatformGetBinaryHandlers(GHIPlatform *ghip, const char *pathUtf8);
+
+Bool GHIPlatformOpenStartMenuTree(GHIPlatform *ghip,
+                                  const char *rootUtf8,
+                                  uint32 flags,
+                                  uint32 &handle,
+                                  uint32 &numItems);
+Bool GHIPlatformGetStartMenuItem(GHIPlatform *ghip,
+                                 uint32 handle,
+                                 uint32 itemIndex,
+                                 Bool &isSubmenu,
+                                 utf::string &menuPath,
+                                 utf::string &itemPathURI,
+                                 utf::string &itemName);
+Bool GHIPlatformCloseStartMenuTree(GHIPlatform *ghip,
+                                   uint32 handle);
 #endif // !OPEN_VM_TOOLS && !__FreeBSD__ && !sun && !__APPLE__
 
 Bool GHIPlatformGetBinaryInfo(GHIPlatform *ghip, const char *pathUriUtf8, std::string &friendlyName, std::list<GHIBinaryIconInfo> &iconList);
index 24069c7e8817144b84a9b49185365c0a3a9f6e99..d44d6234798a79688f481d6271dd1c284343f629 100644 (file)
@@ -594,7 +594,6 @@ GHIPlatformGetBinaryHandlers(GHIPlatform *ghip,      // IN: platform-specific st
 {
    return sEmptyFileTypeList;
 }
-#endif // OPEN_VM_TOOLS
 
 
 /*
@@ -624,16 +623,16 @@ Bool
 GHIPlatformOpenStartMenuTree(GHIPlatform *ghip,        // IN: platform-specific state
                              const char *rootUtf8,     // IN: root of the tree
                              uint32 flags,             // IN: flags
-                             DynBuf *buf)              // OUT: number of items
+                             uint32 &handle,           // OUT: menu handle
+                             uint32 &numItems)         // OUT: number of items
 {
    Bool success = FALSE;
 
 #ifdef REDIST_GMENU
    std::pair<uint32,uint32> descriptor;
    if (ghip->menuItemManager->OpenMenuTree(rootUtf8, &descriptor)) {
-      char tmp[2 * sizeof MAKESTR(UINT_MAX)];
-      Str_Sprintf(tmp, sizeof tmp, "%u %u", descriptor.first, descriptor.second);
-      DynBuf_AppendString(buf, tmp);
+      handle = descriptor.first;
+      numItems = descriptor.second;
       success = TRUE;
    }
 #endif
@@ -642,6 +641,85 @@ GHIPlatformOpenStartMenuTree(GHIPlatform *ghip,        // IN: platform-specific
 }
 
 
+/*
+ *----------------------------------------------------------------------------
+ *
+ * GHIPlatformGetStartMenuItem --
+ *
+ *      Get start menu item at a given index. This function should be called
+ *      in the loop to get all items for a menu sub-tree.
+ *      If there are no more items, the function will return FALSE.
+ *
+ * Results:
+ *      TRUE if there's an item at a given index, FALSE otherwise.
+ *
+ * Side effects:
+ *      None
+ *
+ *----------------------------------------------------------------------------
+ */
+
+Bool
+GHIPlatformGetStartMenuItem(GHIPlatform *ghip,        // IN: platform-specific state
+                            uint32 handle,            // IN: tree handle
+                            uint32 itemIndex,         // IN: the index of the item in the tree
+                            Bool &isSubmenu,          // OUT: True if this item is a submenu
+                            utf::string &menuPath,    // OUT: Path to the submenu (if this item is a submenu)
+                            utf::string &itemPathURI, // OUT: URI for the item (empty if this is a submenu)
+                            utf::string &itemName)    // OUT: The name/label for the item
+{
+   Bool success = FALSE;
+
+#ifdef REDIST_GMENU
+   const MenuItem* menuItem;
+   const Glib::ustring* path;
+
+   if (ghip->menuItemManager->GetMenuItem(handle, itemIndex, &menuItem, &path)) {
+      Glib::ustring key = *path + "/" + menuItem->key;
+      menuPath = key;
+
+      isSubmenu = menuItem->isFolder;
+
+      itemPathURI = menuItem->execPath.c_str();
+      itemName = menuItem->displayName.c_str();
+      success = TRUE;
+   }
+#endif
+
+   return success;
+}
+
+
+/*
+ *----------------------------------------------------------------------------
+ *
+ * GHIPlatformCloseStartMenu --
+ *
+ *      Free all memory associated with this start menu tree and cleanup.
+ *
+ * Results:
+ *      TRUE if the handle is valid
+ *      FALSE otherwise
+ *
+ * Side effects:
+ *      None
+ *
+ *----------------------------------------------------------------------------
+ */
+
+Bool
+GHIPlatformCloseStartMenuTree(GHIPlatform *ghip, // IN: platform-specific state
+                              uint32 handle)     // IN: handle to the tree to be closed
+{
+#ifdef REDIST_GMENU
+   return ghip->menuItemManager->CloseMenuTree(handle);
+#else
+   return FALSE;
+#endif
+}
+#endif // OPEN_VM_TOOLS
+
+
 /*
  *-----------------------------------------------------------------------------
  *
@@ -721,89 +799,6 @@ GHIPlatformMenuItemToURI(GHIPlatform *ghip, // IN
 }
 
 
-/*
- *----------------------------------------------------------------------------
- *
- * GHIPlatformGetStartMenuItem --
- *
- *      Get start menu item at a given index. This function should be called
- *      in the loop to get all items for a menu sub-tree.
- *      If there are no more items, the function will return FALSE.
- *
- *      Upon returning, 'buf' will hold a nul-delimited array of strings:
- *         1. User-visible item name.
- *         2. UNITY_START_MENU_ITEM_* flag.
- *         3. Executable path.
- *         4. Localized user-visible item name.
- *
- * Results:
- *      TRUE if there's an item at a given index, FALSE otherwise.
- *
- * Side effects:
- *      None
- *
- *----------------------------------------------------------------------------
- */
-
-Bool
-GHIPlatformGetStartMenuItem(GHIPlatform *ghip, // IN: platform-specific state
-                            uint32 handle,     // IN: tree handle
-                            uint32 itemIndex,  // IN: the index of the item in the tree
-                            DynBuf *buf)       // OUT: item
-{
-   Bool success = FALSE;
-
-#ifdef REDIST_GMENU
-   const MenuItem* menuItem;
-   const Glib::ustring* path;
-
-   if (ghip->menuItemManager->GetMenuItem(handle, itemIndex, &menuItem, &path)) {
-      Glib::ustring key = *path + "/" + menuItem->key;
-      DynBuf_AppendString(buf, key.c_str());
-
-      char tmp[sizeof MAKESTR(UINT_MAX)];
-      Str_Sprintf(tmp, sizeof tmp, "%u", menuItem->isFolder ? 1 : 0);
-      DynBuf_AppendString(buf, tmp);
-
-      DynBuf_AppendString(buf, menuItem->execPath.c_str());
-      DynBuf_AppendString(buf, menuItem->displayName.c_str());
-      success = TRUE;
-   }
-#endif
-
-   return success;
-}
-
-
-/*
- *----------------------------------------------------------------------------
- *
- * GHIPlatformCloseStartMenu --
- *
- *      Free all memory associated with this start menu tree and cleanup.
- *
- * Results:
- *      TRUE if the handle is valid
- *      FALSE otherwise
- *
- * Side effects:
- *      None
- *
- *----------------------------------------------------------------------------
- */
-
-Bool
-GHIPlatformCloseStartMenuTree(GHIPlatform *ghip, // IN: platform-specific state
-                              uint32 handle)     // IN: handle to the tree to be closed
-{
-#ifdef REDIST_GMENU
-   return ghip->menuItemManager->CloseMenuTree(handle);
-#else
-   return FALSE;
-#endif
-}
-
-
 #if 0 // REMOVE AFTER IMPLEMENTING GHIPlatformShellAction
 /*
  *-----------------------------------------------------------------------------
index 28e13f1a7f0815fb7c46907fb36cb6bc0951b15f..2633493d71b4c1d01ffb2f4fb7094edcd09cb270 100644 (file)
@@ -439,6 +439,9 @@ GHITcloOpenStartMenu(RpcInData *data)        // IN/OUT
    DynBuf *buf = &gTcloUpdate;
    uint32 flags = 0;
    uint32 index = 0;
+   uint32 menuHandle = 0;
+   uint32 numItems = 0;
+
    Bool ret = TRUE;
 
    /* Check our arguments. */
@@ -485,13 +488,19 @@ GHITcloOpenStartMenu(RpcInData *data)        // IN/OUT
    }
 
    DynBuf_SetSize(buf, 0);
-   if (!GHI_OpenStartMenuTree(rootUtf8, flags, buf)) {
+#if !defined(OPEN_VM_TOOLS)
+   if (!GHI_OpenStartMenuTree(rootUtf8, flags, menuHandle, numItems)) {
       Debug("%s: Could not open start menu.\n", __FUNCTION__);
       ret = RPCIN_SETRETVALS(data,
                              "Could not get start menu count",
                              FALSE);
       goto exit;
+   } else {
+       char temp[256];
+       Str_Sprintf(temp, sizeof temp, "%d %d", menuHandle, numItems);
+       DynBuf_AppendString(buf, temp);
    }
+#endif // OPEN_VM_TOOLS
 
    /*
     * Write the final result into the result out parameters and return!
@@ -533,6 +542,12 @@ GHITcloGetStartMenuItem(RpcInData *data)        // IN/OUT
    Bool ret = TRUE;
    uint32 itemIndex = 0;
    uint32 handle = 0;
+#if !defined(OPEN_VM_TOOLS)
+   Bool isSubmenu;
+   utf::string menuPath;
+   utf::string itemPathURI;
+   utf::string itemName;
+#endif // OPEN_VM_TOOLS
 
    /* Check our arguments. */
    ASSERT(data);
@@ -567,13 +582,25 @@ GHITcloGetStartMenuItem(RpcInData *data)        // IN/OUT
    }
 
    DynBuf_SetSize(buf, 0);
-   if (!GHI_GetStartMenuItem(handle, itemIndex, buf)) {
+#if !defined(OPEN_VM_TOOLS)
+   if (!GHI_GetStartMenuItem(handle, itemIndex,
+                             isSubmenu, menuPath, itemPathURI, itemName)) {
       Debug("%s: Could not get start menu item.\n", __FUNCTION__);
       return RPCIN_SETRETVALS(data,
                               "Could not get start menu item",
                               FALSE);
    }
 
+   DynBuf_AppendString(buf, menuPath.c_str());
+   DynBuf_AppendString(buf, isSubmenu ? "1" : "0");
+   DynBuf_AppendString(buf, itemPathURI.c_str());
+   DynBuf_AppendString(buf, itemName.c_str());
+#else
+   return RPCIN_SETRETVALS(data,
+                           "Could not get start menu item",
+                           FALSE);
+#endif // OPEN_VM_TOOLS
+
    /*
     * Write the final result into the result out parameters and return!
     */
@@ -631,7 +658,9 @@ GHITcloCloseStartMenu(RpcInData *data)        // IN/OUT
                               FALSE);
    }
 
+#if !defined(OPEN_VM_TOOLS)
    GHI_CloseStartMenuTree(handle);
+#endif // OPEN_VM_TOOLS
 
    return RPCIN_SETRETVALS(data, "", TRUE);
 }