xref: /aoo42x/main/sw/source/ui/vba/vbaaddins.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #include "vbaaddins.hxx"
28 #include "vbaaddin.hxx"
29 #include <cppuhelper/implbase3.hxx>
30 #include <unotools/pathoptions.hxx>
31 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
32 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
33 
34 using namespace ::ooo::vba;
35 using namespace ::com::sun::star;
36 
37 uno::Reference< container::XIndexAccess > lcl_getAddinCollection( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext )
38 {
39     XNamedObjectCollectionHelper< word::XAddin >::XNamedVec maAddins;
40 
41     // first get the autoload addins in the directory STARTUP
42     uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager(), uno::UNO_QUERY_THROW );
43     uno::Reference< ucb::XSimpleFileAccess > xSFA( xMCF->createInstanceWithContext( rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), xContext), uno::UNO_QUERY_THROW );
44     SvtPathOptions aPathOpt;
45     // FIXME: temporary the STARTUP path is located in $OO/basic3.1/program/addin
46     String aAddinPath = aPathOpt.GetAddinPath();
47     OSL_TRACE("lcl_getAddinCollection: %s", rtl::OUStringToOString( aAddinPath, RTL_TEXTENCODING_UTF8 ).getStr() );
48     if( xSFA->isFolder( aAddinPath ) )
49     {
50         uno::Sequence< rtl::OUString > sEntries = xSFA->getFolderContents( aAddinPath, sal_False );
51         sal_Int32 nEntry = sEntries.getLength();
52         for( sal_Int32 index = 0; index < nEntry; ++index )
53         {
54             rtl::OUString sUrl = sEntries[ index ];
55             if( !xSFA->isFolder( sUrl ) && sUrl.endsWithIgnoreAsciiCaseAsciiL( ".dot", 4 ) )
56             {
57                 maAddins.push_back( uno::Reference< word::XAddin >( new SwVbaAddin( xParent, xContext, sUrl, sal_True ) ) );
58             }
59         }
60     }
61 
62     // TODO: second get the customize addins in the org.openoffice.Office.Writer/GlobalTemplateList
63 
64     uno::Reference< container::XIndexAccess > xAddinsAccess( new XNamedObjectCollectionHelper< word::XAddin >( maAddins ) );
65     return xAddinsAccess;
66 }
67 
68 SwVbaAddins::SwVbaAddins( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext ) throw (uno::RuntimeException): SwVbaAddins_BASE( xParent, xContext, lcl_getAddinCollection( xParent,xContext ) )
69 {
70 }
71 // XEnumerationAccess
72 uno::Type
73 SwVbaAddins::getElementType() throw (uno::RuntimeException)
74 {
75 	return word::XAddin::static_type(0);
76 }
77 uno::Reference< container::XEnumeration >
78 SwVbaAddins::createEnumeration() throw (uno::RuntimeException)
79 {
80     uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
81     return xEnumerationAccess->createEnumeration();
82 }
83 
84 uno::Any
85 SwVbaAddins::createCollectionObject( const css::uno::Any& aSource )
86 {
87     return aSource;
88 }
89 
90 rtl::OUString&
91 SwVbaAddins::getServiceImplName()
92 {
93 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaAddins") );
94 	return sImplName;
95 }
96 
97 css::uno::Sequence<rtl::OUString>
98 SwVbaAddins::getServiceNames()
99 {
100 	static uno::Sequence< rtl::OUString > sNames;
101 	if ( sNames.getLength() == 0 )
102 	{
103 		sNames.realloc( 1 );
104 		sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Addins") );
105 	}
106 	return sNames;
107 }
108