LCOV - code coverage report
Current view: top level - svx/source/dialog - pfiledlg.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 76 1.3 %
Date: 2014-11-03 Functions: 2 7 28.6 %
Legend: Lines: hit not hit

          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 ::com::sun::star;
      35             : 
      36             : sal_Char const sAudio[] = "audio";
      37             : sal_Char const sVideo[] = "video";
      38             : 
      39             : // Filedialog to insert Plugin-Fileformats
      40             : 
      41           0 : ErrCode SvxPluginFileDlg::Execute()
      42             : {
      43           0 :     return maFileDlg.Execute();
      44             : }
      45             : 
      46           0 : OUString SvxPluginFileDlg::GetPath() const
      47             : {
      48           0 :     return maFileDlg.GetPath();
      49             : }
      50             : 
      51           0 : SvxPluginFileDlg::SvxPluginFileDlg (vcl::Window *, sal_uInt16 nKind )
      52           0 :     : maFileDlg(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, SFXWB_INSERT)
      53             : {
      54             :     // set title of the dialogwindow
      55           0 :     switch (nKind)
      56             :     {
      57             :         case SID_INSERT_SOUND :
      58             :         {
      59           0 :             maFileDlg.SetTitle(SVX_RESSTR(STR_INSERT_SOUND_TITLE));
      60             :         }
      61           0 :         break;
      62             :         case SID_INSERT_VIDEO :
      63             :         {
      64           0 :             maFileDlg.SetTitle(SVX_RESSTR(STR_INSERT_VIDEO_TITLE));
      65             :         }
      66           0 :         break;
      67             :     }
      68             : 
      69             :     // fill the filterlist of the filedialog with data of installed plugins
      70           0 :     uno::Reference< uno::XComponentContext >  xContext = comphelper::getProcessComponentContext();
      71           0 :     uno::Reference< plugin::XPluginManager >  rPluginManager( plugin::PluginManager::create(xContext) );
      72             : 
      73           0 :     const uno::Sequence<plugin::PluginDescription > aSeq( rPluginManager->getPluginDescriptions() );
      74           0 :     const plugin::PluginDescription* pDescription = aSeq.getConstArray();
      75           0 :     sal_Int32 nAnzahlPlugins = rPluginManager->getPluginDescriptions().getLength();
      76             : 
      77           0 :     std::list< OUString > aPlugNames;
      78           0 :     std::list< OUString > aPlugExtensions;
      79           0 :     std::list< OUString >::iterator j;
      80           0 :     std::list< OUString >::iterator k;
      81           0 :     std::list< OUString >::const_iterator end;
      82             : 
      83           0 :     for ( int i = 0; i < nAnzahlPlugins; i++ )
      84             :     {
      85           0 :         OUString aStrPlugMIMEType( pDescription[i].Mimetype );
      86           0 :         OUString aStrPlugName( pDescription[i].Description );
      87           0 :         OUString aStrPlugExtension( pDescription[i].Extension );
      88             : 
      89           0 :         aStrPlugMIMEType = aStrPlugMIMEType.toAsciiLowerCase();
      90           0 :         aStrPlugExtension = aStrPlugExtension.toAsciiLowerCase();
      91             : 
      92           0 :         if ( ( nKind == SID_INSERT_SOUND && aStrPlugMIMEType.startsWith( sAudio ) ) ||
      93           0 :              ( nKind == SID_INSERT_VIDEO && aStrPlugMIMEType.startsWith( sVideo ) ) )
      94             :         {
      95             :             // extension already in the filterlist of the filedlg ?
      96           0 :             bool bAlreadyExist = false;
      97           0 :             for ( j = aPlugExtensions.begin(), end = aPlugExtensions.end(); j != end && !bAlreadyExist; ++j )
      98             :             {
      99           0 :                 bAlreadyExist = (j->indexOf( aStrPlugExtension ) != -1 );
     100             :             }
     101             : 
     102           0 :             if ( !bAlreadyExist )
     103             :             {
     104             :                 // filterdescription already there?
     105             :                 // (then append the new extension to the existing filter)
     106           0 :                 int nfound = -1;
     107           0 :                  for ( j = aPlugNames.begin(),
     108             :                           k = aPlugExtensions.begin(),
     109           0 :                           end = aPlugNames.end();
     110           0 :                       j != end && nfound != 0;  )
     111             :                 {
     112           0 :                     if ( ( nfound = j->indexOf( aStrPlugName ) ) == 0 )
     113             :                     {
     114           0 :                         if ( !aStrPlugExtension.isEmpty() )
     115           0 :                             aStrPlugExtension += ";";
     116           0 :                         aStrPlugExtension += *k;
     117             : 
     118             :                         // remove old entry, increment (iterators are invalid thereafter, thus the postincrement)
     119           0 :                         aPlugNames.erase(j++);
     120           0 :                         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 += "  (";
     134           0 :                 aStrPlugName += aStrPlugExtension;
     135           0 :                 aStrPlugName += ")";
     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.equalsIgnoreAsciiCase( sAVI ) )
     146           0 :                     aStrPlugName = SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_AVI );
     147           0 :                 else if ( aStrPlugExtension.equalsIgnoreAsciiCase( sMOV ) )
     148           0 :                     aStrPlugName = SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_MOV );
     149           0 :                 else if ( aStrPlugExtension.indexOf( sMPG ) != -1 ||
     150           0 :                           aStrPlugExtension.indexOf( sMPE ) != -1 ||
     151           0 :                           aStrPlugExtension.indexOf( sMPEG ) != -1 )
     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 :     OUString aAllFilter( ResId( STR_EXTFILTER_ALL, DIALOG_MGR() ).toString() );
     171           0 :     maFileDlg.AddFilter(aAllFilter, "*.*");
     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         594 : }
     185             : 
     186             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10