~ubuntu-branches/ubuntu/lucid/giggle/lucid

« back to all changes in this revision

Viewing changes to src/giggle-personal-details-window.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrea Corradi
  • Date: 2009-03-30 19:41:43 UTC
  • mfrom: (3.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090330194143-nyr9ze1xola1shm5
Tags: 0.4.91-1
* New upstream release (Closes:  #519014)
* Use Standards-Version 3.8.1
* Add new Build-Depends
* Update Homepage and watch file
* Update debian/copyright
* Remove patch
* Update path in debian/rules
* Remove defs option from LDFLAGS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
/*
3
 
 * Copyright (C) 2007 Imendio AB
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
19
 
 */
20
 
 
21
 
#include <config.h>
22
 
#include <glib/gi18n.h>
23
 
#include <gtk/gtk.h>
24
 
#include <glade/glade.h>
25
 
#include <string.h>
26
 
 
27
 
#include "giggle-personal-details-window.h"
28
 
#include "giggle-git.h"
29
 
#include "giggle-configuration.h"
30
 
 
31
 
typedef struct GigglePersonalDetailsWindowPriv GigglePersonalDetailsWindowPriv;
32
 
 
33
 
struct GigglePersonalDetailsWindowPriv {
34
 
        GtkWidget           *name_entry;
35
 
        GtkWidget           *email_entry;
36
 
 
37
 
        GiggleConfiguration *configuration;
38
 
};
39
 
 
40
 
static void personal_details_window_finalize          (GObject             *object);
41
 
static void personal_details_window_response          (GtkDialog           *dialog,
42
 
                                                       gint                 response);
43
 
static void personal_details_configuration_updated_cb (GiggleConfiguration *configuration,
44
 
                                                       gboolean             success,
45
 
                                                       gpointer             user_data);
46
 
                                              
47
 
 
48
 
G_DEFINE_TYPE (GigglePersonalDetailsWindow, giggle_personal_details_window, GTK_TYPE_DIALOG)
49
 
 
50
 
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIGGLE_TYPE_PERSONAL_DETAILS_WINDOW, GigglePersonalDetailsWindowPriv))
51
 
 
52
 
 
53
 
static void
54
 
giggle_personal_details_window_class_init (GigglePersonalDetailsWindowClass *class)
55
 
{
56
 
        GObjectClass *object_class = G_OBJECT_CLASS (class);
57
 
        GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (class);
58
 
 
59
 
        object_class->finalize = personal_details_window_finalize;
60
 
        dialog_class->response = personal_details_window_response;
61
 
 
62
 
        g_type_class_add_private (object_class,
63
 
                                  sizeof (GigglePersonalDetailsWindowPriv));
64
 
}
65
 
 
66
 
static void
67
 
giggle_personal_details_window_init (GigglePersonalDetailsWindow *window)
68
 
{
69
 
        GigglePersonalDetailsWindowPriv *priv;
70
 
        GladeXML                        *xml;
71
 
        GtkWidget                       *table;
72
 
 
73
 
        priv = GET_PRIV (window);
74
 
 
75
 
        xml = glade_xml_new (GLADEDIR "/main-window.glade",
76
 
                             "personal_details_table", NULL);
77
 
 
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");
81
 
 
82
 
        gtk_container_add (GTK_CONTAINER (GTK_DIALOG (window)->vbox), table);
83
 
 
84
 
        gtk_window_set_title (GTK_WINDOW (window), _("Personal Details"));
85
 
        gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
86
 
 
87
 
        gtk_dialog_add_button (GTK_DIALOG (window), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
88
 
        gtk_widget_set_sensitive (GTK_WIDGET (window), FALSE);
89
 
 
90
 
        priv->configuration = giggle_configuration_new ();
91
 
        giggle_configuration_update (priv->configuration,
92
 
                                     personal_details_configuration_updated_cb,
93
 
                                     window);
94
 
}
95
 
 
96
 
static void
97
 
personal_details_window_finalize (GObject *object)
98
 
{
99
 
        GigglePersonalDetailsWindowPriv *priv;
100
 
 
101
 
        priv = GET_PRIV (object);
102
 
 
103
 
        g_object_unref (priv->configuration);
104
 
 
105
 
        G_OBJECT_CLASS (giggle_personal_details_window_parent_class)->finalize (object);
106
 
}
107
 
 
108
 
static void
109
 
personal_details_configuration_changed_cb (GiggleConfiguration *configuration,
110
 
                                           gboolean             success,
111
 
                                           gpointer             user_data)
112
 
{
113
 
        GigglePersonalDetailsWindow *window;
114
 
        GtkWidget                   *dialog, *parent;
115
 
 
116
 
        window = GIGGLE_PERSONAL_DETAILS_WINDOW (user_data);
117
 
 
118
 
        if (success) {
119
 
                return;
120
 
        }
121
 
 
122
 
        g_object_get (window, "transient-for", &parent, NULL);
123
 
        dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
124
 
                                         GTK_DIALOG_MODAL,
125
 
                                         GTK_MESSAGE_ERROR,
126
 
                                         GTK_BUTTONS_CLOSE,
127
 
                                         _("There was an error "
128
 
                                           "setting the configuration"));
129
 
 
130
 
        gtk_dialog_run (GTK_DIALOG (dialog));
131
 
        gtk_widget_destroy (dialog);
132
 
        g_object_unref (parent);
133
 
}
134
 
 
135
 
static void
136
 
personal_details_window_response (GtkDialog *dialog,
137
 
                                  gint       response)
138
 
{
139
 
        GigglePersonalDetailsWindowPriv *priv;
140
 
 
141
 
        priv = GET_PRIV (dialog);
142
 
 
143
 
        giggle_configuration_set_field (priv->configuration,
144
 
                                        CONFIG_FIELD_NAME,
145
 
                                        gtk_entry_get_text (GTK_ENTRY (priv->name_entry)));
146
 
 
147
 
        giggle_configuration_set_field (priv->configuration,
148
 
                                        CONFIG_FIELD_EMAIL,
149
 
                                        gtk_entry_get_text (GTK_ENTRY (priv->email_entry)));
150
 
 
151
 
        giggle_configuration_commit (priv->configuration,
152
 
                                     personal_details_configuration_changed_cb,
153
 
                                     dialog);
154
 
}
155
 
 
156
 
static void
157
 
personal_details_configuration_updated_cb (GiggleConfiguration *configuration,
158
 
                                           gboolean             success,
159
 
                                           gpointer             user_data)
160
 
{
161
 
        GigglePersonalDetailsWindow     *window;
162
 
        GigglePersonalDetailsWindowPriv *priv;
163
 
        const gchar* value;
164
 
 
165
 
        window = GIGGLE_PERSONAL_DETAILS_WINDOW (user_data);
166
 
        priv = GET_PRIV (window);
167
 
 
168
 
        gtk_widget_set_sensitive (GTK_WIDGET (window), TRUE);
169
 
 
170
 
        if (!success) {
171
 
                GtkWidget *dialog, *parent;
172
 
 
173
 
                g_object_get (window, "transient-for", &parent, NULL);
174
 
                gtk_widget_hide (GTK_WIDGET (window));
175
 
 
176
 
                dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
177
 
                                                 GTK_DIALOG_MODAL,
178
 
                                                 GTK_MESSAGE_ERROR,
179
 
                                                 GTK_BUTTONS_CLOSE,
180
 
                                                 _("There was an error "
181
 
                                                   "getting the configuration"));
182
 
 
183
 
                gtk_dialog_run (GTK_DIALOG (dialog));
184
 
                gtk_widget_destroy (dialog);
185
 
                g_object_unref (parent);
186
 
                return;
187
 
        }
188
 
 
189
 
        value = giggle_configuration_get_field (configuration, CONFIG_FIELD_NAME);
190
 
        if (value) {
191
 
                gtk_entry_set_text (GTK_ENTRY (priv->name_entry), value);
192
 
        }
193
 
 
194
 
        value = giggle_configuration_get_field (configuration, CONFIG_FIELD_EMAIL);
195
 
        if (value) {
196
 
                gtk_entry_set_text (GTK_ENTRY (priv->email_entry), value);
197
 
        }
198
 
}
199
 
 
200
 
GtkWidget*
201
 
giggle_personal_details_window_new (void)
202
 
{
203
 
        return g_object_new (GIGGLE_TYPE_PERSONAL_DETAILS_WINDOW,
204
 
                             "has-separator", FALSE,
205
 
                             NULL);
206
 
}