safemode: Add flag to indicate safemode

Change-Id: Ifdbb291715b033eaace159297eac5348530e9f36
This commit is contained in:
Samuel Mehrbrodt 2016-10-11 16:07:37 +02:00
parent 6b44a8186d
commit b3b9ae6c6f
7 changed files with 99 additions and 3 deletions

View file

@ -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();

32
include/sfx2/safemode.hxx Normal file
View file

@ -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: */

View file

@ -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 \

View file

@ -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 >());

View file

@ -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: */

View file

@ -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: */

View file

@ -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 >());