示例#1
0
PurplePounce *
purple_pounce_new(const char *ui_type, PurpleAccount *pouncer,
				const char *pouncee, PurplePounceEvent event,
				PurplePounceOption option)
{
	PurplePounce *pounce;
	PurplePounceHandler *handler;

	g_return_val_if_fail(ui_type != NULL, NULL);
	g_return_val_if_fail(pouncer != NULL, NULL);
	g_return_val_if_fail(pouncee != NULL, NULL);
	g_return_val_if_fail(event   != 0,    NULL);

	pounce = g_new0(PurplePounce, 1);

	pounce->ui_type  = g_strdup(ui_type);
	pounce->pouncer  = pouncer;
	pounce->pouncee  = g_strdup(pouncee);
	pounce->events   = event;
	pounce->options  = option;

	pounce->actions  = g_hash_table_new_full(g_str_hash, g_str_equal,
											 g_free, free_action_data);

	handler = g_hash_table_lookup(pounce_handlers, pounce->ui_type);

	if (handler != NULL && handler->new_pounce != NULL)
		handler->new_pounce(pounce);

	pounces = g_list_append(pounces, pounce);

	schedule_pounces_save();

	return pounce;
}
示例#2
0
void
purple_pounce_set_options(PurplePounce *pounce, PurplePounceOption options)
{
	g_return_if_fail(pounce  != NULL);

	pounce->options = options;

	schedule_pounces_save();
}
示例#3
0
void
gaim_pounce_set_save(GaimPounce *pounce, gboolean save)
{
	g_return_if_fail(pounce != NULL);

	pounce->save = save;

	schedule_pounces_save();
}
示例#4
0
void
purple_pounce_set_save(PurplePounce *pounce, gboolean save)
{
	g_return_if_fail(pounce != NULL);

	pounce->save = save;

	schedule_pounces_save();
}
示例#5
0
void
purple_pounce_set_data(PurplePounce *pounce, void *data)
{
	g_return_if_fail(pounce != NULL);

	pounce->data = data;

	schedule_pounces_save();
}
示例#6
0
void
purple_pounce_set_events(PurplePounce *pounce, PurplePounceEvent events)
{
	g_return_if_fail(pounce != NULL);
	g_return_if_fail(events != PURPLE_POUNCE_NONE);

	pounce->events = events;

	schedule_pounces_save();
}
示例#7
0
void
purple_pounce_set_pouncer(PurplePounce *pounce, PurpleAccount *pouncer)
{
	g_return_if_fail(pounce  != NULL);
	g_return_if_fail(pouncer != NULL);

	pounce->pouncer = pouncer;

	schedule_pounces_save();
}
示例#8
0
void
gaim_pounce_set_events(GaimPounce *pounce, GaimPounceEvent events)
{
	g_return_if_fail(pounce != NULL);
	g_return_if_fail(pounce != GAIM_POUNCE_NONE);

	pounce->events = events;

	schedule_pounces_save();
}
示例#9
0
void
gaim_pounce_set_pouncer(GaimPounce *pounce, GaimAccount *pouncer)
{
	g_return_if_fail(pounce  != NULL);
	g_return_if_fail(pouncer != NULL);

	pounce->pouncer = pouncer;

	schedule_pounces_save();
}
示例#10
0
void
purple_pounce_set_pouncee(PurplePounce *pounce, const char *pouncee)
{
	g_return_if_fail(pounce  != NULL);
	g_return_if_fail(pouncee != NULL);

	g_free(pounce->pouncee);
	pounce->pouncee = g_strdup(pouncee);

	schedule_pounces_save();
}
示例#11
0
void
gaim_pounce_set_pouncee(GaimPounce *pounce, const char *pouncee)
{
	g_return_if_fail(pounce  != NULL);
	g_return_if_fail(pouncee != NULL);

	if (pounce->pouncee != NULL)
		g_free(pounce->pouncee);

	pounce->pouncee = (pouncee == NULL ? NULL : g_strdup(pouncee));

	schedule_pounces_save();
}
示例#12
0
void
purple_pounce_action_set_enabled(PurplePounce *pounce, const char *action,
							   gboolean enabled)
{
	PurplePounceActionData *action_data;

	g_return_if_fail(pounce != NULL);
	g_return_if_fail(action != NULL);

	action_data = find_action_data(pounce, action);

	g_return_if_fail(action_data != NULL);

	action_data->enabled = enabled;

	schedule_pounces_save();
}
示例#13
0
void
purple_pounce_action_set_attribute(PurplePounce *pounce, const char *action,
								 const char *attr, const char *value)
{
	PurplePounceActionData *action_data;

	g_return_if_fail(pounce != NULL);
	g_return_if_fail(action != NULL);
	g_return_if_fail(attr   != NULL);

	action_data = find_action_data(pounce, action);

	g_return_if_fail(action_data != NULL);

	if (value == NULL)
		g_hash_table_remove(action_data->atts, attr);
	else
		g_hash_table_insert(action_data->atts, g_strdup(attr),
							g_strdup(value));

	schedule_pounces_save();
}
示例#14
0
void
purple_pounce_action_register(PurplePounce *pounce, const char *name)
{
	PurplePounceActionData *action_data;

	g_return_if_fail(pounce != NULL);
	g_return_if_fail(name   != NULL);

	if (g_hash_table_lookup(pounce->actions, name) != NULL)
		return;

	action_data = g_new0(PurplePounceActionData, 1);

	action_data->name    = g_strdup(name);
	action_data->enabled = FALSE;
	action_data->atts    = g_hash_table_new_full(g_str_hash, g_str_equal,
												 g_free, g_free);

	g_hash_table_insert(pounce->actions, g_strdup(name), action_data);

	schedule_pounces_save();
}
示例#15
0
void
purple_pounce_destroy(PurplePounce *pounce)
{
	PurplePounceHandler *handler;

	g_return_if_fail(pounce != NULL);

	handler = g_hash_table_lookup(pounce_handlers, pounce->ui_type);

	pounces = g_list_remove(pounces, pounce);

	g_free(pounce->ui_type);
	g_free(pounce->pouncee);

	g_hash_table_destroy(pounce->actions);

	if (handler != NULL && handler->free_pounce != NULL)
		handler->free_pounce(pounce);

	g_free(pounce);

	schedule_pounces_save();
}
示例#16
0
void
gaim_pounces_sync(void)
{
	FILE *fp;
	struct stat st;
	const char *user_dir = gaim_user_dir();
	char *filename;
	char *filename_real;

	if (!pounces_loaded) {
		gaim_debug(GAIM_DEBUG_WARNING, "pounces",
				   "Writing pounces to disk.\n");
		schedule_pounces_save();
		return;
	}

	if (user_dir == NULL)
		return;

	gaim_debug(GAIM_DEBUG_INFO, "pounces", "Writing pounces to disk.\n");

	fp = g_fopen(user_dir, "r");

	if (fp == NULL)
		g_mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR);
	else
		fclose(fp);

	filename = g_build_filename(user_dir, "pounces.xml.save", NULL);

	if ((fp = g_fopen(filename, "w")) != NULL) {
		GList *l;

		fprintf(fp, "<?xml version='1.0' encoding='UTF-8' ?>\n\n");
		fprintf(fp, "<pounces version='1.0'>\n");

		for (l = gaim_pounces_get_all(); l != NULL; l = l->next)
			gaim_pounces_write(fp, l->data);

		fprintf(fp, "</pounces>\n");

		fclose(fp);
		chmod(filename, S_IRUSR | S_IWUSR);
	}
	else {
		gaim_debug(GAIM_DEBUG_ERROR, "pounces", "Unable to write %s\n",
				   filename);
		g_free(filename);
		return;
	}

	if (g_stat(filename, &st) || (st.st_size == 0)) {
		gaim_debug_error("pounces", "Failed to save pounces\n");
		g_unlink(filename);
		g_free(filename);
		return;
	}

	filename_real = g_build_filename(user_dir, "pounces.xml", NULL);

	if (g_rename(filename, filename_real) < 0) {
		gaim_debug(GAIM_DEBUG_ERROR, "pounces", "Error renaming %s to %s\n",
				   filename, filename_real);
	}

	g_free(filename);
	g_free(filename_real);
}
示例#17
0
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);
}