Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
25 :
26 : #include <comphelper/processfactory.hxx>
27 :
28 : #include "svx/pfiledlg.hxx"
29 : #include <svx/dialogs.hrc>
30 :
31 : #include <svx/dialmgr.hxx>
32 : #include <list>
33 :
34 : using namespace ::rtl;
35 : using namespace ::com::sun::star;
36 :
37 : sal_Char const sAudio[] = "audio";
38 : sal_Char const sVideo[] = "video";
39 :
40 : // Filedialog to insert Plugin-Fileformats
41 :
42 0 : ErrCode SvxPluginFileDlg::Execute()
43 : {
44 0 : return maFileDlg.Execute();
45 : }
46 :
47 0 : String SvxPluginFileDlg::GetPath() const
48 : {
49 0 : return maFileDlg.GetPath();
50 : }
51 :
52 0 : SvxPluginFileDlg::SvxPluginFileDlg (Window *, sal_uInt16 nKind )
53 0 : : maFileDlg(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, SFXWB_INSERT)
54 : {
55 : // set title of the dialogwindow
56 0 : switch (nKind)
57 : {
58 : case SID_INSERT_SOUND :
59 : {
60 0 : maFileDlg.SetTitle(SVX_RESSTR(STR_INSERT_SOUND_TITLE));
61 : }
62 0 : break;
63 : case SID_INSERT_VIDEO :
64 : {
65 0 : maFileDlg.SetTitle(SVX_RESSTR(STR_INSERT_VIDEO_TITLE));
66 : }
67 0 : break;
68 : }
69 :
70 : // fill the filterlist of the filedialog with data of installed plugins
71 0 : uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
72 0 : uno::Reference< plugin::XPluginManager > rPluginManager( plugin::PluginManager::create(xContext) );
73 :
74 0 : const uno::Sequence<plugin::PluginDescription > aSeq( rPluginManager->getPluginDescriptions() );
75 0 : const plugin::PluginDescription* pDescription = aSeq.getConstArray();
76 0 : sal_Int32 nAnzahlPlugins = rPluginManager->getPluginDescriptions().getLength();
77 :
78 0 : std::list< String > aPlugNames;
79 0 : std::list< String > aPlugExtensions;
80 0 : std::list< String >::iterator j;
81 0 : std::list< String >::iterator k;
82 0 : std::list< String >::const_iterator end;
83 :
84 0 : for ( int i = 0; i < nAnzahlPlugins; i++ )
85 : {
86 0 : String aStrPlugMIMEType( pDescription[i].Mimetype );
87 0 : String aStrPlugName( pDescription[i].Description );
88 0 : String aStrPlugExtension( pDescription[i].Extension );
89 :
90 0 : aStrPlugMIMEType.ToLowerAscii();
91 0 : aStrPlugExtension.ToLowerAscii();
92 :
93 0 : if ( ( nKind == SID_INSERT_SOUND && aStrPlugMIMEType.SearchAscii ( sAudio ) == 0 ) ||
94 0 : ( nKind == SID_INSERT_VIDEO && aStrPlugMIMEType.SearchAscii ( sVideo ) == 0 ) )
95 : {
96 : // extension already in the filterlist of the filedlg ?
97 0 : sal_Bool bAlreadyExist = sal_False;
98 0 : for ( j = aPlugExtensions.begin(), end = aPlugExtensions.end(); j != end && !bAlreadyExist; ++j )
99 : {
100 0 : bAlreadyExist = (j->Search( aStrPlugExtension ) != STRING_NOTFOUND );
101 : }
102 :
103 0 : if ( !bAlreadyExist )
104 : {
105 : // filterdescription already there?
106 : // (then append the new extension to the existing filter)
107 0 : int nfound = -1;
108 0 : for ( j = aPlugNames.begin(),
109 : k = aPlugExtensions.begin(),
110 0 : end = aPlugNames.end();
111 0 : j != end && nfound != 0; )
112 : {
113 0 : if ( ( nfound = j->Search( aStrPlugName ) ) == 0 )
114 : {
115 0 : if ( aStrPlugExtension.Len() > 0 )
116 0 : aStrPlugExtension.Insert( sal_Unicode( ';' ) );
117 0 : aStrPlugExtension.Insert( *k );
118 :
119 : // remove old entry, increment (iterators are invalid thereafter, thus the postincrement)
120 0 : aPlugNames.erase(j++); aPlugExtensions.erase(k++);
121 :
122 : // update end iterator (which may be invalid, too!)
123 0 : end = aPlugNames.end();
124 : }
125 : else
126 : {
127 : // next element
128 0 : ++j; ++k;
129 : }
130 : }
131 :
132 : // build filterdescription
133 0 : aStrPlugName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " (" ) );
134 0 : aStrPlugName.Append( aStrPlugExtension );
135 0 : aStrPlugName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ")" ) );
136 :
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 0 : const sal_Char sAVI[] = "*.avi";
140 0 : const sal_Char sMOV[] = "*.mov";
141 0 : const sal_Char sMPG[] = "*.mpg";
142 0 : const sal_Char sMPE[] = "*.mpe";
143 0 : const sal_Char sMPEG[] = "*.mpeg";
144 :
145 0 : if ( aStrPlugExtension.EqualsIgnoreCaseAscii( sAVI ) )
146 0 : aStrPlugName = SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_AVI );
147 0 : else if ( aStrPlugExtension.EqualsIgnoreCaseAscii( sMOV ) )
148 0 : aStrPlugName = SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_MOV );
149 0 : else if ( aStrPlugExtension.SearchAscii( sMPG ) != STRING_NOTFOUND ||
150 0 : aStrPlugExtension.SearchAscii( sMPE ) != STRING_NOTFOUND ||
151 0 : aStrPlugExtension.SearchAscii( sMPEG ) != STRING_NOTFOUND )
152 0 : aStrPlugName = SVX_RESSTR(STR_INSERT_VIDEO_EXTFILTER_MPEG);
153 :
154 0 : aPlugNames.push_back( aStrPlugName );
155 0 : aPlugExtensions.push_back( aStrPlugExtension );
156 : }
157 : }
158 0 : }
159 :
160 : // add filter to dialog
161 0 : for ( j = aPlugNames.begin(),
162 : k = aPlugExtensions.begin(),
163 0 : end = aPlugNames.end();
164 : j != end; ++j, ++k )
165 : {
166 0 : maFileDlg.AddFilter( *j, *k );
167 : }
168 :
169 : // add the All-Filter
170 0 : String aAllFilter( ResId( STR_EXTFILTER_ALL, DIALOG_MGR() ) );
171 0 : maFileDlg.AddFilter(aAllFilter, rtl::OUString("*.*"));
172 :
173 : // and activate him
174 0 : maFileDlg.SetCurrentFilter( aAllFilter );
175 0 : }
176 :
177 0 : SvxPluginFileDlg::~SvxPluginFileDlg()
178 : {
179 0 : }
180 :
181 0 : void SvxPluginFileDlg::SetContext( sfx2::FileDialogHelper::Context _eNewContext )
182 : {
183 0 : maFileDlg.SetContext( _eNewContext );
184 0 : }
185 :
186 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|