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

Generated by: LCOV version 1.10