// frmEditAccount.cpp - Edit Account form. // // (c) 2012-2015 Xestia Software Development. // // This file is part of Xestia Address Book. // // Xestia Address Book is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Address Book is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Address Book. If not, see #include "frmEditAccount.h" #include "carddav/carddav.h" frmEditAccount::frmEditAccount( wxWindow* parent ) : frmEditAccountADT( parent ) { } void frmEditAccount::DetectAddressBook( wxCommandEvent& event ) { // Check data before connecting. wxString ValueData; long PortNum; ValueData = txtPort->GetValue(); ValueData.ToLong(&PortNum, 10); long RefreshNum; ValueData = txtRefresh->GetValue(); ValueData.ToLong(&RefreshNum, 10); bool UseSSL; if (txtAddress->IsEmpty()){ wxMessageBox(wxT("The server address cannot be blank."), wxT("Error"), wxICON_ERROR); return; } if (txtPort->IsEmpty() || PortNum < 0 || PortNum > 65535){ wxMessageBox(wxT("The server port needs to be between number 1 and 65535."), wxT("Error"), wxICON_ERROR); return; } if (txtUsername->IsEmpty()){ wxMessageBox(wxT("The server username cannot be blank."), wxT("Error"), wxICON_ERROR); return; } if (txtPassword->IsEmpty()){ wxMessageBox(wxT("The server password cannot be blank."), wxT("Error"), wxICON_ERROR); return; } UseSSL = chkSSL->GetValue(); if (txtRefresh->IsEmpty() || RefreshNum < 300 || RefreshNum > 86400){ RefreshNum = 1800; } // Setup a CardDAV object. CardDAV CDavObj; CDavObj.SetupConnection(txtAddress->GetValue(), (int)PortNum, txtUsername->GetValue(), txtPassword->GetValue(), UseSSL); // Attempt to extract the CardDAV address. wxString ABURL = CDavObj.GetDefaultAddressBookURL(); txtPrefix->SetValue(ABURL); } void frmEditAccount::LoadPointers( wxFileConfig* cfgin ){ cfgfile = cfgin; } void frmEditAccount::LoadSettings( wxString AccNameIn ){ // Get the data from the accounts settings file. AccName = AccNameIn; long itemindex = 0; bool ContinueAcc = TRUE; wxString AccountName; wxString AccountData; ContinueAcc = cfgfile->GetFirstGroup(AccountName, itemindex); while (ContinueAcc){ if (AccountName == AccName){ cfgfile->SetPath(AccountName); txtAccountName->SetValue(AccountName); cfgfile->Read("address", &AccountData); txtAddress->SetValue(AccountData); cfgfile->Read("port", &AccountData); txtPort->SetValue(AccountData); cfgfile->Read("username", &AccountData); txtUsername->SetValue(AccountData); cfgfile->Read("password", &AccountData); txtPassword->SetValue(AccountData); cfgfile->Read("prefix", &AccountData); txtPrefix->SetValue(AccountData); cfgfile->Read("ssl", &AccountData); if (AccountData == wxT("true")){ chkSSL->SetValue(TRUE); } cfgfile->Read("refresh", &AccountData); txtRefresh->SetValue(AccountData); break; } cfgfile->SetPath(wxT("/")); ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex); } } void frmEditAccount::UpdateSettings( wxCommandEvent& event ) { // Update the settings for the account. long itemindex = 0; bool ContinueAcc = TRUE; wxString AccountName; // Look for the account while (ContinueAcc){ if (AccountName == AccName){ // Update the settings for the account. cfgfile->RenameGroup(AccountName, txtAccountName->GetValue()); cfgfile->SetPath(txtAccountName->GetValue()); //txtAccountName->SetValue(AccountName); cfgfile->DeleteEntry(wxT("address"), FALSE); cfgfile->Write(wxT("address"), txtAddress->GetValue()); cfgfile->DeleteEntry(wxT("port"), FALSE); cfgfile->Write(wxT("port"), txtPort->GetValue()); cfgfile->DeleteEntry(wxT("username"), FALSE); cfgfile->Write(wxT("username"), txtUsername->GetValue()); cfgfile->DeleteEntry(wxT("password"), FALSE); cfgfile->Write(wxT("password"), txtPassword->GetValue()); cfgfile->DeleteEntry(wxT("prefix"), FALSE); cfgfile->Write(wxT("prefix"), txtPrefix->GetValue()); cfgfile->DeleteEntry(wxT("ssl"), FALSE); if (chkSSL->GetValue() == TRUE){ cfgfile->Write(wxT("ssl"), wxT("true")); } else { cfgfile->Write(wxT("ssl"), wxT("false")); } cfgfile->DeleteEntry(wxT("refresh"), FALSE); cfgfile->Write(wxT("refresh"), txtRefresh->GetValue()); /*cfgfile->Read("address", &AccountData); //txtAddress->SetValue(AccountData); cfgfile->Read("port", &AccountData); //txtPort->SetValue(AccountData); cfgfile->Read("username", &AccountData); //txtUsername->SetValue(AccountData); cfgfile->Read("password", &AccountData); //txtPassword->SetValue(AccountData); cfgfile->Read("prefix", &AccountData); //txtPrefix->SetValue(AccountData); cfgfile->Read("ssl", &AccountData); if (AccountData == wxT("true")){ chkSSL->SetValue(TRUE); } cfgfile->Read("refresh", &AccountData); //txtRefresh->SetValue(AccountData);*/ break; } cfgfile->SetPath(wxT("/")); ContinueAcc = cfgfile->GetNextGroup(AccountName, itemindex); } this->Close(); } void frmEditAccount::CloseWindow( wxCommandEvent& event ) { this->Close(); }