LCOV - code coverage report
Current view: top level - libreoffice/cui/source/options - optmemory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 100 1.0 %
Date: 2012-12-27 Functions: 2 17 11.8 %
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 <algorithm>
      23             : 
      24             : #include <officecfg/Office/Common.hxx>
      25             : #include <svtools/langtab.hxx>
      26             : #include <svl/zforlist.hxx>
      27             : #include <svtools/grfmgr.hxx>
      28             : #include <svl/flagitem.hxx>
      29             : #include <sfx2/dispatch.hxx>
      30             : #include <unotools/lingucfg.hxx>
      31             : #include <svl/szitem.hxx>
      32             : #include <sfx2/viewsh.hxx>
      33             : #include <sfx2/viewfrm.hxx>
      34             : #include <vcl/msgbox.hxx>
      35             : #include <rtl/math.hxx>
      36             : #include <unotools/useroptions.hxx>
      37             : #include <unotools/fontoptions.hxx>
      38             : #include <svtools/menuoptions.hxx>
      39             : #include <svl/cjkoptions.hxx>
      40             : #include <svtools/miscopt.hxx>
      41             : #include <unotools/syslocaleoptions.hxx>
      42             : #include <svtools/helpopt.hxx>
      43             : #include <unotools/configitem.hxx>
      44             : #include <sfx2/objsh.hxx>
      45             : #include <comphelper/types.hxx>
      46             : #include <editeng/unolingu.hxx>
      47             : #include <editeng/langitem.hxx>
      48             : #include "cuioptgenrl.hxx"
      49             : #include "optpath.hxx"
      50             : #include "optsave.hxx"
      51             : #include "optlingu.hxx"
      52             : #include <svx/xpool.hxx>
      53             : #include <svx/dlgutil.hxx>
      54             : #include "cuitabarea.hxx"
      55             : #include "optmemory.hrc"
      56             : #include "optmemory.hxx"
      57             : #include <svx/ofaitem.hxx>
      58             : #include <cuires.hrc>
      59             : #include "helpid.hrc"
      60             : #include <dialmgr.hxx>
      61             : 
      62             : #include <config_vclplug.h>
      63             : 
      64             : using namespace ::com::sun::star::uno;
      65             : using namespace ::com::sun::star::lang;
      66             : using namespace ::com::sun::star::beans;
      67             : using namespace ::utl;
      68             : using namespace ::rtl;
      69             : using namespace ::sfx2;
      70             : 
      71             : 
      72             : #define NF2BYTES        104857.6                        // 2^20/10, used for aNfGraphicObjectCache-unit -> Byte
      73             : #define BYTES2NF        (1.0/NF2BYTES)                  // 10/2^20
      74             : 
      75             : 
      76           0 : sal_Int32 OfaMemoryOptionsPage::GetNfGraphicCacheVal() const
      77             : {
      78           0 :     return aNfGraphicCache.GetValue() << 20;
      79             : }
      80             : 
      81           0 : inline void OfaMemoryOptionsPage::SetNfGraphicCacheVal( long nSizeInBytes )
      82             : {
      83           0 :     aNfGraphicCache.SetValue( nSizeInBytes >> 20 );
      84           0 : }
      85             : 
      86           0 : long OfaMemoryOptionsPage::GetNfGraphicObjectCacheVal( void ) const
      87             : {
      88           0 :     return long( ::rtl::math::round( double( aNfGraphicObjectCache.GetValue() ) * NF2BYTES ) );
      89             : }
      90             : 
      91           0 : void OfaMemoryOptionsPage::SetNfGraphicObjectCacheVal( long nSizeInBytes )
      92             : {
      93           0 :     aNfGraphicObjectCache.SetValue( long( ::rtl::math::round( double( nSizeInBytes ) * BYTES2NF ) ) );
      94           0 : }
      95             : 
      96           0 : inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheMax( long nSizeInBytes )
      97             : {
      98           0 :     aNfGraphicObjectCache.SetMax( long( double( nSizeInBytes ) * BYTES2NF ) );
      99           0 : }
     100             : 
     101           0 : inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheLast( long nSizeInBytes )
     102             : {
     103           0 :     aNfGraphicObjectCache.SetLast( long( double( nSizeInBytes ) * BYTES2NF ) );
     104           0 : }
     105             : 
     106           0 : int OfaMemoryOptionsPage::DeactivatePage( SfxItemSet* _pSet )
     107             : {
     108           0 :     if ( _pSet )
     109           0 :         FillItemSet( *_pSet );
     110           0 :     return LEAVE_PAGE;
     111             : }
     112             : 
     113             : // -----------------------------------------------------------------------
     114             : 
     115           0 : OfaMemoryOptionsPage::OfaMemoryOptionsPage(Window* pParent, const SfxItemSet& rSet ) :
     116             : 
     117           0 :     SfxTabPage( pParent, CUI_RES( OFA_TP_MEMORY ), rSet ),
     118             : 
     119           0 :     aUndoBox                ( this, CUI_RES( GB_UNDO ) ),
     120           0 :     aUndoText               ( this, CUI_RES( FT_UNDO ) ),
     121           0 :     aUndoEdit               ( this, CUI_RES( ED_UNDO ) ),
     122           0 :     aGbGraphicCache         ( this, CUI_RES( GB_GRAPHICCACHE ) ),
     123           0 :     aFtGraphicCache         ( this, CUI_RES( FT_GRAPHICCACHE ) ),
     124           0 :     aNfGraphicCache         ( this, CUI_RES( NF_GRAPHICCACHE ) ),
     125           0 :     aFtGraphicCacheUnit     ( this, CUI_RES( FT_GRAPHICCACHE_UNIT         ) ),
     126           0 :     aFtGraphicObjectCache   ( this, CUI_RES( FT_GRAPHICOBJECTCACHE ) ),
     127           0 :     aNfGraphicObjectCache   ( this, CUI_RES( NF_GRAPHICOBJECTCACHE ) ),
     128           0 :     aFtGraphicObjectCacheUnit(this, CUI_RES( FT_GRAPHICOBJECTCACHE_UNIT ) ),
     129           0 :     aFtGraphicObjectTime    ( this, CUI_RES( FT_GRAPHICOBJECTTIME ) ),
     130           0 :     aTfGraphicObjectTime    ( this, CUI_RES( TF_GRAPHICOBJECTTIME ) ),
     131           0 :     aFtGraphicObjectTimeUnit( this, CUI_RES( FT_GRAPHICOBJECTTIME_UNIT     ) ),
     132             : 
     133           0 :     aGbOLECache             ( this, CUI_RES( GB_OLECACHE ) ),
     134           0 :     aFtOLECache             ( this, CUI_RES( FT_OLECACHE ) ),
     135           0 :     aNfOLECache             ( this, CUI_RES( NF_OLECACHE ) ),
     136           0 :     aQuickLaunchFL          ( this, CUI_RES( FL_QUICKLAUNCH ) ),
     137           0 :     aQuickLaunchCB          ( this, CUI_RES( CB_QUICKLAUNCH ) )//,
     138             : {
     139             : #if defined(UNX)
     140           0 :     aQuickLaunchCB.SetText( CUI_RES( STR_QUICKLAUNCH_UNX ) );
     141             : #endif
     142           0 :     FreeResource();
     143             : 
     144             :     //quick launch only available in Win
     145             : #if !defined(WNT) && !defined(ENABLE_GTK)
     146             :     aQuickLaunchFL.Hide();
     147             :     aQuickLaunchCB.Hide();
     148             : #endif
     149             : 
     150           0 :     aTfGraphicObjectTime.SetExtFormat( EXTTIMEF_24H_SHORT );
     151             : 
     152           0 :     SetExchangeSupport();
     153             : 
     154           0 :     aNfGraphicCache.SetModifyHdl( LINK( this, OfaMemoryOptionsPage, GraphicCacheConfigHdl ) );
     155           0 : }
     156             : 
     157             : // -----------------------------------------------------------------------
     158             : 
     159           0 : OfaMemoryOptionsPage::~OfaMemoryOptionsPage()
     160             : {
     161           0 : }
     162             : 
     163             : // -----------------------------------------------------------------------
     164             : 
     165           0 : SfxTabPage* OfaMemoryOptionsPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
     166             : {
     167           0 :     return new OfaMemoryOptionsPage( pParent, rAttrSet );
     168             : }
     169             : 
     170             : // -----------------------------------------------------------------------
     171             : 
     172           0 : sal_Bool OfaMemoryOptionsPage::FillItemSet( SfxItemSet& rSet )
     173             : {
     174           0 :     sal_Bool bModified = sal_False;
     175             : 
     176             :     boost::shared_ptr< comphelper::ConfigurationChanges > batch(
     177           0 :         comphelper::ConfigurationChanges::create());
     178             : 
     179           0 :     if ( aUndoEdit.GetText() != aUndoEdit.GetSavedValue() )
     180             :         officecfg::Office::Common::Undo::Steps::set(
     181           0 :             aUndoEdit.GetValue(), batch);
     182             : 
     183             :     // GraphicCache
     184           0 :     sal_Int32 totalCacheSize = GetNfGraphicCacheVal();
     185             :     officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(
     186           0 :         totalCacheSize, batch);
     187           0 :     sal_Int32 objectCacheSize = GetNfGraphicObjectCacheVal();
     188             :     officecfg::Office::Common::Cache::GraphicManager::ObjectCacheSize::set(
     189           0 :         objectCacheSize, batch);
     190             : 
     191           0 :     const Time aTime( aTfGraphicObjectTime.GetTime() );
     192             :     sal_Int32 objectReleaseTime =
     193           0 :         aTime.GetSec() + aTime.GetMin() * 60 + aTime.GetHour() * 3600;
     194             :     officecfg::Office::Common::Cache::GraphicManager::ObjectReleaseTime::set(
     195           0 :         objectReleaseTime, batch);
     196             : 
     197             :     // create a dummy graphic object to get access to the common GraphicManager
     198           0 :     GraphicObject       aDummyObject;
     199           0 :     GraphicManager&     rGrfMgr = aDummyObject.GetGraphicManager();
     200             : 
     201           0 :     rGrfMgr.SetMaxCacheSize(totalCacheSize);
     202           0 :     rGrfMgr.SetMaxObjCacheSize(objectCacheSize, true);
     203           0 :     rGrfMgr.SetCacheTimeout(objectReleaseTime);
     204             : 
     205             :     // OLECache
     206             :     officecfg::Office::Common::Cache::Writer::OLE_Objects::set(
     207           0 :         aNfOLECache.GetValue(), batch);
     208             :     officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::set(
     209           0 :         aNfOLECache.GetValue(), batch);
     210             : 
     211           0 :     batch->commit();
     212             : 
     213           0 :     if( aQuickLaunchCB.IsChecked() != aQuickLaunchCB.GetSavedValue())
     214             :     {
     215           0 :         rSet.Put(SfxBoolItem(SID_ATTR_QUICKLAUNCHER, aQuickLaunchCB.IsChecked()));
     216           0 :         bModified = sal_True;
     217             :     }
     218             : 
     219           0 :     return bModified;
     220             : }
     221             : 
     222             : // -----------------------------------------------------------------------
     223             : 
     224           0 : void OfaMemoryOptionsPage::Reset( const SfxItemSet& rSet )
     225             : {
     226             :     const SfxPoolItem*  pItem;
     227             : 
     228           0 :     aUndoEdit.SetValue(officecfg::Office::Common::Undo::Steps::get());
     229           0 :     aUndoEdit.SaveValue();
     230             : 
     231             :     // GraphicCache
     232             :     long n =
     233             :         officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::get();
     234           0 :     SetNfGraphicCacheVal( n );
     235             :     SetNfGraphicObjectCacheVal(
     236             :         std::min(
     237           0 :             GetNfGraphicCacheVal(),
     238             :             (officecfg::Office::Common::Cache::GraphicManager::ObjectCacheSize::
     239           0 :              get())));
     240             : 
     241             :     sal_Int32 nTime =
     242             :         officecfg::Office::Common::Cache::GraphicManager::ObjectReleaseTime::
     243             :         get();
     244           0 :     Time aTime( (sal_uInt16)( nTime / 3600 ), (sal_uInt16)( ( nTime % 3600 ) / 60 ), (sal_uInt16)( ( nTime % 3600 ) % 60 ) );
     245           0 :     aTfGraphicObjectTime.SetTime( aTime );
     246             : 
     247           0 :     GraphicCacheConfigHdl( &aNfGraphicCache );
     248             : 
     249             :     // OLECache
     250             :     aNfOLECache.SetValue(
     251             :         std::max(
     252             :             officecfg::Office::Common::Cache::Writer::OLE_Objects::get(),
     253             :             (officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::
     254           0 :              get())));
     255             : 
     256           0 :     SfxItemState eState = rSet.GetItemState( SID_ATTR_QUICKLAUNCHER, sal_False, &pItem );
     257           0 :     if ( SFX_ITEM_SET == eState )
     258           0 :         aQuickLaunchCB.Check( ( (SfxBoolItem*)pItem )->GetValue() );
     259           0 :     else if ( SFX_ITEM_DISABLED == eState )
     260             :     {
     261             :         // quickstart not installed
     262           0 :         aQuickLaunchFL.Hide();
     263           0 :         aQuickLaunchCB.Hide();
     264             :     }
     265             : 
     266           0 :     aQuickLaunchCB.SaveValue();
     267           0 : }
     268             : 
     269             : // -----------------------------------------------------------------------
     270             : 
     271           0 : IMPL_LINK_NOARG(OfaMemoryOptionsPage, GraphicCacheConfigHdl)
     272             : {
     273           0 :     sal_Int32 n = GetNfGraphicCacheVal();
     274           0 :     SetNfGraphicObjectCacheMax( n );
     275           0 :     SetNfGraphicObjectCacheLast( n );
     276             : 
     277           0 :     if( GetNfGraphicObjectCacheVal() > n )
     278           0 :         SetNfGraphicObjectCacheVal( n );
     279             : 
     280           0 :     return 0;
     281           3 : }
     282             : 
     283             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10