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 } 00123 00124 void CachePolicyPage::save( Collection &collection ) 00125 { 00126 int interval = d->mUi->checkInterval->value(); 00127 if ( interval == 0 ) 00128 interval = -1; 00129 00130 int cache = d->mUi->localCacheTimeout->value(); 00131 if ( cache == 0 ) 00132 cache = -1; 00133 00134 CachePolicy policy = collection.cachePolicy(); 00135 policy.setInheritFromParent( d->mUi->inherit->isChecked() ); 00136 policy.setIntervalCheckTime( interval ); 00137 policy.setCacheTimeout( cache ); 00138 policy.setSyncOnDemand( d->mUi->syncOnDemand->isChecked() ); 00139 00140 QStringList localParts = d->mUi->localParts->items(); 00141 00142 // Unless we are in "raw" mode, add "bodies" to the list of message 00143 // parts to keep around locally, if the user selected that, or remove 00144 // it otherwise. In "raw" mode we simple use the values from the list 00145 // view. 00146 if ( d->mUi->stackedWidget->currentWidget() != d->mUi->rawPage ) { 00147 if ( d->mUi->retrieveFullMessages->isChecked() 00148 && !localParts.contains( QLatin1String( "RFC822" ) ) ) { 00149 localParts.append( QLatin1String( "RFC822" ) ); 00150 } else if ( !d->mUi->retrieveFullMessages->isChecked() 00151 && localParts.contains( QLatin1String( "RFC822" ) ) ) { 00152 localParts.removeAll( QLatin1String( "RFC822" ) ); 00153 } 00154 } 00155 00156 policy.setLocalParts( localParts ); 00157 collection.setCachePolicy( policy ); 00158 } 00159 00160 #include "cachepolicypage.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:18:30 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:18:30 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.