kcmkmailsummary.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qcheckbox.h>
00025 #include <qlayout.h>
00026
00027 #include <dcopref.h>
00028
00029 #include <kaboutdata.h>
00030 #include <kaccelmanager.h>
00031 #include <kapplication.h>
00032 #include <kconfig.h>
00033 #include <kdebug.h>
00034 #include <kdialog.h>
00035 #include <klistview.h>
00036 #include <klocale.h>
00037
00038 #include "kcmkmailsummary.h"
00039
00040 extern "C"
00041 {
00042 KCModule *create_kmailsummary( QWidget *parent, const char * )
00043 {
00044 return new KCMKMailSummary( parent, "kcmkmailsummary" );
00045 }
00046 }
00047
00048 KCMKMailSummary::KCMKMailSummary( QWidget *parent, const char *name )
00049 : KCModule( parent, name )
00050 {
00051 initGUI();
00052
00053 connect( mFolderView, SIGNAL( clicked( QListViewItem* ) ), SLOT( modified() ) );
00054 connect( mFullPath, SIGNAL( toggled( bool ) ), SLOT( modified() ) );
00055
00056 KAcceleratorManager::manage( this );
00057
00058 load();
00059 }
00060
00061 void KCMKMailSummary::modified()
00062 {
00063 emit changed( true );
00064 }
00065
00066 void KCMKMailSummary::initGUI()
00067 {
00068 QVBoxLayout *layout = new QVBoxLayout( this, KDialog::marginHint(),
00069 KDialog::spacingHint() );
00070
00071 mFolderView = new KListView( this );
00072 mFolderView->setRootIsDecorated( true );
00073 mFolderView->setFullWidth( true );
00074
00075 mFolderView->addColumn( i18n( "Summary" ) );
00076
00077 mFullPath = new QCheckBox( i18n( "Show full path for folders" ), this );
00078
00079 layout->addWidget( mFolderView );
00080 layout->addWidget( mFullPath );
00081 }
00082
00083 void KCMKMailSummary::initFolders()
00084 {
00085 DCOPRef kmail( "kmail", "KMailIface" );
00086
00087 QStringList folderList;
00088 kmail.call( "folderList" ).get( folderList );
00089
00090 mFolderView->clear();
00091 mFolderMap.clear();
00092
00093 QStringList::Iterator it;
00094 for ( it = folderList.begin(); it != folderList.end(); ++it ) {
00095 QString displayName;
00096 if ( (*it) == "/Local" )
00097 displayName = i18n( "prefix for local folders", "Local" );
00098 else {
00099 DCOPRef folderRef = kmail.call( "getFolder(QString)", *it );
00100 folderRef.call( "displayName()" ).get( displayName );
00101 }
00102 if ( (*it).contains( '/' ) == 1 ) {
00103 if ( mFolderMap.find( *it ) == mFolderMap.end() )
00104 mFolderMap.insert( *it, new QListViewItem( mFolderView,
00105 displayName ) );
00106 } else {
00107 const int pos = (*it).findRev( '/' );
00108 const QString parentFolder = (*it).left( pos );
00109 mFolderMap.insert( *it,
00110 new QCheckListItem( mFolderMap[ parentFolder ],
00111 displayName,
00112 QCheckListItem::CheckBox ) );
00113 }
00114 }
00115 }
00116
00117 void KCMKMailSummary::loadFolders()
00118 {
00119 KConfig config( "kcmkmailsummaryrc" );
00120 config.setGroup( "General" );
00121
00122 QStringList folders;
00123 if ( !config.hasKey( "ActiveFolders" ) )
00124 folders << "/Local/inbox";
00125 else
00126 folders = config.readListEntry( "ActiveFolders" );
00127
00128 QMap<QString, QListViewItem*>::Iterator it;
00129 for ( it = mFolderMap.begin(); it != mFolderMap.end(); ++it ) {
00130 if ( QCheckListItem *qli = dynamic_cast<QCheckListItem*>( it.data() ) ) {
00131 if ( folders.contains( it.key() ) ) {
00132 qli->setOn( true );
00133 mFolderView->ensureItemVisible( it.data() );
00134 } else {
00135 qli->setOn( false );
00136 }
00137 }
00138 }
00139 mFullPath->setChecked( config.readBoolEntry( "ShowFullPath", false ) );
00140 }
00141
00142 void KCMKMailSummary::storeFolders()
00143 {
00144 KConfig config( "kcmkmailsummaryrc" );
00145 config.setGroup( "General" );
00146
00147 QStringList folders;
00148
00149 QMap<QString, QListViewItem*>::Iterator it;
00150 for ( it = mFolderMap.begin(); it != mFolderMap.end(); ++it )
00151 if ( QCheckListItem *qli = dynamic_cast<QCheckListItem*>( it.data() ) )
00152 if ( qli->isOn() )
00153 folders.append( it.key() );
00154
00155 config.writeEntry( "ActiveFolders", folders );
00156 config.writeEntry( "ShowFullPath", mFullPath->isChecked() );
00157
00158 config.sync();
00159 }
00160
00161 void KCMKMailSummary::load()
00162 {
00163 initFolders();
00164 loadFolders();
00165
00166 emit changed( false );
00167 }
00168
00169 void KCMKMailSummary::save()
00170 {
00171 storeFolders();
00172
00173 emit changed( false );
00174 }
00175
00176 void KCMKMailSummary::defaults()
00177 {
00178 }
00179
00180 const KAboutData* KCMKMailSummary::aboutData() const
00181 {
00182 KAboutData *about = new KAboutData( I18N_NOOP( "kcmkmailsummary" ),
00183 I18N_NOOP( "Mail Summary Configuration Dialog" ),
00184 0, 0, KAboutData::License_GPL,
00185 I18N_NOOP( "(c) 2004 Tobias Koenig" ) );
00186
00187 about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
00188
00189 return about;
00190 }
00191
00192 #include "kcmkmailsummary.moc"
This file is part of the documentation for kontact Library Version 3.3.2.