LCOV - code coverage report
Current view: top level - sfx2/source/dialog - templateinfodlg.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 55 0.0 %
Date: 2014-04-14 Functions: 0 6 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             : 
      10             : #include <sfx2/templateinfodlg.hxx>
      11             : 
      12             : #include <comphelper/processfactory.hxx>
      13             : #include <sfx2/sfxresid.hxx>
      14             : #include <svtools/DocumentInfoPreview.hxx>
      15             : #include <toolkit/helper/vclunohelper.hxx>
      16             : 
      17             : #include <com/sun/star/beans/XPropertySet.hpp>
      18             : #include <com/sun/star/document/DocumentProperties.hpp>
      19             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      20             : #include <com/sun/star/frame/Frame.hpp>
      21             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      22             : #include <com/sun/star/task/InteractionHandler.hpp>
      23             : #include <com/sun/star/util/URL.hpp>
      24             : #include <com/sun/star/util/URLTransformer.hpp>
      25             : #include <com/sun/star/util/XURLTransformer.hpp>
      26             : 
      27             : #include "templateinfodlg.hrc"
      28             : 
      29             : #define DLG_BORDER_SIZE 12
      30             : 
      31             : using namespace ::com::sun::star;
      32             : using namespace ::com::sun::star::beans;
      33             : using namespace ::com::sun::star::document;
      34             : using namespace ::com::sun::star::frame;
      35             : using namespace ::com::sun::star::lang;
      36             : using namespace ::com::sun::star::task;
      37             : using namespace ::com::sun::star::util;
      38             : 
      39           0 : SfxTemplateInfoDlg::SfxTemplateInfoDlg (Window *pParent)
      40             :     : ModalDialog(pParent,SfxResId(DLG_TEMPLATE_INFORMATION)),
      41             :       maBtnClose(this,SfxResId(BTN_TEMPLATE_INFO_CLOSE)),
      42           0 :       mpPreviewView(new Window(this)),
      43           0 :       mpInfoView(new svtools::ODocumentInfoPreview(this,WB_LEFT | WB_VSCROLL | WB_READONLY | WB_BORDER | WB_3DLOOK))
      44             : {
      45           0 :     maBtnClose.SetClickHdl(LINK(this,SfxTemplateInfoDlg,CloseHdl));
      46             : 
      47           0 :     Size aWinSize = GetOutputSizePixel();
      48           0 :     aWinSize.setHeight( aWinSize.getHeight() - 3*DLG_BORDER_SIZE - maBtnClose.GetOutputHeightPixel() );
      49           0 :     aWinSize.setWidth( (aWinSize.getWidth() - 3*DLG_BORDER_SIZE)/2 );
      50           0 :     mpInfoView->SetPosSizePixel(Point(DLG_BORDER_SIZE,DLG_BORDER_SIZE),aWinSize);
      51             : 
      52           0 :     mpPreviewView->SetPosSizePixel(Point(aWinSize.getWidth()+2*DLG_BORDER_SIZE,DLG_BORDER_SIZE),aWinSize);
      53             : 
      54           0 :     xWindow = VCLUnoHelper::GetInterface(mpPreviewView);
      55             : 
      56           0 :     m_xFrame = Frame::create( comphelper::getProcessComponentContext() );
      57           0 :     m_xFrame->initialize( xWindow );
      58             : 
      59           0 :     mpPreviewView->Show();
      60           0 :     mpInfoView->Show();
      61           0 : }
      62             : 
      63           0 : SfxTemplateInfoDlg::~SfxTemplateInfoDlg()
      64             : {
      65           0 :     m_xFrame->dispose();
      66             : 
      67           0 :     delete mpInfoView;
      68           0 : }
      69             : 
      70           0 : void SfxTemplateInfoDlg::loadDocument(const OUString &rURL)
      71             : {
      72             :     assert(!rURL.isEmpty());
      73             : 
      74           0 :     uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
      75             : 
      76             :     try
      77             :     {
      78             :         uno::Reference<task::XInteractionHandler2> xInteractionHandler(
      79           0 :             task::InteractionHandler::createWithParent(xContext, 0) );
      80             : 
      81           0 :         uno::Sequence<beans::PropertyValue> aProps(1);
      82           0 :         aProps[0].Name = "InteractionHandler";
      83           0 :         aProps[0].Value <<= xInteractionHandler;
      84             : 
      85             :         uno::Reference<document::XDocumentProperties> xDocProps(
      86           0 :                     document::DocumentProperties::create(comphelper::getProcessComponentContext()) );
      87             : 
      88           0 :         xDocProps->loadFromMedium( rURL, aProps );
      89             : 
      90           0 :         mpInfoView->fill( xDocProps, rURL );
      91             : 
      92             :         // Create template preview
      93             :         uno::Reference<util::XURLTransformer > xTrans(
      94           0 :                     util::URLTransformer::create(comphelper::getProcessComponentContext()));
      95             : 
      96           0 :         util::URL aURL;
      97           0 :         aURL.Complete = rURL;
      98           0 :         xTrans->parseStrict(aURL);
      99             : 
     100           0 :         uno::Reference<frame::XDispatch> xDisp = m_xFrame->queryDispatch( aURL, "_self", 0 );
     101             : 
     102           0 :         if ( xDisp.is() )
     103             :         {
     104           0 :             mpPreviewView->EnableInput( false, true );
     105             : 
     106           0 :             bool b = true;
     107           0 :             uno::Sequence <beans::PropertyValue> aArgs( 4 );
     108           0 :             aArgs[0].Name = "Preview";
     109           0 :             aArgs[0].Value.setValue( &b, ::getBooleanCppuType() );
     110           0 :             aArgs[1].Name = "ReadOnly";
     111           0 :             aArgs[1].Value.setValue( &b, ::getBooleanCppuType() );
     112           0 :             aArgs[2].Name = "AsTemplate";    // prevents getting an empty URL with getURL()!
     113           0 :             aArgs[3].Name = "InteractionHandler";
     114           0 :             aArgs[3].Value <<= xInteractionHandler;
     115             : 
     116           0 :             b = false;
     117           0 :             aArgs[2].Value.setValue( &b, ::getBooleanCppuType() );
     118           0 :             xDisp->dispatch( aURL, aArgs );
     119           0 :         }
     120             :     }
     121           0 :     catch ( beans::UnknownPropertyException& )
     122             :     {
     123             :     }
     124           0 :     catch ( uno::Exception& )
     125             :     {
     126           0 :     }
     127           0 : }
     128             : 
     129           0 : IMPL_LINK_NOARG (SfxTemplateInfoDlg, CloseHdl)
     130             : {
     131           0 :     Close();
     132           0 :     return 0;
     133             : }
     134             : 
     135             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10