LCOV - code coverage report
Current view: top level - sw/source/core/unocore - swunohelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 86 122 70.5 %
Date: 2015-06-13 12:38:46 Functions: 7 9 77.8 %
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 <com/sun/star/uno/Sequence.h>
      21             : #include <com/sun/star/uno/Exception.hpp>
      22             : #include <com/sun/star/ucb/UniversalContentBroker.hpp>
      23             : #include <com/sun/star/ucb/XContentIdentifier.hpp>
      24             : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
      25             : #include <com/sun/star/ucb/TransferInfo.hpp>
      26             : #include <com/sun/star/ucb/NameClash.hpp>
      27             : #include <com/sun/star/sdbc/XResultSet.hpp>
      28             : #include <com/sun/star/sdbc/XRow.hpp>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include <comphelper/processfactory.hxx>
      31             : #include <comphelper/types.hxx>
      32             : #include <tools/urlobj.hxx>
      33             : #include <tools/datetime.hxx>
      34             : #include <rtl/ustring.hxx>
      35             : #include <osl/diagnose.h>
      36             : #include <ucbhelper/contentidentifier.hxx>
      37             : #include <ucbhelper/content.hxx>
      38             : #include <swunohelper.hxx>
      39             : 
      40             : //UUUU
      41             : #include <svx/xfillit0.hxx>
      42             : #include <editeng/memberids.hrc>
      43             : #include <svl/itemset.hxx>
      44             : 
      45             : using namespace com::sun::star;
      46             : 
      47             : namespace SWUnoHelper
      48             : {
      49             : 
      50       10909 : sal_Int32 GetEnumAsInt32( const ::com::sun::star::uno::Any& rVal )
      51             : {
      52             :     sal_Int32 eVal;
      53             :     try
      54             :     {
      55       10909 :         eVal = comphelper::getEnumAsINT32( rVal );
      56             :     }
      57           0 :     catch( ::com::sun::star::uno::Exception & )
      58             :     {
      59           0 :         eVal = 0;
      60             :         OSL_FAIL( "can't get EnumAsInt32" );
      61             :     }
      62       10909 :     return eVal;
      63             : }
      64             : 
      65             : // methods for UCB actions
      66           9 : bool UCB_DeleteFile( const OUString& rURL )
      67             : {
      68             :     bool bRemoved;
      69             :     try
      70             :     {
      71             :         ucbhelper::Content aTempContent( rURL,
      72             :                                 ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(),
      73           9 :                                 comphelper::getProcessComponentContext() );
      74             :         aTempContent.executeCommand("delete",
      75           9 :                         ::com::sun::star::uno::makeAny( true ) );
      76           9 :         bRemoved = true;
      77             :     }
      78           0 :     catch( ::com::sun::star::uno::Exception& )
      79             :     {
      80           0 :         bRemoved = false;
      81             :         OSL_FAIL( "Exeception from executeCommand( delete )" );
      82             :     }
      83           9 :     return bRemoved;
      84             : }
      85             : 
      86           2 : bool UCB_CopyFile( const OUString& rURL, const OUString& rNewURL, bool bCopyIsMove )
      87             : {
      88           2 :     bool bCopyCompleted = true;
      89             :     try
      90             :     {
      91           2 :         INetURLObject aURL( rNewURL );
      92           4 :         const OUString sName( aURL.GetName() );
      93           2 :         aURL.removeSegment();
      94           4 :         const OUString sMainURL( aURL.GetMainURL(INetURLObject::NO_DECODE) );
      95             : 
      96             :         ucbhelper::Content aTempContent( sMainURL,
      97             :                                 ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(),
      98           4 :                                 comphelper::getProcessComponentContext() );
      99             : 
     100           4 :         ::com::sun::star::uno::Any aAny;
     101           4 :         ::com::sun::star::ucb::TransferInfo aInfo;
     102           2 :         aInfo.NameClash = ::com::sun::star::ucb::NameClash::ERROR;
     103           2 :         aInfo.NewTitle = sName;
     104           2 :         aInfo.SourceURL = rURL;
     105           2 :         aInfo.MoveData = bCopyIsMove;
     106           2 :         aAny <<= aInfo;
     107           4 :         aTempContent.executeCommand( "transfer", aAny );
     108             :     }
     109           0 :     catch( ::com::sun::star::uno::Exception& )
     110             :     {
     111             :         OSL_FAIL( "Exeception from executeCommand( transfer )" );
     112           0 :         bCopyCompleted = false;
     113             :     }
     114           2 :     return bCopyCompleted;
     115             : }
     116             : 
     117           0 : bool UCB_IsCaseSensitiveFileName( const OUString& rURL )
     118             : {
     119             :     bool bCaseSensitive;
     120             :     try
     121             :     {
     122           0 :         INetURLObject aTempObj( rURL );
     123           0 :         aTempObj.SetBase( aTempObj.GetBase().toAsciiLowerCase() );
     124             :         ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentIdentifier > xRef1 = new
     125           0 :                 ucbhelper::ContentIdentifier( aTempObj.GetMainURL( INetURLObject::NO_DECODE ));
     126             : 
     127           0 :         aTempObj.SetBase(aTempObj.GetBase().toAsciiUpperCase());
     128             :         ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentIdentifier > xRef2 = new
     129           0 :                 ucbhelper::ContentIdentifier( aTempObj.GetMainURL( INetURLObject::NO_DECODE ));
     130             : 
     131             :         ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XUniversalContentBroker > xUcb =
     132           0 :               com::sun::star::ucb::UniversalContentBroker::create(comphelper::getProcessComponentContext());
     133             : 
     134           0 :         sal_Int32 nCompare = xUcb->compareContentIds( xRef1, xRef2 );
     135           0 :         bCaseSensitive = 0 != nCompare;
     136             :     }
     137           0 :     catch( ::com::sun::star::uno::Exception& )
     138             :     {
     139           0 :         bCaseSensitive = false;
     140             :         OSL_FAIL( "Exeception from compareContentIds()" );
     141             :     }
     142           0 :     return bCaseSensitive;
     143             : }
     144             : 
     145           8 : bool UCB_IsReadOnlyFileName( const OUString& rURL )
     146             : {
     147           8 :     bool bIsReadOnly = false;
     148             :     try
     149             :     {
     150           8 :         ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     151          16 :         ::com::sun::star::uno::Any aAny = aCnt.getPropertyValue("IsReadOnly");
     152           8 :         if(aAny.hasValue())
     153          16 :             bIsReadOnly = *static_cast<sal_Bool const *>(aAny.getValue());
     154             :     }
     155           0 :     catch( ::com::sun::star::uno::Exception& )
     156             :     {
     157           0 :         bIsReadOnly = false;
     158             :     }
     159           8 :     return bIsReadOnly;
     160             : }
     161             : 
     162           0 : bool UCB_IsFile( const OUString& rURL )
     163             : {
     164           0 :     bool bExists = false;
     165             :     try
     166             :     {
     167           0 :         ::ucbhelper::Content aContent( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     168           0 :         bExists = aContent.isDocument();
     169             :     }
     170           0 :     catch (::com::sun::star::uno::Exception &)
     171             :     {
     172             :     }
     173           0 :     return bExists;
     174             : }
     175             : 
     176           8 : bool UCB_IsDirectory( const OUString& rURL )
     177             : {
     178           8 :     bool bExists = false;
     179             :     try
     180             :     {
     181           8 :         ::ucbhelper::Content aContent( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     182           8 :         bExists = aContent.isFolder();
     183             :     }
     184           0 :     catch (::com::sun::star::uno::Exception &)
     185             :     {
     186             :     }
     187           8 :     return bExists;
     188             : }
     189             : 
     190             :     // get a list of files from the folder of the URL
     191             :     // options: pExtension = 0 -> all, else this specific extension
     192             :     //          pDateTime != 0 -> returns also the modified date/time of
     193             :     //                       the files in a std::vector<OUString> -->
     194             :     //                       !! objects must be deleted from the caller!!
     195           2 : bool UCB_GetFileListOfFolder( const OUString& rURL,
     196             :                                 std::vector<OUString>& rList,
     197             :                                 const OUString* pExtension,
     198             :                                 std::vector< ::DateTime* >* pDateTimeList )
     199             : {
     200           2 :     bool bOk = false;
     201             :     try
     202             :     {
     203           2 :         ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     204           4 :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > xResultSet;
     205             : 
     206           2 :         const sal_Int32 nSeqSize = pDateTimeList ? 2 : 1;
     207           4 :         ::com::sun::star::uno::Sequence < OUString > aProps( nSeqSize );
     208           2 :         OUString* pProps = aProps.getArray();
     209           2 :         pProps[ 0 ] = "Title";
     210           2 :         if( pDateTimeList )
     211           0 :             pProps[ 1 ] = "DateModified";
     212             : 
     213             :         try
     214             :         {
     215           2 :             xResultSet = aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY );
     216             :         }
     217           0 :         catch( ::com::sun::star::uno::Exception& )
     218             :         {
     219             :             OSL_FAIL( "create cursor failed!" );
     220             :         }
     221             : 
     222           2 :         if( xResultSet.is() )
     223             :         {
     224           2 :             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > xRow( xResultSet, ::com::sun::star::uno::UNO_QUERY );
     225           2 :             const sal_Int32 nExtLen = pExtension ? pExtension->getLength() : 0;
     226             :             try
     227             :             {
     228           2 :                 if( xResultSet->first() )
     229             :                 {
     230           4 :                     do {
     231           4 :                         const OUString sTitle( xRow->getString( 1 ) );
     232          12 :                         if( !nExtLen ||
     233           8 :                             ( sTitle.getLength() > nExtLen &&
     234           4 :                               sTitle.endsWith( *pExtension )) )
     235             :                         {
     236           4 :                             rList.push_back( sTitle );
     237             : 
     238           4 :                             if( pDateTimeList )
     239             :                             {
     240           0 :                                 ::com::sun::star::util::DateTime aStamp = xRow->getTimestamp(2);
     241             :                                 ::DateTime* pDateTime = new ::DateTime(
     242             :                                         ::Date( aStamp.Day,
     243             :                                                 aStamp.Month,
     244             :                                                 aStamp.Year ),
     245             :                                         ::tools::Time( aStamp.Hours,
     246             :                                                 aStamp.Minutes,
     247             :                                                 aStamp.Seconds,
     248           0 :                                                 aStamp.NanoSeconds ));
     249           0 :                                 pDateTimeList->push_back( pDateTime );
     250             :                             }
     251           4 :                         }
     252             : 
     253           4 :                     } while( xResultSet->next() );
     254             :                 }
     255           2 :                 bOk = true;
     256             :             }
     257           0 :             catch( ::com::sun::star::uno::Exception& )
     258             :             {
     259             :                 OSL_FAIL( "Exception caught!" );
     260           2 :             }
     261           2 :         }
     262             :     }
     263           0 :     catch( ::com::sun::star::uno::Exception& )
     264             :     {
     265             :         OSL_FAIL( "Exception caught!" );
     266           0 :         bOk = false;
     267             :     }
     268           2 :     return bOk;
     269             : }
     270             : 
     271             : //UUUU
     272       60104 : bool needToMapFillItemsToSvxBrushItemTypes(const SfxItemSet& rSet,
     273             :         sal_uInt16 const nMID)
     274             : {
     275       60104 :     const XFillStyleItem* pXFillStyleItem(static_cast< const XFillStyleItem*  >(rSet.GetItem(XATTR_FILLSTYLE, false)));
     276             : 
     277       60104 :     if(!pXFillStyleItem)
     278             :     {
     279       59672 :         return false;
     280             :     }
     281             : 
     282             :     // here different FillStyles can be excluded for export; it will depend on the
     283             :     // quality these fallbacks can reach. That again is done in getSvxBrushItemFromSourceSet,
     284             :     // take a look there how the superset of DrawObject FillStyles is mapped to SvxBrushItem.
     285         432 :     const drawing::FillStyle eFill = pXFillStyleItem->GetValue();
     286         432 :     switch (eFill)
     287             :     {
     288             :         case drawing::FillStyle_NONE:
     289          56 :             return false; // ignoring some extremely limited XFillColorItem eval
     290             :             break;
     291             :         case drawing::FillStyle_SOLID:
     292             :         case drawing::FillStyle_GRADIENT: // gradient and hatch don't exist in
     293             :         case drawing::FillStyle_HATCH: // SvxBrushItem so average color is emulated
     294         329 :             switch (nMID)
     295             :             {
     296             :                 case MID_BACK_COLOR:
     297             :                     // Gradient/Hatch always have emulated color
     298             :                     return (drawing::FillStyle_SOLID != eFill)
     299          11 :                         || SfxItemState::SET == rSet.GetItemState(XATTR_FILLCOLOR)
     300           0 :                         || SfxItemState::SET == rSet.GetItemState(XATTR_FILLTRANSPARENCE)
     301          11 :                         || SfxItemState::SET == rSet.GetItemState(XATTR_FILLFLOATTRANSPARENCE);
     302             :                 case MID_BACK_COLOR_R_G_B:
     303             :                     // Gradient/Hatch always have emulated color
     304             :                     return (drawing::FillStyle_SOLID != eFill)
     305          39 :                         || SfxItemState::SET == rSet.GetItemState(XATTR_FILLCOLOR);
     306             :                 case MID_BACK_COLOR_TRANSPARENCY:
     307          40 :                     return SfxItemState::SET == rSet.GetItemState(XATTR_FILLTRANSPARENCE)
     308          40 :                         || SfxItemState::SET == rSet.GetItemState(XATTR_FILLFLOATTRANSPARENCE);
     309             :             }
     310         239 :             break;
     311             :         case drawing::FillStyle_BITMAP:
     312          47 :             switch (nMID)
     313             :             {
     314             :                 case MID_GRAPHIC_URL:
     315           7 :                     return SfxItemState::SET == rSet.GetItemState(XATTR_FILLBITMAP);
     316             :                 case MID_GRAPHIC_POSITION:
     317           7 :                     return SfxItemState::SET == rSet.GetItemState(XATTR_FILLBMP_STRETCH)
     318           6 :                         || SfxItemState::SET == rSet.GetItemState(XATTR_FILLBMP_TILE)
     319          13 :                         || SfxItemState::SET == rSet.GetItemState(XATTR_FILLBMP_POS);
     320             :                 case MID_GRAPHIC_TRANSPARENT:
     321             :                 case MID_GRAPHIC_TRANSPARENCY:
     322          13 :                     return SfxItemState::SET == rSet.GetItemState(XATTR_FILLTRANSPARENCE)
     323          13 :                         || SfxItemState::SET == rSet.GetItemState(XATTR_FILLFLOATTRANSPARENCE);
     324             :             }
     325          20 :             break;
     326             :         default:
     327             :             assert(false);
     328             :     }
     329             : 
     330             : 
     331         259 :     return false;
     332             : }
     333             : 
     334             : }
     335             : 
     336             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11