LCOV - code coverage report
Current view: top level - sfx2/source/dialog - templateinfodlg.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 54 1.9 %
Date: 2014-11-03 Functions: 2 8 25.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             : 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 = new vcl::Window(mpBox);
      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 :     m_xFrame->dispose();
      58           0 : }
      59             : 
      60           0 : void SfxTemplateInfoDlg::loadDocument(const OUString &rURL)
      61             : {
      62             :     assert(!rURL.isEmpty());
      63             : 
      64           0 :     uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
      65             : 
      66             :     try
      67             :     {
      68             :         uno::Reference<task::XInteractionHandler2> xInteractionHandler(
      69           0 :             task::InteractionHandler::createWithParent(xContext, 0) );
      70             : 
      71           0 :         uno::Sequence<beans::PropertyValue> aProps(1);
      72           0 :         aProps[0].Name = "InteractionHandler";
      73           0 :         aProps[0].Value <<= xInteractionHandler;
      74             : 
      75             :         uno::Reference<document::XDocumentProperties> xDocProps(
      76           0 :                     document::DocumentProperties::create(comphelper::getProcessComponentContext()) );
      77             : 
      78           0 :         xDocProps->loadFromMedium( rURL, aProps );
      79             : 
      80           0 :         mpInfoView->fill( xDocProps, rURL );
      81             : 
      82             :         // Create template preview
      83             :         uno::Reference<util::XURLTransformer > xTrans(
      84           0 :                     util::URLTransformer::create(comphelper::getProcessComponentContext()));
      85             : 
      86           0 :         util::URL aURL;
      87           0 :         aURL.Complete = rURL;
      88           0 :         xTrans->parseStrict(aURL);
      89             : 
      90           0 :         uno::Reference<frame::XDispatch> xDisp = m_xFrame->queryDispatch( aURL, "_self", 0 );
      91             : 
      92           0 :         if ( xDisp.is() )
      93             :         {
      94           0 :             mpPreviewView->EnableInput( false, true );
      95             : 
      96           0 :             bool b = true;
      97           0 :             uno::Sequence <beans::PropertyValue> aArgs( 4 );
      98           0 :             aArgs[0].Name = "Preview";
      99           0 :             aArgs[0].Value.setValue( &b, ::getBooleanCppuType() );
     100           0 :             aArgs[1].Name = "ReadOnly";
     101           0 :             aArgs[1].Value.setValue( &b, ::getBooleanCppuType() );
     102           0 :             aArgs[2].Name = "AsTemplate";    // prevents getting an empty URL with getURL()!
     103           0 :             aArgs[3].Name = "InteractionHandler";
     104           0 :             aArgs[3].Value <<= xInteractionHandler;
     105             : 
     106           0 :             b = false;
     107           0 :             aArgs[2].Value.setValue( &b, ::getBooleanCppuType() );
     108           0 :             xDisp->dispatch( aURL, aArgs );
     109           0 :         }
     110             :     }
     111           0 :     catch ( beans::UnknownPropertyException& )
     112             :     {
     113             :     }
     114           0 :     catch ( uno::Exception& )
     115             :     {
     116           0 :     }
     117           0 : }
     118             : 
     119           0 : IMPL_LINK_NOARG (SfxTemplateInfoDlg, CloseHdl)
     120             : {
     121           0 :     Close();
     122           0 :     return 0;
     123         951 : }
     124             : 
     125             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10