00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "cachepolicypage.h"
00021
00022 #include <kdeversion.h>
00023
00024 #if KDE_IS_VERSION( 4, 5, 74 )
00025 #include "ui_cachepolicypage.h"
00026 #else
00027 #include "ui_cachepolicypage-45.h"
00028 #endif
00029
00030 #include "cachepolicy.h"
00031 #include "collection.h"
00032 #include "collectionutils_p.h"
00033
00034 using namespace Akonadi;
00035
00036 class CachePolicyPage::Private
00037 {
00038 public:
00039 Private()
00040 : mUi( new Ui::CachePolicyPage )
00041 {
00042 }
00043
00044 ~Private()
00045 {
00046 delete mUi;
00047 }
00048
00049 void slotIntervalValueChanged( int );
00050 void slotCacheValueChanged( int );
00051
00052 Ui::CachePolicyPage* mUi;
00053 };
00054
00055 void CachePolicyPage::Private::slotIntervalValueChanged( int interval )
00056 {
00057 mUi->checkInterval->setSuffix( QLatin1Char( ' ' ) + i18np( "minute", "minutes", interval ) );
00058 }
00059
00060 void CachePolicyPage::Private::slotCacheValueChanged( int interval )
00061 {
00062 mUi->localCacheTimeout->setSuffix( QLatin1Char( ' ' ) + i18np( "minute", "minutes", interval ) );
00063 }
00064
00065 CachePolicyPage::CachePolicyPage( QWidget *parent, GuiMode mode )
00066 : CollectionPropertiesPage( parent ),
00067 d( new Private )
00068 {
00069 setObjectName( QLatin1String( "Akonadi::CachePolicyPage" ) );
00070 setPageTitle( i18n( "Retrieval" ) );
00071
00072 d->mUi->setupUi( this );
00073 connect( d->mUi->checkInterval, SIGNAL( valueChanged( int ) ),
00074 SLOT( slotIntervalValueChanged( int ) ) );
00075 connect( d->mUi->localCacheTimeout, SIGNAL( valueChanged( int ) ),
00076 SLOT( slotCacheValueChanged( int ) ) );
00077
00078 if ( mode == AdvancedMode ) {
00079 d->mUi->stackedWidget->setCurrentWidget( d->mUi->rawPage );
00080 }
00081 }
00082
00083 CachePolicyPage::~CachePolicyPage()
00084 {
00085 delete d;
00086 }
00087
00088 bool Akonadi::CachePolicyPage::canHandle( const Collection &collection ) const
00089 {
00090 return !CollectionUtils::isVirtual( collection );
00091 }
00092
00093 void CachePolicyPage::load( const Collection &collection )
00094 {
00095 const CachePolicy policy = collection.cachePolicy();
00096
00097 int interval = policy.intervalCheckTime();
00098 if ( interval == -1 )
00099 interval = 0;
00100
00101 int cache = policy.cacheTimeout();
00102 if ( cache == -1 )
00103 cache = 0;
00104
00105 d->mUi->inherit->setChecked( policy.inheritFromParent() );
00106 d->mUi->checkInterval->setValue( interval );
00107 d->mUi->localCacheTimeout->setValue( cache );
00108 d->mUi->syncOnDemand->setChecked( policy.syncOnDemand() );
00109 d->mUi->localParts->setItems( policy.localParts() );
00110
00111 const bool fetchBodies = policy.localParts().contains( QLatin1String( "RFC822" ) );
00112 d->mUi->retrieveFullMessages->setChecked( fetchBodies );
00113
00114
00115 d->mUi->retrieveOnlyHeaders->setChecked( !fetchBodies );
00116 }
00117
00118 void CachePolicyPage::save( Collection &collection )
00119 {
00120 int interval = d->mUi->checkInterval->value();
00121 if ( interval == 0 )
00122 interval = -1;
00123
00124 int cache = d->mUi->localCacheTimeout->value();
00125 if ( cache == 0 )
00126 cache = -1;
00127
00128 CachePolicy policy = collection.cachePolicy();
00129 policy.setInheritFromParent( d->mUi->inherit->isChecked() );
00130 policy.setIntervalCheckTime( interval );
00131 policy.setCacheTimeout( cache );
00132 policy.setSyncOnDemand( d->mUi->syncOnDemand->isChecked() );
00133
00134 QStringList localParts = d->mUi->localParts->items();
00135
00136
00137
00138
00139
00140 if ( d->mUi->stackedWidget->currentWidget() != d->mUi->rawPage ) {
00141 if ( d->mUi->retrieveFullMessages->isChecked()
00142 && !localParts.contains( QLatin1String( "RFC822" ) ) ) {
00143 localParts.append( QLatin1String( "RFC822" ) );
00144 } else if ( !d->mUi->retrieveFullMessages->isChecked()
00145 && localParts.contains( QLatin1String( "RFC822" ) ) ) {
00146 localParts.removeAll( QLatin1String( "RFC822" ) );
00147 }
00148 }
00149
00150 policy.setLocalParts( localParts );
00151 collection.setCachePolicy( policy );
00152 }
00153
00154 #include "cachepolicypage.moc"