• 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
themecombobox.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 "themecombobox.h"
20 
21 #include "messagelist/utils/themecombobox.h"
22 #include "messagelist/utils/themecombobox_p.h"
23 #include "messagelist/storagemodel.h"
24 #include "messagelist/core/manager.h"
25 #include "messagelist/core/theme.h"
26 #include "messagelist/core/settings.h"
27 
28 #include <KDE/KGlobal>
29 
30 using namespace MessageList::Core;
31 using namespace MessageList::Utils;
32 
33 ThemeComboBox::ThemeComboBox( QWidget * parent )
34  : KComboBox( parent ), d( new ThemeComboBoxPrivate( this ) )
35 {
36  if( Manager::instance() )
37  d->slotLoadThemes();
38  else
39  setEnabled(false);
40 }
41 
42 ThemeComboBox::~ThemeComboBox()
43 {
44  delete d;
45 }
46 
47 QString ThemeComboBox::currentTheme() const
48 {
49  return itemData( currentIndex() ).toString();
50 }
51 
52 void ThemeComboBox::writeDefaultConfig() const
53 {
54  KConfigGroup group( Settings::self()->config(), "MessageListView::StorageModelThemes" );
55 
56  const QString themeID = currentTheme();
57  group.writeEntry( QLatin1String( "DefaultSet" ), themeID );
58  if (Manager::instance())
59  Manager::instance()->themesConfigurationCompleted();
60 }
61 
62 void ThemeComboBox::writeStorageModelConfig( const Akonadi::Collection &col, bool isPrivateSetting ) const
63 {
64  if ( col.isValid() )
65  writeStorageModelConfig( QString::number( col.id() ), isPrivateSetting );
66 }
67 
68 void ThemeComboBox::writeStorageModelConfig( MessageList::Core::StorageModel *storageModel, bool isPrivateSetting ) const
69 {
70  writeStorageModelConfig( storageModel->id(), isPrivateSetting );
71 }
72 
73 void ThemeComboBox::writeStorageModelConfig( const QString &id, bool isPrivateSetting )const
74 {
75  if (Manager::instance()) {
76  QString themeID;
77  if ( isPrivateSetting ) {
78  themeID = currentTheme();
79  } else { // explicitly use default theme id when using default theme.
80  themeID = Manager::instance()->defaultTheme()->id();
81  }
82  Manager::instance()->saveThemeForStorageModel( id, themeID, isPrivateSetting );
83  Manager::instance()->themesConfigurationCompleted();
84  }
85 }
86 
87 
88 void ThemeComboBox::readStorageModelConfig( const Akonadi::Collection& col, bool &isPrivateSetting )
89 {
90  if (Manager::instance()) {
91  const Theme *theme = Manager::instance()->themeForStorageModel( col, &isPrivateSetting );
92  d->setCurrentTheme( theme );
93  }
94 }
95 
96 void ThemeComboBox::readStorageModelConfig( MessageList::Core::StorageModel *storageModel, bool &isPrivateSetting )
97 {
98  if (Manager::instance()) {
99  const Theme *theme = Manager::instance()->themeForStorageModel( storageModel, &isPrivateSetting );
100  d->setCurrentTheme( theme );
101  }
102 }
103 
104 void ThemeComboBox::selectDefault()
105 {
106  if (Manager::instance()) {
107  const Theme *defaultTheme = Manager::instance()->defaultTheme();
108  d->setCurrentTheme( defaultTheme );
109  }
110 }
111 
112 void ThemeComboBoxPrivate::slotLoadThemes()
113 {
114  if (!Manager::instance())
115  return;
116  q->clear();
117 
118  // Get all message list themes and sort them into alphabetical order.
119  QList< Theme * > themes = Manager::instance()->themes().values();
120  qSort( themes.begin(), themes.end(), MessageList::Core::Theme::compareName );
121 
122  foreach( const Theme * theme, themes )
123  {
124  q->addItem( theme->name(), QVariant( theme->id() ) );
125  }
126 }
127 
128 void ThemeComboBoxPrivate::setCurrentTheme( const Theme *theme )
129 {
130  Q_ASSERT( theme != 0 );
131 
132  const QString themeID = theme->id();
133  const int themeIndex = q->findData( QVariant( themeID ) );
134  q->setCurrentIndex( themeIndex );
135 }
136 
137 #include "moc_themecombobox.cpp"
QWidget
themecombobox_p.h
MessageList::Core::OptionSet::id
const QString & id() const
Returns the unique id of this OptionSet.
Definition: optionset.h:66
MessageList::Utils::ThemeComboBox::currentTheme
QString currentTheme() const
Definition: themecombobox.cpp:47
MessageList::Core::StorageModel::id
virtual QString id() const =0
Returns an unique id for this Storage collection.
MessageList::Utils::ThemeComboBoxPrivate::q
ThemeComboBox *const q
Definition: themecombobox_p.h:44
theme.h
themecombobox.h
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::ThemeComboBoxPrivate::setCurrentTheme
void setCurrentTheme(const Core::Theme *theme)
Definition: themecombobox.cpp:128
MessageList::Utils::ThemeComboBoxPrivate
Definition: themecombobox_p.h:38
QString
QList
manager.h
QList::end
iterator end()
MessageList::Utils::ThemeComboBox::writeDefaultConfig
void writeDefaultConfig() const
Definition: themecombobox.cpp:52
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::ThemeComboBox::writeStorageModelConfig
void writeStorageModelConfig(MessageList::Core::StorageModel *storageModel, bool isPrivateSetting) const
Definition: themecombobox.cpp:68
QLatin1String
MessageList::Core::Theme::compareName
static bool compareName(Theme *theme1, Theme *theme2)
Definition: theme.h:873
KComboBox
MessageList::Core::Theme
The Theme class defines the visual appearance of the MessageList.
Definition: theme.h:65
MessageList::Utils::ThemeComboBox::readStorageModelConfig
void readStorageModelConfig(const Akonadi::Collection &col, bool &isPrivateSetting)
Definition: themecombobox.cpp:88
QList::begin
iterator begin()
MessageList::Utils::ThemeComboBox::~ThemeComboBox
~ThemeComboBox()
Definition: themecombobox.cpp:42
MessageList::Utils::ThemeComboBoxPrivate::slotLoadThemes
void slotLoadThemes()
Refresh list of themes in the combobox.
Definition: themecombobox.cpp:112
MessageList::Utils::ThemeComboBox::selectDefault
void selectDefault()
Definition: themecombobox.cpp:104
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