LCOV - code coverage report
Current view: top level - svx/source/dialog - pfiledlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 75 0.0 %
Date: 2012-08-25 Functions: 0 5 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 217 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <sfx2/docfile.hxx>
      30                 :            : #include <com/sun/star/plugin/PluginDescription.hpp>
      31                 :            : #include <com/sun/star/plugin/PluginManager.hpp>
      32                 :            : #include <com/sun/star/plugin/XPluginManager.hpp>
      33                 :            : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      34                 :            : 
      35                 :            : #include <comphelper/processfactory.hxx>
      36                 :            : 
      37                 :            : #include "svx/pfiledlg.hxx"
      38                 :            : #include <svx/dialogs.hrc>
      39                 :            : 
      40                 :            : #include <svx/dialmgr.hxx>
      41                 :            : #include <list>
      42                 :            : 
      43                 :            : using namespace ::rtl;
      44                 :            : using namespace ::com::sun::star;
      45                 :            : 
      46                 :            : sal_Char const sAudio[] = "audio";
      47                 :            : sal_Char const sVideo[] = "video";
      48                 :            : 
      49                 :            : // Filedialog to insert Plugin-Fileformats
      50                 :            : 
      51                 :          0 : ErrCode SvxPluginFileDlg::Execute()
      52                 :            : {
      53                 :          0 :     return maFileDlg.Execute();
      54                 :            : }
      55                 :            : 
      56                 :          0 : String SvxPluginFileDlg::GetPath() const
      57                 :            : {
      58                 :          0 :     return maFileDlg.GetPath();
      59                 :            : }
      60                 :            : 
      61                 :          0 : SvxPluginFileDlg::SvxPluginFileDlg (Window *, sal_uInt16 nKind )
      62                 :          0 :     : maFileDlg(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, SFXWB_INSERT)
      63                 :            : {
      64                 :            :     // set title of the dialogwindow
      65      [ #  #  # ]:          0 :     switch (nKind)
      66                 :            :     {
      67                 :            :         case SID_INSERT_SOUND :
      68                 :            :         {
      69 [ #  # ][ #  # ]:          0 :             maFileDlg.SetTitle(SVX_RESSTR(STR_INSERT_SOUND_TITLE));
         [ #  # ][ #  # ]
                 [ #  # ]
      70                 :            :         }
      71                 :          0 :         break;
      72                 :            :         case SID_INSERT_VIDEO :
      73                 :            :         {
      74 [ #  # ][ #  # ]:          0 :             maFileDlg.SetTitle(SVX_RESSTR(STR_INSERT_VIDEO_TITLE));
         [ #  # ][ #  # ]
                 [ #  # ]
      75                 :            :         }
      76                 :          0 :         break;
      77                 :            :     }
      78                 :            : 
      79                 :            :     // fill the filterlist of the filedialog with data of installed plugins
      80         [ #  # ]:          0 :     uno::Reference< uno::XComponentContext >  xContext = comphelper::getProcessComponentContext();
      81         [ #  # ]:          0 :     uno::Reference< plugin::XPluginManager >  rPluginManager( plugin::PluginManager::create(xContext) );
      82                 :            : 
      83 [ #  # ][ #  # ]:          0 :     const uno::Sequence<plugin::PluginDescription > aSeq( rPluginManager->getPluginDescriptions() );
      84                 :          0 :     const plugin::PluginDescription* pDescription = aSeq.getConstArray();
      85 [ #  # ][ #  # ]:          0 :     sal_Int32 nAnzahlPlugins = rPluginManager->getPluginDescriptions().getLength();
                 [ #  # ]
      86                 :            : 
      87         [ #  # ]:          0 :     std::list< String > aPlugNames;
      88         [ #  # ]:          0 :     std::list< String > aPlugExtensions;
      89         [ #  # ]:          0 :     std::list< String >::iterator j;
      90         [ #  # ]:          0 :     std::list< String >::iterator k;
      91         [ #  # ]:          0 :     std::list< String >::const_iterator end;
      92                 :            : 
      93         [ #  # ]:          0 :     for ( int i = 0; i < nAnzahlPlugins; i++ )
      94                 :            :     {
      95         [ #  # ]:          0 :         String aStrPlugMIMEType( pDescription[i].Mimetype );
      96         [ #  # ]:          0 :         String aStrPlugName( pDescription[i].Description );
      97         [ #  # ]:          0 :         String aStrPlugExtension( pDescription[i].Extension );
      98                 :            : 
      99         [ #  # ]:          0 :         aStrPlugMIMEType.ToLowerAscii();
     100         [ #  # ]:          0 :         aStrPlugExtension.ToLowerAscii();
     101                 :            : 
     102 [ #  # ][ #  # ]:          0 :         if ( ( nKind == SID_INSERT_SOUND && aStrPlugMIMEType.SearchAscii ( sAudio ) == 0 ) ||
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     103         [ #  # ]:          0 :              ( nKind == SID_INSERT_VIDEO && aStrPlugMIMEType.SearchAscii ( sVideo ) == 0 ) )
     104                 :            :         {
     105                 :            :             // extension already in the filterlist of the filedlg ?
     106                 :          0 :             sal_Bool bAlreadyExist = sal_False;
     107 [ #  # ][ #  # ]:          0 :             for ( j = aPlugExtensions.begin(), end = aPlugExtensions.end(); j != end && !bAlreadyExist; ++j )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     108                 :            :             {
     109 [ #  # ][ #  # ]:          0 :                 bAlreadyExist = (j->Search( aStrPlugExtension ) != STRING_NOTFOUND );
     110                 :            :             }
     111                 :            : 
     112         [ #  # ]:          0 :             if ( !bAlreadyExist )
     113                 :            :             {
     114                 :            :                 // filterdescription already there?
     115                 :            :                 // (then append the new extension to the existing filter)
     116                 :          0 :                 int nfound = -1;
     117 [ #  # ][ #  # ]:          0 :                  for ( j = aPlugNames.begin(),
                 [ #  # ]
     118                 :            :                           k = aPlugExtensions.begin(),
     119         [ #  # ]:          0 :                           end = aPlugNames.end();
     120         [ #  # ]:          0 :                       j != end && nfound != 0;  )
     121                 :            :                 {
     122 [ #  # ][ #  # ]:          0 :                     if ( ( nfound = j->Search( aStrPlugName ) ) == 0 )
                 [ #  # ]
     123                 :            :                     {
     124         [ #  # ]:          0 :                         if ( aStrPlugExtension.Len() > 0 )
     125         [ #  # ]:          0 :                             aStrPlugExtension.Insert( sal_Unicode( ';' ) );
     126 [ #  # ][ #  # ]:          0 :                         aStrPlugExtension.Insert( *k );
     127                 :            : 
     128                 :            :                         // remove old entry, increment (iterators are invalid thereafter, thus the postincrement)
     129 [ #  # ][ #  # ]:          0 :                         aPlugNames.erase(j++); aPlugExtensions.erase(k++);
         [ #  # ][ #  # ]
     130                 :            : 
     131                 :            :                         // update end iterator (which may be invalid, too!)
     132         [ #  # ]:          0 :                         end = aPlugNames.end();
     133                 :            :                     }
     134                 :            :                     else
     135                 :            :                     {
     136                 :            :                         // next element
     137 [ #  # ][ #  # ]:          0 :                         ++j; ++k;
     138                 :            :                     }
     139                 :            :                 }
     140                 :            : 
     141                 :            :                 // build filterdescription
     142         [ #  # ]:          0 :                 aStrPlugName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "  (" ) );
     143         [ #  # ]:          0 :                 aStrPlugName.Append( aStrPlugExtension );
     144         [ #  # ]:          0 :                 aStrPlugName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ")" ) );
     145                 :            : 
     146                 :            :                 // use a own description for the video-formate avi, mov and mpeg
     147                 :            :                 // the descriptions of these MIME-types are not very meaningful
     148                 :          0 :                 const sal_Char sAVI[] = "*.avi";
     149                 :          0 :                 const sal_Char sMOV[] = "*.mov";
     150                 :          0 :                 const sal_Char sMPG[] = "*.mpg";
     151                 :          0 :                 const sal_Char sMPE[] = "*.mpe";
     152                 :          0 :                 const sal_Char sMPEG[] = "*.mpeg";
     153                 :            : 
     154 [ #  # ][ #  # ]:          0 :                 if ( aStrPlugExtension.EqualsIgnoreCaseAscii( sAVI ) )
     155 [ #  # ][ #  # ]:          0 :                     aStrPlugName = SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_AVI );
                 [ #  # ]
     156 [ #  # ][ #  # ]:          0 :                 else if ( aStrPlugExtension.EqualsIgnoreCaseAscii( sMOV ) )
     157 [ #  # ][ #  # ]:          0 :                     aStrPlugName = SVX_RESSTR( STR_INSERT_VIDEO_EXTFILTER_MOV );
                 [ #  # ]
     158 [ #  # ][ #  # ]:          0 :                 else if ( aStrPlugExtension.SearchAscii( sMPG ) != STRING_NOTFOUND ||
         [ #  # ][ #  # ]
                 [ #  # ]
     159         [ #  # ]:          0 :                           aStrPlugExtension.SearchAscii( sMPE ) != STRING_NOTFOUND ||
     160         [ #  # ]:          0 :                           aStrPlugExtension.SearchAscii( sMPEG ) != STRING_NOTFOUND )
     161 [ #  # ][ #  # ]:          0 :                     aStrPlugName = SVX_RESSTR(STR_INSERT_VIDEO_EXTFILTER_MPEG);
                 [ #  # ]
     162                 :            : 
     163         [ #  # ]:          0 :                 aPlugNames.push_back( aStrPlugName );
     164         [ #  # ]:          0 :                 aPlugExtensions.push_back( aStrPlugExtension );
     165                 :            :             }
     166                 :            :         }
     167 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
     168                 :            : 
     169                 :            :     // add filter to dialog
     170 [ #  # ][ #  # ]:          0 :     for ( j = aPlugNames.begin(),
         [ #  # ][ #  # ]
     171                 :            :               k = aPlugExtensions.begin(),
     172         [ #  # ]:          0 :               end = aPlugNames.end();
     173                 :            :           j != end; ++j, ++k )
     174                 :            :     {
     175 [ #  # ][ #  # ]:          0 :         maFileDlg.AddFilter( *j, *k );
                 [ #  # ]
     176                 :            :     }
     177                 :            : 
     178                 :            :     // add the All-Filter
     179 [ #  # ][ #  # ]:          0 :     String aAllFilter( ResId( STR_EXTFILTER_ALL, DIALOG_MGR() ) );
     180 [ #  # ][ #  # ]:          0 :     maFileDlg.AddFilter(aAllFilter, rtl::OUString("*.*"));
                 [ #  # ]
     181                 :            : 
     182                 :            :     // and activate him
     183 [ #  # ][ #  # ]:          0 :     maFileDlg.SetCurrentFilter( aAllFilter );
                 [ #  # ]
     184                 :          0 : }
     185                 :            : 
     186                 :          0 : SvxPluginFileDlg::~SvxPluginFileDlg()
     187                 :            : {
     188                 :          0 : }
     189                 :            : 
     190                 :          0 : void SvxPluginFileDlg::SetContext( sfx2::FileDialogHelper::Context _eNewContext )
     191                 :            : {
     192                 :          0 :     maFileDlg.SetContext( _eNewContext );
     193                 :          0 : }
     194                 :            : 
     195                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10