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);
39 void frmContactEditorWebsites::ProcessAction( wxCommandEvent& event )
42 // Set if the editor is adding or editing an address.
48 if (EditorMode == FALSE){
52 // Get the website address.
54 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
56 // Get the type of website.
58 if (EditSectionType == CE_GENERAL){
60 WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("")));
62 } else if (EditSectionType == CE_HOME) {
64 WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("home")));
66 } else if (EditSectionType == CE_WORK) {
68 WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("work")));
72 // Add the website priority.
74 if (priorityCtrl->IsPriorityChecked()){
76 WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, priorityCtrl->GetValue()));
80 WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));
88 coldata.SetId(WebsiteListIndex);
89 coldata.SetData(WebsiteListIndex);
90 coldata.SetText(txtWebsite->GetValue());
91 ListCtrlIndex = WebsiteListCtrlPtr->InsertItem(coldata);
93 if (priorityCtrl->IsPriorityChecked()){
95 WebsiteListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
103 // Update the website address.
104 long longSelected = -1;
106 WebsiteListPtr->erase(WebsiteListIndex);
107 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
109 // Update the slider priority.
111 WebsiteListPrefPtr->erase(WebsiteListIndex);
113 if (priorityCtrl->IsPriorityChecked()){
115 WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, priorityCtrl->GetValue()));
119 WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));
125 longSelected = WebsiteListCtrlPtr->GetNextItem(longSelected,
127 wxLIST_STATE_SELECTED);
129 if (longSelected == -1){
133 WebsiteListCtrlPtr->SetItem(longSelected, 0, txtWebsite->GetValue());
135 if (priorityCtrl->IsPriorityChecked()){
137 WebsiteListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
141 WebsiteListCtrlPtr->SetItem(longSelected, 1, wxT(""));
151 void frmContactEditorWebsites::SetEditorMode(bool EditMode, SectionType SectType)
154 // Set if the editor is adding or editing an address.
158 if (EditMode == FALSE){
161 btnAction->SetLabel(_("Add"));
162 this->SetTitle(_("Add Website"));
164 } else if (EditMode == TRUE){
167 btnAction->SetLabel(_("Modify"));
168 this->SetTitle(_("Modify Website"));
170 std::map<int,int>::iterator intiter;
171 std::map<int,wxString>::iterator striter;
174 // Load the data into the form. Get the website.
176 striter = WebsiteListPtr->find(WebsiteListIndex);
178 if (striter->first == WebsiteListIndex){
180 strValue = striter->second;
184 txtWebsite->SetValue(strValue);
188 // Get the website priority.
190 intiter = WebsiteListPrefPtr->find(WebsiteListIndex);
192 if (intiter->first == WebsiteListIndex && intiter->second > 0 &&
193 intiter != WebsiteListPrefPtr->end()){
195 priorityCtrl->SetValue(intiter->second);
196 priorityCtrl->EnablePriority(true);
202 EditSectionType = SectType;
206 void frmContactEditorWebsites::CloseWindow( wxCommandEvent& event )
215 void frmContactEditorWebsites::SetupPointers(std::map<int, wxString> *WebsiteList,
216 std::map<int, wxString> *WebsiteListAltID,
217 std::map<int, wxString> *WebsiteListPID,
218 std::map<int, wxString> *WebsiteListType,
219 std::map<int, wxString> *WebsiteListTokens,
220 std::map<int, wxString> *WebsiteListMediatype,
221 std::map<int, int> *WebsiteListPref,
222 wxListCtrl *WebsiteListCtrl,
226 // Setup the pointers.
228 WebsiteListPtr = WebsiteList;
229 WebsiteListAltIDPtr = WebsiteListAltID;
230 WebsiteListPIDPtr = WebsiteListPID;
231 WebsiteListTypePtr = WebsiteListType;
232 WebsiteListTokensPtr = WebsiteListTokens;
233 WebsiteListMediatypePtr = WebsiteListMediatype;
234 WebsiteListPrefPtr = WebsiteListPref;
235 WebsiteListCtrlPtr = WebsiteListCtrl;
236 WebsiteListIndex = WebsiteIndex;