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

Generated by: LCOV version 1.11