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 ::rtl
;
35 using namespace ::com::sun::star
;
37 sal_Char
const sAudio
[] = "audio";
38 sal_Char
const sVideo
[] = "video";
40 // Filedialog to insert Plugin-Fileformats
42 ErrCode
SvxPluginFileDlg::Execute()
44 return maFileDlg
.Execute();
47 String
SvxPluginFileDlg::GetPath() const
49 return maFileDlg
.GetPath();
52 SvxPluginFileDlg::SvxPluginFileDlg (Window
*, sal_uInt16 nKind
)
53 : maFileDlg(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
, SFXWB_INSERT
)
55 // set title of the dialogwindow
58 case SID_INSERT_SOUND
:
60 maFileDlg
.SetTitle(SVX_RESSTR(STR_INSERT_SOUND_TITLE
));
63 case SID_INSERT_VIDEO
:
65 maFileDlg
.SetTitle(SVX_RESSTR(STR_INSERT_VIDEO_TITLE
));
70 // fill the filterlist of the filedialog with data of installed plugins
71 uno::Reference
< uno::XComponentContext
> xContext
= comphelper::getProcessComponentContext();
72 uno::Reference
< plugin::XPluginManager
> rPluginManager( plugin::PluginManager::create(xContext
) );
74 const uno::Sequence
<plugin::PluginDescription
> aSeq( rPluginManager
->getPluginDescriptions() );
75 const plugin::PluginDescription
* pDescription
= aSeq
.getConstArray();
76 sal_Int32 nAnzahlPlugins
= rPluginManager
->getPluginDescriptions().getLength();
78 std::list
< String
> aPlugNames
;
79 std::list
< String
> aPlugExtensions
;
80 std::list
< String
>::iterator j
;
81 std::list
< String
>::iterator k
;
82 std::list
< String
>::const_iterator end
;
84 for ( int i
= 0; i
< nAnzahlPlugins
; i
++ )
86 String
aStrPlugMIMEType( pDescription
[i
].Mimetype
);
87 String
aStrPlugName( pDescription
[i
].Description
);
88 String
aStrPlugExtension( pDescription
[i
].Extension
);
90 aStrPlugMIMEType
.ToLowerAscii();
91 aStrPlugExtension
.ToLowerAscii();
93 if ( ( nKind
== SID_INSERT_SOUND
&& aStrPlugMIMEType
.SearchAscii ( sAudio
) == 0 ) ||
94 ( nKind
== SID_INSERT_VIDEO
&& aStrPlugMIMEType
.SearchAscii ( sVideo
) == 0 ) )
96 // extension already in the filterlist of the filedlg ?
97 bool bAlreadyExist
= false;
98 for ( j
= aPlugExtensions
.begin(), end
= aPlugExtensions
.end(); j
!= end
&& !bAlreadyExist
; ++j
)
100 bAlreadyExist
= (j
->Search( aStrPlugExtension
) != STRING_NOTFOUND
);
103 if ( !bAlreadyExist
)
105 // filterdescription already there?
106 // (then append the new extension to the existing filter)
108 for ( j
= aPlugNames
.begin(),
109 k
= aPlugExtensions
.begin(),
110 end
= aPlugNames
.end();
111 j
!= end
&& nfound
!= 0; )
113 if ( ( nfound
= j
->Search( aStrPlugName
) ) == 0 )
115 if ( aStrPlugExtension
.Len() > 0 )
116 aStrPlugExtension
.Insert( sal_Unicode( ';' ) );
117 aStrPlugExtension
.Insert( *k
);
119 // remove old entry, increment (iterators are invalid thereafter, thus the postincrement)
120 aPlugNames
.erase(j
++); aPlugExtensions
.erase(k
++);
122 // update end iterator (which may be invalid, too!)
123 end
= aPlugNames
.end();
132 // build filterdescription
133 aStrPlugName
.AppendAscii( " (" );
134 aStrPlugName
.Append( aStrPlugExtension
);
135 aStrPlugName
.AppendAscii( ")" );
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
.EqualsIgnoreCaseAscii( sAVI
) )
146 aStrPlugName
= SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_AVI
);
147 else if ( aStrPlugExtension
.EqualsIgnoreCaseAscii( sMOV
) )
148 aStrPlugName
= SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_MOV
);
149 else if ( aStrPlugExtension
.SearchAscii( sMPG
) != STRING_NOTFOUND
||
150 aStrPlugExtension
.SearchAscii( sMPE
) != STRING_NOTFOUND
||
151 aStrPlugExtension
.SearchAscii( sMPEG
) != STRING_NOTFOUND
)
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 String
aAllFilter( ResId( STR_EXTFILTER_ALL
, DIALOG_MGR() ) );
171 maFileDlg
.AddFilter(aAllFilter
, OUString("*.*"));
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: */