~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/libkdepim-copy/uistatesaver.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Harald Sitter
  • Date: 2009-06-27 04:40:05 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090627044005-4y2vm9xz7rvmzi4p
Tags: 4:4.2.95svn20090701-0ubuntu1
[ Alessandro Ghersi ]
* New upstream release
  - Bump build-deps
* Remove akonadi-kde and libmaildir4 packages
  - remove akonadi-kde.install and libmaildir4.install
  - remove libmaildir4 from debian/rules
  - remove akonadi-kde and libmaildir4 from depends
  - remove akonadi-kde and libmaildir4 from installgen
* Update kdepim-dev.install
* Update kpilot.install
* Add akonadi-kde and libmaildir4 transitional packages

[ Harald Sitter ]
* KAddressbook replaces Kontact << 4.2.85 (LP: #378373)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2008 Volker Krause <vkrause@kde.org>
 
3
 
 
4
    This library is free software; you can redistribute it and/or modify it
 
5
    under the terms of the GNU Library General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or (at your
 
7
    option) any later version.
 
8
 
 
9
    This library is distributed in the hope that it will be useful, but WITHOUT
 
10
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
11
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
 
12
    License for more details.
 
13
 
 
14
    You should have received a copy of the GNU Library General Public License
 
15
    along with this library; see the file COPYING.LIB.  If not, write to the
 
16
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
17
    02110-1301, USA.
 
18
*/
 
19
 
 
20
#include "uistatesaver.h"
 
21
 
 
22
#include <KConfigGroup>
 
23
#include <KDebug>
 
24
 
 
25
#include <QComboBox>
 
26
#include <QHeaderView>
 
27
#include <QSplitter>
 
28
#include <QTabWidget>
 
29
#include <QTreeView>
 
30
 
 
31
using namespace KPIM;
 
32
 
 
33
struct Saver {
 
34
  static void process( QSplitter *splitter, KConfigGroup &config )
 
35
  {
 
36
    if ( splitter->sizes().count( 0 ) == splitter->sizes().count() )
 
37
      return;
 
38
    config.writeEntry( splitter->objectName(), splitter->sizes() );
 
39
  }
 
40
 
 
41
  static void process( QTabWidget *tab, KConfigGroup &config )
 
42
  {
 
43
    config.writeEntry( tab->objectName(), tab->currentIndex() );
 
44
  }
 
45
 
 
46
  static void process( QTreeView *tv, KConfigGroup &config )
 
47
  {
 
48
    config.writeEntry( tv->objectName(), tv->header()->saveState() );
 
49
  }
 
50
 
 
51
  static void process( QComboBox *cb, KConfigGroup &config )
 
52
  {
 
53
    config.writeEntry( cb->objectName(), cb->currentIndex() );
 
54
  }
 
55
};
 
56
 
 
57
struct Restorer {
 
58
  static void process( QSplitter *splitter, const KConfigGroup &config )
 
59
  {
 
60
    const QList<int> sizes = config.readEntry( splitter->objectName(), QList<int>() );
 
61
    if ( !sizes.isEmpty() && splitter->count() == sizes.count() && sizes.count() != sizes.count( 0 ) )
 
62
      splitter->setSizes( sizes );
 
63
  }
 
64
 
 
65
  static void process( QTabWidget *tab, const KConfigGroup &config )
 
66
  {
 
67
    const int index = config.readEntry( tab->objectName(), -1 );
 
68
    if ( index >= 0 && index < tab->count() )
 
69
      tab->setCurrentIndex( index );
 
70
  }
 
71
 
 
72
  static void process( QTreeView *tv, const KConfigGroup &config )
 
73
  {
 
74
    const QByteArray state = config.readEntry( tv->objectName(), QByteArray() );
 
75
    if ( !state.isEmpty() )
 
76
      tv->header()->restoreState( state );
 
77
  }
 
78
 
 
79
  static void process( QComboBox *cb, const KConfigGroup &config )
 
80
  {
 
81
    const int index = config.readEntry( cb->objectName(), -1 );
 
82
    if ( index >= 0 && index < cb->count() )
 
83
      cb->setCurrentIndex( index );
 
84
  }
 
85
};
 
86
 
 
87
#define PROCESS_TYPE( T ) \
 
88
{ \
 
89
  T *obj = qobject_cast<T*>( w ); \
 
90
  if ( obj ) { \
 
91
    Op::process( obj, config ); \
 
92
    continue; \
 
93
  } \
 
94
}
 
95
 
 
96
template <typename Op, typename Config> static void processWidgets( QWidget *widget, Config config )
 
97
{
 
98
  QList<QWidget*> widgets = widget->findChildren<QWidget*>();
 
99
  widgets << widget;
 
100
  foreach ( QWidget* w, widgets ) {
 
101
    if ( w->objectName().isEmpty() )
 
102
      continue;
 
103
    PROCESS_TYPE( QSplitter );
 
104
    PROCESS_TYPE( QTabWidget );
 
105
    PROCESS_TYPE( QTreeView );
 
106
    PROCESS_TYPE( QComboBox );
 
107
  }
 
108
}
 
109
 
 
110
#undef PROCESS_TYPE
 
111
 
 
112
void UiStateSaver::saveState(QWidget * widget, KConfigGroup & config)
 
113
{
 
114
  processWidgets<Saver, KConfigGroup&>( widget, config );
 
115
}
 
116
 
 
117
void UiStateSaver::restoreState(QWidget * widget, const KConfigGroup & config)
 
118
{
 
119
  processWidgets<Restorer, const KConfigGroup&>( widget, config );
 
120
}