1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pfiledlg.cxx,v $
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 // include ---------------------------------------------------------------
35 #include <sfx2/docfile.hxx>
36 #include <com/sun/star/plugin/PluginDescription.hpp>
37 #include <com/sun/star/plugin/XPluginManager.hpp>
39 #include <comphelper/processfactory.hxx>
41 #include "pfiledlg.hxx"
42 #include <svx/dialogs.hrc>
44 #include <svx/dialmgr.hxx>
47 using namespace ::rtl
;
48 using namespace ::com::sun::star
;
50 sal_Char __READONLY_DATA sAudio
[] = "audio";
51 sal_Char __READONLY_DATA sVideo
[] = "video";
53 /*************************************************************************
55 |* Filedialog to insert Plugin-Fileformats
57 \************************************************************************/
59 ErrCode
SvxPluginFileDlg::Execute()
61 return maFileDlg
.Execute();
64 String
SvxPluginFileDlg::GetPath() const
66 return maFileDlg
.GetPath();
69 SvxPluginFileDlg::SvxPluginFileDlg (Window
*, sal_uInt16 nKind
) :
70 maFileDlg(SFXWB_INSERT
)
72 // set title of the dialogwindow
75 case SID_INSERT_SOUND
:
77 maFileDlg
.SetTitle(SVX_RESSTR(STR_INSERT_SOUND_TITLE
));
80 case SID_INSERT_VIDEO
:
82 maFileDlg
.SetTitle(SVX_RESSTR(STR_INSERT_VIDEO_TITLE
));
87 // fill the filterlist of the filedialog with data of installed plugins
88 uno::Reference
< lang::XMultiServiceFactory
> xMgr( ::comphelper::getProcessServiceFactory() );
92 uno::Reference
< plugin::XPluginManager
> rPluginManager( xMgr
->createInstance(
93 OUString::createFromAscii( "com.sun.star.plugin.PluginManager" ) ), uno::UNO_QUERY
);
94 if ( rPluginManager
.is() )
96 const uno::Sequence
<plugin::PluginDescription
> aSeq( rPluginManager
->getPluginDescriptions() );
97 const plugin::PluginDescription
* pDescription
= aSeq
.getConstArray();
98 sal_Int32 nAnzahlPlugins
= rPluginManager
->getPluginDescriptions().getLength();
100 std::list
< String
> aPlugNames
;
101 std::list
< String
> aPlugExtensions
;
102 std::list
< String
>::iterator j
;
103 std::list
< String
>::iterator k
;
104 std::list
< String
>::const_iterator end
;
106 for ( int i
= 0; i
< nAnzahlPlugins
; i
++ )
108 String
aStrPlugMIMEType( pDescription
[i
].Mimetype
);
109 String
aStrPlugName( pDescription
[i
].Description
);
110 String
aStrPlugExtension( pDescription
[i
].Extension
);
112 aStrPlugMIMEType
.ToLowerAscii();
113 aStrPlugExtension
.ToLowerAscii();
115 if ( ( nKind
== SID_INSERT_SOUND
&& aStrPlugMIMEType
.SearchAscii ( sAudio
) == 0 ) ||
116 ( nKind
== SID_INSERT_VIDEO
&& aStrPlugMIMEType
.SearchAscii ( sVideo
) == 0 ) )
118 // extension already in the filterlist of the filedlg ?
119 sal_Bool bAlreadyExist
= sal_False
;
120 for ( j
= aPlugExtensions
.begin(), end
= aPlugExtensions
.end(); j
!= end
&& !bAlreadyExist
; ++j
)
122 bAlreadyExist
= (j
->Search( aStrPlugExtension
) != STRING_NOTFOUND
);
125 if ( !bAlreadyExist
)
127 // filterdescription already there?
128 // (then append the new extension to the existing filter)
130 for ( j
= aPlugNames
.begin(),
131 k
= aPlugExtensions
.begin(),
132 end
= aPlugNames
.end();
133 j
!= end
&& nfound
!= 0; )
135 if ( ( nfound
= j
->Search( aStrPlugName
) ) == 0 )
137 if ( aStrPlugExtension
.Len() > 0 )
138 aStrPlugExtension
.Insert( sal_Unicode( ';' ) );
139 aStrPlugExtension
.Insert( *k
);
141 // remove old entry, increment (iterators are invalid thereafter, thus the postincrement)
142 aPlugNames
.erase(j
++); aPlugExtensions
.erase(k
++);
144 // update end iterator (which may be invalid, too!)
145 end
= aPlugNames
.end();
154 // build filterdescription
155 aStrPlugName
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " (" ) );
156 aStrPlugName
.Append( aStrPlugExtension
);
157 aStrPlugName
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ")" ) );
159 // use a own description for the video-formate avi, mov and mpeg
160 // the descriptions of these MIME-types are not very meaningful
161 const sal_Char sAVI
[] = "*.avi";
162 const sal_Char sMOV
[] = "*.mov";
163 const sal_Char sMPG
[] = "*.mpg";
164 const sal_Char sMPE
[] = "*.mpe";
165 const sal_Char sMPEG
[] = "*.mpeg";
167 if ( aStrPlugExtension
.EqualsIgnoreCaseAscii( sAVI
) )
168 aStrPlugName
= SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_AVI
);
169 else if ( aStrPlugExtension
.EqualsIgnoreCaseAscii( sMOV
) )
170 aStrPlugName
= SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_MOV
);
171 else if ( aStrPlugExtension
.SearchAscii( sMPG
) != STRING_NOTFOUND
||
172 aStrPlugExtension
.SearchAscii( sMPE
) != STRING_NOTFOUND
||
173 aStrPlugExtension
.SearchAscii( sMPEG
) != STRING_NOTFOUND
)
174 aStrPlugName
= SVX_RESSTR(STR_INSERT_VIDEO_EXTFILTER_MPEG
);
176 aPlugNames
.push_back( aStrPlugName
);
177 aPlugExtensions
.push_back( aStrPlugExtension
);
182 // add filter to dialog
183 for ( j
= aPlugNames
.begin(),
184 k
= aPlugExtensions
.begin(),
185 end
= aPlugNames
.end();
188 maFileDlg
.AddFilter( *j
, *k
);
193 // add the All-Filter
194 String
aAllFilter( ResId( STR_EXTFILTER_ALL
, DIALOG_MGR() ) );
195 maFileDlg
.AddFilter( aAllFilter
, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "*.*" ) ) );
198 maFileDlg
.SetCurrentFilter( aAllFilter
);
201 /*************************************************************************
205 \************************************************************************/
207 SvxPluginFileDlg::~SvxPluginFileDlg()
211 /*************************************************************************
213 |* Plugins available for the the MIME-Typ in nKind
214 |* (whith nKind = SID_INSERT_SOUND for MIME-Type audio
215 |* SID_INSERT_VIDEO for MIME-Type video
217 \************************************************************************/
219 #define PFDLG_CHECKED_SOUND 0x0001
220 #define PFDLG_CHECKED_VIDEO 0x0002
221 #define PFDLG_FOUND_SOUND 0x0004
222 #define PFDLG_FOUND_VIDEO 0x0008
224 bool SvxPluginFileDlg::IsAvailable (sal_uInt16 nKind
)
226 static sal_uInt16 nCheck
= 0;
228 if ( nKind
== SID_INSERT_SOUND
&& ( nCheck
& PFDLG_CHECKED_SOUND
) )
229 return (nCheck
& PFDLG_FOUND_SOUND
) != 0;
230 if ( nKind
== SID_INSERT_VIDEO
&& ( nCheck
& PFDLG_CHECKED_VIDEO
) )
231 return (nCheck
& PFDLG_FOUND_VIDEO
) != 0;
234 uno::Reference
< lang::XMultiServiceFactory
> xMgr( ::comphelper::getProcessServiceFactory() );
238 uno::Reference
< plugin::XPluginManager
> rPluginManager
= uno::Reference
< plugin::XPluginManager
> ( xMgr
->createInstance( OUString::createFromAscii( "com.sun.star.plugin.PluginManager" ) ), uno::UNO_QUERY
);
239 if( rPluginManager
.is() )
241 const uno::Sequence
<plugin::PluginDescription
> aSeq( rPluginManager
->getPluginDescriptions() );
242 const plugin::PluginDescription
* pDescription
= aSeq
.getConstArray();
243 sal_Int32 nAnzahlPlugins
= rPluginManager
->getPluginDescriptions().getLength();
245 for ( sal_uInt16 i
= 0; i
< nAnzahlPlugins
&& !bFound
; ++i
)
247 String
aStrPlugMIMEType( pDescription
[i
].Mimetype
);
250 case SID_INSERT_SOUND
:
252 nCheck
|= PFDLG_CHECKED_SOUND
;
254 if( aStrPlugMIMEType
.SearchAscii( sAudio
) == 0 )
257 nCheck
|= PFDLG_FOUND_SOUND
;
261 case SID_INSERT_VIDEO
:
263 nCheck
|= PFDLG_CHECKED_VIDEO
;
265 if (aStrPlugMIMEType
.SearchAscii( sVideo
) == 0)
268 nCheck
|= PFDLG_FOUND_VIDEO
;
280 void SvxPluginFileDlg::SetDialogHelpId( const sal_Int32 _nHelpId
)
282 maFileDlg
.SetDialogHelpId( _nHelpId
);
285 void SvxPluginFileDlg::SetContext( sfx2::FileDialogHelper::Context _eNewContext
)
287 maFileDlg
.SetContext( _eNewContext
);