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: kde4pathslayer.cxx,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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_shell.hxx"
34 #include "kde4pathslayer.hxx"
37 #include <kglobalsettings.h>
39 #include <com/sun/star/configuration/backend/PropertyInfo.hpp>
40 #include <com/sun/star/configuration/backend/XLayerContentDescriber.hpp>
42 #include <osl/security.hxx>
43 #include <osl/file.hxx>
44 #include <com/sun/star/uno/Sequence.hxx>
48 //==============================================================================
50 KDEPathsLayer::KDEPathsLayer(const uno::Reference
<uno::XComponentContext
>& xContext
)
52 //Create instance of LayerContentDescriber Service
53 rtl::OUString
const k_sLayerDescriberService(RTL_CONSTASCII_USTRINGPARAM(
54 "com.sun.star.comp.configuration.backend.LayerDescriber"));
56 typedef uno::Reference
<backend::XLayerContentDescriber
> LayerDescriber
;
57 uno::Reference
< lang::XMultiComponentFactory
> xServiceManager
= xContext
->getServiceManager();
58 if( xServiceManager
.is() )
60 m_xLayerContentDescriber
= LayerDescriber::query(
61 xServiceManager
->createInstanceWithContext(k_sLayerDescriberService
, xContext
));
65 OSL_TRACE("Could not retrieve ServiceManager");
69 //------------------------------------------------------------------------------
71 void SAL_CALL
KDEPathsLayer::readData( const uno::Reference
<backend::XLayerHandler
>& xHandler
)
72 throw ( backend::MalformedDataException
, lang::NullPointerException
,
73 lang::WrappedTargetException
, uno::RuntimeException
)
75 if( ! m_xLayerContentDescriber
.is() )
77 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
78 "Could not create com.sun.star.configuration.backend.LayerContentDescriber Service"
79 ) ), static_cast < backend::XLayer
* > (this) );
82 uno::Sequence
<backend::PropertyInfo
> aPropInfoList(1);
83 sal_Int32 nProperties
= 0;
85 QString
aDocumentsDir( KGlobalSettings::documentPath() );
86 rtl::OUString sDocumentsDir
;
87 rtl::OUString sDocumentsURL
;
88 if ( aDocumentsDir
.endsWith(QChar('/')) )
89 aDocumentsDir
.truncate ( aDocumentsDir
.length() - 1 );
90 sDocumentsDir
= (const sal_Unicode
*) aDocumentsDir
.utf16();
91 osl_getFileURLFromSystemPath( sDocumentsDir
.pData
, &sDocumentsURL
.pData
);
93 aPropInfoList
[nProperties
].Name
= rtl::OUString(
94 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Office.Paths/Variables/Work") );
95 aPropInfoList
[nProperties
].Type
= rtl::OUString(
96 RTL_CONSTASCII_USTRINGPARAM( "string" ) );
97 aPropInfoList
[nProperties
].Protected
= sal_False
;
98 aPropInfoList
[nProperties
++].Value
= uno::makeAny( sDocumentsURL
);
100 if( nProperties
> 0 )
102 aPropInfoList
.realloc(nProperties
);
103 m_xLayerContentDescriber
->describeLayer(xHandler
, aPropInfoList
);
107 //------------------------------------------------------------------------------
109 rtl::OUString SAL_CALL
KDEPathsLayer::getTimestamp(void)
110 throw (uno::RuntimeException
)
112 // Return the value as timestamp to avoid regenerating the binary cache
113 // on each office launch.
115 ::rtl::OUString sTimeStamp
,
116 sep( RTL_CONSTASCII_USTRINGPARAM( "$" ) );
118 QString aDocumentsDir
;
119 aDocumentsDir
= KGlobalSettings::documentPath();
121 sTimeStamp
+= (const sal_Unicode
*) aDocumentsDir
.utf16();