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 <tools/diagnose_ex.h>
15 #include <vcl/svapp.hxx>
16 #include <vcl/weld.hxx>
19 #include <unotools/configmgr.hxx>
20 #include <svx/dialmgr.hxx>
21 #include <svx/strings.hrc>
22 
23 #include <com/sun/star/task/OfficeRestartManager.hpp>
24 #include <com/sun/star/task/XInteractionHandler.hpp>
25 #include <com/sun/star/system/XSystemShellExecute.hpp>
26 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
27 #include <com/sun/star/system/SystemShellExecute.hpp>
28 
29 using namespace css;
30 
32  : GenericDialogController(pParent, "svx/ui/safemodedialog.ui", "SafeModeDialog")
33  , mxBtnContinue(m_xBuilder->weld_button("btn_continue"))
34  , mxBtnRestart(m_xBuilder->weld_button("btn_restart"))
35  , mxBtnApply(m_xBuilder->weld_button("btn_apply"))
36  , mxBoxRestore(m_xBuilder->weld_container("group_restore"))
37  , mxBoxConfigure(m_xBuilder->weld_container("group_configure"))
38  , mxBoxDeinstall(m_xBuilder->weld_container("group_deinstall"))
39  , mxBoxReset(m_xBuilder->weld_container("group_reset"))
40  , mxRadioRestore(m_xBuilder->weld_radio_button("radio_restore"))
41  , mxRadioConfigure(m_xBuilder->weld_radio_button("radio_configure"))
42  , mxRadioExtensions(m_xBuilder->weld_radio_button("radio_extensions"))
43  , mxRadioReset(m_xBuilder->weld_radio_button("radio_reset"))
44  , mxCBCheckProfilesafeConfig(m_xBuilder->weld_check_button("check_profilesafe_config"))
45  , mxCBCheckProfilesafeExtensions(m_xBuilder->weld_check_button("check_profilesafe_extensions"))
46  , mxCBDisableAllExtensions(m_xBuilder->weld_check_button("check_disable_all_extensions"))
47  , mxCBDeinstallUserExtensions(m_xBuilder->weld_check_button("check_deinstall_user_extensions"))
48  , mxCBResetSharedExtensions(m_xBuilder->weld_check_button("check_reset_shared_extensions"))
49  , mxCBResetBundledExtensions(m_xBuilder->weld_check_button("check_reset_bundled_extensions"))
50  , mxCBDisableHWAcceleration(m_xBuilder->weld_check_button("check_disable_hw_acceleration"))
51  , mxCBResetCustomizations(m_xBuilder->weld_check_button("check_reset_customizations"))
52  , mxCBResetWholeUserProfile(m_xBuilder->weld_check_button("check_reset_whole_userprofile"))
53  , mxBugLink(m_xBuilder->weld_link_button("linkbutton_bugs"))
54  , mxUserProfileLink(m_xBuilder->weld_link_button("linkbutton_profile"))
55  , mxBtnCreateZip(m_xBuilder->weld_button("btn_create_zip"))
56  , mxExpander(m_xBuilder->weld_expander("expander"))
57  , maBackupFileHelper()
58 {
59  m_xDialog->set_centered_on_parent(false);
60  mxRadioRestore->connect_toggled(LINK(this, SafeModeDialog, RadioBtnHdl));
61  mxRadioConfigure->connect_toggled(LINK(this, SafeModeDialog, RadioBtnHdl));
62  mxRadioExtensions->connect_toggled(LINK(this, SafeModeDialog, RadioBtnHdl));
63  mxRadioReset->connect_toggled(LINK(this, SafeModeDialog, RadioBtnHdl));
64 
65  mxBtnContinue->connect_clicked(LINK(this, SafeModeDialog, DialogBtnHdl));
66  mxBtnRestart->connect_clicked(LINK(this, SafeModeDialog, DialogBtnHdl));
67  mxBtnApply->connect_clicked(LINK(this, SafeModeDialog, DialogBtnHdl));
68 
69  mxCBCheckProfilesafeConfig->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
70  mxCBCheckProfilesafeExtensions->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
71  mxCBDisableAllExtensions->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
72  mxCBDeinstallUserExtensions->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
73  mxCBResetSharedExtensions->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
74  mxCBResetBundledExtensions->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
75  mxCBDisableHWAcceleration->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
76  mxCBResetCustomizations->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
77  mxCBResetWholeUserProfile->connect_toggled(LINK(this, SafeModeDialog, CheckBoxHdl));
78 
79  mxBtnCreateZip->connect_clicked(LINK(this, SafeModeDialog, CreateZipBtnHdl));
80 
81  // Disable restart btn until some checkbox is active
82  mxBtnApply->set_sensitive(false);
83 
84  // Check the first radio button and call its handler,
85  // it'll disable the relevant parts
86  mxRadioRestore->set_active(true);
87  RadioBtnHdl(*mxRadioRestore);
88 
89  // Set URL for help button (module=safemode)
90  OUString sURL("http://hub.libreoffice.org/send-feedback/?LOversion=" + utl::ConfigManager::getAboutBoxProductVersion() +
91  "&LOlocale=" + utl::ConfigManager::getUILocale() + "&LOmodule=safemode");
92  mxBugLink->set_uri(sURL);
93 
95 }
96 
98 {
99 }
100 
102 {
110 
111  // no disable of mxCBResetWholeUserProfile, always possible (as last choice)
112 }
113 
115 {
116  short nRet = weld::GenericDialogController::run();
117  // Remove the safe mode flag before exiting this dialog
119  return nRet;
120 }
121 
123 {
124  // Restore
125  if (mxRadioRestore->get_active())
126  {
127  if (mxCBCheckProfilesafeConfig->get_active())
128  {
129  // reset UserConfiguration to last known working state
130  // ProfileSafeMode/BackupFileHelper
132  }
133 
134  if (mxCBCheckProfilesafeExtensions->get_active())
135  {
136  // reset State of installed Extensions to last known working state
137  // ProfileSafeMode/BackupFileHelper
139  }
140  }
141 
142  // Configure
143  if (mxRadioConfigure->get_active())
144  {
145  if (mxCBDisableAllExtensions->get_active())
146  {
147  // Disable all extensions
149  }
150 
151  if (mxCBDisableHWAcceleration->get_active())
152  {
154  }
155  }
156 
157  // Deinstall
158  if (mxRadioExtensions->get_active())
159  {
160  if (mxCBDeinstallUserExtensions->get_active())
161  {
162  // Deinstall all User Extensions (installed for User only)
164  }
165 
166  if (mxCBResetSharedExtensions->get_active())
167  {
168  // Reset shared Extensions
170  }
171  if (mxCBResetBundledExtensions->get_active())
172  {
173  // Reset bundled Extensions
175  }
176  }
177 
178  // Reset
179  if (mxRadioReset->get_active())
180  {
181  if (mxCBResetCustomizations->get_active())
182  {
183  // Reset customizations (Settings and UserInterface modifications)
185  }
186 
187  if (mxCBResetWholeUserProfile->get_active())
188  {
189  // Reset the whole UserProfile
191  }
192  }
193 
194  // finally, restart
195  css::task::OfficeRestartManager::get(comphelper::getProcessComponentContext())->requestRestart(
196  css::uno::Reference< css::task::XInteractionHandler >());
197 }
198 
199 IMPL_LINK(SafeModeDialog, RadioBtnHdl, weld::Toggleable&, rButton, void)
200 {
201  if (!rButton.get_active())
202  return;
203  if (mxRadioRestore->get_active())
204  {
205  // Enable the currently selected box
206  mxBoxRestore->set_sensitive(true);
207  // Make sure only possible choices are active
208  enableDisableWidgets();
209  // Disable the unselected boxes
210  mxBoxReset->set_sensitive(false);
211  mxBoxConfigure->set_sensitive(false);
212  mxBoxDeinstall->set_sensitive(false);
213  }
214  else if (mxRadioConfigure->get_active())
215  {
216  // Enable the currently selected box
217  mxBoxConfigure->set_sensitive(true);
218  // Make sure only possible choices are active
219  enableDisableWidgets();
220  // Disable the unselected boxes
221  mxBoxRestore->set_sensitive(false);
222  mxBoxReset->set_sensitive(false);
223  mxBoxDeinstall->set_sensitive(false);
224 
225  }
226  else if (mxRadioExtensions->get_active())
227  {
228  // Enable the currently selected box
229  mxBoxDeinstall->set_sensitive(true);
230  // Make sure only possible choices are active
231  enableDisableWidgets();
232  // Disable the unselected boxes
233  mxBoxRestore->set_sensitive(false);
234  mxBoxConfigure->set_sensitive(false);
235  mxBoxReset->set_sensitive(false);
236  }
237  else if (mxRadioReset->get_active())
238  {
239  // Enable the currently selected box
240  mxBoxReset->set_sensitive(true);
241  // Make sure only possible choices are active
242  enableDisableWidgets();
243  // Disable the unselected boxes
244  mxBoxConfigure->set_sensitive(false);
245  mxBoxRestore->set_sensitive(false);
246  mxBoxDeinstall->set_sensitive(false);
247  }
248 }
249 
250 IMPL_LINK(SafeModeDialog, DialogBtnHdl, weld::Button&, rBtn, void)
251 {
252  if (&rBtn == mxBtnContinue.get())
253  {
254  m_xDialog->response(RET_CLOSE);
255  }
256  else if (&rBtn == mxBtnRestart.get())
257  {
259  m_xDialog->response(RET_CLOSE);
260  uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
261  css::task::OfficeRestartManager::get(xContext)->requestRestart(
262  css::uno::Reference< css::task::XInteractionHandler >());
263  }
264  else if (&rBtn == mxBtnApply.get())
265  {
267  m_xDialog->response(RET_CLOSE);
268  applyChanges();
269  }
270 }
271 
272 namespace {
273  class ProfileExportedDialog : public weld::GenericDialogController
274  {
275  private:
276  std::unique_ptr<weld::Button> m_xButton;
277 
278  DECL_LINK(OpenHdl, weld::Button&, void);
279  public:
280  explicit ProfileExportedDialog(weld::Window* pParent);
281  };
282 
283  ProfileExportedDialog::ProfileExportedDialog(weld::Window* pParent)
284  : GenericDialogController(pParent, "svx/ui/profileexporteddialog.ui", "ProfileExportedDialog")
285  , m_xButton(m_xBuilder->weld_button("ok"))
286  {
287  m_xButton->connect_clicked(LINK(this, ProfileExportedDialog, OpenHdl));
288  }
289 
290  IMPL_LINK_NOARG(ProfileExportedDialog, OpenHdl, weld::Button&, void)
291  {
293  css::uno::Reference< css::system::XSystemShellExecute > exec(
294  css::system::SystemShellExecute::create(comphelper::getProcessComponentContext()));
295  try {
296  exec->execute(uri, OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY);
297  } catch (const css::uno::Exception &) {
298  TOOLS_WARN_EXCEPTION("svx.dialog", "opening <" << uri << "> failed:");
299  }
300  m_xDialog->response(RET_OK);
301  }
302 }
303 
304 IMPL_LINK(SafeModeDialog, CreateZipBtnHdl, weld::Button&, /*rBtn*/, void)
305 {
306  const OUString zipFileURL(comphelper::BackupFileHelper::getUserProfileURL() + "/libreoffice-profile.zip");
307  osl::File::remove(zipFileURL); // Remove previous exports
308  try
309  {
310  utl::ZipPackageHelper aZipHelper(comphelper::getProcessComponentContext(), zipFileURL);
311  aZipHelper.addFolderWithContent(aZipHelper.getRootFolder(), comphelper::BackupFileHelper::getUserProfileWorkURL());
312  aZipHelper.savePackage();
313  }
314  catch (const uno::Exception &)
315  {
316  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
317  VclMessageType::Warning, VclButtonsType::Ok,
318  SvxResId(RID_SVXSTR_SAFEMODE_ZIP_FAILURE)));
319  xBox->run();
320  return;
321  }
322 
323  ProfileExportedDialog aDialog(m_xDialog.get());
324  aDialog.run();
325 }
326 
327 IMPL_LINK(SafeModeDialog, CheckBoxHdl, weld::Toggleable&, /*pCheckBox*/, void)
328 {
329  const bool bEnable(
330  mxCBCheckProfilesafeConfig->get_active() ||
331  mxCBCheckProfilesafeExtensions->get_active() ||
332  mxCBDisableAllExtensions->get_active() ||
333  mxCBDeinstallUserExtensions->get_active() ||
334  mxCBResetSharedExtensions->get_active() ||
335  mxCBResetBundledExtensions->get_active() ||
336  mxCBDisableHWAcceleration->get_active() ||
337  mxCBResetCustomizations->get_active() ||
338  mxCBResetWholeUserProfile->get_active());
339 
340  mxBtnApply->set_sensitive(bEnable);
341 }
342 
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPL_LINK(SafeModeDialog, RadioBtnHdl, weld::Toggleable &, rButton, void)
std::shared_ptr< weld::Dialog > m_xDialog
std::unique_ptr< weld::Button > mxBtnApply
std::unique_ptr< weld::RadioButton > mxRadioConfigure
std::unique_ptr< weld::CheckButton > mxCBDisableAllExtensions
static void tryResetSharedExtensions()
std::unique_ptr< weld::Button > mxBtnContinue
static void tryDisableAllExtensions()
static bool isTryResetSharedExtensionsPossible()
std::unique_ptr< weld::CheckButton > mxCBDisableHWAcceleration
static void tryDeinstallUserExtensions()
static bool isTryDeinstallUserExtensionsPossible()
void enableDisableWidgets()
std::unique_ptr< weld::CheckButton > mxCBResetBundledExtensions
IMPL_LINK_NOARG(MaskData, ExecHdl, weld::Button &, void)
Definition: _bmpmask.cxx:300
static void tryDisableHWAcceleration()
static const OUString & getUserProfileURL()
std::unique_ptr< weld::CheckButton > mxCBResetWholeUserProfile
static bool putRestartFlag()
std::unique_ptr< weld::LinkButton > mxUserProfileLink
virtual ~SafeModeDialog() override
std::unique_ptr< weld::CheckButton > mxCBDeinstallUserExtensions
OUString SvxResId(std::string_view aId)
Definition: dialmgr.cxx:25
#define TOOLS_WARN_EXCEPTION(area, stream)
std::unique_ptr< weld::RadioButton > mxRadioRestore
std::unique_ptr< weld::Button > mxBtnRestart
static OUString getAboutBoxProductVersion()
static OUString getUILocale()
bool isPopPossibleExtensionInfo() const
std::unique_ptr< weld::CheckButton > mxCBResetSharedExtensions
SafeModeDialog(weld::Window *pParent)
static const OUString & getUserProfileWorkURL()
std::unique_ptr< weld::Button > mxBtnCreateZip
comphelper::BackupFileHelper maBackupFileHelper
RET_CLOSE
std::unique_ptr< weld::LinkButton > mxBugLink
virtual short run() override
static bool removeFlag()
Reference< XExecutableDialog > m_xDialog
virtual short run()
Reference< XComponentContext > getProcessComponentContext()
std::unique_ptr< weld::CheckButton > mxCBCheckProfilesafeConfig
static bool isTryResetBundledExtensionsPossible()
std::unique_ptr< weld::CheckButton > mxCBCheckProfilesafeExtensions
static bool isTryResetCustomizationsPossible()
std::unique_ptr< weld::RadioButton > mxRadioExtensions
static void tryResetBundledExtensions()
std::unique_ptr< weld::RadioButton > mxRadioReset
std::unique_ptr< weld::CheckButton > mxCBResetCustomizations
static void tryResetUserProfile()
static bool isTryDisableAllExtensionsPossible()
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
static void tryResetCustomizations()
exports com.sun.star. uri