Return",
NULL,
G_CALLBACK (action_save_and_close_cb) },
{ "file-menu",
NULL,
N_("_File"),
NULL,
NULL,
NULL }
};
static gboolean
signature_editor_delete_event_cb (ESignatureEditor *editor,
GdkEvent *event)
{
GtkActionGroup *action_group;
GtkAction *action;
action_group = editor->priv->action_group;
action = gtk_action_group_get_action (action_group, "close");
gtk_action_activate (action);
return TRUE;
}
static void
signature_editor_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_SIGNATURE:
e_signature_editor_set_signature (
E_SIGNATURE_EDITOR (object),
g_value_get_object (value));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
signature_editor_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_SIGNATURE:
g_value_set_object (
value, e_signature_editor_get_signature (
E_SIGNATURE_EDITOR (object)));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
signature_editor_dispose (GObject *object)
{
ESignatureEditorPrivate *priv;
priv = E_SIGNATURE_EDITOR_GET_PRIVATE (object);
if (priv->action_group != NULL) {
g_object_unref (priv->action_group);
priv->action_group = NULL;
}
if (priv->signature != NULL) {
g_object_unref (priv->signature);
priv->signature = NULL;
}
if (priv->entry != NULL) {
g_object_unref (priv->entry);
priv->entry = NULL;
}
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
signature_editor_finalize (GObject *object)
{
ESignatureEditorPrivate *priv;
priv = E_SIGNATURE_EDITOR_GET_PRIVATE (object);
g_free (priv->original_name);
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
signature_editor_class_init (ESignatureEditorClass *class)
{
GObjectClass *object_class;
parent_class = g_type_class_peek_parent (class);
g_type_class_add_private (class, sizeof (ESignatureEditorPrivate));
object_class = G_OBJECT_CLASS (class);
object_class->set_property = signature_editor_set_property;
object_class->get_property = signature_editor_get_property;
object_class->dispose = signature_editor_dispose;
object_class->finalize = signature_editor_finalize;
g_object_class_install_property (
object_class,
PROP_SIGNATURE,
g_param_spec_object (
"signature",
NULL,
NULL,
E_TYPE_SIGNATURE,
G_PARAM_READWRITE));
}
static void
signature_editor_init (ESignatureEditor *editor)
{
GtkActionGroup *action_group;
GtkUIManager *ui_manager;
GtkWidget *container;
GtkWidget *widget;
GtkWidget *vbox;
GError *error = NULL;
editor->priv = E_SIGNATURE_EDITOR_GET_PRIVATE (editor);
vbox = GTKHTML_EDITOR (editor)->vbox;
ui_manager = gtkhtml_editor_get_ui_manager (GTKHTML_EDITOR (editor));
gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, &error);
handle_error (&error);
action_group = gtk_action_group_new ("signature");
gtk_action_group_set_translation_domain (
action_group, GETTEXT_PACKAGE);
gtk_action_group_add_actions (
action_group, entries,
G_N_ELEMENTS (entries), editor);
gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
editor->priv->action_group = g_object_ref (action_group);
gtk_ui_manager_ensure_update (ui_manager);
gtk_window_set_title (GTK_WINDOW (editor), _("Edit Signature"));
widget = gtk_hbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (widget), 6);
gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
/* Position 2 should be between the main and style toolbars. */
gtk_box_reorder_child (GTK_BOX (vbox), widget, 2);
gtk_widget_show (widget);
container = widget;
widget = gtk_entry_new ();
gtk_box_pack_end (GTK_BOX (container), widget, TRUE, TRUE, 0);
editor->priv->entry = g_object_ref_sink (widget);
gtk_widget_show (widget);
widget = gtk_label_new_with_mnemonic (_("_Signature Name:"));
gtk_label_set_mnemonic_widget (GTK_LABEL (widget), editor->priv->entry);
gtk_box_pack_end (GTK_BOX (container), widget, FALSE, FALSE, 0);
gtk_widget_show (widget);
g_signal_connect (
editor, "delete-event",
G_CALLBACK (signature_editor_delete_event_cb), NULL);
e_signature_editor_set_signature (editor, NULL);
}
GType
e_signature_editor_get_type (void)
{
static GType type = 0;
if (G_UNLIKELY (type == 0)) {
static const GTypeInfo type_info = {
sizeof (ESignatureEditorClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) signature_editor_class_init,
(GClassFinalizeFunc) NULL,
NULL, /* class_data */
sizeof (ESignatureEditor),
0, /* n_preallocs */
(GInstanceInitFunc) signature_editor_init,
NULL /* value_table */
};
type = g_type_register_static (
GTKHTML_TYPE_EDITOR, "ESignatureEditor",
&type_info, 0);
}
return type;
}
GtkWidget *
e_signature_editor_new (void)
{
return g_object_new (E_TYPE_SIGNATURE_EDITOR, NULL);
}
ESignature *
e_signature_editor_get_signature (ESignatureEditor *editor)
{
g_return_val_if_fail (E_IS_SIGNATURE_EDITOR (editor), NULL);
return editor->priv->signature;
}
void
e_signature_editor_set_signature (ESignatureEditor *editor,
ESignature *signature)
{
const gchar *filename;
const gchar *signature_name;
gboolean is_html;
gchar *contents;
gsize length;
GError *error = NULL;
g_return_if_fail (E_IS_SIGNATURE_EDITOR (editor));
if (signature != NULL)
g_return_if_fail (E_SIGNATURE (signature));
if (editor->priv->signature != NULL) {
g_object_unref (editor->priv->signature);
editor->priv->signature = NULL;
}
if (signature == NULL)
goto exit;
editor->priv->signature = g_object_ref (signature);
/* Load signature content. */
filename = e_signature_get_filename (signature);
is_html = e_signature_get_is_html (signature);
if (is_html)
g_file_get_contents (filename, &contents, &length, &error);
else {
gchar *data;
data = e_read_signature_file (signature, FALSE, &error);
if (data != NULL)
contents = g_strdup_printf ("\n%s", data);
else
contents = NULL;
length = -1;
g_free (data);
}
if (error == NULL) {
gtkhtml_editor_set_html_mode (
GTKHTML_EDITOR (editor), is_html);
gtkhtml_editor_set_text_html (
GTKHTML_EDITOR (editor), contents, length);
g_free (contents);
} else {
g_warning ("%s", error->message);
g_error_free (error);
}
exit:
if (signature != NULL)
signature_name = e_signature_get_name (signature);
else
signature_name = _("Unnamed");
/* Set the entry text before we grab focus. */
g_free (editor->priv->original_name);
editor->priv->original_name = g_strdup (signature_name);
gtk_entry_set_text (GTK_ENTRY (editor->priv->entry), signature_name);
/* Set the focus appropriately. If this is a new signature, draw
* the user's attention to the signature name entry. Otherwise go
* straight to the editing area. */
if (signature == NULL)
gtk_widget_grab_focus (editor->priv->entry);
else {
GtkHTML *html;
html = gtkhtml_editor_get_html (GTKHTML_EDITOR (editor));
gtk_widget_grab_focus (GTK_WIDGET (html));
}
g_object_notify (G_OBJECT (editor), "signature");
}