LCOV - code coverage report
Current view: top level - libreoffice/framework/source/classes - taskcreator.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 36 39 92.3 %
Date: 2012-12-17 Functions: 3 4 75.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 <classes/taskcreator.hxx>
      21             : #include "services/taskcreatorsrv.hxx"
      22             : #include <threadhelp/readguard.hxx>
      23             : #include <loadenv/targethelper.hxx>
      24             : #include <services.h>
      25             : 
      26             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      27             : #include <com/sun/star/beans/NamedValue.hpp>
      28             : 
      29             : #include <comphelper/configurationhelper.hxx>
      30             : #include <vcl/svapp.hxx>
      31             : 
      32             : namespace framework{
      33             : 
      34             : /*-****************************************************************************************************//**
      35             :     @short      initialize instance with neccessary informations
      36             :     @descr      We need a valid uno service manager to create or instanciate new services.
      37             :                 All other informations to create frames or tasks come in on right interface methods.
      38             : 
      39             :     @param      xSMGR
      40             :                     points to the valid uno service manager
      41             : *//*-*****************************************************************************************************/
      42         516 : TaskCreator::TaskCreator( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
      43             :     : ThreadHelpBase(       )
      44         516 :     , m_xSMGR       ( xSMGR )
      45             : {
      46         516 : }
      47             : 
      48             : /*-****************************************************************************************************//**
      49             :     @short      deinitialize instance
      50             :     @descr      We should release all used resource which are not needed any longer.
      51             : *//*-*****************************************************************************************************/
      52        1032 : TaskCreator::~TaskCreator()
      53             : {
      54         516 :     m_xSMGR.clear();
      55         516 : }
      56             : 
      57             : /*-****************************************************************************************************//**
      58             :     TODO document me
      59             : *//*-*****************************************************************************************************/
      60         516 : css::uno::Reference< css::frame::XFrame > TaskCreator::createTask( const ::rtl::OUString& sName    ,
      61             :                                                                          sal_Bool         bVisible )
      62             : {
      63             :     /* SAFE { */
      64         516 :     ReadGuard aReadLock( m_aLock );
      65         516 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
      66         516 :     aReadLock.unlock();
      67             :     /* } SAFE */
      68             : 
      69         516 :     css::uno::Reference< css::lang::XSingleServiceFactory > xCreator;
      70         516 :     ::rtl::OUString sCreator = IMPLEMENTATIONNAME_FWK_TASKCREATOR;
      71             : 
      72             :     try
      73             :     {
      74         516 :         if (
      75         516 :             ( TargetHelper::matchSpecialTarget(sName, TargetHelper::E_BLANK  ) ) ||
      76           0 :             ( TargetHelper::matchSpecialTarget(sName, TargetHelper::E_DEFAULT) )
      77             :            )
      78             :         {
      79             :             ::comphelper::ConfigurationHelper::readDirectKey(
      80             :                 comphelper::getComponentContext(xSMGR),
      81             :                 "org.openoffice.Office.TabBrowse",
      82             :                 "TaskCreatorService",
      83             :                 "ImplementationName",
      84         516 :                 ::comphelper::ConfigurationHelper::E_READONLY) >>= sCreator;
      85             :         }
      86             : 
      87             :         xCreator = css::uno::Reference< css::lang::XSingleServiceFactory >(
      88         516 :                     xSMGR->createInstance(sCreator), css::uno::UNO_QUERY_THROW);
      89             :     }
      90           0 :     catch(const css::uno::Exception&)
      91             :     {}
      92             : 
      93             :     // no catch here ... without an task creator service we cant open ANY document window within the office.
      94             :     // Thats IMHO not a good idea. Then we should accept the stacktrace showing us the real problem.
      95             :     // BTW: The used fallback creator service (IMPLEMENTATIONNAME_FWK_TASKCREATOR) is implemented in the same
      96             :     // library then these class here ... Why we should not be able to create it ?
      97         516 :     if ( ! xCreator.is())
      98             :         xCreator = css::uno::Reference< css::lang::XSingleServiceFactory >(
      99           0 :                     xSMGR->createInstance(IMPLEMENTATIONNAME_FWK_TASKCREATOR), css::uno::UNO_QUERY_THROW);
     100             : 
     101         516 :     css::uno::Sequence< css::uno::Any > lArgs(5);
     102         516 :     css::beans::NamedValue              aArg    ;
     103             : 
     104         516 :     aArg.Name    = rtl::OUString(ARGUMENT_PARENTFRAME);
     105         516 :     aArg.Value <<= css::uno::Reference< css::frame::XFrame >(xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY_THROW);
     106         516 :     lArgs[0]   <<= aArg;
     107             : 
     108         516 :     aArg.Name    = rtl::OUString(ARGUMENT_CREATETOPWINDOW);
     109         516 :     aArg.Value <<= sal_True;
     110         516 :     lArgs[1]   <<= aArg;
     111             : 
     112         516 :     aArg.Name    = rtl::OUString(ARGUMENT_MAKEVISIBLE);
     113         516 :     aArg.Value <<= bVisible;
     114         516 :     lArgs[2]   <<= aArg;
     115             : 
     116         516 :     aArg.Name    = rtl::OUString(ARGUMENT_SUPPORTPERSISTENTWINDOWSTATE);
     117         516 :     aArg.Value <<= sal_True;
     118         516 :     lArgs[3]   <<= aArg;
     119             : 
     120         516 :     aArg.Name    = rtl::OUString(ARGUMENT_FRAMENAME);
     121         516 :     aArg.Value <<= sName;
     122         516 :     lArgs[4]   <<= aArg;
     123             : 
     124         516 :     css::uno::Reference< css::frame::XFrame > xTask(xCreator->createInstanceWithArguments(lArgs), css::uno::UNO_QUERY_THROW);
     125         516 :     return xTask;
     126             : }
     127             : 
     128             : } // namespace framework
     129             : 
     130             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10