LCOV - code coverage report
Current view: top level - svx/source/dialog - pfiledlg.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 76 0.0 %
Date: 2014-04-11 Functions: 0 5 0.0 %
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 ::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 : OUString 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< OUString > aPlugNames;
      79           0 :     std::list< OUString > aPlugExtensions;
      80           0 :     std::list< OUString >::iterator j;
      81           0 :     std::list< OUString >::iterator k;
      82           0 :     std::list< OUString >::const_iterator end;
      83             : 
      84           0 :     for ( int i = 0; i < nAnzahlPlugins; i++ )
      85             :     {
      86           0 :         OUString aStrPlugMIMEType( pDescription[i].Mimetype );
      87           0 :         OUString aStrPlugName( pDescription[i].Description );
      88           0 :         OUString aStrPlugExtension( pDescription[i].Extension );
      89             : 
      90           0 :         aStrPlugMIMEType = aStrPlugMIMEType.toAsciiLowerCase();
      91           0 :         aStrPlugExtension = aStrPlugExtension.toAsciiLowerCase();
      92             : 
      93           0 :         if ( ( nKind == SID_INSERT_SOUND && aStrPlugMIMEType.startsWith( sAudio ) ) ||
      94           0 :              ( nKind == SID_INSERT_VIDEO && aStrPlugMIMEType.startsWith( sVideo ) ) )
      95             :         {
      96             :             // extension already in the filterlist of the filedlg ?
      97           0 :             bool bAlreadyExist = false;
      98           0 :             for ( j = aPlugExtensions.begin(), end = aPlugExtensions.end(); j != end && !bAlreadyExist; ++j )
      99             :             {
     100           0 :                 bAlreadyExist = (j->indexOf( aStrPlugExtension ) != -1 );
     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->indexOf( aStrPlugName ) ) == 0 )
     114             :                     {
     115           0 :                         if ( !aStrPlugExtension.isEmpty() )
     116           0 :                             aStrPlugExtension += ";";
     117           0 :                         aStrPlugExtension += *k;
     118             : 
     119             :                         // remove old entry, increment (iterators are invalid thereafter, thus the postincrement)
     120           0 :                         aPlugNames.erase(j++);
     121           0 :                         aPlugExtensions.erase(k++);
     122             : 
     123             :                         // update end iterator (which may be invalid, too!)
     124           0 :                         end = aPlugNames.end();
     125             :                     }
     126             :                     else
     127             :                     {
     128             :                         // next element
     129           0 :                         ++j; ++k;
     130             :                     }
     131             :                 }
     132             : 
     133             :                 // build filterdescription
     134           0 :                 aStrPlugName += "  (";
     135           0 :                 aStrPlugName += aStrPlugExtension;
     136           0 :                 aStrPlugName += ")";
     137             : 
     138             :                 // use a own description for the video-formate avi, mov and mpeg
     139             :                 // the descriptions of these MIME-types are not very meaningful
     140           0 :                 const sal_Char sAVI[] = "*.avi";
     141           0 :                 const sal_Char sMOV[] = "*.mov";
     142           0 :                 const sal_Char sMPG[] = "*.mpg";
     143           0 :                 const sal_Char sMPE[] = "*.mpe";
     144           0 :                 const sal_Char sMPEG[] = "*.mpeg";
     145             : 
     146           0 :                 if ( aStrPlugExtension.equalsIgnoreAsciiCase( sAVI ) )
     147           0 :                     aStrPlugName = SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_AVI );
     148           0 :                 else if ( aStrPlugExtension.equalsIgnoreAsciiCase( sMOV ) )
     149           0 :                     aStrPlugName = SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_MOV );
     150           0 :                 else if ( aStrPlugExtension.indexOf( sMPG ) != -1 ||
     151           0 :                           aStrPlugExtension.indexOf( sMPE ) != -1 ||
     152           0 :                           aStrPlugExtension.indexOf( sMPEG ) != -1 )
     153           0 :                     aStrPlugName = SVX_RESSTR(STR_INSERT_VIDEO_EXTFILTER_MPEG);
     154             : 
     155           0 :                 aPlugNames.push_back( aStrPlugName );
     156           0 :                 aPlugExtensions.push_back( aStrPlugExtension );
     157             :             }
     158             :         }
     159           0 :     }
     160             : 
     161             :     // add filter to dialog
     162           0 :     for ( j = aPlugNames.begin(),
     163             :               k = aPlugExtensions.begin(),
     164           0 :               end = aPlugNames.end();
     165             :           j != end; ++j, ++k )
     166             :     {
     167           0 :         maFileDlg.AddFilter( *j, *k );
     168             :     }
     169             : 
     170             :     // add the All-Filter
     171           0 :     OUString aAllFilter( ResId( STR_EXTFILTER_ALL, DIALOG_MGR() ).toString() );
     172           0 :     maFileDlg.AddFilter(aAllFilter, "*.*");
     173             : 
     174             :     // and activate him
     175           0 :     maFileDlg.SetCurrentFilter( aAllFilter );
     176           0 : }
     177             : 
     178           0 : SvxPluginFileDlg::~SvxPluginFileDlg()
     179             : {
     180           0 : }
     181             : 
     182           0 : void SvxPluginFileDlg::SetContext( sfx2::FileDialogHelper::Context _eNewContext )
     183             : {
     184           0 :     maFileDlg.SetContext( _eNewContext );
     185           0 : }
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10