diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-03-12 19:58:09 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-03-13 10:39:51 +0100 |
commit | cbdc446e6f49ee0968f3c0765b3349f5e681018b (patch) | |
tree | 4c81b4539405f826591a55a1e1802892a4db376b /svtools/source/contnr | |
parent | 3f89190894b056639e9a323ebffe7a2e20ad4dc4 (diff) |
Clean up ODocumentInfoPreview
Diffstat (limited to 'svtools/source/contnr')
-rw-r--r-- | svtools/source/contnr/DocumentInfoPreview.cxx | 181 | ||||
-rw-r--r-- | svtools/source/contnr/fileview.cxx | 6 | ||||
-rw-r--r-- | svtools/source/contnr/fileview.hxx | 42 | ||||
-rw-r--r-- | svtools/source/contnr/templwin.cxx | 190 | ||||
-rw-r--r-- | svtools/source/contnr/templwin.hxx | 10 |
5 files changed, 228 insertions, 201 deletions
diff --git a/svtools/source/contnr/DocumentInfoPreview.cxx b/svtools/source/contnr/DocumentInfoPreview.cxx new file mode 100644 index 000000000000..805ed0aa1895 --- /dev/null +++ b/svtools/source/contnr/DocumentInfoPreview.cxx @@ -0,0 +1,181 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "sal/config.h" + +#include "com/sun/star/beans/XPropertySet.hpp" +#include "com/sun/star/document/XDocumentProperties.hpp" +#include "com/sun/star/script/Converter.hpp" +#include "com/sun/star/script/XTypeConverter.hpp" +#include "comphelper/processfactory.hxx" +#include "comphelper/string.hxx" +#include "rtl/oustringostreaminserter.hxx" +#include "svl/inettype.hxx" +#include "svtools/DocumentInfoPreview.hxx" +#include "svtools/imagemgr.hxx" +#include "svtools/txtattr.hxx" +#include "tools/datetime.hxx" +#include "tools/urlobj.hxx" +#include "unotools/pathoptions.hxx" +#include "unotools/ucbhelper.hxx" + +#include "fileview.hxx" +#include "templwin.hrc" +#include "templwin.hxx" + +namespace svtools { + +namespace { + +namespace css = com::sun::star; + +} + +ODocumentInfoPreview::ODocumentInfoPreview(Window * pParent, WinBits nBits): + Window(pParent, WB_DIALOGCONTROL), m_pEditWin(this, nBits), + m_pInfoTable(new SvtDocInfoTable_Impl), + m_aLocale(SvtPathOptions().GetLocale()) // detect application language +{ + m_pEditWin.SetLeftMargin(10); + m_pEditWin.Show(); + m_pEditWin.EnableCursor(false); +} + +ODocumentInfoPreview::~ODocumentInfoPreview() {} + +void ODocumentInfoPreview::Resize() { + m_pEditWin.SetPosSizePixel(Point(0, 0), GetOutputSize()); +} + +void ODocumentInfoPreview::clear() { + m_pEditWin.SetText(rtl::OUString()); +} + +void ODocumentInfoPreview::fill( + css::uno::Reference< css::document::XDocumentProperties > const & xDocProps, + rtl::OUString const & rURL) +{ + assert(xDocProps.is()); + + m_pEditWin.SetAutoScroll(false); + + insertNonempty(DI_TITLE, xDocProps->getTitle()); + insertNonempty(DI_FROM, xDocProps->getAuthor()); + insertDateTime(DI_DATE, xDocProps->getCreationDate()); + insertNonempty(DI_MODIFIEDBY, xDocProps->getModifiedBy()); + insertDateTime(DI_MODIFIEDDATE, xDocProps->getModificationDate()); + insertNonempty(DI_PRINTBY, xDocProps->getPrintedBy()); + insertDateTime(DI_PRINTDATE, xDocProps->getPrintDate()); + insertNonempty(DI_THEME, xDocProps->getSubject()); + insertNonempty( + DI_KEYWORDS, + comphelper::string::convertCommaSeparated(xDocProps->getKeywords())); + insertNonempty(DI_DESCRIPTION, xDocProps->getDescription()); + if (!rURL.isEmpty()) { + insertNonempty( + DI_SIZE, CreateExactSizeText(utl::UCBContentHelper::GetSize(rURL))); + INetContentType eTypeID = INetContentTypes::GetContentTypeFromURL(rURL); + insertNonempty( + DI_MIMETYPE, + (eTypeID == CONTENT_TYPE_APP_OCTSTREAM + ? SvFileInformationManager::GetDescription(INetURLObject(rURL)) + : INetContentTypes::GetPresentation(eTypeID, m_aLocale))); + } + + // User-defined (custom) properties: + css::uno::Reference< css::beans::XPropertySet > user( + xDocProps->getUserDefinedProperties(), css::uno::UNO_QUERY_THROW); + css::uno::Reference< css::beans::XPropertySetInfo > info( + user->getPropertySetInfo()); + css::uno::Sequence< css::beans::Property > props(info->getProperties()); + for (sal_Int32 i = 0; i < props.getLength(); ++i) { + rtl::OUString name(props[i].Name); + css::uno::Any aAny(user->getPropertyValue(name)); + css::uno::Reference< css::script::XTypeConverter > conv( + css::script::Converter::create( + comphelper::getProcessComponentContext())); + rtl::OUString value; + try { + value = conv->convertToSimpleType(aAny, css::uno::TypeClass_STRING). + get< rtl::OUString >(); + } catch (css::script::CannotConvertException & e) { + SAL_INFO("svtools", "ignored CannotConvertException " << e.Message); + } + if (!value.isEmpty()) { + insertEntry(name, value); + } + } + + m_pEditWin.SetSelection(Selection(0, 0)); + m_pEditWin.SetAutoScroll(true); +} + +void ODocumentInfoPreview::insertEntry( + rtl::OUString const & title, rtl::OUString const & value) +{ + rtl::OUString p1(rtl::OUString("\n") + title + rtl::OUString(":")); + m_pEditWin.InsertText(p1); + m_pEditWin.SetAttrib( + TextAttribFontWeight(WEIGHT_BOLD), m_pEditWin.GetParagraphCount() - 1, + 0, p1.getLength()); + rtl::OUString p2(rtl::OUString("\n") + value); + m_pEditWin.InsertText(p2); + m_pEditWin.SetAttrib( + TextAttribFontWeight(WEIGHT_NORMAL), + m_pEditWin.GetParagraphCount() - 1, 0, p2.getLength()); + m_pEditWin.InsertText(rtl::OUString("\n")); +} + +void ODocumentInfoPreview::insertNonempty(long id, rtl::OUString const & value) +{ + if (!value.isEmpty()) { + insertEntry(m_pInfoTable->GetString(id), value); + } +} + +void ODocumentInfoPreview::insertDateTime( + long id, css::util::DateTime const & value) +{ + DateTime aToolsDT( + Date(value.Day, value.Month, value.Year), + Time( + value.Hours, value.Minutes, value.Seconds, value.HundredthSeconds)); + if (aToolsDT.IsValidAndGregorian()) { + LocaleDataWrapper aLocaleWrapper( + comphelper::getProcessServiceFactory(), + Application::GetSettings().GetLocale()); + rtl::OUStringBuffer buf(aLocaleWrapper.getDate(aToolsDT)); + buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); + buf.append(aLocaleWrapper.getTime(aToolsDT)); + insertEntry(m_pInfoTable->GetString(id), buf.makeStringAndClear()); + } +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/source/contnr/fileview.cxx b/svtools/source/contnr/fileview.cxx index 4e1ff6e51081..ab3f6d8f3fcf 100644 --- a/svtools/source/contnr/fileview.cxx +++ b/svtools/source/contnr/fileview.cxx @@ -26,6 +26,7 @@ * ************************************************************************/ +#include "sal/config.h" #include <svtools/fileview.hxx> #include <svtools/svtdata.hxx> @@ -34,6 +35,7 @@ #include <svtools/svtabbx.hxx> #include <svtools/svtools.hrc> #include "fileview.hrc" +#include "fileview.hxx" #include "contentenumeration.hxx" #include <svtools/AccessibleBrowseBoxObjType.hxx> #include <com/sun/star/util/DateTime.hpp> @@ -656,7 +658,7 @@ inline void SvtFileView_Impl::EndEditing( bool _bCancel ) // functions ------------------------------------------------------------- -OUString CreateExactSizeText_Impl( sal_Int64 nSize ) +OUString CreateExactSizeText( sal_Int64 nSize ) { double fSize( ( double ) nSize ); int nDec; @@ -2223,7 +2225,7 @@ void SvtFileView_Impl::CreateDisplayText_Impl() aValue += aTab; // folders don't have a size if ( ! (*aIt)->mbIsFolder ) - aValue += CreateExactSizeText_Impl( (*aIt)->maSize ); + aValue += CreateExactSizeText( (*aIt)->maSize ); aValue += aTab; // set the date, but volumes have no date if ( ! (*aIt)->mbIsFolder || ! (*aIt)->mbIsVolume ) diff --git a/svtools/source/contnr/fileview.hxx b/svtools/source/contnr/fileview.hxx new file mode 100644 index 000000000000..d0940fbdde23 --- /dev/null +++ b/svtools/source/contnr/fileview.hxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_SVTOOLS_SOURCE_CONTNR_FILEVIEW_HXX +#define INCLUDED_SVTOOLS_SOURCE_CONTNR_FILEVIEW_HXX + +#include "sal/config.h" + +#include "sal/types.h" + +namespace rtl { class OUString; } + +rtl::OUString CreateExactSizeText(sal_Int64 nSize); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/source/contnr/templwin.cxx b/svtools/source/contnr/templwin.cxx index d23862db2ce5..3bdb0f7ee7c6 100644 --- a/svtools/source/contnr/templwin.cxx +++ b/svtools/source/contnr/templwin.cxx @@ -43,7 +43,6 @@ #include <svtools/svtools.hrc> #include "templwin.hrc" #include <svtools/helpid.hrc> -#include <unotools/pathoptions.hxx> #include <unotools/viewoptions.hxx> #include <unotools/ucbhelper.hxx> #include "unotools/configmgr.hxx" @@ -97,7 +96,6 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::view; using namespace svtools; -extern ::rtl::OUString CreateExactSizeText_Impl( sal_Int64 nSize ); // fileview.cxx #define aSeparatorStr "----------------------------------" #define SPLITSET_ID 0 @@ -129,163 +127,6 @@ struct FolderHistory typedef ::std::vector< ::rtl::OUString* > NewDocList_Impl; -ODocumentInfoPreview::ODocumentInfoPreview( Window* pParent ,WinBits _nBits) : Window(pParent,WB_DIALOGCONTROL) -{ - m_pEditWin = new SvtExtendedMultiLineEdit_Impl(this,_nBits); - m_pEditWin->Show(); - m_pEditWin->EnableCursor( sal_False ); - m_pInfoTable = new SvtDocInfoTable_Impl(); - // detect application language - m_aLocale = SvtPathOptions().GetLocale(); -} -// ----------------------------------------------------------------------------- -ODocumentInfoPreview::~ODocumentInfoPreview() -{ - delete m_pEditWin; - delete m_pInfoTable; -} -// ----------------------------------------------------------------------------- -void ODocumentInfoPreview::Resize() -{ - Size aOutputSize( GetOutputSize() ); - m_pEditWin->SetPosSizePixel( Point(0,0),aOutputSize); -} -// ----------------------------------------------------------------------------- -void ODocumentInfoPreview::Clear() -{ - m_pEditWin->Clear(); -} -// ----------------------------------------------------------------------------- - -void lcl_insertDateTimeEntry(SvtExtendedMultiLineEdit_Impl* i_pEditWin, - const ::rtl::OUString & i_rName, const util::DateTime & i_rUDT) -{ - DateTime aToolsDT = - DateTime( Date( i_rUDT.Day, i_rUDT.Month, i_rUDT.Year ), - Time( i_rUDT.Hours, i_rUDT.Minutes, - i_rUDT.Seconds, i_rUDT.HundredthSeconds ) ); - if ( aToolsDT.IsValidAndGregorian() ) - { - LocaleDataWrapper aLocaleWrapper( - ::comphelper::getProcessServiceFactory(), - Application::GetSettings().GetLocale() ); - String aDateStr = aLocaleWrapper.getDate( aToolsDT ); - aDateStr += String( RTL_CONSTASCII_USTRINGPARAM(", ") ); - aDateStr += aLocaleWrapper.getTime( aToolsDT ); - i_pEditWin->InsertEntry( i_rName, aDateStr ); - } -} - -void ODocumentInfoPreview::fill( - const Reference< XDocumentProperties >& i_xDocProps, const String& i_rURL) -{ - if (!i_xDocProps.is()) throw RuntimeException(); - - ::rtl::OUString aStr; - m_pEditWin->SetAutoScroll( sal_False ); - - aStr = i_xDocProps->getTitle(); - if (!aStr.isEmpty()) { - m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_TITLE ), aStr ); - } - - aStr = i_xDocProps->getAuthor(); - if (!aStr.isEmpty()) { - m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_FROM ), aStr ); - } - - lcl_insertDateTimeEntry(m_pEditWin, - m_pInfoTable->GetString( DI_DATE ), - i_xDocProps->getCreationDate()); - - aStr = i_xDocProps->getModifiedBy(); - if (!aStr.isEmpty()) { - m_pEditWin->InsertEntry( m_pInfoTable->GetString(DI_MODIFIEDBY), aStr ); - } - - lcl_insertDateTimeEntry(m_pEditWin, - m_pInfoTable->GetString( DI_MODIFIEDDATE ), - i_xDocProps->getModificationDate()); - - aStr = i_xDocProps->getPrintedBy(); - if (!aStr.isEmpty()) { - m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_PRINTBY ), aStr ); - } - - lcl_insertDateTimeEntry(m_pEditWin, - m_pInfoTable->GetString( DI_PRINTDATE ), - i_xDocProps->getPrintDate()); - - aStr = i_xDocProps->getSubject(); - if (!aStr.isEmpty()) { - m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_THEME ), aStr ); - } - - aStr = - ::comphelper::string::convertCommaSeparated(i_xDocProps->getKeywords()); - if (!aStr.isEmpty()) { - m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_KEYWORDS ), aStr ); - } - - aStr = i_xDocProps->getDescription(); - if (!aStr.isEmpty()) { - m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_DESCRIPTION ), - aStr ); - } - - // size - if ( i_rURL.Len() > 0 ) - { - m_pEditWin->InsertEntry( - m_pInfoTable->GetString( DI_SIZE ), - CreateExactSizeText_Impl( utl::UCBContentHelper::GetSize( i_rURL ) ) ); - } - - // MIMEType - if ( i_rURL.Len() > 0 ) - { - INetContentType eTypeID = - INetContentTypes::GetContentTypeFromURL( i_rURL ); - if ( eTypeID != CONTENT_TYPE_APP_OCTSTREAM ) { - aStr = INetContentTypes::GetPresentation( eTypeID, m_aLocale ); - } else { - aStr = SvFileInformationManager::GetDescription( - INetURLObject(i_rURL) ); - } - if (!aStr.isEmpty()) { - m_pEditWin->InsertEntry( m_pInfoTable->GetString( DI_MIMETYPE ), - aStr ); - } - } - - // user-defined (custom) properties - Reference< XPropertySet > xUserDefined( - i_xDocProps->getUserDefinedProperties(), UNO_QUERY_THROW ); - Reference< XPropertySetInfo > xUDInfo = xUserDefined->getPropertySetInfo(); - Sequence< Property > props = xUDInfo->getProperties(); - for (sal_Int32 i = 0; i < props.getLength(); ++i) { - const ::rtl::OUString name = props[i].Name; - uno::Any aAny; - try { - aAny = xUserDefined->getPropertyValue(name); - uno::Reference < script::XTypeConverter > xConverter( - comphelper::getProcessServiceFactory()->createInstance( - ASCII_STR("com.sun.star.script.Converter")), - UNO_QUERY ); - uno::Any aNew; - aNew = xConverter->convertToSimpleType( aAny, TypeClass_STRING ); - if ((aNew >>= aStr) && !aStr.isEmpty()) { - m_pEditWin->InsertEntry( name, aStr); - } - } catch (uno::Exception &) { - // ignore - } - } - - m_pEditWin->SetSelection( Selection( 0, 0 ) ); - m_pEditWin->SetAutoScroll( sal_True ); -} - // class SvtDummyHeaderBar_Impl ------------------------------------------ void SvtDummyHeaderBar_Impl::UpdateBackgroundColor() @@ -760,35 +601,6 @@ SvtDocInfoTable_Impl::SvtDocInfoTable_Impl() : { } -// ----------------------------------------------------------------------------- -// class SvtExtendedMultiLineEdit_Impl -------------------------------------------- -SvtExtendedMultiLineEdit_Impl::SvtExtendedMultiLineEdit_Impl( Window* pParent,WinBits _nBits ) : - - ExtMultiLineEdit( pParent, _nBits ) - -{ - SetLeftMargin( 10 ); -} -// ----------------------------------------------------------------------------- -void SvtExtendedMultiLineEdit_Impl::InsertEntry( const String& rTitle, const String& rValue ) -{ - String aText( '\n' ); - aText += rTitle; - aText += ':'; - InsertText( aText ); - sal_uLong nPara = GetParagraphCount() - 1; - SetAttrib( TextAttribFontWeight( WEIGHT_BOLD ), nPara, 0, aText.Len() ); - - aText = '\n'; - aText += rValue; - InsertText( aText ); - nPara = GetParagraphCount() - 1; - SetAttrib( TextAttribFontWeight( WEIGHT_NORMAL ), nPara, 0, aText.Len() ); - - InsertText( String( '\n' ) ); -} -// ----------------------------------------------------------------------------- - // ----------------------------------------------------------------------- const String& SvtDocInfoTable_Impl::GetString( long nId ) const @@ -896,7 +708,7 @@ void SvtFrameWindow_Impl::OpenFile( const String& rURL, sal_Bool bPreview, sal_B aCurrentURL = rURL; ViewNonEmptyWin(); - pEditWin->Clear(); + pEditWin->clear(); if ( rURL.Len() > 0 && bPreview && m_xDocProps.is() ) ShowDocInfo( rURL ); diff --git a/svtools/source/contnr/templwin.hxx b/svtools/source/contnr/templwin.hxx index 7e2c7506b48e..207efeb09139 100644 --- a/svtools/source/contnr/templwin.hxx +++ b/svtools/source/contnr/templwin.hxx @@ -176,16 +176,6 @@ public: const String& GetString( long nId ) const; }; -class SvtExtendedMultiLineEdit_Impl : public ExtMultiLineEdit -{ -public: - SvtExtendedMultiLineEdit_Impl( Window* pParent,WinBits _nBits ); - inline ~SvtExtendedMultiLineEdit_Impl() {} - - inline void Clear() { SetText( String() ); } - void InsertEntry( const String& rTitle, const String& rValue ); -}; - class SvtFrameWindow_Impl : public Window { private: |