1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "SafeModeDialog.hxx"
12 #include <osl/file.hxx>
13 #include <sfx2/safemode.hxx>
14 #include <vcl/svapp.hxx>
15 #include <vcl/weld.hxx>
16 #include <comphelper/processfactory.hxx>
17 #include <unotools/ZipPackageHelper.hxx>
18 #include <unotools/configmgr.hxx>
19 #include <svx/dialmgr.hxx>
20 #include <svx/strings.hrc>
21 #include <svx/FileExportedDialog.hxx>
22 #include <officecfg/Office/Common.hxx>
24 #include <com/sun/star/task/OfficeRestartManager.hpp>
25 #include <com/sun/star/task/XInteractionHandler.hpp>
29 SafeModeDialog::SafeModeDialog(weld::Window
* pParent
)
30 : GenericDialogController(pParent
, "svx/ui/safemodedialog.ui", "SafeModeDialog")
31 , mxBtnContinue(m_xBuilder
->weld_button("btn_continue"))
32 , mxBtnRestart(m_xBuilder
->weld_button("btn_restart"))
33 , mxBtnApply(m_xBuilder
->weld_button("btn_apply"))
34 , mxBoxRestore(m_xBuilder
->weld_container("group_restore"))
35 , mxBoxConfigure(m_xBuilder
->weld_container("group_configure"))
36 , mxBoxDeinstall(m_xBuilder
->weld_container("group_deinstall"))
37 , mxBoxReset(m_xBuilder
->weld_container("group_reset"))
38 , mxRadioRestore(m_xBuilder
->weld_radio_button("radio_restore"))
39 , mxRadioConfigure(m_xBuilder
->weld_radio_button("radio_configure"))
40 , mxRadioExtensions(m_xBuilder
->weld_radio_button("radio_extensions"))
41 , mxRadioReset(m_xBuilder
->weld_radio_button("radio_reset"))
42 , mxCBCheckProfilesafeConfig(m_xBuilder
->weld_check_button("check_profilesafe_config"))
43 , mxCBCheckProfilesafeExtensions(m_xBuilder
->weld_check_button("check_profilesafe_extensions"))
44 , mxCBDisableAllExtensions(m_xBuilder
->weld_check_button("check_disable_all_extensions"))
45 , mxCBDeinstallUserExtensions(m_xBuilder
->weld_check_button("check_deinstall_user_extensions"))
46 , mxCBResetSharedExtensions(m_xBuilder
->weld_check_button("check_reset_shared_extensions"))
47 , mxCBResetBundledExtensions(m_xBuilder
->weld_check_button("check_reset_bundled_extensions"))
48 , mxCBDisableHWAcceleration(m_xBuilder
->weld_check_button("check_disable_hw_acceleration"))
49 , mxCBResetCustomizations(m_xBuilder
->weld_check_button("check_reset_customizations"))
50 , mxCBResetWholeUserProfile(m_xBuilder
->weld_check_button("check_reset_whole_userprofile"))
51 , mxBugLink(m_xBuilder
->weld_link_button("linkbutton_bugs"))
52 , mxUserProfileLink(m_xBuilder
->weld_link_button("linkbutton_profile"))
53 , mxBtnCreateZip(m_xBuilder
->weld_button("btn_create_zip"))
55 m_xDialog
->set_centered_on_parent(false);
56 mxRadioRestore
->connect_toggled(LINK(this, SafeModeDialog
, RadioBtnHdl
));
57 mxRadioConfigure
->connect_toggled(LINK(this, SafeModeDialog
, RadioBtnHdl
));
58 mxRadioExtensions
->connect_toggled(LINK(this, SafeModeDialog
, RadioBtnHdl
));
59 mxRadioReset
->connect_toggled(LINK(this, SafeModeDialog
, RadioBtnHdl
));
61 mxBtnContinue
->connect_clicked(LINK(this, SafeModeDialog
, DialogBtnHdl
));
62 mxBtnRestart
->connect_clicked(LINK(this, SafeModeDialog
, DialogBtnHdl
));
63 mxBtnApply
->connect_clicked(LINK(this, SafeModeDialog
, DialogBtnHdl
));
65 mxCBCheckProfilesafeConfig
->connect_toggled(LINK(this, SafeModeDialog
, CheckBoxHdl
));
66 mxCBCheckProfilesafeExtensions
->connect_toggled(LINK(this, SafeModeDialog
, CheckBoxHdl
));
67 mxCBDisableAllExtensions
->connect_toggled(LINK(this, SafeModeDialog
, CheckBoxHdl
));
68 mxCBDeinstallUserExtensions
->connect_toggled(LINK(this, SafeModeDialog
, CheckBoxHdl
));
69 mxCBResetSharedExtensions
->connect_toggled(LINK(this, SafeModeDialog
, CheckBoxHdl
));
70 mxCBResetBundledExtensions
->connect_toggled(LINK(this, SafeModeDialog
, CheckBoxHdl
));
71 mxCBDisableHWAcceleration
->connect_toggled(LINK(this, SafeModeDialog
, CheckBoxHdl
));
72 mxCBResetCustomizations
->connect_toggled(LINK(this, SafeModeDialog
, CheckBoxHdl
));
73 mxCBResetWholeUserProfile
->connect_toggled(LINK(this, SafeModeDialog
, CheckBoxHdl
));
75 mxBtnCreateZip
->connect_clicked(LINK(this, SafeModeDialog
, CreateZipBtnHdl
));
77 // Disable restart btn until some checkbox is active
78 mxBtnApply
->set_sensitive(false);
80 // Check the first radio button and call its handler,
81 // it'll disable the relevant parts
82 mxRadioRestore
->set_active(true);
83 RadioBtnHdl(*mxRadioRestore
);
85 // Set URL for help button (module=safemode)
86 OUString
sURL(officecfg::Office::Common::Menus::SendFeedbackURL::get() //officecfg/registry/data/org/openoffice/Office/Common.xcu => https://hub.libreoffice.org/send-feedback/
87 + "?LOversion=" + utl::ConfigManager::getAboutBoxProductVersion() +
88 "&LOlocale=" + utl::ConfigManager::getUILocale() + "&LOmodule=safemode");
89 mxBugLink
->set_uri(sURL
);
91 mxUserProfileLink
->set_uri(comphelper::BackupFileHelper::getUserProfileURL());
94 SafeModeDialog::~SafeModeDialog()
98 void SafeModeDialog::enableDisableWidgets()
100 mxCBCheckProfilesafeConfig
->set_sensitive(maBackupFileHelper
.isPopPossible());
101 mxCBCheckProfilesafeExtensions
->set_sensitive(maBackupFileHelper
.isPopPossibleExtensionInfo());
102 mxCBDisableAllExtensions
->set_sensitive(comphelper::BackupFileHelper::isTryDisableAllExtensionsPossible());
103 mxCBDeinstallUserExtensions
->set_sensitive(comphelper::BackupFileHelper::isTryDeinstallUserExtensionsPossible());
104 mxCBResetSharedExtensions
->set_sensitive(comphelper::BackupFileHelper::isTryResetSharedExtensionsPossible());
105 mxCBResetBundledExtensions
->set_sensitive(comphelper::BackupFileHelper::isTryResetBundledExtensionsPossible());
106 mxCBResetCustomizations
->set_sensitive(comphelper::BackupFileHelper::isTryResetCustomizationsPossible());
108 // no disable of mxCBResetWholeUserProfile, always possible (as last choice)
111 short SafeModeDialog::run()
113 short nRet
= weld::GenericDialogController::run();
114 // Remove the safe mode flag before exiting this dialog
115 sfx2::SafeMode::removeFlag();
119 void SafeModeDialog::applyChanges()
122 if (mxRadioRestore
->get_active())
124 if (mxCBCheckProfilesafeConfig
->get_active())
126 // reset UserConfiguration to last known working state
127 // ProfileSafeMode/BackupFileHelper
128 maBackupFileHelper
.tryPop();
131 if (mxCBCheckProfilesafeExtensions
->get_active())
133 // reset State of installed Extensions to last known working state
134 // ProfileSafeMode/BackupFileHelper
135 maBackupFileHelper
.tryPopExtensionInfo();
140 if (mxRadioConfigure
->get_active())
142 if (mxCBDisableAllExtensions
->get_active())
144 // Disable all extensions
145 comphelper::BackupFileHelper::tryDisableAllExtensions();
148 if (mxCBDisableHWAcceleration
->get_active())
150 comphelper::BackupFileHelper::tryDisableHWAcceleration();
155 if (mxRadioExtensions
->get_active())
157 if (mxCBDeinstallUserExtensions
->get_active())
159 // Deinstall all User Extensions (installed for User only)
160 comphelper::BackupFileHelper::tryDeinstallUserExtensions();
163 if (mxCBResetSharedExtensions
->get_active())
165 // Reset shared Extensions
166 comphelper::BackupFileHelper::tryResetSharedExtensions();
168 if (mxCBResetBundledExtensions
->get_active())
170 // Reset bundled Extensions
171 comphelper::BackupFileHelper::tryResetBundledExtensions();
176 if (mxRadioReset
->get_active())
178 if (mxCBResetCustomizations
->get_active())
180 // Reset customizations (Settings and UserInterface modifications)
181 comphelper::BackupFileHelper::tryResetCustomizations();
184 if (mxCBResetWholeUserProfile
->get_active())
186 // Reset the whole UserProfile
187 comphelper::BackupFileHelper::tryResetUserProfile();
192 css::task::OfficeRestartManager::get(comphelper::getProcessComponentContext())->requestRestart(
193 css::uno::Reference
< css::task::XInteractionHandler
>());
196 IMPL_LINK(SafeModeDialog
, RadioBtnHdl
, weld::Toggleable
&, rButton
, void)
198 if (!rButton
.get_active())
200 if (mxRadioRestore
->get_active())
202 // Enable the currently selected box
203 mxBoxRestore
->set_sensitive(true);
204 // Make sure only possible choices are active
205 enableDisableWidgets();
206 // Disable the unselected boxes
207 mxBoxReset
->set_sensitive(false);
208 mxBoxConfigure
->set_sensitive(false);
209 mxBoxDeinstall
->set_sensitive(false);
211 else if (mxRadioConfigure
->get_active())
213 // Enable the currently selected box
214 mxBoxConfigure
->set_sensitive(true);
215 // Make sure only possible choices are active
216 enableDisableWidgets();
217 // Disable the unselected boxes
218 mxBoxRestore
->set_sensitive(false);
219 mxBoxReset
->set_sensitive(false);
220 mxBoxDeinstall
->set_sensitive(false);
223 else if (mxRadioExtensions
->get_active())
225 // Enable the currently selected box
226 mxBoxDeinstall
->set_sensitive(true);
227 // Make sure only possible choices are active
228 enableDisableWidgets();
229 // Disable the unselected boxes
230 mxBoxRestore
->set_sensitive(false);
231 mxBoxConfigure
->set_sensitive(false);
232 mxBoxReset
->set_sensitive(false);
234 else if (mxRadioReset
->get_active())
236 // Enable the currently selected box
237 mxBoxReset
->set_sensitive(true);
238 // Make sure only possible choices are active
239 enableDisableWidgets();
240 // Disable the unselected boxes
241 mxBoxConfigure
->set_sensitive(false);
242 mxBoxRestore
->set_sensitive(false);
243 mxBoxDeinstall
->set_sensitive(false);
247 IMPL_LINK(SafeModeDialog
, DialogBtnHdl
, weld::Button
&, rBtn
, void)
249 if (&rBtn
== mxBtnContinue
.get())
251 m_xDialog
->response(RET_CLOSE
);
253 else if (&rBtn
== mxBtnRestart
.get())
255 sfx2::SafeMode::putRestartFlag();
256 m_xDialog
->response(RET_CLOSE
);
257 uno::Reference
< uno::XComponentContext
> xContext
= comphelper::getProcessComponentContext();
258 css::task::OfficeRestartManager::get(xContext
)->requestRestart(
259 css::uno::Reference
< css::task::XInteractionHandler
>());
261 else if (&rBtn
== mxBtnApply
.get())
263 sfx2::SafeMode::putRestartFlag();
264 m_xDialog
->response(RET_CLOSE
);
269 IMPL_LINK(SafeModeDialog
, CreateZipBtnHdl
, weld::Button
&, /*rBtn*/, void)
271 const OUString
zipFileURL(comphelper::BackupFileHelper::getUserProfileURL() + "/libreoffice-profile.zip");
272 osl::File::remove(zipFileURL
); // Remove previous exports
275 utl::ZipPackageHelper
aZipHelper(comphelper::getProcessComponentContext(), zipFileURL
);
276 aZipHelper
.addFolderWithContent(aZipHelper
.getRootFolder(), comphelper::BackupFileHelper::getUserProfileWorkURL());
277 aZipHelper
.savePackage();
279 catch (const uno::Exception
&)
281 std::unique_ptr
<weld::MessageDialog
> xBox(Application::CreateMessageDialog(m_xDialog
.get(),
282 VclMessageType::Warning
, VclButtonsType::Ok
,
283 SvxResId(RID_SVXSTR_SAFEMODE_ZIP_FAILURE
)));
288 FileExportedDialog
aDialog(m_xDialog
.get(), SvxResId(RID_SVXSTR_SAFEMODE_USER_PROFILE_EXPORTED
));
292 IMPL_LINK(SafeModeDialog
, CheckBoxHdl
, weld::Toggleable
&, /*pCheckBox*/, void)
295 mxCBCheckProfilesafeConfig
->get_active() ||
296 mxCBCheckProfilesafeExtensions
->get_active() ||
297 mxCBDisableAllExtensions
->get_active() ||
298 mxCBDeinstallUserExtensions
->get_active() ||
299 mxCBResetSharedExtensions
->get_active() ||
300 mxCBResetBundledExtensions
->get_active() ||
301 mxCBDisableHWAcceleration
->get_active() ||
302 mxCBResetCustomizations
->get_active() ||
303 mxCBResetWholeUserProfile
->get_active());
305 mxBtnApply
->set_sensitive(bEnable
);
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */