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: kdepathslayer.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"
33 #include "kdepathslayer.hxx"
34 #include <vcl/kde_headers.h>
35 #include <com/sun/star/configuration/backend/PropertyInfo.hpp>
36 #ifndef _COM_SUN_STAR_CONFIGURATION_BACKEND_XLAYERCONTENTDESCIBER_HPP_
37 #include <com/sun/star/configuration/backend/XLayerContentDescriber.hpp>
39 #include <osl/security.hxx>
40 #include <osl/file.hxx>
41 #include <com/sun/star/uno/Sequence.hxx>
45 //==============================================================================
47 KDEPathsLayer::KDEPathsLayer(const uno::Reference
<uno::XComponentContext
>& xContext
)
49 //Create instance of LayerContentDescriber Service
50 rtl::OUString
const k_sLayerDescriberService(RTL_CONSTASCII_USTRINGPARAM(
51 "com.sun.star.comp.configuration.backend.LayerDescriber"));
53 typedef uno::Reference
<backend::XLayerContentDescriber
> LayerDescriber
;
54 uno::Reference
< lang::XMultiComponentFactory
> xServiceManager
= xContext
->getServiceManager();
55 if( xServiceManager
.is() )
57 m_xLayerContentDescriber
= LayerDescriber::query(
58 xServiceManager
->createInstanceWithContext(k_sLayerDescriberService
, xContext
));
62 OSL_TRACE("Could not retrieve ServiceManager");
66 //------------------------------------------------------------------------------
68 void SAL_CALL
KDEPathsLayer::readData( const uno::Reference
<backend::XLayerHandler
>& xHandler
)
69 throw ( backend::MalformedDataException
, lang::NullPointerException
,
70 lang::WrappedTargetException
, uno::RuntimeException
)
72 if( ! m_xLayerContentDescriber
.is() )
74 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
75 "Could not create com.sun.star.configuration.backend.LayerContentDescriber Service"
76 ) ), static_cast < backend::XLayer
* > (this) );
79 uno::Sequence
<backend::PropertyInfo
> aPropInfoList(1);
80 sal_Int32 nProperties
= 0;
82 QString
aDocumentsDir( KGlobalSettings::documentPath() );
83 rtl::OUString sDocumentsDir
;
84 rtl::OUString sDocumentsURL
;
85 if ( aDocumentsDir
.endsWith(QChar('/')) )
86 aDocumentsDir
.truncate ( aDocumentsDir
.length() - 1 );
87 sDocumentsDir
= (const sal_Unicode
*) aDocumentsDir
.ucs2();
88 osl_getFileURLFromSystemPath( sDocumentsDir
.pData
, &sDocumentsURL
.pData
);
90 aPropInfoList
[nProperties
].Name
= rtl::OUString(
91 RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Office.Paths/Variables/Work") );
92 aPropInfoList
[nProperties
].Type
= rtl::OUString(
93 RTL_CONSTASCII_USTRINGPARAM( "string" ) );
94 aPropInfoList
[nProperties
].Protected
= sal_False
;
95 aPropInfoList
[nProperties
++].Value
= uno::makeAny( sDocumentsURL
);
99 aPropInfoList
.realloc(nProperties
);
100 m_xLayerContentDescriber
->describeLayer(xHandler
, aPropInfoList
);
104 //------------------------------------------------------------------------------
106 rtl::OUString SAL_CALL
KDEPathsLayer::getTimestamp(void)
107 throw (uno::RuntimeException
)
109 // Return the value as timestamp to avoid regenerating the binary cache
110 // on each office launch.
112 ::rtl::OUString sTimeStamp
,
113 sep( RTL_CONSTASCII_USTRINGPARAM( "$" ) );
115 QString aDocumentsDir
;
116 aDocumentsDir
= KGlobalSettings::documentPath();
118 sTimeStamp
+= (const sal_Unicode
*) aDocumentsDir
.ucs2();