1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <comphelper/processfactory.hxx>
23 #include <comphelper/string.hxx>
25 #include <vcl/stdtext.hxx>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/plugin/PluginDescription.hpp>
29 #include <com/sun/star/plugin/PluginManager.hpp>
30 #include <com/sun/star/plugin/XPluginManager.hpp>
32 #include <plfilter.hxx>
35 using namespace com::sun::star::uno
;
36 using namespace com::sun::star::lang
;
37 using namespace com::sun::star::plugin
;
41 bool operator()( const OUString
& s1
, const OUString
& s2
) const
43 return s1
.compareTo( s2
) < 0;
47 typedef set
< OUString
, ltstr
> StrSet
;
48 typedef map
< OUString
, StrSet
, ltstr
> FilterMap
;
52 void fillNetscapePluginFilters( Sequence
< OUString
>& rPluginNames
, Sequence
< OUString
>& rPluginTypes
)
54 Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
55 Reference
< XPluginManager
> xPMgr( PluginManager::create(xContext
) );
59 // sum up the mimetypes: one description, multiple extensions
61 Sequence
<PluginDescription
> aDescriptions( xPMgr
->getPluginDescriptions() );
62 const PluginDescription
* pDescriptions
= aDescriptions
.getConstArray();
63 for ( sal_uInt32 nPos
= aDescriptions
.getLength(); nPos
--; )
65 const PluginDescription
& rDescr
= pDescriptions
[nPos
];
67 StrSet
& rTypes
= aMap
[ rDescr
.Description
];
68 OUString
aExtension( rDescr
.Extension
);
70 for ( sal_uInt16 nCnt
= comphelper::string::getTokenCount(aExtension
, ';'); nCnt
--; )
72 // no default plugins anymore
73 OUString
aExt( aExtension
.getToken( nCnt
, ';' ) );
75 rTypes
.insert( aExt
);
79 rPluginNames
= Sequence
< OUString
>( aMap
.size() );
80 rPluginTypes
= Sequence
< OUString
>( aMap
.size() );
81 OUString
* pPluginNames
= rPluginNames
.getArray();
82 OUString
* pPluginTypes
= rPluginTypes
.getArray();
84 for ( FilterMap::iterator iPos
= aMap
.begin(); iPos
!= aMap
.end(); ++iPos
)
86 OUString
aText( (*iPos
).first
);
88 StrSet
& rTypes
= (*iPos
).second
;
89 StrSet::iterator i
= rTypes
.begin();
90 while ( i
!= rTypes
.end() )
94 if ( i
!= rTypes
.end() )
98 if ( !aType
.isEmpty() )
103 pPluginNames
[nIndex
] = aText
;
104 pPluginTypes
[nIndex
] = aType
;
108 rPluginNames
.realloc( nIndex
);
109 rPluginTypes
.realloc( nIndex
);
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */