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

Generated by: LCOV version 1.10