LCOV - code coverage report
Current view: top level - cui/source/options - optmemory.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 90 0.0 %
Date: 2014-11-03 Functions: 0 17 0.0 %
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.hxx"
      56             : #include <svx/ofaitem.hxx>
      57             : #include <cuires.hrc>
      58             : #include "helpid.hrc"
      59             : #include <dialmgr.hxx>
      60             : 
      61             : #include <config_vclplug.h>
      62             : 
      63             : using namespace ::com::sun::star::uno;
      64             : using namespace ::com::sun::star::lang;
      65             : using namespace ::com::sun::star::beans;
      66             : using namespace ::utl;
      67             : using namespace ::sfx2;
      68             : 
      69             : 
      70             : #define NF2BYTES        104857.6                        // 2^20/10, used for M_pNfGraphicObjectCache-unit -> Byte
      71             : #define BYTES2NF        (1.0/NF2BYTES)                  // 10/2^20
      72             : 
      73             : 
      74           0 : sal_Int32 OfaMemoryOptionsPage::GetNfGraphicCacheVal() const
      75             : {
      76           0 :     return m_pNfGraphicCache->GetValue() << 20;
      77             : }
      78             : 
      79           0 : inline void OfaMemoryOptionsPage::SetNfGraphicCacheVal( long nSizeInBytes )
      80             : {
      81           0 :     m_pNfGraphicCache->SetValue( nSizeInBytes >> 20 );
      82           0 : }
      83             : 
      84           0 : long OfaMemoryOptionsPage::GetNfGraphicObjectCacheVal( void ) const
      85             : {
      86           0 :     return long( ::rtl::math::round( double( m_pNfGraphicObjectCache->GetValue() ) * NF2BYTES ) );
      87             : }
      88             : 
      89           0 : void OfaMemoryOptionsPage::SetNfGraphicObjectCacheVal( long nSizeInBytes )
      90             : {
      91           0 :     m_pNfGraphicObjectCache->SetValue( long( ::rtl::math::round( double( nSizeInBytes ) * BYTES2NF ) ) );
      92           0 : }
      93             : 
      94           0 : inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheMax( long nSizeInBytes )
      95             : {
      96           0 :     m_pNfGraphicObjectCache->SetMax( long( double( nSizeInBytes ) * BYTES2NF ) );
      97           0 : }
      98             : 
      99           0 : inline void OfaMemoryOptionsPage::SetNfGraphicObjectCacheLast( long nSizeInBytes )
     100             : {
     101           0 :     m_pNfGraphicObjectCache->SetLast( long( double( nSizeInBytes ) * BYTES2NF ) );
     102           0 : }
     103             : 
     104           0 : int OfaMemoryOptionsPage::DeactivatePage( SfxItemSet* _pSet )
     105             : {
     106           0 :     if ( _pSet )
     107           0 :         FillItemSet( _pSet );
     108           0 :     return LEAVE_PAGE;
     109             : }
     110             : 
     111             : 
     112             : 
     113           0 : OfaMemoryOptionsPage::OfaMemoryOptionsPage(vcl::Window* pParent, const SfxItemSet& rSet)
     114           0 :     : SfxTabPage(pParent, "OptMemoryPage", "cui/ui/optmemorypage.ui", &rSet)
     115             : {
     116           0 :     get(m_pUndoEdit, "undo");
     117           0 :     get(m_pNfGraphicCache, "graphiccache");
     118           0 :     get(m_pNfGraphicObjectCache, "objectcache");
     119           0 :     get(m_pTfGraphicObjectTime,"objecttime");
     120           0 :     get(m_pNfOLECache, "olecache");
     121           0 :     get(m_pQuickStarterFrame, "quickstarter");
     122             : 
     123             : #if defined(UNX)
     124           0 :     get(m_pQuickLaunchCB, "systray");
     125             : #else
     126             :     get(m_pQuickLaunchCB, "quicklaunch");
     127             : #endif
     128           0 :     m_pQuickLaunchCB->Show();
     129             : 
     130             :     //Only available in Win or if building the gtk systray
     131             : #if !defined(WNT) && ! ENABLE_GTK
     132             :     m_pQuickStarterFrame->Hide();
     133             : #endif
     134             : 
     135           0 :     m_pTfGraphicObjectTime->SetExtFormat( EXTTIMEF_24H_SHORT );
     136             : 
     137           0 :     SetExchangeSupport();
     138             : 
     139           0 :     m_pNfGraphicCache->SetModifyHdl( LINK( this, OfaMemoryOptionsPage, GraphicCacheConfigHdl ) );
     140           0 : }
     141             : 
     142             : 
     143             : 
     144           0 : OfaMemoryOptionsPage::~OfaMemoryOptionsPage()
     145             : {
     146           0 : }
     147             : 
     148             : 
     149             : 
     150           0 : SfxTabPage* OfaMemoryOptionsPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
     151             : {
     152           0 :     return new OfaMemoryOptionsPage( pParent, *rAttrSet );
     153             : }
     154             : 
     155             : 
     156             : 
     157           0 : bool OfaMemoryOptionsPage::FillItemSet( SfxItemSet* rSet )
     158             : {
     159           0 :     bool bModified = false;
     160             : 
     161             :     boost::shared_ptr< comphelper::ConfigurationChanges > batch(
     162           0 :         comphelper::ConfigurationChanges::create());
     163             : 
     164           0 :     if ( m_pUndoEdit->IsValueChangedFromSaved() )
     165             :         officecfg::Office::Common::Undo::Steps::set(
     166           0 :             m_pUndoEdit->GetValue(), batch);
     167             : 
     168             :     // GraphicCache
     169           0 :     sal_Int32 totalCacheSize = GetNfGraphicCacheVal();
     170             :     officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(
     171           0 :         totalCacheSize, batch);
     172           0 :     sal_Int32 objectCacheSize = GetNfGraphicObjectCacheVal();
     173             :     officecfg::Office::Common::Cache::GraphicManager::ObjectCacheSize::set(
     174           0 :         objectCacheSize, batch);
     175             : 
     176           0 :     const tools::Time aTime( m_pTfGraphicObjectTime->GetTime() );
     177             :     sal_Int32 objectReleaseTime =
     178           0 :         aTime.GetSec() + aTime.GetMin() * 60 + aTime.GetHour() * 3600;
     179             :     officecfg::Office::Common::Cache::GraphicManager::ObjectReleaseTime::set(
     180           0 :         objectReleaseTime, batch);
     181             : 
     182             :     // create a dummy graphic object to get access to the common GraphicManager
     183           0 :     GraphicObject       aDummyObject;
     184           0 :     GraphicManager&     rGrfMgr = aDummyObject.GetGraphicManager();
     185             : 
     186           0 :     rGrfMgr.SetMaxCacheSize(totalCacheSize);
     187           0 :     rGrfMgr.SetMaxObjCacheSize(objectCacheSize, true);
     188           0 :     rGrfMgr.SetCacheTimeout(objectReleaseTime);
     189             : 
     190             :     // OLECache
     191             :     officecfg::Office::Common::Cache::Writer::OLE_Objects::set(
     192           0 :         m_pNfOLECache->GetValue(), batch);
     193             :     officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::set(
     194           0 :         m_pNfOLECache->GetValue(), batch);
     195             : 
     196           0 :     batch->commit();
     197             : 
     198           0 :     if( m_pQuickLaunchCB->IsValueChangedFromSaved())
     199             :     {
     200           0 :         rSet->Put(SfxBoolItem(SID_ATTR_QUICKLAUNCHER, m_pQuickLaunchCB->IsChecked()));
     201           0 :         bModified = true;
     202             :     }
     203             : 
     204           0 :     return bModified;
     205             : }
     206             : 
     207             : 
     208             : 
     209           0 : void OfaMemoryOptionsPage::Reset( const SfxItemSet* rSet )
     210             : {
     211             :     const SfxPoolItem*  pItem;
     212             : 
     213           0 :     m_pUndoEdit->SetValue(officecfg::Office::Common::Undo::Steps::get());
     214           0 :     m_pUndoEdit->SaveValue();
     215             : 
     216             :     // GraphicCache
     217             :     long n =
     218           0 :         officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::get();
     219           0 :     SetNfGraphicCacheVal( n );
     220             :     SetNfGraphicObjectCacheVal(
     221             :         std::min(
     222           0 :             GetNfGraphicCacheVal(),
     223             :             (officecfg::Office::Common::Cache::GraphicManager::ObjectCacheSize::
     224           0 :              get())));
     225             : 
     226             :     sal_Int32 nTime =
     227             :         officecfg::Office::Common::Cache::GraphicManager::ObjectReleaseTime::
     228           0 :         get();
     229           0 :     tools::Time aTime( (sal_uInt16)( nTime / 3600 ), (sal_uInt16)( ( nTime % 3600 ) / 60 ), (sal_uInt16)( ( nTime % 3600 ) % 60 ) );
     230           0 :     m_pTfGraphicObjectTime->SetTime( aTime );
     231             : 
     232           0 :     GraphicCacheConfigHdl(m_pNfGraphicCache);
     233             : 
     234             :     // OLECache
     235             :     m_pNfOLECache->SetValue(
     236             :         std::max(
     237           0 :             officecfg::Office::Common::Cache::Writer::OLE_Objects::get(),
     238             :             (officecfg::Office::Common::Cache::DrawingEngine::OLE_Objects::
     239           0 :              get())));
     240             : 
     241           0 :     SfxItemState eState = rSet->GetItemState( SID_ATTR_QUICKLAUNCHER, false, &pItem );
     242           0 :     if ( SfxItemState::SET == eState )
     243           0 :         m_pQuickLaunchCB->Check( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
     244           0 :     else if ( SfxItemState::DISABLED == eState )
     245             :     {
     246             :         // quickstart not installed
     247           0 :         m_pQuickStarterFrame->Hide();
     248             :     }
     249             : 
     250           0 :     m_pQuickLaunchCB->SaveValue();
     251           0 : }
     252             : 
     253             : 
     254             : 
     255           0 : IMPL_LINK_NOARG(OfaMemoryOptionsPage, GraphicCacheConfigHdl)
     256             : {
     257           0 :     sal_Int32 n = GetNfGraphicCacheVal();
     258           0 :     SetNfGraphicObjectCacheMax( n );
     259           0 :     SetNfGraphicObjectCacheLast( n );
     260             : 
     261           0 :     if( GetNfGraphicObjectCacheVal() > n )
     262           0 :         SetNfGraphicObjectCacheVal( n );
     263             : 
     264           0 :     return 0;
     265           0 : }
     266             : 
     267             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10