LCOV - code coverage report
Current view: top level - sfx2/source/dialog - templateinfodlg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 62 1.6 %
Date: 2015-06-13 12:38:46 Functions: 2 9 22.2 %
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             : using namespace ::com::sun::star;
      28             : using namespace ::com::sun::star::beans;
      29             : using namespace ::com::sun::star::document;
      30             : using namespace ::com::sun::star::frame;
      31             : using namespace ::com::sun::star::lang;
      32             : using namespace ::com::sun::star::task;
      33             : using namespace ::com::sun::star::util;
      34             : 
      35           0 : SfxTemplateInfoDlg::SfxTemplateInfoDlg (vcl::Window *pParent)
      36           0 :     : ModalDialog(pParent, "TemplateInfo", "sfx/ui/templateinfodialog.ui")
      37             : {
      38           0 :     get(mpBtnClose, "close");
      39           0 :     get(mpBox, "box");
      40           0 :     get(mpInfoView, "infoDrawingArea");
      41           0 :     mpPreviewView = VclPtr<vcl::Window>::Create(mpBox.get());
      42             : 
      43           0 :     Size aSize(LogicToPixel(Size(250, 160), MAP_APPFONT));
      44           0 :     mpBox->set_width_request(aSize.Width());
      45           0 :     mpBox->set_height_request(aSize.Height());
      46             : 
      47           0 :     mpBtnClose->SetClickHdl(LINK(this,SfxTemplateInfoDlg,CloseHdl));
      48             : 
      49           0 :     xWindow = VCLUnoHelper::GetInterface(mpPreviewView);
      50             : 
      51           0 :     m_xFrame = Frame::create( comphelper::getProcessComponentContext() );
      52           0 :     m_xFrame->initialize( xWindow );
      53           0 : }
      54             : 
      55           0 : SfxTemplateInfoDlg::~SfxTemplateInfoDlg()
      56             : {
      57           0 :     disposeOnce();
      58           0 : }
      59             : 
      60           0 : void SfxTemplateInfoDlg::dispose()
      61             : {
      62           0 :     m_xFrame->dispose();
      63           0 :     mpBtnClose.clear();
      64           0 :     mpBox.clear();
      65           0 :     mpPreviewView.clear();
      66           0 :     mpInfoView.clear();
      67           0 :     ModalDialog::dispose();
      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, cppu::UnoType<bool>::get() );
     110           0 :             aArgs[1].Name = "ReadOnly";
     111           0 :             aArgs[1].Value.setValue( &b, cppu::UnoType<bool>::get() );
     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, cppu::UnoType<bool>::get() );
     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         648 : }
     134             : 
     135             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11