Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor(*): Call Layout on szrGeneral after adding priorty control
[xestiaab/.git] / source / contacteditor / frmContactEditorWebsites.cpp
1 // frmContactEditorWebsites.cpp - frmContactEditorWebsites form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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"
21 #include <map>
22 #include "../enums.h"
23 #include "../common/textprocessing.h"
25 frmContactEditorWebsites::frmContactEditorWebsites( wxWindow* parent )
26 :
27 frmContactEditorWebsitesADT( parent )
28 {
29         
30         // Setup the window.
31         
32         EditorMode = FALSE;
33         priorityCtrl = new XABPriorityCtrl(tabGeneral);
34         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
35         szrGeneral->Layout();
36         
37 }
39 void frmContactEditorWebsites::ProcessAction( wxCommandEvent& event )
40 {
41         
42         // Set if the editor is adding or editing an address.
43         // FALSE = Add
44         // TRUE = Edit
46         long ListCtrlIndex;
47         
48         if (EditorMode == FALSE){
49         
50                 wxString strValue;
51                 
52                 // Get the website address.
53                 
54                 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
55                 
56                 // Get the type of website.
57                 
58                 if (EditSectionType == CE_GENERAL){
59                 
60                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("")));
61                 
62                 } else if (EditSectionType == CE_HOME) {
63                 
64                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("home")));
65                 
66                 } else if (EditSectionType == CE_WORK) {
67                 
68                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("work")));
69                 
70                 }
71                 
72                 // Add the website priority.
73                 
74                 if (priorityCtrl->IsPriorityChecked()){
75                 
76                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, priorityCtrl->GetValue()));
77                 
78                 } else {
79                 
80                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));                
81                 
82                 }
83                 
84                 // Add to the form.
85                 
86                 wxListItem coldata;
87                 
88                 coldata.SetId(WebsiteListIndex);
89                 coldata.SetData(WebsiteListIndex);              
90                 coldata.SetText(txtWebsite->GetValue());
91                 ListCtrlIndex = WebsiteListCtrlPtr->InsertItem(coldata);
92                 
93                 if (priorityCtrl->IsPriorityChecked()){
94                 
95                         WebsiteListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
96                 
97                 }               
98         
99                 this->Close();          
100         
101         } else {
102         
103                 // Update the website address.
104                 long longSelected = -1;         
105                 wxString strValue;              
106                 WebsiteListPtr->erase(WebsiteListIndex);
107                 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
108                 
109                 // Update the slider priority.
110                 
111                 WebsiteListPrefPtr->erase(WebsiteListIndex);
112                 
113                 if (priorityCtrl->IsPriorityChecked()){
114                 
115                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, priorityCtrl->GetValue()));
116                 
117                 } else {
118                 
119                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));
120                 
121                 }               
122                 
123                 // Update the form.
124                 
125                 longSelected = WebsiteListCtrlPtr->GetNextItem(longSelected, 
126                         wxLIST_NEXT_ALL,
127                         wxLIST_STATE_SELECTED);
128                         
129                 if (longSelected == -1){
130                         return;
131                 }               
132                 
133                 WebsiteListCtrlPtr->SetItem(longSelected, 0, txtWebsite->GetValue());
134                 
135                 if (priorityCtrl->IsPriorityChecked()){
136                 
137                         WebsiteListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
138                 
139                 } else {
140                 
141                         WebsiteListCtrlPtr->SetItem(longSelected, 1, wxT(""));
142                 
143                 }               
144         
145                 this->Close();
146         
147         }
148         
151 void frmContactEditorWebsites::SetEditorMode(bool EditMode, SectionType SectType)
153         
154         // Set if the editor is adding or editing an address.
155         // FALSE = Add
156         // TRUE = Edit
157         
158         if (EditMode == FALSE){
159         
160                 EditorMode = FALSE;
161                 btnAction->SetLabel(_("Add"));
162                 this->SetTitle(_("Add Website"));
163         
164         } else if (EditMode == TRUE){
165         
166                 EditorMode = TRUE;
167                 btnAction->SetLabel(_("Modify"));
168                 this->SetTitle(_("Modify Website"));
169                 
170                 std::map<int,int>::iterator intiter;
171                 std::map<int,wxString>::iterator striter;               
172                 wxString strValue;
173                 
174                 // Load the data into the form. Get the website.
175                 
176                 striter = WebsiteListPtr->find(WebsiteListIndex);
177                  
178                 if (striter->first == WebsiteListIndex){
179                 
180                         strValue = striter->second;
181                 
182                 }
183                 
184                 txtWebsite->SetValue(strValue);
185                 
186                 strValue.Clear();
187                 
188                 // Get the website priority.
189                 
190                 intiter = WebsiteListPrefPtr->find(WebsiteListIndex);
191                 
192                 if (intiter->first == WebsiteListIndex && intiter->second > 0 &&
193                         intiter != WebsiteListPrefPtr->end()){
194                 
195                         priorityCtrl->SetValue(intiter->second);
196                         priorityCtrl->EnablePriority(true);
197                 
198                 }               
199                 
200         }
201         
202         EditSectionType = SectType;
203                 
206 void frmContactEditorWebsites::CloseWindow( wxCommandEvent& event )
208         
209         // Close the window.
210         
211         this->Close();
212         
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,
223         int WebsiteIndex )
226         // Setup the pointers.
227         
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;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy