Skip to content

Commit

Permalink
Accept file and folder drop to overlay exception lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Kissaki committed Apr 6, 2017
1 parent 79dd6b9 commit 4a1663f
Show file tree
Hide file tree
Showing 8 changed files with 984 additions and 882 deletions.
107 changes: 107 additions & 0 deletions src/mumble/Overlay.cpp
Expand Up @@ -21,6 +21,113 @@
#include "User.h"
#include "WebFetch.h"

QString OverlayAppInfo::applicationIdentifierForPath(const QString &path) {
#ifdef Q_OS_MAC
QString qsIdentifier;
CFDictionaryRef plist = NULL;
CFDataRef data = NULL;

QFile qfAppBundle(QString::fromLatin1("%1/Contents/Info.plist").arg(path));
if (qfAppBundle.exists()) {
qfAppBundle.open(QIODevice::ReadOnly);
QByteArray qbaPlistData = qfAppBundle.readAll();

data = CFDataCreateWithBytesNoCopy(NULL, reinterpret_cast<UInt8 *>(qbaPlistData.data()), qbaPlistData.count(), kCFAllocatorNull);
plist = static_cast<CFDictionaryRef>(CFPropertyListCreateFromXMLData(NULL, data, kCFPropertyListImmutable, NULL));
if (plist) {
CFStringRef ident = static_cast<CFStringRef>(CFDictionaryGetValue(plist, CFSTR("CFBundleIdentifier")));
if (ident) {
char buf[4096];
CFStringGetCString(ident, buf, 4096, kCFStringEncodingUTF8);
qsIdentifier = QString::fromUtf8(buf);
}
}
}

if (data)
CFRelease(data);
if (plist)
CFRelease(plist);

return qsIdentifier;
#else
return QDir::toNativeSeparators(path);
#endif
}

OverlayAppInfo OverlayAppInfo::applicationInfoForId(const QString &identifier) {
QString qsAppName(identifier);
QIcon qiAppIcon;
#if defined(Q_OS_MAC)
CFStringRef bundleId = NULL;
CFURLRef bundleUrl = NULL;
CFBundleRef bundle = NULL;
OSStatus err = noErr;
char buf[4096];

bundleId = CFStringCreateWithCharacters(kCFAllocatorDefault, reinterpret_cast<const UniChar *>(identifier.unicode()), identifier.length());
err = LSFindApplicationForInfo(kLSUnknownCreator, bundleId, NULL, NULL, &bundleUrl);
if (err == noErr) {
// Figure out the bundle name of the application.
CFStringRef absBundlePath = CFURLCopyFileSystemPath(bundleUrl, kCFURLPOSIXPathStyle);
CFStringGetCString(absBundlePath, buf, 4096, kCFStringEncodingUTF8);
QString qsBundlePath = QString::fromUtf8(buf);
CFRelease(absBundlePath);
qsAppName = QFileInfo(qsBundlePath).bundleName();

// Load the bundle's icon.
bundle = CFBundleCreate(NULL, bundleUrl);
if (bundle) {
CFDictionaryRef info = CFBundleGetInfoDictionary(bundle);
if (info) {
CFStringRef iconFileName = reinterpret_cast<CFStringRef>(CFDictionaryGetValue(info, CFSTR("CFBundleIconFile")));
if (iconFileName) {
CFStringGetCString(iconFileName, buf, 4096, kCFStringEncodingUTF8);
QString qsIconPath = QString::fromLatin1("%1/Contents/Resources/%2")
.arg(qsBundlePath, QString::fromUtf8(buf));
if (! QFile::exists(qsIconPath))
qsIconPath += QString::fromLatin1(".icns");
if (QFile::exists(qsIconPath))
qiAppIcon = QIcon(qsIconPath);
}
}
}
}

if (bundleId)
CFRelease(bundleId);
if (bundleUrl)
CFRelease(bundleUrl);
if (bundle)
CFRelease(bundle);

#elif defined(Q_OS_WIN)
// qWinAppInst(), whose return value we used to pass
// to ExtractIcon below, was removed in Qt 5.8.
//
// It was removed via
// https://github.com/qt/qtbase/commit/64507c7165e42c2a5029353d8f97a0d841fa6b01
//
// In both Qt 4 and Qt 5, the qWinAppInst() implementation
// simply calls GetModuleHandle(0).
//
// To sidestep the removal of the function, we simply
// call through to GetModuleHandle() directly.
HINSTANCE qWinAppInstValue = GetModuleHandle(NULL);
HICON icon = ExtractIcon(qWinAppInstValue, identifier.toStdWString().c_str(), 0);
if (icon) {
#if QT_VERSION >= 0x050000
extern QPixmap qt_pixmapFromWinHICON(HICON icon);
qiAppIcon = QIcon(qt_pixmapFromWinHICON(icon));
#else
qiAppIcon = QIcon(QPixmap::fromWinHICON(icon));
#endif
DestroyIcon(icon);
}
#endif
return OverlayAppInfo(qsAppName, qiAppIcon);
}

OverlayAppInfo::OverlayAppInfo(QString name, QIcon icon) {
qsDisplayName = name;
qiIcon = icon;
Expand Down
3 changes: 3 additions & 0 deletions src/mumble/Overlay.h
Expand Up @@ -28,6 +28,9 @@ class OverlayClient;
class OverlayConfig;

struct OverlayAppInfo {
static QString applicationIdentifierForPath(const QString &path);
static OverlayAppInfo applicationInfoForId(const QString &identifier);

QString qsDisplayName;
QIcon qiIcon;

Expand Down
12 changes: 8 additions & 4 deletions src/mumble/Overlay.ui
Expand Up @@ -357,7 +357,7 @@
</widget>
</item>
<item>
<widget class="QListWidget" name="qlwLaunchers"/>
<widget class="PathListWidget" name="qlwLaunchers"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
Expand Down Expand Up @@ -394,7 +394,11 @@
</widget>
</item>
<item>
<widget class="QListWidget" name="qlwWhitelist"/>
<widget class="PathListWidget" name="qlwWhitelist">
<property name="acceptDrops">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
Expand Down Expand Up @@ -431,7 +435,7 @@
</widget>
</item>
<item>
<widget class="QListWidget" name="qlwPaths"/>
<widget class="PathListWidget" name="qlwPaths"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
Expand Down Expand Up @@ -468,7 +472,7 @@
</widget>
</item>
<item>
<widget class="QListWidget" name="qlwBlacklist"/>
<widget class="PathListWidget" name="qlwBlacklist"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
Expand Down

0 comments on commit 4a1663f

Please sign in to comment.