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

Generated by: LCOV version 1.10