LibreOffice Module svx (master) 1
SafeModeDialog.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10#include "SafeModeDialog.hxx"
11
12#include <osl/file.hxx>
13#include <sfx2/safemode.hxx>
14#include <vcl/svapp.hxx>
15#include <vcl/weld.hxx>
19#include <svx/dialmgr.hxx>
20#include <svx/strings.hrc>
22#include <officecfg/Office/Common.hxx>
23
24#include <com/sun/star/task/OfficeRestartManager.hpp>
25#include <com/sun/star/task/XInteractionHandler.hpp>
26
27using namespace css;
28
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"))
54{
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));
60
61 mxBtnContinue->connect_clicked(LINK(this, SafeModeDialog, DialogBtnHdl));
62 mxBtnRestart->connect_clicked(LINK(this, SafeModeDialog, DialogBtnHdl));
63 mxBtnApply->connect_clicked(LINK(this, SafeModeDialog, DialogBtnHdl));
64
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));
74
75 mxBtnCreateZip->connect_clicked(LINK(this, SafeModeDialog, CreateZipBtnHdl));
76
77 // Disable restart btn until some checkbox is active
78 mxBtnApply->set_sensitive(false);
79
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);
84
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/
88 "&LOlocale=" + utl::ConfigManager::getUILocale() + "&LOmodule=safemode");
89 mxBugLink->set_uri(sURL);
90
92}
93
95{
96}
97
99{
107
108 // no disable of mxCBResetWholeUserProfile, always possible (as last choice)
109}
110
112{
114 // Remove the safe mode flag before exiting this dialog
116 return nRet;
117}
118
120{
121 // Restore
122 if (mxRadioRestore->get_active())
123 {
124 if (mxCBCheckProfilesafeConfig->get_active())
125 {
126 // reset UserConfiguration to last known working state
127 // ProfileSafeMode/BackupFileHelper
129 }
130
131 if (mxCBCheckProfilesafeExtensions->get_active())
132 {
133 // reset State of installed Extensions to last known working state
134 // ProfileSafeMode/BackupFileHelper
136 }
137 }
138
139 // Configure
140 if (mxRadioConfigure->get_active())
141 {
142 if (mxCBDisableAllExtensions->get_active())
143 {
144 // Disable all extensions
146 }
147
148 if (mxCBDisableHWAcceleration->get_active())
149 {
151 }
152 }
153
154 // Deinstall
155 if (mxRadioExtensions->get_active())
156 {
157 if (mxCBDeinstallUserExtensions->get_active())
158 {
159 // Deinstall all User Extensions (installed for User only)
161 }
162
163 if (mxCBResetSharedExtensions->get_active())
164 {
165 // Reset shared Extensions
167 }
168 if (mxCBResetBundledExtensions->get_active())
169 {
170 // Reset bundled Extensions
172 }
173 }
174
175 // Reset
176 if (mxRadioReset->get_active())
177 {
178 if (mxCBResetCustomizations->get_active())
179 {
180 // Reset customizations (Settings and UserInterface modifications)
182 }
183
184 if (mxCBResetWholeUserProfile->get_active())
185 {
186 // Reset the whole UserProfile
188 }
189 }
190
191 // finally, restart
192 css::task::OfficeRestartManager::get(comphelper::getProcessComponentContext())->requestRestart(
193 css::uno::Reference< css::task::XInteractionHandler >());
194}
195
196IMPL_LINK(SafeModeDialog, RadioBtnHdl, weld::Toggleable&, rButton, void)
197{
198 if (!rButton.get_active())
199 return;
200 if (mxRadioRestore->get_active())
201 {
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);
210 }
211 else if (mxRadioConfigure->get_active())
212 {
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);
221
222 }
223 else if (mxRadioExtensions->get_active())
224 {
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);
233 }
234 else if (mxRadioReset->get_active())
235 {
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);
244 }
245}
246
247IMPL_LINK(SafeModeDialog, DialogBtnHdl, weld::Button&, rBtn, void)
248{
249 if (&rBtn == mxBtnContinue.get())
250 {
251 m_xDialog->response(RET_CLOSE);
252 }
253 else if (&rBtn == mxBtnRestart.get())
254 {
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 >());
260 }
261 else if (&rBtn == mxBtnApply.get())
262 {
264 m_xDialog->response(RET_CLOSE);
265 applyChanges();
266 }
267}
268
269IMPL_LINK(SafeModeDialog, CreateZipBtnHdl, weld::Button&, /*rBtn*/, void)
270{
271 const OUString zipFileURL(comphelper::BackupFileHelper::getUserProfileURL() + "/libreoffice-profile.zip");
272 osl::File::remove(zipFileURL); // Remove previous exports
273 try
274 {
277 aZipHelper.savePackage();
278 }
279 catch (const uno::Exception &)
280 {
281 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
282 VclMessageType::Warning, VclButtonsType::Ok,
283 SvxResId(RID_SVXSTR_SAFEMODE_ZIP_FAILURE)));
284 xBox->run();
285 return;
286 }
287
288 FileExportedDialog aDialog(m_xDialog.get(), SvxResId(RID_SVXSTR_SAFEMODE_USER_PROFILE_EXPORTED));
289 aDialog.run();
290}
291
292IMPL_LINK(SafeModeDialog, CheckBoxHdl, weld::Toggleable&, /*pCheckBox*/, void)
293{
294 const bool bEnable(
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());
304
305 mxBtnApply->set_sensitive(bEnable);
306}
307
308/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPL_LINK(SafeModeDialog, RadioBtnHdl, weld::Toggleable &, rButton, void)
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
std::unique_ptr< weld::RadioButton > mxRadioConfigure
std::unique_ptr< weld::Button > mxBtnContinue
std::unique_ptr< weld::Button > mxBtnApply
SafeModeDialog(weld::Window *pParent)
std::unique_ptr< weld::CheckButton > mxCBResetWholeUserProfile
std::unique_ptr< weld::CheckButton > mxCBDeinstallUserExtensions
std::unique_ptr< weld::CheckButton > mxCBResetCustomizations
std::unique_ptr< weld::CheckButton > mxCBCheckProfilesafeConfig
std::unique_ptr< weld::LinkButton > mxUserProfileLink
std::unique_ptr< weld::CheckButton > mxCBResetBundledExtensions
std::unique_ptr< weld::RadioButton > mxRadioRestore
virtual ~SafeModeDialog() override
virtual short run() override
std::unique_ptr< weld::LinkButton > mxBugLink
std::unique_ptr< weld::RadioButton > mxRadioExtensions
comphelper::BackupFileHelper maBackupFileHelper
std::unique_ptr< weld::CheckButton > mxCBCheckProfilesafeExtensions
std::unique_ptr< weld::Button > mxBtnCreateZip
std::unique_ptr< weld::Button > mxBtnRestart
std::unique_ptr< weld::RadioButton > mxRadioReset
void enableDisableWidgets()
std::unique_ptr< weld::CheckButton > mxCBDisableHWAcceleration
std::unique_ptr< weld::CheckButton > mxCBDisableAllExtensions
std::unique_ptr< weld::CheckButton > mxCBResetSharedExtensions
static void tryResetSharedExtensions()
static void tryResetBundledExtensions()
static bool isTryResetCustomizationsPossible()
static const OUString & getUserProfileWorkURL()
static bool isTryDisableAllExtensionsPossible()
static bool isTryResetBundledExtensionsPossible()
static void tryDisableHWAcceleration()
static void tryDisableAllExtensions()
bool isPopPossibleExtensionInfo() const
static void tryDeinstallUserExtensions()
static void tryResetUserProfile()
static bool isTryResetSharedExtensionsPossible()
static const OUString & getUserProfileURL()
static bool isTryDeinstallUserExtensionsPossible()
static void tryResetCustomizations()
static bool putRestartFlag()
static bool removeFlag()
static OUString getUILocale()
static OUString getAboutBoxProductVersion()
void addFolderWithContent(css::uno::Reference< css::uno::XInterface > const &xRootFolder, const OUString &rDirURL)
css::uno::Reference< css::uno::XInterface > & getRootFolder()
virtual short run()
std::shared_ptr< weld::Dialog > m_xDialog
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
Reference< XComponentContext > getProcessComponentContext()
RET_CLOSE