[Libreoffice-commits] core.git: comphelper/source include/comphelper include/svx svx/AllLangResTarget_svx.mk svx/source svx/uiconfig svx/UIConfig_svx.mk

Samuel Mehrbrodt Samuel.Mehrbrodt at cib.de
Thu Nov 3 12:20:11 UTC 2016


 comphelper/source/misc/backupfilehelper.cxx     |    5 +
 include/comphelper/backupfilehelper.hxx         |    3 
 include/comphelper/package/ZipPackageHelper.hxx |   57 ++++++++++++++++
 include/svx/dialogs.hrc                         |    6 +
 svx/AllLangResTarget_svx.mk                     |    1 
 svx/UIConfig_svx.mk                             |    1 
 svx/source/dialog/SafeMode.src                  |   17 ++++
 svx/source/dialog/SafeModeDialog.cxx            |   65 +++++++++++++++++-
 svx/source/dialog/SafeModeDialog.hxx            |    4 -
 svx/uiconfig/ui/profileexporteddialog.ui        |   84 ++++++++++++++++++++++++
 svx/uiconfig/ui/safemodedialog.ui               |   40 +++++++++--
 11 files changed, 269 insertions(+), 14 deletions(-)

New commits:
commit e509c22863b5184421e710cf8ae81e2ddc961623
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Wed Nov 2 10:26:39 2016 +0100

    SafeModeDialog: Allow to create zip file from profile
    
    Change-Id: I4296d1cf5058be359ffed46745673cf26eba3375
    Reviewed-on: https://gerrit.libreoffice.org/30479
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
    Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

diff --git a/comphelper/source/misc/backupfilehelper.cxx b/comphelper/source/misc/backupfilehelper.cxx
index de03b0b..6432010 100644
--- a/comphelper/source/misc/backupfilehelper.cxx
+++ b/comphelper/source/misc/backupfilehelper.cxx
@@ -2207,6 +2207,11 @@ namespace comphelper
         return maUserConfigBaseURL;
     }
 
+    const OUString& BackupFileHelper::getUserProfileWorkURL()
+    {
+        return maUserConfigWorkURL;
+    }
+
     /////////////////// helpers ///////////////////////
 
     const rtl::OUString BackupFileHelper::getPackURL()
diff --git a/include/comphelper/backupfilehelper.hxx b/include/comphelper/backupfilehelper.hxx
index 07cfb61..d11208a 100644
--- a/include/comphelper/backupfilehelper.hxx
+++ b/include/comphelper/backupfilehelper.hxx
@@ -182,6 +182,9 @@ namespace comphelper
         /** Return the profile url */
         static const OUString& getUserProfileURL();
 
+        /** Return the url of the backed up profile (when in safe mode) */
+        static const OUString& getUserProfileWorkURL();
+
     private:
         // internal helper methods
         static const rtl::OUString getPackURL();
diff --git a/include/comphelper/package/ZipPackageHelper.hxx b/include/comphelper/package/ZipPackageHelper.hxx
new file mode 100644
index 0000000..2cdd5db
--- /dev/null
+++ b/include/comphelper/package/ZipPackageHelper.hxx
@@ -0,0 +1,57 @@
+/* -*- 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: */
diff --git a/include/svx/dialogs.hrc b/include/svx/dialogs.hrc
index aba0095..3ccea55 100644
--- a/include/svx/dialogs.hrc
+++ b/include/svx/dialogs.hrc
@@ -1080,8 +1080,12 @@
 #define RID_SVXSTRARY_SPACING            (RID_SVX_START + 1398)
 #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 !!!
-#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
 // of grouping them by semantics. The reason is that resource ids have to be
