+
+ // Display a confirmation dialog to confirm deletion.
+
+ long lstAccountsIndex = -1;
+ wxMessageDialog dlgdel(this, wxT("Are you sure you want to delete this account?\r\n\r\nAll data that is stored locally will be removed."), wxT("Delete account"), wxYES_NO | wxICON_EXCLAMATION);
+
+ if (dlgdel.ShowModal() == wxID_YES){
+
+ // Remove the selected item from the accounts list
+ // and mark in the accounts list as deleted (Don't write to
+ // accounts file).
+
+ lstAccountsIndex = lstAccounts->GetNextItem(lstAccountsIndex,
+ wxLIST_NEXT_ALL,
+ wxLIST_STATE_SELECTED);
+
+ bool ContinueAcc = TRUE;
+ wxString AccountDir;
+ wxString AccountType;
+ wxString AccountDirFull;
+ wxString AccountDirDelFull;
+ wxString AccountName;
+ wxString AccName;
+ long itemindex = 0;
+
+ wxString AccFilename = GetAccountsFile();
+
+ wxFileConfig *cfgfile = new wxFileConfig("", "", AccFilename);
+
+ AccName = preferences->accounts.GetAccountName((int)lstAccounts->GetItemData(lstAccountsIndex));
+
+ // Get the account directory name and account type..
+
+ ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex);
+
+ while (ContinueAcc){
+
+ if (AccountName == AccName){
+
+ cfgfile->SetPath(AccountName);
+
+ cfgfile->Read("accountdir", &AccountDir);
+ cfgfile->Read("type", &AccountType);
+
+ break;
+
+ }
+
+ cfgfile->SetPath(wxT("/"));
+ ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex);
+
+ }
+
+ AccountDirFull.Append(AccountDir);
+ AccountDirFull.Append(wxT("."));
+
+ /*if (AccountType == wxT("CalDAV")){
+
+ AccountDirFull.Append(wxT("local"));
+
+ } else */
+
+ if (AccountType == wxT("Local")){
+
+ AccountDirFull.Append(wxT("Local"));
+
+ }/*else {
+
+ AccountDirFull.Append(AccountType.Lower());
+
+ }*/
+
+ lstAccounts->DeleteItem(lstAccountsIndex);
+
+ // Delete the directory that contains the account information.
+
+ if (!AccountDirFull.IsEmpty()){
+
+ AccountDirDelFull.Append(wxString::FromUTF8(getenv("HOME")));
+ AccountDirDelFull.Append(wxT("/.xestiacal/accounts/"));
+ AccountDirDelFull.Append(AccountDirFull);
+
+ wxRmDir(AccountDirDelFull);
+
+ }
+
+ // Delete the account from the configuration file.
+
+ cfgfile->SetPath(wxT("/"));
+ cfgfile->DeleteGroup(AccountName);
+ cfgfile->Flush();
+
+ // Set flag for reloading accounts on window closure.
+
+ *ReloadAccountConfig = TRUE;
+
+ }
+
+ btnAccountModify->Enable(FALSE);
+ btnAccountDelete->Enable(FALSE);
+