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