summaryrefslogtreecommitdiff
path: root/sfx2/source/dialog/templateinfodlg.cxx
blob: 1f6f9935aaf8cd92b9b52f751e280ecd36080183 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <sfx2/templateinfodlg.hxx>

#include <comphelper/processfactory.hxx>
#include <sfx2/sfxresid.hxx>
#include <svtools/DocumentInfoPreview.hxx>
#include <toolkit/helper/vclunohelper.hxx>

#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/document/DocumentProperties.hpp>
#include <com/sun/star/frame/XDispatchProvider.hpp>
#include <com/sun/star/frame/Frame.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/task/InteractionHandler.hpp>
#include <com/sun/star/util/URL.hpp>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/util/XURLTransformer.hpp>

using namespace ::com::sun::star;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::document;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::task;
using namespace ::com::sun::star::util;

SfxTemplateInfoDlg::SfxTemplateInfoDlg (vcl::Window *pParent)
    : ModalDialog(pParent, "TemplateInfo", "sfx/ui/templateinfodialog.ui")
{
    get(mpBtnClose, "close");
    get(mpBox, "box");
    get(mpInfoView, "infoDrawingArea");
    mpPreviewView = new vcl::Window(mpBox);

    Size aSize(LogicToPixel(Size(250, 160), MAP_APPFONT));
    mpBox->set_width_request(aSize.Width());
    mpBox->set_height_request(aSize.Height());

    mpBtnClose->SetClickHdl(LINK(this,SfxTemplateInfoDlg,CloseHdl));

    xWindow = VCLUnoHelper::GetInterface(mpPreviewView);

    m_xFrame = Frame::create( comphelper::getProcessComponentContext() );
    m_xFrame->initialize( xWindow );
}

SfxTemplateInfoDlg::~SfxTemplateInfoDlg()
{
    m_xFrame->dispose();
}

void SfxTemplateInfoDlg::loadDocument(const OUString &rURL)
{
    assert(!rURL.isEmpty());

    uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());

    try
    {
        uno::Reference<task::XInteractionHandler2> xInteractionHandler(
            task::InteractionHandler::createWithParent(xContext, 0) );

        uno::Sequence<beans::PropertyValue> aProps(1);
        aProps[0].Name = "InteractionHandler";
        aProps[0].Value <<= xInteractionHandler;

        uno::Reference<document::XDocumentProperties> xDocProps(
                    document::DocumentProperties::create(comphelper::getProcessComponentContext()) );

        xDocProps->loadFromMedium( rURL, aProps );

        mpInfoView->fill( xDocProps, rURL );

        // Create template preview
        uno::Reference<util::XURLTransformer > xTrans(
                    util::URLTransformer::create(comphelper::getProcessComponentContext()));

        util::URL aURL;
        aURL.Complete = rURL;
        xTrans->parseStrict(aURL);

        uno::Reference<frame::XDispatch> xDisp = m_xFrame->queryDispatch( aURL, "_self", 0 );

        if ( xDisp.is() )
        {
            mpPreviewView->EnableInput( false, true );

            bool b = true;
            uno::Sequence <beans::PropertyValue> aArgs( 4 );
            aArgs[0].Name = "Preview";
            aArgs[0].Value.setValue( &b, cppu::UnoType<bool>::get() );
            aArgs[1].Name = "ReadOnly";
            aArgs[1].Value.setValue( &b, cppu::UnoType<bool>::get() );
            aArgs[2].Name = "AsTemplate";    // prevents getting an empty URL with getURL()!
            aArgs[3].Name = "InteractionHandler";
            aArgs[3].Value <<= xInteractionHandler;

            b = false;
            aArgs[2].Value.setValue( &b, cppu::UnoType<bool>::get() );
            xDisp->dispatch( aURL, aArgs );
        }
    }
    catch ( beans::UnknownPropertyException& )
    {
    }
    catch ( uno::Exception& )
    {
    }
}

IMPL_LINK_NOARG (SfxTemplateInfoDlg, CloseHdl)
{
    Close();
    return 0;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */