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
23#include <com/sun/star/task/OfficeRestartManager.hpp>
24#include <com/sun/star/task/XInteractionHandler.hpp>
25
26using namespace css;
27
29 : GenericDialogController(pParent, "svx/ui/safemodedialog.ui", "SafeModeDialog")
30 , mxBtnContinue(m_xBuilder->weld_button("btn_continue"))
31 , mxBtnRestart(m_xBuilder->weld_button("btn_restart"))
32 , mxBtnApply(m_xBuilder->weld_button("btn_apply"))
33 , mxBoxRestore(m_xBuilder->weld_container("group_restore"))
34 , mxBoxConfigure(m_xBuilder->weld_container("group_configure"))
35 , mxBoxDeinstall(m_xBuilder->weld_container("group_deinstall"))
36 , mxBoxReset(m_xBuilder->weld_container("group_reset"))
37 , mxRadioRestore(m_xBuilder->weld_radio_button("radio_restore"))
38 , mxRadioConfigure(m_xBuilder->weld_radio_button("radio_configure"))
39 , mxRadioExtensions(m_xBuilder->weld_radio_button("radio_extensions"))
40 , mxRadioReset(m_xBuilder->weld_radio_button("radio_reset"))
41 , mxCBCheckProfilesafeConfig(m_xBuilder->weld_check_button("check_profilesafe_config"))
42 , mxCBCheckProfilesafeExtensions(m_xBuilder->weld_check_button("check_profilesafe_extensions"))
43 , mxCBDisableAllExtensions(m_xBuilder->weld_check_button("check_disable_all_extensions"))
44 , mxCBDeinstallUserExtensions(m_xBuilder->weld_check_button("check_deinstall_user_extensions"))
45 , mxCBResetSharedExtensions(m_xBuilder->weld_check_button("check_reset_shared_extensions"))
46 , mxCBResetBundledExtensions(m_xBuilder->weld_check_button("check_reset_bundled_extensions"))
47 , mxCBDisableHWAcceleration(m_xBuilder->weld_check_button("check_disable_hw_acceleration"))
48 , mxCBResetCustomizations(m_xBuilder->weld_check_button("check_reset_customizations"))
49 , mxCBResetWholeUserProfile(m_xBuilder->weld_check_button("check_reset_whole_userprofile"))
50 , mxBugLink(m_xBuilder->weld_link_button("linkbutton_bugs"))
51 , mxUserProfileLink(m_xBuilder->weld_link_button("linkbutton_profile"))
52 , mxBtnCreateZip(m_xBuilder->weld_button("btn_create_zip"))
53 , mxExpander(m_xBuilder->weld_expander("expander"))
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("http://hub.libreoffice.org/send-feedback/?LOversion=" + utl::ConfigManager::getAboutBoxProductVersion() +
87 "&LOlocale=" + utl::ConfigManager::getUILocale() + "&LOmodule=safemode");
88 mxBugLink->set_uri(sURL);
89
91}
92
94{
95}
96
98{
106
107 // no disable of mxCBResetWholeUserProfile, always possible (as last choice)
108}
109
111{
113 // Remove the safe mode flag before exiting this dialog
115 return nRet;
116}
117
119{
120 // Restore
121 if (mxRadioRestore->get_active())
122 {
123 if (mxCBCheckProfilesafeConfig->get_active())
124 {
125 // reset UserConfiguration to last known working state
126 // ProfileSafeMode/BackupFileHelper
128 }
129
130 if (mxCBCheckProfilesafeExtensions->get_active())
131 {
132 // reset State of installed Extensions to last known working state
133 // ProfileSafeMode/BackupFileHelper
135 }
136 }
137
138 // Configure
139 if (mxRadioConfigure->get_active())
140 {
141 if (mxCBDisableAllExtensions->get_active())
142 {
143 // Disable all extensions
145 }
146
147 if (mxCBDisableHWAcceleration->get_active())
148 {
150 }
151 }
152
153 // Deinstall
154 if (mxRadioExtensions->get_active())
155 {
156 if (mxCBDeinstallUserExtensions->get_active())
157 {
158 // Deinstall all User Extensions (installed for User only)
160 }
161
162 if (mxCBResetSharedExtensions->get_active())
163 {
164 // Reset shared Extensions
166 }
167 if (mxCBResetBundledExtensions->get_active())
168 {
169 // Reset bundled Extensions
171 }
172 }
173
174 // Reset
175 if (mxRadioReset->get_active())
176 {
177 if (mxCBResetCustomizations->get_active())
178 {
179 // Reset customizations (Settings and UserInterface modifications)
181 }
182
183 if (mxCBResetWholeUserProfile->get_active())
184 {
185 // Reset the whole UserProfile
187 }
188 }
189
190 // finally, restart
191 css::task::OfficeRestartManager::get(comphelper::getProcessComponentContext())->requestRestart(
192 css::uno::Reference< css::task::XInteractionHandler >());
193}
194
195IMPL_LINK(SafeModeDialog, RadioBtnHdl, weld::Toggleable&, rButton, void)
196{
197 if (!rButton.get_active())
198 return;
199 if (mxRadioRestore->get_active())
200 {
201 // Enable the currently selected box
202 mxBoxRestore->set_sensitive(true);
203 // Make sure only possible choices are active
204 enableDisableWidgets();
205 // Disable the unselected boxes
206 mxBoxReset->set_sensitive(false);
207 mxBoxConfigure->set_sensitive(false);
208 mxBoxDeinstall->set_sensitive(false);
209 }
210 else if (mxRadioConfigure->get_active())
211 {
212 // Enable the currently selected box
213 mxBoxConfigure->set_sensitive(true);
214 // Make sure only possible choices are active
215 enableDisableWidgets();
216 // Disable the unselected boxes
217 mxBoxRestore->set_sensitive(false);
218 mxBoxReset->set_sensitive(false);
219 mxBoxDeinstall->set_sensitive(false);
220
221 }
222 else if (mxRadioExtensions->get_active())
223 {
224 // Enable the currently selected box
225 mxBoxDeinstall->set_sensitive(true);
226 // Make sure only possible choices are active
227 enableDisableWidgets();
228 // Disable the unselected boxes
229 mxBoxRestore->set_sensitive(false);
230 mxBoxConfigure->set_sensitive(false);
231 mxBoxReset->set_sensitive(false);
232 }
233 else if (mxRadioReset->get_active())
234 {
235 // Enable the currently selected box
236 mxBoxReset->set_sensitive(true);
237 // Make sure only possible choices are active
238 enableDisableWidgets();
239 // Disable the unselected boxes
240 mxBoxConfigure->set_sensitive(false);
241 mxBoxRestore->set_sensitive(false);
242 mxBoxDeinstall->set_sensitive(false);
243 }
244}
245
246IMPL_LINK(SafeModeDialog, DialogBtnHdl, weld::Button&, rBtn, void)
247{
248 if (&rBtn == mxBtnContinue.get())
249 {
250 m_xDialog->response(RET_CLOSE);
251 }
252 else if (&rBtn == mxBtnRestart.get())
253 {
255 m_xDialog->response(RET_CLOSE);
256 uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
257 css::task::OfficeRestartManager::get(xContext)->requestRestart(
258 css::uno::Reference< css::task::XInteractionHandler >());
259 }
260 else if (&rBtn == mxBtnApply.get())
261 {
263 m_xDialog->response(RET_CLOSE);
264 applyChanges();
265 }
266}
267
268IMPL_LINK(SafeModeDialog, CreateZipBtnHdl, weld::Button&, /*rBtn*/, void)
269{
270 const OUString zipFileURL(comphelper::BackupFileHelper::getUserProfileURL() + "/libreoffice-profile.zip");
271 osl::File::remove(zipFileURL); // Remove previous exports
272 try
273 {
276 aZipHelper.savePackage();
277 }
278 catch (const uno::Exception &)
279 {
280 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
281 VclMessageType::Warning, VclButtonsType::Ok,
282 SvxResId(RID_SVXSTR_SAFEMODE_ZIP_FAILURE)));
283 xBox->run();
284 return;
285 }
286
287 FileExportedDialog aDialog(m_xDialog.get(),"Your user profile has been exported as 'libreoffice-profile.zip'.");
288 aDialog.run();
289}
290
291IMPL_LINK(SafeModeDialog, CheckBoxHdl, weld::Toggleable&, /*pCheckBox*/, void)
292{
293 const bool bEnable(
294 mxCBCheckProfilesafeConfig->get_active() ||
295 mxCBCheckProfilesafeExtensions->get_active() ||
296 mxCBDisableAllExtensions->get_active() ||
297 mxCBDeinstallUserExtensions->get_active() ||
298 mxCBResetSharedExtensions->get_active() ||
299 mxCBResetBundledExtensions->get_active() ||
300 mxCBDisableHWAcceleration->get_active() ||
301 mxCBResetCustomizations->get_active() ||
302 mxCBResetWholeUserProfile->get_active());
303
304 mxBtnApply->set_sensitive(bEnable);
305}
306
307/* 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, bool bMobile=false)
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