kcmkmailsummary.cpp
00001 /* 00002 This file is part of Kontact. 00003 Copyright (c) 2004 Tobias Koenig <tokoe@kde.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of TQt, and distribute the resulting executable, 00021 without including the source code for TQt in the source distribution. 00022 */ 00023 00024 #include <tqcheckbox.h> 00025 #include <tqlayout.h> 00026 00027 #include <dcopref.h> 00028 00029 #include <tdeaboutdata.h> 00030 #include <tdeaccelmanager.h> 00031 #include <tdeapplication.h> 00032 #include <tdeconfig.h> 00033 #include <kdebug.h> 00034 #include <kdialog.h> 00035 #include <tdelistview.h> 00036 #include <tdelocale.h> 00037 00038 #include "kcmkmailsummary.h" 00039 00040 #include <tdepimmacros.h> 00041 00042 extern "C" 00043 { 00044 KDE_EXPORT TDECModule *create_kmailsummary( TQWidget *parent, const char * ) 00045 { 00046 return new KCMKMailSummary( parent, "kcmkmailsummary" ); 00047 } 00048 } 00049 00050 KCMKMailSummary::KCMKMailSummary( TQWidget *parent, const char *name ) 00051 : TDECModule( parent, name ) 00052 { 00053 initGUI(); 00054 00055 connect( mFolderView, TQT_SIGNAL( clicked( TQListViewItem* ) ), TQT_SLOT( modified() ) ); 00056 connect( mFullPath, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( modified() ) ); 00057 00058 TDEAcceleratorManager::manage( this ); 00059 00060 load(); 00061 00062 TDEAboutData *about = new TDEAboutData( I18N_NOOP( "kcmkmailsummary" ), 00063 I18N_NOOP( "Mail Summary Configuration Dialog" ), 00064 0, 0, TDEAboutData::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 TQVBoxLayout *layout = new TQVBoxLayout( this, 0, KDialog::spacingHint() ); 00079 00080 mFolderView = new TDEListView( this ); 00081 mFolderView->setRootIsDecorated( true ); 00082 mFolderView->setFullWidth( true ); 00083 00084 mFolderView->addColumn( i18n( "Summary" ) ); 00085 00086 mFullPath = new TQCheckBox( 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 TQStringList folderList; 00097 kmail.call( "folderList" ).get( folderList ); 00098 00099 mFolderView->clear(); 00100 mFolderMap.clear(); 00101 00102 TQStringList::Iterator it; 00103 for ( it = folderList.begin(); it != folderList.end(); ++it ) { 00104 TQString displayName; 00105 if ( (*it) == "/Local" ) 00106 displayName = i18n( "prefix for local folders", "Local" ); 00107 else { 00108 DCOPRef folderRef = kmail.call( "getFolder(TQString)", *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 TQListViewItem( mFolderView, 00114 displayName ) ); 00115 } else { 00116 const int pos = (*it).findRev( '/' ); 00117 const TQString parentFolder = (*it).left( pos ); 00118 mFolderMap.insert( *it, 00119 new TQCheckListItem( mFolderMap[ parentFolder ], 00120 displayName, 00121 TQCheckListItem::CheckBox ) ); 00122 } 00123 } 00124 } 00125 00126 void KCMKMailSummary::loadFolders() 00127 { 00128 TDEConfig config( "kcmkmailsummaryrc" ); 00129 config.setGroup( "General" ); 00130 00131 TQStringList folders; 00132 if ( !config.hasKey( "ActiveFolders" ) ) 00133 folders << "/Local/inbox"; 00134 else 00135 folders = config.readListEntry( "ActiveFolders" ); 00136 00137 TQMap<TQString, TQListViewItem*>::Iterator it; 00138 for ( it = mFolderMap.begin(); it != mFolderMap.end(); ++it ) { 00139 if ( TQCheckListItem *qli = dynamic_cast<TQCheckListItem*>( 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 TDEConfig config( "kcmkmailsummaryrc" ); 00154 config.setGroup( "General" ); 00155 00156 TQStringList folders; 00157 00158 TQMap<TQString, TQListViewItem*>::Iterator it; 00159 for ( it = mFolderMap.begin(); it != mFolderMap.end(); ++it ) 00160 if ( TQCheckListItem *qli = dynamic_cast<TQCheckListItem*>( 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"