diff --git a/svx/AllLangResTarget_svx.mk b/svx/AllLangResTarget_svx.mk
index 3a98734..8f4be3f 100644
--- a/svx/AllLangResTarget_svx.mk
+++ b/svx/AllLangResTarget_svx.mk
@@ -50,6 +50,7 @@ $(eval $(call gb_SrsTarget_add_files,svx/res,\
     svx/source/dialog/prtqry.src \
     svx/source/dialog/ruler.src \
     svx/source/dialog/spacing.src \
+    svx/source/dialog/SafeMode.src \
     svx/source/dialog/samecontent.src \
     svx/source/dialog/sdstring.src \
     svx/source/dialog/srchdlg.src \
diff --git a/svx/UIConfig_svx.mk b/svx/UIConfig_svx.mk
index 65b9bde..5c71dc2 100644
--- a/svx/UIConfig_svx.mk
+++ b/svx/UIConfig_svx.mk
@@ -53,6 +53,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svx,\
 	svx/uiconfig/ui/paralrspacing \
 	svx/uiconfig/ui/paraulspacing \
 	svx/uiconfig/ui/passwd \
+	svx/uiconfig/ui/profileexporteddialog \
 	svx/uiconfig/ui/querydeletecontourdialog \
 	svx/uiconfig/ui/querydeleteobjectdialog \
 	svx/uiconfig/ui/querydeletethemedialog \
diff --git a/svx/source/dialog/SafeMode.src b/svx/source/dialog/SafeMode.src
new file mode 100644
index 0000000..2de389e
--- /dev/null
+++ b/svx/source/dialog/SafeMode.src
@@ -0,0 +1,17 @@
+/* -*- 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: */
diff --git a/svx/source/dialog/SafeModeDialog.cxx b/svx/source/dialog/SafeModeDialog.cxx
index 84d8476..35b135b 100644
--- a/svx/source/dialog/SafeModeDialog.cxx
+++ b/svx/source/dialog/SafeModeDialog.cxx
@@ -17,8 +17,11 @@
 #include <vcl/layout.hxx>
 #include <comphelper/anytostring.hxx>
 #include <comphelper/processfactory.hxx>
+#include <unotools/ZipPackageHelper.hxx>
 #include <cppuhelper/exc_hlp.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/XDesktop2.hpp>
@@ -79,14 +82,15 @@ SafeModeDialog::SafeModeDialog(vcl::Window* pParent)
 
     get(mpBugLink, "linkbutton_bugs");
     get(mpUserProfileLink, "linkbutton_profile");
+    get(mpBtnCreateZip, "btn_create_zip");
 
     mpRadioRestore->SetClickHdl(LINK(this, SafeModeDialog, RadioBtnHdl));
     mpRadioConfigure->SetClickHdl(LINK(this, SafeModeDialog, RadioBtnHdl));
     mpRadioReset->SetClickHdl(LINK(this, SafeModeDialog, RadioBtnHdl));
 
-    mpBtnContinue->SetClickHdl(LINK(this, SafeModeDialog, BtnHdl));
-    mpBtnQuit->SetClickHdl(LINK(this, SafeModeDialog, BtnHdl));
-    mpBtnRestart->SetClickHdl(LINK(this, SafeModeDialog, BtnHdl));
+    mpBtnContinue->SetClickHdl(LINK(this, SafeModeDialog, DialogBtnHdl));
+    mpBtnQuit->SetClickHdl(LINK(this, SafeModeDialog, DialogBtnHdl));
+    mpBtnRestart->SetClickHdl(LINK(this, SafeModeDialog, DialogBtnHdl));
 
     mpCBCheckProfilesafeConfig->SetToggleHdl(LINK(this, SafeModeDialog, CheckBoxHdl));
     mpCBCheckProfilesafeExtensions->SetToggleHdl(LINK(this, SafeModeDialog, CheckBoxHdl));
@@ -97,6 +101,8 @@ SafeModeDialog::SafeModeDialog(vcl::Window* pParent)
     mpCBResetCustomizations->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
     mpBtnRestart->Disable();
 
@@ -174,6 +180,7 @@ void SafeModeDialog::dispose()
 
     mpBugLink.clear();
     mpUserProfileLink.clear();
+    mpBtnCreateZip.clear();
 
     Dialog::dispose();
 }
@@ -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())
     {
@@ -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)
 {
     const bool bEnable(
diff --git a/svx/source/dialog/SafeModeDialog.hxx b/svx/source/dialog/SafeModeDialog.hxx
index 05ee6a2..9bc5d91 100644
--- a/svx/source/dialog/SafeModeDialog.hxx
+++ b/svx/source/dialog/SafeModeDialog.hxx
@@ -56,6 +56,7 @@ private:
 
     VclPtr<FixedHyperlink> mpBugLink;
     VclPtr<FixedHyperlink> mpUserProfileLink;
+    VclPtr<Button> mpBtnCreateZip;
 
     // local BackupFileHelper for handling possible restores
     comphelper::BackupFileHelper maBackupFileHelper;
@@ -65,7 +66,8 @@ private:
 
     DECL_LINK(RadioBtnHdl, Button*, void);
     DECL_LINK(CheckBoxHdl, CheckBox&, void);
-    DECL_LINK(BtnHdl, Button*, void);
+    DECL_LINK(CreateZipBtnHdl, Button*, void);
+    DECL_LINK(DialogBtnHdl, Button*, void);
 };
 
 #endif
diff --git a/svx/uiconfig/ui/profileexporteddialog.ui b/svx/uiconfig/ui/profileexporteddialog.ui
new file mode 100644
index 0000000..3897bd5
--- /dev/null
+++ b/svx/uiconfig/ui/profileexporteddialog.ui
@@ -0,0 +1,84 @@
+<?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>
diff --git a/svx/uiconfig/ui/safemodedialog.ui b/svx/uiconfig/ui/safemodedialog.ui
index 74d32df..43989aa 100644
--- a/svx/uiconfig/ui/safemodedialog.ui
+++ b/svx/uiconfig/ui/safemodedialog.ui
@@ -354,8 +354,7 @@ The offered possible changes get more radical from top to bottom, so it is recom
                   <object class="GtkLabel" id="label4">
                     <property name="visible">True</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.
-Your User Profile is located at:</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>
                     <property name="xalign">0</property>
                   </object>
                   <packing>
@@ -365,17 +364,42 @@ Your User Profile is located at:</property>
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLinkButton" id="linkbutton_profile">
-                    <property name="label" translatable="yes">Show User Profile</property>
+                  <object class="GtkBox">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="relief">none</property>
+                    <property name="can_focus">False</property>
+                    <property name="homogeneous">True</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>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">True</property>
-                    <property name="position">3</property>
+                    <property name="position">4</property>
                   </packing>
                 </child>
               </object>


More information about the Libreoffice-commits mailing list