LCOV - code coverage report
Current view: top level - uui/source - iahndl-filter.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 118 0.8 %
Date: 2015-06-13 12:38:46 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 <com/sun/star/beans/XPropertyAccess.hpp>
      21             : #include <com/sun/star/container/XContainerQuery.hpp>
      22             : #include <com/sun/star/container/XNameContainer.hpp>
      23             : #include <com/sun/star/document/FilterOptionsRequest.hpp>
      24             : #include <com/sun/star/document/NoSuchFilterRequest.hpp>
      25             : #include <com/sun/star/document/XImporter.hpp>
      26             : #include <com/sun/star/document/XInteractionFilterOptions.hpp>
      27             : #include <com/sun/star/document/XInteractionFilterSelect.hpp>
      28             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      29             : #include <com/sun/star/task/XInteractionAbort.hpp>
      30             : #include <com/sun/star/task/XInteractionRequest.hpp>
      31             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      32             : 
      33             : #include <osl/mutex.hxx>
      34             : #include <comphelper/sequenceashashmap.hxx>
      35             : #include <vcl/svapp.hxx>
      36             : 
      37             : #include "getcontinuations.hxx"
      38             : #include "fltdlg.hxx"
      39             : 
      40             : #include "iahndl.hxx"
      41             : #include <boost/scoped_ptr.hpp>
      42             : 
      43             : using namespace com::sun::star;
      44             : 
      45             : namespace {
      46             : 
      47             : void
      48           0 : executeFilterDialog(
      49             :     vcl::Window          * pParent ,
      50             :     OUString       const & rURL    ,
      51             :     uui::FilterNameList const & rFilters,
      52             :     OUString             & rFilter )
      53             : {
      54             :     try
      55             :     {
      56           0 :         SolarMutexGuard aGuard;
      57             : 
      58           0 :         ScopedVclPtrInstance< uui::FilterDialog > xDialog(pParent);
      59             : 
      60           0 :         xDialog->SetURL(rURL);
      61           0 :         xDialog->ChangeFilters(&rFilters);
      62             : 
      63           0 :         uui::FilterNameListPtr pSelected = rFilters.end();
      64           0 :         if( xDialog->AskForFilter( pSelected ) )
      65             :         {
      66           0 :             rFilter = pSelected->sInternal;
      67           0 :         }
      68             :     }
      69           0 :     catch (std::bad_alloc const &)
      70             :     {
      71           0 :         throw uno::RuntimeException("out of memory");
      72             :     }
      73           0 : }
      74             : 
      75             : void
      76           0 : handleNoSuchFilterRequest_(
      77             :     vcl::Window * pParent,
      78             :     uno::Reference< uno::XComponentContext > const & xContext,
      79             :     document::NoSuchFilterRequest const & rRequest,
      80             :     uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
      81             :             rContinuations )
      82             : {
      83           0 :     uno::Reference< task::XInteractionAbort > xAbort;
      84           0 :     uno::Reference< document::XInteractionFilterSelect > xFilterTransport;
      85           0 :     getContinuations(rContinuations, &xAbort, &xFilterTransport);
      86             : 
      87             :     // check necessary resources - if they don't exist - abort or
      88             :     // break this operation
      89           0 :     if (!xAbort.is())
      90           0 :         return;
      91             : 
      92           0 :     if (!xFilterTransport.is())
      93             :     {
      94           0 :         xAbort->select();
      95           0 :         return;
      96             :     }
      97             : 
      98           0 :     uno::Reference< container::XContainerQuery > xFilterContainer;
      99             :     try
     100             :     {
     101           0 :         xFilterContainer.set( xContext->getServiceManager()->createInstanceWithContext(
     102           0 :                                   OUString( "com.sun.star.document.FilterFactory"), xContext ),
     103           0 :                               uno::UNO_QUERY );
     104             :     }
     105           0 :     catch ( uno::Exception const & )
     106             :     {
     107             :     }
     108             : 
     109           0 :     if (!xFilterContainer.is())
     110             :     {
     111           0 :         xAbort->select();
     112           0 :         return;
     113             :     }
     114             : 
     115           0 :     uui::FilterNameList lNames;
     116             : 
     117             :     // Note: We look for all filters here which match the following criteria:
     118             :     //          - they are import filters as minimum (of course they can
     119             :     //            support export too)
     120             :     //          - we don't show any filter which are flagged as "don't show it
     121             :     //            at the UI" or "they are not installed"
     122             :     //          - we ignore filters, which have not set any valid
     123             :     //            DocumentService (e.g. our pure graphic filters)
     124             :     //          - we show it sorted by her UIName's
     125             :     //          - We don't use the order flag or prefer default filters.
     126             :     //            (Because this list shows all filters and the user should
     127             :     //            find his filter very easy by his UIName ...)
     128             :     //          - We use "_query_all" here ... but we filter graphic filters
     129             :     //            out by using DocumentService property later!
     130             :     uno::Reference< container::XEnumeration > xFilters
     131           0 :         = xFilterContainer->createSubSetEnumerationByQuery(
     132           0 :             OUString( "_query_all:sort_prop=uiname:iflags=1:eflags=143360"));
     133           0 :     while (xFilters->hasMoreElements())
     134             :     {
     135             :         try
     136             :         {
     137           0 :             ::comphelper::SequenceAsHashMap lProps(xFilters->nextElement());
     138           0 :             uui::FilterNamePair             aPair;
     139             : 
     140           0 :             aPair.sInternal = lProps.getUnpackedValueOrDefault(
     141           0 :                 OUString("Name"), OUString());
     142           0 :             aPair.sUI       = lProps.getUnpackedValueOrDefault(
     143           0 :                  OUString("UIName"), OUString());
     144           0 :             if ( aPair.sInternal.isEmpty() || aPair.sUI.isEmpty() )
     145             :             {
     146           0 :                continue;
     147             :             }
     148           0 :             lNames.push_back( aPair );
     149             :         }
     150           0 :         catch(const uno::RuntimeException&)
     151             :         {
     152           0 :             throw;
     153             :         }
     154           0 :         catch(const uno::Exception&)
     155             :         {
     156           0 :             continue;
     157             :         }
     158             :     }
     159             : 
     160             :     // no list available for showing
     161             :     // -> abort operation
     162           0 :     if (lNames.size()<1)
     163             :     {
     164           0 :         xAbort->select();
     165           0 :         return;
     166             :     }
     167             : 
     168             :     // let the user select the right filter
     169           0 :     OUString sSelectedFilter;
     170             :     executeFilterDialog( pParent,
     171             :                          rRequest.URL,
     172             :                          lNames,
     173           0 :                          sSelectedFilter );
     174             : 
     175             :     // If he doesn't select anyone
     176             :     // -> abort operation
     177           0 :     if (sSelectedFilter.isEmpty())
     178             :     {
     179           0 :         xAbort->select();
     180           0 :         return;
     181             :     }
     182             : 
     183             :     // otherwise set it for return
     184           0 :     xFilterTransport->setFilter( sSelectedFilter );
     185           0 :     xFilterTransport->select();
     186             : }
     187             : 
     188             : void
     189           0 : handleFilterOptionsRequest_(
     190             :     uno::Reference< uno::XComponentContext > const & xContext,
     191             :     document::FilterOptionsRequest const & rRequest,
     192             :     uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
     193             :         rContinuations)
     194             : {
     195           0 :     uno::Reference< task::XInteractionAbort > xAbort;
     196           0 :     uno::Reference< document::XInteractionFilterOptions > xFilterOptions;
     197           0 :     getContinuations(rContinuations, &xAbort, &xFilterOptions);
     198             : 
     199           0 :     uno::Reference< container::XNameAccess > xFilterCFG;
     200             :     try
     201             :     {
     202           0 :         xFilterCFG.set( xContext->getServiceManager()->createInstanceWithContext(
     203           0 :                             OUString( "com.sun.star.document.FilterFactory" ), xContext ),
     204           0 :                         uno::UNO_QUERY );
     205             :     }
     206           0 :     catch ( uno::Exception const & )
     207             :     {
     208             :     }
     209             : 
     210           0 :     if( xFilterCFG.is() && rRequest.rProperties.getLength() )
     211             :     {
     212             :         try
     213             :         {
     214           0 :             OUString aFilterName;
     215           0 :             sal_Int32 nPropCount = rRequest.rProperties.getLength();
     216           0 :             for( sal_Int32 ind = 0; ind < nPropCount; ++ind )
     217             :             {
     218           0 :                 if( rRequest.rProperties[ind].Name == "FilterName" )
     219             :                 {
     220           0 :                     rRequest.rProperties[ind].Value >>= aFilterName;
     221           0 :                     break;
     222             :                 }
     223             :             }
     224             : 
     225           0 :             uno::Sequence < beans::PropertyValue > aProps;
     226           0 :             if ( xFilterCFG->getByName( aFilterName ) >>= aProps )
     227             :             {
     228           0 :                 sal_Int32 nPropertyCount = aProps.getLength();
     229           0 :                 for( sal_Int32 nProperty=0;
     230             :                      nProperty < nPropertyCount;
     231             :                      ++nProperty )
     232           0 :                     if( aProps[nProperty].Name == "UIComponent" )
     233             :                     {
     234           0 :                         OUString aServiceName;
     235           0 :                         aProps[nProperty].Value >>= aServiceName;
     236           0 :                         if( !aServiceName.isEmpty() )
     237             :                         {
     238             :                             uno::Reference<
     239             :                                 ui::dialogs::XExecutableDialog > xFilterDialog(
     240           0 :                                     xContext->getServiceManager()->createInstanceWithContext(
     241           0 :                                         aServiceName, xContext ),
     242           0 :                                     uno::UNO_QUERY );
     243             :                             uno::Reference< beans::XPropertyAccess >
     244             :                                 xFilterProperties( xFilterDialog,
     245           0 :                                                    uno::UNO_QUERY );
     246             : 
     247           0 :                             if( xFilterDialog.is() && xFilterProperties.is() )
     248             :                             {
     249             :                                 uno::Reference<
     250             :                                     document::XImporter > xImporter(
     251           0 :                                         xFilterDialog, uno::UNO_QUERY );
     252           0 :                                 if( xImporter.is() )
     253           0 :                                     xImporter->setTargetDocument(
     254             :                                         uno::Reference< lang::XComponent >(
     255           0 :                                             rRequest.rModel, uno::UNO_QUERY ) );
     256             : 
     257           0 :                                 xFilterProperties->setPropertyValues(
     258           0 :                                     rRequest.rProperties );
     259             : 
     260           0 :                                 if( xFilterDialog->execute() )
     261             :                                 {
     262           0 :                                     xFilterOptions->setFilterOptions(
     263           0 :                                         xFilterProperties->getPropertyValues() );
     264           0 :                                     xFilterOptions->select();
     265           0 :                                     return;
     266           0 :                                 }
     267           0 :                             }
     268             :                         }
     269           0 :                         break;
     270             :                     }
     271           0 :             }
     272             :         }
     273           0 :         catch( container::NoSuchElementException& )
     274             :         {
     275             :             // the filter name is unknown
     276             :         }
     277           0 :         catch( uno::Exception& )
     278             :         {
     279             :         }
     280             :     }
     281             : 
     282           0 :     xAbort->select();
     283             : }
     284             : 
     285             : } // namespace
     286             : 
     287             : bool
     288           0 : UUIInteractionHelper::handleNoSuchFilterRequest(
     289             :     uno::Reference< task::XInteractionRequest > const & rRequest)
     290             : {
     291           0 :     uno::Any aAnyRequest(rRequest->getRequest());
     292             : 
     293           0 :     document::NoSuchFilterRequest aNoSuchFilterRequest;
     294           0 :     if (aAnyRequest >>= aNoSuchFilterRequest)
     295             :     {
     296             :         handleNoSuchFilterRequest_(getParentProperty(),
     297             :                                    m_xContext,
     298             :                                    aNoSuchFilterRequest,
     299           0 :                                    rRequest->getContinuations());
     300           0 :         return true;
     301             :     }
     302           0 :     return false;
     303             : }
     304             : 
     305             : bool
     306           0 : UUIInteractionHelper::handleFilterOptionsRequest(
     307             :     uno::Reference< task::XInteractionRequest > const & rRequest)
     308             : {
     309           0 :     uno::Any aAnyRequest(rRequest->getRequest());
     310             : 
     311           0 :     document::FilterOptionsRequest aFilterOptionsRequest;
     312           0 :     if (aAnyRequest >>= aFilterOptionsRequest)
     313             :     {
     314             :         handleFilterOptionsRequest_(m_xContext,
     315             :                                     aFilterOptionsRequest,
     316           0 :                                     rRequest->getContinuations());
     317           0 :         return true;
     318             :     }
     319           0 :     return false;
     320         159 : }
     321             : 
     322             : 
     323             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11