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