Exemple #1
0
static void *
finch_request_choice(const char *title, const char *primary,
		const char *secondary, int default_value,
		const char *ok_text, GCallback ok_cb,
		const char *cancel_text, GCallback cancel_cb,
		PurpleAccount *account, const char *who, PurpleConversation *conv,
		void *user_data, va_list choices)
{
	GntWidget *window, *combo, *box;
	const char *text;
	int val;

	window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_CHOICE);

	combo = gnt_combo_box_new();
	gnt_box_add_widget(GNT_BOX(window), combo);
	while ((text = va_arg(choices, const char *)))
	{
		val = va_arg(choices, int);
		gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(val + 1), text);
	}
	gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), GINT_TO_POINTER(default_value + 1));

	box = setup_button_box(window, user_data, request_choice_cb, combo,
			ok_text, ok_cb, cancel_text, cancel_cb, NULL);
	gnt_box_add_widget(GNT_BOX(window), box);

	setup_default_callback(window, cancel_cb, user_data);
	gnt_widget_show(window);
	
	return window;
}
Exemple #2
0
static gboolean
dropdown_menu(GntBindable *b, GList *null)
{
	if (GNT_WIDGET_IS_FLAG_SET(GNT_COMBO_BOX(b)->dropdown->parent, GNT_WIDGET_MAPPED))
		return FALSE;
	popup_dropdown(GNT_COMBO_BOX(b));
	return TRUE;
}
Exemple #3
0
static void
load_pref_window(const char * profile)
{
	gint i;

	finch_sound_set_active_profile(profile);

	gnt_combo_box_set_selected(GNT_COMBO_BOX(pref_dialog->method), (gchar *)purple_prefs_get_string(make_pref("/method")));

	gnt_entry_set_text(GNT_ENTRY(pref_dialog->command), purple_prefs_get_path(make_pref("/command")));

	gnt_check_box_set_checked(GNT_CHECK_BOX(pref_dialog->conv_focus), purple_prefs_get_bool(make_pref("/conv_focus")));

	gnt_combo_box_set_selected(GNT_COMBO_BOX(pref_dialog->while_status), GINT_TO_POINTER(purple_prefs_get_int("/purple" "/sound/while_status")));

	gnt_slider_set_value(GNT_SLIDER(pref_dialog->volume), CLAMP(purple_prefs_get_int(make_pref("/volume")), 0, 100));

	for (i = 0; i < PURPLE_NUM_SOUNDS; i++) {
		FinchSoundEvent * event = &sounds[i];
		gchar *boolpref;
		gchar *filepref, *basename = NULL;
		const char * profile = finch_sound_get_active_profile();

		filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", profile, event->pref);

		g_free(event->file);
		event->file = g_strdup(purple_prefs_get_path(filepref));

		g_free(filepref);
		if (event->label == NULL) {
			continue;
		}

		boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", profile, event->pref);

		gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), 0, event->label);
		gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), 1,
				event->file[0] ? (basename = g_path_get_basename(event->file)) : _("(default)"));
		g_free(basename);

		gnt_tree_set_choice(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), purple_prefs_get_bool(boolpref));

		g_free(boolpref);
	}

	gnt_tree_set_selected(GNT_TREE(pref_dialog->profiles), (gchar *)finch_sound_get_active_profile());

	gnt_widget_draw(pref_dialog->window);
}
static void
save_savedstatus_cb(GntWidget *button, EditStatus *edit)
{
	const char *title, *message;
	PurpleStatusPrimitive prim;
	PurpleSavedStatus *find;

	title = gnt_entry_get_text(GNT_ENTRY(edit->title));
	message = gnt_entry_get_text(GNT_ENTRY(edit->message));
	if (!message || !*message)
		message = NULL;

	prim = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(edit->type)));

	if (!title || !*title)
	{
		purple_notify_error(edit, _("Error"), _("Invalid title"),
				_("Please enter a non-empty title for the status."));
		gnt_box_give_focus_to_child(GNT_BOX(edit->window), edit->title);
		return;
	}

	find = purple_savedstatus_find(title);
	if (find && find != edit->saved)
	{
		purple_notify_error(edit, _("Error"), _("Duplicate title"),
				_("Please enter a different title for the status."));
		gnt_box_give_focus_to_child(GNT_BOX(edit->window), edit->title);
		return;
	}
	
	if (edit->saved == NULL)
	{
		edit->saved = purple_savedstatus_new(title, prim);
		purple_savedstatus_set_message(edit->saved, message);
		set_substatuses(edit);
		if (statuses.tree)
			gnt_tree_add_row_last(GNT_TREE(statuses.tree), edit->saved,
					gnt_tree_create_row(GNT_TREE(statuses.tree), title,
						purple_primitive_get_name_from_type(prim), message), NULL);
	}
	else
	{
		purple_savedstatus_set_title(edit->saved, title);
		purple_savedstatus_set_type(edit->saved, prim);
		purple_savedstatus_set_message(edit->saved, message);
		if (statuses.tree)
		{
			gnt_tree_change_text(GNT_TREE(statuses.tree), edit->saved, 0, title);
			gnt_tree_change_text(GNT_TREE(statuses.tree), edit->saved, 1,
						purple_primitive_get_name_from_type(prim));
			gnt_tree_change_text(GNT_TREE(statuses.tree), edit->saved, 2, message);
		}
	}

	if (g_object_get_data(G_OBJECT(button), "use"))
		purple_savedstatus_activate(edit->saved);

	gnt_widget_destroy(edit->window);
}
Exemple #5
0
static void
gnt_combo_box_draw(GntWidget *widget)
{
	GntComboBox *box = GNT_COMBO_BOX(widget);
	char *text = NULL, *s;
	GntColorType type;
	int len;

	if (box->dropdown && box->selected)
		text = gnt_tree_get_selection_text(GNT_TREE(box->dropdown));

	if (text == NULL)
		text = g_strdup("");

	if (gnt_widget_has_focus(widget))
		type = GNT_COLOR_HIGHLIGHT;
	else
		type = GNT_COLOR_NORMAL;

	wbkgdset(widget->window, '\0' | gnt_color_pair(type));

	s = (char*)gnt_util_onscreen_width_to_pointer(text, widget->priv.width - 4, &len);
	*s = '\0';

	mvwaddstr(widget->window, 1, 1, C_(text));
	whline(widget->window, ' ' | gnt_color_pair(type), widget->priv.width - 4 - len);
	mvwaddch(widget->window, 1, widget->priv.width - 3, ACS_VLINE | gnt_color_pair(GNT_COLOR_NORMAL));
	mvwaddch(widget->window, 1, widget->priv.width - 2, ACS_DARROW | gnt_color_pair(GNT_COLOR_NORMAL));
	wmove(widget->window, 1, 1);

	g_free(text);
	GNTDEBUG;
}
Exemple #6
0
static gboolean
gnt_combo_box_key_pressed(GntWidget *widget, const char *text)
{
	GntComboBox *box = GNT_COMBO_BOX(widget);
	gboolean showing = !!GNT_WIDGET_IS_FLAG_SET(box->dropdown->parent, GNT_WIDGET_MAPPED);

	if (showing) {
		if (text[1] == 0) {
			switch (text[0]) {
				case '\r':
				case '\t':
				case '\n':
					hide_popup(box, TRUE);
					return TRUE;
				case 27:
					hide_popup(box, FALSE);
					return TRUE;
			}
		}
	}

	if (gnt_widget_key_pressed(box->dropdown, text)) {
		if (!showing)
			popup_dropdown(box);
		return TRUE;
	}

	{
#define SEARCH_IN_RANGE(start, end) do { \
		GntTreeRow *row; \
		for (row = start; row != end; \
				row = gnt_tree_row_get_next(tree, row)) { \
			gpointer key = gnt_tree_row_get_key(tree, row); \
			GList *list = gnt_tree_get_row_text_list(tree, key); \
			gboolean found = FALSE; \
			found = (list->data && g_ascii_strncasecmp(text, list->data, len) == 0); \
			g_list_foreach(list, (GFunc)g_free, NULL); \
			g_list_free(list); \
			if (found) { \
				if (!showing) \
					popup_dropdown(box); \
				gnt_tree_set_selected(tree, key); \
				return TRUE; \
			} \
		} \
} while (0)

		int len = strlen(text);
		GntTree *tree = GNT_TREE(box->dropdown);
		GntTreeRow *current = tree->current;

		SEARCH_IN_RANGE(gnt_tree_row_get_next(tree, current), NULL);
		SEARCH_IN_RANGE(tree->top, current);

#undef SEARCH_IN_RANGE
	}

	return FALSE;
}
Exemple #7
0
static void
gnt_combo_box_lost_focus(GntWidget *widget)
{
	GntComboBox *combo = GNT_COMBO_BOX(widget);
	if (GNT_WIDGET_IS_FLAG_SET(combo->dropdown->parent, GNT_WIDGET_MAPPED))
		hide_popup(combo, FALSE);
	widget_lost_focus(widget);
}
Exemple #8
0
static GntWidget*
create_choice_field(PurpleRequestField *field)
{
	int id;
	GList *list;
	GntWidget *combo = gnt_combo_box_new();

	list = purple_request_field_choice_get_labels(field);
	for (id = 1; list; list = list->next, id++)
	{
		gnt_combo_box_add_data(GNT_COMBO_BOX(combo),
				GINT_TO_POINTER(id), list->data);
	}
	gnt_combo_box_set_selected(GNT_COMBO_BOX(combo),
			GINT_TO_POINTER(purple_request_field_choice_get_default_value(field)));
	return combo;
}
Exemple #9
0
static void
gnt_combo_box_size_request(GntWidget *widget)
{
	if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED))
	{
		GntWidget *dd = GNT_COMBO_BOX(widget)->dropdown;
		gnt_widget_size_request(dd);
		widget->priv.height = 3;   /* For now, a combobox will have border */
		widget->priv.width = MAX(10, dd->priv.width + 2);
	}
}
Exemple #10
0
static void fl_get_list(GntWidget *button, gpointer null)
{
	PurpleAccount *account = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(froomlist.accounts));
	PurpleConnection *gc = purple_account_get_connection(account);

	if (!gc)
		return;

	update_roomlist(NULL);
	froomlist.roomlist = purple_roomlist_get_list(gc);
	gnt_box_give_focus_to_child(GNT_BOX(froomlist.window), froomlist.tree);
}
Exemple #11
0
static gboolean
gnt_combo_box_clicked(GntWidget *widget, GntMouseEvent event, int x, int y)
{
	GntComboBox *box = GNT_COMBO_BOX(widget);
	gboolean dshowing = GNT_WIDGET_IS_FLAG_SET(box->dropdown->parent, GNT_WIDGET_MAPPED);

	if (event == GNT_MOUSE_SCROLL_UP) {
		if (dshowing)
			gnt_widget_key_pressed(box->dropdown, GNT_KEY_UP);
	} else if (event == GNT_MOUSE_SCROLL_DOWN) {
		if (dshowing)
			gnt_widget_key_pressed(box->dropdown, GNT_KEY_DOWN);
	} else if (event == GNT_LEFT_MOUSE_DOWN) {
		if (dshowing) {
			hide_popup(box, TRUE);
		} else {
			popup_dropdown(GNT_COMBO_BOX(widget));
		}
	} else
		return FALSE;
	return TRUE;
}
Exemple #12
0
static GntWidget*
create_account_field(PurpleRequestField *field)
{
	gboolean all;
	PurpleAccount *def;
	GList *list;
	GntWidget *combo = gnt_combo_box_new();

	all = purple_request_field_account_get_show_all(field);
	def = purple_request_field_account_get_value(field);
	if (!def)
		def = purple_request_field_account_get_default_value(field);

	if (all)
		list = purple_accounts_get_all();
	else
		list = purple_connections_get_all();

	for (; list; list = list->next)
	{
		PurpleAccount *account;
		char *text;

		if (all)
			account = list->data;
		else
			account = purple_connection_get_account(list->data);

		text = g_strdup_printf("%s (%s)",
				purple_account_get_username(account),
				purple_account_get_protocol_name(account));
		gnt_combo_box_add_data(GNT_COMBO_BOX(combo), account, text);
		g_free(text);
		if (account == def)
			gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), account);
	}
	gnt_widget_set_size(combo, 20, 3); /* ew */
	return combo;
}
Exemple #13
0
static GntWidget*
create_list_field(PurpleRequestField *field)
{
	GntWidget *ret = NULL;
	GList *list;
	gboolean multi = purple_request_field_list_get_multi_select(field);
	if (multi)
	{
		GntWidget *tree = gnt_tree_new();

		list = purple_request_field_list_get_items(field);
		for (; list; list = list->next)
		{
			const char *text = list->data;
			gpointer key = purple_request_field_list_get_data(field, text);
			gnt_tree_add_choice(GNT_TREE(tree), key,
					gnt_tree_create_row(GNT_TREE(tree), text), NULL, NULL);
			if (purple_request_field_list_is_selected(field, text))
				gnt_tree_set_choice(GNT_TREE(tree), key, TRUE);
		}
		ret = tree;
	}
	else
	{
		GntWidget *combo = gnt_combo_box_new();

		list = purple_request_field_list_get_items(field);
		for (; list; list = list->next)
		{
			const char *text = list->data;
			gpointer key = purple_request_field_list_get_data(field, text);
			gnt_combo_box_add_data(GNT_COMBO_BOX(combo), key, text);
			if (purple_request_field_list_is_selected(field, text))
				gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), key);
		}
		ret = combo;
	}
	return ret;
}
Exemple #14
0
static void
request_choice_cb(GntWidget *button, GntComboBox *combo)
{
	PurpleRequestChoiceCb callback = g_object_get_data(G_OBJECT(button), "activate-callback");
	gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata");
	int choice = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo))) - 1;

	if (callback)
		callback(data, choice);

	while (button->parent)
		button = button->parent;

	purple_request_close(PURPLE_REQUEST_INPUT, button);
}
Exemple #15
0
static void
use_trans_status_cb(GntWidget *button, EditStatus *edit)
{
	const char *message;
	PurpleStatusPrimitive prim;
	PurpleSavedStatus *saved;

	message = gnt_entry_get_text(GNT_ENTRY(edit->message));
	prim = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(edit->type)));

	saved = purple_savedstatus_find_transient_by_type_and_message(prim, message);
	if (saved == NULL) {
		saved = purple_savedstatus_new(NULL, prim);
		edit->saved = saved;
		set_substatuses(edit);
	}
	purple_savedstatus_set_message(saved, message);
	purple_savedstatus_activate(saved);
	gnt_widget_destroy(edit->window);
}
Exemple #16
0
static void
save_cb(GntWidget *button, gpointer win)
{
	GList * itr;

	purple_prefs_set_string(make_pref("/method"), gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog->method)));
	purple_prefs_set_path(make_pref("/command"), gnt_entry_get_text(GNT_ENTRY(pref_dialog->command)));
	purple_prefs_set_bool(make_pref("/conv_focus"), gnt_check_box_get_checked(GNT_CHECK_BOX(pref_dialog->conv_focus)));
	purple_prefs_set_int("/purple/sound/while_status", GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog->while_status))));

	for (itr = gnt_tree_get_rows(GNT_TREE(pref_dialog->events)); itr; itr = itr->next) {
		FinchSoundEvent * event = &sounds[GPOINTER_TO_INT(itr->data)];
		char * filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", finch_sound_get_active_profile(), event->pref);
		char * boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", finch_sound_get_active_profile(), event->pref);
		purple_prefs_set_bool(boolpref, gnt_tree_get_choice(GNT_TREE(pref_dialog->events), itr->data));
		purple_prefs_set_path(filepref, event->file ? event->file : "");
		g_free(filepref);
		g_free(boolpref);
	}
	gnt_widget_destroy(GNT_WIDGET(win));
}
Exemple #17
0
static void
reset_account_list(PurpleAccount *account)
{
	GList *list;
	GntComboBox *accounts = GNT_COMBO_BOX(froomlist.accounts);
	gnt_combo_box_remove_all(accounts);
	for (list = purple_connections_get_all(); list; list = list->next) {
		PurplePluginProtocolInfo *prpl_info = NULL;
		PurpleConnection *gc = list->data;

		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc));
		if (PURPLE_CONNECTION_IS_CONNECTED(gc) &&
		        prpl_info->roomlist_get_list != NULL) {
			PurpleAccount *account = purple_connection_get_account(gc);
			char *text = g_strdup_printf("%s (%s)",
					purple_account_get_username(account),
					purple_account_get_protocol_name(account));
			gnt_combo_box_add_data(accounts, account, text);
			g_free(text);
		}
	}
}
static gboolean
gnt_combo_box_key_pressed(GntWidget *widget, const char *text)
{
	GntComboBox *box = GNT_COMBO_BOX(widget);
	if (GNT_WIDGET_IS_FLAG_SET(box->dropdown->parent, GNT_WIDGET_MAPPED))
	{
		if (text[1] == 0)
		{
			switch (text[0])
			{
				case '\r':
				case '\t':
				case '\n':
					hide_popup(box, TRUE);
					return TRUE;
				case 27:
					hide_popup(box, FALSE);
					return TRUE;
			}
		}
		if (gnt_widget_key_pressed(box->dropdown, text))
			return TRUE;
	}
	else
	{
		if (text[0] == 27)
		{
			if (strcmp(text, GNT_KEY_UP) == 0 ||
					strcmp(text, GNT_KEY_DOWN) == 0)
			{
				popup_dropdown(box);
				return TRUE;
			}
		}
	}

	return FALSE;
}
Exemple #19
0
static void
save_substatus_cb(GntWidget *widget, EditSubStatus *sub)
{
	PurpleSavedStatus *saved = sub->parent->saved;
	RowInfo *row = sub->key;
	const char *message;
	PurpleStatusType *type;

	type = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(sub->type));
	message = gnt_entry_get_text(GNT_ENTRY(sub->message));

	row->type = type;
	row->message = g_strdup(message);

	if (saved)    /* Save the substatus if the savedstatus actually exists. */
		purple_savedstatus_set_substatus(saved, row->account, type, message);

	gnt_tree_set_choice(GNT_TREE(sub->parent->tree), row, TRUE);
	gnt_tree_change_text(GNT_TREE(sub->parent->tree), row, 1,
			purple_status_type_get_name(type));
	gnt_tree_change_text(GNT_TREE(sub->parent->tree), row, 2, message);
	
	gnt_widget_destroy(sub->window);
}
Exemple #20
0
void finch_savedstatus_edit(PurpleSavedStatus *saved)
{
	EditStatus *edit;
	GntWidget *window, *box, *button, *entry, *combo, *label, *tree;
	PurpleStatusPrimitive prims[] = {PURPLE_STATUS_AVAILABLE, PURPLE_STATUS_AWAY,
		PURPLE_STATUS_INVISIBLE, PURPLE_STATUS_OFFLINE, PURPLE_STATUS_UNSET}, current;
	GList *iter;
	int i;

	if (saved)
	{
		GList *iter;
		for (iter = edits; iter; iter = iter->next)
		{
			edit = iter->data;
			if (edit->saved == saved)
				return;
		}
	}

	edit = g_new0(EditStatus, 1);
	edit->saved = saved;
	edit->window = window = gnt_vbox_new(FALSE);
	gnt_box_set_toplevel(GNT_BOX(window), TRUE);
	gnt_box_set_title(GNT_BOX(window), _("Edit Status"));
	gnt_box_set_fill(GNT_BOX(window), TRUE);
	gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID);
	gnt_box_set_pad(GNT_BOX(window), 0);

	edits = g_list_append(edits, edit);

	/* Title */
	box = gnt_hbox_new(FALSE);
	gnt_box_set_alignment(GNT_BOX(box), GNT_ALIGN_LEFT);
	gnt_box_add_widget(GNT_BOX(window), box);
	gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Title")));

	edit->title = entry = gnt_entry_new(saved ? purple_savedstatus_get_title(saved) : NULL);
	gnt_box_add_widget(GNT_BOX(box), entry);

	/* Type */
	box = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(window), box);
	gnt_box_add_widget(GNT_BOX(box), label = gnt_label_new(_("Status")));
	gnt_widget_set_size(label, 0, 1);

	edit->type = combo = gnt_combo_box_new();
	gnt_box_add_widget(GNT_BOX(box), combo);
	current = saved ? purple_savedstatus_get_type(saved) : PURPLE_STATUS_UNSET;
	for (i = 0; prims[i] != PURPLE_STATUS_UNSET; i++)
	{
		gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(prims[i]),
				purple_primitive_get_name_from_type(prims[i]));
		if (prims[i] == current)
			gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), GINT_TO_POINTER(current));
	}

	/* Message */
	box = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(window), box);
	gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Message")));

	edit->message = entry = gnt_entry_new(saved ? purple_savedstatus_get_message(saved) : NULL);
	gnt_box_add_widget(GNT_BOX(window), entry);

	gnt_box_add_widget(GNT_BOX(window), gnt_hline_new());
	gnt_box_add_widget(GNT_BOX(window), gnt_label_new(_("Use different status for following accounts")));

	edit->hash = g_hash_table_new(g_direct_hash, g_direct_equal);
	edit->tree = tree = gnt_tree_new_with_columns(3);
	gnt_box_add_widget(GNT_BOX(window), tree);
	gnt_tree_set_show_title(GNT_TREE(tree), TRUE);
	gnt_tree_set_column_titles(GNT_TREE(tree), _("Account"), _("Status"), _("Message"));
	gnt_tree_set_col_width(GNT_TREE(tree), 0, 30);
	gnt_tree_set_col_width(GNT_TREE(tree), 1, 10);
	gnt_tree_set_col_width(GNT_TREE(tree), 2, 30);

	for (iter = purple_accounts_get_all(); iter; iter = iter->next)
	{
		add_substatus(edit, iter->data);
	}

	g_signal_connect(G_OBJECT(tree), "key_pressed", G_CALLBACK(popup_substatus), edit);

	/* The buttons */
	box = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(window), box);

	/* Use */
	button = gnt_button_new(_("Use"));
	gnt_box_add_widget(GNT_BOX(box), button);
	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(use_trans_status_cb), edit);

	/* Save */
	button = gnt_button_new(_("Save"));
	gnt_box_add_widget(GNT_BOX(box), button);
	g_object_set_data(G_OBJECT(button), "use", NULL);
	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(save_savedstatus_cb), edit);

	/* Save & Use */
	button = gnt_button_new(_("Save & Use"));
	gnt_box_add_widget(GNT_BOX(box), button);
	g_object_set_data(G_OBJECT(button), "use", GINT_TO_POINTER(TRUE));
	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(save_savedstatus_cb), edit);

	/* Cancel */
	button = gnt_button_new(_("Cancel"));
	gnt_box_add_widget(GNT_BOX(box), button);
	g_signal_connect_swapped(G_OBJECT(button), "activate",
			G_CALLBACK(gnt_widget_destroy), window);

	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(update_edit_list), edit);

	gnt_widget_show(window);
}
Exemple #21
0
static void
request_fields_cb(GntWidget *button, PurpleRequestFields *fields)
{
	PurpleRequestFieldsCb callback = g_object_get_data(G_OBJECT(button), "activate-callback");
	gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata");
	GList *list;

	/* Update the data of the fields. Pidgin does this differently. Instead of
	 * updating the fields at the end like here, it updates the appropriate field
	 * instantly whenever a change is made. That allows it to make sure the
	 * 'required' fields are entered before the user can hit OK. It's not the case
	 * here, althought it can be done. */
	for (list = purple_request_fields_get_groups(fields); list; list = list->next)
	{
		PurpleRequestFieldGroup *group = list->data;
		GList *fields = purple_request_field_group_get_fields(group);

		for (; fields ; fields = fields->next)
		{
			PurpleRequestField *field = fields->data;
			PurpleRequestFieldType type = purple_request_field_get_type(field);
			if (type == PURPLE_REQUEST_FIELD_BOOLEAN)
			{
				GntWidget *check = FINCH_GET_DATA(field);
				gboolean value = gnt_check_box_get_checked(GNT_CHECK_BOX(check));
				purple_request_field_bool_set_value(field, value);
			}
			else if (type == PURPLE_REQUEST_FIELD_STRING)
			{
				GntWidget *entry = FINCH_GET_DATA(field);
				const char *text = gnt_entry_get_text(GNT_ENTRY(entry));
				purple_request_field_string_set_value(field, (text && *text) ? text : NULL);
			}
			else if (type == PURPLE_REQUEST_FIELD_INTEGER)
			{
				GntWidget *entry = FINCH_GET_DATA(field);
				const char *text = gnt_entry_get_text(GNT_ENTRY(entry));
				int value = (text && *text) ? atoi(text) : 0;
				purple_request_field_int_set_value(field, value);
			}
			else if (type == PURPLE_REQUEST_FIELD_CHOICE)
			{
				GntWidget *combo = FINCH_GET_DATA(field);
				int id;
				id = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)));
				purple_request_field_choice_set_value(field, id);
			}
			else if (type == PURPLE_REQUEST_FIELD_LIST)
			{
				GList *list = NULL;
				if (purple_request_field_list_get_multi_select(field))
				{
					GList *iter;
					GntWidget *tree = FINCH_GET_DATA(field);

					iter = purple_request_field_list_get_items(field);
					for (; iter; iter = iter->next)
					{
						const char *text = iter->data;
						gpointer key = purple_request_field_list_get_data(field, text);
						if (gnt_tree_get_choice(GNT_TREE(tree), key))
							list = g_list_prepend(list, key);
					}
				}
				else
				{
					GntWidget *combo = FINCH_GET_DATA(field);
					gpointer data = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo));
					list = g_list_append(list, data);
				}

				purple_request_field_list_set_selected(field, list);
				g_list_free(list);
			}
			else if (type == PURPLE_REQUEST_FIELD_ACCOUNT)
			{
				GntWidget *combo = FINCH_GET_DATA(field);
				PurpleAccount *acc = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo));
				purple_request_field_account_set_value(field, acc);
			}
		}
	}

	purple_notify_close_with_handle(button);

	if (!g_object_get_data(G_OBJECT(button), "cancellation-function") &&
			!purple_request_fields_all_required_filled(fields)) {
		purple_notify_error(button, _("Error"),
				_("You must fill all the required fields."),
				_("The required fields are underlined."));
		return;
	}

	if (callback)
		callback(data, fields);

	while (button->parent)
		button = button->parent;

	purple_request_close(PURPLE_REQUEST_FIELDS, button);
}
Exemple #22
0
static void
gnt_combo_box_size_changed(GntWidget *widget, int oldw, int oldh)
{
	GntComboBox *box = GNT_COMBO_BOX(widget);
	gnt_widget_set_size(box->dropdown, widget->priv.width - 1, box->dropdown->priv.height);
}
Exemple #23
0
static gboolean
popup_substatus(GntTree *tree, const char *key, EditStatus *edit)
{
	if (key[0] == ' ' && key[1] == 0)
	{
		EditSubStatus *sub;
		GntWidget *window, *combo, *entry, *box, *button, *l;
		PurpleSavedStatusSub *substatus = NULL;
		GList *iter;
		char *name;
		RowInfo *selected = gnt_tree_get_selection_data(tree);
		PurpleAccount *account = selected->account;

		if (gnt_tree_get_choice(tree, selected))
		{
			/* There was a savedstatus for this account. Now remove it. */
			g_free(selected->message);
			selected->type = NULL;
			selected->message = NULL;
			/* XXX: should we really be saving it right now? */
			purple_savedstatus_unset_substatus(edit->saved, account);
			gnt_tree_change_text(tree, account, 1, NULL);
			gnt_tree_change_text(tree, account, 2, NULL);
			return FALSE;
		}

		if (g_hash_table_lookup(edit->hash, account))
			return TRUE;

		if (edit->saved)
			substatus = purple_savedstatus_get_substatus(edit->saved, account);

		sub = g_new0(EditSubStatus, 1);
		sub->parent = edit;
		sub->key = selected;

		sub->window = window = gnt_vbox_new(FALSE);
		gnt_box_set_toplevel(GNT_BOX(window), TRUE);
		gnt_box_set_title(GNT_BOX(window), _("Substatus"));  /* XXX: a better title */
		gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID);

		box = gnt_hbox_new(FALSE);
		gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Account:")));
		name = g_strdup_printf("%s (%s)", purple_account_get_username(account),
				purple_account_get_protocol_name(account));
		gnt_box_add_widget(GNT_BOX(box), gnt_label_new(name));
		g_free(name);
		gnt_box_add_widget(GNT_BOX(window), box);

		box = gnt_hbox_new(FALSE);
		gnt_box_add_widget(GNT_BOX(box), (l = gnt_label_new(_("Status:"))));
		gnt_widget_set_size(l, 0, 1);   /* I don't like having to do this */
		sub->type = combo = gnt_combo_box_new();
		gnt_box_add_widget(GNT_BOX(box), combo);
		gnt_box_add_widget(GNT_BOX(window), box);

		for (iter = purple_account_get_status_types(account); iter; iter = iter->next)
		{
			PurpleStatusType *type = iter->data;
			if (!purple_status_type_is_user_settable(type))
				continue;
			gnt_combo_box_add_data(GNT_COMBO_BOX(combo), type, purple_status_type_get_name(type));
		}

		box = gnt_hbox_new(FALSE);
		gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Message:")));
		sub->message = entry = gnt_entry_new(substatus ? purple_savedstatus_substatus_get_message(substatus) : NULL);
		gnt_box_add_widget(GNT_BOX(box), entry);
		gnt_box_add_widget(GNT_BOX(window), box);

		box  = gnt_hbox_new(FALSE);
		button = gnt_button_new(_("Cancel"));
		g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), window);
		gnt_box_add_widget(GNT_BOX(box), button);
		button = gnt_button_new(_("Save"));
		g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(save_substatus_cb), sub);
		gnt_box_add_widget(GNT_BOX(box), button);
		gnt_box_add_widget(GNT_BOX(window), box);

		gnt_widget_show(window);

		g_hash_table_insert(edit->hash, account, sub);

		g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(substatus_window_destroy_cb), sub);

		return TRUE;
	}
	return FALSE;
}
Exemple #24
0
static void
gnt_combo_box_destroy(GntWidget *widget)
{
	gnt_widget_destroy(GNT_COMBO_BOX(widget)->dropdown->parent);
}
Exemple #25
0
static void
setup_roomlist(PurpleAccount *account)
{
	GntWidget *window, *tree, *hbox, *accounts;
	int iter;
	struct {
		const char *label;
		GCallback callback;
		GntWidget **widget;
	} buttons[] = {
		{_("Stop"), G_CALLBACK(fl_stop), &froomlist.stop},
		{_("Get"), G_CALLBACK(fl_get_list), &froomlist.getlist},
		{_("Add"), G_CALLBACK(fl_add_chat), &froomlist.add},
		{_("Close"), G_CALLBACK(fl_close), &froomlist.close},
		{NULL, NULL, NULL}
	};

	if (froomlist.window)
		return;

	froomlist.window = window = gnt_window_new();
	g_object_set(G_OBJECT(window), "vertical", TRUE, NULL);
	gnt_box_set_pad(GNT_BOX(window), 0);
	gnt_box_set_title(GNT_BOX(window), _("Room List"));
	gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID);

	froomlist.accounts = accounts = gnt_combo_box_new();
	reset_account_list(account);
	gnt_box_add_widget(GNT_BOX(window), accounts);
	g_signal_connect(G_OBJECT(accounts), "selection-changed",
			G_CALLBACK(roomlist_account_changed), NULL);
	froomlist.account = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(accounts));

	froomlist.tree = tree = gnt_tree_new_with_columns(2);
	gnt_tree_set_show_title(GNT_TREE(tree), TRUE);
	g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(roomlist_activated), NULL);
	gnt_tree_set_column_titles(GNT_TREE(tree), _("Name"), "");
	gnt_tree_set_show_separator(GNT_TREE(tree), FALSE);
	gnt_tree_set_col_width(GNT_TREE(tree), 1, 1);
	gnt_tree_set_column_resizable(GNT_TREE(tree), 1, FALSE);
	gnt_tree_set_search_column(GNT_TREE(tree), 0);

	gnt_box_add_widget(GNT_BOX(window), tree);

	froomlist.details = gnt_text_view_new();
	gnt_text_view_set_flag(GNT_TEXT_VIEW(froomlist.details), GNT_TEXT_VIEW_TOP_ALIGN);
	gnt_box_add_widget(GNT_BOX(window), froomlist.details);
	gnt_widget_set_size(froomlist.details, -1, 8);

	hbox = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(window), hbox);

	for (iter = 0; buttons[iter].label; iter++) {
		GntWidget *button = gnt_button_new(buttons[iter].label);
		gnt_box_add_widget(GNT_BOX(hbox), button);
		g_signal_connect(G_OBJECT(button), "activate", buttons[iter].callback, NULL);
		*buttons[iter].widget = button;
		gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(froomlist.details), button);
	}

	g_signal_connect(G_OBJECT(tree), "selection-changed", G_CALLBACK(roomlist_selection_changed), NULL);

	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(unset_roomlist), NULL);
}
Exemple #26
0
	gnt_bindable_class_register_action(bindable, "dropdown", dropdown_menu,
			GNT_KEY_DOWN, NULL);
	gnt_bindable_register_binding(bindable, "dropdown", GNT_KEY_UP, NULL);

	gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable);

	GNTDEBUG;
}

static void
gnt_combo_box_init(GTypeInstance *instance, gpointer class)
{
	GntWidget *box;
	GntWidget *widget = GNT_WIDGET(instance);
	GntComboBox *combo = GNT_COMBO_BOX(instance);

	GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance),
			GNT_WIDGET_GROW_X | GNT_WIDGET_CAN_TAKE_FOCUS | GNT_WIDGET_NO_SHADOW);
	combo->dropdown = gnt_tree_new();

	box = gnt_box_new(FALSE, FALSE);
	GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_NO_SHADOW | GNT_WIDGET_NO_BORDER | GNT_WIDGET_TRANSIENT);
	gnt_box_set_pad(GNT_BOX(box), 0);
	gnt_box_add_widget(GNT_BOX(box), combo->dropdown);

	widget->priv.minw = 4;
	widget->priv.minh = 3;
	GNTDEBUG;
}
Exemple #27
0
void
finch_sounds_show_all(void)
{
	GntWidget *box, *tmpbox, *splitbox, *cmbox, *slider;
	GntWidget *entry;
	GntWidget *chkbox;
	GntWidget *button;
	GntWidget *label;
	GntWidget *tree;
	GntWidget *win;

	gint i;
	GList *itr, *list;

	if (pref_dialog) {
		gnt_window_present(pref_dialog->window);
		return;
	}

	pref_dialog = g_new0(SoundPrefDialog, 1);

	pref_dialog->original_profile = g_strdup(finch_sound_get_active_profile());

	pref_dialog->window = win = gnt_window_box_new(FALSE, TRUE);
	gnt_box_set_pad(GNT_BOX(win), 0);
	gnt_box_set_toplevel(GNT_BOX(win), TRUE);
	gnt_box_set_title(GNT_BOX(win), _("Sound Preferences"));
	gnt_box_set_fill(GNT_BOX(win), TRUE);
	gnt_box_set_alignment(GNT_BOX(win), GNT_ALIGN_MID);

	/* Profiles */
	splitbox = gnt_hbox_new(FALSE);
	gnt_box_set_pad(GNT_BOX(splitbox), 0);
	gnt_box_set_alignment(GNT_BOX(splitbox), GNT_ALIGN_TOP);

	box = gnt_vbox_new(FALSE);
	gnt_box_set_pad(GNT_BOX(box), 0);
	gnt_box_add_widget(GNT_BOX(box), gnt_label_new_with_format(_("Profiles"), GNT_TEXT_FLAG_BOLD));
	pref_dialog->profiles = tree = gnt_tree_new();
	gnt_tree_set_hash_fns(GNT_TREE(tree), g_str_hash, g_str_equal, g_free);
	gnt_tree_set_compare_func(GNT_TREE(tree), (GCompareFunc)g_ascii_strcasecmp);
	g_signal_connect(G_OBJECT(tree), "selection-changed", G_CALLBACK(prof_load_cb), NULL);

	itr = list = finch_sound_get_profiles();
	for (; itr; itr = itr->next) {
		/* Do not free itr->data. It's the stored as a key for the tree, and will
		 * be freed when the tree is destroyed. */
		gnt_tree_add_row_after(GNT_TREE(tree), itr->data,
				gnt_tree_create_row(GNT_TREE(tree), itr->data), NULL, NULL);
	}
	g_list_free(list);

	gnt_box_add_widget(GNT_BOX(box), tree);

	pref_dialog->new_profile = entry = gnt_entry_new("");
	gnt_box_add_widget(GNT_BOX(box), entry);

	tmpbox = gnt_hbox_new(FALSE);
	button = gnt_button_new("Add");
	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(prof_add_cb), entry);
	gnt_box_add_widget(GNT_BOX(tmpbox), button);
	button = gnt_button_new("Delete");
	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(prof_del_cb), NULL);
	gnt_box_add_widget(GNT_BOX(tmpbox), button);
	gnt_box_add_widget(GNT_BOX(box), tmpbox);
	gnt_box_add_widget(GNT_BOX(splitbox), box);

	gnt_box_add_widget(GNT_BOX(splitbox), gnt_vline_new());

	/* Sound method */

	box = gnt_vbox_new(FALSE);
	gnt_box_set_pad(GNT_BOX(box), 0);

	pref_dialog->method = cmbox = gnt_combo_box_new();
	gnt_tree_set_hash_fns(GNT_TREE(GNT_COMBO_BOX(cmbox)->dropdown), g_str_hash, g_str_equal, NULL);
	gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox), "automatic", _("Automatic"));
	gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox), "alsa", "ALSA");
	gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox), "esd", "ESD");
	gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox), "beep", _("Console Beep"));
	gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox), "custom", _("Command"));
	gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox), "nosound", _("No Sound"));

	label = gnt_label_new_with_format(_("Sound Method"), GNT_TEXT_FLAG_BOLD);
	gnt_box_add_widget(GNT_BOX(box), label);
	tmpbox = gnt_hbox_new(TRUE);
	gnt_box_set_fill(GNT_BOX(tmpbox), FALSE);
	gnt_box_set_pad(GNT_BOX(tmpbox), 0);
	gnt_box_add_widget(GNT_BOX(tmpbox), gnt_label_new(_("Method: ")));
	gnt_box_add_widget(GNT_BOX(tmpbox), cmbox);
	gnt_box_add_widget(GNT_BOX(box), tmpbox);

	tmpbox = gnt_hbox_new(TRUE);
	gnt_box_set_pad(GNT_BOX(tmpbox), 0);
	gnt_box_set_fill(GNT_BOX(tmpbox), FALSE);
	gnt_box_add_widget(GNT_BOX(tmpbox), gnt_label_new(_("Sound Command\n(%s for filename)")));
	pref_dialog->command = entry = gnt_entry_new("");
	gnt_box_add_widget(GNT_BOX(tmpbox), entry);
	gnt_box_add_widget(GNT_BOX(box), tmpbox);

	gnt_box_add_widget(GNT_BOX(box), gnt_line_new(FALSE));

	/* Sound options */
	gnt_box_add_widget(GNT_BOX(box), gnt_label_new_with_format(_("Sound Options"), GNT_TEXT_FLAG_BOLD));
	pref_dialog->conv_focus = chkbox = gnt_check_box_new(_("Sounds when conversation has focus"));
	gnt_box_add_widget(GNT_BOX(box), chkbox);

	tmpbox = gnt_hbox_new(TRUE);
	gnt_box_set_pad(GNT_BOX(tmpbox), 0);
	gnt_box_set_fill(GNT_BOX(tmpbox), FALSE);
	gnt_box_add_widget(GNT_BOX(tmpbox), gnt_label_new("Enable Sounds:"));
	pref_dialog->while_status = cmbox = gnt_combo_box_new();
	gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox), GINT_TO_POINTER(3), _("Always"));
	gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox), GINT_TO_POINTER(1), _("Only when available"));
	gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox), GINT_TO_POINTER(2), _("Only when not available"));
	gnt_box_add_widget(GNT_BOX(tmpbox), cmbox);
	gnt_box_add_widget(GNT_BOX(box), tmpbox);

	tmpbox = gnt_hbox_new(TRUE);
	gnt_box_set_pad(GNT_BOX(tmpbox), 0);
	gnt_box_set_fill(GNT_BOX(tmpbox), FALSE);
	gnt_box_add_widget(GNT_BOX(tmpbox), gnt_label_new(_("Volume(0-100):")));

	pref_dialog->volume = slider = gnt_slider_new(FALSE, 100, 0);
	gnt_slider_set_step(GNT_SLIDER(slider), 5);
	gnt_slider_set_small_step(GNT_SLIDER(slider), 1);
	gnt_slider_set_large_step(GNT_SLIDER(slider), 20);
	label = gnt_label_new("");
	gnt_slider_reflect_label(GNT_SLIDER(slider), GNT_LABEL(label));
	gnt_box_set_pad(GNT_BOX(tmpbox), 1);
	gnt_box_add_widget(GNT_BOX(tmpbox), slider);
	gnt_box_add_widget(GNT_BOX(tmpbox), label);
	gnt_box_add_widget(GNT_BOX(box), tmpbox);
	gnt_box_add_widget(GNT_BOX(splitbox), box);

	gnt_box_add_widget(GNT_BOX(win), splitbox);

	gnt_box_add_widget(GNT_BOX(win), gnt_hline_new());

	/* Sound events */
	gnt_box_add_widget(GNT_BOX(win), gnt_label_new_with_format(_("Sound Events"), GNT_TEXT_FLAG_BOLD));
	pref_dialog->events = tree = gnt_tree_new_with_columns(2);
	gnt_tree_set_column_titles(GNT_TREE(tree), _("Event"), _("File"));
	gnt_tree_set_show_title(GNT_TREE(tree), TRUE);

	for (i = 0; i < PURPLE_NUM_SOUNDS; i++) {
		FinchSoundEvent * event = &sounds[i];

		if (event->label == NULL) {
			continue;
		}

		gnt_tree_add_choice(GNT_TREE(tree), GINT_TO_POINTER(i),
			gnt_tree_create_row(GNT_TREE(tree), event->label, event->def),
			NULL, NULL);
	}

	gnt_tree_adjust_columns(GNT_TREE(tree));
	gnt_box_add_widget(GNT_BOX(win), tree);

	box = gnt_hbox_new(FALSE);
	button = gnt_button_new(_("Test"));
	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(test_cb), NULL);
	gnt_box_add_widget(GNT_BOX(box), button);
	button = gnt_button_new(_("Reset"));
	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(reset_cb), NULL);
	gnt_box_add_widget(GNT_BOX(box), button);
	button = gnt_button_new(_("Choose..."));
	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(choose_cb), NULL);
	gnt_box_add_widget(GNT_BOX(box), button);
	gnt_box_add_widget(GNT_BOX(win), box);

	gnt_box_add_widget(GNT_BOX(win), gnt_line_new(FALSE));

	/* Add new stuff before this */
	box = gnt_hbox_new(FALSE);
	gnt_box_set_fill(GNT_BOX(box), TRUE);
	button = gnt_button_new(_("Save"));
	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(save_cb), win);
	gnt_box_add_widget(GNT_BOX(box), button);
	button = gnt_button_new(_("Cancel"));
	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(cancel_cb), win);
	gnt_box_add_widget(GNT_BOX(box), button);
	gnt_box_add_widget(GNT_BOX(win), box);

	g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(release_pref_dialog), NULL);

	load_pref_window(finch_sound_get_active_profile());

	gnt_widget_show(win);
}
Exemple #28
0
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);
}
Exemple #29
0
void
finch_pounce_editor_show(PurpleAccount *account, const char *name,
							PurplePounce *cur_pounce)
{
	PurpleGntPounceDialog *dialog;
	GntWidget *window;
	GntWidget *bbox;
	GntWidget *hbox, *vbox;
	GntWidget *button;
	GntWidget *combo;
	GList *list;

	g_return_if_fail((cur_pounce != NULL) ||
	                 (account != NULL) ||
	                 (purple_accounts_get_all() != NULL));

	dialog = g_new0(PurpleGntPounceDialog, 1);

	if (cur_pounce != NULL) {
		dialog->pounce  = cur_pounce;
		dialog->account = purple_pounce_get_pouncer(cur_pounce);
	} else if (account != NULL) {
		dialog->pounce  = NULL;
		dialog->account = account;
	} else {
		GList *connections = purple_connections_get_all();
		PurpleConnection *gc;

		if (connections != NULL) {
			gc = (PurpleConnection *)connections->data;
			dialog->account = purple_connection_get_account(gc);
		} else
			dialog->account = purple_accounts_get_all()->data;

		dialog->pounce  = NULL;
	}

	/* Create the window. */
	dialog->window = window = gnt_vbox_new(FALSE);
	gnt_box_set_pad(GNT_BOX(window), 0);
	gnt_box_set_toplevel(GNT_BOX(window), TRUE);
	gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_LEFT);
	gnt_box_set_title(GNT_BOX(window),
						 (cur_pounce == NULL
						  ? _("New Buddy Pounce") : _("Edit Buddy Pounce")));

	g_signal_connect(G_OBJECT(window), "destroy",
					 G_CALLBACK(delete_win_cb), dialog);

	gnt_box_add_widget(GNT_BOX(window), gnt_label_new_with_format(_("Pounce on Whom"), GNT_TEXT_FLAG_BOLD));

	/* Account: */
	gnt_box_add_widget(GNT_BOX(window), gnt_label_new(_("Account:")));
	dialog->account_menu = combo = gnt_combo_box_new();
	list = purple_accounts_get_all();
	for (; list; list = list->next)
	{
		PurpleAccount *account;
		char *text;

		account = list->data;
		text = g_strdup_printf("%s (%s)",
				purple_account_get_username(account),
				purple_account_get_protocol_name(account));
		gnt_combo_box_add_data(GNT_COMBO_BOX(combo), account, text);
		g_free(text);
	}
	if (dialog->account)
		gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), dialog->account);

	gnt_box_add_widget(GNT_BOX(window), combo);

	/* Buddy: */
	hbox = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Buddy name:")));

	dialog->buddy_entry = gnt_entry_new(NULL);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->buddy_entry);

	setup_buddy_list_suggestion(GNT_ENTRY(dialog->buddy_entry), TRUE);

	gnt_box_add_widget(GNT_BOX(window), hbox);

	if (cur_pounce != NULL) {
		gnt_entry_set_text(GNT_ENTRY(dialog->buddy_entry),
						   purple_pounce_get_pouncee(cur_pounce));
	} else if (name != NULL) {
		gnt_entry_set_text(GNT_ENTRY(dialog->buddy_entry), name);
	}

	/* Create the event frame */
	gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE));
	gnt_box_add_widget(GNT_BOX(window), gnt_label_new_with_format(_("Pounce When Buddy..."), GNT_TEXT_FLAG_BOLD));

	dialog->signon = gnt_check_box_new(_("Signs on"));
	dialog->signoff = gnt_check_box_new(_("Signs off"));
	dialog->away = gnt_check_box_new(_("Goes away"));
	dialog->away_return = gnt_check_box_new(_("Returns from away"));
	dialog->idle = gnt_check_box_new(_("Becomes idle"));
	dialog->idle_return = gnt_check_box_new(_("Is no longer idle"));
	dialog->typing = gnt_check_box_new(_("Starts typing"));
	dialog->typed = gnt_check_box_new(_("Pauses while typing"));
	dialog->stop_typing = gnt_check_box_new(_("Stops typing"));
	dialog->message_recv = gnt_check_box_new(_("Sends a message"));

	hbox = gnt_hbox_new(TRUE);
	gnt_box_set_pad(GNT_BOX(hbox), 2);

	vbox = gnt_vbox_new(FALSE);
	gnt_box_set_pad(GNT_BOX(vbox), 0);
	gnt_box_add_widget(GNT_BOX(hbox), vbox);

	gnt_box_add_widget(GNT_BOX(vbox), dialog->signon);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->away);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->idle);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->typing);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->stop_typing);

	vbox = gnt_vbox_new(FALSE);
	gnt_box_set_pad(GNT_BOX(vbox), 0);
	gnt_box_add_widget(GNT_BOX(hbox), vbox);

	gnt_box_add_widget(GNT_BOX(vbox), dialog->signoff);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->away_return);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->idle_return);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->typed);
	gnt_box_add_widget(GNT_BOX(vbox), dialog->message_recv);

	gnt_box_add_widget(GNT_BOX(window), hbox);

	/* Create the "Action" frame. */
	gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE));
	gnt_box_add_widget(GNT_BOX(window), gnt_label_new_with_format(_("Action"), GNT_TEXT_FLAG_BOLD));

	dialog->open_win = gnt_check_box_new(_("Open an IM window"));
	dialog->popup = gnt_check_box_new(_("Pop up a notification"));
	dialog->send_msg = gnt_check_box_new(_("Send a message"));
	dialog->exec_cmd = gnt_check_box_new(_("Execute a command"));
	dialog->play_sound = gnt_check_box_new(_("Play a sound"));

	dialog->send_msg_entry    = gnt_entry_new(NULL);
	dialog->exec_cmd_entry    = gnt_entry_new(NULL);
	dialog->popup_entry       = gnt_entry_new(NULL);
	dialog->exec_cmd_entry   = gnt_entry_new(NULL);

	hbox = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->open_win);
	gnt_box_add_widget(GNT_BOX(window), hbox);
	hbox = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->popup);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->popup_entry);
	gnt_box_add_widget(GNT_BOX(window), hbox);
	hbox = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->send_msg);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->send_msg_entry);
	gnt_box_add_widget(GNT_BOX(window), hbox);
	hbox = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->exec_cmd);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->exec_cmd_entry);
	gnt_box_add_widget(GNT_BOX(window), hbox);
	hbox = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(hbox), dialog->play_sound);
	gnt_box_add_widget(GNT_BOX(window), hbox);

	gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE));
	gnt_box_add_widget(GNT_BOX(window), gnt_label_new_with_format(_("Options"), GNT_TEXT_FLAG_BOLD));
	dialog->on_away = gnt_check_box_new(_("Pounce only when my status is not Available"));
	gnt_box_add_widget(GNT_BOX(window), dialog->on_away);
	dialog->save_pounce = gnt_check_box_new(_("Recurring"));
	gnt_box_add_widget(GNT_BOX(window), dialog->save_pounce);


	gnt_box_add_widget(GNT_BOX(window), gnt_line_new(FALSE));
	/* Now the button box! */
	bbox = gnt_hbox_new(FALSE);

	/* Cancel button */
	button = gnt_button_new(_("Cancel"));
	gnt_box_add_widget(GNT_BOX(bbox), button);
	g_signal_connect(G_OBJECT(button), "activate",
					 G_CALLBACK(cancel_cb), dialog);

	/* Save button */
	dialog->save_button = button = gnt_button_new(_("Save"));
	gnt_box_add_widget(GNT_BOX(bbox), button);
	g_signal_connect(G_OBJECT(button), "activate",
					 G_CALLBACK(save_pounce_cb), dialog);

	gnt_box_add_widget(GNT_BOX(window), bbox);


	/* Set the values of stuff. */
	if (cur_pounce != NULL)
	{
		PurplePounceEvent events   = purple_pounce_get_events(cur_pounce);
		PurplePounceOption options = purple_pounce_get_options(cur_pounce);
		const char *value;

		/* Options */
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->on_away),
									(options & PURPLE_POUNCE_OPTION_AWAY));

		/* Events */
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->signon),
									(events & PURPLE_POUNCE_SIGNON));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->signoff),
									(events & PURPLE_POUNCE_SIGNOFF));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->away),
									(events & PURPLE_POUNCE_AWAY));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->away_return),
									(events & PURPLE_POUNCE_AWAY_RETURN));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->idle),
									(events & PURPLE_POUNCE_IDLE));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->idle_return),
									(events & PURPLE_POUNCE_IDLE_RETURN));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->typing),
									(events & PURPLE_POUNCE_TYPING));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->typed),
									(events & PURPLE_POUNCE_TYPED));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->stop_typing),
									(events & PURPLE_POUNCE_TYPING_STOPPED));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->message_recv),
									(events & PURPLE_POUNCE_MESSAGE_RECEIVED));

		/* Actions */
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->open_win),
			purple_pounce_action_is_enabled(cur_pounce, "open-window"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->popup),
			purple_pounce_action_is_enabled(cur_pounce, "popup-notify"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->send_msg),
			purple_pounce_action_is_enabled(cur_pounce, "send-message"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->exec_cmd),
			purple_pounce_action_is_enabled(cur_pounce, "execute-command"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->play_sound),
			purple_pounce_action_is_enabled(cur_pounce, "play-beep"));

		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->save_pounce),
			purple_pounce_get_save(cur_pounce));

		if ((value = purple_pounce_action_get_attribute(cur_pounce,
		                                              "send-message",
		                                              "message")) != NULL)
		{
			gnt_entry_set_text(GNT_ENTRY(dialog->send_msg_entry), value);
		}

		if ((value = purple_pounce_action_get_attribute(cur_pounce,
		                                              "popup-notify",
		                                              "reason")) != NULL)
		{
			gnt_entry_set_text(GNT_ENTRY(dialog->popup_entry), value);
		}

		if ((value = purple_pounce_action_get_attribute(cur_pounce,
		                                              "execute-command",
		                                              "command")) != NULL)
		{
			gnt_entry_set_text(GNT_ENTRY(dialog->exec_cmd_entry), value);
		}
	}
	else
	{
		PurpleBuddy *buddy = NULL;

		if (name != NULL)
			buddy = purple_find_buddy(account, name);

		/* Set some defaults */
		if (buddy == NULL) {
			gnt_check_box_set_checked(
				GNT_CHECK_BOX(dialog->signon), TRUE);
		} else {
			if (!PURPLE_BUDDY_IS_ONLINE(buddy)) {
				gnt_check_box_set_checked(
					GNT_CHECK_BOX(dialog->signon), TRUE);
			} else {
				gboolean default_set = FALSE;
				PurplePresence *presence = purple_buddy_get_presence(buddy);

				if (purple_presence_is_idle(presence))
				{
					gnt_check_box_set_checked(
						GNT_CHECK_BOX(dialog->idle_return), TRUE);

					default_set = TRUE;
				}

				if (!purple_presence_is_available(presence))
				{
					gnt_check_box_set_checked(
						GNT_CHECK_BOX(dialog->away_return), TRUE);

					default_set = TRUE;
				}

				if (!default_set)
				{
					gnt_check_box_set_checked(
						GNT_CHECK_BOX(dialog->signon), TRUE);
				}
			}
		}

		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->open_win),
			purple_prefs_get_bool("/finch/pounces/default_actions/open-window"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->popup),
			purple_prefs_get_bool("/finch/pounces/default_actions/popup-notify"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->send_msg),
			purple_prefs_get_bool("/finch/pounces/default_actions/send-message"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->exec_cmd),
			purple_prefs_get_bool("/finch/pounces/default_actions/execute-command"));
		gnt_check_box_set_checked(GNT_CHECK_BOX(dialog->play_sound),
			purple_prefs_get_bool("/finch/pounces/default_actions/play-beep"));
	}

	gnt_widget_show(window);
}