~ubuntu-branches/ubuntu/quantal/kdepimlibs/quantal-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
    Copyright (c) 2008 Volker Krause <vkrause@kde.org>

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This library is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

#include "cachepolicypage.h"

#include "ui_cachepolicypage.h"

#include "cachepolicy.h"
#include "collection.h"
#include "collectionutils_p.h"

using namespace Akonadi;

class CachePolicyPage::Private
{
  public:
    Private()
      : mUi( new Ui::CachePolicyPage )
    {
    }

    ~Private()
    {
      delete mUi;
    }

    void slotIntervalValueChanged( int );
    void slotCacheValueChanged( int );
    void slotRetrievalOptionsGroupBoxDisabled( bool disable );

    Ui::CachePolicyPage* mUi;
};

void CachePolicyPage::Private::slotIntervalValueChanged( int interval )
{
  mUi->checkInterval->setSuffix( QLatin1Char( ' ' ) + i18np( "minute", "minutes", interval ) );
}

void CachePolicyPage::Private::slotCacheValueChanged( int interval )
{
  mUi->localCacheTimeout->setSuffix( QLatin1Char( ' ' ) + i18np( "minute", "minutes", interval ) );
}

void CachePolicyPage::Private::slotRetrievalOptionsGroupBoxDisabled( bool disable )
{
  mUi->retrievalOptionsGroupBox->setDisabled( disable );
  if ( !disable ) {
    mUi->label->setEnabled( mUi->retrieveOnlyHeaders->isChecked() );
    mUi->localCacheTimeout->setEnabled( mUi->retrieveOnlyHeaders->isChecked() );
  }
}


CachePolicyPage::CachePolicyPage( QWidget *parent, GuiMode mode )
  : CollectionPropertiesPage( parent ),
    d( new Private )
{
  setObjectName( QLatin1String( "Akonadi::CachePolicyPage" ) );
  setPageTitle( i18n( "Retrieval" ) );

  d->mUi->setupUi( this );
  connect( d->mUi->checkInterval, SIGNAL(valueChanged(int)),
           SLOT(slotIntervalValueChanged(int)) );
  connect( d->mUi->localCacheTimeout, SIGNAL(valueChanged(int)),
           SLOT(slotCacheValueChanged(int)) );
  connect( d->mUi->inherit, SIGNAL(toggled(bool)),
           SLOT(slotRetrievalOptionsGroupBoxDisabled(bool)));
  if ( mode == AdvancedMode ) {
    d->mUi->stackedWidget->setCurrentWidget( d->mUi->rawPage );
  }
}

CachePolicyPage::~CachePolicyPage()
{
  delete d;
}

bool Akonadi::CachePolicyPage::canHandle( const Collection &collection ) const
{
  return !CollectionUtils::isVirtual( collection );
}

void CachePolicyPage::load( const Collection &collection )
{
  const CachePolicy policy = collection.cachePolicy();

  int interval = policy.intervalCheckTime();
  if ( interval == -1 )
    interval = 0;

  int cache = policy.cacheTimeout();
  if ( cache == -1 )
    cache = 0;

  d->mUi->inherit->setChecked( policy.inheritFromParent() );
  d->mUi->checkInterval->setValue( interval );
  d->mUi->localCacheTimeout->setValue( cache );
  d->mUi->syncOnDemand->setChecked( policy.syncOnDemand() );
  d->mUi->localParts->setItems( policy.localParts() );

  const bool fetchBodies = policy.localParts().contains( QLatin1String( "RFC822" ) );
  d->mUi->retrieveFullMessages->setChecked( fetchBodies );

  //done explicitly to disable/enabled widgets
  d->mUi->retrieveOnlyHeaders->setChecked( !fetchBodies );
  d->mUi->label->setEnabled(!fetchBodies);
  d->mUi->localCacheTimeout->setEnabled(!fetchBodies);
}

void CachePolicyPage::save( Collection &collection )
{
  int interval = d->mUi->checkInterval->value();
  if ( interval == 0 )
    interval = -1;

  int cache = d->mUi->localCacheTimeout->value();
  if ( cache == 0 )
    cache = -1;

  CachePolicy policy = collection.cachePolicy();
  policy.setInheritFromParent( d->mUi->inherit->isChecked() );
  policy.setIntervalCheckTime( interval );
  policy.setCacheTimeout( cache );
  policy.setSyncOnDemand( d->mUi->syncOnDemand->isChecked() );

  QStringList localParts = d->mUi->localParts->items();

  // Unless we are in "raw" mode, add "bodies" to the list of message
  // parts to keep around locally, if the user selected that, or remove
  // it otherwise. In "raw" mode we simple use the values from the list
  // view.
  if ( d->mUi->stackedWidget->currentWidget() != d->mUi->rawPage ) {
    if ( d->mUi->retrieveFullMessages->isChecked()
         && !localParts.contains( QLatin1String( "RFC822" ) ) ) {
        localParts.append( QLatin1String( "RFC822" ) );
    } else if ( !d->mUi->retrieveFullMessages->isChecked()
         && localParts.contains( QLatin1String( "RFC822" ) ) ) {
      localParts.removeAll( QLatin1String( "RFC822" )  );
    }
  }

  policy.setLocalParts( localParts );
  collection.setCachePolicy( policy );
}

#include "cachepolicypage.moc"