Update ooo320-m1
[ooovba.git] / svx / source / cui / plfilter.cxx
blob2c8b4c86bfd17c7d6966d9a4b4ac63eb6b367a79
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: plfilter.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
38 #include <set>
39 #include <map>
40 #include <unotools/processfactory.hxx>
42 #include <tools/debug.hxx>
43 #include <vcl/stdtext.hxx>
45 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
46 #include <com/sun/star/plugin/PluginDescription.hpp>
47 #include <com/sun/star/plugin/XPluginManager.hpp>
49 using namespace std;
50 using namespace com::sun::star::uno;
51 using namespace com::sun::star::lang;
52 using namespace com::sun::star::plugin;
54 struct ltstr
56 bool operator()( const String& s1, const String& s2 ) const
58 return ( s1.CompareTo( s2 ) == COMPARE_LESS );
62 typedef set< String, ltstr > StrSet;
63 typedef map< String, StrSet, ltstr > FilterMap;
66 //==================================================================================================
67 void fillNetscapePluginFilters( Sequence< rtl::OUString >& rPluginNames, Sequence< rtl::OUString >& rPluginTypes )
69 Reference< XMultiServiceFactory > xMan( ::utl::getProcessServiceFactory() );
70 Reference< XPluginManager > xPMgr( xMan->createInstance(
71 rtl::OUString::createFromAscii("com.sun.star.plugin.PluginManager") ), UNO_QUERY );
73 if ( xPMgr.is() )
75 FilterMap aMap;
77 // mimetypes zusammenfassen: eine description, mehrere extensions
79 Sequence<PluginDescription > aDescriptions( xPMgr->getPluginDescriptions() );
80 const PluginDescription * pDescriptions = aDescriptions.getConstArray();
81 for ( UINT32 nPos = aDescriptions.getLength(); nPos--; )
83 const PluginDescription & rDescr = pDescriptions[nPos];
85 StrSet& rTypes = aMap[ rDescr.Description ];
86 String aExtension( rDescr.Extension );
88 for ( USHORT nCnt = aExtension.GetTokenCount( ';' ); nCnt--; )
90 // no default plugins anymore
91 String aExt( aExtension.GetToken( nCnt, ';' ) );
92 if ( aExt.CompareToAscii( "*.*" ) != COMPARE_EQUAL )
93 rTypes.insert( aExt );
97 rPluginNames = Sequence< rtl::OUString >( aMap.size() );
98 rPluginTypes = Sequence< rtl::OUString >( aMap.size() );
99 rtl::OUString* pPluginNames = rPluginNames.getArray();
100 rtl::OUString* pPluginTypes = rPluginTypes.getArray();
101 int nIndex = 0;
102 for ( FilterMap::iterator iPos = aMap.begin(); iPos != aMap.end(); ++iPos )
104 String aText( (*iPos).first );
105 String aType;
106 StrSet& rTypes = (*iPos).second;
107 StrSet::iterator i = rTypes.begin();
108 while ( i != rTypes.end() )
110 aType += (*i);
111 ++i;
112 if ( i != rTypes.end() )
113 aType += ';';
116 if ( aType.Len() )
118 aText += String::CreateFromAscii( " (" );
119 aText += aType;
120 aText += ')';
121 pPluginNames[nIndex] = aText;
122 pPluginTypes[nIndex] = aType;
123 nIndex++;
126 rPluginNames.realloc( nIndex );
127 rPluginTypes.realloc( nIndex );
129 else
130 ShowServiceNotAvailableError( NULL,
131 String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.plugin.PluginManager" ) ), TRUE );