LCOV - code coverage report
Current view: top level - svtools/source/contnr - DocumentInfoPreview.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 15 79 19.0 %
Date: 2015-06-13 12:38:46 Functions: 6 13 46.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11