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

Generated by: LCOV version 1.11