~ubuntu-branches/ubuntu/trusty/gq/trusty

« back to all changes in this revision

Viewing changes to src/gq-login-dialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2009-10-25 23:34:56 UTC
  • mfrom: (1.1.4 upstream) (3.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091025233456-i794n3yg2cff930j
Tags: 1.3.4-1
* QA upload.
  + Set maintainer to Debian QA Group <packages@qa.debian.org>.
* New upstream release. (Closes: #534705).
  + Does not segfault on amd64. (Closes: #444312).
  + Remove all existing patches and change patch system to quilt.
  + Replace dpatch build-dep with quilt.
* 01_desktop_file.diff - Remove encoding and bogus categories 
  from desktop file.
* Copy in config.{sub,guess} on configure, rm them on clean.
  + Add build-dep on autotools-dev.
* Make clean not ignore errors.
* Add copyright holders and version path to GPL (GPL-2).
* Update watch file to use SF redirector. (Closes: #449749).
* Bump debhelper build-dep and compat to 5.
* Bump Standards Version to 3.8.3.
  + Menu policy transition.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of GQ
 
2
 *
 
3
 * AUTHORS
 
4
 *     Sven Herzberg  <herzi@gnome-de.org>
 
5
 *
 
6
 * Copyright (C) 2006  Sven Herzberg <herzi@gnome-de.org>
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public License as
 
10
 * published by the Free Software Foundation; either version 2.1 of the
 
11
 * License, or (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU Lesser General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Lesser General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
21
 * USA
 
22
 */
 
23
 
 
24
#include "gq-login-dialog.h"
 
25
 
 
26
#include <string.h>
 
27
#include <gtk/gtkcheckbutton.h>
 
28
#include <gtk/gtkentry.h>
 
29
#include <gtk/gtklabel.h>
 
30
#include <gtk/gtksizegroup.h>
 
31
 
 
32
#include "configfile.h" // token_bindtype
 
33
#include "gq-keyring.h"
 
34
 
 
35
#ifdef HAVE_CONFIG_H
 
36
# include <config.h>
 
37
#endif
 
38
#include <glib/gi18n.h>
 
39
 
 
40
struct GqLoginDialogPrivate {
 
41
        GqServer* server;
 
42
 
 
43
        GtkLabel* label_hostname;
 
44
        GtkLabel* label_bind_dn;
 
45
        GtkEntry* entry_bind_pw;
 
46
        GtkLabel* label_bind_type;
 
47
        GtkCheckButton* checkbutton_save_password;
 
48
};
 
49
#define P(i) (G_TYPE_INSTANCE_GET_PRIVATE((i), GQ_TYPE_LOGIN_DIALOG, struct GqLoginDialogPrivate))
 
50
 
 
51
GtkWidget*
 
52
gq_login_dialog_new(GqServer* server)
 
53
{
 
54
        return g_object_new(GQ_TYPE_LOGIN_DIALOG, "server", server, NULL);
 
55
}
 
56
 
 
57
gchar const*
 
58
gq_login_dialog_get_password(GqLoginDialog const* self)
 
59
{
 
60
        gchar const* retval;
 
61
 
 
62
        g_return_val_if_fail(GQ_IS_LOGIN_DIALOG(self), NULL);
 
63
        retval = gtk_entry_get_text(P(self)->entry_bind_pw);
 
64
 
 
65
        return retval && *retval ? retval : NULL;
 
66
}
 
67
 
 
68
gboolean
 
69
gq_login_dialog_get_save_password(GqLoginDialog const* self)
 
70
{
 
71
        g_return_val_if_fail(GQ_IS_LOGIN_DIALOG(self), FALSE);
 
72
 
 
73
        return gq_keyring_can_save() &&
 
74
               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(P(self)->checkbutton_save_password));
 
75
}
 
76
 
 
77
static void
 
78
login_dialog_update_bind_dn(GqLoginDialog* self)
 
79
{
 
80
        gtk_label_set_text(P(self)->label_bind_dn,
 
81
                           gq_server_get_bind_dn(P(self)->server));
 
82
}
 
83
 
 
84
static void
 
85
login_dialog_update_bind_type(GqLoginDialog* self)
 
86
{
 
87
        // TRANSLATORS: "(Simple,Kerberos,SASL) Authentication"
 
88
        gchar* string = g_strdup_printf(_("%s Authentication"),
 
89
                                        token_bindtype[gq_server_get_bind_type(P(self)->server)].keyword);
 
90
#warning "FIXME: get this translatable as a whole text"
 
91
        gtk_label_set_text(P(self)->label_bind_type, string);
 
92
        g_free(string);
 
93
        string = NULL;
 
94
}
 
95
 
 
96
static void
 
97
login_dialog_update_server_name(GqLoginDialog* self)
 
98
{
 
99
        gchar* string;
 
100
        if(gq_server_get_name(P(self)->server) && gq_server_get_host(P(self)->server) &&
 
101
           (!strcmp(gq_server_get_name(P(self)->server), gq_server_get_host(P(self)->server))))
 
102
        {
 
103
                // Server Name and Hostname are equal, do not print twice
 
104
                // TRANSLATORS: "hostname:port"
 
105
                string = g_strdup_printf(_("%s:%d"),
 
106
                gq_server_get_name(P(self)->server),
 
107
                gq_server_get_port(P(self)->server));
 
108
        } else {
 
109
                // TRANSLATORS: "servername (hostname:port)"
 
110
                string = g_strdup_printf(_("%s (%s:%d)"),
 
111
                gq_server_get_name(P(self)->server),
 
112
                gq_server_get_host(P(self)->server),
 
113
                gq_server_get_port(P(self)->server));
 
114
        }
 
115
        gtk_label_set_text(P(self)->label_hostname, string);
 
116
        g_free(string);
 
117
}
 
118
 
 
119
static void
 
120
login_dialog_set_server(GqLoginDialog* self,
 
121
                        GqServer     * server)
 
122
{
 
123
        g_return_if_fail(GQ_IS_LOGIN_DIALOG(self));
 
124
        g_return_if_fail(!server || GQ_IS_SERVER(server));
 
125
 
 
126
        if(server == P(self)->server) {
 
127
                return;
 
128
        }
 
129
 
 
130
        if(P(self)->server) {
 
131
                g_signal_handlers_disconnect_by_func(P(self)->server,
 
132
                                                     login_dialog_update_bind_dn,
 
133
                                                     self);
 
134
                g_signal_handlers_disconnect_by_func(P(self)->server,
 
135
                                                     login_dialog_update_bind_type,
 
136
                                                     self);
 
137
                g_signal_handlers_disconnect_by_func(P(self)->server,
 
138
                                                     login_dialog_update_server_name,
 
139
                                                     self);
 
140
                g_object_unref(P(self)->server);
 
141
                P(self)->server = NULL;
 
142
        }
 
143
 
 
144
        if(server) {
 
145
                P(self)->server = g_object_ref(server);
 
146
                g_signal_connect_swapped(P(self)->server, "notify::bind-dn",
 
147
                                         G_CALLBACK(login_dialog_update_bind_dn), self);
 
148
                g_signal_connect_swapped(P(self)->server, "notify::bind-type",
 
149
                                         G_CALLBACK(login_dialog_update_bind_type), self);
 
150
                g_signal_connect_swapped(P(self)->server, "notify::name",
 
151
                                         G_CALLBACK(login_dialog_update_server_name), self);
 
152
                g_signal_connect_swapped(P(self)->server, "notify::host",
 
153
                                         G_CALLBACK(login_dialog_update_server_name), self);
 
154
 
 
155
                login_dialog_update_bind_dn(self);
 
156
                login_dialog_update_bind_type(self);
 
157
                login_dialog_update_server_name(self);
 
158
        }
 
159
 
 
160
        g_object_notify(G_OBJECT(self), "server");
 
161
}
 
162
 
 
163
/* GType */
 
164
G_DEFINE_TYPE(GqLoginDialog, gq_login_dialog, HERZI_TYPE_GLADE_DIALOG);
 
165
 
 
166
enum {
 
167
        PROP_0,
 
168
        PROP_SERVER
 
169
};
 
170
 
 
171
static void
 
172
gq_login_dialog_init(GqLoginDialog* self)
 
173
{}
 
174
 
 
175
static void
 
176
login_dialog_connect_widgets(HerziGladeDialog* dialog,
 
177
                             GladeXML        * xml)
 
178
{
 
179
        GtkSizeGroup* group_left  = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
 
180
        GtkSizeGroup* group_right = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
 
181
 
 
182
        gtk_size_group_add_widget(group_left, glade_xml_get_widget(xml, "label_hostname"));
 
183
        gtk_size_group_add_widget(group_left, glade_xml_get_widget(xml, "label_bind_dn"));
 
184
        gtk_size_group_add_widget(group_left, glade_xml_get_widget(xml, "label_bind_mode"));
 
185
        gtk_size_group_add_widget(group_left, glade_xml_get_widget(xml, "label_password"));
 
186
        gtk_size_group_add_widget(group_right, glade_xml_get_widget(xml, "input_hostname"));
 
187
        gtk_size_group_add_widget(group_right, glade_xml_get_widget(xml, "input_bind_dn"));
 
188
        gtk_size_group_add_widget(group_right, glade_xml_get_widget(xml, "input_bind_mode"));
 
189
        gtk_size_group_add_widget(group_right, glade_xml_get_widget(xml, "input_password"));
 
190
 
 
191
        if(!gq_keyring_can_save()) {
 
192
                gtk_widget_set_sensitive(glade_xml_get_widget(xml, "checkbutton_save_password"),
 
193
                                         FALSE);
 
194
        }
 
195
 
 
196
        P(dialog)->label_bind_dn   = GTK_LABEL(glade_xml_get_widget(xml, "input_bind_dn"));
 
197
        P(dialog)->entry_bind_pw   = GTK_ENTRY(glade_xml_get_widget(xml, "input_password"));
 
198
        P(dialog)->label_bind_type = GTK_LABEL(glade_xml_get_widget(xml, "input_bind_mode"));
 
199
        P(dialog)->label_hostname  = GTK_LABEL(glade_xml_get_widget(xml, "input_hostname"));
 
200
        P(dialog)->checkbutton_save_password =
 
201
                                GTK_CHECK_BUTTON(glade_xml_get_widget(xml, "checkbutton_save_password"));
 
202
}
 
203
 
 
204
static void
 
205
login_dialog_dispose(GObject* object)
 
206
{
 
207
        if(P(object)->server) {
 
208
                login_dialog_set_server(GQ_LOGIN_DIALOG(object), NULL);
 
209
        }
 
210
 
 
211
        G_OBJECT_CLASS(gq_login_dialog_parent_class)->dispose(object);
 
212
}
 
213
 
 
214
static void
 
215
login_dialog_get_property(GObject   * object,
 
216
                          guint       prop_id,
 
217
                          GValue    * value,
 
218
                          GParamSpec* pspec)
 
219
{
 
220
        switch(prop_id) {
 
221
        case PROP_SERVER:
 
222
                g_value_set_object(value, P(object)->server);
 
223
                break;
 
224
        default:
 
225
                G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 
226
                break;
 
227
        }
 
228
}
 
229
 
 
230
static void
 
231
login_dialog_set_property(GObject     * object,
 
232
                          guint         prop_id,
 
233
                          GValue const* value,
 
234
                          GParamSpec  * pspec)
 
235
{
 
236
        switch(prop_id) {
 
237
        case PROP_SERVER:
 
238
                login_dialog_set_server(GQ_LOGIN_DIALOG(object), g_value_get_object(value));
 
239
                break;
 
240
        default:
 
241
                G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 
242
                break;
 
243
        }
 
244
}
 
245
 
 
246
static void
 
247
gq_login_dialog_class_init(GqLoginDialogClass* self_class)
 
248
{
 
249
        GObjectClass         * object_class = G_OBJECT_CLASS(self_class);
 
250
        HerziGladeDialogClass* glade_dialog_class = HERZI_GLADE_DIALOG_CLASS(self_class);
 
251
 
 
252
        /* GObjectClass */
 
253
        object_class->dispose      = login_dialog_dispose;
 
254
        object_class->get_property = login_dialog_get_property;
 
255
        object_class->set_property = login_dialog_set_property;
 
256
        g_object_class_install_property(object_class,
 
257
                                        PROP_SERVER,
 
258
                                        g_param_spec_object("server",
 
259
                                                            _("Server"),
 
260
                                                            _("The server to be connected to"),
 
261
                                                            GQ_TYPE_SERVER,
 
262
                                                            G_PARAM_READWRITE));
 
263
 
 
264
        /* HerziGladeDialogClass */
 
265
        glade_dialog_class->connect_widgets = login_dialog_connect_widgets;
 
266
        glade_dialog_class->filename        = PACKAGE_PREFIX "/share/gq/gq.glade";
 
267
        glade_dialog_class->root_widget     = "password_dialog";
 
268
 
 
269
        /* GqLoginDialogClass */
 
270
        g_type_class_add_private(self_class, sizeof(struct GqLoginDialogPrivate));
 
271
}
 
272