Merge pull request #1829 from nextcloud/fix-explorer-pinning

Fix Explorer pinning: Add fallbacks for Shell commands (fixes #1599)
This commit is contained in:
Michael Schuster 2020-03-03 20:12:32 +01:00 committed by GitHub
commit 601804b78c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 5 deletions

View file

@ -182,20 +182,38 @@ IFACEMETHODIMP OCContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO pici)
{
std::wstring command;
CMINVOKECOMMANDINFOEX *piciEx = nullptr;
if (pici->cbSize == sizeof(CMINVOKECOMMANDINFOEX))
piciEx = (CMINVOKECOMMANDINFOEX*)pici;
// For the Unicode case, if the high-order word is not zero, the
// command's verb string is in lpcmi->lpVerbW.
if (HIWORD(((CMINVOKECOMMANDINFOEX*)pici)->lpVerbW))
{
command = ((CMINVOKECOMMANDINFOEX *)pici)->lpVerbW;
} else {
if (piciEx
&& (piciEx->fMask & CMIC_MASK_UNICODE)
&& HIWORD(((CMINVOKECOMMANDINFOEX*)pici)->lpVerbW)) {
command = piciEx->lpVerbW;
// Verify that we handle the verb
bool handled = false;
for (auto &item : m_info.menuItems) {
if (item.command == command) {
handled = true;
break;
}
}
if (!handled)
return E_FAIL;
} else if (IS_INTRESOURCE(pici->lpVerb)) {
// If the command cannot be identified through the verb string, then
// check the identifier offset.
auto offset = LOWORD(pici->lpVerb);
if (offset >= m_info.menuItems.size())
return E_FAIL;
command = m_info.menuItems[offset].command;
} else {
return E_FAIL;
}
OCClientInterface::SendRequest(command.data(), m_selectedFiles);

View file

@ -52,6 +52,7 @@
#include <QInputDialog>
#include <QClipboard>
#include <QDesktopServices>
#include <QStandardPaths>
@ -291,6 +292,12 @@ void SocketApi::slotReadSocket()
int indexOfMethod = staticMetaObject.indexOfMethod(functionWithArguments);
QString argument = line.remove(0, command.length() + 1);
if (indexOfMethod == -1) {
// Fallback: Try upper-case command
functionWithArguments = "command_" + command.toUpper() + "(QString,SocketListener*)";
indexOfMethod = staticMetaObject.indexOfMethod(functionWithArguments);
}
if (indexOfMethod != -1) {
staticMetaObject.method(indexOfMethod).invoke(this, Q_ARG(QString, argument), Q_ARG(SocketListener *, listener));
} else {
@ -621,6 +628,24 @@ void SocketApi::command_COPY_PUBLIC_LINK(const QString &localFile, SocketListene
job->run();
}
// Windows Shell / Explorer pinning fallbacks, see issue: https://github.com/nextcloud/desktop/issues/1599
#ifdef Q_OS_WIN
void SocketApi::command_COPYASPATH(const QString &localFile, SocketListener *)
{
QApplication::clipboard()->setText(localFile);
}
void SocketApi::command_OPENNEWWINDOW(const QString &localFile, SocketListener *)
{
QDesktopServices::openUrl(QUrl::fromLocalFile(localFile));
}
void SocketApi::command_OPEN(const QString &localFile, SocketListener *socketListener)
{
command_OPENNEWWINDOW(localFile, socketListener);
}
#endif
// Fetches the private link url asynchronously and then calls the target slot
void SocketApi::fetchPrivateLinkUrlHelper(const QString &localFile, const std::function<void(const QString &url)> &targetFun)
{

View file

@ -106,6 +106,13 @@ private:
Q_INVOKABLE void command_EMAIL_PRIVATE_LINK(const QString &localFile, SocketListener *listener);
Q_INVOKABLE void command_OPEN_PRIVATE_LINK(const QString &localFile, SocketListener *listener);
// Windows Shell / Explorer pinning fallbacks, see issue: https://github.com/nextcloud/desktop/issues/1599
#ifdef Q_OS_WIN
Q_INVOKABLE void command_COPYASPATH(const QString &localFile, SocketListener *listener);
Q_INVOKABLE void command_OPENNEWWINDOW(const QString &localFile, SocketListener *listener);
Q_INVOKABLE void command_OPEN(const QString &localFile, SocketListener *listener);
#endif
// Fetch the private link and call targetFun
void fetchPrivateLinkUrlHelper(const QString &localFile, const std::function<void(const QString &url)> &targetFun);