diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index b926404d2..478cee194 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -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(); diff --git a/src/lib/other/registerqappassociation.cpp b/src/lib/other/registerqappassociation.cpp index 8a044be63..4677367e6 100644 --- a/src/lib/other/registerqappassociation.cpp +++ b/src/lib/other/registerqappassociation.cpp @@ -1,5 +1,5 @@ /* ============================================================ -* Copyright (C) 2012-2014 S. Razi Alavizadeh +* Copyright (C) 2012-2017 S. Razi Alavizadeh * This file is part of QupZilla - WebKit based browser 2010-2014 * by David Rosca * @@ -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(_appRegisteredName.utf16())); + pAARUI->Release(); + } + + return true; +} + void RegisterQAppAssociation::createProgId(const QString &progId) { QSettings regUserRoot(_UserRootKey, QSettings::NativeFormat); diff --git a/src/lib/other/registerqappassociation.h b/src/lib/other/registerqappassociation.h index aff8c42bd..cf1d6dc5f 100644 --- a/src/lib/other/registerqappassociation.h +++ b/src/lib/other/registerqappassociation.h @@ -1,5 +1,5 @@ /* ============================================================ -* Copyright (C) 2012-2014 S. Razi Alavizadeh +* Copyright (C) 2012-2017 S. Razi Alavizadeh * This file is part of QupZilla - WebKit based browser 2010-2014 * by David Rosca * @@ -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; diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index c8a2ddc8f..bfcfe2043 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -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 }