From 23e248b5d19ffddd4e836773044123ca977d09ef Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Fri, 13 Feb 2015 16:00:22 +0100 Subject: [PATCH] shell_integration: Fetch the share menu title from the client on Windows The context menu will now show "Share with ownCloud" instead of "Share" as it does on other platforms. This also updates the submodule to point to matching binaries. --- binary | 2 +- doc/installing.rst | 2 +- .../windows/OCContextMenu/OCClientInterface.cpp | 17 +++++++++++------ .../windows/OCContextMenu/OCClientInterface.h | 6 +++++- .../windows/OCContextMenu/OCContextMenu.cpp | 6 ++++-- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/binary b/binary index 96dd38811..5a664de4d 160000 --- a/binary +++ b/binary @@ -1 +1 @@ -Subproject commit 96dd38811b58b28146a204124a8e764b3513b7f4 +Subproject commit 5a664de4d3ac2b6edb6a16edbb5e376724e64e76 diff --git a/doc/installing.rst b/doc/installing.rst index 7f9a824b5..b950d5a55 100644 --- a/doc/installing.rst +++ b/doc/installing.rst @@ -81,7 +81,7 @@ file manager integration works. .. image:: images/client8.png When you are in your local ownCloud folder you can right-click any file or -folder, and then left-click Share to create a share link. Note that Windows +folder, and then left-click "Share with ownCloud" to create a share link. Note that Windows may also have a Share With option. This is not the ownCloud Share option. The ownCloud share dialog looks like the following example: diff --git a/shell_integration/windows/OCContextMenu/OCClientInterface.cpp b/shell_integration/windows/OCContextMenu/OCClientInterface.cpp index 8472a7cca..ab6206f92 100644 --- a/shell_integration/windows/OCContextMenu/OCClientInterface.cpp +++ b/shell_integration/windows/OCContextMenu/OCClientInterface.cpp @@ -34,28 +34,33 @@ using namespace std; #define PIPE_TIMEOUT 5*1000 //ms #define SOCK_BUFFER 4096 -std::vector OCClientInterface::WatchedDirectories() +OCClientInterface::ContextMenuInfo OCClientInterface::FetchInfo() { auto pipename = std::wstring(L"\\\\.\\pipe\\"); pipename += L"ownCloud"; CommunicationSocket socket; if (!WaitNamedPipe(pipename.data(), PIPE_TIMEOUT)) { - return std::vector(); + return {}; } if (!socket.Connect(pipename)) { - return std::vector(); + return {}; } - std::vector watchedDirectories; + socket.SendMsg(L"SHARE_MENU_TITLE\n"); + + ContextMenuInfo info; std::wstring response; Sleep(50); while (socket.ReadLine(&response)) { if (StringUtil::begins_with(response, wstring(L"REGISTER_PATH:"))) { wstring responsePath = response.substr(14); // length of REGISTER_PATH - watchedDirectories.push_back(responsePath); + info.watchedDirectories.push_back(responsePath); + } + else if (StringUtil::begins_with(response, wstring(L"SHARE_MENU_TITLE:"))) { + info.shareMenuTitle = response.substr(17); // length of SHARE_MENU_TITLE: } } - return watchedDirectories; + return info; } void OCClientInterface::ShareObject(const std::wstring &path) diff --git a/shell_integration/windows/OCContextMenu/OCClientInterface.h b/shell_integration/windows/OCContextMenu/OCClientInterface.h index 7356d1e28..16608e276 100644 --- a/shell_integration/windows/OCContextMenu/OCClientInterface.h +++ b/shell_integration/windows/OCContextMenu/OCClientInterface.h @@ -43,7 +43,11 @@ class CommunicationSocket; class OCClientInterface { public: - static std::vector WatchedDirectories(); + struct ContextMenuInfo { + std::vector watchedDirectories; + std::wstring shareMenuTitle; + }; + static ContextMenuInfo FetchInfo(); static void ShareObject(const std::wstring &path); }; diff --git a/shell_integration/windows/OCContextMenu/OCContextMenu.cpp b/shell_integration/windows/OCContextMenu/OCContextMenu.cpp index 4a612a9ca..14cb1b65e 100644 --- a/shell_integration/windows/OCContextMenu/OCContextMenu.cpp +++ b/shell_integration/windows/OCContextMenu/OCContextMenu.cpp @@ -150,8 +150,9 @@ IFACEMETHODIMP OCContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(0)); } + OCClientInterface::ContextMenuInfo info = OCClientInterface::FetchInfo(); bool skip = true; - for (const std::wstring path : OCClientInterface::WatchedDirectories()) { + for (const std::wstring path : info.watchedDirectories) { if (StringUtil::begins_with(std::wstring(m_szSelectedFile), path)) { skip = false; break; @@ -165,11 +166,12 @@ IFACEMETHODIMP OCContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT InsertSeperator(hMenu, indexMenu); indexMenu++; + assert(!info.shareMenuTitle.empty()); MENUITEMINFO mii = { sizeof(mii) }; mii.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_FTYPE | MIIM_ID | MIIM_STATE; mii.wID = idCmdFirst + IDM_SHARE; mii.fType = MFT_STRING; - mii.dwTypeData = m_pszMenuText; + mii.dwTypeData = &info.shareMenuTitle[0]; mii.fState = MFS_ENABLED; if (!InsertMenuItem(hMenu, indexMenu, TRUE, &mii)) {