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 sliPriority->Disable();
37 void frmContactEditorWebsites::EnablePriority( wxCommandEvent& event )
40 // Enable the priority setting.
42 if (chkUsePref->IsChecked()){
43 sliPriority->Enable();
45 sliPriority->Disable();
50 void frmContactEditorWebsites::ProcessAction( wxCommandEvent& event )
53 // Set if the editor is adding or editing an address.
59 if (EditorMode == FALSE){
63 // Get the website address.
65 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
67 // Get the type of website.
69 if (EditSectionType == CE_GENERAL){
71 WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("")));
73 } else if (EditSectionType == CE_HOME) {
75 WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("home")));
77 } else if (EditSectionType == CE_WORK) {
79 WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("work")));
83 // Add the website priority.
85 if (chkUsePref->IsChecked()){
87 WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, sliPriority->GetValue()));
91 WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));
99 coldata.SetId(WebsiteListIndex);
100 coldata.SetData(WebsiteListIndex);
101 coldata.SetText(txtWebsite->GetValue());
102 ListCtrlIndex = WebsiteListCtrlPtr->InsertItem(coldata);
104 if (chkUsePref->IsChecked()){
106 WebsiteListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
114 // Update the website address.
115 long longSelected = -1;
117 WebsiteListPtr->erase(WebsiteListIndex);
118 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
120 // Update the slider priority.
122 WebsiteListPrefPtr->erase(WebsiteListIndex);
124 if (chkUsePref->IsChecked()){
126 WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, sliPriority->GetValue()));
130 WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));
136 longSelected = WebsiteListCtrlPtr->GetNextItem(longSelected,
138 wxLIST_STATE_SELECTED);
140 if (longSelected == -1){
144 WebsiteListCtrlPtr->SetItem(longSelected, 0, txtWebsite->GetValue());
146 if (chkUsePref->IsChecked()){
148 WebsiteListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
152 WebsiteListCtrlPtr->SetItem(longSelected, 1, wxT(""));
162 void frmContactEditorWebsites::SetEditorMode(bool EditMode, SectionType SectType)
165 // Set if the editor is adding or editing an address.
169 if (EditMode == FALSE){
172 btnAction->SetLabel(_("Add"));
173 this->SetTitle(_("Add Website"));
175 } else if (EditMode == TRUE){
178 btnAction->SetLabel(_("Modify"));
179 this->SetTitle(_("Modify Website"));
181 std::map<int,int>::iterator intiter;
182 std::map<int,wxString>::iterator striter;
185 // Load the data into the form. Get the website.
187 striter = WebsiteListPtr->find(WebsiteListIndex);
189 if (striter->first == WebsiteListIndex){
191 strValue = striter->second;
195 txtWebsite->SetValue(strValue);
199 // Get the website priority.
201 intiter = WebsiteListPrefPtr->find(WebsiteListIndex);
203 if (intiter->first == WebsiteListIndex && intiter->second > 0 &&
204 intiter != WebsiteListPrefPtr->end()){
206 sliPriority->SetValue(intiter->second);
207 sliPriority->Enable();
208 chkUsePref->SetValue(TRUE);
214 EditSectionType = SectType;
218 void frmContactEditorWebsites::CloseWindow( wxCommandEvent& event )
227 void frmContactEditorWebsites::SetupPointers(std::map<int, wxString> *WebsiteList,
228 std::map<int, wxString> *WebsiteListAltID,
229 std::map<int, wxString> *WebsiteListPID,
230 std::map<int, wxString> *WebsiteListType,
231 std::map<int, wxString> *WebsiteListTokens,
232 std::map<int, wxString> *WebsiteListMediatype,
233 std::map<int, int> *WebsiteListPref,
234 wxListCtrl *WebsiteListCtrl,
238 // Setup the pointers.
240 WebsiteListPtr = WebsiteList;
241 WebsiteListAltIDPtr = WebsiteListAltID;
242 WebsiteListPIDPtr = WebsiteListPID;
243 WebsiteListTypePtr = WebsiteListType;
244 WebsiteListTokensPtr = WebsiteListTokens;
245 WebsiteListMediatypePtr = WebsiteListMediatype;
246 WebsiteListPrefPtr = WebsiteListPref;
247 WebsiteListCtrlPtr = WebsiteListCtrl;
248 WebsiteListIndex = WebsiteIndex;