xref: /trunk/main/cui/source/dialogs/plfilter.cxx (revision 2ee96f1c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_cui.hxx"
26 
27 #include <set>
28 #include <map>
29 #include <unotools/processfactory.hxx>
30 
31 #include <tools/debug.hxx>
32 #include <vcl/stdtext.hxx>
33 
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/plugin/PluginDescription.hpp>
36 #include <com/sun/star/plugin/XPluginManager.hpp>
37 
38 using namespace std;
39 using namespace com::sun::star::uno;
40 using namespace com::sun::star::lang;
41 using namespace com::sun::star::plugin;
42 
43 struct ltstr
44 {
operator ()ltstr45 	bool operator()( const String& s1, const String& s2 ) const
46 	{
47 		return ( s1.CompareTo( s2 ) == COMPARE_LESS );
48 	}
49 };
50 
51 typedef set< String, ltstr > StrSet;
52 typedef map< String, StrSet, ltstr > FilterMap;
53 
54 
55 //==================================================================================================
fillNetscapePluginFilters(Sequence<rtl::OUString> & rPluginNames,Sequence<rtl::OUString> & rPluginTypes)56 void fillNetscapePluginFilters( Sequence< rtl::OUString >& rPluginNames, Sequence< rtl::OUString >& rPluginTypes )
57 {
58 	Reference< XMultiServiceFactory > xMan( ::utl::getProcessServiceFactory() );
59 	Reference< XPluginManager > xPMgr( xMan->createInstance(
60 		rtl::OUString::createFromAscii("com.sun.star.plugin.PluginManager") ), UNO_QUERY );
61 
62 	if ( xPMgr.is() )
63 	{
64 		FilterMap aMap;
65 
66 		// mimetypes zusammenfassen: eine description, mehrere extensions
67 
68 		Sequence<PluginDescription > aDescriptions( xPMgr->getPluginDescriptions() );
69 		const PluginDescription * pDescriptions = aDescriptions.getConstArray();
70 		for ( sal_uInt32 nPos = aDescriptions.getLength(); nPos--; )
71 		{
72 			const PluginDescription & rDescr = pDescriptions[nPos];
73 
74 			StrSet& rTypes = aMap[ rDescr.Description ];
75 			String aExtension( rDescr.Extension );
76 
77 			for ( sal_uInt16 nCnt = aExtension.GetTokenCount( ';' ); nCnt--; )
78 			{
79 				// no default plugins anymore
80 				String aExt( aExtension.GetToken( nCnt, ';' ) );
81 				if ( aExt.CompareToAscii( "*.*" ) != COMPARE_EQUAL )
82 					rTypes.insert( aExt );
83 			}
84 		}
85 
86         rPluginNames = Sequence< rtl::OUString >( aMap.size() );
87         rPluginTypes = Sequence< rtl::OUString >( aMap.size() );
88         rtl::OUString* pPluginNames = rPluginNames.getArray();
89         rtl::OUString* pPluginTypes = rPluginTypes.getArray();
90         int nIndex = 0;
91 		for ( FilterMap::iterator iPos = aMap.begin(); iPos != aMap.end(); ++iPos )
92 		{
93 			String aText( (*iPos).first );
94 			String aType;
95 			StrSet& rTypes = (*iPos).second;
96 			StrSet::iterator i = rTypes.begin();
97 			while ( i != rTypes.end() )
98 			{
99 				aType += (*i);
100 				++i;
101 				if ( i != rTypes.end() )
102 					aType += ';';
103 			}
104 
105 			if ( aType.Len() )
106 			{
107 				aText += String::CreateFromAscii( " (" );
108 				aText += aType;
109 				aText += ')';
110                 pPluginNames[nIndex] = aText;
111                 pPluginTypes[nIndex] = aType;
112                 nIndex++;
113 			}
114 		}
115         rPluginNames.realloc( nIndex );
116         rPluginTypes.realloc( nIndex );
117 	}
118 	else
119 		ShowServiceNotAvailableError( NULL,
120 			String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.plugin.PluginManager" ) ), sal_True );
121 }
122 
123