[Libreoffice-commits] core.git: Branch 'feature/cmis' - include/sfx2 sfx2/source

Cao Cuong Ngo cao.cuong.ngo at gmail.com
Thu Jul 18 02:39:01 PDT 2013


 include/sfx2/dinfdlg.hxx       |   18 ---
 sfx2/source/dialog/dinfdlg.cxx |  205 ++++++++---------------------------------
 sfx2/source/doc/objserv.cxx    |    2 
 3 files changed, 48 insertions(+), 177 deletions(-)

New commits:
commit 2507e671554cc9ec058c0fdb6082898eca4d4bc4
Author: Cao Cuong Ngo <cao.cuong.ngo at gmail.com>
Date:   Thu Jul 18 11:30:59 2013 +0200

    CMIS properties dialog
    
    Use Sequence directly instead of creating intermediate properties
    
    Change-Id: I194342678d7f56f34cc24a56440827e795e6be95

diff --git a/include/sfx2/dinfdlg.hxx b/include/sfx2/dinfdlg.hxx
index e677f57..a344bdc 100644
--- a/include/sfx2/dinfdlg.hxx
+++ b/include/sfx2/dinfdlg.hxx
@@ -50,8 +50,6 @@ namespace com { namespace sun { namespace star {
 } } }
 
 struct CustomProperty;
-struct CmisProperty;
-
 
 // class SfxDocumentInfoItem ---------------------------------------------
 
@@ -79,7 +77,7 @@ private:
     sal_Bool                            m_bDeleteUserData;
     sal_Bool                            m_bUseUserData;
     std::vector< CustomProperty* >    m_aCustomProperties;
-    std::vector< CmisProperty* >      m_aCmisProperties;
+    ::com::sun::star::uno::Sequence< ::com::sun::star::document::CmisProperty > m_aCmisProperties;
 
 public:
     TYPEINFO();
@@ -99,7 +97,7 @@ public:
             ::com::sun::star::document::XDocumentProperties> & i_xDocProps,
         bool i_bDoNotUpdateUserDefined = false)
         const;
-    sal_Bool    isCmisDocument() const { return m_aCmisProperties.size() > 0;}
+    sal_Bool    isCmisDocument() const { return m_aCmisProperties.getLength() > 0;}
 
     sal_Bool    isAutoloadEnabled() const { return m_isAutoloadEnabled; }
     void        setAutoloadEnabled(sal_Bool i_val) { m_isAutoloadEnabled = i_val; }
@@ -162,18 +160,10 @@ public:
     void        AddCustomProperty(  const OUString& sName,
                                     const com::sun::star::uno::Any& rValue );
 
-    std::vector< CmisProperty* >  GetCmisProperties() const;
-
     ::com::sun::star::uno::Sequence< ::com::sun::star::document::CmisProperty >
-                        GetCmisPropertiesSeq() const;
-
-    void        ClearCmisProperties();
-    void        AddCmisProperty(  const OUString& sId, const OUString& sName,
-                                  const bool bUpdatable, const bool bRequired,
-                                  const bool bMultiValued, const bool bOpenChoice,
-                                  const com::sun::star::uno::Any& Choices,
-                                  const com::sun::star::uno::Any& rValue );
+                        GetCmisProperties() const;
 
+    void        SetCmisProperties(::com::sun::star::uno::Sequence< ::com::sun::star::document::CmisProperty > cmisProps );
     virtual SfxPoolItem*    Clone( SfxItemPool* pPool = NULL ) const;
     virtual int             operator==( const SfxPoolItem& ) const;
     virtual bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const;
diff --git a/sfx2/source/dialog/dinfdlg.cxx b/sfx2/source/dialog/dinfdlg.cxx
index 205b0b5..ba9b364 100644
--- a/sfx2/source/dialog/dinfdlg.cxx
+++ b/sfx2/source/dialog/dinfdlg.cxx
@@ -91,47 +91,6 @@ struct CustomProperty
     { return m_sName.equals( rProp.m_sName ) && m_aValue == rProp.m_aValue; }
 };
 
