00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "configaccounts.h"
00019
00020 K_PLUGIN_FACTORY( ConfigAccountsFactory, registerPlugin<ConfigAccounts>(); )
00021 K_EXPORT_PLUGIN( ConfigAccountsFactory( "kcm_kshowmailconfigaccounts" ) )
00022
00023 ConfigAccounts::ConfigAccounts( QWidget * parent, const QVariantList & args )
00024 : KCModule( ConfigAccountsFactory::componentData(), parent, args )
00025 {
00026
00027
00028
00029
00030 QHBoxLayout* layMain = new QHBoxLayout( this );
00031
00032
00033 accountListView = new QTreeWidget( this );
00034 accountListView->setColumnCount( 1 );
00035 accountListView->setHeaderLabels( QStringList( i18nc( "@title:column account name in the main view of the account config dialog", "Name" ) ) );
00036 accountListView->setIndentation( 0 );
00037
00038 layMain->addWidget( accountListView );
00039
00040
00041 QVBoxLayout* layButtons = new QVBoxLayout();
00042 layMain->addLayout( layButtons );
00043
00044
00045 btnAdd = new KPushButton( KStandardGuiItem::add(), this );
00046 layButtons->addWidget( btnAdd );
00047 btnAdd->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
00048 connect( btnAdd, SIGNAL( clicked() ), this, SLOT( slotAdd() ) );
00049
00050 btnEdit = new KPushButton( KStandardGuiItem::configure(), this );
00051 layButtons->addWidget( btnEdit );
00052 btnEdit->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
00053 connect( btnEdit, SIGNAL( clicked() ), this, SLOT( slotEdit() ) );
00054
00055 btnRemove = new KPushButton( KStandardGuiItem::remove(), this );
00056 layButtons->addWidget( btnRemove );
00057 btnRemove->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
00058 connect( btnRemove, SIGNAL( clicked() ), this, SLOT( slotRemove() ) );
00059
00060 layButtons->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
00061
00062 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
00063
00064
00065
00066 config = KGlobal::config();
00067
00068 }
00069
00070 ConfigAccounts::~ConfigAccounts()
00071 {
00072 }
00073
00074 void ConfigAccounts::load()
00075 {
00076
00077 KConfigGroup* configAcc = new KConfigGroup( config, CONFIG_GROUP_ACCOUNTS );
00078 QStringList accounts = configAcc->readEntry( CONFIG_ENTRY_ACCOUNTS_LIST, QStringList() );
00079
00080
00081 for( QStringList::Iterator it = accounts.begin(); it != accounts.end(); ++it )
00082 {
00083
00084 AccountSetupItem* item = new AccountSetupItem( accountListView, *it );
00085
00086
00087 item->load();
00088
00089 }
00090 }
00091
00092 void ConfigAccounts::save()
00093 {
00094 KConfigGroup grpAccounts = config->group( CONFIG_GROUP_ACCOUNTS );
00095
00096
00097 QStringList oldList = grpAccounts.readEntry( CONFIG_ENTRY_ACCOUNTS_LIST, QStringList() );
00098
00099
00100 for( QStringList::Iterator it = oldList.begin(); it != oldList.end(); ++it )
00101 {
00102 config->deleteGroup( *it );
00103 }
00104
00105
00106
00107 QStringList accounts;
00108 AccountSetupItem* item = NULL;
00109 int index = 0;
00110
00111 do
00112 {
00113 item = (AccountSetupItem*)( accountListView->topLevelItem( index ) );
00114 if( item != NULL )
00115 {
00116 index++;
00117 accounts.append( item->getAccountName() );
00118 }
00119 } while( item != NULL );
00120
00121 grpAccounts.writeEntry( CONFIG_ENTRY_ACCOUNTS_LIST, accounts );
00122
00123
00124 index = 0;
00125 item = NULL;
00126 do
00127 {
00128 item = (AccountSetupItem*)( accountListView->topLevelItem( index ) );
00129 if( item != NULL )
00130 {
00131 index++;
00132 item->save();
00133 }
00134 } while( item != NULL );
00135
00136
00137 config->sync();
00138 }
00139
00140 void ConfigAccounts::defaults()
00141 {
00142 }
00143
00144 void ConfigAccounts::slotChanged( )
00145 {
00146 KCModule::changed();
00147 }
00148
00149 void ConfigAccounts::slotAdd( )
00150 {
00151
00152 QPointer<AccountSetupDialog> dlg = new AccountSetupDialog( this, accountListView, NULL );
00153 int res = dlg->exec();
00154
00155
00156 if( res == KDialog::Accepted )
00157 slotChanged();
00158
00159
00160 delete dlg;
00161 }
00162
00163 void ConfigAccounts::slotEdit( )
00164 {
00165
00166 AccountSetupItem* account = (AccountSetupItem*)( accountListView->currentItem() );
00167
00168
00169 if( account == NULL )
00170 return;
00171
00172
00173 AccountSetupDialog* dlg = new AccountSetupDialog( this, accountListView, account );
00174 int res = dlg->exec();
00175
00176
00177 if( res == KDialog::Accepted )
00178 slotChanged();
00179
00180
00181 delete dlg;
00182 }
00183
00184 void ConfigAccounts::slotRemove( )
00185 {
00186
00187 AccountSetupItem* account = (AccountSetupItem*)( accountListView->currentItem() );
00188
00189
00190 if( account == NULL )
00191 return;
00192
00193
00194 int result = KMessageBox::questionYesNo( this, i18nc( "@info", "Do you really want to remove account <resource>%1</resource>?", account->getAccountName() ) );
00195 if( result == KMessageBox::Yes )
00196 {
00197 delete account;
00198 slotChanged();
00199 }
00200 }
00201
00202