From ae71570ee7db0a4a9d237424ed2cc3204e86f136 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Fri, 15 Nov 2019 12:14:31 +0300 Subject: tdf#44462: add a link to Windows Default apps settings applet Add "Windows Default apps" button to Options->General to run system applet to control file associations, in accordance to recommendation from MS [1]. On Windows 10, though, the call to LaunchAdvancedAssociationUI would only bring a system-modal infobanner suggesting the user to go to Settings > Apps > Default apps, as documented at [2]. Since this is what MS considers the correct way to manage application associations, the infobanner should be enough. [1] https://docs.microsoft.com/en-us/windows/win32/shell/default-programs [2] https://docs.microsoft.com/en-us/windows/win32/api/shobjidl/nf-shobjidl-iapplicationassociationregistrationui-launchadvancedassociationui Change-Id: I79cccdd00afac998c028b8e151db66bbd75be985 Reviewed-on: https://gerrit.libreoffice.org/82777 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- cui/Library_cui.mk | 1 + cui/source/options/optgdlg.cxx | 39 ++++++++++++++++++++++++++++++ cui/source/options/optgdlg.hxx | 7 ++++++ cui/uiconfig/ui/optgeneralpage.ui | 51 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+) (limited to 'cui') diff --git a/cui/Library_cui.mk b/cui/Library_cui.mk index e45e35a8f0e3..27d89ec1c3b6 100644 --- a/cui/Library_cui.mk +++ b/cui/Library_cui.mk @@ -87,6 +87,7 @@ ifeq ($(OS),WNT) $(eval $(call gb_Library_use_system_win32_libs,cui,\ advapi32 \ shlwapi \ + ole32 \ )) endif diff --git a/cui/source/options/optgdlg.cxx b/cui/source/options/optgdlg.cxx index 3079b2c92c2c..597d75358d1c 100644 --- a/cui/source/options/optgdlg.cxx +++ b/cui/source/options/optgdlg.cxx @@ -81,6 +81,12 @@ #include #include +#if defined(_WIN32) +#include +#include +#include +#include +#endif using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::beans; @@ -248,6 +254,10 @@ OfaMiscTabPage::OfaMiscTabPage(weld::Container* pPage, weld::DialogController* p #else , m_xQuickLaunchCB(m_xBuilder->weld_check_button("quicklaunch")) #endif +#if defined(_WIN32) + , m_xFileAssocFrame(m_xBuilder->weld_widget("fileassoc")) + , m_xFileAssocBtn(m_xBuilder->weld_button("assocfiles")) +#endif { if (!lcl_HasSystemFilePicker()) m_xFileDlgFrame->hide(); @@ -273,6 +283,11 @@ OfaMiscTabPage::OfaMiscTabPage(weld::Container* pPage, weld::DialogController* p m_xQuickStarterFrame->hide(); #endif +#if defined(_WIN32) + m_xFileAssocFrame->show(); + m_xFileAssocBtn->connect_clicked(LINK(this, OfaMiscTabPage, FileAssocClick)); +#endif + m_aStrDateInfo = m_xToYearFT->get_label(); m_xYearValueField->connect_value_changed( LINK( this, OfaMiscTabPage, TwoFigureHdl ) ); @@ -427,6 +442,30 @@ IMPL_LINK_NOARG( OfaMiscTabPage, TwoFigureHdl, weld::SpinButton&, void ) m_xToYearFT->set_label( aOutput ); } +#if defined(_WIN32) +IMPL_LINK_NOARG(OfaMiscTabPage, FileAssocClick, weld::Button&, void) +{ + const bool bUninit = SUCCEEDED(CoInitialize(nullptr)); + IApplicationAssociationRegistrationUI* pIf = nullptr; + HRESULT res = CoCreateInstance(CLSID_ApplicationAssociationRegistrationUI, 0, + CLSCTX_INPROC_SERVER, IID_IApplicationAssociationRegistrationUI, + reinterpret_cast(&pIf)); + + if (SUCCEEDED(res) && pIf) + { + // LaunchAdvancedAssociationUI only works for applications registered under + // Software\RegisteredApplications. See scp2/source/ooo/registryitem_ooo.scp + const OUString expanded = Translate::ExpandVariables("%PRODUCTNAME %PRODUCTVERSION"); + // This will only show "To change your default apps, go to Settings > Apps > Default apps" + // on Win10; this is expected. At least this will self-document it to users. + pIf->LaunchAdvancedAssociationUI(o3tl::toW(expanded.getStr())); + pIf->Release(); + } + if (bUninit) + CoUninitialize(); +} +#endif + class CanvasSettings { public: diff --git a/cui/source/options/optgdlg.hxx b/cui/source/options/optgdlg.hxx index 5c591e7c876f..392554f6e8dd 100644 --- a/cui/source/options/optgdlg.hxx +++ b/cui/source/options/optgdlg.hxx @@ -54,8 +54,15 @@ private: std::unique_ptr m_xCrashReport; std::unique_ptr m_xQuickStarterFrame; std::unique_ptr m_xQuickLaunchCB; +#if defined(_WIN32) + std::unique_ptr m_xFileAssocFrame; + std::unique_ptr m_xFileAssocBtn; +#endif DECL_LINK(TwoFigureHdl, weld::SpinButton&, void); +#if defined(_WIN32) + DECL_LINK(FileAssocClick, weld::Button&, void); +#endif protected: virtual DeactivateRC DeactivatePage( SfxItemSet* pSet ) override; diff --git a/cui/uiconfig/ui/optgeneralpage.ui b/cui/uiconfig/ui/optgeneralpage.ui index dc1fa2231ecf..87ff247ffdf1 100644 --- a/cui/uiconfig/ui/optgeneralpage.ui +++ b/cui/uiconfig/ui/optgeneralpage.ui @@ -450,5 +450,56 @@ 6 + + + False + 0 + none + + + True + False + 6 + 12 + + + True + False + 6 + + + True + Windows Default apps + True + False + True + True + True + + + 0 + 0 + + + + + + + + + True + False + %PRODUCTNAME File Associations + + + + + + + + 0 + 7 + + -- cgit