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"));
43 void frmContactEditorIM::EnablePriority( wxCommandEvent& event )
45 if (chkUsePref->IsChecked()){
46 sliPriority->Enable();
48 sliPriority->Disable();
52 void frmContactEditorIM::ProcessAction( wxCommandEvent& event )
57 // Check if IM type is empty and if it is then
58 // throw an error message.
60 wxString strIMTypeValue;
61 strIMTypeValue = cmbIMType->GetValue();
63 if (strIMTypeValue.IsEmpty()){
65 wxMessageDialog NopeDlg(this, _("IM Type is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
71 if (txtUsername->IsEmpty()){
73 wxMessageDialog NopeDlg(this, _("Username/E-mail Address is required."), _("Error"), wxOK|wxICON_ERROR, wxDefaultPosition);
79 if (EditorMode == FALSE){
81 // Add the address to the list (maps).
83 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 + wxT(":"));
124 strIMAddress.Append(strValue);
125 strIMAddress.Append(txtUsername->GetValue());
127 IMListPtr->insert(std::make_pair(IMListIndex, strIMAddress));
131 if (EditSectionType == CE_GENERAL){
133 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("")));
135 } else if (EditSectionType == CE_HOME) {
137 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("home")));
139 } else if (EditSectionType == CE_WORK) {
141 IMListTypePtr->insert(std::make_pair(IMListIndex, wxT("work")));
147 if (chkUsePref->IsChecked()){
149 IMListPrefPtr->insert(std::make_pair(IMListIndex, sliPriority->GetValue()));
153 IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));
161 coldata.SetId(IMListIndex);
162 coldata.SetData(IMListIndex);
163 coldata.SetText(cmbIMType->GetValue());
164 ListCtrlIndex = IMListCtrlPtr->InsertItem(coldata);
166 IMListCtrlPtr->SetItem(ListCtrlIndex, 1, txtUsername->GetValue());
168 if (chkUsePref->IsChecked()){
170 IMListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
176 } else if (EditorMode == TRUE){
178 // Edit the address in the list.
180 wxString strIMAddress;
182 long longSelected = -1;
184 // Strip out the colons.
186 strIMAddress.Replace(wxT(":"), wxT(""), TRUE);
190 strIMTypeValue = cmbIMType->GetString(cmbIMType->GetSelection());
192 if (strIMTypeValue == wxT("AIM")){
194 strIMAddress.Append(wxT("aim:"));
196 } else if (strIMTypeValue == wxT("Gadu-Gadu")){
198 strIMAddress.Append(wxT("gg:"));
200 } else if (strIMTypeValue == wxT("ICQ")){
202 strIMAddress.Append(wxT("icq:"));
204 } else if (strIMTypeValue == wxT("Skype")){
206 strIMAddress.Append(wxT("skype:"));
208 } else if (strIMTypeValue == wxT("XMPP")){
210 strIMAddress.Append(wxT("xmpp:"));
212 } else if (strIMTypeValue == wxT("Yahoo")){
214 strIMAddress.Append(wxT("yahoo:"));
218 strIMAddress.Append(strIMTypeValue + wxT(":"));
222 strIMAddress.Append(strValue);
223 strIMAddress.Append(txtUsername->GetValue());
225 IMListPtr->erase(IMListIndex);
226 IMListPtr->insert(std::make_pair(IMListIndex, strIMAddress));
230 IMListPrefPtr->erase(IMListIndex);
232 if (chkUsePref->IsChecked()){
234 IMListPrefPtr->insert(std::make_pair(IMListIndex, sliPriority->GetValue()));
238 IMListPrefPtr->insert(std::make_pair(IMListIndex, 0));
242 // Modify the data on the form.
244 longSelected = IMListCtrlPtr->GetNextItem(longSelected,
246 wxLIST_STATE_SELECTED);
248 if (longSelected == -1){
252 IMListCtrlPtr->SetItem(longSelected, 0, cmbIMType->GetValue());
253 IMListCtrlPtr->SetItem(longSelected, 1, txtUsername->GetValue());
255 if (chkUsePref->IsChecked()){
257 IMListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
261 IMListCtrlPtr->SetItem(longSelected, 2, wxT(""));
271 void frmContactEditorIM::CloseWindow( wxCommandEvent& event )
276 void frmContactEditorIM::SetEditorMode(bool EditMode, SectionType SectType)
278 // Set if the editor is adding or editing an address.
282 if (EditMode == FALSE){
285 btnAction->SetLabel(_("Add"));
286 this->SetTitle(_("Add IM"));
288 } else if (EditMode == TRUE){
291 btnAction->SetLabel(_("Modify"));
292 this->SetTitle(_("Modify IM"));
294 std::map<int,int>::iterator intiter;
295 std::map<int,wxString>::iterator striter;
300 // Setup the IM Type.
302 striter = IMListPtr->find(IMListIndex);
304 if (striter->first == IMListIndex){
306 strValue = striter->second;
310 wxStringTokenizer IMAddressToken(strValue, wxT(":"));
311 strIMType = IMAddressToken.GetNextToken();
312 strIMUser = IMAddressToken.GetNextToken();
314 if (strIMType == wxT("aim")){
316 cmbIMType->SetValue(wxT("AIM"));
318 } else if (strIMType == wxT("gg")){
320 cmbIMType->SetValue(wxT("Gadu-Gadu"));
322 } else if (strIMType == wxT("icq")){
324 cmbIMType->SetValue(wxT("ICQ"));
326 } else if (strIMType == wxT("skype")){
328 cmbIMType->SetValue(wxT("Skype"));
330 } else if (strIMType == wxT("xmpp")){
332 cmbIMType->SetValue(wxT("XMPP"));
334 } else if (strIMType == wxT("yahoo")){
336 cmbIMType->SetValue(wxT("Yahoo"));
340 cmbIMType->SetValue(strIMType);
344 // Setup the username.
346 txtUsername->SetValue(strIMUser);
348 // Setup the priority.
350 intiter = IMListPrefPtr->find(IMListIndex);
352 if (intiter->first == IMListIndex && intiter->second > 0){
354 sliPriority->SetValue(intiter->second);
355 sliPriority->Enable();
356 chkUsePref->SetValue(TRUE);
362 EditSectionType = SectType;
366 void frmContactEditorIM::SetupPointers( std::map<int, wxString> *IMList,
367 std::map<int, wxString> *IMListAltID,
368 std::map<int, wxString> *IMListPID,
369 std::map<int, wxString> *IMListType,
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 IMListTokensPtr = IMListTokens;
382 IMListMediatypePtr = IMListMediatype;
383 IMListPrefPtr = IMListPref;
384 IMListCtrlPtr = IMListCtrl;
385 IMListIndex = IMIndex;