akonadi
cachepolicypage.cpp
00001 /* 00002 Copyright (c) 2008 Volker Krause <vkrause@kde.org> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 00018 */ 00019 00020 #include "cachepolicypage.h" 00021 00022 #include "ui_cachepolicypage.h" 00023 00024 #include "cachepolicy.h" 00025 #include "collection.h" 00026 #include "collectionutils_p.h" 00027 00028 using namespace Akonadi; 00029 00030 class CachePolicyPage::Private 00031 { 00032 public: 00033 Private() 00034 : mUi( new Ui::CachePolicyPage ) 00035 { 00036 } 00037 00038 ~Private() 00039 { 00040 delete mUi; 00041 } 00042 00043 void slotIntervalValueChanged( int ); 00044 void slotCacheValueChanged( int ); 00045 void slotRetrievalOptionsGroupBoxDisabled( bool disable ); 00046 00047 Ui::CachePolicyPage* mUi; 00048 }; 00049 00050 void CachePolicyPage::Private::slotIntervalValueChanged( int interval ) 00051 { 00052 mUi->checkInterval->setSuffix( QLatin1Char( ' ' ) + i18np( "minute", "minutes", interval ) ); 00053 } 00054 00055 void CachePolicyPage::Private::slotCacheValueChanged( int interval ) 00056 { 00057 mUi->localCacheTimeout->setSuffix( QLatin1Char( ' ' ) + i18np( "minute", "minutes", interval ) ); 00058 } 00059 00060 void CachePolicyPage::Private::slotRetrievalOptionsGroupBoxDisabled( bool disable ) 00061 { 00062 mUi->retrievalOptionsGroupBox->setDisabled( disable ); 00063 if ( !disable ) { 00064 mUi->label->setEnabled( mUi->retrieveOnlyHeaders->isChecked() ); 00065 mUi->localCacheTimeout->setEnabled( mUi->retrieveOnlyHeaders->isChecked() ); 00066 } 00067 } 00068 00069 00070 CachePolicyPage::CachePolicyPage( QWidget *parent, GuiMode mode ) 00071 : CollectionPropertiesPage( parent ), 00072 d( new Private ) 00073 { 00074 setObjectName( QLatin1String( "Akonadi::CachePolicyPage" ) ); 00075 setPageTitle( i18n( "Retrieval" ) ); 00076 00077 d->mUi->setupUi( this ); 00078 connect( d->mUi->checkInterval, SIGNAL(valueChanged(int)), 00079 SLOT(slotIntervalValueChanged(int)) ); 00080 connect( d->mUi->localCacheTimeout, SIGNAL(valueChanged(int)), 00081 SLOT(slotCacheValueChanged(int)) ); 00082 connect( d->mUi->inherit, SIGNAL(toggled(bool)), 00083 SLOT(slotRetrievalOptionsGroupBoxDisabled(bool))); 00084 if ( mode == AdvancedMode ) { 00085 d->mUi->stackedWidget->setCurrentWidget( d->mUi->rawPage ); 00086 } 00087 } 00088 00089 CachePolicyPage::~CachePolicyPage() 00090 { 00091 delete d; 00092 } 00093 00094 bool Akonadi::CachePolicyPage::canHandle( const Collection &collection ) const 00095 { 00096 return !CollectionUtils::isVirtual( collection ); 00097 } 00098 00099 void CachePolicyPage::load( const Collection &collection ) 00100 { 00101 const CachePolicy policy = collection.cachePolicy(); 00102 00103 int interval = policy.intervalCheckTime(); 00104 if ( interval == -1 ) 00105 interval = 0; 00106 00107 int cache = policy.cacheTimeout(); 00108 if ( cache == -1 ) 00109 cache = 0; 00110 00111 d->mUi->inherit->setChecked( policy.inheritFromParent() ); 00112 d->mUi->checkInterval->setValue( interval ); 00113 d->mUi->localCacheTimeout->setValue( cache ); 00114 d->mUi->syncOnDemand->setChecked( policy.syncOnDemand() ); 00115 d->mUi->localParts->setItems( policy.localParts() ); 00116 00117 const bool fetchBodies = policy.localParts().contains( QLatin1String( "RFC822" ) ); 00118 d->mUi->retrieveFullMessages->setChecked( fetchBodies ); 00119 00120 //done explicitly to disable/enabled widgets 00121 d->mUi->retrieveOnlyHeaders->setChecked( !fetchBodies ); 00122 d->mUi->label->setEnabled(!fetchBodies); 00123 d->mUi->localCacheTimeout->setEnabled(!fetchBodies); 00124 } 00125 00126 void CachePolicyPage::save( Collection &collection ) 00127 { 00128 int interval = d->mUi->checkInterval->value(); 00129 if ( interval == 0 ) 00130 interval = -1; 00131 00132 int cache = d->mUi->localCacheTimeout->value(); 00133 if ( cache == 0 ) 00134 cache = -1; 00135 00136 CachePolicy policy = collection.cachePolicy(); 00137 policy.setInheritFromParent( d->mUi->inherit->isChecked() ); 00138 policy.setIntervalCheckTime( interval ); 00139 policy.setCacheTimeout( cache ); 00140 policy.setSyncOnDemand( d->mUi->syncOnDemand->isChecked() ); 00141 00142 QStringList localParts = d->mUi->localParts->items(); 00143 00144 // Unless we are in "raw" mode, add "bodies" to the list of message 00145 // parts to keep around locally, if the user selected that, or remove 00146 // it otherwise. In "raw" mode we simple use the values from the list 00147 // view. 00148 if ( d->mUi->stackedWidget->currentWidget() != d->mUi->rawPage ) { 00149 if ( d->mUi->retrieveFullMessages->isChecked() 00150 && !localParts.contains( QLatin1String( "RFC822" ) ) ) { 00151 localParts.append( QLatin1String( "RFC822" ) ); 00152 } else if ( !d->mUi->retrieveFullMessages->isChecked() 00153 && localParts.contains( QLatin1String( "RFC822" ) ) ) { 00154 localParts.removeAll( QLatin1String( "RFC822" ) ); 00155 } 00156 } 00157 00158 policy.setLocalParts( localParts ); 00159 collection.setCachePolicy( policy ); 00160 } 00161 00162 #include "cachepolicypage.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:17 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:17 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.