-struct CmisProperty
-{
-    OUString                    m_sId;
-    OUString                    m_sName;
-    bool                        m_bUpdatable;
-    bool                        m_bRequired;
-    bool                        m_bMultiValued;
-    bool                        m_bOpenChoice;
-    com::sun::star::uno::Any    m_aChoices;
-    com::sun::star::uno::Any    m_aValue;
-
-    CmisProperty( const OUString& sId,
-                  const OUString& sName,
-                  const bool bUpdatable,
-                  const bool bRequired,
-                  const bool bMultiValued,
-                  const bool bOpenChoice,
-                  const com::sun::star::uno::Any& aChoices,
-                  const com::sun::star::uno::Any& rValue ) :
-                m_sId( sId ),
-                m_sName( sName ),
-                m_bUpdatable( bUpdatable ),
-                m_bRequired( bRequired ),
-                m_bMultiValued( bMultiValued ),
-                m_bOpenChoice( bOpenChoice ),
-                m_aChoices( aChoices),
-                m_aValue( rValue )
-        {}
-
-    inline bool operator==( const CmisProperty& rProp )
-    { return m_sId.equals( rProp.m_sId )
-          && m_sName         == rProp.m_sName
-          && m_bUpdatable    == rProp.m_bUpdatable
-          && m_bRequired     == rProp.m_bRequired
-          && m_bMultiValued  == rProp.m_bMultiValued
-          && m_bOpenChoice   == rProp.m_bOpenChoice
-          && m_aChoices      == rProp.m_aChoices
-          && m_aValue        == rProp.m_aValue;
-    }
-};
-
 static
 bool operator==(const util::DateTime &i_rLeft, const util::DateTime &i_rRight)
 {
@@ -312,18 +271,8 @@ SfxDocumentInfoItem::SfxDocumentInfoItem( const String& rFile,
             }
         }
 
-        for ( sal_Int32 i = 0; i < i_cmisProps.getLength(); ++i )
-        {
-           CmisProperty* pProp = new CmisProperty( i_cmisProps[i].Id,
-                                                   i_cmisProps[i].Name,
-                                                   i_cmisProps[i].Updatable,
-                                                   i_cmisProps[i].Required,
-                                                   i_cmisProps[i].MultiValued,
-                                                   i_cmisProps[i].OpenChoice,
-                                                   i_cmisProps[i].Choices,
-                                                   i_cmisProps[i].Value );
-           m_aCmisProperties.push_back( pProp );
-        }
+        // get CMIS properties
+        m_aCmisProperties = i_cmisProps;
     }
     catch ( Exception& ) {}
 }
@@ -359,25 +308,14 @@ SfxDocumentInfoItem::SfxDocumentInfoItem( const SfxDocumentInfoItem& rItem )
                                                     rItem.m_aCustomProperties[i]->m_aValue );
         m_aCustomProperties.push_back( pProp );
     }
-    for ( sal_uInt32 i = 0; i < rItem.m_aCmisProperties.size(); i++ )
-    {
-        CmisProperty* pProp = new CmisProperty( rItem.m_aCmisProperties[i]->m_sId,
-                                                rItem.m_aCmisProperties[i]->m_sName,
-                                                rItem.m_aCmisProperties[i]->m_bUpdatable,
-                                                rItem.m_aCmisProperties[i]->m_bRequired,
-                                                rItem.m_aCmisProperties[i]->m_bMultiValued,
-                                                rItem.m_aCmisProperties[i]->m_bOpenChoice,
-                                                rItem.m_aCmisProperties[i]->m_aChoices,
-                                                rItem.m_aCmisProperties[i]->m_aValue );
-        m_aCmisProperties.push_back( pProp );
-    }
+
+    m_aCmisProperties = rItem.m_aCmisProperties;
 }
 
 //------------------------------------------------------------------------
 SfxDocumentInfoItem::~SfxDocumentInfoItem()
 {
     ClearCustomProperties();
-    ClearCmisProperties();
 }
 
 //------------------------------------------------------------------------
@@ -412,11 +350,8 @@ int SfxDocumentInfoItem::operator==( const SfxPoolItem& rItem) const
          m_Title                == rInfoItem.m_Title             &&
          m_aCustomProperties.size() == rInfoItem.m_aCustomProperties.size() &&
          std::equal(m_aCustomProperties.begin(), m_aCustomProperties.end(),
-            rInfoItem.m_aCustomProperties.begin());
-
-         m_aCmisProperties.size() == rInfoItem.m_aCmisProperties.size() &&
-         std::equal(m_aCmisProperties.begin(), m_aCmisProperties.end(),
-            rInfoItem.m_aCmisProperties.begin());
+            rInfoItem.m_aCustomProperties.begin()) &&
+         m_aCmisProperties.getLength() == rInfoItem.m_aCmisProperties.getLength();
 }
 
 //------------------------------------------------------------------------
