LCOV - code coverage report
Current view: top level - libreoffice/sdext/source/minimizer - fileopendialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 83 0.0 %
Date: 2012-12-27 Functions: 0 6 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             : 
      21             : #include "fileopendialog.hxx"
      22             : #include <sal/types.h>
      23             : #include "pppoptimizertoken.hxx"
      24             : #include <com/sun/star/lang/XInitialization.hpp>
      25             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      26             : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
      27             : #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
      28             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      29             : #include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
      30             : #include <com/sun/star/ui/dialogs/ControlActions.hpp>
      31             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      32             : #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
      33             : #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
      34             : #include <com/sun/star/ui/dialogs/XFilePreview.hpp>
      35             : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
      36             : #include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
      37             : #include <com/sun/star/lang/XServiceInfo.hpp>
      38             : #include <com/sun/star/beans/XPropertySet.hpp>
      39             : #include <com/sun/star/beans/PropertyValue.hpp>
      40             : #include <com/sun/star/beans/NamedValue.hpp>
      41             : #include <com/sun/star/embed/ElementModes.hpp>
      42             : #include <com/sun/star/container/XEnumeration.hpp>
      43             : #include <com/sun/star/container/XNameAccess.hpp>
      44             : #include <com/sun/star/container/XContainerQuery.hpp>
      45             : #include <com/sun/star/view/XControlAccess.hpp>
      46             : #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
      47             : 
      48             : 
      49             : using namespace ::rtl;
      50             : using namespace ::com::sun::star::uno;
      51             : using namespace ::com::sun::star::lang;
      52             : using namespace ::com::sun::star::beans;
      53             : using namespace ::com::sun::star::container;
      54             : using namespace ::com::sun::star::view;
      55             : using namespace ::com::sun::star::ui::dialogs;
      56             : 
      57           0 : FileOpenDialog::FileOpenDialog( const Reference< XComponentContext >& rxMSF ) :
      58           0 :     mxMSF( rxMSF )
      59             : {
      60           0 :     Sequence< Any > aInitPropSeq( 1 );
      61           0 :     aInitPropSeq[ 0 ] <<= (sal_Int16)TemplateDescription::FILESAVE_AUTOEXTENSION;   // TemplateDescription.FILEOPEN_SIMPLE
      62             : 
      63           0 :     mxFilePicker = Reference < XFilePicker >( mxMSF->getServiceManager()->createInstanceWithArgumentsAndContext(
      64           0 :         OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aInitPropSeq, rxMSF ),UNO_QUERY_THROW );
      65           0 :     mxFilePicker->setMultiSelectionMode( sal_False );
      66             : 
      67           0 :     Reference< XFilePickerControlAccess > xAccess( mxFilePicker, UNO_QUERY );
      68           0 :     if ( xAccess.is() )
      69             :     {
      70           0 :         Any aValue( static_cast< sal_Bool >( sal_True ) );
      71             :         try
      72             :         {
      73           0 :             xAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue );
      74             :         }
      75           0 :         catch( com::sun::star::uno::Exception& )
      76           0 :         {}
      77             :     }
      78             : 
      79             :     // collecting a list of impress filters
      80           0 :     Reference< XNameAccess > xFilters( mxMSF->getServiceManager()->createInstanceWithContext(
      81           0 :         OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" ) ), rxMSF ), UNO_QUERY_THROW );
      82           0 :     Sequence< OUString > aFilterList( xFilters->getElementNames() );
      83           0 :     for ( int i = 0; i < aFilterList.getLength(); i++ )
      84             :     {
      85             :         try
      86             :         {
      87           0 :             Sequence< PropertyValue > aFilterProperties;
      88           0 :             if ( xFilters->getByName( aFilterList[ i ] ) >>= aFilterProperties )
      89             :             {
      90           0 :                 FilterEntry aFilterEntry;
      91           0 :                 sal_Bool bImpressFilter = sal_False;
      92           0 :                 for ( int j = 0; j < aFilterProperties.getLength(); j++ )
      93             :                 {
      94           0 :                     PropertyValue& rProperty( aFilterProperties[ j ] );
      95           0 :                     switch( TKGet( rProperty.Name ) )
      96             :                     {
      97             :                         case TK_DocumentService :
      98             :                         {
      99           0 :                             rtl::OUString sDocumentService;
     100           0 :                             rProperty.Value >>= sDocumentService;
     101           0 :                             if ( sDocumentService == "com.sun.star.presentation.PresentationDocument" )
     102           0 :                                 bImpressFilter = sal_True;
     103             :                             else
     104           0 :                                 j = aFilterProperties.getLength();
     105             :                         }
     106           0 :                         break;
     107           0 :                         case TK_Name :      rProperty.Value >>= aFilterEntry.maName; break;
     108           0 :                         case TK_UIName :    rProperty.Value >>= aFilterEntry.maUIName; break;
     109           0 :                         case TK_Type :      rProperty.Value >>= aFilterEntry.maType; break;
     110           0 :                         case TK_Flags :     rProperty.Value >>= aFilterEntry.maFlags; break;
     111           0 :                         default : break;
     112             :                     }
     113             :                 }
     114           0 :                 if ( bImpressFilter && ( ( aFilterEntry.maFlags & 3 ) == 3 ) )
     115             :                 {
     116           0 :                     aFilterEntryList.push_back( aFilterEntry );
     117           0 :                 }
     118           0 :             }
     119             :         }
     120           0 :         catch( Exception& )
     121             :         {
     122             :         }
     123             :     }
     124             : 
     125           0 :     Reference< XNameAccess > xTypes( mxMSF->getServiceManager()->createInstanceWithContext(
     126           0 :         OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.TypeDetection" ) ), rxMSF ), UNO_QUERY_THROW );
     127           0 :     Sequence< OUString > aTypeList( xFilters->getElementNames() );
     128             : 
     129             : //  mxFilePicker->setDefaultName( );
     130             : 
     131           0 :     Reference< XFilterManager > xFilterManager( mxFilePicker, UNO_QUERY_THROW );
     132           0 :     std::vector< FilterEntry >::iterator aIter( aFilterEntryList.begin() );
     133           0 :     while( aIter != aFilterEntryList.end() )
     134             :     {
     135           0 :         Sequence< PropertyValue > aTypeProperties;
     136             :         try
     137             :         {
     138           0 :             if ( xTypes->getByName( aIter->maType ) >>= aTypeProperties )
     139             :             {
     140           0 :                 Sequence< OUString > aExtensions;
     141           0 :                 for ( int i = 0; i < aTypeProperties.getLength(); i++ )
     142             :                 {
     143           0 :                     switch( TKGet( aTypeProperties[ i ].Name ) )
     144             :                     {
     145           0 :                         case TK_Extensions : aTypeProperties[ i ].Value >>= aExtensions; break;
     146           0 :                         default: break;
     147             :                     }
     148             :                 }
     149           0 :                 if ( aExtensions.getLength() )
     150             :                 {
     151           0 :                     xFilterManager->appendFilter( aIter->maUIName, aExtensions[ 0 ] );
     152           0 :                     if ( aIter->maFlags & 0x100 )
     153           0 :                         xFilterManager->setCurrentFilter( aIter->maUIName );
     154           0 :                 }
     155             :             }
     156             :         }
     157           0 :         catch ( Exception& )
     158             :         {
     159             :         }
     160           0 :         aIter++;
     161           0 :     }
     162           0 : }
     163           0 : FileOpenDialog::~FileOpenDialog()
     164             : {
     165           0 : }
     166           0 : sal_Int16 FileOpenDialog::execute()
     167             : {
     168           0 :     return mxFilePicker->execute();
     169             : }
     170           0 : void FileOpenDialog::setDefaultName( const rtl::OUString& rDefaultName )
     171             : {
     172           0 :     mxFilePicker->setDefaultName( rDefaultName );
     173           0 : }
     174           0 : ::rtl::OUString FileOpenDialog::getURL() const
     175             : {
     176           0 :     Sequence< OUString > aFileSeq( mxFilePicker->getFiles() );
     177           0 :     return aFileSeq.getLength() ? aFileSeq[ 0 ] : OUString();
     178             : };
     179           0 : ::rtl::OUString FileOpenDialog::getFilterName() const
     180             : {
     181           0 :     rtl::OUString aFilterName;
     182           0 :     Reference< XFilterManager > xFilterManager( mxFilePicker, UNO_QUERY_THROW );
     183           0 :     rtl::OUString aUIName( xFilterManager->getCurrentFilter() );
     184           0 :     std::vector< FilterEntry >::const_iterator aIter( aFilterEntryList.begin() );
     185           0 :     while( aIter != aFilterEntryList.end() )
     186             :     {
     187           0 :         if ( aIter->maUIName == aUIName )
     188             :         {
     189           0 :             aFilterName = aIter->maName;
     190           0 :             break;
     191             :         }
     192           0 :         aIter++;
     193             :     }
     194           0 :     return aFilterName;
     195             : };
     196             : 
     197             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10