LibreOffice Module sw (master) 1
vbaaddins.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#include "vbaaddins.hxx"
20#include "vbaaddin.hxx"
22#include <sal/log.hxx>
23#include <com/sun/star/lang/XMultiComponentFactory.hpp>
24#include <com/sun/star/ucb/SimpleFileAccess.hpp>
25
26using namespace ::ooo::vba;
27using namespace ::com::sun::star;
28
29static uno::Reference< container::XIndexAccess > lcl_getAddinCollection( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext )
30{
32
33 // first get the autoload addins in the directory STARTUP
34 uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager(), uno::UNO_SET_THROW );
35 uno::Reference<ucb::XSimpleFileAccess3> xSFA(ucb::SimpleFileAccess::create(xContext));
36 SvtPathOptions aPathOpt;
37 // FIXME: temporary the STARTUP path is located in $OO/basic3.1/program/addin
38 const OUString& aAddinPath = aPathOpt.GetAddinPath();
39 SAL_INFO("sw.vba", "lcl_getAddinCollection: " << aAddinPath );
40 if( xSFA->isFolder( aAddinPath ) )
41 {
42 const uno::Sequence< OUString > sEntries = xSFA->getFolderContents( aAddinPath, false );
43 for( const OUString& sUrl : sEntries )
44 {
45 if( !xSFA->isFolder( sUrl ) && sUrl.endsWithIgnoreAsciiCase( ".dot" ) )
46 {
47 aAddins.push_back( uno::Reference< word::XAddin >( new SwVbaAddin( xParent, xContext, sUrl ) ) );
48 }
49 }
50 }
51
52 // TODO: second get the customize addins in the org.openoffice.Office.Writer/GlobalTemplateList
53
54 uno::Reference< container::XIndexAccess > xAddinsAccess( new XNamedObjectCollectionHelper< word::XAddin >( std::move(aAddins) ) );
55 return xAddinsAccess;
56}
57
58SwVbaAddins::SwVbaAddins( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext ): SwVbaAddins_BASE( xParent, xContext, lcl_getAddinCollection( xParent,xContext ) )
59{
60}
61// XEnumerationAccess
64{
66}
67uno::Reference< container::XEnumeration >
69{
70 uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
71 return xEnumerationAccess->createEnumeration();
72}
73
75SwVbaAddins::createCollectionObject( const css::uno::Any& aSource )
76{
77 return aSource;
78}
79
80OUString
82{
83 return "SwVbaAddins";
84}
85
86css::uno::Sequence<OUString>
88{
89 static uno::Sequence< OUString > const sNames
90 {
91 "ooo.vba.word.Addins"
92 };
93 return sNames;
94}
95
96/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
const OUString & GetAddinPath() const
virtual css::uno::Type SAL_CALL getElementType() override
Definition: vbaaddins.cxx:63
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
Definition: vbaaddins.cxx:75
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: vbaaddins.cxx:68
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbaaddins.cxx:87
SwVbaAddins(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext)
Definition: vbaaddins.cxx:58
virtual OUString getServiceImplName() override
Definition: vbaaddins.cxx:81
css::uno::Type const & get()
#define SAL_INFO(area, stream)
static uno::Reference< container::XIndexAccess > lcl_getAddinCollection(const uno::Reference< XHelperInterface > &xParent, const uno::Reference< uno::XComponentContext > &xContext)
Definition: vbaaddins.cxx:29