LCOV - code coverage report
Current view: top level - svx/source/core - extedit.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 45 2.2 %
Date: 2012-08-25 Functions: 2 10 20.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 102 2.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4                 :            :  *
       5                 :            :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :            :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :            :  * the License. You may obtain a copy of the License at
       8                 :            :  * http://www.mozilla.org/MPL/
       9                 :            :  *
      10                 :            :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :            :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :            :  * for the specific language governing rights and limitations under the
      13                 :            :  * License.
      14                 :            :  *
      15                 :            :  * The Initial Developer of the Original Code is
      16                 :            :  *       [ Surendran Mahendran <surenspost@gmail.com>]
      17                 :            :  *
      18                 :            :  * Alternatively, the contents of this file may be used under the terms of
      19                 :            :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      20                 :            :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      21                 :            :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      22                 :            :  * instead of those above.
      23                 :            :  */
      24                 :            : 
      25                 :            : #include <svx/extedit.hxx>
      26                 :            : #include <svx/graphichelper.hxx>
      27                 :            : #include <sfx2/viewfrm.hxx>
      28                 :            : #include <sfx2/bindings.hxx>
      29                 :            : #include <osl/file.hxx>
      30                 :            : #include <osl/thread.hxx>
      31                 :            : #include <osl/process.h>
      32                 :            : #include <osl/time.h>
      33                 :            : #include <svtools/filter.hxx>
      34                 :            : #include <svtools/filechangedchecker.hxx>
      35                 :            : #include <svx/xoutbmp.hxx>
      36                 :            : #include <unotools/ucbstreamhelper.hxx>
      37                 :            : #include <vcl/svapp.hxx>
      38                 :            : #include <vcl/graph.hxx>
      39                 :            : #include <vcl/cvtgrf.hxx>
      40                 :            : 
      41                 :            : #include "com/sun/star/system/XSystemShellExecute.hpp"
      42                 :            : #include "com/sun/star/system/SystemShellExecuteFlags.hpp"
      43                 :            : #include <comphelper/processfactory.hxx>
      44                 :            : 
      45                 :            : #include <boost/bind.hpp>
      46                 :            : 
      47                 :            : using namespace ::com::sun::star;
      48                 :          0 : ExternalToolEdit::ExternalToolEdit()
      49                 :          0 : {}
      50                 :            : 
      51                 :          0 : ExternalToolEdit::~ExternalToolEdit()
      52         [ #  # ]:          0 : {}
      53                 :            : 
      54                 :          0 : void ExternalToolEdit::HandleCloseEvent(ExternalToolEdit* pData)
      55                 :            : {
      56         [ #  # ]:          0 :     Graphic newGraphic;
      57                 :            : 
      58                 :            :     //import the temp file image stream into the newGraphic
      59 [ #  # ][ #  # ]:          0 :     SvStream* pStream = utl::UcbStreamHelper::CreateStream(pData->m_aFileName, STREAM_READ);
                 [ #  # ]
      60         [ #  # ]:          0 :     if(pStream)
      61                 :            :     {
      62         [ #  # ]:          0 :         GraphicConverter::Import(*pStream, newGraphic);
      63                 :            : 
      64                 :            :         // Now update the Graphic in the shell by re-reading from the newGraphic
      65         [ #  # ]:          0 :         pData->Update( newGraphic );
      66                 :            : 
      67 [ #  # ][ #  # ]:          0 :         delete(pStream);
      68         [ #  # ]:          0 :     }
      69                 :          0 : }
      70                 :            : 
      71                 :          0 : IMPL_LINK (ExternalToolEdit, StartListeningEvent, void*, pEvent)
      72                 :            : {
      73                 :            :     //Start an event listener implemented via VCL timeout
      74                 :          0 :     ExternalToolEdit* pData = ( ExternalToolEdit* )pEvent;
      75         [ #  # ]:          0 :     String aURL( pData->m_aFileName );
      76                 :            : 
      77                 :            :     new FileChangedChecker(
      78                 :            :         pData->m_aFileName,
      79 [ #  # ][ #  # ]:          0 :         ::boost::bind(&HandleCloseEvent, pData));
         [ #  # ][ #  # ]
                 [ #  # ]
      80                 :            : 
      81         [ #  # ]:          0 :     return 0;
      82                 :            : }
      83                 :            : 
      84                 :          0 : void ExternalToolEdit::threadWorker(void* pThreadData)
      85                 :            : {
      86                 :          0 :     ExternalToolEdit* pData = (ExternalToolEdit*) pThreadData;
      87                 :            : 
      88                 :            :     // Make an asynchronous call to listen to the event of temporary image file
      89                 :            :     // getting changed
      90 [ #  # ][ #  # ]:          0 :     Application::PostUserEvent( LINK( NULL, ExternalToolEdit, StartListeningEvent ), pThreadData);
      91                 :            : 
      92                 :            :     uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
      93 [ #  # ][ #  # ]:          0 :             ::comphelper::getProcessServiceFactory()->createInstance(
      94 [ #  # ][ #  # ]:          0 :                 DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute") ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
                 [ #  # ]
      95 [ #  # ][ #  # ]:          0 :     xSystemShellExecute->execute( pData->m_aFileName, rtl::OUString(),  com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
      96                 :          0 : }
      97                 :            : 
      98                 :          0 : void ExternalToolEdit::Edit( GraphicObject* pGraphicObject )
      99                 :            : {
     100                 :            :     //Get the graphic from the GraphicObject
     101                 :          0 :     m_pGraphicObject = pGraphicObject;
     102 [ #  # ][ #  # ]:          0 :     const Graphic aGraphic = pGraphicObject->GetGraphic();
     103                 :            : 
     104                 :            :     //get the Preferred File Extension for this graphic
     105         [ #  # ]:          0 :     String fExtension;
     106         [ #  # ]:          0 :     GraphicHelper::GetPreferedExtension(fExtension, aGraphic);
     107                 :            : 
     108                 :            :     //Create the temp File
     109                 :          0 :     rtl::OUString tempFileBase, tempFileName;
     110                 :            :     oslFileHandle pHandle;
     111         [ #  # ]:          0 :     osl::FileBase::createTempFile(0, &pHandle, &tempFileBase);
     112                 :            : 
     113                 :            :     // Move it to a file name with image extension properly set
     114         [ #  # ]:          0 :     tempFileName = tempFileBase + rtl::OUString('.') + rtl::OUString(fExtension);
     115         [ #  # ]:          0 :     osl::File::move(tempFileBase, tempFileName);
     116                 :            : 
     117                 :            :     //Write Graphic to the Temp File
     118         [ #  # ]:          0 :     GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
     119         [ #  # ]:          0 :     sal_uInt16 nFilter(rGraphicFilter.GetExportFormatNumber(fExtension));
     120         [ #  # ]:          0 :     String aFilter(rGraphicFilter.GetExportFormatShortName(nFilter));
     121         [ #  # ]:          0 :     String sPath(tempFileName);
     122                 :            : 
     123                 :            :     // Write the Graphic to the file now
     124         [ #  # ]:          0 :     XOutBitmap::WriteGraphic(aGraphic, sPath, aFilter, XOUTBMP_USE_NATIVE_IF_POSSIBLE|XOUTBMP_DONT_EXPAND_FILENAME);
     125                 :            : 
     126                 :            :     // There is a possiblity that sPath extnesion might have been changed if the
     127                 :            :     // provided extension is not writable
     128         [ #  # ]:          0 :     tempFileName = rtl::OUString(sPath);
     129                 :            : 
     130                 :            :     //Create a thread
     131         [ #  # ]:          0 :     rtl_uString* aFileName = new rtl_uString();
     132                 :            :     rtl_uString_newFromAscii(
     133                 :            :         &aFileName,
     134         [ #  # ]:          0 :         rtl::OUStringToOString(tempFileName, RTL_TEXTENCODING_UTF8).getStr());
     135                 :          0 :     m_aFileName = aFileName;
     136                 :            :     // Create the data that is needed by the thread later
     137 [ #  # ][ #  # ]:          0 :     osl_createThread(ExternalToolEdit::threadWorker, this);
         [ #  # ][ #  # ]
                 [ #  # ]
     138 [ +  - ][ +  - ]:        450 : }

Generated by: LCOV version 1.10