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

messagelist

  • sources
  • kde-4.12
  • kdepim
  • messagelist
  • utils
aggregationcombobox.cpp
Go to the documentation of this file.
1 /* Copyright 2009 James Bendig <james@imptalk.com>
2 
3  This program is free software; you can redistribute it and/or
4  modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation; either version 2 of
6  the License or (at your option) version 3 or any later version
7  accepted by the membership of KDE e.V. (or its successor approved
8  by the membership of KDE e.V.), which shall act as a proxy
9  defined in Section 14 of version 3 of the license.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "aggregationcombobox.h"
20 #include "aggregationcombobox_p.h"
21 
22 #include "messagelist/core/aggregation.h"
23 #include "messagelist/core/manager.h"
24 #include "messagelist/core/settings.h"
25 #include "messagelist/storagemodel.h"
26 #include <KDE/KGlobal>
27 
28 using namespace MessageList::Core;
29 using namespace MessageList::Utils;
30 
31 AggregationComboBox::AggregationComboBox( QWidget * parent )
32 : KComboBox( parent ), d( new AggregationComboBoxPrivate( this ) )
33 {
34  if( Manager::instance() )
35  d->slotLoadAggregations();
36  else
37  setEnabled(false);
38 }
39 
40 AggregationComboBox::~AggregationComboBox()
41 {
42  delete d;
43 }
44 
45 QString AggregationComboBox::currentAggregation() const
46 {
47  return itemData( currentIndex() ).toString();
48 }
49 
50 void AggregationComboBox::writeDefaultConfig() const
51 {
52  KConfigGroup group( Settings::self()->config(), "MessageListView::StorageModelAggregations" );
53 
54  const QString aggregationID = currentAggregation();
55  group.writeEntry( QLatin1String( "DefaultSet" ), aggregationID );
56 
57  Manager::instance()->aggregationsConfigurationCompleted();
58 }
59 
60 void AggregationComboBox::writeStorageModelConfig( MessageList::Core::StorageModel *storageModel, bool isPrivateSetting ) const
61 {
62  writeStorageModelConfig( storageModel->id(), isPrivateSetting );
63 }
64 
65 void AggregationComboBox::writeStorageModelConfig( const QString &id, bool isPrivateSetting ) const
66 {
67  // message list aggregation
68  QString aggregationID;
69  if ( isPrivateSetting ) {
70  aggregationID = currentAggregation();
71  } else { // explicitly use default aggregation id when using default aggregation.
72  aggregationID = Manager::instance()->defaultAggregation()->id();
73  }
74  Manager::instance()->saveAggregationForStorageModel( id, aggregationID, isPrivateSetting );
75  Manager::instance()->aggregationsConfigurationCompleted();
76 }
77 
78 void AggregationComboBox::writeStorageModelConfig( const Akonadi::Collection&col, bool isPrivateSetting ) const
79 {
80  writeStorageModelConfig( QString::number( col.id() ), isPrivateSetting );
81 }
82 
83 void AggregationComboBox::readStorageModelConfig( const QString & id, bool &isPrivateSetting )
84 {
85  const Aggregation *aggregation = Manager::instance()->aggregationForStorageModel( id, &isPrivateSetting );
86  d->setCurrentAggregation( aggregation );
87 }
88 
89 void AggregationComboBox::readStorageModelConfig( MessageList::Core::StorageModel *storageModel, bool &isPrivateSetting )
90 {
91  readStorageModelConfig( storageModel->id(), isPrivateSetting );
92 }
93 
94 void AggregationComboBox::readStorageModelConfig( const Akonadi::Collection &col, bool &isPrivateSetting )
95 {
96  if ( col.isValid() )
97  readStorageModelConfig( QString::number( col.id() ), isPrivateSetting );
98 }
99 
100 void AggregationComboBox::selectDefault()
101 {
102  const Aggregation *defaultAggregation = Manager::instance()->defaultAggregation();
103  d->setCurrentAggregation( defaultAggregation );
104 }
105 
106 void AggregationComboBoxPrivate::slotLoadAggregations()
107 {
108  q->clear();
109 
110  // Get all message list aggregations and sort them into alphabetical order.
111  QList< Aggregation * > aggregations = Manager::instance()->aggregations().values();
112  qSort( aggregations.begin(), aggregations.end(), MessageList::Core::Aggregation::compareName );
113 
114  foreach( const Aggregation * aggregation, aggregations )
115  {
116  q->addItem( aggregation->name(), QVariant( aggregation->id() ) );
117  }
118 }
119 
120 void AggregationComboBoxPrivate::setCurrentAggregation( const Aggregation *aggregation )
121 {
122  Q_ASSERT( aggregation != 0 );
123 
124  const QString aggregationID = aggregation->id();
125  const int aggregationIndex = q->findData( QVariant( aggregationID ) );
126  q->setCurrentIndex( aggregationIndex );
127 }
128 
129 #include "aggregationcombobox.moc"
MessageList::Utils::AggregationComboBox::currentAggregation
QString currentAggregation() const
Definition: aggregationcombobox.cpp:45
MessageList::Core::Aggregation
A set of aggregation options that can be applied to the MessageList::Model in a single shot...
Definition: aggregation.h:43
MessageList::Core::OptionSet::id
const QString & id() const
Returns the unique id of this OptionSet.
Definition: optionset.h:66
MessageList::Core::Aggregation::compareName
static bool compareName(Aggregation *agg1, Aggregation *agg2)
Definition: aggregation.h:153
MessageList::Core::StorageModel::id
virtual QString id() const =0
Returns an unique id for this Storage collection.
MessageList::Utils::AggregationComboBox::~AggregationComboBox
~AggregationComboBox()
Definition: aggregationcombobox.cpp:40
QWidget
MessageList::Utils::AggregationComboBox::readStorageModelConfig
void readStorageModelConfig(MessageList::Core::StorageModel *storageModel, bool &isPrivateSetting)
Definition: aggregationcombobox.cpp:89
MessageList::Core::OptionSet::name
const QString & name() const
Returns the name of this OptionSet.
Definition: optionset.h:72
storagemodel.h
MessageList::Utils::AggregationComboBoxPrivate::setCurrentAggregation
void setCurrentAggregation(const Core::Aggregation *aggregation)
Definition: aggregationcombobox.cpp:120
aggregation.h
MessageList::Utils::AggregationComboBox::writeStorageModelConfig
void writeStorageModelConfig(MessageList::Core::StorageModel *storageModel, bool isPrivateSetting) const
Definition: aggregationcombobox.cpp:60
manager.h
MessageList::Core::StorageModel
The QAbstractItemModel based interface that you need to provide for your storage to work with Message...
Definition: storagemodelbase.h:45
MessageList::Utils::AggregationComboBox::selectDefault
void selectDefault()
Definition: aggregationcombobox.cpp:100
settings.h
MessageList::Utils::AggregationComboBoxPrivate::q
AggregationComboBox *const q
Definition: aggregationcombobox_p.h:44
KComboBox
aggregationcombobox.h
MessageList::Utils::AggregationComboBoxPrivate
Definition: aggregationcombobox_p.h:38
aggregationcombobox_p.h
MessageList::Utils::AggregationComboBox::writeDefaultConfig
void writeDefaultConfig() const
Definition: aggregationcombobox.cpp:50
MessageList::Utils::AggregationComboBoxPrivate::slotLoadAggregations
void slotLoadAggregations()
Refresh list of aggregations in the combobox.
Definition: aggregationcombobox.cpp:106
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messagelist

Skip menu "messagelist"
  • 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