1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: profile.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _OSL_PROFILE_HXX_
32 #define _OSL_PROFILE_HXX_
35 #include <rtl/ustring.hxx>
41 typedef oslProfileOption ProfileOption
;
43 const int Profile_DEFAULT
= osl_Profile_DEFAULT
;
44 const int Profile_SYSTEM
= osl_Profile_SYSTEM
; /* use system depended functinality */
45 const int Profile_READLOCK
= osl_Profile_READLOCK
; /* lock file for reading */
46 const int Profile_WRITELOCK
= osl_Profile_WRITELOCK
; /* lock file for writing */
55 /** Open or create a configuration profile.
56 @return 0 if the profile could not be created, otherwise a handle to the profile.
58 Profile(const rtl::OUString strProfileName
, oslProfileOption Options
= Profile_DEFAULT
)
60 profile
= osl_openProfile(strProfileName
.pData
, Options
);
62 throw std::exception();
66 /** Close the opened profile an flush all data to the disk.
67 @param Profile handle to a opened profile.
71 osl_closeProfile(profile
);
77 return osl_flushProfile(profile
);
80 rtl::OString
readString( const rtl::OString
& rSection
, const rtl::OString
& rEntry
,
81 const rtl::OString
& rDefault
)
84 return osl_readProfileString( profile
,
89 rDefault
) ? rtl::OString( aBuf
) : rtl::OString();
93 sal_Bool
readBool( const rtl::OString
& rSection
, const rtl::OString
& rEntry
, sal_Bool bDefault
)
95 return osl_readProfileBool( profile
, rSection
, rEntry
, bDefault
);
98 sal_uInt32
readIdent(const rtl::OString
& rSection
, const rtl::OString
& rEntry
,
99 sal_uInt32 nFirstId
, const std::list
< rtl::OString
>& rStrings
,
102 int nItems
= rStrings
.size();
103 const sal_Char
** pStrings
= new const sal_Char
*[ nItems
+1 ];
104 std::list
< rtl::OString
>::const_iterator it
= rStrings
.begin();
106 while( it
!= rStrings
.end() )
108 pStrings
[ nItems
++ ] = *it
;
111 pStrings
[ nItems
] = NULL
;
112 sal_uInt32 nRet
= osl_readProfileIdent(profile
, rSection
, rEntry
, nFirstId
, pStrings
, nDefault
);
117 sal_Bool
writeString(const rtl::OString
& rSection
, const rtl::OString
& rEntry
,
118 const rtl::OString
& rString
)
120 return osl_writeProfileString(profile
, rSection
, rEntry
, rString
);
123 sal_Bool
writeBool(const rtl::OString
& rSection
, const rtl::OString
& rEntry
, sal_Bool Value
)
125 return osl_writeProfileBool(profile
, rSection
, rEntry
, Value
);
128 sal_Bool
writeIdent(const rtl::OString
& rSection
, const rtl::OString
& rEntry
,
129 sal_uInt32 nFirstId
, const std::list
< rtl::OString
>& rStrings
,
132 int nItems
= rStrings
.size();
133 const sal_Char
** pStrings
= new const sal_Char
*[ nItems
+1 ];
134 std::list
< rtl::OString
>::const_iterator it
= rStrings
.begin();
136 while( it
!= rStrings
.end() )
138 pStrings
[ nItems
++ ] = *it
;
141 pStrings
[ nItems
] = NULL
;
143 osl_writeProfileIdent(profile
, rSection
, rEntry
, nFirstId
, pStrings
, nValue
);
148 /** Acquire the mutex, block if already acquired by another thread.
149 @param Profile handle to a opened profile.
150 @return False if section or entry could not be found.
152 sal_Bool
removeEntry(const rtl::OString
& rSection
, const rtl::OString
& rEntry
)
154 return osl_removeProfileEntry(profile
, rSection
, rEntry
);
157 /** Get all entries belonging to the specified section.
158 @param Profile handle to a opened profile.
159 @return Pointer to a array of pointers.
161 std::list
< rtl::OString
> getSectionEntries(const rtl::OString
& rSection
)
163 std::list
< rtl::OString
> aEntries
;
165 // count buffer size necessary
166 int n
= osl_getProfileSectionEntries( profile
, rSection
, NULL
, 0 );
169 sal_Char
* pBuf
= new sal_Char
[ n
+1 ];
170 osl_getProfileSectionEntries( profile
, rSection
, pBuf
, n
+1 );
172 for( n
= 0; ( nLen
= strlen( pBuf
+n
) ); n
+= nLen
+1 )
173 aEntries
.push_back( rtl::OString( pBuf
+n
) );
180 /** Get all section entries
181 @param Profile handle to a opened profile.
182 @return Pointer to a array of pointers.
184 std::list
< rtl::OString
> getSections()
186 std::list
< rtl::OString
> aSections
;
188 // count buffer size necessary
189 int n
= osl_getProfileSections( profile
, NULL
, 0 );
192 sal_Char
* pBuf
= new sal_Char
[ n
+1 ];
193 osl_getProfileSections( profile
, pBuf
, n
+1 );
195 for( n
= 0; ( nLen
= strlen( pBuf
+n
) ); n
+= nLen
+1 )
196 aSections
.push_back( rtl::OString( pBuf
+n
) );
205 #endif /* _OSL_PROFILE_HXX_ */