@@ -554,69 +489,14 @@ void SfxDocumentInfoItem::AddCustomProperty( const OUString& sName, const Any& r
     m_aCustomProperties.push_back( pProp );
 }
 
-
-std::vector< CmisProperty* > SfxDocumentInfoItem::GetCmisProperties() const
-{
-    std::vector< CmisProperty* > aRet;
-    for ( sal_uInt32 i = 0; i < m_aCmisProperties.size(); i++ )
-    {
-        CmisProperty* pProp = new CmisProperty( m_aCmisProperties[i]->m_sId,
-                                                m_aCmisProperties[i]->m_sName,
-                                                m_aCmisProperties[i]->m_bUpdatable,
-                                                m_aCmisProperties[i]->m_bRequired,
-                                                m_aCmisProperties[i]->m_bMultiValued,
-                                                m_aCmisProperties[i]->m_bOpenChoice,
-                                                m_aCmisProperties[i]->m_aChoices,
-                                                m_aCmisProperties[i]->m_aValue );
-        aRet.push_back( pProp );
-    }
-
-    return aRet;
-}
-
-uno::Sequence< document::CmisProperty > SfxDocumentInfoItem::GetCmisPropertiesSeq() const
+uno::Sequence< document::CmisProperty > SfxDocumentInfoItem::GetCmisProperties() const
 {
-    Sequence< document::CmisProperty > aPropertiesSeq( m_aCmisProperties.size( ) );
-    std::vector< CmisProperty* >::const_iterator pIter;
-
-    sal_Int32 i = 0;
-    for ( pIter = m_aCmisProperties.begin();
-        pIter != m_aCmisProperties.end(); ++pIter, i++ )
-    {
-        CmisProperty* aProp = *pIter;
-        aPropertiesSeq[i].Id = aProp->m_sId;
-        aPropertiesSeq[i].Name = aProp->m_sName;
-        aPropertiesSeq[i].Updatable = aProp->m_bUpdatable;
-        aPropertiesSeq[i].Required = aProp->m_bRequired;
-        aPropertiesSeq[i].MultiValued = aProp->m_bMultiValued;
-        aPropertiesSeq[i].OpenChoice = aProp->m_bOpenChoice;
-        aPropertiesSeq[i].Choices = aProp->m_aChoices;
-        aPropertiesSeq[i].Value = aProp->m_aValue;
-    }
-
-    return aPropertiesSeq;
+    return m_aCmisProperties;
 }
 
-void SfxDocumentInfoItem::ClearCmisProperties()
+void SfxDocumentInfoItem::SetCmisProperties( Sequence< document::CmisProperty > cmisProps)
 {
-    for ( sal_uInt32 i = 0; i < m_aCmisProperties.size(); i++ )
-        delete m_aCmisProperties[i];
-    m_aCmisProperties.clear();
-}
-
-void SfxDocumentInfoItem::AddCmisProperty( const OUString& sId,
-                                           const OUString& sName,
-                                           const bool bUpdatable,
-                                           const bool bRequired,
-                                           const bool bMultiValued,
-                                           const bool bOpenChoice,
-                                           const Any& aChoices,
-                                           const Any& aValue )
-{
-    CmisProperty* pProp = new CmisProperty( sId, sName, bUpdatable,
-                                            bRequired, bMultiValued,
-                                            bOpenChoice, aChoices, aValue );
-    m_aCmisProperties.push_back( pProp );
+    m_aCmisProperties = cmisProps;
 }
 
 bool SfxDocumentInfoItem::QueryValue( Any& rVal, sal_uInt8 nMemberId ) const
@@ -2821,7 +2701,6 @@ SfxCmisPropertiesPage::SfxCmisPropertiesPage( Window* pParent, const SfxItemSet&
 
 sal_Bool SfxCmisPropertiesPage::FillItemSet( SfxItemSet& rSet )
 {
-    sal_Bool bModified = sal_False;
     const SfxPoolItem* pItem = NULL;
     SfxDocumentInfoItem* pInfo = NULL;
     bool bMustDelete = false;
@@ -2838,56 +2717,58 @@ sal_Bool SfxCmisPropertiesPage::FillItemSet( SfxItemSet& rSet )
         }
     }
 
