Kaydet (Commit) e509c228 authored tarafından Samuel Mehrbrodt's avatar Samuel Mehrbrodt

SafeModeDialog: Allow to create zip file from profile

Change-Id: I4296d1cf5058be359ffed46745673cf26eba3375
Reviewed-on: https://gerrit.libreoffice.org/30479Reviewed-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Tested-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
üst 954f721a
...@@ -2207,6 +2207,11 @@ namespace comphelper ...@@ -2207,6 +2207,11 @@ namespace comphelper
return maUserConfigBaseURL; return maUserConfigBaseURL;
} }
const OUString& BackupFileHelper::getUserProfileWorkURL()
{
return maUserConfigWorkURL;
}
/////////////////// helpers /////////////////////// /////////////////// helpers ///////////////////////
const rtl::OUString BackupFileHelper::getPackURL() const rtl::OUString BackupFileHelper::getPackURL()
......
...@@ -182,6 +182,9 @@ namespace comphelper ...@@ -182,6 +182,9 @@ namespace comphelper
/** Return the profile url */ /** Return the profile url */
static const OUString& getUserProfileURL(); static const OUString& getUserProfileURL();
/** Return the url of the backed up profile (when in safe mode) */
static const OUString& getUserProfileWorkURL();
private: private:
// internal helper methods // internal helper methods
static const rtl::OUString getPackURL(); static const rtl::OUString getPackURL();
......
/* -*- 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_COMPHELPER_PACKAGE_ZIPPACKAGEHELPER_HXX
#define INCLUDED_COMPHELPER_PACKAGE_ZIPPACKAGEHELPER_HXX
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/io/XInputStream.hpp>
class ZipPackageHelper
{
public:
ZipPackageHelper( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
const OUString& sPackageURL);
void savePackage();
void addFile( const OUString& rSourceFile )
throw( css::uno::Exception, std::exception );
void addStream( css::uno::Reference< css::io::XInputStream > const & xInput,
const OUString& aName ) throw( css::uno::Exception );
css::uno::Reference< css::uno::XInterface > addFolder( const OUString& rName )
throw( css::uno::Exception, std::exception );
void addFolderWithContent( const OUString& rDirURL );
private:
css::uno::Reference< css::uno::XComponentContext > mxContext;
css::uno::Reference< css::container::XHierarchicalNameAccess > mxHNameAccess;
css::uno::Reference< css::lang::XSingleServiceFactory > mxFactory;
css::uno::Reference< css::uno::XInterface > mxRootFolder;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -1080,8 +1080,12 @@ ...@@ -1080,8 +1080,12 @@
#define RID_SVXSTRARY_SPACING (RID_SVX_START + 1398) #define RID_SVXSTRARY_SPACING (RID_SVX_START + 1398)
#define RID_SVXSTRARY_SAMECONTENT (RID_SVX_START + 1399) #define RID_SVXSTRARY_SAMECONTENT (RID_SVX_START + 1399)
// Strings for SafeModeDialog
#define RID_SVXSTR_SAFEMODE_ZIP_FAILURE (RID_SVX_START + 1400)
// !!! IMPORTANT: consider and update RID_SVXSTR_NEXTFREE when introducing new RIDs for Strings !!! // !!! IMPORTANT: consider and update RID_SVXSTR_NEXTFREE when introducing new RIDs for Strings !!!
#define RID_SVXSTR_NEXTFREE (RID_SVX_START + 1400) #define RID_SVXSTR_NEXTFREE (RID_SVX_START + 1401)
// if we have _a_lot_ time, we should group the resource ids by type, instead // if we have _a_lot_ time, we should group the resource ids by type, instead
// of grouping them by semantics. The reason is that resource ids have to be // of grouping them by semantics. The reason is that resource ids have to be
......
...@@ -50,6 +50,7 @@ $(eval $(call gb_SrsTarget_add_files,svx/res,\ ...@@ -50,6 +50,7 @@ $(eval $(call gb_SrsTarget_add_files,svx/res,\
svx/source/dialog/prtqry.src \ svx/source/dialog/prtqry.src \
svx/source/dialog/ruler.src \ svx/source/dialog/ruler.src \
svx/source/dialog/spacing.src \ svx/source/dialog/spacing.src \
svx/source/dialog/SafeMode.src \
svx/source/dialog/samecontent.src \ svx/source/dialog/samecontent.src \
svx/source/dialog/sdstring.src \ svx/source/dialog/sdstring.src \
svx/source/dialog/srchdlg.src \ svx/source/dialog/srchdlg.src \
......
...@@ -53,6 +53,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svx,\ ...@@ -53,6 +53,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svx,\
svx/uiconfig/ui/paralrspacing \ svx/uiconfig/ui/paralrspacing \
svx/uiconfig/ui/paraulspacing \ svx/uiconfig/ui/paraulspacing \
svx/uiconfig/ui/passwd \ svx/uiconfig/ui/passwd \
svx/uiconfig/ui/profileexporteddialog \
svx/uiconfig/ui/querydeletecontourdialog \ svx/uiconfig/ui/querydeletecontourdialog \
svx/uiconfig/ui/querydeleteobjectdialog \ svx/uiconfig/ui/querydeleteobjectdialog \
svx/uiconfig/ui/querydeletethemedialog \ svx/uiconfig/ui/querydeletethemedialog \
......
/* -*- 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 <svx/dialogs.hrc>
String RID_SVXSTR_SAFEMODE_ZIP_FAILURE
{
Text[en-US] = "The zip file could not be created.";
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
...@@ -17,8 +17,11 @@ ...@@ -17,8 +17,11 @@
#include <vcl/layout.hxx> #include <vcl/layout.hxx>
#include <comphelper/anytostring.hxx> #include <comphelper/anytostring.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <unotools/ZipPackageHelper.hxx>
#include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/exc_hlp.hxx>
#include <unotools/configmgr.hxx> #include <unotools/configmgr.hxx>
#include <svx/dialmgr.hxx>
#include <svx/dialogs.hrc>
#include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XDesktop2.hpp> #include <com/sun/star/frame/XDesktop2.hpp>
...@@ -79,14 +82,15 @@ SafeModeDialog::SafeModeDialog(vcl::Window* pParent) ...@@ -79,14 +82,15 @@ SafeModeDialog::SafeModeDialog(vcl::Window* pParent)
get(mpBugLink, "linkbutton_bugs"); get(mpBugLink, "linkbutton_bugs");
get(mpUserProfileLink, "linkbutton_profile"); get(mpUserProfileLink, "linkbutton_profile");
get(mpBtnCreateZip, "btn_create_zip");
mpRadioRestore->SetClickHdl(LINK(this, SafeModeDialog, RadioBtnHdl)); mpRadioRestore->SetClickHdl(LINK(this, SafeModeDialog, RadioBtnHdl));
mpRadioConfigure->SetClickHdl(LINK(this, SafeModeDialog, RadioBtnHdl)); mpRadioConfigure->SetClickHdl(LINK(this, SafeModeDialog, RadioBtnHdl));
mpRadioReset->SetClickHdl(LINK(this, SafeModeDialog, RadioBtnHdl)); mpRadioReset->SetClickHdl(LINK(this, SafeModeDialog, RadioBtnHdl));
mpBtnContinue->SetClickHdl(LINK(this, SafeModeDialog, BtnHdl)); mpBtnContinue->SetClickHdl(LINK(this, SafeModeDialog, DialogBtnHdl));
mpBtnQuit->SetClickHdl(LINK(this, SafeModeDialog, BtnHdl)); mpBtnQuit->SetClickHdl(LINK(this, SafeModeDialog, DialogBtnHdl));
mpBtnRestart->SetClickHdl(LINK(this, SafeModeDialog, BtnHdl)); mpBtnRestart->SetClickHdl(LINK(this, SafeModeDialog, DialogBtnHdl));
mpCBCheckProfilesafeConfig->SetToggleHdl(LINK(this, SafeModeDialog, CheckBoxHdl)); mpCBCheckProfilesafeConfig->SetToggleHdl(LINK(this, SafeModeDialog, CheckBoxHdl));
mpCBCheckProfilesafeExtensions->SetToggleHdl(LINK(this, SafeModeDialog, CheckBoxHdl)); mpCBCheckProfilesafeExtensions->SetToggleHdl(LINK(this, SafeModeDialog, CheckBoxHdl));
...@@ -97,6 +101,8 @@ SafeModeDialog::SafeModeDialog(vcl::Window* pParent) ...@@ -97,6 +101,8 @@ SafeModeDialog::SafeModeDialog(vcl::Window* pParent)
mpCBResetCustomizations->SetToggleHdl(LINK(this, SafeModeDialog, CheckBoxHdl)); mpCBResetCustomizations->SetToggleHdl(LINK(this, SafeModeDialog, CheckBoxHdl));
mpCBResetWholeUserProfile->SetToggleHdl(LINK(this, SafeModeDialog, CheckBoxHdl)); mpCBResetWholeUserProfile->SetToggleHdl(LINK(this, SafeModeDialog, CheckBoxHdl));
mpBtnCreateZip->SetClickHdl(LINK(this, SafeModeDialog, CreateZipBtnHdl));
// Disable restart btn until some checkbox is active // Disable restart btn until some checkbox is active
mpBtnRestart->Disable(); mpBtnRestart->Disable();
...@@ -174,6 +180,7 @@ void SafeModeDialog::dispose() ...@@ -174,6 +180,7 @@ void SafeModeDialog::dispose()
mpBugLink.clear(); mpBugLink.clear();
mpUserProfileLink.clear(); mpUserProfileLink.clear();
mpBtnCreateZip.clear();
Dialog::dispose(); Dialog::dispose();
} }
...@@ -276,7 +283,7 @@ IMPL_LINK(SafeModeDialog, RadioBtnHdl, Button*, pBtn, void) ...@@ -276,7 +283,7 @@ IMPL_LINK(SafeModeDialog, RadioBtnHdl, Button*, pBtn, void)
} }
} }
IMPL_LINK(SafeModeDialog, BtnHdl, Button*, pBtn, void) IMPL_LINK(SafeModeDialog, DialogBtnHdl, Button*, pBtn, void)
{ {
if (pBtn == mpBtnContinue.get()) if (pBtn == mpBtnContinue.get())
{ {
...@@ -294,6 +301,56 @@ IMPL_LINK(SafeModeDialog, BtnHdl, Button*, pBtn, void) ...@@ -294,6 +301,56 @@ IMPL_LINK(SafeModeDialog, BtnHdl, Button*, pBtn, void)
} }
} }
namespace {
class ProfileExportedDialog : public ModalDialog
{
private:
DECL_LINK(OpenHdl, Button*, void);
public:
explicit ProfileExportedDialog();
};
ProfileExportedDialog::ProfileExportedDialog()
: ModalDialog(nullptr, "SafeModeQueryDialog", "svx/ui/profileexporteddialog.ui")
{
get<Button>("openfolder")->SetClickHdl(LINK(this, ProfileExportedDialog, OpenHdl));
}
IMPL_LINK_NOARG(ProfileExportedDialog, OpenHdl, Button*, void)
{
const OUString uri(comphelper::BackupFileHelper::getUserProfileURL());
css::uno::Reference< css::system::XSystemShellExecute > exec(
css::system::SystemShellExecute::create(comphelper::getProcessComponentContext()));
try {
exec->execute(uri, OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY);
} catch (css::uno::Exception) {
}
EndDialog(RET_OK);
}
}
IMPL_LINK(SafeModeDialog, CreateZipBtnHdl, Button*, /*pBtn*/, void)
{
const OUString zipFileName("libreoffice-profile.zip");
const OUString zipFileURL(comphelper::BackupFileHelper::getUserProfileURL() + "/" + zipFileName);
osl::File::remove(zipFileURL); // Remove previous exports
try
{
utl::ZipPackageHelper aZipHelper(comphelper::getProcessComponentContext(), zipFileURL);
aZipHelper.addFolderWithContent(aZipHelper.getRootFolder(), comphelper::BackupFileHelper::getUserProfileWorkURL());
aZipHelper.savePackage();
}
catch (uno::Exception)
{
ScopedVclPtrInstance< MessageDialog > aErrorBox(this, SVX_RESSTR(RID_SVXSTR_SAFEMODE_ZIP_FAILURE));
aErrorBox->Execute();
return;
}
ScopedVclPtrInstance< ProfileExportedDialog > aDialog;
aDialog->Execute();
}
IMPL_LINK(SafeModeDialog, CheckBoxHdl, CheckBox&, /*pCheckBox*/, void) IMPL_LINK(SafeModeDialog, CheckBoxHdl, CheckBox&, /*pCheckBox*/, void)
{ {
const bool bEnable( const bool bEnable(
......
...@@ -56,6 +56,7 @@ private: ...@@ -56,6 +56,7 @@ private:
VclPtr<FixedHyperlink> mpBugLink; VclPtr<FixedHyperlink> mpBugLink;
VclPtr<FixedHyperlink> mpUserProfileLink; VclPtr<FixedHyperlink> mpUserProfileLink;
VclPtr<Button> mpBtnCreateZip;
// local BackupFileHelper for handling possible restores // local BackupFileHelper for handling possible restores
comphelper::BackupFileHelper maBackupFileHelper; comphelper::BackupFileHelper maBackupFileHelper;
...@@ -65,7 +66,8 @@ private: ...@@ -65,7 +66,8 @@ private:
DECL_LINK(RadioBtnHdl, Button*, void); DECL_LINK(RadioBtnHdl, Button*, void);
DECL_LINK(CheckBoxHdl, CheckBox&, void); DECL_LINK(CheckBoxHdl, CheckBox&, void);
DECL_LINK(BtnHdl, Button*, void); DECL_LINK(CreateZipBtnHdl, Button*, void);
DECL_LINK(DialogBtnHdl, Button*, void);
}; };
#endif #endif
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkDialog" id="SafeModeQueryDialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="title" translatable="yes">Enter Safe Mode</property>
<property name="resizable">False</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<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="close">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="secondary">True</property>
</packing>
</child>
<child>
<object class="GtkButton" id="openfolder">
<property name="label">Open Containing _Folder</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">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Your user profile has been exported as “libreoffice-profile.zip”.</property>
<property name="wrap">True</property>
<property name="max_width_chars">80</property>
<property name="lines">2</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">close</action-widget>
<action-widget response="0">openfolder</action-widget>
</action-widgets>
</object>
</interface>
...@@ -354,8 +354,7 @@ The offered possible changes get more radical from top to bottom, so it is recom ...@@ -354,8 +354,7 @@ The offered possible changes get more radical from top to bottom, so it is recom
<object class="GtkLabel" id="label4"> <object class="GtkLabel" id="label4">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">You can also include the relevant parts of your User Profile. Beware that it might contain personal data. <property name="label" translatable="yes">You can also include the relevant parts of your User Profile. Beware that it might contain personal data.</property>
Your User Profile is located at:</property>
<property name="xalign">0</property> <property name="xalign">0</property>
</object> </object>
<packing> <packing>
...@@ -365,17 +364,42 @@ Your User Profile is located at:</property> ...@@ -365,17 +364,42 @@ Your User Profile is located at:</property>
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkLinkButton" id="linkbutton_profile"> <object class="GtkBox">
<property name="label" translatable="yes">Show User Profile</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">False</property>
<property name="receives_default">True</property> <property name="homogeneous">True</property>
<property name="relief">none</property> <child>
<object class="GtkButton" id="btn_create_zip">
<property name="label" translatable="yes">Create zip archive from User Profile</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</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_profile">
<property name="label" translatable="yes">Show User Profile</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> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">3</property> <property name="position">4</property>
</packing> </packing>
</child> </child>
</object> </object>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment