LCOV - code coverage report
Current view: top level - sc/source/ui/miscdlgs - solverutil.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 77 0.0 %
Date: 2014-04-14 Functions: 0 3 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             : #include "solverutil.hxx"
      21             : 
      22             : #include <com/sun/star/container/XContentEnumerationAccess.hpp>
      23             : #include <com/sun/star/lang/XServiceInfo.hpp>
      24             : #include <com/sun/star/lang/XSingleComponentFactory.hpp>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : #include <com/sun/star/beans/PropertyValue.hpp>
      27             : #include <com/sun/star/sheet/XSolver.hpp>
      28             : #include <com/sun/star/sheet/XSolverDescription.hpp>
      29             : 
      30             : #include <comphelper/processfactory.hxx>
      31             : 
      32             : using namespace com::sun::star;
      33             : 
      34             : #define SCSOLVER_SERVICE "com.sun.star.sheet.Solver"
      35             : 
      36           0 : void ScSolverUtil::GetImplementations( uno::Sequence<OUString>& rImplNames,
      37             :                                        uno::Sequence<OUString>& rDescriptions )
      38             : {
      39           0 :     rImplNames.realloc(0);      // clear
      40           0 :     rDescriptions.realloc(0);
      41             : 
      42             :     uno::Reference<uno::XComponentContext> xCtx(
      43           0 :         comphelper::getProcessComponentContext() );
      44             : 
      45             :     uno::Reference<container::XContentEnumerationAccess> xEnAc(
      46           0 :             xCtx->getServiceManager(), uno::UNO_QUERY );
      47           0 :     if ( xEnAc.is() )
      48             :     {
      49             :         uno::Reference<container::XEnumeration> xEnum =
      50           0 :                         xEnAc->createContentEnumeration( OUString(SCSOLVER_SERVICE) );
      51           0 :         if ( xEnum.is() )
      52             :         {
      53           0 :             sal_Int32 nCount = 0;
      54           0 :             while ( xEnum->hasMoreElements() )
      55             :             {
      56           0 :                 uno::Any aAny = xEnum->nextElement();
      57           0 :                 uno::Reference<lang::XServiceInfo> xInfo;
      58           0 :                 aAny >>= xInfo;
      59           0 :                 if ( xInfo.is() )
      60             :                 {
      61           0 :                     uno::Reference<lang::XSingleComponentFactory> xCFac( xInfo, uno::UNO_QUERY );
      62           0 :                     if ( xCFac.is() )
      63             :                     {
      64           0 :                         OUString sName = xInfo->getImplementationName();
      65           0 :                         OUString sDescription;
      66             : 
      67             :                         uno::Reference<sheet::XSolver> xSolver(
      68           0 :                                 xCFac->createInstanceWithContext(xCtx), uno::UNO_QUERY );
      69           0 :                         uno::Reference<sheet::XSolverDescription> xDesc( xSolver, uno::UNO_QUERY );
      70           0 :                         if ( xDesc.is() )
      71           0 :                             sDescription = xDesc->getComponentDescription();
      72             : 
      73           0 :                         if ( sDescription.isEmpty() )
      74           0 :                             sDescription = sName;          // use implementation name if no description available
      75             : 
      76           0 :                         rImplNames.realloc( nCount+1 );
      77           0 :                         rImplNames[nCount] = sName;
      78           0 :                         rDescriptions.realloc( nCount+1 );
      79           0 :                         rDescriptions[nCount] = sDescription;
      80           0 :                         ++nCount;
      81           0 :                     }
      82             :                 }
      83           0 :             }
      84           0 :         }
      85           0 :     }
      86           0 : }
      87             : 
      88           0 : uno::Reference<sheet::XSolver> ScSolverUtil::GetSolver( const OUString& rImplName )
      89             : {
      90           0 :     uno::Reference<sheet::XSolver> xSolver;
      91             : 
      92             :     uno::Reference<uno::XComponentContext> xCtx(
      93           0 :         comphelper::getProcessComponentContext() );
      94             : 
      95             :     uno::Reference<container::XContentEnumerationAccess> xEnAc(
      96           0 :             xCtx->getServiceManager(), uno::UNO_QUERY );
      97           0 :     if ( xEnAc.is() )
      98             :     {
      99             :         uno::Reference<container::XEnumeration> xEnum =
     100           0 :                         xEnAc->createContentEnumeration( OUString(SCSOLVER_SERVICE) );
     101           0 :         if ( xEnum.is() )
     102             :         {
     103           0 :             while ( xEnum->hasMoreElements() && !xSolver.is() )
     104             :             {
     105           0 :                 uno::Any aAny = xEnum->nextElement();
     106           0 :                 uno::Reference<lang::XServiceInfo> xInfo;
     107           0 :                 aAny >>= xInfo;
     108           0 :                 if ( xInfo.is() )
     109             :                 {
     110           0 :                     uno::Reference<lang::XSingleComponentFactory> xCFac( xInfo, uno::UNO_QUERY );
     111           0 :                     if ( xCFac.is() )
     112             :                     {
     113           0 :                         OUString sName = xInfo->getImplementationName();
     114           0 :                         if ( sName == rImplName )
     115           0 :                             xSolver.set( xCFac->createInstanceWithContext(xCtx), uno::UNO_QUERY );
     116           0 :                     }
     117             :                 }
     118           0 :             }
     119           0 :         }
     120             :     }
     121             : 
     122             :     SAL_WARN_IF( !xSolver.is(), "sc.ui", "can't get solver" );
     123           0 :     return xSolver;
     124             : }
     125             : 
     126           0 : uno::Sequence<beans::PropertyValue> ScSolverUtil::GetDefaults( const OUString& rImplName )
     127             : {
     128           0 :     uno::Sequence<beans::PropertyValue> aDefaults;
     129             : 
     130           0 :     uno::Reference<sheet::XSolver> xSolver = GetSolver( rImplName );
     131           0 :     uno::Reference<beans::XPropertySet> xPropSet( xSolver, uno::UNO_QUERY );
     132           0 :     if ( !xPropSet.is() )
     133             :     {
     134             :         // no XPropertySet - no options
     135           0 :         return aDefaults;
     136             :     }
     137             : 
     138             :     // fill maProperties
     139             : 
     140           0 :     uno::Reference<beans::XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
     141             :     OSL_ENSURE( xInfo.is(), "can't get property set info" );
     142           0 :     if ( !xInfo.is() )
     143           0 :         return aDefaults;
     144             : 
     145           0 :     uno::Sequence<beans::Property> aPropSeq = xInfo->getProperties();
     146           0 :     const sal_Int32 nSize = aPropSeq.getLength();
     147           0 :     aDefaults.realloc(nSize);
     148           0 :     sal_Int32 nValid = 0;
     149           0 :     for (sal_Int32 nPos=0; nPos<nSize; ++nPos)
     150             :     {
     151           0 :         const beans::Property& rProp = aPropSeq[nPos];
     152           0 :         uno::Any aValue = xPropSet->getPropertyValue( rProp.Name );
     153           0 :         uno::TypeClass eClass = aValue.getValueTypeClass();
     154             :         // only use properties of supported types
     155           0 :         if ( eClass == uno::TypeClass_BOOLEAN || eClass == uno::TypeClass_LONG || eClass == uno::TypeClass_DOUBLE )
     156           0 :             aDefaults[nValid++] = beans::PropertyValue( rProp.Name, -1, aValue, beans::PropertyState_DIRECT_VALUE );
     157           0 :     }
     158           0 :     aDefaults.realloc(nValid);
     159             : 
     160             :     //! get user-visible names, sort by them
     161             : 
     162           0 :     return aDefaults;
     163             : }
     164             : 
     165             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10