kcmkmailsummary.cpp
1/*
2 This file is part of Kontact.
3 Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of TQt, and distribute the resulting executable,
21 without including the source code for TQt in the source distribution.
22*/
23
24#include <tqcheckbox.h>
25#include <tqlayout.h>
26
27#include <dcopref.h>
28
29#include <tdeaboutdata.h>
30#include <tdeaccelmanager.h>
31#include <tdeapplication.h>
32#include <tdeconfig.h>
33#include <kdebug.h>
34#include <kdialog.h>
35#include <tdelistview.h>
36#include <tdelocale.h>
37
38#include "kcmkmailsummary.h"
39
40#include <tdemacros.h>
41
42extern "C"
43{
44 TDE_EXPORT TDECModule *create_kmailsummary( TQWidget *parent, const char * )
45 {
46 return new KCMKMailSummary( parent, "kcmkmailsummary" );
47 }
48}
49
50KCMKMailSummary::KCMKMailSummary( TQWidget *parent, const char *name )
51 : TDECModule( parent, name )
52{
53 initGUI();
54
55 connect( mFolderView, TQ_SIGNAL( clicked( TQListViewItem* ) ), TQ_SLOT( modified() ) );
56 connect( mFullPath, TQ_SIGNAL( toggled( bool ) ), TQ_SLOT( modified() ) );
57
58 TDEAcceleratorManager::manage( this );
59
60 load();
61
62 TDEAboutData *about = new TDEAboutData( I18N_NOOP( "kcmkmailsummary" ),
63 I18N_NOOP( "Mail Summary Configuration Dialog" ),
64 0, 0, TDEAboutData::License_GPL,
65 I18N_NOOP( "(c) 2004 Tobias Koenig" ) );
66
67 about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
68 setAboutData( about );
69}
70
71void KCMKMailSummary::modified()
72{
73 emit changed( true );
74}
75
76void KCMKMailSummary::initGUI()
77{
78 TQVBoxLayout *layout = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
79
80 mFolderView = new TDEListView( this );
81 mFolderView->setRootIsDecorated( true );
82 mFolderView->setFullWidth( true );
83
84 mFolderView->addColumn( i18n( "Summary" ) );
85
86 mFullPath = new TQCheckBox( i18n( "Show full path for folders" ), this );
87
88 layout->addWidget( mFolderView );
89 layout->addWidget( mFullPath );
90}
91
92void KCMKMailSummary::initFolders()
93{
94 DCOPRef kmail( "kmail", "KMailIface" );
95
96 TQStringList folderList;
97 kmail.call( "folderList" ).get( folderList );
98
99 mFolderView->clear();
100 mFolderMap.clear();
101
102 TQStringList::Iterator it;
103 for ( it = folderList.begin(); it != folderList.end(); ++it ) {
104 TQString displayName;
105 if ( (*it) == "/Local" )
106 displayName = i18n( "prefix for local folders", "Local" );
107 else {
108 DCOPRef folderRef = kmail.call( "getFolder(TQString)", *it );
109 folderRef.call( "displayName()" ).get( displayName );
110 }
111 if ( (*it).contains( '/' ) == 1 ) {
112 if ( mFolderMap.find( *it ) == mFolderMap.end() )
113 mFolderMap.insert( *it, new TQListViewItem( mFolderView,
114 displayName ) );
115 } else {
116 const int pos = (*it).findRev( '/' );
117 const TQString parentFolder = (*it).left( pos );
118 mFolderMap.insert( *it,
119 new TQCheckListItem( mFolderMap[ parentFolder ],
120 displayName,
121 TQCheckListItem::CheckBox ) );
122 }
123 }
124}
125
126void KCMKMailSummary::loadFolders()
127{
128 TDEConfig config( "kcmkmailsummaryrc" );
129 config.setGroup( "General" );
130
131 TQStringList folders;
132 if ( !config.hasKey( "ActiveFolders" ) )
133 folders << "/Local/inbox";
134 else
135 folders = config.readListEntry( "ActiveFolders" );
136
137 TQMap<TQString, TQListViewItem*>::Iterator it;
138 for ( it = mFolderMap.begin(); it != mFolderMap.end(); ++it ) {
139 if ( TQCheckListItem *qli = dynamic_cast<TQCheckListItem*>( it.data() ) ) {
140 if ( folders.contains( it.key() ) ) {
141 qli->setOn( true );
142 mFolderView->ensureItemVisible( it.data() );
143 } else {
144 qli->setOn( false );
145 }
146 }
147 }
148 mFullPath->setChecked( config.readBoolEntry( "ShowFullPath", true ) );
149}
150
151void KCMKMailSummary::storeFolders()
152{
153 TDEConfig config( "kcmkmailsummaryrc" );
154 config.setGroup( "General" );
155
156 TQStringList folders;
157
158 TQMap<TQString, TQListViewItem*>::Iterator it;
159 for ( it = mFolderMap.begin(); it != mFolderMap.end(); ++it )
160 if ( TQCheckListItem *qli = dynamic_cast<TQCheckListItem*>( it.data() ) )
161 if ( qli->isOn() )
162 folders.append( it.key() );
163
164 config.writeEntry( "ActiveFolders", folders );
165 config.writeEntry( "ShowFullPath", mFullPath->isChecked() );
166
167 config.sync();
168}
169
170void KCMKMailSummary::load()
171{
172 initFolders();
173 loadFolders();
174
175 emit changed( false );
176}
177
178void KCMKMailSummary::save()
179{
180 storeFolders();
181
182 emit changed( false );
183}
184
185void KCMKMailSummary::defaults()
186{
187 mFullPath->setChecked( true );
188
189 emit changed( true );
190}
191
192#include "kcmkmailsummary.moc"