Bump version to 5.0-14
[LibreOffice.git] / svtools / source / contnr / DocumentInfoPreview.cxx
blobf94ee83e6585c10cd7f964688a5693b5dfc90d50
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>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/document/XDocumentProperties.hpp>
24 #include <com/sun/star/script/Converter.hpp>
25 #include <com/sun/star/script/XTypeConverter.hpp>
26 #include <comphelper/processfactory.hxx>
27 #include <comphelper/string.hxx>
28 #include <rtl/ustring.hxx>
29 #include <svl/inettype.hxx>
30 #include <svtools/DocumentInfoPreview.hxx>
31 #include <svtools/imagemgr.hxx>
32 #include <vcl/builder.hxx>
33 #include <vcl/txtattr.hxx>
34 #include <vcl/settings.hxx>
35 #include <vcl/builderfactory.hxx>
36 #include <tools/datetime.hxx>
37 #include <tools/urlobj.hxx>
38 #include <unotools/pathoptions.hxx>
39 #include <unotools/ucbhelper.hxx>
41 #include "fileview.hxx"
42 #include "templwin.hrc"
43 #include "templwin.hxx"
45 namespace svtools {
47 ODocumentInfoPreview::ODocumentInfoPreview(vcl::Window * pParent, WinBits nBits):
48 Window(pParent, WB_DIALOGCONTROL),
49 m_pEditWin( VclPtr<ExtMultiLineEdit>::Create(this, nBits) ),
50 m_xInfoTable(new SvtDocInfoTable_Impl),
51 m_aLanguageTag(SvtPathOptions().GetLanguageTag()) // detect application language
53 m_pEditWin->SetLeftMargin(10);
54 m_pEditWin->Show();
55 m_pEditWin->EnableCursor(false);
58 ODocumentInfoPreview::~ODocumentInfoPreview()
60 disposeOnce();
63 void ODocumentInfoPreview::dispose()
65 m_pEditWin.disposeAndClear();
66 Window::dispose();
69 VCL_BUILDER_FACTORY_ARGS(ODocumentInfoPreview, WB_BORDER | WB_READONLY)
71 void ODocumentInfoPreview::Resize() {
72 m_pEditWin->SetPosSizePixel(Point(0, 0), GetOutputSize());
75 void ODocumentInfoPreview::clear() {
76 m_pEditWin->SetText(OUString());
79 void ODocumentInfoPreview::fill(
80 css::uno::Reference< css::document::XDocumentProperties > const & xDocProps,
81 OUString const & rURL)
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());
99 if (!rURL.isEmpty()) {
100 insertNonempty(
101 DI_SIZE, CreateExactSizeText(utl::UCBContentHelper::GetSize(rURL)));
102 INetContentType eTypeID = INetContentTypes::GetContentTypeFromURL(rURL);
103 if(eTypeID == CONTENT_TYPE_APP_OCTSTREAM)
105 insertNonempty( DI_MIMETYPE, SvFileInformationManager::GetDescription(INetURLObject(rURL)));
107 else
109 insertNonempty( DI_MIMETYPE, INetContentTypes::GetPresentation(eTypeID, m_aLanguageTag));
113 // User-defined (custom) properties:
114 css::uno::Reference< css::beans::XPropertySet > user(
115 xDocProps->getUserDefinedProperties(), css::uno::UNO_QUERY_THROW);
116 css::uno::Reference< css::beans::XPropertySetInfo > info(
117 user->getPropertySetInfo());
118 css::uno::Sequence< css::beans::Property > props(info->getProperties());
119 for (sal_Int32 i = 0; i < props.getLength(); ++i) {
120 OUString name(props[i].Name);
121 css::uno::Any aAny(user->getPropertyValue(name));
122 css::uno::Reference< css::script::XTypeConverter > conv(
123 css::script::Converter::create(
124 comphelper::getProcessComponentContext()));
125 OUString value;
126 try {
127 value = conv->convertToSimpleType(aAny, css::uno::TypeClass_STRING).
128 get< OUString >();
129 } catch (css::script::CannotConvertException & e) {
130 SAL_INFO("svtools.contnr", "ignored CannotConvertException " << e.Message);
132 if (!value.isEmpty()) {
133 insertEntry(name, value);
137 m_pEditWin->SetSelection(Selection(0, 0));
138 m_pEditWin->SetAutoScroll(true);
141 void ODocumentInfoPreview::insertEntry(
142 OUString const & title, OUString const & value)
144 if (!m_pEditWin->GetText().isEmpty()) {
145 m_pEditWin->InsertText(OUString("\n\n"));
147 OUString caption(title + ":\n");
148 m_pEditWin->InsertText(caption);
149 m_pEditWin->SetAttrib(
150 TextAttribFontWeight(WEIGHT_BOLD), m_pEditWin->GetParagraphCount() - 2,
151 0, caption.getLength() - 1);
152 m_pEditWin->InsertText(value);
155 void ODocumentInfoPreview::insertNonempty(long id, OUString const & value)
157 if (!value.isEmpty()) {
158 insertEntry(m_xInfoTable->GetString(id), value);
162 void ODocumentInfoPreview::insertDateTime(
163 long id, css::util::DateTime const & value)
165 DateTime aToolsDT(
166 Date(value.Day, value.Month, value.Year),
167 tools::Time(
168 value.Hours, value.Minutes, value.Seconds, value.NanoSeconds));
169 if (aToolsDT.IsValidAndGregorian()) {
170 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
171 OUStringBuffer buf(rLocaleWrapper.getDate(aToolsDT));
172 buf.append(", ");
173 buf.append(rLocaleWrapper.getTime(aToolsDT));
174 insertEntry(m_xInfoTable->GetString(id), buf.makeStringAndClear());
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */