bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / dialog / templateinfodlg.cxx
blobdf195c8efdb225c77d5629270574ba1dee774541
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <sfx2/templateinfodlg.hxx>
12 #include <comphelper/processfactory.hxx>
13 #include <sfx2/sfxresid.hxx>
14 #include <svtools/DocumentInfoPreview.hxx>
15 #include <toolkit/helper/vclunohelper.hxx>
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>
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;
35 SfxTemplateInfoDlg::SfxTemplateInfoDlg (vcl::Window *pParent)
36 : ModalDialog(pParent, "TemplateInfo", "sfx/ui/templateinfodialog.ui")
38 get(mpBtnClose, "close");
39 get(mpBox, "box");
40 get(mpInfoView, "infoDrawingArea");
41 mpPreviewView = VclPtr<vcl::Window>::Create(mpBox.get());
43 Size aSize(LogicToPixel(Size(250, 160), MAP_APPFONT));
44 mpBox->set_width_request(aSize.Width());
45 mpBox->set_height_request(aSize.Height());
47 mpBtnClose->SetClickHdl(LINK(this,SfxTemplateInfoDlg,CloseHdl));
49 xWindow = VCLUnoHelper::GetInterface(mpPreviewView);
51 m_xFrame = Frame::create( comphelper::getProcessComponentContext() );
52 m_xFrame->initialize( xWindow );
55 SfxTemplateInfoDlg::~SfxTemplateInfoDlg()
57 disposeOnce();
60 void SfxTemplateInfoDlg::dispose()
62 m_xFrame->dispose();
63 mpBtnClose.clear();
64 mpBox.clear();
65 mpPreviewView.clear();
66 mpInfoView.clear();
67 ModalDialog::dispose();
70 void SfxTemplateInfoDlg::loadDocument(const OUString &rURL)
72 assert(!rURL.isEmpty());
74 uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
76 try
78 uno::Reference<task::XInteractionHandler2> xInteractionHandler(
79 task::InteractionHandler::createWithParent(xContext, 0) );
81 uno::Sequence<beans::PropertyValue> aProps(1);
82 aProps[0].Name = "InteractionHandler";
83 aProps[0].Value <<= xInteractionHandler;
85 uno::Reference<document::XDocumentProperties> xDocProps(
86 document::DocumentProperties::create(comphelper::getProcessComponentContext()) );
88 xDocProps->loadFromMedium( rURL, aProps );
90 mpInfoView->fill( xDocProps, rURL );
92 // Create template preview
93 uno::Reference<util::XURLTransformer > xTrans(
94 util::URLTransformer::create(comphelper::getProcessComponentContext()));
96 util::URL aURL;
97 aURL.Complete = rURL;
98 xTrans->parseStrict(aURL);
100 uno::Reference<frame::XDispatch> xDisp = m_xFrame->queryDispatch( aURL, "_self", 0 );
102 if ( xDisp.is() )
104 mpPreviewView->EnableInput( false, true );
106 bool b = true;
107 uno::Sequence <beans::PropertyValue> aArgs( 4 );
108 aArgs[0].Name = "Preview";
109 aArgs[0].Value.setValue( &b, cppu::UnoType<bool>::get() );
110 aArgs[1].Name = "ReadOnly";
111 aArgs[1].Value.setValue( &b, cppu::UnoType<bool>::get() );
112 aArgs[2].Name = "AsTemplate"; // prevents getting an empty URL with getURL()!
113 aArgs[3].Name = "InteractionHandler";
114 aArgs[3].Value <<= xInteractionHandler;
116 b = false;
117 aArgs[2].Value.setValue( &b, cppu::UnoType<bool>::get() );
118 xDisp->dispatch( aURL, aArgs );
121 catch ( beans::UnknownPropertyException& )
124 catch ( uno::Exception& )
129 IMPL_LINK_NOARG (SfxTemplateInfoDlg, CloseHdl)
131 Close();
132 return 0;
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */