[Libreoffice-commits] core.git: 4 commits - desktop/source include/sfx2 sfx2/Library_sfx.mk sfx2/source svx/source

Samuel Mehrbrodt Samuel.Mehrbrodt at cib.de
Wed Oct 12 10:36:52 UTC 2016


 desktop/source/app/app.cxx           |    3 +
 include/sfx2/safemode.hxx            |   52 ++++++++++++++++++++++++++++++
 sfx2/Library_sfx.mk                  |    1 
 sfx2/source/appl/appserv.cxx         |    2 +
 sfx2/source/safemode/safemode.cxx    |   59 +++++++++++++++++++++++++++++++++++
 svx/source/dialog/SafeModeDialog.cxx |   10 +++++
 svx/source/dialog/SafeModeDialog.hxx |    2 +
 svx/source/dialog/crashreportdlg.cxx |    3 +
 8 files changed, 129 insertions(+), 3 deletions(-)

New commits:
commit 2811e4215abb998ebea65512d8dcd86697e3301e
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Wed Oct 12 11:18:08 2016 +0200

    Delete the safemode flag when closing the dialog
    
    Change-Id: I7131849cc417155b55425eba1494992f7d07fa0b

diff --git a/svx/source/dialog/SafeModeDialog.cxx b/svx/source/dialog/SafeModeDialog.cxx
index 0553436..549a62f 100644
--- a/svx/source/dialog/SafeModeDialog.cxx
+++ b/svx/source/dialog/SafeModeDialog.cxx
@@ -46,6 +46,14 @@ void SafeModeDialog::dispose()
     Dialog::dispose();
 }
 
