safemode: Add hints how to get help/report a bug

Change-Id: Ie65e9706017f5f56fa4c453aa3fdb117b201096e
Reviewed-on: https://gerrit.libreoffice.org/29961
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
diff --git a/svx/source/dialog/SafeModeDialog.cxx b/svx/source/dialog/SafeModeDialog.cxx
index a2e6ca2..d5a2e6af 100644
--- a/svx/source/dialog/SafeModeDialog.cxx
+++ b/svx/source/dialog/SafeModeDialog.cxx
@@ -12,13 +12,21 @@
#include <config_folders.h>
#include <rtl/bootstrap.hxx>
#include <osl/file.hxx>
#include <comphelper/processfactory.hxx>
#include <sfx2/safemode.hxx>
#include <vcl/svapp.hxx>
#include <vcl/layout.hxx>
#include <comphelper/anytostring.hxx>
#include <comphelper/processfactory.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <unotools/configmgr.hxx>

#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XDesktop2.hpp>
#include <com/sun/star/task/OfficeRestartManager.hpp>
#include <com/sun/star/task/XInteractionHandler.hpp>
#include <com/sun/star/system/XSystemShellExecute.hpp>
#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
#include <com/sun/star/system/SystemShellExecute.hpp>

using namespace css;

@@ -47,6 +55,8 @@ SafeModeDialog::SafeModeDialog(vcl::Window* pParent)
    get(mpCBResetCustomizations, "check_reset_customizations");
    get(mpCBResetWholeUserProfile, "check_reset_whole_userprofile");

    get(mpBugLink, "linkbutton_bugs");

    mpBtnContinue->SetClickHdl(LINK(this, SafeModeDialog, BtnHdl));
    mpBtnQuit->SetClickHdl(LINK(this, SafeModeDialog, BtnHdl));
    mpBtnRestart->SetClickHdl(LINK(this, SafeModeDialog, BtnHdl));
@@ -57,6 +67,8 @@ SafeModeDialog::SafeModeDialog(vcl::Window* pParent)
    mpCBResetCustomizations->SetToggleHdl(LINK(this, SafeModeDialog, CheckBoxHdl));
    mpCBResetWholeUserProfile->SetToggleHdl(LINK(this, SafeModeDialog, CheckBoxHdl));

    mpBugLink->SetClickHdl(LINK(this, SafeModeDialog, HandleHyperlink));

    // Disable restart btn until some checkbox is active
    mpBtnRestart->Disable();

@@ -79,6 +91,11 @@ SafeModeDialog::SafeModeDialog(vcl::Window* pParent)
    {
        mpCBResetCustomizations->Disable();
    }

    // Set URL for help button (module=safemode)
    OUString sURL("http://hub.libreoffice.org/send-feedback/?LOversion=" + utl::ConfigManager::getAboutBoxProductVersion() +
        "&LOlocale=" + utl::ConfigManager::getLocale() + "&LOmodule=safemode");
    mpBugLink->SetURL(sURL);
}

SafeModeDialog::~SafeModeDialog()
@@ -98,6 +115,8 @@ void SafeModeDialog::dispose()
    mpCBResetCustomizations.clear();
    mpCBResetWholeUserProfile.clear();

    mpBugLink.clear();

    Dialog::dispose();
}

@@ -157,6 +176,30 @@ void SafeModeDialog::applyChanges()
        css::uno::Reference< css::task::XInteractionHandler >());
}

void SafeModeDialog::openWebBrowser(const OUString & sURL, const OUString &sTitle)
{
    if ( sURL.isEmpty() ) // Nothing to do, when the URL is empty
        return;

    try
    {
        uno::Reference< system::XSystemShellExecute > xSystemShellExecute(
            system::SystemShellExecute::create(comphelper::getProcessComponentContext()));
        //throws css::lang::IllegalArgumentException, css::system::SystemShellExecuteException
        xSystemShellExecute->execute( sURL, OUString(), system::SystemShellExecuteFlags::URIS_ONLY );
    }
    catch ( const uno::Exception& )
    {
        uno::Any exc(cppu::getCaughtException());
        OUString msg(comphelper::anyToString(exc));
        const SolarMutexGuard guard;
        ScopedVclPtrInstance< MessageDialog > aErrorBox(nullptr, msg);
        aErrorBox->SetText( sTitle );
        aErrorBox->Execute();
    }
}


IMPL_LINK(SafeModeDialog, BtnHdl, Button*, pBtn, void)
{
    if (pBtn == mpBtnContinue.get())
@@ -186,4 +229,9 @@ IMPL_LINK(SafeModeDialog, CheckBoxHdl, CheckBox&, /*pCheckBox*/, void)
    mpBtnRestart->Enable(bEnable);
}

