• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
  • collectionpage
collectionviewpage.cpp
Go to the documentation of this file.
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>
4 
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.
8 
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.
13 
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
17 */
18 
19 
20 #include "collectionviewpage.h"
21 #include "kmkernel.h"
22 #include "kernel/mailkernel.h"
23 
24 #include <akonadi/collection.h>
25 #include <akonadi/entitydisplayattribute.h>
26 #include <akonadi/kmime/messagefolderattribute.h>
27 
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>
36 
37 
38 #include "messagelist/utils/aggregationcombobox.h"
39 #include "messagelist/utils/aggregationconfigbutton.h"
40 #include "messagelist/utils/themecombobox.h"
41 #include "messagelist/utils/themeconfigbutton.h"
42 
43 #include "foldercollection.h"
44 
45 using namespace MailCommon;
46 
47 CollectionViewPage::CollectionViewPage(QWidget * parent) :
48  CollectionPropertiesPage( parent ), mIsLocalSystemFolder(false)
49 {
50  setObjectName( QLatin1String( "KMail::CollectionViewPage" ) );
51  setPageTitle( i18nc( "@title:tab View settings for a folder.", "View" ) );
52 }
53 
54 CollectionViewPage::~CollectionViewPage()
55 {
56 }
57 
58 void CollectionViewPage::init(const Akonadi::Collection & col)
59 {
60  mCurrentCollection = col;
61  QSharedPointer<FolderCollection> fd = FolderCollection::forCollection( col, false );
62  mIsLocalSystemFolder = CommonKernel->isSystemFolderCollection( col ) || fd->isStructural() || Kernel::folderIsInbox( col, true );
63 
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 ) {
69  // icons
70  mIconsCheckBox = new QCheckBox( i18n( "Use custom &icons"), this );
71  mIconsCheckBox->setChecked( false );
72 
73  mNormalIconLabel = new QLabel( i18nc( "Icon used for folders with no unread messages.", "&Normal:" ), this );
74  mNormalIconLabel->setEnabled( false );
75 
76  mNormalIconButton = new KIconButton( this );
77  mNormalIconLabel->setBuddy( mNormalIconButton );
78  mNormalIconButton->setIconType( KIconLoader::NoGroup, KIconLoader::Place, false );
79  mNormalIconButton->setIconSize( 16 );
80  mNormalIconButton->setStrictIconSize( true );
81  mNormalIconButton->setFixedSize( 28, 28 );
82  // Can't use iconset here.
83  mNormalIconButton->setIcon( QLatin1String("folder") );
84  mNormalIconButton->setEnabled( false );
85 
86  mUnreadIconLabel = new QLabel( i18nc( "Icon used for folders which do have unread messages.", "&Unread:" ), this );
87  mUnreadIconLabel->setEnabled( false );
88 
89  mUnreadIconButton = new KIconButton( this );
90  mUnreadIconLabel->setBuddy( mUnreadIconButton );
91  mUnreadIconButton->setIconType( KIconLoader::NoGroup, KIconLoader::Place, false );
92  mUnreadIconButton->setIconSize( 16 );
93  mUnreadIconButton->setStrictIconSize( true );
94  mUnreadIconButton->setFixedSize( 28, 28 );
95  // Can't use iconset here.
96  mUnreadIconButton->setIcon( QLatin1String("folder-open") );
97  mUnreadIconButton->setEnabled( false );
98 
99  QHBoxLayout * iconHLayout = new QHBoxLayout();
100  iconHLayout->addWidget( mIconsCheckBox );
101  iconHLayout->addStretch( 2 );
102  iconHLayout->addWidget( mNormalIconLabel );
103  iconHLayout->addWidget( mNormalIconButton );
104  iconHLayout->addWidget( mUnreadIconLabel );
105  iconHLayout->addWidget( mUnreadIconButton );
106  iconHLayout->addStretch( 1 );
107  topLayout->addLayout( iconHLayout );
108 
109  connect( mIconsCheckBox, SIGNAL(toggled(bool)),
110  mNormalIconLabel, SLOT(setEnabled(bool)) );
111  connect( mIconsCheckBox, SIGNAL(toggled(bool)),
112  mNormalIconButton, SLOT(setEnabled(bool)) );
113  connect( mIconsCheckBox, SIGNAL(toggled(bool)),
114  mUnreadIconButton, SLOT(setEnabled(bool)) );
115  connect( mIconsCheckBox, SIGNAL(toggled(bool)),
116  mUnreadIconLabel, SLOT(setEnabled(bool)) );
117 
118  connect( mNormalIconButton, SIGNAL(iconChanged(QString)),
119  this, SLOT(slotChangeIcon(QString)) );
120  }
121 
122  // sender or receiver column
123  const QString senderReceiverColumnTip = i18n( "Show Sender/Receiver Column in List of Messages" );
124 
125  QLabel * senderReceiverColumnLabel = new QLabel( i18n( "Sho&w column:" ), this );
126  mShowSenderReceiverComboBox = new KComboBox( this );
127  mShowSenderReceiverComboBox->setToolTip( senderReceiverColumnTip );
128  senderReceiverColumnLabel->setBuddy( mShowSenderReceiverComboBox );
129  mShowSenderReceiverComboBox->insertItem( 0, i18nc( "@item:inlistbox Show default value.", "Default" ) );
130  mShowSenderReceiverComboBox->insertItem( 1, i18nc( "@item:inlistbox Show sender.", "Sender" ) );
131  mShowSenderReceiverComboBox->insertItem( 2, i18nc( "@item:inlistbox Show receiver.", "Receiver" ) );
132 
133  QHBoxLayout * senderReceiverColumnHLayout = new QHBoxLayout();
134  senderReceiverColumnHLayout->addWidget( senderReceiverColumnLabel );
135  senderReceiverColumnHLayout->addWidget( mShowSenderReceiverComboBox );
136  topLayout->addLayout( senderReceiverColumnHLayout );
137 
138  // message list
139  QGroupBox * messageListGroup = new QGroupBox( i18n( "Message List" ), this );
140  QVBoxLayout * messageListGroupLayout = new QVBoxLayout( messageListGroup );
141  messageListGroupLayout->setSpacing( KDialog::spacingHint() );
142  messageListGroupLayout->setMargin( KDialog::marginHint() );
143  topLayout->addWidget( messageListGroup );
144 
145  // message list aggregation
146  mUseDefaultAggregationCheckBox = new QCheckBox( i18n( "Use default aggregation" ), messageListGroup );
147  messageListGroupLayout->addWidget( mUseDefaultAggregationCheckBox );
148  connect( mUseDefaultAggregationCheckBox, SIGNAL(stateChanged(int)),
149  this, SLOT(slotAggregationCheckboxChanged()) );
150 
151  mAggregationComboBox = new MessageList::Utils::AggregationComboBox( messageListGroup );
152 
153  QLabel * aggregationLabel = new QLabel( i18n( "Aggregation" ), messageListGroup );
154  aggregationLabel->setBuddy( mAggregationComboBox );
155 
156  using MessageList::Utils::AggregationConfigButton;
157  AggregationConfigButton * aggregationConfigButton = new AggregationConfigButton( messageListGroup, mAggregationComboBox );
158  // Make sure any changes made in the aggregations configure dialog are reflected in the combo.
159  connect( aggregationConfigButton, SIGNAL(configureDialogCompleted()),
160  this, SLOT(slotSelectFolderAggregation()) );
161 
162  QHBoxLayout * aggregationLayout = new QHBoxLayout();
163  aggregationLayout->addWidget( aggregationLabel, 1 );
164  aggregationLayout->addWidget( mAggregationComboBox, 1 );
165  aggregationLayout->addWidget( aggregationConfigButton, 0 );
166  messageListGroupLayout->addLayout( aggregationLayout );
167 
168  // message list theme
169  mUseDefaultThemeCheckBox = new QCheckBox( i18n( "Use default theme" ), messageListGroup );
170  messageListGroupLayout->addWidget( mUseDefaultThemeCheckBox );
171  connect( mUseDefaultThemeCheckBox, SIGNAL(stateChanged(int)),
172  this, SLOT(slotThemeCheckboxChanged()) );
173 
174  mThemeComboBox = new MessageList::Utils::ThemeComboBox( messageListGroup );
175 
176  QLabel * themeLabel = new QLabel( i18n( "Theme" ), messageListGroup );
177  themeLabel->setBuddy( mThemeComboBox );
178 
179  using MessageList::Utils::ThemeConfigButton;
180  ThemeConfigButton * themeConfigButton = new ThemeConfigButton( messageListGroup, mThemeComboBox );
181  // Make sure any changes made in the themes configure dialog are reflected in the combo.
182  connect( themeConfigButton, SIGNAL(configureDialogCompleted()),
183  this, SLOT(slotSelectFolderTheme()) );
184 
185  QHBoxLayout * themeLayout = new QHBoxLayout();
186  themeLayout->addWidget( themeLabel, 1 );
187  themeLayout->addWidget( mThemeComboBox, 1 );
188  themeLayout->addWidget( themeConfigButton, 0 );
189  messageListGroupLayout->addLayout( themeLayout );
190 
191  topLayout->addStretch( 100 );
192 }
193 
194 
195 void CollectionViewPage::slotChangeIcon( const QString & icon )
196 {
197  mUnreadIconButton->setIcon( icon );
198 }
199 
200 void CollectionViewPage::slotAggregationCheckboxChanged()
201 {
202  mAggregationComboBox->setEnabled( !mUseDefaultAggregationCheckBox->isChecked() );
203 }
204 
205 void CollectionViewPage::slotThemeCheckboxChanged()
206 {
207  mThemeComboBox->setEnabled( !mUseDefaultThemeCheckBox->isChecked() );
208 }
209 
210 void CollectionViewPage::slotSelectFolderAggregation()
211 {
212  bool usesPrivateAggregation = false;
213  mAggregationComboBox->readStorageModelConfig(mCurrentCollection, usesPrivateAggregation );
214  mUseDefaultAggregationCheckBox->setChecked( !usesPrivateAggregation );
215 }
216 
217 void CollectionViewPage::slotSelectFolderTheme()
218 {
219  bool usesPrivateTheme = false;
220  mThemeComboBox->readStorageModelConfig( mCurrentCollection, usesPrivateTheme );
221  mUseDefaultThemeCheckBox->setChecked( !usesPrivateTheme );
222 }
223 
224 void CollectionViewPage::load( const Akonadi::Collection & col )
225 {
226  init( col );
227  if ( !mIsLocalSystemFolder ) {
228  QString iconName;
229  QString unreadIconName;
230  bool iconWasEmpty = false;
231  if ( col.hasAttribute<Akonadi::EntityDisplayAttribute>() ) {
232  iconName = col.attribute<Akonadi::EntityDisplayAttribute>()->iconName();
233  unreadIconName = col.attribute<Akonadi::EntityDisplayAttribute>()->activeIconName();
234  }
235 
236  if ( iconName.isEmpty() ) {
237  iconName = QLatin1String( "folder" );
238  iconWasEmpty = true;
239  }
240  mNormalIconButton->setIcon( iconName );
241 
242  if ( unreadIconName.isEmpty() ) {
243  mUnreadIconButton->setIcon( iconName );
244  }
245  else {
246  mUnreadIconButton->setIcon( unreadIconName );
247  }
248 
249  mIconsCheckBox->setChecked( !iconWasEmpty );
250  }
251 
252  if ( col.hasAttribute<Akonadi::MessageFolderAttribute>() ) {
253  const bool outboundFolder = col.attribute<Akonadi::MessageFolderAttribute>()->isOutboundFolder();
254  if ( outboundFolder )
255  mShowSenderReceiverComboBox->setCurrentIndex( 2 );
256  else
257  mShowSenderReceiverComboBox->setCurrentIndex( 1 );
258  } else {
259  mShowSenderReceiverComboBox->setCurrentIndex( 0 );
260  }
261  mShowSenderReceiverValue = mShowSenderReceiverComboBox->currentIndex();
262 
263  // message list aggregation
264  slotSelectFolderAggregation();
265 
266  // message list theme
267  slotSelectFolderTheme();
268 }
269 
270 void CollectionViewPage::save( Akonadi::Collection & col )
271 {
272  if ( !mIsLocalSystemFolder ) {
273  if ( mIconsCheckBox->isChecked() ) {
274  col.attribute<Akonadi::EntityDisplayAttribute>( Akonadi::Collection::AddIfMissing )->setIconName( mNormalIconButton->icon() );
275  col.attribute<Akonadi::EntityDisplayAttribute>( Akonadi::Collection::AddIfMissing )->setActiveIconName( mUnreadIconButton->icon() );
276  }
277  else if ( col.hasAttribute<Akonadi::EntityDisplayAttribute>() ) {
278  col.attribute<Akonadi::EntityDisplayAttribute>()->setIconName( QString() );
279  col.attribute<Akonadi::EntityDisplayAttribute>()->setActiveIconName( QString() );
280  }
281  }
282 
283  const int currentIndex = mShowSenderReceiverComboBox->currentIndex();
284  if ( mShowSenderReceiverValue != currentIndex ) {
285  if ( currentIndex == 1 ) {
286  Akonadi::MessageFolderAttribute *messageFolder = col.attribute<Akonadi::MessageFolderAttribute>( Akonadi::Entity::AddIfMissing );
287  messageFolder->setOutboundFolder( false );
288  } else if ( currentIndex == 2 ) {
289  Akonadi::MessageFolderAttribute *messageFolder = col.attribute<Akonadi::MessageFolderAttribute>( Akonadi::Entity::AddIfMissing );
290  messageFolder->setOutboundFolder( true );
291  } else {
292  col.removeAttribute<Akonadi::MessageFolderAttribute>();
293  }
294  }
295  // message list theme
296  const bool usePrivateTheme = !mUseDefaultThemeCheckBox->isChecked();
297  mThemeComboBox->writeStorageModelConfig( mCurrentCollection, usePrivateTheme );
298  // message list aggregation
299  const bool usePrivateAggregation = !mUseDefaultAggregationCheckBox->isChecked();
300  mAggregationComboBox->writeStorageModelConfig( mCurrentCollection, usePrivateAggregation );
301 }
302 
303 
304 #include "collectionviewpage.moc"
CollectionViewPage::slotSelectFolderAggregation
void slotSelectFolderAggregation()
Definition: collectionviewpage.cpp:210
QSharedPointer
Definition: collectionmailinglistpage.h:34
QWidget
CollectionViewPage::load
void load(const Akonadi::Collection &col)
Definition: collectionviewpage.cpp:224
CollectionViewPage::save
void save(Akonadi::Collection &col)
Definition: collectionviewpage.cpp:270
CollectionViewPage::slotThemeCheckboxChanged
void slotThemeCheckboxChanged()
Definition: collectionviewpage.cpp:205
CollectionViewPage::CollectionViewPage
CollectionViewPage(QWidget *parent=0)
Definition: collectionviewpage.cpp:47
CollectionViewPage::slotChangeIcon
void slotChangeIcon(const QString &icon)
Definition: collectionviewpage.cpp:195
collectionviewpage.h
kmkernel.h
QLabel
CollectionViewPage::~CollectionViewPage
~CollectionViewPage()
Definition: collectionviewpage.cpp:54
KComboBox
CollectionViewPage::slotSelectFolderTheme
void slotSelectFolderTheme()
Definition: collectionviewpage.cpp:217
CollectionViewPage::slotAggregationCheckboxChanged
void slotAggregationCheckboxChanged()
Definition: collectionviewpage.cpp:200
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal