bump product version to 6.3.0.0.beta1
[LibreOffice.git] / svtools / source / contnr / DocumentInfoPreview.cxx
bloba34030701f9892ae57eece8032b2f7e58f8eb039
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/document/XDocumentProperties.hpp>
25 #include <com/sun/star/script/CannotConvertException.hpp>
26 #include <com/sun/star/script/Converter.hpp>
27 #include <com/sun/star/script/XTypeConverter.hpp>
28 #include <comphelper/processfactory.hxx>
29 #include <comphelper/string.hxx>
30 #include <rtl/ustring.hxx>
31 #include <svl/inettype.hxx>
32 #include <svtools/DocumentInfoPreview.hxx>
33 #include <svtools/imagemgr.hxx>
34 #include <svtools/svmedit2.hxx>
35 #include <vcl/builder.hxx>
36 #include <vcl/txtattr.hxx>
37 #include <vcl/settings.hxx>
38 #include <vcl/svapp.hxx>
39 #include <vcl/builderfactory.hxx>
40 #include <tools/datetime.hxx>
41 #include <tools/urlobj.hxx>
42 #include <unotools/ucbhelper.hxx>
43 #include <unotools/localedatawrapper.hxx>
45 #include <templwin.hrc>
46 #include "templwin.hxx"
48 namespace svtools {
50 ODocumentInfoPreview::ODocumentInfoPreview(vcl::Window * pParent, WinBits nBits)
51 : Window(pParent, WB_DIALOGCONTROL)
52 , m_pEditWin( VclPtr<ExtMultiLineEdit>::Create(this, nBits) )
54 m_pEditWin->SetLeftMargin(10);
55 m_pEditWin->Show();
56 m_pEditWin->EnableCursor(false);
59 ODocumentInfoPreview::~ODocumentInfoPreview()
61 disposeOnce();
64 void ODocumentInfoPreview::dispose()
66 m_pEditWin.disposeAndClear();
67 Window::dispose();
70 VCL_BUILDER_FACTORY_ARGS(ODocumentInfoPreview, WB_BORDER | WB_READONLY)
72 void ODocumentInfoPreview::Resize() {
73 m_pEditWin->SetPosSizePixel(Point(0, 0), GetOutputSize());
76 void ODocumentInfoPreview::clear() {
77 m_pEditWin->SetText(OUString());
80 void ODocumentInfoPreview::fill(
81 css::uno::Reference< css::document::XDocumentProperties > const & xDocProps)
83 assert(xDocProps.is());
85 m_pEditWin->SetAutoScroll(false);
87 insertNonempty(DI_TITLE, xDocProps->getTitle());
88 insertNonempty(DI_FROM, xDocProps->getAuthor());
89 insertDateTime(DI_DATE, xDocProps->getCreationDate());
90 insertNonempty(DI_MODIFIEDBY, xDocProps->getModifiedBy());
91 insertDateTime(DI_MODIFIEDDATE, xDocProps->getModificationDate());
92 insertNonempty(DI_PRINTBY, xDocProps->getPrintedBy());
93 insertDateTime(DI_PRINTDATE, xDocProps->getPrintDate());
94 insertNonempty(DI_THEME, xDocProps->getSubject());
95 insertNonempty(
96 DI_KEYWORDS,
97 comphelper::string::convertCommaSeparated(xDocProps->getKeywords()));
98 insertNonempty(DI_DESCRIPTION, xDocProps->getDescription());
100 // User-defined (custom) properties:
101 css::uno::Reference< css::beans::XPropertySet > user(
102 xDocProps->getUserDefinedProperties(), css::uno::UNO_QUERY_THROW);
103 css::uno::Reference< css::beans::XPropertySetInfo > info(
104 user->getPropertySetInfo());
105 css::uno::Sequence< css::beans::Property > props(info->getProperties());
106 for (sal_Int32 i = 0; i < props.getLength(); ++i) {
107 OUString name(props[i].Name);
108 css::uno::Any aAny(user->getPropertyValue(name));
109 css::uno::Reference< css::script::XTypeConverter > conv(
110 css::script::Converter::create(
111 comphelper::getProcessComponentContext()));
112 OUString value;
113 try {
114 value = conv->convertToSimpleType(aAny, css::uno::TypeClass_STRING).
115 get< OUString >();
116 } catch (css::script::CannotConvertException & e) {
117 SAL_INFO("svtools.contnr", "ignored " << e);
119 if (!value.isEmpty()) {
120 insertEntry(name, value);
124 m_pEditWin->SetSelection(Selection(0, 0));
125 m_pEditWin->SetAutoScroll(true);
128 void ODocumentInfoPreview::insertEntry(
129 OUString const & title, OUString const & value)
131 if (!m_pEditWin->GetText().isEmpty()) {
132 m_pEditWin->InsertText("\n\n");
134 OUString caption(title + ":\n");
135 m_pEditWin->InsertText(caption);
136 m_pEditWin->SetAttrib(
137 TextAttribFontWeight(WEIGHT_BOLD), m_pEditWin->GetParagraphCount() - 2,
138 0, caption.getLength() - 1);
139 m_pEditWin->InsertText(value);
142 void ODocumentInfoPreview::insertNonempty(long id, OUString const & value)
144 if (!value.isEmpty()) {
145 insertEntry(SvtDocInfoTable_Impl::GetString(id), value);
149 void ODocumentInfoPreview::insertDateTime(
150 long id, css::util::DateTime const & value)
152 DateTime aToolsDT(
153 Date(value.Day, value.Month, value.Year),
154 tools::Time(
155 value.Hours, value.Minutes, value.Seconds, value.NanoSeconds));
156 if (aToolsDT.IsValidAndGregorian()) {
157 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
158 OUStringBuffer buf(rLocaleWrapper.getDate(aToolsDT));
159 buf.append(", ");
160 buf.append(rLocaleWrapper.getTime(aToolsDT));
161 insertEntry(SvtDocInfoTable_Impl::GetString(id), buf.makeStringAndClear());
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */