1 // frmContactEditorIM.cpp - frmContactEditorIM form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmContactEditorIM.h"
20 #include <wx/msgdlg.h>
21 #include <wx/tokenzr.h>
23 #include "../common/textprocessing.h"
25 frmContactEditorIM::frmContactEditorIM( wxWindow* parent )
27 frmContactEditorIMADT( parent )
30 sliPriority->Disable();
32 // Add some values to the drop down box for IM types.
34 cmbIMType->Append(wxT("AIM"));
35 cmbIMType->Append(wxT("Gadu-Gadu"));
36 cmbIMType->Append(wxT("ICQ"));
37 cmbIMType->Append(wxT("Skype"));
38 cmbIMType->Append(wxT("XMPP"));
39 cmbIMType->Append(wxT("Yahoo"));
40 cmbIMType->Append(_("Other"));
44 void frmContactEditorIM::EnablePriority( wxCommandEvent& event )
46 if (chkUsePref->IsChecked()){
47 sliPriority->Enable();
49 sliPriority->Disable();
53 void frmContactEditorIM::ProcessAction( wxCommandEvent& event )
58 // Check if IM type is empty and if it is then
59 // throw an error message.
61 wxString strIMTypeValue;
62 strIMTypeValue = cmbIMType->GetValue();
64 if (strIMTypeValue.IsEmpty()){
66 wxMessageDialog NopeDlg(this, _("IM Type is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
72 if (txtUsername->IsEmpty()){
74 wxMessageDialog NopeDlg(this, _("Username/E-mail Address is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
80 if (EditorMode == FALSE){
82 // Add the address to the list (maps).
84 wxString strIMAddress;
86 // Strip out the colons.
88 strIMAddress.Replace(wxT(":"), wxT(""), TRUE);
92 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
94 if (strIMTypeValue == wxT("AIM")){
96 strIMAddress.Append(wxT("aim"));
98 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
100 strIMAddress.Append(wxT("gg"));
102 } else if (strIMTypeValue == wxT("ICQ")){
104 strIMAddress.Append(wxT("icq"));
106 } else if (strIMTypeValue == wxT("Skype")){
108 strIMAddress.Append(wxT("skype"));
110 } else if (strIMTypeValue == wxT("XMPP")){
112 strIMAddress.Append(wxT("xmpp"));
114 } else if (strIMTypeValue == wxT("Yahoo")){
116 strIMAddress.Append(wxT("yahoo"));
120 strIMAddress.Append(strIMTypeValue);
124 IMListTypeInfoPtr->insert(std::make_pair(IMListIndex, strIMAddress));
125 IMListPtr->insert(std::make_pair(IMListIndex, txtUsername->GetValue()));
129 if (EditSectionType == CE_GENERAL){
131 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("")));
133 } else if (EditSectionType == CE_HOME) {
135 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("home")));
137 } else if (EditSectionType == CE_WORK) {
139 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("work")));
145 if (chkUsePref->IsChecked()){
147 IMListPrefPtr->insert(std::make_pair(IMListIndex, sliPriority->GetValue()));
151 IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));
159 coldata.SetId(IMListIndex);
160 coldata.SetData(IMListIndex);
161 coldata.SetText(cmbIMType->GetValue());
162 ListCtrlIndex = IMListCtrlPtr->InsertItem(coldata);
164 IMListCtrlPtr->SetItem(ListCtrlIndex, 1, txtUsername->GetValue());
166 if (chkUsePref->IsChecked()){
168 IMListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
174 } else if (EditorMode == TRUE){
176 // Edit the address in the list.
178 wxString strIMAddress;
179 long longSelected = -1;
183 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
185 if (strIMTypeValue == wxT("AIM")){
187 strIMAddress.Append(wxT("aim"));
189 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
191 strIMAddress.Append(wxT("gg"));
193 } else if (strIMTypeValue == wxT("ICQ")){
195 strIMAddress.Append(wxT("icq"));
197 } else if (strIMTypeValue == wxT("Skype")){
199 strIMAddress.Append(wxT("skype"));
201 } else if (strIMTypeValue == wxT("XMPP")){
203 strIMAddress.Append(wxT("xmpp"));
205 } else if (strIMTypeValue == wxT("Yahoo")){
207 strIMAddress.Append(wxT("yahoo"));
211 strIMAddress.Append(strIMTypeValue);
215 IMListPtr->erase(IMListIndex);
216 IMListPtr->insert(std::make_pair(IMListIndex, txtUsername->GetValue()));
218 IMListTypeInfoPtr->erase(IMListIndex);
219 IMListTypeInfoPtr->insert(std::make_pair(IMListIndex, strIMAddress));
223 IMListPrefPtr->erase(IMListIndex);
225 if (chkUsePref->IsChecked()){
227 IMListPrefPtr->insert(std::make_pair(IMListIndex, sliPriority->GetValue()));
231 IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));
235 // Modify the data on the form.
237 longSelected = IMListCtrlPtr->GetNextItem(longSelected,
239 wxLIST_STATE_SELECTED);
241 if (longSelected == -1){
245 IMListCtrlPtr->SetItem(longSelected, 0, cmbIMType->GetValue());
246 IMListCtrlPtr->SetItem(longSelected, 1, txtUsername->GetValue());
248 if (chkUsePref->IsChecked()){
250 IMListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
254 IMListCtrlPtr->SetItem(longSelected, 2, wxT(""));
264 void frmContactEditorIM::CloseWindow( wxCommandEvent& event )
269 void frmContactEditorIM::SetEditorMode(bool EditMode, SectionType SectType)
271 // Set if the editor is adding or editing an address.
275 if (EditMode == FALSE){
278 btnAction->SetLabel(_("Add"));
279 this->SetTitle(_("Add IM"));
281 } else if (EditMode == TRUE){
284 btnAction->SetLabel(_("Modify"));
285 this->SetTitle(_("Modify IM"));
287 std::map<int,int>::iterator intiter;
288 std::map<int,wxString>::iterator striter;
293 // Setup the IM Type.
295 striter = IMListPtr->find(IMListIndex);
297 if (striter->first == IMListIndex){
299 strValue = striter->second;
303 strIMUser = IMListPtr->find(IMListIndex)->second;
304 strIMType = IMListTypeInfoPtr->find(IMListIndex)->second;
306 if (strIMType == wxT("aim")){
308 cmbIMType->SetValue(wxT("AIM"));
309 cmbIMType->SetSelection(0);
311 } else if (strIMType == wxT("gg")){
313 cmbIMType->SetValue(wxT("Gadu-Gadu"));
314 cmbIMType->SetSelection(1);
316 } else if (strIMType == wxT("icq")){
318 cmbIMType->SetValue(wxT("ICQ"));
319 cmbIMType->SetSelection(2);
321 } else if (strIMType == wxT("skype")){
323 cmbIMType->SetValue(wxT("Skype"));
324 cmbIMType->SetSelection(3);
326 } else if (strIMType == wxT("xmpp")){
328 cmbIMType->SetValue(wxT("XMPP"));
329 cmbIMType->SetSelection(4);
331 } else if (strIMType == wxT("yahoo")){
333 cmbIMType->SetValue(wxT("Yahoo"));
334 cmbIMType->SetSelection(5);
338 cmbIMType->SetValue(strIMType);
339 cmbIMType->SetSelection(6);
343 // Setup the username.
345 txtUsername->SetValue(strIMUser);
347 // Setup the priority.
349 intiter = IMListPrefPtr->find(IMListIndex);
351 if (intiter->first == IMListIndex && intiter->second > 0){
353 sliPriority->SetValue(intiter->second);
354 sliPriority->Enable();
355 chkUsePref->SetValue(TRUE);
361 EditSectionType = SectType;
365 void frmContactEditorIM::SetupPointers( std::map<int, wxString> *IMList,
366 std::map<int, wxString> *IMListAltID,
367 std::map<int, wxString> *IMListPID,
368 std::map<int, wxString> *IMListType,
369 std::map<int, wxString> *IMListTypeInfo,
370 std::map<int, wxString> *IMListTokens,
371 std::map<int, wxString> *IMListMediatype,
372 std::map<int, int> *IMListPref,
373 wxListCtrl *IMListCtrl,
378 IMListAltIDPtr = IMListAltID;
379 IMListPIDPtr = IMListPID;
380 IMListTypePtr = IMListType;
381 IMListTypeInfoPtr = IMListTypeInfo;
382 IMListTokensPtr = IMListTokens;
383 IMListMediatypePtr = IMListMediatype;
384 IMListPrefPtr = IMListPref;
385 IMListCtrlPtr = IMListCtrl;
386 IMListIndex = IMIndex;