1 // Copyright 2005-2019 The Mumble Developers. All rights reserved.
2 // Use of this source code is governed by a BSD-style license
3 // that can be found in the LICENSE file at the root of the
4 // Mumble source tree or at <https://www.mumble.info/LICENSE>.
5
6 #include "mumble_pch.hpp"
7
8 #include "TaskList.h"
9
10 #include <shobjidl.h>
11 #include <propkey.h>
12 #include <propvarutil.h>
13
14 extern bool bIsWin7;
15
addToRecentList(QString name,QString user,QString host,int port)16 void TaskList::addToRecentList(QString name, QString user, QString host, int port) {
17 if (! bIsWin7)
18 return;
19
20 HRESULT hr;
21 IShellLink *link = NULL;
22 IPropertyStore *ps = NULL;
23 PROPVARIANT pt;
24
25 hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, __uuidof(IShellLink), reinterpret_cast<void **>(&link));
26 if (!link || FAILED(hr))
27 return;
28
29 QUrl url;
30 url.setScheme(QLatin1String("mumble"));
31 url.setUserName(user);
32 url.setHost(host);
33 url.setPort(port);
34
35 #if QT_VERSION >= 0x050000
36 QUrlQuery query;
37 query.addQueryItem(QLatin1String("title"), name);
38 query.addQueryItem(QLatin1String("version"), QLatin1String("1.2.0"));
39 url.setQuery(query);
40 #else
41 url.addQueryItem(QLatin1String("title"), name);
42 url.addQueryItem(QLatin1String("version"), QLatin1String("1.2.0"));
43 #endif
44
45 QSettings settings(QLatin1String("HKEY_CLASSES_ROOT"), QSettings::NativeFormat);
46
47 QString app = settings.value(QLatin1String("mumble/DefaultIcon/.")).toString();
48 if (app.isEmpty() || ! QFileInfo(app).exists())
49 app = QCoreApplication::applicationFilePath();
50
51 link->SetPath(app.toStdWString().c_str());
52 link->SetArguments(QString::fromLatin1(url.toEncoded()).toStdWString().c_str());
53
54 hr = link->QueryInterface(__uuidof(IPropertyStore), reinterpret_cast<void **>(&ps));
55 if (FAILED(hr)) {
56 qFatal("TaskList: Failed to get property store");
57 goto cleanup;
58 }
59
60 InitPropVariantFromString(name.toStdWString().c_str(), &pt);
61 hr = ps->SetValue(PKEY_Title, pt);
62 PropVariantClear(&pt);
63
64 if (FAILED(hr)) {
65 qFatal("TaskList: Failed to set title");
66 goto cleanup;
67 }
68
69 hr = ps->Commit();
70 if (FAILED(hr)) {
71 qFatal("TaskList: Failed commit");
72 goto cleanup;
73 }
74
75 SHAddToRecentDocs(SHARD_LINK, link);
76
77 cleanup:
78 if (ps)
79 ps->Release();
80 if (link)
81 link->Release();
82 }
83