1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
* Copyright (C) 2007 Imendio AB
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License as
7
* published by the Free Software Foundation; either version 2 of the
8
* License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* General Public License for more details.
15
* You should have received a copy of the GNU General Public
16
* License along with this program; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
22
#include <glib/gi18n.h>
24
#include <glade/glade.h>
27
#include "giggle-personal-details-window.h"
28
#include "giggle-git.h"
29
#include "giggle-configuration.h"
31
typedef struct GigglePersonalDetailsWindowPriv GigglePersonalDetailsWindowPriv;
33
struct GigglePersonalDetailsWindowPriv {
34
GtkWidget *name_entry;
35
GtkWidget *email_entry;
37
GiggleConfiguration *configuration;
40
static void personal_details_window_finalize (GObject *object);
41
static void personal_details_window_response (GtkDialog *dialog,
43
static void personal_details_configuration_updated_cb (GiggleConfiguration *configuration,
48
G_DEFINE_TYPE (GigglePersonalDetailsWindow, giggle_personal_details_window, GTK_TYPE_DIALOG)
50
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIGGLE_TYPE_PERSONAL_DETAILS_WINDOW, GigglePersonalDetailsWindowPriv))
54
giggle_personal_details_window_class_init (GigglePersonalDetailsWindowClass *class)
56
GObjectClass *object_class = G_OBJECT_CLASS (class);
57
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (class);
59
object_class->finalize = personal_details_window_finalize;
60
dialog_class->response = personal_details_window_response;
62
g_type_class_add_private (object_class,
63
sizeof (GigglePersonalDetailsWindowPriv));
67
giggle_personal_details_window_init (GigglePersonalDetailsWindow *window)
69
GigglePersonalDetailsWindowPriv *priv;
73
priv = GET_PRIV (window);
75
xml = glade_xml_new (GLADEDIR "/main-window.glade",
76
"personal_details_table", NULL);
78
table = glade_xml_get_widget (xml, "personal_details_table");
79
priv->name_entry = glade_xml_get_widget (xml, "name_entry");
80
priv->email_entry = glade_xml_get_widget (xml, "email_entry");
82
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (window)->vbox), table);
84
gtk_window_set_title (GTK_WINDOW (window), _("Personal Details"));
85
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
87
gtk_dialog_add_button (GTK_DIALOG (window), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
88
gtk_widget_set_sensitive (GTK_WIDGET (window), FALSE);
90
priv->configuration = giggle_configuration_new ();
91
giggle_configuration_update (priv->configuration,
92
personal_details_configuration_updated_cb,
97
personal_details_window_finalize (GObject *object)
99
GigglePersonalDetailsWindowPriv *priv;
101
priv = GET_PRIV (object);
103
g_object_unref (priv->configuration);
105
G_OBJECT_CLASS (giggle_personal_details_window_parent_class)->finalize (object);
109
personal_details_configuration_changed_cb (GiggleConfiguration *configuration,
113
GigglePersonalDetailsWindow *window;
114
GtkWidget *dialog, *parent;
116
window = GIGGLE_PERSONAL_DETAILS_WINDOW (user_data);
122
g_object_get (window, "transient-for", &parent, NULL);
123
dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
127
_("There was an error "
128
"setting the configuration"));
130
gtk_dialog_run (GTK_DIALOG (dialog));
131
gtk_widget_destroy (dialog);
132
g_object_unref (parent);
136
personal_details_window_response (GtkDialog *dialog,
139
GigglePersonalDetailsWindowPriv *priv;
141
priv = GET_PRIV (dialog);
143
giggle_configuration_set_field (priv->configuration,
145
gtk_entry_get_text (GTK_ENTRY (priv->name_entry)));
147
giggle_configuration_set_field (priv->configuration,
149
gtk_entry_get_text (GTK_ENTRY (priv->email_entry)));
151
giggle_configuration_commit (priv->configuration,
152
personal_details_configuration_changed_cb,
157
personal_details_configuration_updated_cb (GiggleConfiguration *configuration,
161
GigglePersonalDetailsWindow *window;
162
GigglePersonalDetailsWindowPriv *priv;
165
window = GIGGLE_PERSONAL_DETAILS_WINDOW (user_data);
166
priv = GET_PRIV (window);
168
gtk_widget_set_sensitive (GTK_WIDGET (window), TRUE);
171
GtkWidget *dialog, *parent;
173
g_object_get (window, "transient-for", &parent, NULL);
174
gtk_widget_hide (GTK_WIDGET (window));
176
dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
180
_("There was an error "
181
"getting the configuration"));
183
gtk_dialog_run (GTK_DIALOG (dialog));
184
gtk_widget_destroy (dialog);
185
g_object_unref (parent);
189
value = giggle_configuration_get_field (configuration, CONFIG_FIELD_NAME);
191
gtk_entry_set_text (GTK_ENTRY (priv->name_entry), value);
194
value = giggle_configuration_get_field (configuration, CONFIG_FIELD_EMAIL);
196
gtk_entry_set_text (GTK_ENTRY (priv->email_entry), value);
201
giggle_personal_details_window_new (void)
203
return g_object_new (GIGGLE_TYPE_PERSONAL_DETAILS_WINDOW,
204
"has-separator", FALSE,