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_clicked(LINK(this, SafeModeDialog, RadioBtnHdl));
61  mxRadioConfigure->connect_clicked(LINK(this, SafeModeDialog, RadioBtnHdl));
62  mxRadioExtensions->connect_clicked(LINK(this, SafeModeDialog, RadioBtnHdl));
63  mxRadioReset->connect_clicked(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::Button&, rBtn, void)
200 {
201  if (&rBtn == mxRadioRestore.get())
202  {
203  // Enable the currently selected box
204  mxBoxRestore->set_sensitive(true);
205  // Make sure only possible choices are active
206  enableDisableWidgets();
207  // Disable the unselected boxes
208  mxBoxReset->set_sensitive(false);
209  mxBoxConfigure->set_sensitive(false);
210  mxBoxDeinstall->set_sensitive(false);
211  }
212  else if (&rBtn == mxRadioConfigure.get())
213  {
214  // Enable the currently selected box
215  mxBoxConfigure->set_sensitive(true);
216  // Make sure only possible choices are active
217  enableDisableWidgets();
218  // Disable the unselected boxes
219  mxBoxRestore->set_sensitive(false);
220  mxBoxReset->set_sensitive(false);
221  mxBoxDeinstall->set_sensitive(false);
222 
223  }
224  else if (&rBtn == mxRadioExtensions.get())
225  {
226  // Enable the currently selected box
227  mxBoxDeinstall->set_sensitive(true);
228  // Make sure only possible choices are active
229  enableDisableWidgets();
230  // Disable the unselected boxes
231  mxBoxRestore->set_sensitive(false);
232  mxBoxConfigure->set_sensitive(false);
233  mxBoxReset->set_sensitive(false);
234  }
235  else if (&rBtn == mxRadioReset.get())
236  {
237  // Enable the currently selected box
238  mxBoxReset->set_sensitive(true);
239  // Make sure only possible choices are active
240  enableDisableWidgets();
241  // Disable the unselected boxes
242  mxBoxConfigure->set_sensitive(false);
243  mxBoxRestore->set_sensitive(false);
244  mxBoxDeinstall->set_sensitive(false);
245  }
246 }
247 
248 IMPL_LINK(SafeModeDialog, DialogBtnHdl, weld::Button&, rBtn, void)
249 {
250  if (&rBtn == mxBtnContinue.get())
251  {
252  m_xDialog->response(RET_CLOSE);
253  }
254  else if (&rBtn == mxBtnRestart.get())
255  {
257  m_xDialog->response(RET_CLOSE);
258  uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
259  css::task::OfficeRestartManager::get(xContext)->requestRestart(
260  css::uno::Reference< css::task::XInteractionHandler >());
261  }
262  else if (&rBtn == mxBtnApply.get())
263  {
265  m_xDialog->response(RET_CLOSE);
266  applyChanges();
267  }
268 }
269 
270 namespace {
271  class ProfileExportedDialog : public weld::GenericDialogController
272  {
273  private:
274  std::unique_ptr<weld::Button> m_xButton;
275 
276  DECL_LINK(OpenHdl, weld::Button&, void);
277  public:
278  explicit ProfileExportedDialog(weld::Window* pParent);
279  };
280 
281  ProfileExportedDialog::ProfileExportedDialog(weld::Window* pParent)
282  : GenericDialogController(pParent, "svx/ui/profileexporteddialog.ui", "ProfileExportedDialog")
283  , m_xButton(m_xBuilder->weld_button("ok"))
284  {
285  m_xButton->connect_clicked(LINK(this, ProfileExportedDialog, OpenHdl));
286  }
287 
288  IMPL_LINK_NOARG(ProfileExportedDialog, OpenHdl, weld::Button&, void)
289  {
291  css::uno::Reference< css::system::XSystemShellExecute > exec(
292  css::system::SystemShellExecute::create(comphelper::getProcessComponentContext()));
293  try {
294  exec->execute(uri, OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY);
295  } catch (const css::uno::Exception &) {
296  TOOLS_WARN_EXCEPTION("svx.dialog", "opening <" << uri << "> failed:");
297  }
298  m_xDialog->response(RET_OK);
299  }
300 }
301 
302 IMPL_LINK(SafeModeDialog, CreateZipBtnHdl, weld::Button&, /*rBtn*/, void)
303 {
304  const OUString zipFileName("libreoffice-profile.zip");
305  const OUString zipFileURL(comphelper::BackupFileHelper::getUserProfileURL() + "/" + zipFileName);
306  osl::File::remove(zipFileURL); // Remove previous exports
307  try
308  {
311  aZipHelper.savePackage();
312  }
313  catch (const uno::Exception &)
314  {
315  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
316  VclMessageType::Warning, VclButtonsType::Ok,
317  SvxResId(RID_SVXSTR_SAFEMODE_ZIP_FAILURE)));
318  xBox->run();
319  return;
320  }
321 
322  ProfileExportedDialog aDialog(m_xDialog.get());
323  aDialog.run();
324 }
325 
326 IMPL_LINK(SafeModeDialog, CheckBoxHdl, weld::ToggleButton&, /*pCheckBox*/, void)
327 {
328  const bool bEnable(
329  mxCBCheckProfilesafeConfig->get_active() ||
330  mxCBCheckProfilesafeExtensions->get_active() ||
331  mxCBDisableAllExtensions->get_active() ||
332  mxCBDeinstallUserExtensions->get_active() ||
333  mxCBResetSharedExtensions->get_active() ||
334  mxCBResetBundledExtensions->get_active() ||
335  mxCBDisableHWAcceleration->get_active() ||
336  mxCBResetCustomizations->get_active() ||
337  mxCBResetWholeUserProfile->get_active());
338 
339  mxBtnApply->set_sensitive(bEnable);
340 }
341 
342 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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()
void addFolderWithContent(css::uno::Reference< css::uno::XInterface > const &xRootFolder, const OUString &rDirURL)
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
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
static bool putRestartFlag()
std::unique_ptr< weld::LinkButton > mxUserProfileLink
virtual ~SafeModeDialog() override
std::unique_ptr< weld::CheckButton > mxCBDeinstallUserExtensions
css::uno::Reference< css::uno::XInterface > & getRootFolder()
#define TOOLS_WARN_EXCEPTION(area, stream)
IMPL_LINK(SafeModeDialog, RadioBtnHdl, weld::Button &, rBtn, void)
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()
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage)
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 void tryResetCustomizations()