Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
utf8: Implemented further UTF8 support
[xestiacalendar/.git] / source / forms / calendareditor / frmCalendarEditor.cpp
1 // frmCalendarEditor.cpp - frmCalendarEditor form functions.
2 //
3 // (c) 2016-2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
7 // Xestia Calendar 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 Calendar 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 Calendar. If not, see <http://www.gnu.org/licenses/>
19 #include "frmCalendarEditor.h"
21 using namespace std;
23 frmCalendarEditor::frmCalendarEditor( wxWindow* parent )
24 :
25 frmCalendarEditorADT( parent )
26 {
28 }
30 void frmCalendarEditor::SetMode(bool setMode){
31         
32         editMode = setMode;
33         
34         if (editMode == true){
35                 
36                 lblAccount->Show(false);
37                 cmbAccount->Show(false);
38                 btnCreate->SetLabel(_("Update"));
39                 
40         }
41         
42 }
44 void frmCalendarEditor::CloseWindow( wxCommandEvent &event )
45 {
46         
47         this->Close();
48         
49 }
51 void frmCalendarEditor::SetupAccounts(XCALPreferences *preferencesData){
52         
53         for (int accountSeek = 0; accountSeek < preferencesData->accounts.GetCount(); accountSeek++){
54                 
55                 // Check if the account is a supported type before adding.
56                 
57                 if (preferencesData->accounts.GetAccountType(accountSeek) != wxT("Local")){
58                         
59                         // Go to the next account.
60                         
61                         continue;
62                         
63                 }
64                 
65                 cmbAccount->Append(preferencesData->accounts.GetAccountName(accountSeek));
66                 accountPrefencesIDList.push_back(accountSeek);
67                 
68         }
69         
70         this->preferencesData = preferencesData;
71         
72 }
74 void frmCalendarEditor::ProcessCalendar( wxCommandEvent &event ){
75         
76         // Check that an account has been selected before continuing.
77         
78         if (cmbAccount->GetCurrentSelection() == -1 && editMode == false){
79                 wxMessageBox(_("No account was selected for this calendar."), _("Error"));
80                 return;
81         }
82         
83         // Check that the calendar has a name before continuing.
84         
85         if (txtName->IsEmpty()){
86                 wxMessageBox(_("No name for the calendar has been entered."), _("Error"));
87                 return;
88         }
89         
90         // Post an event to the main window to create or edit the calendar with the
91         // details given.
92         
93         CalendarProperties *calendarInfo = new CalendarProperties;
94         
95         // Setup the data.
96         
97         if (editMode == true){
98                 
99                 calendarInfo->accountPreferencesID = accountPrefencesIDList[cmbAccount->GetCurrentSelection()];
100                 calendarInfo->calendarID = calendarID;
101                 
102         } else {
104                 // Go through the list of accounts and find the matching account name.
105                 
106                 int accountSeek = 0;
107                 
108                 for (accountSeek = 0; accountSeek < preferencesData->accounts.GetCount(); accountSeek++){
109                         
110                         if ((wxString)cmbAccount->GetStringSelection() == preferencesData->accounts.GetAccountName(accountSeek)){
111                                 break;
112                         }
113                         
114                 }
115                 
116                 calendarInfo->accountPreferencesID = accountPrefencesIDList[cmbAccount->GetCurrentSelection()];
117                 
118         }
120         calendarInfo->editMode = editMode;
121         calendarInfo->accountName = std::string(cmbAccount->GetStringSelection().ToUTF8());
122         calendarInfo->calendarName = std::string(txtName->GetValue().ToUTF8());
123         calendarInfo->calendarDescription = std::string(txtDescription->GetValue().ToUTF8());
124         
125         calendarInfo->calendarColour = (clpColour->GetColour().GetAsString(wxC2S_HTML_SYNTAX).ToStdString() + "FF");
126         
127         wxCommandEvent processCalendarEvent(XCMAIN_PROCESSCALENDAR);
128         processCalendarEvent.SetId(ID_PROCESSCALENDAR);
129         processCalendarEvent.SetClientData((void*)calendarInfo);
130         wxPostEvent(this->GetParent(), processCalendarEvent);
131         
132         this->Close();
133         
136 void frmCalendarEditor::SetData(int calendarID, std::string accountName, std::string calendarName, std::string calendarDescription, Colour calendarColour){
137         
138         txtName->SetValue(wxString(calendarName.c_str(), wxConvUTF8));
139         txtDescription->SetValue(wxString(calendarDescription.c_str(), wxConvUTF8));
140         clpColour->SetColour(wxColour(calendarColour.red, calendarColour.green, calendarColour.blue));
141         cmbAccount->SetStringSelection(wxString(accountName.c_str(), wxConvUTF8));
142         this->calendarID = calendarID;
143         
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