IMPL_LINK( SafeModeDialog, HandleHyperlink, FixedHyperlink&, rHyperlink, void )
{
    SafeModeDialog::openWebBrowser( rHyperlink.GetURL(), GetText() );
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/dialog/SafeModeDialog.hxx b/svx/source/dialog/SafeModeDialog.hxx
index 6f2e4af..f84f94d 100644
--- a/svx/source/dialog/SafeModeDialog.hxx
+++ b/svx/source/dialog/SafeModeDialog.hxx
@@ -15,6 +15,7 @@
#include <vcl/fixed.hxx>
#include <vcl/edit.hxx>
#include <vcl/vclmedit.hxx>
#include <vcl/fixedhyper.hxx>
#include <comphelper/backupfilehelper.hxx>

class SafeModeDialog : public Dialog
@@ -41,14 +42,18 @@ private:
    VclPtr<CheckBox> mpCBResetCustomizations;
    VclPtr<CheckBox> mpCBResetWholeUserProfile;

    VclPtr<FixedHyperlink> mpBugLink;

    // local BackupFileHelper for handling possible restores
    comphelper::BackupFileHelper maBackupFileHelper;

    static void terminateOffice();
    void applyChanges();
    static void openWebBrowser(const OUString & sURL, const OUString &sTitle);

    DECL_LINK(CheckBoxHdl, CheckBox&, void);
    DECL_LINK(BtnHdl, Button*, void);
    DECL_LINK(HandleHyperlink, FixedHyperlink&, void);
};

#endif
diff --git a/svx/uiconfig/ui/safemodedialog.ui b/svx/uiconfig/ui/safemodedialog.ui
index a1a352a..cfc7e0f 100644
--- a/svx/uiconfig/ui/safemodedialog.ui
+++ b/svx/uiconfig/ui/safemodedialog.ui
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<!-- Generated with glade 3.18.3 -->
<interface>
  <requires lib="gtk+" version="3.12"/>
  <object class="GtkDialog" id="SafeModeDialog">
@@ -13,16 +13,71 @@
        <property name="can_focus">False</property>
        <property name="orientation">vertical</property>
        <property name="spacing">12</property>
        <child internal-child="action_area">
          <object class="GtkButtonBox" id="dialog-action_area1">
            <property name="can_focus">False</property>
            <property name="layout_style">end</property>
            <child>
              <object class="GtkButton" id="btn_continue">
                <property name="label" translatable="yes">_Continue in Safe Mode</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="has_default">True</property>
                <property name="receives_default">True</property>
                <property name="use_underline">True</property>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="btn_quit">
                <property name="label" translatable="yes">_Quit</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_underline">True</property>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">1</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="btn_restart">
                <property name="label" translatable="yes">_Make Changes and Restart</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_underline">True</property>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">3</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">False</property>
            <property name="pack_type">end</property>
            <property name="position">4</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel" id="label1">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="xalign">0</property>
            <property name="yalign">0</property>
            <property name="label" translatable="yes">%PRODUCTNAME is now running in Safe Mode. You can make one or more of the following changes to return to a working state.

The offered possible changes get more radical from top to bottom, so it is recommended to try them thoroughly one after the other.</property>
            <property name="wrap">True</property>
            <property name="xalign">0</property>
            <property name="yalign">0</property>
          </object>
          <packing>
            <property name="expand">False</property>
@@ -117,59 +172,60 @@ The offered possible changes get more radical from top to bottom, so it is recom
            <property name="position">1</property>
          </packing>
        </child>
        <child internal-child="action_area">
          <object class="GtkButtonBox" id="dialog-action_area1">
            <property name="can_focus">False</property>
            <property name="layout_style">end</property>
        <child>
          <object class="GtkExpander" id="expander1">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <child>
              <object class="GtkButton" id="btn_continue">
                <property name="label" translatable="yes">_Continue in Safe Mode</property>
              <object class="GtkBox" id="box2">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="has_default">True</property>
                <property name="receives_default">True</property>
                <property name="use_underline">True</property>
                <property name="can_focus">False</property>
                <property name="orientation">vertical</property>
                <property name="spacing">12</property>
                <child>
                  <object class="GtkLabel" id="label3">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="label" translatable="yes">If you experience problems that are not resolved by using the Safe Mode, visit the following link to get help or report a bug.

You can also include the relevant parts of your User Profile. Beware that it might contain personal data.</property>
                    <property name="xalign">0</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">True</property>
                    <property name="position">0</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkLinkButton" id="linkbutton_bugs">
                    <property name="label" translatable="yes">Get Help</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                    <property name="relief">none</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">True</property>
                    <property name="position">1</property>
                  </packing>
                </child>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="btn_quit">
                <property name="label" translatable="yes">_Quit</property>
            <child type="label">
              <object class="GtkLabel" id="label2">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_underline">True</property>
                <property name="can_focus">False</property>
                <property name="margin_bottom">6</property>
                <property name="label" translatable="yes">Advanced</property>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">1</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="btn_restart">
                <property name="label" translatable="yes">_Make Changes and Restart</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_underline">True</property>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">3</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">False</property>
            <property name="pack_type">end</property>
            <property name="position">4</property>
            <property name="fill">True</property>
            <property name="position">3</property>
          </packing>
        </child>
      </object>