Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial import of code already done for Xestia Address Book
[xestiaab/.git] / source / contacteditor / frmContactEditorWebsites.cpp
1 #include "frmContactEditorWebsites.h"
3 #include <map>
4 #include "../enums.h"
5 #include "../common/textprocessing.h"
7 frmContactEditorWebsites::frmContactEditorWebsites( wxWindow* parent )
8 :
9 frmContactEditorWebsitesADT( parent )
10 {
11         EditorMode = FALSE;
12         sliPriority->Disable();
13 }
15 void frmContactEditorWebsites::EnablePriority( wxCommandEvent& event )
16 {
17         if (chkUsePref->IsChecked()){
18                 sliPriority->Enable();
19         } else {
20                 sliPriority->Disable();
21         }
22 }
24 void frmContactEditorWebsites::ProcessAction( wxCommandEvent& event )
25 {
26         // Set if the editor is adding or editing an address.
27         // FALSE = Add
28         // TRUE = Edit
30         long ListCtrlIndex;
31         
32         if (EditorMode == FALSE){
33         
34                 wxString strValue;
35                 
36                 // Get the website address.
37                 
38                 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
39                 
40                 // Get the type of website.
41                 
42                 if (EditSectionType == CE_GENERAL){
43                 
44                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("")));
45                 
46                 } else if (EditSectionType == CE_HOME) {
47                 
48                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("home")));
49                 
50                 } else if (EditSectionType == CE_WORK) {
51                 
52                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("work")));
53                 
54                 }
55                 
56                 // Add the website priority.
57                 
58                 if (chkUsePref->IsChecked()){
59                 
60                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, sliPriority->GetValue()));
61                 
62                 } else {
63                 
64                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));                
65                 
66                 }
67                 
68                 // Add to the form.
69                 
70                 wxListItem coldata;
71                 
72                 coldata.SetId(WebsiteListIndex);
73                 coldata.SetData(WebsiteListIndex);              
74                 coldata.SetText(txtWebsite->GetValue());
75                 ListCtrlIndex = WebsiteListCtrlPtr->InsertItem(coldata);
76                 
77                 if (chkUsePref->IsChecked()){
78                 
79                         WebsiteListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
80                 
81                 }               
82         
83                 this->Close();          
84         
85         } else {
86         
87                 // Update the website address.
88                 long longSelected = -1;         
89                 wxString strValue;              
90                 WebsiteListPtr->erase(WebsiteListIndex);
91                 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
92                 
93                 // Update the slider priority.
94                 
95                 WebsiteListPrefPtr->erase(WebsiteListIndex);
96                 
97                 if (chkUsePref->IsChecked()){
98                 
99                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, sliPriority->GetValue()));
100                 
101                 } else {
102                 
103                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));
104                 
105                 }               
106                 
107                 // Update the form.
108                 
109                 longSelected = WebsiteListCtrlPtr->GetNextItem(longSelected, 
110                         wxLIST_NEXT_ALL,
111                         wxLIST_STATE_SELECTED);
112                         
113                 if (longSelected == -1){
114                         return;
115                 }               
116                 
117                 WebsiteListCtrlPtr->SetItem(longSelected, 0, txtWebsite->GetValue());
118                 
119                 if (chkUsePref->IsChecked()){
120                 
121                         WebsiteListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
122                 
123                 } else {
124                 
125                         WebsiteListCtrlPtr->SetItem(longSelected, 1, wxT(""));
126                 
127                 }               
128         
129                 this->Close();
130         
131         }
134 void frmContactEditorWebsites::SetEditorMode(bool EditMode, SectionType SectType)
136         // Set if the editor is adding or editing an address.
137         // FALSE = Add
138         // TRUE = Edit
139         
140         if (EditMode == FALSE){
141         
142                 EditorMode = FALSE;
143                 btnAction->SetLabel(_("Add"));
144                 this->SetTitle(_("Add Website"));
145         
146         } else if (EditMode == TRUE){
147         
148                 EditorMode = TRUE;
149                 btnAction->SetLabel(_("Modify"));
150                 this->SetTitle(_("Modify Website"));
151                 
152                 std::map<int,int>::iterator intiter;
153                 std::map<int,wxString>::iterator striter;               
154                 wxString strValue;
155                 
156                 // Load the data into the form. Get the website.
157                 
158                 striter = WebsiteListPtr->find(WebsiteListIndex);
159                  
160                 if (striter->first == WebsiteListIndex){
161                 
162                         strValue = striter->second;
163                 
164                 }
165                 
166                 txtWebsite->SetValue(strValue);
167                 
168                 strValue.Clear();
169                 
170                 // Get the website priority.
171                 
172                 intiter = WebsiteListPrefPtr->find(WebsiteListIndex);
173                 
174                 if (intiter->first == WebsiteListIndex && intiter->second > 0){
175                 
176                         sliPriority->SetValue(intiter->second);
177                         sliPriority->Enable();
178                         chkUsePref->SetValue(TRUE);
179                 
180                 }               
181                 
182         }
183         
184         EditSectionType = SectType;
185                 
188 void frmContactEditorWebsites::CloseWindow( wxCommandEvent& event )
190         this->Close();
193 void frmContactEditorWebsites::SetupPointers(std::map<int, wxString> *WebsiteList,
194         std::map<int, wxString> *WebsiteListAltID,
195         std::map<int, wxString> *WebsiteListPID,
196         std::map<int, wxString> *WebsiteListType,
197         std::map<int, wxString> *WebsiteListTokens,
198         std::map<int, wxString> *WebsiteListMediatype,
199         std::map<int, int> *WebsiteListPref,
200         wxListCtrl *WebsiteListCtrl,
201         int WebsiteIndex )
204         WebsiteListPtr = WebsiteList;
205         WebsiteListAltIDPtr = WebsiteListAltID;
206         WebsiteListPIDPtr = WebsiteListPID;
207         WebsiteListTypePtr = WebsiteListType;
208         WebsiteListTokensPtr = WebsiteListTokens;
209         WebsiteListMediatypePtr = WebsiteListMediatype;
210         WebsiteListPrefPtr = WebsiteListPref;
211         WebsiteListCtrlPtr = WebsiteListCtrl;
212         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