[Libreoffice-commits] core.git: 3 commits - extensions/source extensions/uiconfig

Miklos Vajna vmiklos at collabora.co.uk
Thu Jun 4 06:15:24 PDT 2015


 extensions/source/abpilot/abpfinalpage.cxx        |   17 +++++++
 extensions/source/abpilot/abpfinalpage.hxx        |    3 +
 extensions/source/abpilot/abspilot.cxx            |    3 -
 extensions/source/abpilot/addresssettings.hxx     |    1 
 extensions/source/abpilot/datasourcehandling.cxx  |   52 ++++++++++++++++++++--
 extensions/source/abpilot/datasourcehandling.hxx  |    3 -
 extensions/uiconfig/sabpilot/ui/datasourcepage.ui |   22 +++++++--
 7 files changed, 92 insertions(+), 9 deletions(-)

New commits:
commit b3f5ab776591f134e5f1692e745f62a2df599a67
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jun 4 14:19:38 2015 +0200

    abpilot: embed the data source definition, if possible + requested
    
    Change-Id: I0e70459e331995388b36c77c351bff89ece004a6

diff --git a/extensions/source/abpilot/abspilot.cxx b/extensions/source/abpilot/abspilot.cxx
index 459f321..1ef0ebe 100644
--- a/extensions/source/abpilot/abspilot.cxx
+++ b/extensions/source/abpilot/abspilot.cxx
@@ -158,7 +158,7 @@ namespace abp
             m_aNewDataSource.rename( m_aSettings.sDataSourceName );
 
         // 1. the data source
-        m_aNewDataSource.store();
+        m_aNewDataSource.store(m_aSettings);
 
         // 2. check if we need to register the data source
         if ( m_aSettings.bRegisterDataSource )
diff --git a/extensions/source/abpilot/datasourcehandling.cxx b/extensions/source/abpilot/datasourcehandling.cxx
index 3895268..f3d6268 100644
--- a/extensions/source/abpilot/datasourcehandling.cxx
+++ b/extensions/source/abpilot/datasourcehandling.cxx
@@ -22,6 +22,7 @@
 #include "abptypes.hxx"
 #include "componentmodule.hxx"
 #include "datasourcehandling.hxx"
+#include "addresssettings.hxx"
 
 #include <boost/noncopyable.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
@@ -46,7 +47,28 @@
 #include <unotools/confignode.hxx>
 #include <unotools/sharedunocomponent.hxx>
 #include <vcl/stdtext.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <comphelper/propertysequence.hxx>
 
+namespace
+{
+
+/// Returns the URL of this object shell.
+OUString lcl_getOwnURL(SfxObjectShell* pObjectShell)
+{
+    OUString aRet;
+
+    if (!pObjectShell)
+        return aRet;
+
+    const INetURLObject& rURLObject = pObjectShell->GetMedium()->GetURLObject();
+    aRet = rURLObject.GetMainURL(INetURLObject::DECODE_WITH_CHARSET);
+    return aRet;
+}
+
+}
 
 namespace abp
 {
@@ -54,6 +76,7 @@ namespace abp
 
     using namespace ::utl;
     using namespace ::comphelper;
+    using namespace ::com::sun::star;
     using namespace ::com::sun::star::uno;
     using namespace ::com::sun::star::lang;
     using namespace ::com::sun::star::sdb;
@@ -347,8 +370,7 @@ namespace abp
         delete m_pImpl;
     }
 
