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