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 #2
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);
}
Exemple #3
0
void
finch_xfer_dialog_cancel_xfer(PurpleXfer *xfer)
{
	PurpleGntXferUiData *data;
	const gchar *status;

	g_return_if_fail(xfer_dialog != NULL);
	g_return_if_fail(xfer != NULL);

	data = FINCHXFER(xfer);

	if (data == NULL)
		return;

	if (!data->in_list)
		return;

	if ((purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL) && (xfer_dialog->auto_clear)) {
		finch_xfer_dialog_remove_xfer(xfer);
		return;
	}

	update_title_progress();

	if (purple_xfer_is_canceled(xfer))
		status = _("Cancelled");
	else
		status = _("Failed");

	gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_STATUS, status);
}
Exemple #4
0
static void
reset_cb(GntWidget *button, gpointer null)
{
	/* Don't dereference this pointer ! */
	gpointer key = gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events));

	FinchSoundEvent * event = &sounds[GPOINTER_TO_INT(key)];
	g_free(event->file);
	event->file = NULL;
	gnt_tree_change_text(GNT_TREE(pref_dialog->events), key, 1, _("(default)"));
}
Exemple #5
0
static void
file_cb(GntFileSel *w, const char *path, const char *file, gpointer data)
{
	FinchSoundEvent *event = data;

	g_free(event->file);
	event->file = g_strdup(path);

	gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(event->id), 1, file);
	gnt_tree_set_choice(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(event->id), TRUE);

	gnt_widget_destroy(GNT_WIDGET(w));
}
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);
}
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 #8
0
void
finch_xfer_dialog_update_xfer(PurpleXfer *xfer)
{
	PurpleGntXferUiData *data;
	char *size_str, *remaining_str;
	time_t current_time;
	char prog_str[5];
	double kb_sent;
	double kbps = 0.0;
	time_t elapsed, now;
	char *kbsec;
	gboolean send;

	if ((now = purple_xfer_get_end_time(xfer)) == 0)
		now = time(NULL);

	kb_sent = purple_xfer_get_bytes_sent(xfer) / 1024.0;
	elapsed = (purple_xfer_get_start_time(xfer) > 0 ? now - purple_xfer_get_start_time(xfer) : 0);
	kbps    = (elapsed > 0 ? (kb_sent / elapsed) : 0);

	g_return_if_fail(xfer_dialog != NULL);
	g_return_if_fail(xfer != NULL);

	if ((data = FINCHXFER(xfer)) == NULL)
		return;

	if (data->in_list == FALSE || data->notified)
		return;

	current_time = time(NULL);
	if (((current_time - data->last_updated_time) == 0) &&
		(!purple_xfer_is_completed(xfer))) {
		/* Don't update the window more than once per second */
		return;
	}
	data->last_updated_time = current_time;

	send = (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND);
	size_str      = purple_str_size_to_units(purple_xfer_get_size(xfer));
	remaining_str = purple_str_size_to_units(purple_xfer_get_bytes_remaining(xfer));
	kbsec = g_strdup_printf(_("%.2f KiB/s"), kbps);

	gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_PROGRESS,
			g_ascii_dtostr(prog_str, sizeof(prog_str), purple_xfer_get_progress(xfer) * 100.));
	gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_SIZE, size_str);
	gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_REMAINING, remaining_str);
	gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_SPEED, kbsec);
	g_free(size_str);
	g_free(remaining_str);
	g_free(kbsec);
	if (purple_xfer_is_completed(xfer)) {
		gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_STATUS, send ? _("Sent") : _("Received"));
		gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_REMAINING, _("Finished"));
		if (!send) {
			char *msg = g_strdup_printf(_("The file was saved as %s."), purple_xfer_get_local_filename(xfer));
			purple_xfer_conversation_write(xfer, msg, FALSE);
			g_free(msg);
		}
		data->notified = TRUE;
	} else {
		gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_STATUS,
				send ? _("Sending") : _("Receiving"));
	}

	update_title_progress();

	if (purple_xfer_is_completed(xfer) && xfer_dialog->auto_clear)
		finch_xfer_dialog_remove_xfer(xfer);
}