KIO

widgetsopenwithhandler_win.cpp
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2008 Jarosław Staniek <staniek@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include <QDir>
9#include <QWidget>
10
11#include <qt_windows.h>
12
13// TODO move to a shared lib
14static int runDll(WId windowId, const QString &libraryName, const QByteArray &functionName, const QString &arguments)
15{
16 HMODULE libHandle = LoadLibraryW((LPCWSTR)libraryName.utf16());
17 if (!libHandle) {
18 return 0;
19 }
20 typedef int(WINAPI * FunctionType)(HWND, HMODULE, LPCWSTR, int);
21
22 FunctionType function = (FunctionType)GetProcAddress(libHandle, functionName.constData());
23
24 if (!function) {
25 return 0;
26 }
27 int result = function((HWND)windowId, libHandle, (LPCWSTR)arguments.utf16(), SW_SHOW);
28 FreeLibrary(libHandle);
29 return result;
30}
31
32static int runDll(WId windowId, const QString &libraryName, const QByteArray &functionName, const QByteArray &arguments)
33{
34 HMODULE libHandle = LoadLibraryW((LPCWSTR)libraryName.utf16());
35 if (!libHandle) {
36 return 0;
37 }
38 typedef int(WINAPI * FunctionType)(HWND, HMODULE, LPCSTR, int);
39
40 FunctionType function = (FunctionType)GetProcAddress(libHandle, functionName.constData());
41
42 if (!function) {
43 return 0;
44 }
45 int result = function((HWND)windowId, libHandle, (LPCSTR)arguments.constData(), SW_SHOW);
46 FreeLibrary(libHandle);
47 return result;
48}
49
50// TODO move to a shared lib
51static int runDll(QWidget *parent, const QString &libraryName, const QByteArray &functionName, const QString &arguments)
52{
53 return runDll(parent ? parent->winId() : 0, libraryName, functionName, arguments);
54}
55
56// Windows implementation using "OpenAs_RunDLL" entry
57static bool displayNativeOpenWithDialog(const QList<QUrl> &lst, QWidget *window)
58{
59 QStringList fnames;
60 for (const QUrl &url : lst) {
61 fnames += url.isLocalFile() ? QDir::toNativeSeparators(url.toLocalFile()) : url.toString();
62 }
63 int result = runDll(window, QLatin1String("shell32.dll"), "OpenAs_RunDLLW", fnames.join(QLatin1Char(' ')));
64 return result == 0;
65}
char * toString(const EngineQuery &query)
const char * constData() const const
QString toNativeSeparators(const QString &pathName)
const ushort * utf16() const const
QString join(QChar separator) const const
WId winId() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:49:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.