1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sfx2/docfile.hxx>
21 #include <com/sun/star/plugin/PluginDescription.hpp>
22 #include <com/sun/star/plugin/PluginManager.hpp>
23 #include <com/sun/star/plugin/XPluginManager.hpp>
24 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
26 #include <comphelper/processfactory.hxx>
28 #include "svx/pfiledlg.hxx"
29 #include <svx/dialogs.hrc>
31 #include <svx/dialmgr.hxx>
34 using namespace ::com::sun::star
;
36 sal_Char
const sAudio
[] = "audio";
37 sal_Char
const sVideo
[] = "video";
39 // Filedialog to insert Plugin-Fileformats
41 ErrCode
SvxPluginFileDlg::Execute()
43 return maFileDlg
.Execute();
46 OUString
SvxPluginFileDlg::GetPath() const
48 return maFileDlg
.GetPath();
51 SvxPluginFileDlg::SvxPluginFileDlg (vcl::Window
*, sal_uInt16 nKind
)
52 : maFileDlg(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
, SFXWB_INSERT
)
54 // set title of the dialogwindow
57 case SID_INSERT_SOUND
:
59 maFileDlg
.SetTitle(SVX_RESSTR(STR_INSERT_SOUND_TITLE
));
62 case SID_INSERT_VIDEO
:
64 maFileDlg
.SetTitle(SVX_RESSTR(STR_INSERT_VIDEO_TITLE
));
69 // fill the filterlist of the filedialog with data of installed plugins
70 uno::Reference
< uno::XComponentContext
> xContext
= comphelper::getProcessComponentContext();
71 uno::Reference
< plugin::XPluginManager
> rPluginManager( plugin::PluginManager::create(xContext
) );
73 const uno::Sequence
<plugin::PluginDescription
> aSeq( rPluginManager
->getPluginDescriptions() );
74 const plugin::PluginDescription
* pDescription
= aSeq
.getConstArray();
75 sal_Int32 nAnzahlPlugins
= rPluginManager
->getPluginDescriptions().getLength();
77 std::list
< OUString
> aPlugNames
;
78 std::list
< OUString
> aPlugExtensions
;
79 std::list
< OUString
>::iterator j
;
80 std::list
< OUString
>::iterator k
;
81 std::list
< OUString
>::const_iterator end
;
83 for ( int i
= 0; i
< nAnzahlPlugins
; i
++ )
85 OUString
aStrPlugMIMEType( pDescription
[i
].Mimetype
);
86 OUString
aStrPlugName( pDescription
[i
].Description
);
87 OUString
aStrPlugExtension( pDescription
[i
].Extension
);
89 aStrPlugMIMEType
= aStrPlugMIMEType
.toAsciiLowerCase();
90 aStrPlugExtension
= aStrPlugExtension
.toAsciiLowerCase();
92 if ( ( nKind
== SID_INSERT_SOUND
&& aStrPlugMIMEType
.startsWith( sAudio
) ) ||
93 ( nKind
== SID_INSERT_VIDEO
&& aStrPlugMIMEType
.startsWith( sVideo
) ) )
95 // extension already in the filterlist of the filedlg ?
96 bool bAlreadyExist
= false;
97 for ( j
= aPlugExtensions
.begin(), end
= aPlugExtensions
.end(); j
!= end
&& !bAlreadyExist
; ++j
)
99 bAlreadyExist
= (j
->indexOf( aStrPlugExtension
) != -1 );
102 if ( !bAlreadyExist
)
104 // filterdescription already there?
105 // (then append the new extension to the existing filter)
107 for ( j
= aPlugNames
.begin(),
108 k
= aPlugExtensions
.begin(),
109 end
= aPlugNames
.end();
110 j
!= end
&& nfound
!= 0; )
112 if ( ( nfound
= j
->indexOf( aStrPlugName
) ) == 0 )
114 if ( !aStrPlugExtension
.isEmpty() )
115 aStrPlugExtension
+= ";";
116 aStrPlugExtension
+= *k
;
118 // remove old entry, increment (iterators are invalid thereafter, thus the postincrement)
119 aPlugNames
.erase(j
++);
120 aPlugExtensions
.erase(k
++);
122 // update end iterator (which may be invalid, too!)
123 end
= aPlugNames
.end();
132 // build filterdescription
133 aStrPlugName
+= " (";
134 aStrPlugName
+= aStrPlugExtension
;
137 // use a own description for the video-formate avi, mov and mpeg
138 // the descriptions of these MIME-types are not very meaningful
139 const sal_Char sAVI
[] = "*.avi";
140 const sal_Char sMOV
[] = "*.mov";
141 const sal_Char sMPG
[] = "*.mpg";
142 const sal_Char sMPE
[] = "*.mpe";
143 const sal_Char sMPEG
[] = "*.mpeg";
145 if ( aStrPlugExtension
.equalsIgnoreAsciiCase( sAVI
) )
146 aStrPlugName
= SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_AVI
);
147 else if ( aStrPlugExtension
.equalsIgnoreAsciiCase( sMOV
) )
148 aStrPlugName
= SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_MOV
);
149 else if ( aStrPlugExtension
.indexOf( sMPG
) != -1 ||
150 aStrPlugExtension
.indexOf( sMPE
) != -1 ||
151 aStrPlugExtension
.indexOf( sMPEG
) != -1 )
152 aStrPlugName
= SVX_RESSTR(STR_INSERT_VIDEO_EXTFILTER_MPEG
);
154 aPlugNames
.push_back( aStrPlugName
);
155 aPlugExtensions
.push_back( aStrPlugExtension
);
160 // add filter to dialog
161 for ( j
= aPlugNames
.begin(),
162 k
= aPlugExtensions
.begin(),
163 end
= aPlugNames
.end();
166 maFileDlg
.AddFilter( *j
, *k
);
169 // add the All-Filter
170 OUString
aAllFilter( ResId( STR_EXTFILTER_ALL
, DIALOG_MGR() ).toString() );
171 maFileDlg
.AddFilter(aAllFilter
, "*.*");
174 maFileDlg
.SetCurrentFilter( aAllFilter
);
177 SvxPluginFileDlg::~SvxPluginFileDlg()
181 void SvxPluginFileDlg::SetContext( sfx2::FileDialogHelper::Context _eNewContext
)
183 maFileDlg
.SetContext( _eNewContext
);
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */