Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed stray carddav.h from frmActivityMgr.h
[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         sliPriority->Disable();
34         
35 }
37 void frmContactEditorWebsites::EnablePriority( wxCommandEvent& event )
38 {
39         
40         // Enable the priority setting.
41         
42         if (chkUsePref->IsChecked()){
43                 sliPriority->Enable();
44         } else {
45                 sliPriority->Disable();
46         }
47         
48 }
50 void frmContactEditorWebsites::ProcessAction( wxCommandEvent& event )
51 {
52         
53         // Set if the editor is adding or editing an address.
54         // FALSE = Add
55         // TRUE = Edit
57         long ListCtrlIndex;
58         
59         if (EditorMode == FALSE){
60         
61                 wxString strValue;
62                 
63                 // Get the website address.
64                 
65                 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
66                 
67                 // Get the type of website.
68                 
69                 if (EditSectionType == CE_GENERAL){
70                 
71                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("")));
72                 
73                 } else if (EditSectionType == CE_HOME) {
74                 
75                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("home")));
76                 
77                 } else if (EditSectionType == CE_WORK) {
78                 
79                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("work")));
80                 
81                 }
82                 
83                 // Add the website priority.
84                 
85                 if (chkUsePref->IsChecked()){
86                 
87                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, sliPriority->GetValue()));
88                 
89                 } else {
90                 
91                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));                
92                 
93                 }
94                 
95                 // Add to the form.
96                 
97                 wxListItem coldata;
98                 
99                 coldata.SetId(WebsiteListIndex);
100                 coldata.SetData(WebsiteListIndex);              
101                 coldata.SetText(txtWebsite->GetValue());
102                 ListCtrlIndex = WebsiteListCtrlPtr->InsertItem(coldata);
103                 
104                 if (chkUsePref->IsChecked()){
105                 
106                         WebsiteListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
107                 
108                 }               
109         
110                 this->Close();          
111         
112         } else {
113         
114                 // Update the website address.
115                 long longSelected = -1;         
116                 wxString strValue;              
117                 WebsiteListPtr->erase(WebsiteListIndex);
118                 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
119                 
120                 // Update the slider priority.
121                 
122                 WebsiteListPrefPtr->erase(WebsiteListIndex);
123                 
124                 if (chkUsePref->IsChecked()){
125                 
126                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, sliPriority->GetValue()));
127                 
128                 } else {
129                 
130                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));
131                 
132                 }               
133                 
134                 // Update the form.
135                 
136                 longSelected = WebsiteListCtrlPtr->GetNextItem(longSelected, 
137                         wxLIST_NEXT_ALL,
138                         wxLIST_STATE_SELECTED);
139                         
140                 if (longSelected == -1){
141                         return;
142                 }               
143                 
144                 WebsiteListCtrlPtr->SetItem(longSelected, 0, txtWebsite->GetValue());
145                 
146                 if (chkUsePref->IsChecked()){
147                 
148                         WebsiteListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
149                 
150                 } else {
151                 
152                         WebsiteListCtrlPtr->SetItem(longSelected, 1, wxT(""));
153                 
154                 }               
155         
156                 this->Close();
157         
158         }
159         
162 void frmContactEditorWebsites::SetEditorMode(bool EditMode, SectionType SectType)
164         
165         // Set if the editor is adding or editing an address.
166         // FALSE = Add
167         // TRUE = Edit
168         
169         if (EditMode == FALSE){
170         
171                 EditorMode = FALSE;
172                 btnAction->SetLabel(_("Add"));
173                 this->SetTitle(_("Add Website"));
174         
175         } else if (EditMode == TRUE){
176         
177                 EditorMode = TRUE;
178                 btnAction->SetLabel(_("Modify"));
179                 this->SetTitle(_("Modify Website"));
180                 
181                 std::map<int,int>::iterator intiter;
182                 std::map<int,wxString>::iterator striter;               
183                 wxString strValue;
184                 
185                 // Load the data into the form. Get the website.
186                 
187                 striter = WebsiteListPtr->find(WebsiteListIndex);
188                  
189                 if (striter->first == WebsiteListIndex){
190                 
191                         strValue = striter->second;
192                 
193                 }
194                 
195                 txtWebsite->SetValue(strValue);
196                 
197                 strValue.Clear();
198                 
199                 // Get the website priority.
200                 
201                 intiter = WebsiteListPrefPtr->find(WebsiteListIndex);
202                 
203                 if (intiter->first == WebsiteListIndex && intiter->second > 0 &&
204                         intiter != WebsiteListPrefPtr->end()){
205                 
206                         sliPriority->SetValue(intiter->second);
207                         sliPriority->Enable();
208                         chkUsePref->SetValue(TRUE);
209                 
210                 }               
211                 
212         }
213         
214         EditSectionType = SectType;
215                 
218 void frmContactEditorWebsites::CloseWindow( wxCommandEvent& event )
220         
221         // Close the window.
222         
223         this->Close();
224         
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,
235         int WebsiteIndex )
238         // Setup the pointers.
239         
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;
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