-
-    void ODataSource::store()
+    void ODataSource::store(const AddressSettings& rSettings)
     {
         if (!isValid())
             // nothing to do
@@ -361,7 +383,31 @@ namespace abp
                 xStorable.set(xDocAccess->getDatabaseDocument(), css::uno::UNO_QUERY);
             OSL_ENSURE( xStorable.is(),"DataSource is no XStorable!" );
             if ( xStorable.is() )
-                xStorable->storeAsURL(m_pImpl->sName,Sequence<PropertyValue>());
+            {
+                SfxObjectShell* pObjectShell = SfxViewFrame::Current()->GetObjectShell();
+                OUString aOwnURL = lcl_getOwnURL(pObjectShell);
+                if (aOwnURL.isEmpty() || !rSettings.bEmbedDataSource)
+                {
+                    // Cannot or should not embed.
+                    xStorable->storeAsURL(m_pImpl->sName,Sequence<PropertyValue>());
+                }
+                else
+                {
+                    // Embed.
+                    OUString aStreamRelPath = "EmbeddedDatabase";
+                    OUString sTmpName = "vnd.sun.star.pkg://";
+                    sTmpName += INetURLObject::encode(aOwnURL, INetURLObject::PART_AUTHORITY, INetURLObject::ENCODE_ALL);
+                    sTmpName += "/" + aStreamRelPath;
+                    uno::Reference<embed::XStorage> xStorage = pObjectShell->GetStorage();
+                    uno::Sequence<beans::PropertyValue> aSequence = comphelper::InitPropertySequence(
+                    {
+                        {"TargetStorage", uno::makeAny(xStorage)},
+                        {"StreamRelPath", uno::makeAny(aStreamRelPath)}
+                    });
+                    xStorable->storeAsURL(sTmpName, aSequence);
+                    m_pImpl->sName = sTmpName;
+                }
+            }
         }
         catch(const Exception&)
         {
diff --git a/extensions/source/abpilot/datasourcehandling.hxx b/extensions/source/abpilot/datasourcehandling.hxx
index fd4a75f..0d96f1d 100644
--- a/extensions/source/abpilot/datasourcehandling.hxx
+++ b/extensions/source/abpilot/datasourcehandling.hxx
@@ -95,6 +95,7 @@ namespace abp
 
     struct ODataSourceImpl;
     struct PackageAccessControl;
+    struct AddressSettings;
     /** a non-UNO wrapper for a data source
         <p>This class allows to access data sources without the need to compile the respective file with
         exception handling enabled (hopefully :).</p>
@@ -159,7 +160,7 @@ namespace abp
         void        disconnect( );
 
         /// stores the database file
-        void        store();
+        void        store(const AddressSettings& rSettings);
 
         /// register the data source under the given name in the configuration
         void        registerDataSource( const OUString& _sRegisteredDataSourceName );
commit b2117c98ed959e79079084a6e3e6e490573e7236
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jun 4 12:42:06 2015 +0200

    abpilot: store embedding preference in AddressSettings
    
    Change-Id: I83235f79d30e5f573fee95a525b4cfe1211a24b7

diff --git a/extensions/source/abpilot/abpfinalpage.cxx b/extensions/source/abpilot/abpfinalpage.cxx
index ccbd9b6..12dbd49 100644
--- a/extensions/source/abpilot/abpfinalpage.cxx
+++ b/extensions/source/abpilot/abpfinalpage.cxx
@@ -158,6 +158,7 @@ namespace abp
         rSettings.bRegisterDataSource = m_pRegisterName->IsChecked();
         if ( rSettings.bRegisterDataSource )
             rSettings.sRegisteredDataSourceName = m_pName->GetText();
+        rSettings.bEmbedDataSource = m_pEmbed->IsChecked();
 
         return true;
     }
diff --git a/extensions/source/abpilot/abspilot.cxx b/extensions/source/abpilot/abspilot.cxx
index a27b1e6..459f321 100644
--- a/extensions/source/abpilot/abspilot.cxx
+++ b/extensions/source/abpilot/abspilot.cxx
@@ -113,6 +113,7 @@ namespace abp
 #endif
         m_aSettings.sDataSourceName = ModuleRes(RID_STR_DEFAULT_NAME).toString();
         m_aSettings.bRegisterDataSource = false;
+        m_aSettings.bEmbedDataSource = false;
         m_aSettings.bIgnoreNoTable = false;
 
         defaultButton(WizardButtonFlags::NEXT);
diff --git a/extensions/source/abpilot/addresssettings.hxx b/extensions/source/abpilot/addresssettings.hxx
index 4cc4377..16d508a 100644
--- a/extensions/source/abpilot/addresssettings.hxx
+++ b/extensions/source/abpilot/addresssettings.hxx
@@ -54,6 +54,7 @@ namespace abp
         bool                bIgnoreNoTable;
         MapString2String    aFieldMapping;
         bool                bRegisterDataSource;
+        bool                bEmbedDataSource;
     };
 
 
commit ef0217f24e99a3313ed1467c6f2f496a14777db2
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jun 4 12:01:25 2015 +0200

    abpilot: add checkbox to embed data source in datasourcepage
    
    Change-Id: Iea9984af3f08ed214815b9477019695f2339a7f3

diff --git a/extensions/source/abpilot/abpfinalpage.cxx b/extensions/source/abpilot/abpfinalpage.cxx
index 0be3156..ccbd9b6 100644
--- a/extensions/source/abpilot/abpfinalpage.cxx
+++ b/extensions/source/abpilot/abpfinalpage.cxx
@@ -49,7 +49,9 @@ namespace abp
         get(m_pLocation, "location");
         get(m_pBrowse, "browse");
         get(m_pRegisterName, "available");
+        get(m_pEmbed, "embed");
         get(m_pNameLabel, "nameft");
+        get(m_pLocationLabel, "locationft");
         get(m_pName, "name");
         get(m_pDuplicateNameError, "warning");
         m_pLocationController = new svx::DatabaseLocationInputController(_pParent->getORB(),
@@ -59,6 +61,9 @@ namespace abp
         m_pLocation->SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
         m_pRegisterName->SetClickHdl( LINK( this, FinalPage, OnRegister ) );
         m_pRegisterName->Check(true);
+        m_pEmbed->SetClickHdl( LINK( this, FinalPage, OnEmbed ) );
+        m_pEmbed->Check(true);
+        OnEmbed(m_pEmbed);
     }
 
     FinalPage::~FinalPage()
@@ -72,7 +77,9 @@ namespace abp
         m_pLocation.clear();
         m_pBrowse.clear();
         m_pRegisterName.clear();
+        m_pEmbed.clear();
         m_pNameLabel.clear();
+        m_pLocationLabel.clear();
         m_pName.clear();
         m_pDuplicateNameError.clear();
         AddressBookSourcePage::dispose();
@@ -219,6 +226,15 @@ namespace abp
         return 0L;
     }
 
+    IMPL_LINK_NOARG(FinalPage, OnEmbed)
+    {
+        bool bEmbed = m_pEmbed->IsChecked();
+        m_pLocationLabel->Enable(!bEmbed);
+        m_pLocation->Enable(!bEmbed);
+        m_pBrowse->Enable(!bEmbed);
+        return 0L;
+    }
+
 }   // namespace abp
 
 
diff --git a/extensions/source/abpilot/abpfinalpage.hxx b/extensions/source/abpilot/abpfinalpage.hxx
index d601e8d..ceb1d0b 100644
--- a/extensions/source/abpilot/abpfinalpage.hxx
+++ b/extensions/source/abpilot/abpfinalpage.hxx
@@ -38,7 +38,9 @@ namespace abp
         VclPtr< ::svt::OFileURLControl>  m_pLocation;
         VclPtr<PushButton>       m_pBrowse;
         VclPtr<CheckBox>         m_pRegisterName;
+        VclPtr<CheckBox>         m_pEmbed;
         VclPtr<FixedText>        m_pNameLabel;
+        VclPtr<FixedText>        m_pLocationLabel;
         VclPtr<Edit>             m_pName;
         VclPtr<FixedText>        m_pDuplicateNameError;
 
@@ -67,6 +69,7 @@ namespace abp
     private:
         DECL_LINK( OnNameModified, Edit* );
         DECL_LINK(OnRegister, void *);
+        DECL_LINK(OnEmbed, void *);
 
         bool    isValidName() const;
         void        implCheckName();
diff --git a/extensions/uiconfig/sabpilot/ui/datasourcepage.ui b/extensions/uiconfig/sabpilot/ui/datasourcepage.ui
index cce60fe..0339bd7 100644
--- a/extensions/uiconfig/sabpilot/ui/datasourcepage.ui
+++ b/extensions/uiconfig/sabpilot/ui/datasourcepage.ui
@@ -34,13 +34,27 @@ Now, just enter the name under which you want to register the data source in %PR
         <property name="hexpand">True</property>
         <property name="row_spacing">6</property>
         <child>
+          <object class="GtkCheckButton" id="embed">
+            <property name="label" translatable="yes">Embed this address book definition into the current document.</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="xalign">0</property>
+            <property name="draw_indicator">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+          </packing>
+        </child>
+        <child>
           <object class="GtkGrid" id="grid4">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="hexpand">True</property>
             <property name="column_spacing">12</property>
             <child>
-              <object class="GtkLabel" id="label1">
+              <object class="GtkLabel" id="locationft">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="xalign">0</property>
@@ -92,7 +106,7 @@ Now, just enter the name under which you want to register the data source in %PR
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">0</property>
+            <property name="top_attach">1</property>
             <property name="width">1</property>
             <property name="height">1</property>
           </packing>
@@ -108,7 +122,7 @@ Now, just enter the name under which you want to register the data source in %PR
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">1</property>
+            <property name="top_attach">2</property>
             <property name="width">1</property>
             <property name="height">1</property>
           </packing>
@@ -190,7 +204,7 @@ Now, just enter the name under which you want to register the data source in %PR
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">2</property>
+            <property name="top_attach">3</property>
             <property name="width">1</property>
             <property name="height">1</property>
           </packing>


More information about the Libreoffice-commits mailing list