-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path7cterm.cpp
163 lines (136 loc) · 3.65 KB
/
7cterm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <ctime>
#include <vector>
#include <libical/ical.h>
#include <cstdlib>
#include "ical_x_defs.hpp" //Contains libical macros, property types
#include "text_utilities.cpp" //Contains general text utilities
#include "exception.hpp"
#include "log.cpp"
#include "event_actions.cpp"
int main()
{
vector<string> classes; //the first line of the ics7 file contains the elements of this
icalproperty_set_x_name(ical_x_class_prop, "X-CLASS");
icalcomponent* calendar = NULL;
struct icaltimetype atime;
struct icalperiodtype rtime;
//FIXME Later versions will try to load from the default file here
//If we don't have a saved calendar, make a new one
if (calendar == NULL)
{
atime = icaltime_from_timet( time(0),0);
rtime.start = icaltime_from_timet( time(0),0);
rtime.end = icaltime_from_timet( time(0),0);
rtime.end.hour++;
calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
}
//FIXME Find all non-school days by prompt?
//FIXME Ask for start/end of semester
//Actually manipulating the calendar
while (true)
{
//Prompt for user action
cout << "What would you like to do?\n" <<
"1. Add a class\n" <<
"2. Add an event\n" <<
"3. Delete an event\n" <<
"4. Edit an event\n" <<
"5. Find an event\n" <<
"6. View an event\n" <<
"7. Delete a class\n" <<
"8. Exit the program\n" << endl;
cout << "Enter the integer corresponding to your choice" << endl;
string user_choice = "";
cin >> user_choice;
bool user_choice_flag = true;
//Check the string is all digits
for (int i = 0; i < user_choice.size(); i++)
{
if (!isdigit(user_choice[i]))
{
cout << "Invalid selection (Not all digits)" << endl;
user_choice_flag = false;
break;
}
}
if (!user_choice_flag)
{
continue;
}
//Given the choice, perform the desired action
switch (atoi(user_choice.c_str()))
{
//ADD CLASS
case 1:
{
add_class(calendar, classes);
break;
}
//ADD EVENT (for a class or in general)
case 2:
{
add_event(calendar);
break;
}
//DELETE SINGLE EVENT
case 3:
{
delete_event(calendar);
break;
}
//EDIT EVENT (class or general)
case 4:
{
edit_event(calendar);
break;
}
//FIND EVENT
case 5:
{
icalcomponent* event = find_event(calendar);
if (event == NULL)
{
append_action_to_closed_log("Find event", false);
}else
{
append_action_to_closed_log("Find event", true);
}
break;
}
//VIEW EVENT
case 6:
{
view_event(calendar);
break;
}
//DELETE CLASS
//FIXME Not implemented in this sprint
case 7:
{
//FIXME Ask for class name
//FIXME Scan through first level of components for class
//FIXME Print all matches and get the one to delete
//FIXME Warn that all events for that class will be deleted
//FIXME Delete class after user okay
cout << "This feature is not implemented in this sprint." << endl;
break;
}
//EXIT
case 8:
{
//Prompt for okay
if (yes_no_prompt("Your calendar data will not be saved. Continue? (y/n)"))
{
return 0;
}
break;
}
default:
{
cout << "Invalid selection (Not between 1 and 8 inclusive)" << endl;
break;
}
}
}
return 0;
}