GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / contnr / DocumentInfoPreview.cxx
blobbb6129878da83a141514320d0222637cbb49d63c
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/txtattr.hxx"
33 #include "tools/datetime.hxx"
34 #include "tools/urlobj.hxx"
35 #include "unotools/pathoptions.hxx"
36 #include "unotools/ucbhelper.hxx"
38 #include "fileview.hxx"
39 #include "templwin.hrc"
40 #include "templwin.hxx"
42 namespace svtools {
44 ODocumentInfoPreview::ODocumentInfoPreview(Window * pParent, WinBits nBits):
45 Window(pParent, WB_DIALOGCONTROL), m_pEditWin(this, nBits),
46 m_pInfoTable(new SvtDocInfoTable_Impl),
47 m_aLanguageTag(SvtPathOptions().GetLanguageTag()) // detect application language
49 m_pEditWin.SetLeftMargin(10);
50 m_pEditWin.Show();
51 m_pEditWin.EnableCursor(false);
54 ODocumentInfoPreview::~ODocumentInfoPreview() {}
56 void ODocumentInfoPreview::Resize() {
57 m_pEditWin.SetPosSizePixel(Point(0, 0), GetOutputSize());
60 void ODocumentInfoPreview::clear() {
61 m_pEditWin.SetText(OUString());
64 void ODocumentInfoPreview::fill(
65 css::uno::Reference< css::document::XDocumentProperties > const & xDocProps,
66 OUString const & rURL)
68 assert(xDocProps.is());
70 m_pEditWin.SetAutoScroll(false);
72 insertNonempty(DI_TITLE, xDocProps->getTitle());
73 insertNonempty(DI_FROM, xDocProps->getAuthor());
74 insertDateTime(DI_DATE, xDocProps->getCreationDate());
75 insertNonempty(DI_MODIFIEDBY, xDocProps->getModifiedBy());
76 insertDateTime(DI_MODIFIEDDATE, xDocProps->getModificationDate());
77 insertNonempty(DI_PRINTBY, xDocProps->getPrintedBy());
78 insertDateTime(DI_PRINTDATE, xDocProps->getPrintDate());
79 insertNonempty(DI_THEME, xDocProps->getSubject());
80 insertNonempty(
81 DI_KEYWORDS,
82 comphelper::string::convertCommaSeparated(xDocProps->getKeywords()));
83 insertNonempty(DI_DESCRIPTION, xDocProps->getDescription());
84 if (!rURL.isEmpty()) {
85 insertNonempty(
86 DI_SIZE, CreateExactSizeText(utl::UCBContentHelper::GetSize(rURL)));
87 INetContentType eTypeID = INetContentTypes::GetContentTypeFromURL(rURL);
88 if(eTypeID == CONTENT_TYPE_APP_OCTSTREAM)
90 insertNonempty( DI_MIMETYPE, SvFileInformationManager::GetDescription(INetURLObject(rURL)));
92 else
94 insertNonempty( DI_MIMETYPE, INetContentTypes::GetPresentation(eTypeID, m_aLanguageTag));
98 // User-defined (custom) properties:
99 css::uno::Reference< css::beans::XPropertySet > user(
100 xDocProps->getUserDefinedProperties(), css::uno::UNO_QUERY_THROW);
101 css::uno::Reference< css::beans::XPropertySetInfo > info(
102 user->getPropertySetInfo());
103 css::uno::Sequence< css::beans::Property > props(info->getProperties());
104 for (sal_Int32 i = 0; i < props.getLength(); ++i) {
105 OUString name(props[i].Name);
106 css::uno::Any aAny(user->getPropertyValue(name));
107 css::uno::Reference< css::script::XTypeConverter > conv(
108 css::script::Converter::create(
109 comphelper::getProcessComponentContext()));
110 OUString value;
111 try {
112 value = conv->convertToSimpleType(aAny, css::uno::TypeClass_STRING).
113 get< OUString >();
114 } catch (css::script::CannotConvertException & e) {
115 SAL_INFO("svtools.contnr", "ignored CannotConvertException " << e.Message);
117 if (!value.isEmpty()) {
118 insertEntry(name, value);
122 m_pEditWin.SetSelection(Selection(0, 0));
123 m_pEditWin.SetAutoScroll(true);
126 void ODocumentInfoPreview::insertEntry(
127 OUString const & title, OUString const & value)
129 if (!m_pEditWin.GetText().isEmpty()) {
130 m_pEditWin.InsertText(OUString("\n\n"));
132 OUString caption(title + OUString(":\n"));
133 m_pEditWin.InsertText(caption);
134 m_pEditWin.SetAttrib(
135 TextAttribFontWeight(WEIGHT_BOLD), m_pEditWin.GetParagraphCount() - 2,
136 0, caption.getLength() - 1);
137 m_pEditWin.InsertText(value);
140 void ODocumentInfoPreview::insertNonempty(long id, OUString const & value)
142 if (!value.isEmpty()) {
143 insertEntry(m_pInfoTable->GetString(id), value);
147 void ODocumentInfoPreview::insertDateTime(
148 long id, css::util::DateTime const & value)
150 DateTime aToolsDT(
151 Date(value.Day, value.Month, value.Year),
152 Time(
153 value.Hours, value.Minutes, value.Seconds, value.NanoSeconds));
154 if (aToolsDT.IsValidAndGregorian()) {
155 const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
156 OUStringBuffer buf(rLocaleWrapper.getDate(aToolsDT));
157 buf.append(", ");
158 buf.append(rLocaleWrapper.getTime(aToolsDT));
159 insertEntry(m_pInfoTable->GetString(id), buf.makeStringAndClear());
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */