bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / dialogs / plfilter.cxx
blob386ff6971d5e63744fe7d7c80b20adb2810f33d5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <set>
21 #include <map>
22 #include <comphelper/processfactory.hxx>
23 #include <comphelper/string.hxx>
25 #include <vcl/stdtext.hxx>
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>
32 #include <plfilter.hxx>
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;
39 struct ltstr
41 bool operator()( const OUString& s1, const OUString& s2 ) const
43 return s1.compareTo( s2 ) < 0;
47 typedef set< OUString, ltstr > StrSet;
48 typedef map< OUString, StrSet, ltstr > FilterMap;
52 void fillNetscapePluginFilters( Sequence< OUString >& rPluginNames, Sequence< OUString >& rPluginTypes )
54 Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
55 Reference< XPluginManager > xPMgr( PluginManager::create(xContext) );
57 FilterMap aMap;
59 // sum up the mimetypes: one description, multiple extensions
61 Sequence<PluginDescription > aDescriptions( xPMgr->getPluginDescriptions() );
62 const PluginDescription * pDescriptions = aDescriptions.getConstArray();
63 for ( sal_uInt32 nPos = aDescriptions.getLength(); nPos--; )
65 const PluginDescription & rDescr = pDescriptions[nPos];
67 StrSet& rTypes = aMap[ rDescr.Description ];
68 OUString aExtension( rDescr.Extension );
70 for ( sal_uInt16 nCnt = comphelper::string::getTokenCount(aExtension, ';'); nCnt--; )
72 // no default plugins anymore
73 OUString aExt( aExtension.getToken( nCnt, ';' ) );
74 if ( aExt == "*.*" )
75 rTypes.insert( aExt );
79 rPluginNames = Sequence< OUString >( aMap.size() );
80 rPluginTypes = Sequence< OUString >( aMap.size() );
81 OUString* pPluginNames = rPluginNames.getArray();
82 OUString* pPluginTypes = rPluginTypes.getArray();
83 int nIndex = 0;
84 for ( FilterMap::iterator iPos = aMap.begin(); iPos != aMap.end(); ++iPos )
86 OUString aText( (*iPos).first );
87 OUString aType;
88 StrSet& rTypes = (*iPos).second;
89 StrSet::iterator i = rTypes.begin();
90 while ( i != rTypes.end() )
92 aType += (*i);
93 ++i;
94 if ( i != rTypes.end() )
95 aType += ";";
98 if ( !aType.isEmpty() )
100 aText += " (";
101 aText += aType;
102 aText += ")";
103 pPluginNames[nIndex] = aText;
104 pPluginTypes[nIndex] = aType;
105 nIndex++;
108 rPluginNames.realloc( nIndex );
109 rPluginTypes.realloc( nIndex );
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */