LCOV - code coverage report
Current view: top level - libreoffice/basctl/source/basicide - documentenumeration.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 54 0.0 %
Date: 2012-12-27 Functions: 0 7 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 "documentenumeration.hxx"
      22             : 
      23             : #include <com/sun/star/frame/Desktop.hpp>
      24             : #include <com/sun/star/frame/XModel2.hpp>
      25             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      26             : #include <com/sun/star/lang/XServiceInfo.hpp>
      27             : #include <com/sun/star/frame/XFramesSupplier.hpp>
      28             : #include <com/sun/star/uno/XComponentContext.hpp>
      29             : 
      30             : #include <tools/diagnose_ex.h>
      31             : 
      32             : #include <comphelper/stl_types.hxx>
      33             : 
      34             : //........................................................................
      35             : namespace basctl { namespace docs {
      36             : //........................................................................
      37             : 
      38             :     /** === begin UNO using === **/
      39             :     using ::com::sun::star::uno::Exception;
      40             :     using ::com::sun::star::uno::Reference;
      41             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      42             :     using ::com::sun::star::uno::UNO_SET_THROW;
      43             :     using ::com::sun::star::frame::Desktop;
      44             :     using ::com::sun::star::frame::XDesktop2;
      45             :     using ::com::sun::star::container::XEnumerationAccess;
      46             :     using ::com::sun::star::container::XEnumeration;
      47             :     using ::com::sun::star::uno::Any;
      48             :     using ::com::sun::star::frame::XModel;
      49             :     using ::com::sun::star::frame::XFramesSupplier;
      50             :     using ::com::sun::star::frame::XFrames;
      51             :     using ::com::sun::star::frame::XController;
      52             :     using ::com::sun::star::frame::XModel2;
      53             :     using ::com::sun::star::uno::UNO_QUERY;
      54             :     using ::com::sun::star::lang::XServiceInfo;
      55             :     using ::com::sun::star::uno::Sequence;
      56             :     using ::com::sun::star::frame::XFrame;
      57             :     /** === end UNO using === **/
      58             :     namespace FrameSearchFlag = ::com::sun::star::frame::FrameSearchFlag;
      59             : 
      60             :     //====================================================================
      61             :     //= DocumentEnumeration_Data
      62             :     //====================================================================
      63           0 :     struct DocumentEnumeration_Data
      64             :     {
      65             :         Reference< com::sun::star::uno::XComponentContext > aContext;
      66             :         const IDocumentDescriptorFilter*    pFilter;
      67             : 
      68           0 :         DocumentEnumeration_Data( Reference< com::sun::star::uno::XComponentContext > const & _rContext, const IDocumentDescriptorFilter* _pFilter )
      69             :             :aContext( _rContext )
      70           0 :             ,pFilter( _pFilter )
      71             :         {
      72           0 :         }
      73             :     };
      74             : 
      75             :     //====================================================================
      76             :     //= DocumentEnumeration
      77             :     //====================================================================
      78             :     //--------------------------------------------------------------------
      79           0 :     DocumentEnumeration::DocumentEnumeration( Reference< com::sun::star::uno::XComponentContext > const & _rContext, const IDocumentDescriptorFilter* _pFilter )
      80           0 :         :m_pData( new DocumentEnumeration_Data( _rContext, _pFilter ) )
      81             :     {
      82           0 :     }
      83             : 
      84             :     //--------------------------------------------------------------------
      85           0 :     DocumentEnumeration::~DocumentEnumeration()
      86             :     {
      87           0 :     }
      88             : 
      89             :     //--------------------------------------------------------------------
      90             :     namespace
      91             :     {
      92             :         //................................................................
      93           0 :         void lcl_getDocumentControllers_nothrow( DocumentDescriptor& _io_rDocDesc )
      94             :         {
      95             :             OSL_PRECOND( _io_rDocDesc.xModel.is(), "lcl_getDocumentControllers_nothrow: illegal model!" );
      96             : 
      97           0 :             _io_rDocDesc.aControllers.clear();
      98             :             try
      99             :             {
     100           0 :                 Reference< XModel2 > xModel2( _io_rDocDesc.xModel, UNO_QUERY );
     101           0 :                 if ( xModel2.is() )
     102             :                 {
     103           0 :                     Reference< XEnumeration > xEnum( xModel2->getControllers(), UNO_SET_THROW );
     104           0 :                     while ( xEnum->hasMoreElements() )
     105             :                     {
     106           0 :                         Reference< XController > xController( xEnum->nextElement(), UNO_QUERY_THROW );
     107           0 :                         _io_rDocDesc.aControllers.push_back( xController );
     108           0 :                     }
     109             :                 }
     110           0 :                 else if ( _io_rDocDesc.xModel.is() )
     111           0 :                     _io_rDocDesc.aControllers.push_back( _io_rDocDesc.xModel->getCurrentController() );
     112             :             }
     113           0 :             catch( const Exception& )
     114             :             {
     115             :                 DBG_UNHANDLED_EXCEPTION();
     116             :             }
     117           0 :         }
     118             : 
     119             :         //................................................................
     120           0 :         void lcl_getDocuments_nothrow( const Sequence< Reference< XFrame > >& _rFrames, Documents& _out_rDocuments,
     121             :             const IDocumentDescriptorFilter* _pFilter )
     122             :         {
     123             :             // ensure we don't encounter some models multiple times
     124           0 :             ::std::set< Reference< XModel >, ::comphelper::OInterfaceCompare< XModel > > aEncounteredModels;
     125             : 
     126           0 :             for (   const Reference< XFrame >* pFrame = _rFrames.getConstArray();
     127           0 :                     pFrame != _rFrames.getConstArray() + _rFrames.getLength();
     128             :                     ++pFrame
     129             :                 )
     130             :             {
     131             :                 try
     132             :                 {
     133             :                     OSL_ENSURE( pFrame->is(), "lcl_getDocuments_nothrow: illegal frame!" );
     134           0 :                     if ( !pFrame->is() )
     135           0 :                         continue;
     136           0 :                     Reference< XController > xController( (*pFrame)->getController() );
     137           0 :                     if ( !xController.is() )
     138           0 :                         continue;
     139             : 
     140           0 :                     Reference< XModel > xModel( xController->getModel() );
     141           0 :                     if ( !xModel.is() )
     142             :                         // though it's legal for a controller to not have a model, we're not interested in
     143             :                         // those
     144           0 :                         continue;
     145             : 
     146           0 :                     if ( aEncounteredModels.find( xModel ) != aEncounteredModels.end() )
     147             :                         // there might be multiple frames for the same model
     148             :                         // handle it only once
     149           0 :                         continue;
     150           0 :                     aEncounteredModels.insert( xModel );
     151             : 
     152             :                     // create a DocumentDescriptor
     153           0 :                     DocumentDescriptor aDescriptor;
     154           0 :                     aDescriptor.xModel = xModel;
     155           0 :                     lcl_getDocumentControllers_nothrow( aDescriptor );
     156             : 
     157             :                     // consult filter, if there is one
     158           0 :                     if ( _pFilter && !_pFilter->includeDocument( aDescriptor ) )
     159           0 :                         continue;
     160             : 
     161           0 :                     _out_rDocuments.push_back( aDescriptor );
     162             :                 }
     163           0 :                 catch( const Exception& )
     164             :                 {
     165             :                     DBG_UNHANDLED_EXCEPTION();
     166             :                 }
     167           0 :             }
     168           0 :         }
     169             :     }
     170             : 
     171             :     //--------------------------------------------------------------------
     172           0 :     void DocumentEnumeration::getDocuments( Documents& _out_rDocuments ) const
     173             :     {
     174           0 :         _out_rDocuments.clear();
     175             : 
     176             :         try
     177             :         {
     178           0 :             const Reference< XDesktop2 > xDesktop = Desktop::create( m_pData->aContext );
     179           0 :             const Reference< XFrames > xFrames( xDesktop->getFrames(), UNO_SET_THROW );
     180           0 :             const Sequence< Reference< XFrame > > aFrames( xFrames->queryFrames( FrameSearchFlag::ALL ) );
     181             : 
     182           0 :             lcl_getDocuments_nothrow( aFrames, _out_rDocuments, m_pData->pFilter );
     183             :         }
     184           0 :         catch( const Exception& )
     185             :         {
     186             :             DBG_UNHANDLED_EXCEPTION();
     187             :         }
     188           0 :     }
     189             : 
     190             : //........................................................................
     191             : } } // namespace basctl::docs
     192             : //........................................................................
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10