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{
54 m_xDialog->set_centered_on_parent(false);
55 mxRadioRestore->connect_toggled(LINK(this, SafeModeDialog, RadioBtnHdl));
56 mxRadioConfigure->connect_toggled(LINK(this, SafeModeDialog, RadioBtnHdl));
57 mxRadioExtensions->connect_toggled(LINK(this, SafeModeDialog, RadioBtnHdl));
58 mxRadioReset->connect_toggled(LINK(this, SafeModeDialog, RadioBtnHdl));
59
60 mxBtnContinue->connect_clicked(LINK(this, SafeModeDialog, DialogBtnHdl));
61 mxBtnRestart->connect_clicked(LINK(this, SafeModeDialog, DialogBtnHdl));
62 mxBtnApply->connect_clicked(LINK(this, SafeModeDialog, DialogBtnHdl));
63
64 mxCBCheckProfilesafeConfig->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
65 mxCBCheckProfilesafeExtensions->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
66 mxCBDisableAllExtensions->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
67 mxCBDeinstallUserExtensions->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
68 mxCBResetSharedExtensions->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
69 mxCBResetBundledExtensions->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
70 mxCBDisableHWAcceleration->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
71 mxCBResetCustomizations->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
72 mxCBResetWholeUserProfile->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
73
74 mxBtnCreateZip->connect_clicked(LINK(this, SafeModeDialog, CreateZipBtnHdl));
75
76 // Disable restart btn until some checkbox is active
77 mxBtnApply->set_sensitive(false);
78
79 // Check the first radio button and call its handler,
80 // it'll disable the relevant parts
81 mxRadioRestore->set_active(true);
82 RadioBtnHdl(*mxRadioRestore);
83
84 // Set URL for help button (module=safemode)
85 OUString sURL("http://hub.libreoffice.org/send-feedback/?LOversion=" + utl::ConfigManager::getAboutBoxProductVersion() +
86 "&LOlocale=" + utl::ConfigManager::getUILocale() + "&LOmodule=safemode");
87 mxBugLink->set_uri(sURL);
88
90}
91
93{
94}
95
97{
105
106 // no disable of mxCBResetWholeUserProfile, always possible (as last choice)
107}
108
110{
112 // Remove the safe mode flag before exiting this dialog
114 return nRet;
115}
116
118{
119 // Restore
120 if (mxRadioRestore->get_active())
121 {
122 if (mxCBCheckProfilesafeConfig->get_active())
123 {
124 // reset UserConfiguration to last known working state
125 // ProfileSafeMode/BackupFileHelper
127 }
128
129 if (mxCBCheckProfilesafeExtensions->get_active())
130 {
131 // reset State of installed Extensions to last known working state
132 // ProfileSafeMode/BackupFileHelper
134 }
135 }
136
137 // Configure
138 if (mxRadioConfigure->get_active())
139 {
140 if (mxCBDisableAllExtensions->get_active())
141 {
142 // Disable all extensions
144 }
145
146 if (mxCBDisableHWAcceleration->get_active())
147 {
149 }
150 }
151
152 // Deinstall
153 if (mxRadioExtensions->get_active())
154 {
155 if (mxCBDeinstallUserExtensions->get_active())
156 {
157 // Deinstall all User Extensions (installed for User only)
159 }
160
161 if (mxCBResetSharedExtensions->get_active())
162 {
163 // Reset shared Extensions
165 }
166 if (mxCBResetBundledExtensions->get_active())
167 {
168 // Reset bundled Extensions
170 }
171 }
172
173 // Reset
174 if (mxRadioReset->get_active())
175 {
176 if (mxCBResetCustomizations->get_active())
177 {
178 // Reset customizations (Settings and UserInterface modifications)
180 }
181
182 if (mxCBResetWholeUserProfile->get_active())
183 {
184 // Reset the whole UserProfile
186 }
187 }
188
189 // finally, restart
190 css::task::OfficeRestartManager::get(comphelper::getProcessComponentContext())->requestRestart(
191 css::uno::Reference< css::task::XInteractionHandler >());
192}
193
194IMPL_LINK(SafeModeDialog, RadioBtnHdl, weld::Toggleable&, rButton, void)
195{
196 if (!rButton.get_active())
197 return;
198 if (mxRadioRestore->get_active())
199 {
200 // Enable the currently selected box
201 mxBoxRestore->set_sensitive(true);
202 // Make sure only possible choices are active
203 enableDisableWidgets();
204 // Disable the unselected boxes
205 mxBoxReset->set_sensitive(false);
206 mxBoxConfigure->set_sensitive(false);
207 mxBoxDeinstall->set_sensitive(false);
208 }
209 else if (mxRadioConfigure->get_active())
210 {
211 // Enable the currently selected box
212 mxBoxConfigure->set_sensitive(true);
213 // Make sure only possible choices are active
214 enableDisableWidgets();
215 // Disable the unselected boxes
216 mxBoxRestore->set_sensitive(false);
217 mxBoxReset->set_sensitive(false);
218 mxBoxDeinstall->set_sensitive(false);
219
220 }
221 else if (mxRadioExtensions->get_active())
222 {
223 // Enable the currently selected box
224 mxBoxDeinstall->set_sensitive(true);
225 // Make sure only possible choices are active
226 enableDisableWidgets();
227 // Disable the unselected boxes
228 mxBoxRestore->set_sensitive(false);
229 mxBoxConfigure->set_sensitive(false);
230 mxBoxReset->set_sensitive(false);
231 }
232 else if (mxRadioReset->get_active())
233 {
234 // Enable the currently selected box
235 mxBoxReset->set_sensitive(true);
236 // Make sure only possible choices are active
237 enableDisableWidgets();
238 // Disable the unselected boxes
239 mxBoxConfigure->set_sensitive(false);
240 mxBoxRestore->set_sensitive(false);
241 mxBoxDeinstall->set_sensitive(false);
242 }
243}
244
245IMPL_LINK(SafeModeDialog, DialogBtnHdl, weld::Button&, rBtn, void)
246{
247 if (&rBtn == mxBtnContinue.get())
248 {
249 m_xDialog->response(RET_CLOSE);
250 }
251 else if (&rBtn == mxBtnRestart.get())
252 {
254 m_xDialog->response(RET_CLOSE);
255 uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
256 css::task::OfficeRestartManager::get(xContext)->requestRestart(
257 css::uno::Reference< css::task::XInteractionHandler >());
258 }
259 else if (&rBtn == mxBtnApply.get())
260 {
262 m_xDialog->response(RET_CLOSE);
263 applyChanges();
264 }
265}
266
267IMPL_LINK(SafeModeDialog, CreateZipBtnHdl, weld::Button&, /*rBtn*/, void)
268{
269 const OUString zipFileURL(comphelper::BackupFileHelper::getUserProfileURL() + "/libreoffice-profile.zip");
270 osl::File::remove(zipFileURL); // Remove previous exports
271 try
272 {
275 aZipHelper.savePackage();
276 }
277 catch (const uno::Exception &)
278 {
279 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
280 VclMessageType::Warning, VclButtonsType::Ok,
281 SvxResId(RID_SVXSTR_SAFEMODE_ZIP_FAILURE)));
282 xBox->run();
283 return;
284 }
285
286 FileExportedDialog aDialog(m_xDialog.get(),"Your user profile has been exported as 'libreoffice-profile.zip'.");
287 aDialog.run();
288}
289
290IMPL_LINK(SafeModeDialog, CheckBoxHdl, weld::Toggleable&, /*pCheckBox*/, void)
291{
292 const bool bEnable(
293 mxCBCheckProfilesafeConfig->get_active() ||
294 mxCBCheckProfilesafeExtensions->get_active() ||
295 mxCBDisableAllExtensions->get_active() ||
296 mxCBDeinstallUserExtensions->get_active() ||
297 mxCBResetSharedExtensions->get_active() ||
298 mxCBResetBundledExtensions->get_active() ||
299 mxCBDisableHWAcceleration->get_active() ||
300 mxCBResetCustomizations->get_active() ||
301 mxCBResetWholeUserProfile->get_active());
302
303 mxBtnApply->set_sensitive(bEnable);
304}
305
306/* 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