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