+bool SafeModeDialog::Close()
+{
+    // Remove the safe mode flag before exiting this dialog
+    sfx2::SafeMode::removeFlag();
+
+    return Dialog::Close();
+}
+
 IMPL_LINK(SafeModeDialog, BtnHdl, Button*, pBtn, void)
 {
     if (pBtn == mpBtnContinue.get())
@@ -60,7 +68,6 @@ IMPL_LINK(SafeModeDialog, BtnHdl, Button*, pBtn, void)
     {
         Close();
     }
-    sfx2::SafeMode::removeFlag();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/dialog/SafeModeDialog.hxx b/svx/source/dialog/SafeModeDialog.hxx
index ac71cf4..41acc1f 100644
--- a/svx/source/dialog/SafeModeDialog.hxx
+++ b/svx/source/dialog/SafeModeDialog.hxx
@@ -26,6 +26,8 @@ public:
 
     virtual void dispose() override;
 
+    virtual bool Close() override;
+
 private:
 
     VclPtr<Button> mpBtnContinue;
commit d69006657512a5d23b03c69d89b378f47fa5c521
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Wed Oct 12 10:43:55 2016 +0200

    Fix writing the flag file
    
    Change-Id: Id2eef64b52ac0f7c48dc090ed3ce41f5cde6b775

diff --git a/sfx2/source/safemode/safemode.cxx b/sfx2/source/safemode/safemode.cxx
index a5669d1..3e84f7e 100644
--- a/sfx2/source/safemode/safemode.cxx
+++ b/sfx2/source/safemode/safemode.cxx
@@ -45,11 +45,12 @@ bool SafeMode::removeFlag()
 
 OUString SafeMode::getFileName()
 {
-    OUString url("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/safemode");
+    OUString url("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/");
     rtl::Bootstrap::expandMacros(url);
 
     OUString aProfilePath;
     FileBase::getSystemPathFromFileURL(url, aProfilePath);
+    FileBase::getAbsoluteFileURL(url, "safemode", aProfilePath);
     return aProfilePath;
 }
 
commit a1261b63f22b8d9d7b134137d1252b6b28dea35c
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Wed Oct 12 10:42:47 2016 +0200

    Safemode: Add doxygen documentation
    
    Change-Id: Ic5a7f5dfcefe66c961c9b71e9dbdfefeb9f06825

diff --git a/include/sfx2/safemode.hxx b/include/sfx2/safemode.hxx
index 666d2d4..03f8590 100644
--- a/include/sfx2/safemode.hxx
+++ b/include/sfx2/safemode.hxx
@@ -19,9 +19,29 @@ namespace sfx2 {
 class SFX2_DLLPUBLIC SafeMode
 {
 public:
+    /**
+     * Write a flag file to the user profile indicating that the next launch should be in safe mode.
+     *
+     * @return Whether the file could be written successfully
+     */
     static bool putFlag();
+
+    /**
+     * Check the existence of the safe mode flag file.
+     *
+     * @return Whether the flag file for the safe mode exists
+     */
     static bool hasFlag();
+
+    /**
+     * Remove the flag file for the safe mode.
+     *
+     * @return Whether the flag file could be removed successfully
+     */
     static bool removeFlag();
+
+private:
+    /** Returns the path of the safe mode flag file.*/
     static OUString getFileName();
 };
 
commit b3b9ae6c6fd19b437a5414489a9f38fb310a2843
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Tue Oct 11 16:07:37 2016 +0200

    safemode: Add flag to indicate safemode
    
    Change-Id: Ifdbb291715b033eaace159297eac5348530e9f36

diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index a9d10c3..69da758 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -101,6 +101,7 @@
 #include <vcl/settings.hxx>
 #include <sfx2/sfx.hrc>
 #include <sfx2/app.hxx>
+#include <sfx2/safemode.hxx>
 #include <svl/itemset.hxx>
 #include <svl/eitem.hxx>
 #include <basic/sbstar.hxx>
@@ -2138,7 +2139,7 @@ void Desktop::OpenClients()
     bool bAllowRecoveryAndSessionManagement = ( !rArgs.IsNoRestore() ) && ( !rArgs.IsHeadless()  );
 
     // Enter safe mode if requested
-    if (rArgs.IsSafeMode())
+    if (rArgs.IsSafeMode() || sfx2::SafeMode::hasFlag())
         handleSafeMode();
 
 
diff --git a/include/sfx2/safemode.hxx b/include/sfx2/safemode.hxx
new file mode 100644
index 0000000..666d2d4
--- /dev/null
+++ b/include/sfx2/safemode.hxx
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SFX2_SAFEMODE_HXX
+#define INCLUDED_SFX2_SAFEMODE_HXX
+
+#include <sfx2/dllapi.h>
+
+#include <rtl/ustring.hxx>
+
+namespace sfx2 {
+
+class SFX2_DLLPUBLIC SafeMode
+{
+public:
+    static bool putFlag();
+    static bool hasFlag();
+    static bool removeFlag();
+    static OUString getFileName();
+};
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index 9ec5f0e..e3daa77 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -251,6 +251,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
     sfx2/source/notify/globalevents \
     sfx2/source/notify/hintpost \
     sfx2/source/notify/openurlhint \
+    sfx2/source/safemode/safemode \
     sfx2/source/sidebar/Sidebar \
     sfx2/source/sidebar/SidebarChildWindow \
     sfx2/source/sidebar/SidebarDockingWindow \
diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx
index b09613e..defd3b6 100644
--- a/sfx2/source/appl/appserv.cxx
+++ b/sfx2/source/appl/appserv.cxx
@@ -127,6 +127,7 @@
 #include <sfx2/sidebar/Sidebar.hxx>
 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
 #include <sfx2/sidebar/SidebarController.hxx>
+#include <sfx2/safemode.hxx>
 
 #include <comphelper/types.hxx>
 #include <officecfg/Office/Common.hxx>
@@ -311,6 +312,7 @@ namespace
     IMPL_LINK_NOARG(SafeModeQueryDialog, RestartHdl, Button*, void)
     {
         EndDialog(RET_OK);
+        sfx2::SafeMode::putFlag();
         uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
         css::task::OfficeRestartManager::get(xContext)->requestRestart(
             css::uno::Reference< css::task::XInteractionHandler >());
diff --git a/sfx2/source/safemode/safemode.cxx b/sfx2/source/safemode/safemode.cxx
new file mode 100644
index 0000000..a5669d1
--- /dev/null
+++ b/sfx2/source/safemode/safemode.cxx
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sfx2/safemode.hxx>
+
+#include <config_folders.h>
+
+#include <osl/file.hxx>
+#include <rtl/bootstrap.hxx>
+
+using namespace osl;
+
+namespace sfx2 {
+
+bool SafeMode::putFlag()
+{
+    File safeModeFile(getFileName());
+    if (safeModeFile.open(osl_File_OpenFlag_Create) == FileBase::E_None)
+    {
+        safeModeFile.close();
+        return true;
+    }
+    return false;
+}
+bool SafeMode::hasFlag()
+{
+    File safeModeFile(getFileName());
+    if (safeModeFile.open(osl_File_OpenFlag_Read) == FileBase::E_None)
+    {
+        safeModeFile.close();
+        return true;
+    }
+    return false;
+}
+bool SafeMode::removeFlag()
+{
+    return File::remove(getFileName()) == FileBase::E_None;
+}
+
+OUString SafeMode::getFileName()
+{
+    OUString url("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/safemode");
+    rtl::Bootstrap::expandMacros(url);
+
+    OUString aProfilePath;
+    FileBase::getSystemPathFromFileURL(url, aProfilePath);
+    return aProfilePath;
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/dialog/SafeModeDialog.cxx b/svx/source/dialog/SafeModeDialog.cxx
index c9f6e4c..0553436 100644
--- a/svx/source/dialog/SafeModeDialog.cxx
+++ b/svx/source/dialog/SafeModeDialog.cxx
@@ -10,9 +10,9 @@
 #include "SafeModeDialog.hxx"
 
 #include <config_folders.h>
-
 #include <rtl/bootstrap.hxx>
 #include <osl/file.hxx>
+#include <sfx2/safemode.hxx>
 
 SafeModeDialog::SafeModeDialog(vcl::Window* pParent):
     Dialog(pParent, "SafeModeDialog", "svx/ui/safemodedialog.ui")
@@ -60,6 +60,7 @@ IMPL_LINK(SafeModeDialog, BtnHdl, Button*, pBtn, void)
     {
         Close();
     }
+    sfx2::SafeMode::removeFlag();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/dialog/crashreportdlg.cxx b/svx/source/dialog/crashreportdlg.cxx
index bbac211..1692a44 100644
--- a/svx/source/dialog/crashreportdlg.cxx
+++ b/svx/source/dialog/crashreportdlg.cxx
@@ -15,6 +15,7 @@
 #include <rtl/bootstrap.hxx>
 #include <desktop/crashreport.hxx>
 #include <desktop/minidump.hxx>
+#include <sfx2/safemode.hxx>
 #include <comphelper/processfactory.hxx>
 #include <osl/file.hxx>
 
@@ -104,7 +105,7 @@ IMPL_LINK(CrashReportDialog, BtnHdl, Button*, pBtn, void)
     // Check whether to go to safe mode
     if (mpCBSafeMode->IsChecked())
     {
-        //TODO: Actually set the safe mode, currently it's only restarting
+        sfx2::SafeMode::putFlag();
         css::uno::Reference< css::uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
         css::task::OfficeRestartManager::get(xContext)->requestRestart(
             css::uno::Reference< css::task::XInteractionHandler >());


More information about the Libreoffice-commits mailing list