Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <sal/config.h>
21 :
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 <tools/datetime.hxx>
36 : #include <tools/urlobj.hxx>
37 : #include <unotools/pathoptions.hxx>
38 : #include <unotools/ucbhelper.hxx>
39 :
40 : #include "fileview.hxx"
41 : #include "templwin.hrc"
42 : #include "templwin.hxx"
43 :
44 : namespace svtools {
45 :
46 16 : ODocumentInfoPreview::ODocumentInfoPreview(vcl::Window * pParent, WinBits nBits):
47 : Window(pParent, WB_DIALOGCONTROL), m_pEditWin(this, nBits),
48 16 : m_pInfoTable(new SvtDocInfoTable_Impl),
49 32 : m_aLanguageTag(SvtPathOptions().GetLanguageTag()) // detect application language
50 : {
51 16 : m_pEditWin.SetLeftMargin(10);
52 16 : m_pEditWin.Show();
53 16 : m_pEditWin.EnableCursor(false);
54 16 : }
55 :
56 12 : ODocumentInfoPreview::~ODocumentInfoPreview() {}
57 :
58 0 : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeODocumentInfoPreview(vcl::Window *pParent, VclBuilder::stringmap&)
59 : {
60 0 : return new ODocumentInfoPreview(pParent, WB_BORDER | WB_READONLY);
61 : }
62 :
63 0 : void ODocumentInfoPreview::Resize() {
64 0 : m_pEditWin.SetPosSizePixel(Point(0, 0), GetOutputSize());
65 0 : }
66 :
67 0 : void ODocumentInfoPreview::clear() {
68 0 : m_pEditWin.SetText(OUString());
69 0 : }
70 :
71 0 : void ODocumentInfoPreview::fill(
72 : css::uno::Reference< css::document::XDocumentProperties > const & xDocProps,
73 : OUString const & rURL)
74 : {
75 : assert(xDocProps.is());
76 :
77 0 : m_pEditWin.SetAutoScroll(false);
78 :
79 0 : insertNonempty(DI_TITLE, xDocProps->getTitle());
80 0 : insertNonempty(DI_FROM, xDocProps->getAuthor());
81 0 : insertDateTime(DI_DATE, xDocProps->getCreationDate());
82 0 : insertNonempty(DI_MODIFIEDBY, xDocProps->getModifiedBy());
83 0 : insertDateTime(DI_MODIFIEDDATE, xDocProps->getModificationDate());
84 0 : insertNonempty(DI_PRINTBY, xDocProps->getPrintedBy());
85 0 : insertDateTime(DI_PRINTDATE, xDocProps->getPrintDate());
86 0 : insertNonempty(DI_THEME, xDocProps->getSubject());
87 : insertNonempty(
88 : DI_KEYWORDS,
89 0 : comphelper::string::convertCommaSeparated(xDocProps->getKeywords()));
90 0 : insertNonempty(DI_DESCRIPTION, xDocProps->getDescription());
91 0 : if (!rURL.isEmpty()) {
92 : insertNonempty(
93 0 : DI_SIZE, CreateExactSizeText(utl::UCBContentHelper::GetSize(rURL)));
94 0 : INetContentType eTypeID = INetContentTypes::GetContentTypeFromURL(rURL);
95 0 : if(eTypeID == CONTENT_TYPE_APP_OCTSTREAM)
96 : {
97 0 : insertNonempty( DI_MIMETYPE, SvFileInformationManager::GetDescription(INetURLObject(rURL)));
98 : }
99 : else
100 : {
101 0 : insertNonempty( DI_MIMETYPE, INetContentTypes::GetPresentation(eTypeID, m_aLanguageTag));
102 : }
103 : }
104 :
105 : // User-defined (custom) properties:
106 : css::uno::Reference< css::beans::XPropertySet > user(
107 0 : xDocProps->getUserDefinedProperties(), css::uno::UNO_QUERY_THROW);
108 : css::uno::Reference< css::beans::XPropertySetInfo > info(
109 0 : user->getPropertySetInfo());
110 0 : css::uno::Sequence< css::beans::Property > props(info->getProperties());
111 0 : for (sal_Int32 i = 0; i < props.getLength(); ++i) {
112 0 : OUString name(props[i].Name);
113 0 : css::uno::Any aAny(user->getPropertyValue(name));
114 : css::uno::Reference< css::script::XTypeConverter > conv(
115 : css::script::Converter::create(
116 0 : comphelper::getProcessComponentContext()));
117 0 : OUString value;
118 : try {
119 0 : value = conv->convertToSimpleType(aAny, css::uno::TypeClass_STRING).
120 0 : get< OUString >();
121 0 : } catch (css::script::CannotConvertException & e) {
122 : SAL_INFO("svtools.contnr", "ignored CannotConvertException " << e.Message);
123 : }
124 0 : if (!value.isEmpty()) {
125 0 : insertEntry(name, value);
126 : }
127 0 : }
128 :
129 0 : m_pEditWin.SetSelection(Selection(0, 0));
130 0 : m_pEditWin.SetAutoScroll(true);
131 0 : }
132 :
133 0 : void ODocumentInfoPreview::insertEntry(
134 : OUString const & title, OUString const & value)
135 : {
136 0 : if (!m_pEditWin.GetText().isEmpty()) {
137 0 : m_pEditWin.InsertText(OUString("\n\n"));
138 : }
139 0 : OUString caption(title + ":\n");
140 0 : m_pEditWin.InsertText(caption);
141 : m_pEditWin.SetAttrib(
142 0 : TextAttribFontWeight(WEIGHT_BOLD), m_pEditWin.GetParagraphCount() - 2,
143 0 : 0, caption.getLength() - 1);
144 0 : m_pEditWin.InsertText(value);
145 0 : }
146 :
147 0 : void ODocumentInfoPreview::insertNonempty(long id, OUString const & value)
148 : {
149 0 : if (!value.isEmpty()) {
150 0 : insertEntry(m_pInfoTable->GetString(id), value);
151 : }
152 0 : }
153 :
154 0 : void ODocumentInfoPreview::insertDateTime(
155 : long id, css::util::DateTime const & value)
156 : {
157 : DateTime aToolsDT(
158 : Date(value.Day, value.Month, value.Year),
159 : tools::Time(
160 0 : value.Hours, value.Minutes, value.Seconds, value.NanoSeconds));
161 0 : if (aToolsDT.IsValidAndGregorian()) {
162 0 : const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
163 0 : OUStringBuffer buf(rLocaleWrapper.getDate(aToolsDT));
164 0 : buf.append(", ");
165 0 : buf.append(rLocaleWrapper.getTime(aToolsDT));
166 0 : insertEntry(m_pInfoTable->GetString(id), buf.makeStringAndClear());
167 : }
168 0 : }
169 :
170 1227 : }
171 :
172 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|