xref: /aoo42x/main/svx/source/dialog/pfiledlg.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // include ---------------------------------------------------------------
32*cdf0e10cSrcweir #include <sfx2/docfile.hxx>
33*cdf0e10cSrcweir #include <com/sun/star/plugin/PluginDescription.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/plugin/XPluginManager.hpp>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include "svx/pfiledlg.hxx"
39*cdf0e10cSrcweir #include <svx/dialogs.hrc>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <svx/dialmgr.hxx>
42*cdf0e10cSrcweir #include <list>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir using namespace ::rtl;
45*cdf0e10cSrcweir using namespace ::com::sun::star;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir sal_Char __READONLY_DATA sAudio[] = "audio";
48*cdf0e10cSrcweir sal_Char __READONLY_DATA sVideo[] = "video";
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir /*************************************************************************
51*cdf0e10cSrcweir |*
52*cdf0e10cSrcweir |* Filedialog to insert Plugin-Fileformats
53*cdf0e10cSrcweir |*
54*cdf0e10cSrcweir \************************************************************************/
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir ErrCode SvxPluginFileDlg::Execute()
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir 	return maFileDlg.Execute();
59*cdf0e10cSrcweir }
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir String SvxPluginFileDlg::GetPath() const
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir 	return maFileDlg.GetPath();
64*cdf0e10cSrcweir }
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir SvxPluginFileDlg::SvxPluginFileDlg (Window *, sal_uInt16 nKind ) :
67*cdf0e10cSrcweir 	maFileDlg(SFXWB_INSERT)
68*cdf0e10cSrcweir {
69*cdf0e10cSrcweir 	// set title of the dialogwindow
70*cdf0e10cSrcweir 	switch (nKind)
71*cdf0e10cSrcweir 	{
72*cdf0e10cSrcweir 		case SID_INSERT_SOUND :
73*cdf0e10cSrcweir 		{
74*cdf0e10cSrcweir 			maFileDlg.SetTitle(SVX_RESSTR(STR_INSERT_SOUND_TITLE));
75*cdf0e10cSrcweir 		}
76*cdf0e10cSrcweir 		break;
77*cdf0e10cSrcweir 		case SID_INSERT_VIDEO :
78*cdf0e10cSrcweir 		{
79*cdf0e10cSrcweir 			maFileDlg.SetTitle(SVX_RESSTR(STR_INSERT_VIDEO_TITLE));
80*cdf0e10cSrcweir 		}
81*cdf0e10cSrcweir 		break;
82*cdf0e10cSrcweir 	}
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	// fill the filterlist of the filedialog with data of installed plugins
85*cdf0e10cSrcweir 	uno::Reference< lang::XMultiServiceFactory >  xMgr( ::comphelper::getProcessServiceFactory() );
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 	if( xMgr.is() )
88*cdf0e10cSrcweir 	{
89*cdf0e10cSrcweir 		uno::Reference< plugin::XPluginManager > rPluginManager( xMgr->createInstance(
90*cdf0e10cSrcweir 			OUString::createFromAscii( "com.sun.star.plugin.PluginManager" ) ), uno::UNO_QUERY );
91*cdf0e10cSrcweir 		if ( rPluginManager.is() )
92*cdf0e10cSrcweir 		{
93*cdf0e10cSrcweir 			const uno::Sequence<plugin::PluginDescription > aSeq( rPluginManager->getPluginDescriptions() );
94*cdf0e10cSrcweir 			const plugin::PluginDescription* pDescription = aSeq.getConstArray();
95*cdf0e10cSrcweir 			sal_Int32 nAnzahlPlugins = rPluginManager->getPluginDescriptions().getLength();
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 			std::list< String >	aPlugNames;
98*cdf0e10cSrcweir 			std::list< String >	aPlugExtensions;
99*cdf0e10cSrcweir 			std::list< String >::iterator j;
100*cdf0e10cSrcweir 			std::list< String >::iterator k;
101*cdf0e10cSrcweir 			std::list< String >::const_iterator end;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 			for ( int i = 0; i < nAnzahlPlugins; i++ )
104*cdf0e10cSrcweir 			{
105*cdf0e10cSrcweir 				String aStrPlugMIMEType( pDescription[i].Mimetype );
106*cdf0e10cSrcweir 				String aStrPlugName( pDescription[i].Description );
107*cdf0e10cSrcweir 				String aStrPlugExtension( pDescription[i].Extension );
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 				aStrPlugMIMEType.ToLowerAscii();
110*cdf0e10cSrcweir 				aStrPlugExtension.ToLowerAscii();
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 				if ( ( nKind == SID_INSERT_SOUND && aStrPlugMIMEType.SearchAscii ( sAudio ) == 0 ) ||
113*cdf0e10cSrcweir 					 ( nKind == SID_INSERT_VIDEO && aStrPlugMIMEType.SearchAscii ( sVideo ) == 0 ) )
114*cdf0e10cSrcweir 				{
115*cdf0e10cSrcweir 					// extension already in the filterlist of the filedlg ?
116*cdf0e10cSrcweir 					sal_Bool bAlreadyExist = sal_False;
117*cdf0e10cSrcweir 					for ( j = aPlugExtensions.begin(), end = aPlugExtensions.end(); j != end && !bAlreadyExist; ++j )
118*cdf0e10cSrcweir 					{
119*cdf0e10cSrcweir 						bAlreadyExist = (j->Search( aStrPlugExtension ) != STRING_NOTFOUND );
120*cdf0e10cSrcweir 					}
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 					if ( !bAlreadyExist )
123*cdf0e10cSrcweir 					{
124*cdf0e10cSrcweir 						// filterdescription already there?
125*cdf0e10cSrcweir 						// (then append the new extension to the existing filter)
126*cdf0e10cSrcweir 						int nfound = -1;
127*cdf0e10cSrcweir  						for ( j = aPlugNames.begin(),
128*cdf0e10cSrcweir 								  k = aPlugExtensions.begin(),
129*cdf0e10cSrcweir 								  end = aPlugNames.end();
130*cdf0e10cSrcweir 							  j != end && nfound != 0;  )
131*cdf0e10cSrcweir 						{
132*cdf0e10cSrcweir 							if ( ( nfound = j->Search( aStrPlugName ) ) == 0 )
133*cdf0e10cSrcweir 							{
134*cdf0e10cSrcweir 								if ( aStrPlugExtension.Len() > 0 )
135*cdf0e10cSrcweir 									aStrPlugExtension.Insert( sal_Unicode( ';' ) );
136*cdf0e10cSrcweir 								aStrPlugExtension.Insert( *k );
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 								// remove old entry, increment (iterators are invalid thereafter, thus the postincrement)
139*cdf0e10cSrcweir 								aPlugNames.erase(j++); aPlugExtensions.erase(k++);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 								// update end iterator (which may be invalid, too!)
142*cdf0e10cSrcweir 								end = aPlugNames.end();
143*cdf0e10cSrcweir 							}
144*cdf0e10cSrcweir 							else
145*cdf0e10cSrcweir 							{
146*cdf0e10cSrcweir 								// next element
147*cdf0e10cSrcweir 								++j; ++k;
148*cdf0e10cSrcweir 							}
149*cdf0e10cSrcweir 						}
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 						// build filterdescription
152*cdf0e10cSrcweir 						aStrPlugName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "  (" ) );
153*cdf0e10cSrcweir 						aStrPlugName.Append( aStrPlugExtension );
154*cdf0e10cSrcweir 						aStrPlugName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ")" ) );
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 						// use a own description for the video-formate avi, mov and mpeg
157*cdf0e10cSrcweir 						// the descriptions of these MIME-types are not very meaningful
158*cdf0e10cSrcweir 						const sal_Char sAVI[] = "*.avi";
159*cdf0e10cSrcweir 						const sal_Char sMOV[] = "*.mov";
160*cdf0e10cSrcweir 						const sal_Char sMPG[] = "*.mpg";
161*cdf0e10cSrcweir 						const sal_Char sMPE[] = "*.mpe";
162*cdf0e10cSrcweir 						const sal_Char sMPEG[] = "*.mpeg";
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 						if ( aStrPlugExtension.EqualsIgnoreCaseAscii( sAVI ) )
165*cdf0e10cSrcweir 							aStrPlugName = SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_AVI );
166*cdf0e10cSrcweir 						else if ( aStrPlugExtension.EqualsIgnoreCaseAscii( sMOV ) )
167*cdf0e10cSrcweir 							aStrPlugName = SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_MOV );
168*cdf0e10cSrcweir 						else if ( aStrPlugExtension.SearchAscii( sMPG ) != STRING_NOTFOUND ||
169*cdf0e10cSrcweir 								  aStrPlugExtension.SearchAscii( sMPE ) != STRING_NOTFOUND ||
170*cdf0e10cSrcweir 								  aStrPlugExtension.SearchAscii( sMPEG ) != STRING_NOTFOUND )
171*cdf0e10cSrcweir 							aStrPlugName = SVX_RESSTR(STR_INSERT_VIDEO_EXTFILTER_MPEG);
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 						aPlugNames.push_back( aStrPlugName );
174*cdf0e10cSrcweir 						aPlugExtensions.push_back( aStrPlugExtension );
175*cdf0e10cSrcweir 					}
176*cdf0e10cSrcweir 				}
177*cdf0e10cSrcweir 			}
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 			// add filter to dialog
180*cdf0e10cSrcweir 			for ( j = aPlugNames.begin(),
181*cdf0e10cSrcweir 					  k = aPlugExtensions.begin(),
182*cdf0e10cSrcweir 					  end = aPlugNames.end();
183*cdf0e10cSrcweir 				  j != end; ++j, ++k )
184*cdf0e10cSrcweir 			{
185*cdf0e10cSrcweir 				maFileDlg.AddFilter( *j, *k );
186*cdf0e10cSrcweir 			}
187*cdf0e10cSrcweir 		}
188*cdf0e10cSrcweir 	}
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	// add the All-Filter
191*cdf0e10cSrcweir     String aAllFilter( ResId( STR_EXTFILTER_ALL, DIALOG_MGR() ) );
192*cdf0e10cSrcweir 	maFileDlg.AddFilter( aAllFilter, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "*.*" ) ) );
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 	// and activate him
195*cdf0e10cSrcweir 	maFileDlg.SetCurrentFilter( aAllFilter );
196*cdf0e10cSrcweir }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir /*************************************************************************
199*cdf0e10cSrcweir |*
200*cdf0e10cSrcweir |* Dtor
201*cdf0e10cSrcweir |*
202*cdf0e10cSrcweir \************************************************************************/
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir SvxPluginFileDlg::~SvxPluginFileDlg()
205*cdf0e10cSrcweir {
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir /*************************************************************************
209*cdf0e10cSrcweir |*
210*cdf0e10cSrcweir |* Plugins available for the the MIME-Typ in nKind
211*cdf0e10cSrcweir |* (whith nKind = SID_INSERT_SOUND for MIME-Type audio
212*cdf0e10cSrcweir |*                SID_INSERT_VIDEO for MIME-Type video
213*cdf0e10cSrcweir |*
214*cdf0e10cSrcweir \************************************************************************/
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir #define PFDLG_CHECKED_SOUND		0x0001
217*cdf0e10cSrcweir #define PFDLG_CHECKED_VIDEO		0x0002
218*cdf0e10cSrcweir #define PFDLG_FOUND_SOUND		0x0004
219*cdf0e10cSrcweir #define PFDLG_FOUND_VIDEO		0x0008
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir bool SvxPluginFileDlg::IsAvailable (sal_uInt16 nKind)
222*cdf0e10cSrcweir {
223*cdf0e10cSrcweir 	static sal_uInt16 nCheck = 0;
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 	if ( nKind == SID_INSERT_SOUND && ( nCheck & PFDLG_CHECKED_SOUND ) )
226*cdf0e10cSrcweir 		return (nCheck & PFDLG_FOUND_SOUND) != 0;
227*cdf0e10cSrcweir 	if ( nKind == SID_INSERT_VIDEO && ( nCheck & PFDLG_CHECKED_VIDEO ) )
228*cdf0e10cSrcweir 		return (nCheck & PFDLG_FOUND_VIDEO) != 0;
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 	bool bFound = false;
231*cdf0e10cSrcweir 	uno::Reference< lang::XMultiServiceFactory >  xMgr( ::comphelper::getProcessServiceFactory() );
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 	if( xMgr.is() )
234*cdf0e10cSrcweir 	{
235*cdf0e10cSrcweir 		uno::Reference< plugin::XPluginManager >  rPluginManager = uno::Reference< plugin::XPluginManager > ( xMgr->createInstance( OUString::createFromAscii( "com.sun.star.plugin.PluginManager" ) ), uno::UNO_QUERY );
236*cdf0e10cSrcweir 		if( rPluginManager.is() )
237*cdf0e10cSrcweir 		{
238*cdf0e10cSrcweir 			const uno::Sequence<plugin::PluginDescription > aSeq( rPluginManager->getPluginDescriptions() );
239*cdf0e10cSrcweir 			const plugin::PluginDescription* pDescription = aSeq.getConstArray();
240*cdf0e10cSrcweir 			sal_Int32 nAnzahlPlugins = rPluginManager->getPluginDescriptions().getLength();
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 			for ( sal_uInt16 i = 0; i < nAnzahlPlugins && !bFound; ++i )
243*cdf0e10cSrcweir 			{
244*cdf0e10cSrcweir 				String aStrPlugMIMEType( pDescription[i].Mimetype );
245*cdf0e10cSrcweir 				switch (nKind)
246*cdf0e10cSrcweir 				{
247*cdf0e10cSrcweir 					case SID_INSERT_SOUND :
248*cdf0e10cSrcweir 					{
249*cdf0e10cSrcweir 						nCheck |= PFDLG_CHECKED_SOUND;
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 						if( aStrPlugMIMEType.SearchAscii( sAudio ) == 0 )
252*cdf0e10cSrcweir 						{
253*cdf0e10cSrcweir 							bFound = true;
254*cdf0e10cSrcweir 							nCheck |= PFDLG_FOUND_SOUND;
255*cdf0e10cSrcweir 						}
256*cdf0e10cSrcweir 					}
257*cdf0e10cSrcweir 					break;
258*cdf0e10cSrcweir 					case SID_INSERT_VIDEO :
259*cdf0e10cSrcweir 					{
260*cdf0e10cSrcweir 						nCheck |= PFDLG_CHECKED_VIDEO;
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 						if (aStrPlugMIMEType.SearchAscii( sVideo ) == 0)
263*cdf0e10cSrcweir 						{
264*cdf0e10cSrcweir 							bFound = true;
265*cdf0e10cSrcweir 							nCheck |= PFDLG_FOUND_VIDEO;
266*cdf0e10cSrcweir 						}
267*cdf0e10cSrcweir 					}
268*cdf0e10cSrcweir 					break;
269*cdf0e10cSrcweir 				}
270*cdf0e10cSrcweir 			}
271*cdf0e10cSrcweir 		}
272*cdf0e10cSrcweir 	}
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 	return bFound;
275*cdf0e10cSrcweir }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir void SvxPluginFileDlg::SetContext( sfx2::FileDialogHelper::Context _eNewContext )
278*cdf0e10cSrcweir {
279*cdf0e10cSrcweir 	maFileDlg.SetContext( _eNewContext );
280*cdf0e10cSrcweir }
281