void view_event(icalcomponent* calendar) { //Ask user if they want null fields in addition to filled ones bool show_null_fields_too = yes_no_prompt("Do you want to view empty fields? (y/n)"); icalcomponent* event = find_event(calendar); if (event == NULL) { append_action_to_closed_log("View event", false); } //Once user selects desired one, displays all needed fields icalproperty* p; for(p = icalcomponent_get_first_property(event,ICAL_ANY_PROPERTY); p != 0; p = icalcomponent_get_next_property(event,ICAL_ANY_PROPERTY)) { if ((icalproperty_get_comment(p) != NULL) || (show_null_fields_too)) { cout << icalproperty_get_x_name(p) << ": "; cout << icalproperty_get_comment(p) << endl; } } append_action_to_closed_log("View event", true); }
void tmplput_CtxICalProperty(StrBuf *Target, WCTemplputParams *TP) { icalproperty *p = (icalproperty *) CTX(CTX_ICALPROPERTY); const char *str; str = icalproperty_get_comment (p); StrBufAppendTemplateStr(Target, TP, str, 0); }
void tmplput_ICalItem(StrBuf *Target, WCTemplputParams *TP) { icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL); icalproperty *p; icalproperty_kind Kind; const char *str; Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 0, ICAL_ANY_PROPERTY); p = icalcomponent_get_first_property(cal, Kind); if (p != NULL) { str = icalproperty_get_comment (p); StrBufAppendTemplateStr(Target, TP, str, 1); } }
void test_properties() { icalproperty *prop; icalparameter *param; icalvalue *value; char *str; icalproperty *clone; /* Create a new property */ prop = icalproperty_vanew_comment( "Another Comment", icalparameter_new_cn("A Common Name 1"), icalparameter_new_cn("A Common Name 2"), icalparameter_new_cn("A Common Name 3"), icalparameter_new_cn("A Common Name 4"), 0); /* Iterate through all of the parameters in the property */ for(param = icalproperty_get_first_parameter(prop,ICAL_ANY_PARAMETER); param != 0; param = icalproperty_get_next_parameter(prop,ICAL_ANY_PARAMETER)) { printf("Prop parameter: %s\n",icalparameter_get_cn(param)); } /* Get a string representation of the property's value */ printf("Prop value: %s\n",icalproperty_get_comment(prop)); /* Spit out the property in its RFC 5545 representation */ str = icalproperty_as_ical_string_r(prop); printf("As iCAL string:\n %s\n", str); free(str); /* Make a copy of the property. Caller owns the memory */ clone = icalproperty_new_clone(prop); /* Get a reference to the value within the clone property */ value = icalproperty_get_value(clone); str = icalvalue_as_ical_string_r(value); printf("Value: %s", str); free(str); /* Free the original and the clone */ icalproperty_free(clone); icalproperty_free(prop); }
//Order swapped from 7cterm.cpp due to dependencies icalcomponent* find_event(icalcomponent* calendar) { int num_matches = 0; //Display possible fields and prompt for which ones(!) to use //FIXME Doesn't display possible properties for readability cout << "Enter all properties you want to use in all caps, delimited by semicolons" << endl; string properties; cin >> properties; char* c_properties = new char[properties.size()+1]; strcpy(c_properties, properties.c_str()); char* sel_props_c = strtok(c_properties, ";"); vector<string> sel_props; vector<int> sel_props_pos; while (sel_props_c != NULL) { sel_props.push_back(sel_props_c); sel_props_pos.push_back(0); sel_props_c = strtok(c_properties, ";"); } string all_props[] = {"ATTACH", "ATTENDEE", "CATEGORIES", "CLASS", "COMMENT", "CONTACT", "CREATED", "DESCRIPTION", "DTEND", "DTSTAMP", "DTSTART", "DURATION", "EXDATE", "EXRULE", "GEO", "LAST-MOD", "LOCATION", "ORGANIZER", "PRIORITY", "RDATE", "RECURID", "RELATED", "RESOURCES", "RRULE", "RSTATUS", "SEQ", "STATUS", "SUMMARY", "TRANSP", "UID", "URL"}; for (int i = 0; i < sel_props.size() && i < 31; i++) { for (int j = 0; j < 31; j++) { if (sel_props[i] == all_props[j]) { sel_props_pos[i] = j; break; } } if (sel_props[i] == "X-CLASS") { sel_props_pos[i] = 32; //beyond the end of all_props } } vector<string> values; cout << "Enter values for: " << endl; for (int i = 0; i < sel_props.size(); i++) { cout << sel_props[i] << ": "; flush(cout); string value; cin >> value; //FIXME error check for type values.push_back(value); } //Iterate through class events and non-class events to match properties icalcomponent *c; vector<icalcomponent*> matching_events; for (c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT); c != 0; c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT)) { bool is_match = true; //Check each of the properties for (int i = 0; i < sel_props.size(); i++) { if (sel_props_pos[i] == 32) { icalproperty* p = icalcomponent_get_first_property(c, ICAL_X_PROPERTY); char* class_name; strcpy(class_name, icalproperty_get_x(p)); for (int j = 0; class_name != 0 && j < values[i].size(); j++) { if (class_name[j] != values[i][j]) { is_match = false; break; } } }else { //FIXME Iterate through all properties icalproperty* p = icalcomponent_get_first_property(c,ICAL_ANY_PROPERTY); char* prop_value; strcpy(prop_value, icalproperty_get_comment(p)); for (int j = 0; prop_value != 0 && j < values[i].size(); j++) { if (prop_value[j] != values[i][j]) { is_match = false; break; } } } } if (is_match) { matching_events.push_back(c); num_matches++; } } if (num_matches == 0) { cout << "No matches found" << endl; return NULL; } cout << "Which event do you want?" << endl; int user_choice; while (true) { cin >> user_choice; if ((user_choice >= 1) && (user_choice <= num_matches)) { break; } cout << "Invalid selection (Not between 1 and "<< num_matches <<" inclusive)" << endl; } //Return the user_choice-th event from the results return matching_events[user_choice]; }