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
00063
00064 config = KGlobal::config();
00065
00066 }
00067
00068 ConfigAccounts::~ConfigAccounts()
00069 {
00070 }
00071
00072 void ConfigAccounts::load()
00073 {
00074
00075 KConfigGroup* configAcc = new KConfigGroup( config, CONFIG_GROUP_ACCOUNTS );
00076 QStringList accounts = configAcc->readEntry( CONFIG_ENTRY_ACCOUNTS_LIST, QStringList() );
00077
00078
00079 for( QStringList::Iterator it = accounts.begin(); it != accounts.end(); ++it )
00080 {
00081
00082 AccountSetupItem* item = new AccountSetupItem( accountListView, *it );
00083
00084
00085 item->load();
00086
00087 }
00088 }
00089
00090 void ConfigAccounts::save()
00091 {
00092 KConfigGroup grpAccounts = config->group( CONFIG_GROUP_ACCOUNTS );
00093
00094
00095 QStringList oldList = grpAccounts.readEntry( CONFIG_ENTRY_ACCOUNTS_LIST, QStringList() );
00096
00097
00098 for( QStringList::Iterator it = oldList.begin(); it != oldList.end(); ++it )
00099 {
00100 config->deleteGroup( *it );
00101 }
00102
00103
00104
00105 QStringList accounts;
00106 AccountSetupItem* item = NULL;
00107 int index = 0;
00108
00109 do
00110 {
00111 item = (AccountSetupItem*)( accountListView->topLevelItem( index ) );
00112 if( item != NULL )
00113 {
00114 index++;
00115 accounts.append( item->getAccountName() );
00116 }
00117 } while( item != NULL );
00118
00119 grpAccounts.writeEntry( CONFIG_ENTRY_ACCOUNTS_LIST, accounts );
00120
00121
00122 index = 0;
00123 item = NULL;
00124 do
00125 {
00126 item = (AccountSetupItem*)( accountListView->topLevelItem( index ) );
00127 if( item != NULL )
00128 {
00129 index++;
00130 item->save();
00131 }
00132 } while( item != NULL );
00133
00134
00135 config->sync();
00136 }
00137
00138 void ConfigAccounts::defaults()
00139 {
00140 }
00141
00142 void ConfigAccounts::slotChanged( )
00143 {
00144 KCModule::changed();
00145 }
00146
00147 void ConfigAccounts::slotAdd( )
00148 {
00149
00150 QPointer<AccountSetupDialog> dlg = new AccountSetupDialog( this, accountListView, NULL );
00151 int res = dlg->exec();
00152
00153
00154 if( res == KDialog::Accepted )
00155 slotChanged();
00156
00157
00158 delete dlg;
00159 }
00160
00161 void ConfigAccounts::slotEdit( )
00162 {
00163
00164 AccountSetupItem* account = (AccountSetupItem*)( accountListView->currentItem() );
00165
00166
00167 if( account == NULL )
00168 return;
00169
00170
00171 AccountSetupDialog* dlg = new AccountSetupDialog( this, accountListView, account );
00172 int res = dlg->exec();
00173
00174
00175 if( res == KDialog::Accepted )
00176 slotChanged();
00177
00178
00179 delete dlg;
00180 }
00181
00182 void ConfigAccounts::slotRemove( )
00183 {
00184
00185 AccountSetupItem* account = (AccountSetupItem*)( accountListView->currentItem() );
00186
00187
00188 if( account == NULL )
00189 return;
00190
00191
00192 int result = KMessageBox::questionYesNo( this, i18nc( "@info", "Do you really want to remove account <resource>%1</resource>?", account->getAccountName() ) );
00193 if( result == KMessageBox::Yes )
00194 {
00195 delete account;
00196 slotChanged();
00197 }
00198 }
00199
00200