static void end_element_handler(GMarkupParseContext *context, const gchar *element_name, gpointer user_data, GError **error) { PounceParserData *data = user_data; gchar *buffer = NULL; if (data->buffer != NULL) { buffer = g_string_free(data->buffer, FALSE); data->buffer = NULL; } if (purple_strequal(element_name, "account")) { g_free(data->account_name); data->account_name = g_strdup(buffer); } else if (purple_strequal(element_name, "pouncee")) { g_free(data->pouncee); data->pouncee = g_strdup(buffer); } else if (purple_strequal(element_name, "option")) { if (purple_strequal(data->option_type, "on-away")) data->options |= PURPLE_POUNCE_OPTION_AWAY; g_free(data->option_type); data->option_type = NULL; } else if (purple_strequal(element_name, "event")) { if (purple_strequal(data->event_type, "sign-on")) data->events |= PURPLE_POUNCE_SIGNON; else if (purple_strequal(data->event_type, "sign-off")) data->events |= PURPLE_POUNCE_SIGNOFF; else if (purple_strequal(data->event_type, "away")) data->events |= PURPLE_POUNCE_AWAY; else if (purple_strequal(data->event_type, "return-from-away")) data->events |= PURPLE_POUNCE_AWAY_RETURN; else if (purple_strequal(data->event_type, "idle")) data->events |= PURPLE_POUNCE_IDLE; else if (purple_strequal(data->event_type, "return-from-idle")) data->events |= PURPLE_POUNCE_IDLE_RETURN; else if (purple_strequal(data->event_type, "start-typing")) data->events |= PURPLE_POUNCE_TYPING; else if (purple_strequal(data->event_type, "typed")) data->events |= PURPLE_POUNCE_TYPED; else if (purple_strequal(data->event_type, "stop-typing")) data->events |= PURPLE_POUNCE_TYPING_STOPPED; else if (purple_strequal(data->event_type, "message-received")) data->events |= PURPLE_POUNCE_MESSAGE_RECEIVED; g_free(data->event_type); data->event_type = NULL; } else if (purple_strequal(element_name, "action")) { if (data->pounce != NULL) { purple_pounce_action_register(data->pounce, data->action_name); purple_pounce_action_set_enabled(data->pounce, data->action_name, TRUE); } g_free(data->action_name); data->action_name = NULL; } else if (purple_strequal(element_name, "param")) { if (data->pounce != NULL) { purple_pounce_action_set_attribute(data->pounce, data->action_name, data->param_name, buffer); } g_free(data->param_name); data->param_name = NULL; } else if (purple_strequal(element_name, "events")) { PurpleAccount *account; account = purple_accounts_find(data->account_name, data->protocol_id); g_free(data->account_name); g_free(data->protocol_id); data->account_name = NULL; data->protocol_id = NULL; if (account == NULL) { purple_debug(PURPLE_DEBUG_ERROR, "pounce", "Account for pounce not found!\n"); /* * This pounce has effectively been removed, so make * sure that we save the changes to pounces.xml */ schedule_pounces_save(); } else { purple_debug(PURPLE_DEBUG_INFO, "pounce", "Creating pounce: %s, %s\n", data->ui_name, data->pouncee); data->pounce = purple_pounce_new(data->ui_name, account, data->pouncee, data->events, data->options); } g_free(data->pouncee); data->pouncee = NULL; } else if (purple_strequal(element_name, "save")) { if (data->pounce != NULL) purple_pounce_set_save(data->pounce, TRUE); } else if (purple_strequal(element_name, "pounce")) { data->pounce = NULL; data->events = 0; data->options = 0; g_free(data->ui_name); g_free(data->pouncee); g_free(data->protocol_id); g_free(data->event_type); g_free(data->option_type); g_free(data->action_name); g_free(data->param_name); g_free(data->account_name); data->ui_name = NULL; data->pounce = NULL; data->protocol_id = NULL; data->event_type = NULL; data->option_type = NULL; data->action_name = NULL; data->param_name = NULL; data->account_name = NULL; } g_free(buffer); }
static void save_pounce_cb(GntWidget *w, PurpleGntPounceDialog *dialog) { const char *name; const char *message, *command, *reason; PurplePounceEvent events = PURPLE_POUNCE_NONE; PurplePounceOption options = PURPLE_POUNCE_OPTION_NONE; name = gnt_entry_get_text(GNT_ENTRY(dialog->buddy_entry)); if (*name == '\0') { purple_notify_error(NULL, NULL, _("Please enter a buddy to pounce."), NULL); return; } /* Options */ if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->on_away))) options |= PURPLE_POUNCE_OPTION_AWAY; /* Events */ if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->signon))) events |= PURPLE_POUNCE_SIGNON; if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->signoff))) events |= PURPLE_POUNCE_SIGNOFF; if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->away))) events |= PURPLE_POUNCE_AWAY; if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->away_return))) events |= PURPLE_POUNCE_AWAY_RETURN; if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->idle))) events |= PURPLE_POUNCE_IDLE; if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->idle_return))) events |= PURPLE_POUNCE_IDLE_RETURN; if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->typing))) events |= PURPLE_POUNCE_TYPING; if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->typed))) events |= PURPLE_POUNCE_TYPED; if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->stop_typing))) events |= PURPLE_POUNCE_TYPING_STOPPED; if (gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->message_recv))) events |= PURPLE_POUNCE_MESSAGE_RECEIVED; /* Data fields */ message = gnt_entry_get_text(GNT_ENTRY(dialog->send_msg_entry)); command = gnt_entry_get_text(GNT_ENTRY(dialog->exec_cmd_entry)); reason = gnt_entry_get_text(GNT_ENTRY(dialog->popup_entry)); if (*reason == '\0') reason = NULL; if (*message == '\0') message = NULL; if (*command == '\0') command = NULL; if (dialog->pounce == NULL) { dialog->pounce = purple_pounce_new(FINCH_UI, dialog->account, name, events, options); } else { purple_pounce_set_events(dialog->pounce, events); purple_pounce_set_options(dialog->pounce, options); purple_pounce_set_pouncer(dialog->pounce, dialog->account); purple_pounce_set_pouncee(dialog->pounce, name); } /* Actions */ purple_pounce_action_set_enabled(dialog->pounce, "open-window", gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->open_win))); purple_pounce_action_set_enabled(dialog->pounce, "popup-notify", gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->popup))); purple_pounce_action_set_enabled(dialog->pounce, "send-message", gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->send_msg))); purple_pounce_action_set_enabled(dialog->pounce, "execute-command", gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->exec_cmd))); purple_pounce_action_set_enabled(dialog->pounce, "play-beep", gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->play_sound))); purple_pounce_action_set_attribute(dialog->pounce, "send-message", "message", message); purple_pounce_action_set_attribute(dialog->pounce, "execute-command", "command", command); purple_pounce_action_set_attribute(dialog->pounce, "popup-notify", "reason", reason); /* Set the defaults for next time. */ purple_prefs_set_bool("/finch/pounces/default_actions/open-window", gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->open_win))); purple_prefs_set_bool("/finch/pounces/default_actions/popup-notify", gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->popup))); purple_prefs_set_bool("/finch/pounces/default_actions/send-message", gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->send_msg))); purple_prefs_set_bool("/finch/pounces/default_actions/execute-command", gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->exec_cmd))); purple_prefs_set_bool("/finch/pounces/default_actions/play-beep", gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->play_sound))); purple_pounce_set_save(dialog->pounce, gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->save_pounce))); purple_pounce_set_pouncer(dialog->pounce, (PurpleAccount *)gnt_combo_box_get_selected_data(GNT_COMBO_BOX(dialog->account_menu))); update_pounces(); gnt_widget_destroy(dialog->window); }