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

messagelist

  • sources
  • kde-4.14
  • 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  if (Manager::instance())
58  Manager::instance()->aggregationsConfigurationCompleted();
59 }
60 
61 void AggregationComboBox::writeStorageModelConfig( MessageList::Core::StorageModel *storageModel, bool isPrivateSetting ) const
62 {
63  writeStorageModelConfig( storageModel->id(), isPrivateSetting );
64 }
65 
66 void AggregationComboBox::writeStorageModelConfig( const QString &id, bool isPrivateSetting ) const
67 {
68  if (Manager::instance()) {
69  // message list aggregation
70  QString aggregationID;
71  if ( isPrivateSetting ) {
72  aggregationID = currentAggregation();
73  } else { // explicitly use default aggregation id when using default aggregation.
74  aggregationID = Manager::instance()->defaultAggregation()->id();
75  }
76  Manager::instance()->saveAggregationForStorageModel( id, aggregationID, isPrivateSetting );
77  Manager::instance()->aggregationsConfigurationCompleted();
78  }
79 }
80 
81 void AggregationComboBox::writeStorageModelConfig( const Akonadi::Collection&col, bool isPrivateSetting ) const
82 {
83  writeStorageModelConfig( QString::number( col.id() ), isPrivateSetting );
84 }
85 
86 void AggregationComboBox::readStorageModelConfig( const QString & id, bool &isPrivateSetting )
87 {
88  if (Manager::instance()) {
89  const Aggregation *aggregation = Manager::instance()->aggregationForStorageModel( id, &isPrivateSetting );
90  d->setCurrentAggregation( aggregation );
91  }
92 }
93 
94 void AggregationComboBox::readStorageModelConfig( MessageList::Core::StorageModel *storageModel, bool &isPrivateSetting )
95 {
96  readStorageModelConfig( storageModel->id(), isPrivateSetting );
97 }
98 
99 void AggregationComboBox::readStorageModelConfig( const Akonadi::Collection &col, bool &isPrivateSetting )
100 {
101  if ( col.isValid() )
102  readStorageModelConfig( QString::number( col.id() ), isPrivateSetting );
103 }
104 
105 void AggregationComboBox::selectDefault()
106 {
107  if (Manager::instance()) {
108  const Aggregation *defaultAggregation = Manager::instance()->defaultAggregation();
109  d->setCurrentAggregation( defaultAggregation );
110  }
111 }
112 
113 void AggregationComboBoxPrivate::slotLoadAggregations()
114 {
115  if (!Manager::instance())
116  return;
117  q->clear();
118 
119  // Get all message list aggregations and sort them into alphabetical order.
120  QList< Aggregation * > aggregations = Manager::instance()->aggregations().values();
121  qSort( aggregations.begin(), aggregations.end(), MessageList::Core::Aggregation::compareName );
122 
123  foreach( const Aggregation * aggregation, aggregations )
124  {
125  q->addItem( aggregation->name(), QVariant( aggregation->id() ) );
126  }
127 }
128 
129 void AggregationComboBoxPrivate::setCurrentAggregation( const Aggregation *aggregation )
130 {
131  Q_ASSERT( aggregation != 0 );
132 
133  const QString aggregationID = aggregation->id();
134  const int aggregationIndex = q->findData( QVariant( aggregationID ) );
135  q->setCurrentIndex( aggregationIndex );
136 }
137 
138 #include "moc_aggregationcombobox.cpp"
MessageList::Utils::AggregationComboBox::currentAggregation
QString currentAggregation() const
Definition: aggregationcombobox.cpp:45
QWidget
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
MessageList::Utils::AggregationComboBox::readStorageModelConfig
void readStorageModelConfig(MessageList::Core::StorageModel *storageModel, bool &isPrivateSetting)
Definition: aggregationcombobox.cpp:94
MessageList::Core::OptionSet::name
const QString & name() const
Returns the name of this OptionSet.
Definition: optionset.h:72
QString::number
QString number(int n, int base)
storagemodel.h
MessageList::Utils::AggregationComboBoxPrivate::setCurrentAggregation
void setCurrentAggregation(const Core::Aggregation *aggregation)
Definition: aggregationcombobox.cpp:129
QString
aggregation.h
QList
MessageList::Utils::AggregationComboBox::writeStorageModelConfig
void writeStorageModelConfig(MessageList::Core::StorageModel *storageModel, bool isPrivateSetting) const
Definition: aggregationcombobox.cpp:61
manager.h
QList::end
iterator end()
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:105
QLatin1String
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:113
QList::begin
iterator begin()
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:01 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
  • pimprint

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