Line data Source code
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 :
20 : #include <set>
21 : #include <map>
22 : #include <comphelper/processfactory.hxx>
23 : #include <comphelper/string.hxx>
24 :
25 : #include <vcl/stdtext.hxx>
26 :
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>
31 :
32 : #include <plfilter.hxx>
33 :
34 : using namespace std;
35 : using namespace com::sun::star::uno;
36 : using namespace com::sun::star::lang;
37 : using namespace com::sun::star::plugin;
38 :
39 : struct ltstr
40 : {
41 0 : bool operator()( const OUString& s1, const OUString& s2 ) const
42 : {
43 0 : return s1.compareTo( s2 ) < 0;
44 : }
45 : };
46 :
47 : typedef set< OUString, ltstr > StrSet;
48 : typedef map< OUString, StrSet, ltstr > FilterMap;
49 :
50 :
51 :
52 0 : void fillNetscapePluginFilters( Sequence< OUString >& rPluginNames, Sequence< OUString >& rPluginTypes )
53 : {
54 0 : Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
55 0 : Reference< XPluginManager > xPMgr( PluginManager::create(xContext) );
56 :
57 0 : FilterMap aMap;
58 :
59 : // sum up the mimetypes: one description, multiple extensions
60 :
61 0 : Sequence<PluginDescription > aDescriptions( xPMgr->getPluginDescriptions() );
62 0 : const PluginDescription * pDescriptions = aDescriptions.getConstArray();
63 0 : for ( sal_uInt32 nPos = aDescriptions.getLength(); nPos--; )
64 : {
65 0 : const PluginDescription & rDescr = pDescriptions[nPos];
66 :
67 0 : StrSet& rTypes = aMap[ rDescr.Description ];
68 0 : OUString aExtension( rDescr.Extension );
69 :
70 0 : for ( sal_uInt16 nCnt = comphelper::string::getTokenCount(aExtension, ';'); nCnt--; )
71 : {
72 : // no default plugins anymore
73 0 : OUString aExt( aExtension.getToken( nCnt, ';' ) );
74 0 : if ( aExt == "*.*" )
75 0 : rTypes.insert( aExt );
76 0 : }
77 0 : }
78 :
79 0 : rPluginNames = Sequence< OUString >( aMap.size() );
80 0 : rPluginTypes = Sequence< OUString >( aMap.size() );
81 0 : OUString* pPluginNames = rPluginNames.getArray();
82 0 : OUString* pPluginTypes = rPluginTypes.getArray();
83 0 : int nIndex = 0;
84 0 : for ( FilterMap::iterator iPos = aMap.begin(); iPos != aMap.end(); ++iPos )
85 : {
86 0 : OUString aText( (*iPos).first );
87 0 : OUString aType;
88 0 : StrSet& rTypes = (*iPos).second;
89 0 : StrSet::iterator i = rTypes.begin();
90 0 : while ( i != rTypes.end() )
91 : {
92 0 : aType += (*i);
93 0 : ++i;
94 0 : if ( i != rTypes.end() )
95 0 : aType += ";";
96 : }
97 :
98 0 : if ( !aType.isEmpty() )
99 : {
100 0 : aText += " (";
101 0 : aText += aType;
102 0 : aText += ")";
103 0 : pPluginNames[nIndex] = aText;
104 0 : pPluginTypes[nIndex] = aType;
105 0 : nIndex++;
106 : }
107 0 : }
108 0 : rPluginNames.realloc( nIndex );
109 0 : rPluginTypes.realloc( nIndex );
110 0 : }
111 :
112 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|