[Libreoffice-commits] core.git: 2 commits - include/sfx2 include/svl sc/source sfx2/source svl/source sw/inc sw/source

Noel Grandin noel at peralex.com
Wed Apr 15 04:38:42 PDT 2015


 include/sfx2/docfile.hxx              |    3 -
 include/svl/documentlockfile.hxx      |    4 -
 include/svl/lockfilecommon.hxx        |   20 +++---
 include/svl/mailenum.hxx              |   10 ---
 include/svl/sharecontrolfile.hxx      |   20 ++----
 sc/source/ui/docshell/docsh.cxx       |   17 ++---
 sc/source/ui/docshell/docsh4.cxx      |   17 ++---
 sc/source/ui/miscdlgs/sharedocdlg.cxx |   19 +++---
 sfx2/source/doc/docfile.cxx           |   38 +++++-------
 svl/source/misc/documentlockfile.cxx  |   28 ++++-----
 svl/source/misc/lockfilecommon.cxx    |   38 +++++-------
 svl/source/misc/sharecontrolfile.cxx  |  100 ++++++++++++++--------------------
 sw/inc/modcfg.hxx                     |   26 +++++++-
 sw/source/ui/envelp/mailmrge.cxx      |   16 ++---
 sw/source/uibase/config/modcfg.cxx    |    6 +-
 15 files changed, 166 insertions(+), 196 deletions(-)

New commits:
commit f0461e8360e13137c29dfcc1d20ba93e7bbd3073
Author: Noel Grandin <noel at peralex.com>
Date:   Tue Apr 14 13:47:01 2015 +0200

    convert LOCKFILE_ constants to scoped enum and cleanup
    
    Change-Id: I9a2339cc953a718403b3cd0960d5d8d34abae455
    Reviewed-on: https://gerrit.libreoffice.org/15304
    Tested-by: Noel Grandin <noelgrandin at gmail.com>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/include/sfx2/docfile.hxx b/include/sfx2/docfile.hxx
index 2964e19..f6f4fb1 100644
--- a/include/sfx2/docfile.hxx
+++ b/include/sfx2/docfile.hxx
@@ -24,6 +24,7 @@
 #include <sal/config.h>
 #include <sfx2/dllapi.h>
 #include <sfx2/signaturestate.hxx>
+#include <svl/lockfilecommon.hxx>
 #include <sal/types.h>
 #include <com/sun/star/util/RevisionTag.hpp>
 #include <com/sun/star/util/DateTime.hpp>
@@ -160,7 +161,7 @@ public:
     bool                Commit();
     bool                IsStorage();
 
-    sal_Int8            ShowLockedDocumentDialog( const css::uno::Sequence< OUString >& aData, bool bIsLoading, bool bOwnLock );
+    sal_Int8            ShowLockedDocumentDialog( const LockFileEntry& aData, bool bIsLoading, bool bOwnLock );
     void                LockOrigFileOnDemand( bool bLoading, bool bNoUI );
     void                UnlockFile( bool bReleaseLockStream );
 
diff --git a/include/svl/documentlockfile.hxx b/include/svl/documentlockfile.hxx
index e698a0e..9449994 100644
--- a/include/svl/documentlockfile.hxx
+++ b/include/svl/documentlockfile.hxx
@@ -39,14 +39,14 @@ class SVL_DLLPUBLIC DocumentLockFile : public LockFileCommon
 
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > OpenStream();
 
-    void WriteEntryToStream( const ::com::sun::star::uno::Sequence< OUString >& aEntry, ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xStream );
+    void WriteEntryToStream( const LockFileEntry& aEntry, ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xStream );
 
 public:
     DocumentLockFile( const OUString& aOrigURL );
     ~DocumentLockFile();
 
     bool CreateOwnLockFile();
-    ::com::sun::star::uno::Sequence< OUString > GetLockData();
+    LockFileEntry GetLockData();
     bool OverwriteOwnLockFile();
     void RemoveFile();
 
diff --git a/include/svl/lockfilecommon.hxx b/include/svl/lockfilecommon.hxx
index 7f32d84..767df06 100644
--- a/include/svl/lockfilecommon.hxx
+++ b/include/svl/lockfilecommon.hxx
@@ -30,13 +30,15 @@
 
 #include <osl/mutex.hxx>
 #include <tools/urlobj.hxx>
+#include <o3tl/enumarray.hxx>
+#include <vector>
 
-#define LOCKFILE_OOOUSERNAME_ID   0
-#define LOCKFILE_SYSUSERNAME_ID   1
-#define LOCKFILE_LOCALHOST_ID     2
-#define LOCKFILE_EDITTIME_ID      3
-#define LOCKFILE_USERURL_ID       4
-#define LOCKFILE_ENTRYSIZE        5
+enum class LockFileComponent
+{
+    OOOUSERNAME, SYSUSERNAME, LOCALHOST, EDITTIME, USERURL, LAST=USERURL
+};
+
+typedef o3tl::enumarray<LockFileComponent,OUString> LockFileEntry;
 
 namespace svt {
 
@@ -53,13 +55,13 @@ public:
     LockFileCommon( const OUString& aOrigURL, const OUString& aPrefix );
     ~LockFileCommon();
 
-    static ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< OUString > > ParseList( const ::com::sun::star::uno::Sequence< sal_Int8 >& aBuffer );
-    static ::com::sun::star::uno::Sequence< OUString > ParseEntry( const ::com::sun::star::uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& o_nCurPos );
+    static void ParseList( const ::com::sun::star::uno::Sequence< sal_Int8 >& aBuffer, std::vector< LockFileEntry > &rOutput );
+    static LockFileEntry ParseEntry( const ::com::sun::star::uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& o_nCurPos );
     static OUString ParseName( const ::com::sun::star::uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& o_nCurPos );
     static OUString EscapeCharacters( const OUString& aSource );
     static OUString GetOOOUserName();
     static OUString GetCurrentLocalTime();
-    static ::com::sun::star::uno::Sequence< OUString > GenerateOwnEntry();
+    static LockFileEntry GenerateOwnEntry();
 };
 
 }
