Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditorAddress: Implemented priority control
[xestiaab/.git] / source / contacteditor / frmContactEditorAddress.cpp
index f613e0a..a653d27 100644 (file)
@@ -1,3 +1,21 @@
+// frmContactEditorAddress.cpp - frmContactEditorAddress form.
+//
+// (c) 2012-2015 Xestia Software Development.
+//
+// This file is part of Xestia Address Book.
+//
+// Xestia Address Book is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Address Book is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
+
 #include "frmContactEditorAddress.h"
 #include <map>
 #include <wx/tokenzr.h>
@@ -8,8 +26,14 @@ frmContactEditorAddress::frmContactEditorAddress( wxWindow* parent )
 :
 frmContactEditorAddressADT( parent )
 {
+       
+       // Setup the window.
+       
        EditorMode = FALSE;
-       sliPriority->Disable();
+       priorityCtrl = new XABPriorityCtrl(tabGeneral);
+       szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
+       szrGeneral->Layout();
+       
 }
 
 void frmContactEditorAddress::InitAddressEditor( wxInitDialogEvent& event )
@@ -17,18 +41,11 @@ void frmContactEditorAddress::InitAddressEditor( wxInitDialogEvent& event )
        // Do nothing with this subroutine at this time.
 }
 
-void frmContactEditorAddress::EnablePriority( wxCommandEvent& event )
-{
-       if (chkUsePref->IsChecked()){
-               sliPriority->Enable();
-       } else {
-               sliPriority->Disable();
-       }
-}
-
 void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
 {
 
+       // Process data.
+       
        // Check what edit mode we are in and go from there.
        
        long ListCtrlIndex;
@@ -54,7 +71,10 @@ void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
                
                // Add the label to the list (maps).
                
-               AddressListLabelPtr->insert(std::make_pair(AddressListIndex, txtLabel->GetValue()));
+               wxString LabelData = txtLabel->GetValue();
+               LabelData.Prepend("\"");
+               LabelData.Append("\"");
+               AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData));
                
                // Add the language to the list (maps).
                
@@ -88,19 +108,14 @@ void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
                        AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("work")));
                
                }
-               
-               //AddressListTypePtr = &AddressListType;
-               
+
                // Add the mediatype to the list (maps).
                
                AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
                
-               //AddressListMediatypePtr = &AddressListMediatype;
-               //AddressListPrefPtr = &AddressListPref;
+               if (priorityCtrl->IsPriorityChecked()){
                
-               if (chkUsePref->IsChecked()){
-               
-                       AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
+                       AddressListPrefPtr->insert(std::make_pair(AddressListIndex, priorityCtrl->GetValue()));
                
                } else {
                
@@ -121,9 +136,9 @@ void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
                AddressListCtrlPtr->SetItem(ListCtrlIndex, 2, txtCounty->GetValue());
                AddressListCtrlPtr->SetItem(ListCtrlIndex, 3, txtPostCode->GetValue());
                
-               if (chkUsePref->IsChecked()){
+               if (priorityCtrl->IsPriorityChecked()){
                
-                       AddressListCtrlPtr->SetItem(ListCtrlIndex, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
+                       AddressListCtrlPtr->SetItem(ListCtrlIndex, 4, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
                
                }
                
@@ -137,24 +152,6 @@ void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
                wxString strValue;
                long longSelected = -1;
                
-               /*
-               strAddress.Append(wxT(";;"));
-
-               strAddress.Append(txtAddress->GetValue());
-               strAddress.Append(wxT(";"));
-               
-               strAddress.Append(txtTownCity->GetValue());
-               strAddress.Append(wxT(";"));
-               
-               strAddress.Append(txtCounty->GetValue());
-               strAddress.Append(wxT(";"));
-               
-               strAddress.Append(txtPostCode->GetValue());
-               strAddress.Append(wxT(";"));
-
-               strAddress.Append(txtCountry->GetValue());
-               */
-               
                AddressListPtr->erase(AddressListIndex);                
                AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue()));
 
@@ -170,16 +167,16 @@ void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
                AddressListCountryPtr->erase(AddressListIndex);
                AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue()));
                
-               //AddressListLabelPtr = &AddressListLabel;
-               
                // Add the label to the list (maps).
                
                AddressListLabelPtr->erase(AddressListIndex);
-               AddressListLabelPtr->insert(std::make_pair(AddressListIndex, txtLabel->GetValue()));
                
-               // Add the language to the list (maps).
+               wxString LabelData = txtLabel->GetValue();
+               LabelData.Prepend("\"");
+               LabelData.Append("\"");
+               AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData));
                
-               //AddressListLangPtr = &AddressListLang;
+               // Add the language to the list (maps).
                
                AddressListLangPtr->erase(AddressListIndex);
                AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
@@ -202,24 +199,17 @@ void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
                
                AddressListTimezonePtr->erase(AddressListIndex);
                AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
-
-               // No need to update type since it will not have changed.
-               
-               //AddressListTypePtr = &AddressListType;
                
                // Add the mediatype to the list (maps).
                
                AddressListMediatypePtr->erase(AddressListIndex);
                AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
                
-               //AddressListMediatypePtr = &AddressListMediatype;
-               //AddressListPrefPtr = &AddressListPref;
-               
                AddressListPrefPtr->erase(AddressListIndex);
                
-               if (chkUsePref->IsChecked()){
+               if (priorityCtrl->IsPriorityChecked()){
                
-                       AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
+                       AddressListPrefPtr->insert(std::make_pair(AddressListIndex, priorityCtrl->GetValue()));
                
                } else {
                
@@ -242,9 +232,9 @@ void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
                AddressListCtrlPtr->SetItem(longSelected, 2, txtCounty->GetValue());
                AddressListCtrlPtr->SetItem(longSelected, 3, txtPostCode->GetValue());
                
-               if (chkUsePref->IsChecked()){
+               if (priorityCtrl->IsPriorityChecked()){
                
-                       AddressListCtrlPtr->SetItem(longSelected, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
+                       AddressListCtrlPtr->SetItem(longSelected, 4, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
                
                } else {
                
@@ -260,12 +250,18 @@ void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
 
 void frmContactEditorAddress::CloseWindow( wxCommandEvent& event )
 {
+       
+       // Close the window.
+       
        this->Close();
+       
 }
 
 void frmContactEditorAddress::CopyAddress( wxCommandEvent& event )
 {
 
+       // Copy the address.
+       
        wxString MailingLabel;
        bool AddComma = FALSE;
        
@@ -338,6 +334,9 @@ void frmContactEditorAddress::CopyAddress( wxCommandEvent& event )
 
 void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType )
 {
+       
+       // Set the editor mode.
+       
        // Set if the editor is adding or editing an address.
        // FALSE = Add
        // TRUE = Edit
@@ -363,7 +362,8 @@ void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType
                
                striter = AddressListPtr->find(AddressListIndex);
                 
-               if (striter->first == AddressListIndex){
+               if (striter->first == AddressListIndex &&
+                 striter != AddressListPtr->end()){
                
                        txtAddress->SetValue(striter->second);
                
@@ -371,7 +371,8 @@ void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType
                
                striter = AddressListTownPtr->find(AddressListIndex);
 
-               if (striter->first == AddressListIndex){
+               if (striter->first == AddressListIndex &&
+                 striter != AddressListTownPtr->end()){
                
                        txtTownCity->SetValue(striter->second);
                
@@ -379,7 +380,8 @@ void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType
                
                striter = AddressListCountyPtr->find(AddressListIndex);
 
-               if (striter->first == AddressListIndex){
+               if (striter->first == AddressListIndex &&
+                 striter != AddressListCountyPtr->end()){
                
                        txtCounty->SetValue(striter->second);
                
@@ -387,7 +389,8 @@ void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType
 
                striter = AddressListPostCodePtr->find(AddressListIndex);
 
-               if (striter->first == AddressListIndex){
+               if (striter->first == AddressListIndex &&
+                 striter != AddressListPostCodePtr->end()){
                
                        txtPostCode->SetValue(striter->second);
                
@@ -395,24 +398,22 @@ void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType
 
                striter = AddressListCountryPtr->find(AddressListIndex);
 
-               if (striter->first == AddressListIndex){
+               if (striter->first == AddressListIndex &&
+                 striter != AddressListCountryPtr->end()){
                
                        txtCountry->SetValue(striter->second);
                
                }
                
-               //CaptureString(&strValue, TRUE);
-               //->Replace(wxT("\;"), wxT("\;;"), TRUE);
-               
                // Setup the Slider.
                
                intiter = AddressListPrefPtr->find(AddressListIndex);
                
-               if (intiter->first == AddressListIndex && intiter->second > 0){
+               if (intiter->first == AddressListIndex && intiter->second > 0 && intiter != AddressListPrefPtr->end() &&
+                 intiter != AddressListPrefPtr->end()){
                
-                       sliPriority->SetValue(intiter->second);
-                       sliPriority->Enable();
-                       chkUsePref->SetValue(TRUE);
+                       priorityCtrl->SetValue(intiter->second);
+                       priorityCtrl->EnablePriority(true);
                
                }
                
@@ -420,9 +421,14 @@ void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType
                
                striter = AddressListLabelPtr->find(AddressListIndex);
                 
-               if (striter->first == AddressListIndex){
+               if (striter->first == AddressListIndex && striter != AddressListLabelPtr->end() &&
+                 striter != AddressListLabelPtr->end()){
                
                        strValue = striter->second;
+                       if (strValue.Left(1) == "\"" && strValue.Right(1) == "\""){
+                               strValue.erase(0, 1);
+                               strValue.RemoveLast();
+                       }
                
                }
 
@@ -432,17 +438,17 @@ void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType
                
                striter = AddressListLangPtr->find(AddressListIndex);
                 
-               if (striter->first == AddressListIndex){
+               if (striter->first == AddressListIndex && striter != AddressListLangPtr->end()){
                
                        strValue = striter->second;
-               
+
                }       
                
                cmbLanguage->SetValue(strValue);
                
                striter = AddressListGeoPtr->find(AddressListIndex);
                 
-               if (striter->first == AddressListIndex){
+               if (striter->first == AddressListIndex && striter != AddressListGeoPtr->end()){
                
                        strValue = striter->second;
                
@@ -452,7 +458,7 @@ void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType
                
                striter = AddressListTimezonePtr->find(AddressListIndex);
                 
-               if (striter->first == AddressListIndex){
+               if (striter->first == AddressListIndex && striter != AddressListTimezonePtr->end()){
                
                        strValue = striter->second;
                
@@ -484,6 +490,8 @@ void frmContactEditorAddress::SetupPointers( std::map<int, wxString> *AddressLis
        int AddressIndex )
 {
 
+       // Setup the pointers.
+       
        AddressListPtr = AddressList;
        AddressListTownPtr = AddressListTown;
        AddressListCountyPtr = AddressListCounty;
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