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

Generated by: LCOV version 1.10