diff --git a/include/svl/sharecontrolfile.hxx b/include/svl/sharecontrolfile.hxx
index 04f46d7..26ec507 100644
--- a/include/svl/sharecontrolfile.hxx
+++ b/include/svl/sharecontrolfile.hxx
@@ -29,13 +29,8 @@
 #include <com/sun/star/io/XTruncate.hpp>
 
 #include <svl/lockfilecommon.hxx>
-
-#define SHARED_OOOUSERNAME_ID   LOCKFILE_OOOUSERNAME_ID
-#define SHARED_SYSUSERNAME_ID   LOCKFILE_SYSUSERNAME_ID
-#define SHARED_LOCALHOST_ID     LOCKFILE_LOCALHOST_ID
-#define SHARED_EDITTIME_ID      LOCKFILE_EDITTIME_ID
-#define SHARED_USERURL_ID       LOCKFILE_USERURL_ID
-#define SHARED_ENTRYSIZE        LOCKFILE_ENTRYSIZE
+#include <o3tl/enumarray.hxx>
+#include <vector>
 
 namespace svt {
 
@@ -47,7 +42,7 @@ class SVL_DLLPUBLIC ShareControlFile : public LockFileCommon
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable > m_xSeekable;
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XTruncate > m_xTruncate;
 
-    ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< OUString > > m_aUsersData;
+    std::vector< LockFileEntry > m_aUsersData;
 
     void OpenStream();
     void Close();
@@ -62,11 +57,12 @@ public:
     ShareControlFile( const OUString& aOrigURL );
     ~ShareControlFile();
 
-    ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< OUString > > GetUsersData();
-    void SetUsersDataAndStore( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< OUString > >& aUserNames );
-    ::com::sun::star::uno::Sequence< OUString > InsertOwnEntry();
+    std::vector< LockFileEntry > GetUsersData();
+    void SetUsersDataAndStore( const std::vector< LockFileEntry >& aUserNames );
+    LockFileEntry InsertOwnEntry();
     bool HasOwnEntry();
-    void RemoveEntry( const ::com::sun::star::uno::Sequence< OUString >& aOptionalSpecification = ::com::sun::star::uno::Sequence< OUString >() );
+    void RemoveEntry( const LockFileEntry& aOptionalSpecification );
+    void RemoveEntry();
     void RemoveFile();
 };
 
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 79ce486..a422041 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -793,17 +793,14 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
                                         try
                                         {
                                             ::svt::DocumentLockFile aLockFile( GetSharedFileURL() );
-                                            uno::Sequence< OUString > aData = aLockFile.GetLockData();
-                                            if ( aData.getLength() > LOCKFILE_SYSUSERNAME_ID )
+                                            LockFileEntry aData = aLockFile.GetLockData();
+                                            if ( !aData[LockFileComponent::OOOUSERNAME].isEmpty() )
                                             {
-                                                if ( !aData[LOCKFILE_OOOUSERNAME_ID].isEmpty() )
-                                                {
-                                                    aUserName = aData[LOCKFILE_OOOUSERNAME_ID];
-                                                }
-                                                else if ( !aData[LOCKFILE_SYSUSERNAME_ID].isEmpty() )
-                                                {
-                                                    aUserName = aData[LOCKFILE_SYSUSERNAME_ID];
-                                                }
+                                                aUserName = aData[LockFileComponent::OOOUSERNAME];
+                                            }
+                                            else if ( !aData[LockFileComponent::SYSUSERNAME].isEmpty() )
+                                            {
+                                                aUserName = aData[LockFileComponent::SYSUSERNAME];
                                             }
                                         }
                                         catch ( uno::Exception& )
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index a9dd15c..4a9c0d7 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -997,17 +997,14 @@ void ScDocShell::Execute( SfxRequest& rReq )
                                         try
                                         {
                                             ::svt::DocumentLockFile aLockFile( GetSharedFileURL() );
-                                            uno::Sequence< OUString > aData = aLockFile.GetLockData();
-                                            if ( aData.getLength() > LOCKFILE_SYSUSERNAME_ID )
+                                            LockFileEntry aData = aLockFile.GetLockData();
+                                            if ( !aData[LockFileComponent::OOOUSERNAME].isEmpty() )
                                             {
-                                                if ( !aData[LOCKFILE_OOOUSERNAME_ID].isEmpty() )
-                                                {
-                                                    aUserName = aData[LOCKFILE_OOOUSERNAME_ID];
-                                                }
-                                                else if ( !aData[LOCKFILE_SYSUSERNAME_ID].isEmpty() )
-                                                {
-                                                    aUserName = aData[LOCKFILE_SYSUSERNAME_ID];
-                                                }
+                                                aUserName = aData[LockFileComponent::OOOUSERNAME];
+                                            }
+                                            else if ( !aData[LockFileComponent::SYSUSERNAME].isEmpty() )
+                                            {
+                                                aUserName = aData[LockFileComponent::SYSUSERNAME];
                                             }
                                         }
                                         catch ( uno::Exception& )
