// frmContactEditorIM.cpp - frmContactEditorIM 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 "frmContactEditorIM.h"
#include
#include
#include "../common/textprocessing.h"
frmContactEditorIM::frmContactEditorIM( wxWindow* parent )
:
frmContactEditorIMADT( parent )
{
EditorMode = FALSE;
sliPriority->Disable();
// Add some values to the drop down box for IM types.
cmbIMType->Append(wxT("AIM"));
cmbIMType->Append(wxT("Gadu-Gadu"));
cmbIMType->Append(wxT("ICQ"));
cmbIMType->Append(wxT("Skype"));
cmbIMType->Append(wxT("XMPP"));
cmbIMType->Append(wxT("Yahoo"));
}
void frmContactEditorIM::EnablePriority( wxCommandEvent& event )
{
if (chkUsePref->IsChecked()){
sliPriority->Enable();
} else {
sliPriority->Disable();
}
}
void frmContactEditorIM::ProcessAction( wxCommandEvent& event )
{
long ListCtrlIndex;
// Check if IM type is empty and if it is then
// throw an error message.
wxString strIMTypeValue;
strIMTypeValue = cmbIMType->GetValue();
if (strIMTypeValue.IsEmpty()){
wxMessageDialog NopeDlg(this, _("IM Type is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
NopeDlg.ShowModal();
return;
}
if (txtUsername->IsEmpty()){
wxMessageDialog NopeDlg(this, _("Username/E-mail Address is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
NopeDlg.ShowModal();
return;
}
if (EditorMode == FALSE){
// Add the address to the list (maps).
wxString strIMAddress;
wxString strValue;
// Strip out the colons.
strIMAddress.Replace(wxT(":"), wxT(""), TRUE);
// Specify the type.
strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
if (strIMTypeValue == wxT("AIM")){
strIMAddress.Append(wxT("aim:"));
} else if (strIMTypeValue == wxT("Gadu-Gadu")){
strIMAddress.Append(wxT("gg:"));
} else if (strIMTypeValue == wxT("ICQ")){
strIMAddress.Append(wxT("icq:"));
} else if (strIMTypeValue == wxT("Skype")){
strIMAddress.Append(wxT("skype:"));
} else if (strIMTypeValue == wxT("XMPP")){
strIMAddress.Append(wxT("xmpp:"));
} else if (strIMTypeValue == wxT("Yahoo")){
strIMAddress.Append(wxT("yahoo:"));
} else {
strIMAddress.Append(strIMTypeValue + wxT(":"));
}
strIMAddress.Append(strValue);
strIMAddress.Append(txtUsername->GetValue());
IMListPtr->insert(std::make_pair(IMListIndex, strIMAddress));
// Set the type.
if (EditSectionType == CE_GENERAL){
IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("")));
} else if (EditSectionType == CE_HOME) {
IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("home")));
} else if (EditSectionType == CE_WORK) {
IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("work")));
}
// Set the priority.
if (chkUsePref->IsChecked()){
IMListPrefPtr->insert(std::make_pair(IMListIndex, sliPriority->GetValue()));
} else {
IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));
}
// Add to the form.
wxListItem coldata;
coldata.SetId(IMListIndex);
coldata.SetData(IMListIndex);
coldata.SetText(cmbIMType->GetValue());
ListCtrlIndex = IMListCtrlPtr->InsertItem(coldata);
IMListCtrlPtr->SetItem(ListCtrlIndex, 1, txtUsername->GetValue());
if (chkUsePref->IsChecked()){
IMListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
}
this->Close();
} else if (EditorMode == TRUE){
// Edit the address in the list.
wxString strIMAddress;
wxString strValue;
long longSelected = -1;
// Strip out the colons.
strIMAddress.Replace(wxT(":"), wxT(""), TRUE);
// Specify the type.
strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
if (strIMTypeValue == wxT("AIM")){
strIMAddress.Append(wxT("aim:"));
} else if (strIMTypeValue == wxT("Gadu-Gadu")){
strIMAddress.Append(wxT("gg:"));
} else if (strIMTypeValue == wxT("ICQ")){
strIMAddress.Append(wxT("icq:"));
} else if (strIMTypeValue == wxT("Skype")){
strIMAddress.Append(wxT("skype:"));
} else if (strIMTypeValue == wxT("XMPP")){
strIMAddress.Append(wxT("xmpp:"));
} else if (strIMTypeValue == wxT("Yahoo")){
strIMAddress.Append(wxT("yahoo:"));
} else {
strIMAddress.Append(strIMTypeValue + wxT(":"));
}
strIMAddress.Append(strValue);
strIMAddress.Append(txtUsername->GetValue());
IMListPtr->erase(IMListIndex);
IMListPtr->insert(std::make_pair(IMListIndex, strIMAddress));
// Set the priority.
IMListPrefPtr->erase(IMListIndex);
if (chkUsePref->IsChecked()){
IMListPrefPtr->insert(std::make_pair(IMListIndex, sliPriority->GetValue()));
} else {
IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));
}
// Modify the data on the form.
longSelected = IMListCtrlPtr->GetNextItem(longSelected,
wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
if (longSelected == -1){
return;
}
IMListCtrlPtr->SetItem(longSelected, 0, cmbIMType->GetValue());
IMListCtrlPtr->SetItem(longSelected, 1, txtUsername->GetValue());
if (chkUsePref->IsChecked()){
IMListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
} else {
IMListCtrlPtr->SetItem(longSelected, 2, wxT(""));
}
this->Close();
}
}
void frmContactEditorIM::CloseWindow( wxCommandEvent& event )
{
this->Close();
}
void frmContactEditorIM::SetEditorMode(bool EditMode, SectionType SectType)
{
// Set if the editor is adding or editing an address.
// FALSE = Add
// TRUE = Edit
if (EditMode == FALSE){
EditorMode = FALSE;
btnAction->SetLabel(_("Add"));
this->SetTitle(_("Add IM"));
} else if (EditMode == TRUE){
EditorMode = TRUE;
btnAction->SetLabel(_("Modify"));
this->SetTitle(_("Modify IM"));
std::map::iterator intiter;
std::map::iterator striter;
wxString strValue;
wxString strIMType;
wxString strIMUser;
// Setup the IM Type.
striter = IMListPtr->find(IMListIndex);
if (striter->first == IMListIndex){
strValue = striter->second;
}
wxStringTokenizer IMAddressToken(strValue, wxT(":"));
strIMType = IMAddressToken.GetNextToken();
strIMUser = IMAddressToken.GetNextToken();
if (strIMType == wxT("aim")){
cmbIMType->SetValue(wxT("AIM"));
} else if (strIMType == wxT("gg")){
cmbIMType->SetValue(wxT("Gadu-Gadu"));
} else if (strIMType == wxT("icq")){
cmbIMType->SetValue(wxT("ICQ"));
} else if (strIMType == wxT("skype")){
cmbIMType->SetValue(wxT("Skype"));
} else if (strIMType == wxT("xmpp")){
cmbIMType->SetValue(wxT("XMPP"));
} else if (strIMType == wxT("yahoo")){
cmbIMType->SetValue(wxT("Yahoo"));
} else {
cmbIMType->SetValue(strIMType);
}
// Setup the username.
txtUsername->SetValue(strIMUser);
// Setup the priority.
intiter = IMListPrefPtr->find(IMListIndex);
if (intiter->first == IMListIndex && intiter->second > 0){
sliPriority->SetValue(intiter->second);
sliPriority->Enable();
chkUsePref->SetValue(TRUE);
}
}
EditSectionType = SectType;
}
void frmContactEditorIM::SetupPointers( std::map *IMList,
std::map *IMListAltID,
std::map *IMListPID,
std::map *IMListType,
std::map *IMListTokens,
std::map *IMListMediatype,
std::map *IMListPref,
wxListCtrl *IMListCtrl,
int IMIndex )
{
IMListPtr = IMList;
IMListAltIDPtr = IMListAltID;
IMListPIDPtr = IMListPID;
IMListTypePtr = IMListType;
IMListTokensPtr = IMListTokens;
IMListMediatypePtr = IMListMediatype;
IMListPrefPtr = IMListPref;
IMListCtrlPtr = IMListCtrl;
IMListIndex = IMIndex;
}