+    sal_Int32 modifiedNum = 0;
     if ( pInfo )
     {
-        Sequence< document::CmisProperty > aOldProps = pInfo->GetCmisPropertiesSeq( );
-        pInfo->ClearCmisProperties();
-        Sequence< document::CmisProperty > aPropertySeq = m_pPropertiesCtrl->GetCmisProperties();
+        Sequence< document::CmisProperty > aOldProps = pInfo->GetCmisProperties( );
+        Sequence< document::CmisProperty > aNewProps = m_pPropertiesCtrl->GetCmisProperties();
 
-        for ( sal_Int32 i = 0; i< aPropertySeq.getLength( ); i++  )
+        for ( sal_Int32 i = 0; i< aNewProps.getLength( ); i++  )
         {
             OUString oldValue;
             aOldProps[i].Value >>= oldValue;
             OUString newValue;
-            aPropertySeq[i].Value >>= newValue;
-            if ( !aPropertySeq[i].Id.isEmpty() &&
-                  aPropertySeq[i].Updatable &&
-                  oldValue != newValue )
-            {
-                pInfo->AddCmisProperty( aPropertySeq[i].Id,
-                                        aPropertySeq[i].Name,
-                                        aPropertySeq[i].Updatable,
-                                        aPropertySeq[i].Required,
-                                        aPropertySeq[i].MultiValued,
-                                        aPropertySeq[i].OpenChoice,
-                                        aPropertySeq[i].Choices,
-                                        aPropertySeq[i].Value );
-                bModified = true;
-            }
+            aNewProps[i].Value >>= newValue;
+            if ( !aNewProps[i].Id.isEmpty() && aNewProps[i].Updatable && oldValue != newValue )
+                modifiedNum++;
+        }
+        Sequence< document::CmisProperty> aModifiedProps( modifiedNum );
+        sal_Int32 nCount = 0;
+        for ( sal_Int32 i = 0; i< aNewProps.getLength( ); i++  )
+        {
+            OUString oldValue;
+            aOldProps[i].Value >>= oldValue;
+            OUString newValue;
+            aNewProps[i].Value >>= newValue;
+            if ( !aNewProps[i].Id.isEmpty() && aNewProps[i].Updatable && oldValue != newValue )
+                aModifiedProps[ nCount++ ] = aNewProps[i];
         }
+
+        pInfo->SetCmisProperties( aModifiedProps );
+
     }
 
     rSet.Put( *pInfo );
     if ( bMustDelete )
         delete pInfo;
-    return bModified;
+    return modifiedNum;
 }
 
 void SfxCmisPropertiesPage::Reset( const SfxItemSet& rItemSet )
 {
     m_pPropertiesCtrl->ClearAllLines();
     const SfxDocumentInfoItem* m_pInfoItem = &(const SfxDocumentInfoItem &)rItemSet.Get(SID_DOCINFO);
-    std::vector< CmisProperty* > aCmisProps = m_pInfoItem->GetCmisProperties();
-    for ( sal_uInt32 i = 0; i < aCmisProps.size(); i++ )
-    {
-        m_pPropertiesCtrl->AddLine( aCmisProps[i]->m_sId,
-                                    aCmisProps[i]->m_sName,
-                                    aCmisProps[i]->m_bUpdatable,
-                                    aCmisProps[i]->m_bRequired,
-                                    aCmisProps[i]->m_bMultiValued,
-                                    aCmisProps[i]->m_bOpenChoice,
-                                    aCmisProps[i]->m_aChoices,
-                                    aCmisProps[i]->m_aValue, false );
+    uno::Sequence< document::CmisProperty > aCmisProps = m_pInfoItem->GetCmisProperties();
+    for ( sal_uInt32 i = 0; i < aCmisProps.getLength(); i++ )
+    {
+        m_pPropertiesCtrl->AddLine( aCmisProps[i].Id,
+                                    aCmisProps[i].Name,
+                                    aCmisProps[i].Updatable,
+                                    aCmisProps[i].Required,
+                                    aCmisProps[i].MultiValued,
+                                    aCmisProps[i].OpenChoice,
+                                    aCmisProps[i].Choices,
+                                    aCmisProps[i].Value, false );
     }
 }
 
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 8c63652..5e04bb6 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -519,7 +519,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
                         // user has done some changes to DocumentInfo
                         pDocInfoItem->UpdateDocumentInfo(getDocProperties());
                         uno::Sequence< document::CmisProperty > aNewCmisProperties =
-                            pDocInfoItem->GetCmisPropertiesSeq( );
+                            pDocInfoItem->GetCmisProperties( );
                         if ( aNewCmisProperties.getLength( ) > 0 )
                             xCmisDoc->updateCmisProperties( aNewCmisProperties );
                         SetUseUserData( ((const SfxDocumentInfoItem *)pDocInfoItem)->IsUseUserData() );


More information about the Libreoffice-commits mailing list