diff --git a/sc/source/ui/miscdlgs/sharedocdlg.cxx b/sc/source/ui/miscdlgs/sharedocdlg.cxx
index d934ff7..911b74d 100644
--- a/sc/source/ui/miscdlgs/sharedocdlg.cxx
+++ b/sc/source/ui/miscdlgs/sharedocdlg.cxx
@@ -135,9 +135,8 @@ void ScShareDocumentDlg::UpdateView()
         try
         {
             ::svt::ShareControlFile aControlFile( mpDocShell->GetSharedFileURL() );
-            uno::Sequence< uno::Sequence< OUString > > aUsersData = aControlFile.GetUsersData();
-            const uno::Sequence< OUString >* pUsersData = aUsersData.getConstArray();
-            sal_Int32 nLength = aUsersData.getLength();
+            std::vector<LockFileEntry> aUsersData = aControlFile.GetUsersData();
+            sal_Int32 nLength = aUsersData.size();
 
             if ( nLength > 0 )
             {
@@ -145,24 +144,24 @@ void ScShareDocumentDlg::UpdateView()
 
                 for ( sal_Int32 i = 0; i < nLength; ++i )
                 {
-                    if ( pUsersData[i].getLength() > SHARED_EDITTIME_ID )
+                    if ( !aUsersData[i][LockFileComponent::EDITTIME].isEmpty() )
                     {
                         OUString aUser;
-                        if ( !pUsersData[i][SHARED_OOOUSERNAME_ID].isEmpty() )
+                        if ( !aUsersData[i][LockFileComponent::OOOUSERNAME].isEmpty() )
                         {
-                            aUser = pUsersData[i][SHARED_OOOUSERNAME_ID];
+                            aUser = aUsersData[i][LockFileComponent::OOOUSERNAME];
                         }
-                        else if ( !pUsersData[i][SHARED_SYSUSERNAME_ID].isEmpty() )
+                        else if ( !aUsersData[i][LockFileComponent::SYSUSERNAME].isEmpty() )
                         {
-                            aUser = pUsersData[i][SHARED_SYSUSERNAME_ID];
+                            aUser = aUsersData[i][LockFileComponent::SYSUSERNAME];
                         }
                         else
                         {
-                            aUser = OUString(m_aStrUnknownUser) + " " + OUString::number( nUnknownUser++ );
+                            aUser = m_aStrUnknownUser + " " + OUString::number( nUnknownUser++ );
                         }
 
                         // parse the edit time string of the format "DD.MM.YYYY hh:mm"
-                        OUString aDateTimeStr = pUsersData[i][SHARED_EDITTIME_ID];
+                        OUString aDateTimeStr = aUsersData[i][LockFileComponent::EDITTIME];
                         sal_Int32 nIndex = 0;
                         OUString aDateStr = aDateTimeStr.getToken( 0, ' ', nIndex );
                         OUString aTimeStr = aDateTimeStr.getToken( 0, ' ', nIndex );
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index cdd18ce..8fff9b0 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -823,7 +823,7 @@ void SfxMedium::SetEncryptionDataToStorage_Impl()
 // not for some URL scheme belongs in UCB, not here.
 
 
-sal_Int8 SfxMedium::ShowLockedDocumentDialog( const uno::Sequence< OUString >& aData, bool bIsLoading, bool bOwnLock )
+sal_Int8 SfxMedium::ShowLockedDocumentDialog( const LockFileEntry& aData, bool bIsLoading, bool bOwnLock )
 {
     sal_Int8 nResult = LOCK_UI_NOLOCK;
 
@@ -838,27 +838,23 @@ sal_Int8 SfxMedium::ShowLockedDocumentDialog( const uno::Sequence< OUString >& a
 
         if ( bOwnLock )
         {
-            if ( aData.getLength() > LOCKFILE_EDITTIME_ID )
-                aInfo = aData[LOCKFILE_EDITTIME_ID];
+            aInfo = aData[LockFileComponent::EDITTIME];
 
             xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny(
                 document::OwnLockOnDocumentRequest( OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo, !bIsLoading ) ) );
         }
         else /*logically therefore bIsLoading is set */
         {
-            if ( aData.getLength() > LOCKFILE_EDITTIME_ID )
-            {
-                if ( !aData[LOCKFILE_OOOUSERNAME_ID].isEmpty() )
-                    aInfo = aData[LOCKFILE_OOOUSERNAME_ID];
-                else
-                    aInfo = aData[LOCKFILE_SYSUSERNAME_ID];
+            if ( !aData[LockFileComponent::OOOUSERNAME].isEmpty() )
+                aInfo = aData[LockFileComponent::OOOUSERNAME];
+            else
+                aInfo = aData[LockFileComponent::SYSUSERNAME];
 
-                if ( !aInfo.isEmpty() && !aData[LOCKFILE_EDITTIME_ID].isEmpty() )
-                {
-                    aInfo +=  " ( " ;
-                    aInfo += aData[LOCKFILE_EDITTIME_ID];
-                    aInfo += " )";
-                }
+            if ( !aInfo.isEmpty() && !aData[LockFileComponent::EDITTIME].isEmpty() )
+            {
+                aInfo +=  " ( " ;
+                aInfo += aData[LockFileComponent::EDITTIME];
+                aInfo += " )";
             }
 
             xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny(
@@ -1104,7 +1100,7 @@ void SfxMedium::LockOrigFileOnDemand( bool bLoading, bool bNoUI )
 
                             if ( !bResult )
                             {
-                                uno::Sequence< OUString > aData;
+                                LockFileEntry aData;
                                 try
                                 {
                                     // impossibility to get data is no real problem
@@ -1118,14 +1114,12 @@ void SfxMedium::LockOrigFileOnDemand( bool bLoading, bool bNoUI )
 
                                 if ( !bHandleSysLocked )
                                 {
-                                    uno::Sequence< OUString > aOwnData = svt::LockFileCommon::GenerateOwnEntry();
-                                    bOwnLock = ( aData.getLength() > LOCKFILE_USERURL_ID
-                                              && aOwnData.getLength() > LOCKFILE_USERURL_ID
-                                              && aOwnData[LOCKFILE_SYSUSERNAME_ID].equals( aData[LOCKFILE_SYSUSERNAME_ID] ) );
+                                    LockFileEntry aOwnData = svt::LockFileCommon::GenerateOwnEntry();
+                                    bOwnLock = aOwnData[LockFileComponent::SYSUSERNAME].equals( aData[LockFileComponent::SYSUSERNAME] );
 
                                     if ( bOwnLock
-                                      && aOwnData[LOCKFILE_LOCALHOST_ID].equals( aData[LOCKFILE_LOCALHOST_ID] )
-                                      && aOwnData[LOCKFILE_USERURL_ID].equals( aData[LOCKFILE_USERURL_ID] ) )
+                                      && aOwnData[LockFileComponent::LOCALHOST].equals( aData[LockFileComponent::LOCALHOST] )
+                                      && aOwnData[LockFileComponent::USERURL].equals( aData[LockFileComponent::USERURL] ) )
                                     {
                                         // this is own lock from the same installation, it could remain because of crash
                                         bResult = true;
diff --git a/svl/source/misc/documentlockfile.cxx b/svl/source/misc/documentlockfile.cxx
index 71b84f9..db7b769 100644
--- a/svl/source/misc/documentlockfile.cxx
+++ b/svl/source/misc/documentlockfile.cxx
@@ -30,6 +30,7 @@
 #include <osl/time.h>
 #include <osl/security.hxx>
 #include <osl/socket.hxx>
+#include <o3tl/enumrange.hxx>
 
 #include <rtl/string.hxx>
 #include <rtl/ustring.hxx>
@@ -64,16 +65,16 @@ DocumentLockFile::~DocumentLockFile()
 }
 
 
-void DocumentLockFile::WriteEntryToStream( const uno::Sequence< OUString >& aEntry, uno::Reference< io::XOutputStream > xOutput )
+void DocumentLockFile::WriteEntryToStream( const LockFileEntry& aEntry, uno::Reference< io::XOutputStream > xOutput )
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
     OUStringBuffer aBuffer;
 
-    for ( sal_Int32 nEntryInd = 0; nEntryInd < aEntry.getLength(); nEntryInd++ )
+    for ( LockFileComponent lft : o3tl::enumrange<LockFileComponent>() )
     {
-        aBuffer.append( EscapeCharacters( aEntry[nEntryInd] ) );
-        if ( nEntryInd < aEntry.getLength() - 1 )
+        aBuffer.append( EscapeCharacters( aEntry[lft] ) );
+        if ( lft < LockFileComponent::LAST )
             aBuffer.append( ',' );
         else
             aBuffer.append( ';' );
@@ -102,7 +103,7 @@ bool DocumentLockFile::CreateOwnLockFile()
         if ( !xInput.is() || !xOutput.is() )
             throw uno::RuntimeException();
 
-        uno::Sequence< OUString > aNewEntry = GenerateOwnEntry();
+        LockFileEntry aNewEntry = GenerateOwnEntry();
         WriteEntryToStream( aNewEntry, xOutput );
         xOutput->closeOutput();
 
@@ -132,7 +133,7 @@ bool DocumentLockFile::CreateOwnLockFile()
 }
 
 
-uno::Sequence< OUString > DocumentLockFile::GetLockData()
+LockFileEntry DocumentLockFile::GetLockData()
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
@@ -176,7 +177,7 @@ bool DocumentLockFile::OverwriteOwnLockFile()
         uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv;
         ::ucbhelper::Content aTargetContent( m_aURL, xEnv, comphelper::getProcessComponentContext() );
 
-        uno::Sequence< OUString > aNewEntry = GenerateOwnEntry();
+        LockFileEntry aNewEntry = GenerateOwnEntry();
 
         uno::Reference< io::XStream > xStream = aTargetContent.openWriteableStreamNoLock();
         uno::Reference< io::XOutputStream > xOutput = xStream->getOutputStream();
@@ -200,15 +201,12 @@ void DocumentLockFile::RemoveFile()
     ::osl::MutexGuard aGuard( m_aMutex );
 
     // TODO/LATER: the removing is not atomic, is it possible in general to make it atomic?
-    uno::Sequence< OUString > aNewEntry = GenerateOwnEntry();
-    uno::Sequence< OUString > aFileData = GetLockData();
+    LockFileEntry aNewEntry = GenerateOwnEntry();
+    LockFileEntry aFileData = GetLockData();
 
-    if ( aFileData.getLength() < LOCKFILE_ENTRYSIZE )
-        throw io::WrongFormatException();
-
-    if ( !aFileData[LOCKFILE_SYSUSERNAME_ID].equals( aNewEntry[LOCKFILE_SYSUSERNAME_ID] )
-      || !aFileData[LOCKFILE_LOCALHOST_ID].equals( aNewEntry[LOCKFILE_LOCALHOST_ID] )
-      || !aFileData[LOCKFILE_USERURL_ID].equals( aNewEntry[LOCKFILE_USERURL_ID] ) )
+    if ( !aFileData[LockFileComponent::SYSUSERNAME].equals( aNewEntry[LockFileComponent::SYSUSERNAME] )
+      || !aFileData[LockFileComponent::LOCALHOST].equals( aNewEntry[LockFileComponent::LOCALHOST] )
+      || !aFileData[LockFileComponent::USERURL].equals( aNewEntry[LockFileComponent::USERURL] ) )
         throw io::IOException(); // not the owner, access denied
 
     uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv;
diff --git a/svl/source/misc/lockfilecommon.cxx b/svl/source/misc/lockfilecommon.cxx
index ea0a596..e19bd44 100644
--- a/svl/source/misc/lockfilecommon.cxx
+++ b/svl/source/misc/lockfilecommon.cxx
@@ -30,6 +30,7 @@
 #include <osl/security.hxx>
 #include <osl/socket.hxx>
 #include <osl/file.hxx>
+#include <o3tl/enumrange.hxx>
 
 #include <rtl/string.hxx>
 #include <rtl/ustring.hxx>
@@ -95,35 +96,26 @@ INetURLObject LockFileCommon::ResolveLinks( const INetURLObject& aDocURL )
 }
 
 
-uno::Sequence< uno::Sequence< OUString > > LockFileCommon::ParseList( const uno::Sequence< sal_Int8 >& aBuffer )
+void LockFileCommon::ParseList( const uno::Sequence< sal_Int8 >& aBuffer, std::vector< LockFileEntry > & aResult )
 {
     sal_Int32 nCurPos = 0;
-    sal_Int32 nCurEntry = 0;
-    uno::Sequence< uno::Sequence< OUString > > aResult( 10 );
-
     while ( nCurPos < aBuffer.getLength() )
     {
-        if ( nCurEntry >= aResult.getLength() )
-            aResult.realloc( nCurEntry + 10 );
-        aResult[nCurEntry] = ParseEntry( aBuffer, nCurPos );
-        nCurEntry++;
+        aResult.push_back( ParseEntry( aBuffer, nCurPos ) );
     }
-
-    aResult.realloc( nCurEntry );
-    return aResult;
 }
 
 
-uno::Sequence< OUString > LockFileCommon::ParseEntry( const uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& io_nCurPos )
+LockFileEntry LockFileCommon::ParseEntry( const uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& io_nCurPos )
 {
-    uno::Sequence< OUString > aResult( LOCKFILE_ENTRYSIZE );
+    LockFileEntry aResult;
 
-    for ( int nInd = 0; nInd < LOCKFILE_ENTRYSIZE; nInd++ )
+    for ( LockFileComponent nInd : o3tl::enumrange<LockFileComponent>() )
     {
         aResult[nInd] = ParseName( aBuffer, io_nCurPos );
         if ( io_nCurPos >= aBuffer.getLength()
-          || ( nInd < LOCKFILE_ENTRYSIZE - 1 && aBuffer[io_nCurPos++] != ',' )
-          || ( nInd == LOCKFILE_ENTRYSIZE - 1 && aBuffer[io_nCurPos++] != ';' ) )
+          || ( nInd < LockFileComponent::LAST && aBuffer[io_nCurPos++] != ',' )
+          || ( nInd == LockFileComponent::LAST && aBuffer[io_nCurPos++] != ';' ) )
             throw io::WrongFormatException();
     }
 
@@ -220,20 +212,20 @@ OUString LockFileCommon::GetCurrentLocalTime()
 }
 
 
-uno::Sequence< OUString > LockFileCommon::GenerateOwnEntry()
+LockFileEntry LockFileCommon::GenerateOwnEntry()
 {
-    uno::Sequence< OUString > aResult( LOCKFILE_ENTRYSIZE );
+    LockFileEntry aResult;
 
-    aResult[LOCKFILE_OOOUSERNAME_ID] = GetOOOUserName();
+    aResult[LockFileComponent::OOOUSERNAME] = GetOOOUserName();
 
     ::osl::Security aSecurity;
-    aSecurity.getUserName( aResult[LOCKFILE_SYSUSERNAME_ID] );
+    aSecurity.getUserName( aResult[LockFileComponent::SYSUSERNAME] );
 
-    aResult[LOCKFILE_LOCALHOST_ID] = ::osl::SocketAddr::getLocalHostname();
+    aResult[LockFileComponent::LOCALHOST] = ::osl::SocketAddr::getLocalHostname();
 
-    aResult[LOCKFILE_EDITTIME_ID] = GetCurrentLocalTime();
+    aResult[LockFileComponent::EDITTIME] = GetCurrentLocalTime();
 
-    ::utl::Bootstrap::locateUserInstallation( aResult[LOCKFILE_USERURL_ID] );
+    ::utl::Bootstrap::locateUserInstallation( aResult[LockFileComponent::USERURL] );
 
 
     return aResult;
diff --git a/svl/source/misc/sharecontrolfile.cxx b/svl/source/misc/sharecontrolfile.cxx
index b2b3ded..b866e84 100644
--- a/svl/source/misc/sharecontrolfile.cxx
+++ b/svl/source/misc/sharecontrolfile.cxx
@@ -30,6 +30,7 @@
 #include <osl/time.h>
 #include <osl/security.hxx>
 #include <osl/socket.hxx>
+#include <o3tl/enumrange.hxx>
 
 #include <rtl/string.hxx>
 #include <rtl/ustring.hxx>
@@ -150,19 +151,19 @@ void ShareControlFile::Close()
         m_xOutputStream = uno::Reference< io::XOutputStream >();
         m_xSeekable = uno::Reference< io::XSeekable >();
         m_xTruncate = uno::Reference< io::XTruncate >();
-        m_aUsersData.realloc( 0 );
+        m_aUsersData.clear();
     }
 }
 
 
-uno::Sequence< uno::Sequence< OUString > > ShareControlFile::GetUsersData()
+std::vector< o3tl::enumarray< LockFileComponent, OUString > > ShareControlFile::GetUsersData()
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
     if ( !IsValid() )
         throw io::NotConnectedException();
 
-    if ( !m_aUsersData.getLength() )
+    if ( m_aUsersData.empty() )
     {
         sal_Int64 nLength = m_xSeekable->getLength();
         if ( nLength > SAL_MAX_INT32 )
@@ -185,14 +186,14 @@ uno::Sequence< uno::Sequence< OUString > > ShareControlFile::GetUsersData()
             nLength -= nRead;
         }
 
-        m_aUsersData = ParseList( aBuffer );
+        ParseList( aBuffer, m_aUsersData );
     }
 
     return m_aUsersData;
 }
 
 
-void ShareControlFile::SetUsersDataAndStore( const uno::Sequence< uno::Sequence< OUString > >& aUsersData )
+void ShareControlFile::SetUsersDataAndStore( const std::vector< LockFileEntry >& aUsersData )
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
@@ -206,15 +207,12 @@ void ShareControlFile::SetUsersDataAndStore( const uno::Sequence< uno::Sequence<
     m_xSeekable->seek( 0 );
 
     OUStringBuffer aBuffer;
-    for ( sal_Int32 nInd = 0; nInd < aUsersData.getLength(); nInd++ )
+    for ( size_t nInd = 0; nInd < aUsersData.size(); nInd++ )
     {
-        if ( aUsersData[nInd].getLength() != SHARED_ENTRYSIZE )
-            throw lang::IllegalArgumentException();
-
-        for ( sal_Int32 nEntryInd = 0; nEntryInd < SHARED_ENTRYSIZE; nEntryInd++ )
+        for ( LockFileComponent nEntryInd : o3tl::enumrange<LockFileComponent>() )
         {
             aBuffer.append( EscapeCharacters( aUsersData[nInd][nEntryInd] ) );
-            if ( nEntryInd < SHARED_ENTRYSIZE - 1 )
+            if ( nEntryInd < LockFileComponent::LAST )
                 aBuffer.append( ',' );
             else
                 aBuffer.append( ';' );
@@ -228,7 +226,7 @@ void ShareControlFile::SetUsersDataAndStore( const uno::Sequence< uno::Sequence<
 }
 
 
-uno::Sequence< OUString > ShareControlFile::InsertOwnEntry()
+LockFileEntry ShareControlFile::InsertOwnEntry()
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
@@ -236,38 +234,34 @@ uno::Sequence< OUString > ShareControlFile::InsertOwnEntry()
         throw io::NotConnectedException();
 
     GetUsersData();
-    uno::Sequence< ::uno::Sequence< OUString > > aNewData( m_aUsersData.getLength() + 1 );
-    uno::Sequence< OUString > aNewEntry = GenerateOwnEntry();
+    std::vector< LockFileEntry > aNewData( m_aUsersData );
+    LockFileEntry aNewEntry = GenerateOwnEntry();
 
     bool bExists = false;
     sal_Int32 nNewInd = 0;
-    for ( sal_Int32 nInd = 0; nInd < m_aUsersData.getLength(); nInd++ )
+    for ( size_t nInd = 0; nInd < m_aUsersData.size(); nInd++ )
     {
-        if ( m_aUsersData[nInd].getLength() == SHARED_ENTRYSIZE )
+        if ( m_aUsersData[nInd][LockFileComponent::LOCALHOST] == aNewEntry[LockFileComponent::LOCALHOST]
+             && m_aUsersData[nInd][LockFileComponent::SYSUSERNAME] == aNewEntry[LockFileComponent::SYSUSERNAME]
+             && m_aUsersData[nInd][LockFileComponent::USERURL] == aNewEntry[LockFileComponent::USERURL] )
         {
-            if ( m_aUsersData[nInd][SHARED_LOCALHOST_ID] == aNewEntry[SHARED_LOCALHOST_ID]
-              && m_aUsersData[nInd][SHARED_SYSUSERNAME_ID] == aNewEntry[SHARED_SYSUSERNAME_ID]
-              && m_aUsersData[nInd][SHARED_USERURL_ID] == aNewEntry[SHARED_USERURL_ID] )
-            {
-                if ( !bExists )
-                {
-                    aNewData[nNewInd] = aNewEntry;
-                    bExists = true;
-                }
-            }
-            else
+            if ( !bExists )
             {
-                aNewData[nNewInd] = m_aUsersData[nInd];
+                aNewData[nNewInd] = aNewEntry;
+                bExists = true;
             }
-
-            nNewInd++;
         }
+        else
+        {
+            aNewData[nNewInd] = m_aUsersData[nInd];
+        }
+
+        nNewInd++;
     }
 
     if ( !bExists )
-        aNewData[nNewInd++] = aNewEntry;
+        aNewData.push_back( aNewEntry );
 
-    aNewData.realloc( nNewInd );
     SetUsersDataAndStore( aNewData );
 
     return aNewEntry;
@@ -284,14 +278,13 @@ bool ShareControlFile::HasOwnEntry()
     }
 
     GetUsersData();
-    uno::Sequence< OUString > aEntry = GenerateOwnEntry();
+    LockFileEntry aEntry = GenerateOwnEntry();
 
-    for ( sal_Int32 nInd = 0; nInd < m_aUsersData.getLength(); ++nInd )
+    for ( size_t nInd = 0; nInd < m_aUsersData.size(); ++nInd )
     {
-        if ( m_aUsersData[nInd].getLength() == SHARED_ENTRYSIZE &&
-             m_aUsersData[nInd][SHARED_LOCALHOST_ID] == aEntry[SHARED_LOCALHOST_ID] &&
-             m_aUsersData[nInd][SHARED_SYSUSERNAME_ID] == aEntry[SHARED_SYSUSERNAME_ID] &&
-             m_aUsersData[nInd][SHARED_USERURL_ID] == aEntry[SHARED_USERURL_ID] )
+        if ( m_aUsersData[nInd][LockFileComponent::LOCALHOST] == aEntry[LockFileComponent::LOCALHOST] &&
+             m_aUsersData[nInd][LockFileComponent::SYSUSERNAME] == aEntry[LockFileComponent::SYSUSERNAME] &&
+             m_aUsersData[nInd][LockFileComponent::USERURL] == aEntry[LockFileComponent::USERURL] )
         {
             return true;
         }
@@ -301,7 +294,12 @@ bool ShareControlFile::HasOwnEntry()
 }
 
 
-void ShareControlFile::RemoveEntry( const uno::Sequence< OUString >& aArgEntry )
+void ShareControlFile::RemoveEntry()
+{
+    RemoveEntry(GenerateOwnEntry());
+}
+
+void ShareControlFile::RemoveEntry( const LockFileEntry& aEntry )
 {
     ::osl::MutexGuard aGuard( m_aMutex );
 
@@ -310,31 +308,21 @@ void ShareControlFile::RemoveEntry( const uno::Sequence< OUString >& aArgEntry )
 
     GetUsersData();
 
-    uno::Sequence< OUString > aEntry = aArgEntry;
-    if ( aEntry.getLength() != SHARED_ENTRYSIZE )
-        aEntry = GenerateOwnEntry();
-
-    uno::Sequence< ::uno::Sequence< OUString > > aNewData( m_aUsersData.getLength() + 1 );
+    std::vector< LockFileEntry > aNewData;
 
-    sal_Int32 nNewInd = 0;
-    for ( sal_Int32 nInd = 0; nInd < m_aUsersData.getLength(); nInd++ )
+    for ( size_t nInd = 0; nInd < m_aUsersData.size(); nInd++ )
     {
-        if ( m_aUsersData[nInd].getLength() == SHARED_ENTRYSIZE )
+        if ( m_aUsersData[nInd][LockFileComponent::LOCALHOST] != aEntry[LockFileComponent::LOCALHOST]
+             || m_aUsersData[nInd][LockFileComponent::SYSUSERNAME] != aEntry[LockFileComponent::SYSUSERNAME]
+             || m_aUsersData[nInd][LockFileComponent::USERURL] != aEntry[LockFileComponent::USERURL] )
         {
-            if ( m_aUsersData[nInd][SHARED_LOCALHOST_ID] != aEntry[SHARED_LOCALHOST_ID]
-              || m_aUsersData[nInd][SHARED_SYSUSERNAME_ID] != aEntry[SHARED_SYSUSERNAME_ID]
-              || m_aUsersData[nInd][SHARED_USERURL_ID] != aEntry[SHARED_USERURL_ID] )
-            {
-                aNewData[nNewInd] = m_aUsersData[nInd];
-                nNewInd++;
-            }
+            aNewData.push_back( m_aUsersData[nInd] );
         }
     }
 
-    aNewData.realloc( nNewInd );
     SetUsersDataAndStore( aNewData );
 
-    if ( !nNewInd )
+    if ( aNewData.empty() )
     {
         // try to remove the file if it is empty
         RemoveFile();
commit ba9acdf799bf556c8a20b1dc27eb116e23d481db
Author: Noel Grandin <noel at peralex.com>
Date:   Mon Apr 13 16:33:56 2015 +0200

    convert TXTFORMAT constants to scoped enum
    
    and move them to the SW module since that is the only place they are
    used
    
    Change-Id: Ic037e5ac9d2514377669c5f583b856e1da429a19
    Reviewed-on: https://gerrit.libreoffice.org/15303
    Tested-by: Noel Grandin <noelgrandin at gmail.com>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/include/svl/mailenum.hxx b/include/svl/mailenum.hxx
index ceee806..85595c2 100644
--- a/include/svl/mailenum.hxx
+++ b/include/svl/mailenum.hxx
@@ -19,8 +19,6 @@
 #ifndef INCLUDED_SVL_MAILENUM_HXX
 #define INCLUDED_SVL_MAILENUM_HXX
 
-// enum ------------------------------------------------------------------
-
 enum MailState
 {
     MAIL_STATE_SUCCESS = 0,
@@ -75,14 +73,6 @@ enum MailAction
     MAIL_ACTION_PREV        // jump to previous mail
 };
 
-// text format for the sending of messages ------------------------------
-
-#define TXTFORMAT_ASCII     ((sal_uInt8)0x01)
-#define TXTFORMAT_HTML      ((sal_uInt8)0x02)
-#define TXTFORMAT_RTF       ((sal_uInt8)0x04)
-#define TXTFORMAT_OFFICE    ((sal_uInt8)0x08)
-
-
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/inc/modcfg.hxx b/sw/inc/modcfg.hxx
index 7242ed6..e79c236 100644
--- a/sw/inc/modcfg.hxx
+++ b/sw/inc/modcfg.hxx
@@ -30,10 +30,26 @@
 #include "itabenum.hxx"
 #include <tools/globname.hxx>
 #include <editeng/svxenum.hxx>
-class SwModuleOptions;
+#include <o3tl/typed_flags_set.hxx>
 
+class SwModuleOptions;
 class InsCaptionOpt;
 
+// text format for the sending of messages ------------------------------
+enum class MailTxtFormats
+{
+    NONE      = 0x00,
+    ASCII     = 0x01,
+    HTML      = 0x02,
+    RTF       = 0x04,
+    OFFICE    = 0x08
+};
+namespace o3tl
+{
+    template<> struct typed_flags<MailTxtFormats> : is_typed_flags<MailTxtFormats, 0x0f> {};
+}
+
+
 class InsCaptionOptArr
 {
 private:
@@ -161,7 +177,7 @@ class SwMiscConfig : public utl::ConfigItem
     bool        bSinglePrintJob;            // FormLetter/PrintOutput/SinglePrintJobs
     bool        bIsNameFromColumn;          // FormLetter/FileOutput/FileName/Generation
     bool        bAskForMailMergeInPrint;    // Ask if documents containing fields should be 'mailmerged'
-    sal_Int16   nMailingFormats;            // FormLetter/MailingOutput/Formats
+    MailTxtFormats nMailingFormats;            // FormLetter/MailingOutput/Formats
     OUString    sNameFromColumn;            // FormLetter/FileOutput/FileName/FromDatabaseField (string!)
     OUString    sMailingPath;               // FormLetter/FileOutput/Path
     OUString    sMailName;                  // FormLetter/FileOutput/FileName/FromManualSetting (string!)
@@ -286,9 +302,9 @@ public:
     void        SetGrfToGalleryAsLnk( bool b )  { aMiscConfig.bGrfToGalleryAsLnk = b;
                                                   aMiscConfig.SetModified();}
 
-    sal_Int16   GetMailingFormats() const       { return aMiscConfig.nMailingFormats;}
-    void        SetMailingFormats( sal_Int16 nSet ) { aMiscConfig.nMailingFormats = nSet;
-                                                  aMiscConfig.SetModified();}
+    MailTxtFormats GetMailingFormats() const               { return aMiscConfig.nMailingFormats;}
+    void           SetMailingFormats( MailTxtFormats nSet ) { aMiscConfig.nMailingFormats = nSet;
+                                                            aMiscConfig.SetModified();}
 
     bool        IsSinglePrintJob() const        { return aMiscConfig.bSinglePrintJob; }
     void        SetSinglePrintJob( bool b )     { aMiscConfig.bSinglePrintJob = b;
diff --git a/sw/source/ui/envelp/mailmrge.cxx b/sw/source/ui/envelp/mailmrge.cxx
index 00da816..dac471e 100644
--- a/sw/source/ui/envelp/mailmrge.cxx
+++ b/sw/source/ui/envelp/mailmrge.cxx
@@ -256,10 +256,10 @@ SwMailMergeDlg::SwMailMergeDlg(vcl::Window* pParent, SwWrtShell& rShell,
 
     pModOpt = SW_MOD()->GetModuleConfig();
 
-    sal_Int16 nMailingMode(pModOpt->GetMailingFormats());
-    m_pFormatSwCB->Check((nMailingMode & TXTFORMAT_OFFICE) != 0);
-    m_pFormatHtmlCB->Check((nMailingMode & TXTFORMAT_HTML) != 0);
-    m_pFormatRtfCB->Check((nMailingMode & TXTFORMAT_RTF) != 0);
+    MailTxtFormats nMailingMode(pModOpt->GetMailingFormats());
+    m_pFormatSwCB->Check(bool(nMailingMode & MailTxtFormats::OFFICE));
+    m_pFormatHtmlCB->Check(bool(nMailingMode & MailTxtFormats::HTML));
+    m_pFormatRtfCB->Check(bool(nMailingMode & MailTxtFormats::RTF));
 
     m_pAllRB->Check(true);
 
@@ -578,14 +578,14 @@ bool SwMailMergeDlg::ExecQryShell()
 
     pModOpt->SetSinglePrintJob(m_pSingleJobsCB->IsChecked());
 
-    sal_uInt8 nMailingMode = 0;
+    MailTxtFormats nMailingMode = MailTxtFormats::NONE;
 
     if (m_pFormatSwCB->IsChecked())
-        nMailingMode |= TXTFORMAT_OFFICE;
+        nMailingMode |= MailTxtFormats::OFFICE;
     if (m_pFormatHtmlCB->IsChecked())
-        nMailingMode |= TXTFORMAT_HTML;
+        nMailingMode |= MailTxtFormats::HTML;
     if (m_pFormatRtfCB->IsChecked())
-        nMailingMode |= TXTFORMAT_RTF;
+        nMailingMode |= MailTxtFormats::RTF;
     pModOpt->SetMailingFormats(nMailingMode);
     return true;
 }
diff --git a/sw/source/uibase/config/modcfg.cxx b/sw/source/uibase/config/modcfg.cxx
index 94a651f..a9d5392 100644
--- a/sw/source/uibase/config/modcfg.cxx
+++ b/sw/source/uibase/config/modcfg.cxx
@@ -1196,7 +1196,7 @@ SwMiscConfig::SwMiscConfig() :
     bSinglePrintJob(false),
     bIsNameFromColumn(true),
     bAskForMailMergeInPrint(true),
-    nMailingFormats(0)
+    nMailingFormats(MailTxtFormats::NONE)
 {
     Load();
 }
@@ -1255,7 +1255,7 @@ void SwMiscConfig::ImplCommit()
             case 3 : pValues[nProp] <<= bGrfToGalleryAsLnk; break;
             case 4 : pValues[nProp] <<= bNumAlignSize; break;
             case 5 : pValues[nProp] <<= bSinglePrintJob; break;
-            case 6 : pValues[nProp] <<= nMailingFormats;             break;
+            case 6 : pValues[nProp] <<= static_cast<sal_uInt8>(nMailingFormats); break;
             case 7 : pValues[nProp] <<= sNameFromColumn;  break;
             case 8 : pValues[nProp] <<= sMailingPath;     break;
             case 9 : pValues[nProp] <<= sMailName;        break;
@@ -1289,7 +1289,7 @@ void SwMiscConfig::Load()
                     case 3 : bGrfToGalleryAsLnk = *static_cast<sal_Bool const *>(pValues[nProp].getValue()); break;
                     case 4 : bNumAlignSize = *static_cast<sal_Bool const *>(pValues[nProp].getValue()); break;
                     case 5 : bSinglePrintJob = *static_cast<sal_Bool const *>(pValues[nProp].getValue()); break;
-                    case 6 : pValues[nProp] >>= nMailingFormats;              ; break;
+                    case 6 : nMailingFormats = static_cast<MailTxtFormats>(*static_cast<sal_uInt8 const *>(pValues[nProp].getValue())); break;
                     case 7 : pValues[nProp] >>= sTmp; sNameFromColumn = sTmp; break;
                     case 8 : pValues[nProp] >>= sTmp; sMailingPath = sTmp;  break;
                     case 9 : pValues[nProp] >>= sTmp; sMailName = sTmp;     break;


More information about the Libreoffice-commits mailing list