Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added copyright and license header to the C++ source and header files in the contacte...
[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         EditorMode = FALSE;
30         sliPriority->Disable();
31 }
33 void frmContactEditorWebsites::EnablePriority( wxCommandEvent& event )
34 {
35         if (chkUsePref->IsChecked()){
36                 sliPriority->Enable();
37         } else {
38                 sliPriority->Disable();
39         }
40 }
42 void frmContactEditorWebsites::ProcessAction( wxCommandEvent& event )
43 {
44         // Set if the editor is adding or editing an address.
45         // FALSE = Add
46         // TRUE = Edit
48         long ListCtrlIndex;
49         
50         if (EditorMode == FALSE){
51         
52                 wxString strValue;
53                 
54                 // Get the website address.
55                 
56                 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
57                 
58                 // Get the type of website.
59                 
60                 if (EditSectionType == CE_GENERAL){
61                 
62                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("")));
63                 
64                 } else if (EditSectionType == CE_HOME) {
65                 
66                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("home")));
67                 
68                 } else if (EditSectionType == CE_WORK) {
69                 
70                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("work")));
71                 
72                 }
73                 
74                 // Add the website priority.
75                 
76                 if (chkUsePref->IsChecked()){
77                 
78                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, sliPriority->GetValue()));
79                 
80                 } else {
81                 
82                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));                
83                 
84                 }
85                 
86                 // Add to the form.
87                 
88                 wxListItem coldata;
89                 
90                 coldata.SetId(WebsiteListIndex);
91                 coldata.SetData(WebsiteListIndex);              
92                 coldata.SetText(txtWebsite->GetValue());
93                 ListCtrlIndex = WebsiteListCtrlPtr->InsertItem(coldata);
94                 
95                 if (chkUsePref->IsChecked()){
96                 
97                         WebsiteListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
98                 
99                 }               
100         
101                 this->Close();          
102         
103         } else {
104         
105                 // Update the website address.
106                 long longSelected = -1;         
107                 wxString strValue;              
108                 WebsiteListPtr->erase(WebsiteListIndex);
109                 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
110                 
111                 // Update the slider priority.
112                 
113                 WebsiteListPrefPtr->erase(WebsiteListIndex);
114                 
115                 if (chkUsePref->IsChecked()){
116                 
117                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, sliPriority->GetValue()));
118                 
119                 } else {
120                 
121                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));
122                 
123                 }               
124                 
125                 // Update the form.
126                 
127                 longSelected = WebsiteListCtrlPtr->GetNextItem(longSelected, 
128                         wxLIST_NEXT_ALL,
129                         wxLIST_STATE_SELECTED);
130                         
131                 if (longSelected == -1){
132                         return;
133                 }               
134                 
135                 WebsiteListCtrlPtr->SetItem(longSelected, 0, txtWebsite->GetValue());
136                 
137                 if (chkUsePref->IsChecked()){
138                 
139                         WebsiteListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
140                 
141                 } else {
142                 
143                         WebsiteListCtrlPtr->SetItem(longSelected, 1, wxT(""));
144                 
145                 }               
146         
147                 this->Close();
148         
149         }
152 void frmContactEditorWebsites::SetEditorMode(bool EditMode, SectionType SectType)
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                 
194                         sliPriority->SetValue(intiter->second);
195                         sliPriority->Enable();
196                         chkUsePref->SetValue(TRUE);
197                 
198                 }               
199                 
200         }
201         
202         EditSectionType = SectType;
203                 
206 void frmContactEditorWebsites::CloseWindow( wxCommandEvent& event )
208         this->Close();
211 void frmContactEditorWebsites::SetupPointers(std::map<int, wxString> *WebsiteList,
212         std::map<int, wxString> *WebsiteListAltID,
213         std::map<int, wxString> *WebsiteListPID,
214         std::map<int, wxString> *WebsiteListType,
215         std::map<int, wxString> *WebsiteListTokens,
216         std::map<int, wxString> *WebsiteListMediatype,
217         std::map<int, int> *WebsiteListPref,
218         wxListCtrl *WebsiteListCtrl,
219         int WebsiteIndex )
222         WebsiteListPtr = WebsiteList;
223         WebsiteListAltIDPtr = WebsiteListAltID;
224         WebsiteListPIDPtr = WebsiteListPID;
225         WebsiteListTypePtr = WebsiteListType;
226         WebsiteListTokensPtr = WebsiteListTokens;
227         WebsiteListMediatypePtr = WebsiteListMediatype;
228         WebsiteListPrefPtr = WebsiteListPref;
229         WebsiteListCtrlPtr = WebsiteListCtrl;
230         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