Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed references to the boost library in remaining source and header files.
[xestiaab/.git] / source / contacteditor / frmContactEditorKey.cpp
1 // frmContactEditorKey.cpp - frmContactEditorKey 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 "frmContactEditorKey.h"
20 #include <wx/tokenzr.h>
21 #include "../common/textprocessing.h"
22 #include "../common/base64.h"
24 frmContactEditorKey::frmContactEditorKey( wxWindow* parent )
25 :
26 frmContactEditorKeyADT( parent )
27 {
28         EditorMode = FALSE;
29         sliPriority->Disable();
30         
31         // Setup the control boxes and hide tabs unless they are
32         // needed.
33         
34         tabURL->Hide();
35         tabKey->Hide();
36         
37         cmbKeyMainType->Append(_("URL"));
38         cmbKeyMainType->Append(_("Key"));
39         
40         cmbType->Append(_("Home"));
41         cmbType->Append(_("Work"));
42         
43         cmbURL->Append(_("PGP Key"));
44         
45         cmbKeyType->Append(_("PGP Key"));
47 }
49 void frmContactEditorKey::EnablePriority( wxCommandEvent& event )
50 {
51         if (chkUsePref->IsChecked()){
52                 sliPriority->Enable();
53         } else {
54                 sliPriority->Disable();
55         }
56 }
58 void frmContactEditorKey::SetEditorMode(bool EditMode)
59 {
60         // Set if the editor is adding or editing an address.
61         // FALSE = Add
62         // TRUE = Edit
63         
64         if (EditMode == FALSE){
65         
66                 EditorMode = FALSE;
67                 btnAction->SetLabel(_("Add"));
68                 this->SetTitle(_("Add Key"));
69         
70         } else if (EditMode == TRUE){
71         
72                 EditorMode = TRUE;
73                 btnAction->SetLabel(_("Modify"));
74                 this->SetTitle(_("Modify Key"));
75                 
76                 std::map<int,bool>::iterator booliter;
77                 std::map<int,int>::iterator intiter;
78                 std::map<int,wxString>::iterator striter;               
79                 wxString strValue;
80                 bool boolKeyData = FALSE;       
81                 
82                 // Get the key data type.
83                 
84                 booliter = KeyListKeyTypePtr->find(KeyListIndex);
85                 
86                 if (booliter->first == KeyListIndex){
87                 
88                         boolKeyData = booliter->second;
89                 
90                 }
91                 
92                 // Get the data depending on key data type.             
93                 
94                 if (boolKeyData == FALSE){
95                 
96                         // Setup the URL.
97                 
98                         cmbKeyMainType->SetSelection(0);
99                         
100                         striter = KeyListPtr->find(KeyListIndex);
101                         
102                         if (striter->first == KeyListIndex){
103                         
104                                 strValue = striter->second;
105                         
106                         }
107                         
108                         txtAddress->ChangeValue(strValue);
109                         strValue.Clear();
110                         
111                         striter = KeyListDataTypePtr->find(KeyListIndex);
112                         
113                         if (striter->first == KeyListIndex){
114                         
115                                 strValue = striter->second;
116                         
117                         }                       
118                         
119                         cmbURL->SetValue(strValue);
120                 
121                 } else if (boolKeyData == TRUE){
122                 
123                         // Setup the key.
124                 
125                         cmbKeyMainType->SetSelection(1);
126                         std::string base64dec;
127                         
128                         // Decode the base64 data.
129                         
130                         striter = KeyListPtr->find(KeyListIndex);
131                         
132                         if (striter->first == KeyListIndex){
133                         
134                                 strValue = striter->second;
135                         
136                         }
137                         
138                         std::string base64enc = std::string(strValue.mb_str());
139                         base64dec = base64_decode(base64enc);
140                         
141                         strValue.Clear();
142                         wxString strValue(base64dec.c_str(), wxConvUTF8);
143                         
144                         txtKeyData->SetValue(strValue);         
145                         
146                         // Get the key data type.
147                         
148                         strValue.Clear();
149                         
150                         striter = KeyListDataTypePtr->find(KeyListIndex);
151                         
152                         if (striter->first == KeyListIndex){
153                         
154                                 strValue = striter->second;
155                         
156                         }                       
157                         
158                         cmbKeyType->SetValue(strValue);                         
159                 
160                 }
161                 
162                 ProcessKeyType();
163                 
164                 // Get the type.
165                 
166                 striter = KeyListTypePtr->find(KeyListIndex);   
167                 
168                 if (striter->first == KeyListIndex){
169                 
170                         strValue = striter->second;
171                 
172                 }               
173                 
174                 if (strValue == wxT("home")){
175                 
176                         cmbType->SetSelection(0);
177                 
178                 } else if (strValue == wxT("work")){
179                 
180                         cmbType->SetSelection(1);       
181                 
182                 } else {
183                 
184                         //cmbType->SetSelection(-1);
185                 
186                 }
187                 
188                 // Get the key priority.
189                 
190                 intiter = KeyListPrefPtr->find(KeyListIndex);
191                 
192                 if (intiter->first == KeyListIndex && intiter->second > 0){
193                 
194                         sliPriority->SetValue(intiter->second);
195                         sliPriority->Enable();
196                         chkUsePref->SetValue(TRUE);
197                 
198                 }
199                 
200         }
201                 
204 void frmContactEditorKey::ProcessAction( wxCommandEvent& event )
206         long ListCtrlIndex;
207         int intKeyType = 0;
208         
209         intKeyType = cmbKeyMainType->GetCurrentSelection();
210         
211         if (intKeyType == -1){
212         
213                 // No option selected so do nothing.
214         
215                 return;
216         
217         }
218         
219         if (EditorMode == FALSE){
221                 wxString strValue;
222                 wxListItem coldata;             
223                 
224                 coldata.SetId(KeyListIndex);
225                 coldata.SetData(KeyListIndex);
226                 ListCtrlIndex = KeyListCtrlPtr->InsertItem(coldata);            
227                 
228                 // Get Key data.
229                 
230                 if (intKeyType == 0){
231                 
232                         // URL is text.
233                                         
234                         KeyListPtr->insert(std::make_pair(KeyListIndex, txtAddress->GetValue()));
236                         coldata.SetText(txtAddress->GetValue());
237                         KeyListCtrlPtr->SetItem(ListCtrlIndex, 0, strValue);
238                         KeyListKeyTypePtr->insert(std::make_pair(KeyListIndex, FALSE));
239                 
240                 } else if (intKeyType == 1){
241                 
242                         // Encode the data in the text to base64.
243                         
244                         wxString wxSb64orig = txtKeyData->GetValue();
245                         std::string base64new = std::string(wxSb64orig.mb_str());
246                         std::string base64enc = base64_encode(reinterpret_cast<const unsigned char*>(base64new.c_str()), (int)base64new.length());
247                         wxString wxSb64key(base64enc.c_str(), wxConvUTF8);
248                         
249                         KeyListPtr->insert(std::make_pair(KeyListIndex, wxSb64key));
250                         KeyListDataTypePtr->insert(std::make_pair(KeyListIndex, cmbKeyType->GetValue()));
251                         KeyListCtrlPtr->SetItem(ListCtrlIndex, 0, _("PGP Key"));
252                         KeyListKeyTypePtr->insert(std::make_pair(KeyListIndex, TRUE));                  
253                 
254                 }
255                 
256                 // Get Key type.
257                 
258                 strValue.Clear();
259                 strValue = cmbType->GetString(cmbType->GetSelection());
261                 if (strValue == _("Home")) {
262                 
263                         KeyListTypePtr->insert(std::make_pair(KeyListIndex, wxT("home")));
264                         KeyListCtrlPtr->SetItem(ListCtrlIndex, 1, strValue);
265                 
266                 } else if (strValue == _("Work")) {
267                 
268                         KeyListTypePtr->insert(std::make_pair(KeyListIndex, wxT("work")));
269                         KeyListCtrlPtr->SetItem(ListCtrlIndex, 1, strValue);                    
270                 
271                 } else {
272                 
273                         KeyListTypePtr->insert(std::make_pair(KeyListIndex, wxT("")));                  
274                 
275                 }
276                 
277                 // Get Key priority.
278                 
279                 if (chkUsePref->IsChecked()){
280                 
281                         KeyListPrefPtr->insert(std::make_pair(KeyListIndex, sliPriority->GetValue()));
282                         KeyListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));                        
283                 
284                 } else {
285                 
286                         KeyListPrefPtr->insert(std::make_pair(KeyListIndex, 0));
287                 
288                 }
289                 
290                 if (chkUsePref->IsChecked()){
291                 
292                 }
293                 
294                 this->Close();
295                 
296         } else if (EditorMode == TRUE){
298                 long longSelected = -1; 
299                 wxString strValue;              
300                 
301                 longSelected = KeyListCtrlPtr->GetNextItem(longSelected, 
302                         wxLIST_NEXT_ALL,
303                         wxLIST_STATE_SELECTED);
304                         
305                 if (longSelected == -1){
306                         return;
307                 }
308                 
309                 // Update Key data.             
310                 
311                 if (intKeyType == 0){
312                 
313                         // URL is text.
314                                         
315                         KeyListPtr->erase(KeyListIndex);
316                         KeyListPtr->insert(std::make_pair(KeyListIndex, txtAddress->GetValue()));
318                         KeyListCtrlPtr->SetItem(longSelected, 0, strValue);
319                         KeyListKeyTypePtr->erase(KeyListIndex);                 
320                         KeyListKeyTypePtr->insert(std::make_pair(KeyListIndex, FALSE));
321                 
322                 } else if (intKeyType == 1){
323                 
324                         // Encode the data in the text to base64.
325                         
326                         wxString wxSb64orig = txtKeyData->GetValue();
327                         std::string base64new = std::string(wxSb64orig.mb_str());
328                         std::string base64enc = base64_encode(reinterpret_cast<const unsigned char*>(base64new.c_str()), (int)base64new.length());
329                         wxString wxSb64key(base64enc.c_str(), wxConvUTF8);
330                         
331                         KeyListPtr->erase(KeyListIndex);                        
332                         KeyListPtr->insert(std::make_pair(KeyListIndex, wxSb64key));
333                         
334                         KeyListDataTypePtr->erase(KeyListIndex);
335                         KeyListDataTypePtr->insert(std::make_pair(KeyListIndex, cmbKeyType->GetValue()));
336                         
337                         KeyListCtrlPtr->SetItem(longSelected, 0, _("PGP Key"));
338                         
339                         KeyListKeyTypePtr->erase(KeyListIndex);
340                         KeyListKeyTypePtr->insert(std::make_pair(KeyListIndex, TRUE));                  
341                 
342                 }
343                 
344                 // Update Key type.
345                 
346                 strValue.Clear();
347                 strValue = cmbType->GetString(cmbType->GetSelection());
349                 KeyListTypePtr->erase(KeyListIndex);
351                 if (strValue == _("Home")) {
352                 
353                         KeyListTypePtr->insert(std::make_pair(KeyListIndex, wxT("home")));
354                         KeyListCtrlPtr->SetItem(longSelected, 1, strValue);
355                 
356                 } else if (strValue == _("Work")) {
357                 
358                         KeyListTypePtr->insert(std::make_pair(KeyListIndex, wxT("work")));
359                         KeyListCtrlPtr->SetItem(longSelected, 1, strValue);                     
360                 
361                 } else {
362                 
363                         KeyListTypePtr->insert(std::make_pair(KeyListIndex, wxT("")));                  
364                 
365                 }
366                 
367                 // Update the key priority.
368                 
369                 KeyListPrefPtr->erase(KeyListIndex);            
370                 
371                 if (chkUsePref->IsChecked()){
372                 
373                         KeyListPrefPtr->insert(std::make_pair(KeyListIndex, sliPriority->GetValue()));
374                         KeyListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
375                 
376                 } else {
377                 
378                         KeyListPrefPtr->insert(std::make_pair(KeyListIndex, 0));
379                 
380                 }
381                 
382                 this->Close();  
383         
384         }
387 void frmContactEditorKey::ProcessKeyType( wxCommandEvent& event )
390         int intKeyType = 0;
391         
392         intKeyType = cmbKeyMainType->GetCurrentSelection();
393         
394         if (intKeyType == 0){
395         
396                 tabURL->Show();
397                 tabKey->Hide();
398         
399         } else if (intKeyType == 1){
400         
401                 tabURL->Hide();
402                 tabKey->Show();
403         
404         }
408 void frmContactEditorKey::ProcessKeyType()
411         int intKeyType = 0;
412         
413         intKeyType = cmbKeyMainType->GetCurrentSelection();
414         
415         if (intKeyType == 0){
416         
417                 tabURL->Show();
418                 tabKey->Hide();
419         
420         } else if (intKeyType == 1){
421         
422                 tabURL->Hide();
423                 tabKey->Show();
424         
425         }
429 void frmContactEditorKey::ConvertURLType( wxCommandEvent& event )
432         wxString strValue;
434         strValue = cmbURL->GetString(cmbURL->GetCurrentSelection());
435         
436         if (strValue == _("PGP Key")){
437         
438                 cmbURL->SetValue(wxT("application/pgp-keys"));
439         
440         }
444 void frmContactEditorKey::ConvertKeyType( wxCommandEvent& event )
447         wxString strValue;
449         strValue = cmbKeyType->GetString(cmbKeyType->GetCurrentSelection());
450         
451         if (strValue == _("PGP Key")){
452         
453                 cmbKeyType->SetValue(wxT("application/pgp-keys"));
454         
455         }
459 void frmContactEditorKey::CloseWindow( wxCommandEvent& event )
461         this->Close();
464 void frmContactEditorKey::SetupPointers(std::map<int, wxString> *KeyList,
465         std::map<int, wxString> *KeyListAltID,
466         std::map<int, wxString> *KeyListPID,
467         std::map<int, bool> *KeyListKeyType,    
468         std::map<int, wxString> *KeyListDataType,       
469         std::map<int, wxString> *KeyListType,
470         std::map<int, wxString> *KeyListTokens,
471         std::map<int, int> *KeyListPref,
472         wxListCtrl *KeyListCtrl,
473         int KeyIndex )
476         KeyListPtr = KeyList;
477         KeyListAltIDPtr = KeyListAltID;
478         KeyListPIDPtr = KeyListPID;
479         KeyListKeyTypePtr = KeyListKeyType;     
480         KeyListDataTypePtr = KeyListDataType;
481         KeyListTypePtr = KeyListType;
482         KeyListTokensPtr = KeyListTokens;
483         KeyListPrefPtr = KeyListPref;
484         KeyListCtrlPtr = KeyListCtrl;
485         KeyListIndex = KeyIndex;
486         
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