1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Windows: At first try to show native default app settings UI (>=Vista).

This commit is contained in:
srazi 2017-08-22 04:31:00 +04:30 committed by David Rosca
parent 1bc35dafc4
commit 2aa25fe0b1
4 changed files with 74 additions and 4 deletions

View File

@ -1092,7 +1092,8 @@ void MainApplication::checkDefaultWebBrowser()
dialog.setIcon(QMessageBox::Warning);
if (dialog.exec() == QMessageBox::Yes) {
associationManager()->registerAllAssociation();
if (!mApp->associationManager()->showNativeDefaultAppSettingsUi())
mApp->associationManager()->registerAllAssociation();
}
checkAgain = dialog.isChecked();

View File

@ -1,5 +1,5 @@
/* ============================================================
* Copyright (C) 2012-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* Copyright (C) 2012-2017 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* This file is part of QupZilla - WebKit based browser 2010-2014
* by David Rosca <nowrep@gmail.com>
*
@ -148,6 +148,12 @@ bool RegisterQAppAssociation::isVistaOrNewer()
QSysInfo::windowsVersion() <= QSysInfo::WV_NT_based);
}
bool RegisterQAppAssociation::isWin10OrNewer()
{
return (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS10 &&
QSysInfo::windowsVersion() <= QSysInfo::WV_NT_based);
}
void RegisterQAppAssociation::registerAssociation(const QString &assocName, AssociationType type)
{
if (isVistaOrNewer()) { // Vista and newer
@ -261,6 +267,65 @@ void RegisterQAppAssociation::registerAllAssociation()
}
}
// The code of the following method was taken
// from https://github.com/mozilla/gecko-dev/blob/master/browser/components/shell/nsWindowsShellService.cpp#L364
// that is licensed under MPL-2.0.
bool RegisterQAppAssociation::showNativeDefaultAppSettingsUi()
{
if (!isVistaOrNewer()) {
return false;
}
if (isWin10OrNewer()) {
IApplicationActivationManager* pActivator;
HRESULT hr = CoCreateInstance(CLSID_ApplicationActivationManager,
nullptr,
CLSCTX_INPROC,
IID_IApplicationActivationManager,
(void**)&pActivator);
if (!SUCCEEDED(hr)) {
return false;
}
DWORD pid;
hr = pActivator->ActivateApplication(
L"windows.immersivecontrolpanel_cw5n1h2txyewy"
L"!microsoft.windows.immersivecontrolpanel",
L"page=SettingsPageAppsDefaults", AO_NONE, &pid);
if (!SUCCEEDED(hr)) {
return false;
}
// Do not check error because we could at least open
// the "Default apps" setting.
pActivator->ActivateApplication(
L"windows.immersivecontrolpanel_cw5n1h2txyewy"
L"!microsoft.windows.immersivecontrolpanel",
L"page=SettingsPageAppsDefaults"
L"&target=SystemSettings_DefaultApps_Browser", AO_NONE, &pid);
pActivator->Release();
}
else {
IApplicationAssociationRegistrationUI* pAARUI = NULL;
HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistrationUI,
NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistrationUI),
reinterpret_cast< void** > (&pAARUI));
if (!SUCCEEDED(hr)) {
return false;
}
hr = pAARUI->LaunchAdvancedAssociationUI(reinterpret_cast<LPCWSTR>(_appRegisteredName.utf16()));
pAARUI->Release();
}
return true;
}
void RegisterQAppAssociation::createProgId(const QString &progId)
{
QSettings regUserRoot(_UserRootKey, QSettings::NativeFormat);

View File

@ -1,5 +1,5 @@
/* ============================================================
* Copyright (C) 2012-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* Copyright (C) 2012-2017 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* This file is part of QupZilla - WebKit based browser 2010-2014
* by David Rosca <nowrep@gmail.com>
*
@ -50,6 +50,7 @@ public:
void setPerMachineRegisteration(bool enable);
bool registerAppCapabilities();
bool isVistaOrNewer();
bool isWin10OrNewer();
void registerAssociation(const QString &assocName, AssociationType type);
void createProgId(const QString &progId);
@ -57,6 +58,7 @@ public:
bool isDefaultForAllCapabilities();
void registerAllAssociation();
bool showNativeDefaultAppSettingsUi();
private:
QString _appRegisteredName;

View File

@ -611,9 +611,11 @@ void Preferences::makeQupZillaDefault()
{
#if defined(Q_OS_WIN) && !defined(Q_OS_OS2)
disconnect(ui->checkNowDefaultBrowser, SIGNAL(clicked()), this, SLOT(makeQupZillaDefault()));
mApp->associationManager()->registerAllAssociation();
ui->checkNowDefaultBrowser->setText(tr("Default"));
ui->checkNowDefaultBrowser->setEnabled(false);
if (!mApp->associationManager()->showNativeDefaultAppSettingsUi())
mApp->associationManager()->registerAllAssociation();
#endif
}