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