Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <set>
30 : : #include <map>
31 : : #include <comphelper/processfactory.hxx>
32 : : #include <comphelper/string.hxx>
33 : :
34 : : #include <vcl/stdtext.hxx>
35 : :
36 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 : : #include <com/sun/star/plugin/PluginDescription.hpp>
38 : : #include <com/sun/star/plugin/PluginManager.hpp>
39 : : #include <com/sun/star/plugin/XPluginManager.hpp>
40 : :
41 : : using namespace std;
42 : : using namespace com::sun::star::uno;
43 : : using namespace com::sun::star::lang;
44 : : using namespace com::sun::star::plugin;
45 : :
46 : : struct ltstr
47 : : {
48 : 0 : bool operator()( const String& s1, const String& s2 ) const
49 : : {
50 : 0 : return ( s1.CompareTo( s2 ) == COMPARE_LESS );
51 : : }
52 : : };
53 : :
54 : : typedef set< String, ltstr > StrSet;
55 : : typedef map< String, StrSet, ltstr > FilterMap;
56 : :
57 : :
58 : : //==================================================================================================
59 : 0 : void fillNetscapePluginFilters( Sequence< rtl::OUString >& rPluginNames, Sequence< rtl::OUString >& rPluginTypes )
60 : : {
61 [ # # ]: 0 : Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
62 [ # # ]: 0 : Reference< XPluginManager > xPMgr( PluginManager::create(xContext) );
63 : :
64 [ # # ]: 0 : FilterMap aMap;
65 : :
66 : : // sum up the mimetypes: one description, multiple extensions
67 : :
68 [ # # ][ # # ]: 0 : Sequence<PluginDescription > aDescriptions( xPMgr->getPluginDescriptions() );
69 : 0 : const PluginDescription * pDescriptions = aDescriptions.getConstArray();
70 [ # # ]: 0 : for ( sal_uInt32 nPos = aDescriptions.getLength(); nPos--; )
71 : : {
72 : 0 : const PluginDescription & rDescr = pDescriptions[nPos];
73 : :
74 [ # # ][ # # ]: 0 : StrSet& rTypes = aMap[ rDescr.Description ];
[ # # ]
75 [ # # ]: 0 : String aExtension( rDescr.Extension );
76 : :
77 [ # # ][ # # ]: 0 : for ( sal_uInt16 nCnt = comphelper::string::getTokenCount(aExtension, ';'); nCnt--; )
[ # # ]
78 : : {
79 : : // no default plugins anymore
80 [ # # ]: 0 : String aExt( aExtension.GetToken( nCnt, ';' ) );
81 [ # # ][ # # ]: 0 : if ( aExt.CompareToAscii( "*.*" ) != COMPARE_EQUAL )
82 [ # # ]: 0 : rTypes.insert( aExt );
83 [ # # ]: 0 : }
84 [ # # ]: 0 : }
85 : :
86 [ # # ][ # # ]: 0 : rPluginNames = Sequence< rtl::OUString >( aMap.size() );
[ # # ]
87 [ # # ][ # # ]: 0 : rPluginTypes = Sequence< rtl::OUString >( aMap.size() );
[ # # ]
88 [ # # ]: 0 : rtl::OUString* pPluginNames = rPluginNames.getArray();
89 [ # # ]: 0 : rtl::OUString* pPluginTypes = rPluginTypes.getArray();
90 : 0 : int nIndex = 0;
91 [ # # ]: 0 : for ( FilterMap::iterator iPos = aMap.begin(); iPos != aMap.end(); ++iPos )
92 : : {
93 [ # # ]: 0 : String aText( (*iPos).first );
94 [ # # ]: 0 : String aType;
95 : 0 : StrSet& rTypes = (*iPos).second;
96 : 0 : StrSet::iterator i = rTypes.begin();
97 [ # # ][ # # ]: 0 : while ( i != rTypes.end() )
98 : : {
99 [ # # ][ # # ]: 0 : aType += (*i);
100 [ # # ]: 0 : ++i;
101 [ # # ][ # # ]: 0 : if ( i != rTypes.end() )
102 [ # # ]: 0 : aType += ';';
103 : : }
104 : :
105 [ # # ]: 0 : if ( aType.Len() )
106 : : {
107 [ # # ]: 0 : aText += rtl::OUString( " (" );
108 [ # # ]: 0 : aText += aType;
109 [ # # ]: 0 : aText += ')';
110 [ # # ]: 0 : pPluginNames[nIndex] = aText;
111 [ # # ]: 0 : pPluginTypes[nIndex] = aType;
112 : 0 : nIndex++;
113 : : }
114 [ # # ][ # # ]: 0 : }
115 [ # # ]: 0 : rPluginNames.realloc( nIndex );
116 [ # # ][ # # ]: 0 : rPluginTypes.realloc( nIndex );
117 : 0 : }
118 : :
119 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|