1 // frmContactEditorWebsites.cpp - frmContactEditorWebsites 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 "frmContactEditorWebsites.h"
23 #include "../common/textprocessing.h"
25 frmContactEditorWebsites::frmContactEditorWebsites( wxWindow* parent )
27 frmContactEditorWebsitesADT( parent )
33 priorityCtrl = new XABPriorityCtrl(tabGeneral);
34 szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
38 void frmContactEditorWebsites::ProcessAction( wxCommandEvent& event )
41 // Set if the editor is adding or editing an address.
47 if (EditorMode == FALSE){
51 // Get the website address.
53 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
55 // Get the type of website.
57 if (EditSectionType == CE_GENERAL){
59 WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("")));
61 } else if (EditSectionType == CE_HOME) {
63 WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("home")));
65 } else if (EditSectionType == CE_WORK) {
67 WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("work")));
71 // Add the website priority.
73 if (priorityCtrl->IsPriorityChecked()){
75 WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, priorityCtrl->GetValue()));
79 WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));
87 coldata.SetId(WebsiteListIndex);
88 coldata.SetData(WebsiteListIndex);
89 coldata.SetText(txtWebsite->GetValue());
90 ListCtrlIndex = WebsiteListCtrlPtr->InsertItem(coldata);
92 if (priorityCtrl->IsPriorityChecked()){
94 WebsiteListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
102 // Update the website address.
103 long longSelected = -1;
105 WebsiteListPtr->erase(WebsiteListIndex);
106 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
108 // Update the slider priority.
110 WebsiteListPrefPtr->erase(WebsiteListIndex);
112 if (priorityCtrl->IsPriorityChecked()){
114 WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, priorityCtrl->GetValue()));
118 WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));
124 longSelected = WebsiteListCtrlPtr->GetNextItem(longSelected,
126 wxLIST_STATE_SELECTED);
128 if (longSelected == -1){
132 WebsiteListCtrlPtr->SetItem(longSelected, 0, txtWebsite->GetValue());
134 if (priorityCtrl->IsPriorityChecked()){
136 WebsiteListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
140 WebsiteListCtrlPtr->SetItem(longSelected, 1, wxT(""));
150 void frmContactEditorWebsites::SetEditorMode(bool EditMode, SectionType SectType)
153 // Set if the editor is adding or editing an address.
157 if (EditMode == FALSE){
160 btnAction->SetLabel(_("Add"));
161 this->SetTitle(_("Add Website"));
163 } else if (EditMode == TRUE){
166 btnAction->SetLabel(_("Modify"));
167 this->SetTitle(_("Modify Website"));
169 std::map<int,int>::iterator intiter;
170 std::map<int,wxString>::iterator striter;
173 // Load the data into the form. Get the website.
175 striter = WebsiteListPtr->find(WebsiteListIndex);
177 if (striter->first == WebsiteListIndex){
179 strValue = striter->second;
183 txtWebsite->SetValue(strValue);
187 // Get the website priority.
189 intiter = WebsiteListPrefPtr->find(WebsiteListIndex);
191 if (intiter->first == WebsiteListIndex && intiter->second > 0 &&
192 intiter != WebsiteListPrefPtr->end()){
194 priorityCtrl->SetValue(intiter->second);
195 priorityCtrl->EnablePriority(true);
201 EditSectionType = SectType;
205 void frmContactEditorWebsites::CloseWindow( wxCommandEvent& event )
214 void frmContactEditorWebsites::SetupPointers(std::map<int, wxString> *WebsiteList,
215 std::map<int, wxString> *WebsiteListAltID,
216 std::map<int, wxString> *WebsiteListPID,
217 std::map<int, wxString> *WebsiteListType,
218 std::map<int, wxString> *WebsiteListTokens,
219 std::map<int, wxString> *WebsiteListMediatype,
220 std::map<int, int> *WebsiteListPref,
221 wxListCtrl *WebsiteListCtrl,
225 // Setup the pointers.
227 WebsiteListPtr = WebsiteList;
228 WebsiteListAltIDPtr = WebsiteListAltID;
229 WebsiteListPIDPtr = WebsiteListPID;
230 WebsiteListTypePtr = WebsiteListType;
231 WebsiteListTokensPtr = WebsiteListTokens;
232 WebsiteListMediatypePtr = WebsiteListMediatype;
233 WebsiteListPrefPtr = WebsiteListPref;
234 WebsiteListCtrlPtr = WebsiteListCtrl;
235 WebsiteListIndex = WebsiteIndex;