Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed stray carddav.h from frmActivityMgr.h
[xestiaab/.git] / source / contacteditor / frmContactEditorTitles.cpp
1 // frmContactEditorTitles.cpp - frmContactEditorTitles 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 "frmContactEditorTitles.h"
21 #include <map>
22 #include "../enums.h"
23 #include "../common/textprocessing.h"
25 frmContactEditorTitles::frmContactEditorTitles( wxWindow* parent )
26 :
27 frmContactEditorTitlesADT( parent )
28 {
29         
30         // Setup the window.
31         
32         EditorMode = FALSE;
33         sliPriority->Disable();
34 }
36 void frmContactEditorTitles::EnablePriority( wxCommandEvent& event )
37 {
38         
39         // Enable/disable the priority setting.
40         
41         if (chkUsePref->IsChecked()){
42                 sliPriority->Enable();
43         } else {
44                 sliPriority->Disable();
45         }
46         
47 }
49 void frmContactEditorTitles::ProcessAction( wxCommandEvent& event )
50 {
51         
52         // Process action.
53         
54         // Set if the editor is adding or editing an address.
55         // FALSE = Add
56         // TRUE = Edit
58         long ListCtrlIndex;
59         
60         if (EditorMode == FALSE){
61         
62                 wxString strValue;
63                 
64                 // Get the website address.
65                 
66                 TitlesListPtr->insert(std::make_pair(TitlesListIndex, txtTitle->GetValue()));
67                 
68                 // Get the type of website.
69                 
70                 if (EditSectionType == CE_GENERAL){
71                 
72                         TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("")));
73                 
74                 } else if (EditSectionType == CE_HOME) {
75                 
76                         TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("home")));
77                 
78                 } else if (EditSectionType == CE_WORK) {
79                 
80                         TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("work")));
81                 
82                 }
83                 
84                 // Add the website priority.
85                 
86                 if (chkUsePref->IsChecked()){
87                 
88                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, sliPriority->GetValue()));
89                 
90                 } else {
91                 
92                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, 0));          
93                 
94                 }
95                 
96                 // Add to the form.
97                 
98                 wxListItem coldata;
99                 
100                 coldata.SetId(TitlesListIndex);
101                 coldata.SetData(TitlesListIndex);               
102                 coldata.SetText(txtTitle->GetValue());
103                 ListCtrlIndex = TitlesListCtrlPtr->InsertItem(coldata);
104                 
105                 if (chkUsePref->IsChecked()){
106                 
107                         TitlesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
108                 
109                 }               
110         
111                 this->Close();          
112         
113         } else {
114         
115                 // Update the title.
116                 long longSelected = -1;         
117                 wxString strValue;
118                 TitlesListPtr->erase(TitlesListIndex);
119                 TitlesListPtr->insert(std::make_pair(TitlesListIndex, txtTitle->GetValue()));
120                 
121                 // Update the slider priority.
122                 
123                 TitlesListPrefPtr->erase(TitlesListIndex);
124                 
125                 if (chkUsePref->IsChecked()){
126                 
127                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, sliPriority->GetValue()));
128                 
129                 } else {
130                 
131                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, 0));
132                 
133                 }               
134                 
135                 // Update the form.
136                 
137                 longSelected = TitlesListCtrlPtr->GetNextItem(longSelected, 
138                         wxLIST_NEXT_ALL,
139                         wxLIST_STATE_SELECTED);
140                         
141                 if (longSelected == -1){
142                         return;
143                 }               
144                 
145                 TitlesListCtrlPtr->SetItem(longSelected, 0, txtTitle->GetValue());
146                 
147                 if (chkUsePref->IsChecked()){
148                 
149                         TitlesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
150                 
151                 } else {
152                 
153                         TitlesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
154                 
155                 }               
156         
157                 this->Close();
158         
159         }
162 void frmContactEditorTitles::SetEditorMode(bool EditMode, SectionType SectType)
164         
165         // Set the editor mode.
166         
167         // Set if the editor is adding or editing an address.
168         // FALSE = Add
169         // TRUE = Edit
170         
171         if (EditMode == FALSE){
172         
173                 EditorMode = FALSE;
174                 btnAction->SetLabel(_("Add"));
175                 this->SetTitle(_("Add Title"));
176         
177         } else if (EditMode == TRUE){
178         
179                 EditorMode = TRUE;
180                 btnAction->SetLabel(_("Modify"));
181                 this->SetTitle(_("Modify Title"));
182                 
183                 std::map<int,int>::iterator intiter;
184                 std::map<int,wxString>::iterator striter;               
185                 wxString strValue;
186                 
187                 // Load the data into the form. Get the website.
188                 
189                 striter = TitlesListPtr->find(TitlesListIndex);
190                  
191                 if (striter->first == TitlesListIndex &&
192                         striter != TitlesListPtr->end()){
193                 
194                         strValue = striter->second;
195                 
196                 }
197                 
198                 txtTitle->SetValue(strValue);
199                 
200                 strValue.Clear();
201                 
202                 // Get the website priority.
203                 
204                 intiter = TitlesListPrefPtr->find(TitlesListIndex);
205                 
206                 if (intiter->first == TitlesListIndex && intiter->second > 0 &&
207                         intiter != TitlesListPrefPtr->end()){
208                 
209                         sliPriority->SetValue(intiter->second);
210                         sliPriority->Enable();
211                         chkUsePref->SetValue(TRUE);
212                 
213                 }       
214                 
215         }
216         
217         EditSectionType = SectType;
218                 
221 void frmContactEditorTitles::CloseWindow( wxCommandEvent& event )
223         
224         // Close the window.
225         
226         this->Close();
227         
230 void frmContactEditorTitles::SetupPointers(std::map<int, wxString> *TitlesList,
231         std::map<int, wxString> *TitlesListLanguage,
232         std::map<int, wxString> *TitlesListAltID,
233         std::map<int, wxString> *TitlesListPID,
234         std::map<int, wxString> *TitlesListType,
235         std::map<int, wxString> *TitlesListTokens,
236         std::map<int, int> *TitlesListPref,
237         wxListCtrl *TitlesListCtrl,
238         int TitlesIndex )
241         // Setup the pointers.
242         
243         TitlesListPtr = TitlesList;
244         TitlesListLanguagePtr = TitlesListLanguage;
245         TitlesListAltIDPtr = TitlesListAltID;
246         TitlesListPIDPtr = TitlesListPID;
247         TitlesListTypePtr = TitlesListType;
248         TitlesListTokensPtr = TitlesListTokens;
249         TitlesListPrefPtr = TitlesListPref;
250         TitlesListCtrlPtr = TitlesListCtrl;
251         TitlesListIndex = TitlesIndex;
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