The last part of typo fixes (I really hope)
[kdepim.git] / kmail / collectionviewpage.cpp
blob96dce47d19b8fd5f8d7654b6d8dce552f899ade4
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 This file is part of KMail, the KDE mail client.
3 Copyright (c) 2009 Montel Laurent <montel@kde.org>
5 KMail is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License, version 2, as
7 published by the Free Software Foundation.
9 KMail is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "collectionviewpage.h"
21 #include "kmkernel.h"
22 #include "mailkernel.h"
24 #include <akonadi/collection.h>
25 #include <akonadi/entitydisplayattribute.h>
26 #include <akonadi/kmime/messagefolderattribute.h>
28 #include <QGroupBox>
29 #include <QHBoxLayout>
30 #include <kicondialog.h>
31 #include <QLabel>
32 #include <QCheckBox>
33 #include <QVBoxLayout>
34 #include <KLocale>
35 #include <KDialog>
38 #include "messagelist/utils/aggregationcombobox.h"
39 #include "messagelist/utils/aggregationconfigbutton.h"
40 #include "messagelist/utils/themecombobox.h"
41 #include "messagelist/utils/themeconfigbutton.h"
43 #include "foldercollection.h"
45 using namespace MailCommon;
47 CollectionViewPage::CollectionViewPage(QWidget * parent) :
48 CollectionPropertiesPage( parent ), mFolderCollection( 0 )
50 setObjectName( QLatin1String( "KMail::CollectionViewPage" ) );
51 setPageTitle( i18nc( "@title:tab View settings for a folder.", "View" ) );
54 CollectionViewPage::~CollectionViewPage()
58 void CollectionViewPage::init(const Akonadi::Collection & col)
60 mCurrentCollection = col;
61 mFolderCollection = FolderCollection::forCollection( col );
62 mIsLocalSystemFolder = CommonKernel->isSystemFolderCollection( col ) || mFolderCollection->isStructural();
64 QVBoxLayout * topLayout = new QVBoxLayout( this );
65 topLayout->setSpacing( KDialog::spacingHint() );
66 topLayout->setMargin( KDialog::marginHint() );
67 // Musn't be able to edit details for non-resource, system folder.
68 if ( !mIsLocalSystemFolder )
70 // icons
71 mIconsCheckBox = new QCheckBox( i18n( "Use custom &icons"), this );
72 mIconsCheckBox->setChecked( false );
74 mNormalIconLabel = new QLabel( i18nc( "Icon used for folders with no unread messages.", "&Normal:" ), this );
75 mNormalIconLabel->setEnabled( false );
77 mNormalIconButton = new KIconButton( this );
78 mNormalIconLabel->setBuddy( mNormalIconButton );
79 mNormalIconButton->setIconType( KIconLoader::NoGroup, KIconLoader::Place, false );
80 mNormalIconButton->setIconSize( 16 );
81 mNormalIconButton->setStrictIconSize( true );
82 mNormalIconButton->setFixedSize( 28, 28 );
83 // Can't use iconset here.
84 mNormalIconButton->setIcon( "folder" );
85 mNormalIconButton->setEnabled( false );
87 mUnreadIconLabel = new QLabel( i18nc( "Icon used for folders which do have unread messages.", "&Unread:" ), this );
88 mUnreadIconLabel->setEnabled( false );
90 mUnreadIconButton = new KIconButton( this );
91 mUnreadIconLabel->setBuddy( mUnreadIconButton );
92 mUnreadIconButton->setIconType( KIconLoader::NoGroup, KIconLoader::Place, false );
93 mUnreadIconButton->setIconSize( 16 );
94 mUnreadIconButton->setStrictIconSize( true );
95 mUnreadIconButton->setFixedSize( 28, 28 );
96 // Can't use iconset here.
97 mUnreadIconButton->setIcon( "folder-open" );
98 mUnreadIconButton->setEnabled( false );
100 QHBoxLayout * iconHLayout = new QHBoxLayout();
101 iconHLayout->addWidget( mIconsCheckBox );
102 iconHLayout->addStretch( 2 );
103 iconHLayout->addWidget( mNormalIconLabel );
104 iconHLayout->addWidget( mNormalIconButton );
105 iconHLayout->addWidget( mUnreadIconLabel );
106 iconHLayout->addWidget( mUnreadIconButton );
107 iconHLayout->addStretch( 1 );
108 topLayout->addLayout( iconHLayout );
110 connect( mIconsCheckBox, SIGNAL( toggled( bool ) ),
111 mNormalIconLabel, SLOT( setEnabled( bool ) ) );
112 connect( mIconsCheckBox, SIGNAL( toggled( bool ) ),
113 mNormalIconButton, SLOT( setEnabled( bool ) ) );
114 connect( mIconsCheckBox, SIGNAL( toggled( bool ) ),
115 mUnreadIconButton, SLOT( setEnabled( bool ) ) );
116 connect( mIconsCheckBox, SIGNAL( toggled( bool ) ),
117 mUnreadIconLabel, SLOT( setEnabled( bool ) ) );
119 connect( mNormalIconButton, SIGNAL( iconChanged( const QString& ) ),
120 this, SLOT( slotChangeIcon( const QString& ) ) );
123 // sender or receiver column
124 const QString senderReceiverColumnTip = i18n( "Show Sender/Receiver Column in List of Messages" );
126 QLabel * senderReceiverColumnLabel = new QLabel( i18n( "Sho&w column:" ), this );
127 mShowSenderReceiverComboBox = new KComboBox( this );
128 mShowSenderReceiverComboBox->setToolTip( senderReceiverColumnTip );
129 senderReceiverColumnLabel->setBuddy( mShowSenderReceiverComboBox );
130 mShowSenderReceiverComboBox->insertItem( 0, i18nc( "@item:inlistbox Show default value.", "Default" ) );
131 mShowSenderReceiverComboBox->insertItem( 1, i18nc( "@item:inlistbox Show sender.", "Sender" ) );
132 mShowSenderReceiverComboBox->insertItem( 2, i18nc( "@item:inlistbox Show receiver.", "Receiver" ) );
134 QHBoxLayout * senderReceiverColumnHLayout = new QHBoxLayout();
135 senderReceiverColumnHLayout->addWidget( senderReceiverColumnLabel );
136 senderReceiverColumnHLayout->addWidget( mShowSenderReceiverComboBox );
137 topLayout->addLayout( senderReceiverColumnHLayout );
139 // message list
140 QGroupBox * messageListGroup = new QGroupBox( i18n( "Message List" ), this );
141 QVBoxLayout * messageListGroupLayout = new QVBoxLayout( messageListGroup );
142 messageListGroupLayout->setSpacing( KDialog::spacingHint() );
143 messageListGroupLayout->setMargin( KDialog::marginHint() );
144 topLayout->addWidget( messageListGroup );
146 // message list aggregation
147 mUseDefaultAggregationCheckBox = new QCheckBox( i18n( "Use default aggregation" ), messageListGroup );
148 messageListGroupLayout->addWidget( mUseDefaultAggregationCheckBox );
149 connect( mUseDefaultAggregationCheckBox, SIGNAL( stateChanged( int ) ),
150 this, SLOT( slotAggregationCheckboxChanged() ) );
152 mAggregationComboBox = new MessageList::Utils::AggregationComboBox( messageListGroup );
154 QLabel * aggregationLabel = new QLabel( i18n( "Aggregation" ), messageListGroup );
155 aggregationLabel->setBuddy( mAggregationComboBox );
157 using MessageList::Utils::AggregationConfigButton;
158 AggregationConfigButton * aggregationConfigButton = new AggregationConfigButton( messageListGroup, mAggregationComboBox );
159 // Make sure any changes made in the aggregations configure dialog are reflected in the combo.
160 connect( aggregationConfigButton, SIGNAL( configureDialogCompleted() ),
161 this, SLOT( slotSelectFolderAggregation() ) );
163 QHBoxLayout * aggregationLayout = new QHBoxLayout();
164 aggregationLayout->addWidget( aggregationLabel, 1 );
165 aggregationLayout->addWidget( mAggregationComboBox, 1 );
166 aggregationLayout->addWidget( aggregationConfigButton, 0 );
167 messageListGroupLayout->addLayout( aggregationLayout );
169 // message list theme
170 mUseDefaultThemeCheckBox = new QCheckBox( i18n( "Use default theme" ), messageListGroup );
171 messageListGroupLayout->addWidget( mUseDefaultThemeCheckBox );
172 connect( mUseDefaultThemeCheckBox, SIGNAL( stateChanged( int ) ),
173 this, SLOT( slotThemeCheckboxChanged() ) );
175 mThemeComboBox = new MessageList::Utils::ThemeComboBox( messageListGroup );
177 QLabel * themeLabel = new QLabel( i18n( "Theme" ), messageListGroup );
178 themeLabel->setBuddy( mThemeComboBox );
180 using MessageList::Utils::ThemeConfigButton;
181 ThemeConfigButton * themeConfigButton = new ThemeConfigButton( messageListGroup, mThemeComboBox );
182 // Make sure any changes made in the themes configure dialog are reflected in the combo.
183 connect( themeConfigButton, SIGNAL( configureDialogCompleted() ),
184 this, SLOT( slotSelectFolderTheme() ) );
186 QHBoxLayout * themeLayout = new QHBoxLayout();
187 themeLayout->addWidget( themeLabel, 1 );
188 themeLayout->addWidget( mThemeComboBox, 1 );
189 themeLayout->addWidget( themeConfigButton, 0 );
190 messageListGroupLayout->addLayout( themeLayout );
192 topLayout->addStretch( 100 );
197 void CollectionViewPage::slotChangeIcon( const QString & icon )
199 mUnreadIconButton->setIcon( icon );
202 void CollectionViewPage::slotAggregationCheckboxChanged()
204 mAggregationComboBox->setEnabled( !mUseDefaultAggregationCheckBox->isChecked() );
207 void CollectionViewPage::slotThemeCheckboxChanged()
209 mThemeComboBox->setEnabled( !mUseDefaultThemeCheckBox->isChecked() );
212 void CollectionViewPage::slotSelectFolderAggregation()
214 bool usesPrivateAggregation = false;
215 mAggregationComboBox->readStorageModelConfig(mCurrentCollection, usesPrivateAggregation );
216 mUseDefaultAggregationCheckBox->setChecked( !usesPrivateAggregation );
219 void CollectionViewPage::slotSelectFolderTheme()
221 bool usesPrivateTheme = false;
222 mThemeComboBox->readStorageModelConfig( mCurrentCollection, usesPrivateTheme );
223 mUseDefaultThemeCheckBox->setChecked( !usesPrivateTheme );
226 void CollectionViewPage::load( const Akonadi::Collection & col )
228 init( col );
229 if ( !mIsLocalSystemFolder ) {
230 QString iconName;
231 QString unreadIconName;
232 bool iconWasEmpty = false;
233 if ( col.hasAttribute<Akonadi::EntityDisplayAttribute>() ) {
234 iconName = col.attribute<Akonadi::EntityDisplayAttribute>()->iconName();
235 unreadIconName = col.attribute<Akonadi::EntityDisplayAttribute>()->activeIconName();
238 if ( iconName.isEmpty() ) {
239 iconName = QLatin1String( "folder" );
240 iconWasEmpty = true;
242 mNormalIconButton->setIcon( iconName );
244 if ( unreadIconName.isEmpty() ) {
245 mUnreadIconButton->setIcon( iconName );
247 else {
248 mUnreadIconButton->setIcon( unreadIconName );
251 mIconsCheckBox->setChecked( !iconWasEmpty );
254 if ( col.hasAttribute<Akonadi::MessageFolderAttribute>() ) {
255 const bool outboundFolder = col.attribute<Akonadi::MessageFolderAttribute>()->isOutboundFolder();
256 if ( outboundFolder )
257 mShowSenderReceiverComboBox->setCurrentIndex( 2 );
258 else
259 mShowSenderReceiverComboBox->setCurrentIndex( 1 );
260 } else {
261 mShowSenderReceiverComboBox->setCurrentIndex( 0 );
263 mShowSenderReceiverValue = mShowSenderReceiverComboBox->currentIndex();
265 // message list aggregation
266 slotSelectFolderAggregation();
268 // message list theme
269 slotSelectFolderTheme();
272 void CollectionViewPage::save( Akonadi::Collection & col )
274 if ( !mIsLocalSystemFolder ) {
275 if ( mIconsCheckBox->isChecked() ) {
276 col.attribute<Akonadi::EntityDisplayAttribute>( Akonadi::Collection::AddIfMissing )->setIconName( mNormalIconButton->icon() );
277 col.attribute<Akonadi::EntityDisplayAttribute>( Akonadi::Collection::AddIfMissing )->setActiveIconName( mUnreadIconButton->icon() );
279 else if ( col.hasAttribute<Akonadi::EntityDisplayAttribute>() ) {
280 col.attribute<Akonadi::EntityDisplayAttribute>()->setIconName( QString() );
281 col.attribute<Akonadi::EntityDisplayAttribute>()->setActiveIconName( QString() );
285 const int currentIndex = mShowSenderReceiverComboBox->currentIndex();
286 if ( mShowSenderReceiverValue != currentIndex ) {
287 if ( currentIndex == 1 ) {
288 Akonadi::MessageFolderAttribute *messageFolder = col.attribute<Akonadi::MessageFolderAttribute>( Akonadi::Entity::AddIfMissing );
289 messageFolder->setOutboundFolder( false );
290 } else if ( currentIndex == 2 ) {
291 Akonadi::MessageFolderAttribute *messageFolder = col.attribute<Akonadi::MessageFolderAttribute>( Akonadi::Entity::AddIfMissing );
292 messageFolder->setOutboundFolder( true );
293 } else {
294 col.removeAttribute<Akonadi::MessageFolderAttribute>();
297 // message list theme
298 const bool usePrivateTheme = !mUseDefaultThemeCheckBox->isChecked();
299 mThemeComboBox->writeStorageModelConfig( mCurrentCollection, usePrivateTheme );
300 // message list aggregation
301 const bool usePrivateAggregation = !mUseDefaultAggregationCheckBox->isChecked();
302 mAggregationComboBox->writeStorageModelConfig( mCurrentCollection, usePrivateAggregation );