Ejemplo n.º 1
0
static void
signature_manager_edit_signature (ESignatureManager *manager)
{
	ESignatureTreeView *tree_view;
	ESignatureList *signature_list;
	ESignature *signature;
	GtkWidget *editor;
	const gchar *title;
	const gchar *filename;

	tree_view = e_signature_manager_get_tree_view (manager);
	signature = e_signature_tree_view_get_selected (tree_view);
	signature_list = e_signature_manager_get_signature_list (manager);

	if (signature == NULL)
		return;

	if (e_signature_get_is_script (signature))
		goto script;

	filename = e_signature_get_filename (signature);
	if (filename == NULL || *filename == '\0')
		e_signature_set_filename (signature, _("Unnamed"));

	editor = e_signature_editor_new ();
	e_signature_editor_set_signature (
		E_SIGNATURE_EDITOR (editor), signature);
	signature_manager_emit_editor_created (manager, editor);

	goto exit;

script:
	title = _("Edit Signature Script");

	if (signature_manager_run_script_dialog (manager, signature, title))
		e_signature_list_change (signature_list, signature);

	e_signature_list_save (signature_list);

exit:
	gtk_widget_grab_focus (GTK_WIDGET (tree_view));

	g_object_unref (signature);
}
Ejemplo n.º 2
0
static void
action_save_and_close_cb (GtkAction *action,
                          ESignatureEditor *editor)
{
	GtkWidget *entry;
	ESignatureList *signature_list;
	ESignature *signature;
	ESignature *same_name;
	const gchar *filename;
	gchar *signature_name;
	gboolean html;
	GError *error = NULL;

	entry = editor->priv->entry;
	html = gtkhtml_editor_get_html_mode (GTKHTML_EDITOR (editor));

	if (editor->priv->signature == NULL)
		signature = mail_config_signature_new (NULL, FALSE, html);
	else {
		signature = g_object_ref (editor->priv->signature);
		signature->html = html;
	}

	filename = signature->filename;
	gtkhtml_editor_save (GTKHTML_EDITOR (editor), filename, html, &error);

	if (error != NULL) {
		e_error_run (
			GTK_WINDOW (editor),
			"mail:no-save-signature",
			error->message, NULL);
		g_clear_error (&error);
		return;
	}

	signature_list = mail_config_get_signatures ();

	signature_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
	g_strstrip (signature_name);

	/* Make sure the signature name is not blank. */
	if (*signature_name == '\0') {
		e_error_run (
			GTK_WINDOW (editor),
			"mail:blank-signature", NULL);
		gtk_widget_grab_focus (entry);
		g_free (signature_name);
		return;
	}

	/* Don't overwrite an existing signature of the same name.
	 * XXX ESignatureList misuses const. */
	same_name = (ESignature *) e_signature_list_find (
		signature_list, E_SIGNATURE_FIND_NAME, signature_name);
	if (same_name != NULL && strcmp (signature->uid, same_name->uid) != 0) {
		e_error_run (
			GTK_WINDOW (editor),
			"mail:signature-already-exists",
			signature_name, NULL);
		gtk_widget_grab_focus (entry);
		g_free (signature_name);
		return;
	}

	g_free (signature->name);
	signature->name = signature_name;

	if (editor->priv->signature != NULL)
		e_signature_list_change (signature_list, signature);
	else
		mail_config_add_signature (signature);

	gtk_widget_destroy (GTK_WIDGET (editor));
}