1
/* This file is part of GQ
4
* Sven Herzberg <herzi@gnome-de.org>
6
* Copyright (C) 2006 Sven Herzberg <herzi@gnome-de.org>
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.
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.
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
24
#include "gq-login-dialog.h"
27
#include <gtk/gtkcheckbutton.h>
28
#include <gtk/gtkentry.h>
29
#include <gtk/gtklabel.h>
30
#include <gtk/gtksizegroup.h>
32
#include "configfile.h" // token_bindtype
33
#include "gq-keyring.h"
38
#include <glib/gi18n.h>
40
struct GqLoginDialogPrivate {
43
GtkLabel* label_hostname;
44
GtkLabel* label_bind_dn;
45
GtkEntry* entry_bind_pw;
46
GtkLabel* label_bind_type;
47
GtkCheckButton* checkbutton_save_password;
49
#define P(i) (G_TYPE_INSTANCE_GET_PRIVATE((i), GQ_TYPE_LOGIN_DIALOG, struct GqLoginDialogPrivate))
52
gq_login_dialog_new(GqServer* server)
54
return g_object_new(GQ_TYPE_LOGIN_DIALOG, "server", server, NULL);
58
gq_login_dialog_get_password(GqLoginDialog const* self)
62
g_return_val_if_fail(GQ_IS_LOGIN_DIALOG(self), NULL);
63
retval = gtk_entry_get_text(P(self)->entry_bind_pw);
65
return retval && *retval ? retval : NULL;
69
gq_login_dialog_get_save_password(GqLoginDialog const* self)
71
g_return_val_if_fail(GQ_IS_LOGIN_DIALOG(self), FALSE);
73
return gq_keyring_can_save() &&
74
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(P(self)->checkbutton_save_password));
78
login_dialog_update_bind_dn(GqLoginDialog* self)
80
gtk_label_set_text(P(self)->label_bind_dn,
81
gq_server_get_bind_dn(P(self)->server));
85
login_dialog_update_bind_type(GqLoginDialog* self)
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);
97
login_dialog_update_server_name(GqLoginDialog* self)
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))))
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));
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));
115
gtk_label_set_text(P(self)->label_hostname, string);
120
login_dialog_set_server(GqLoginDialog* self,
123
g_return_if_fail(GQ_IS_LOGIN_DIALOG(self));
124
g_return_if_fail(!server || GQ_IS_SERVER(server));
126
if(server == P(self)->server) {
130
if(P(self)->server) {
131
g_signal_handlers_disconnect_by_func(P(self)->server,
132
login_dialog_update_bind_dn,
134
g_signal_handlers_disconnect_by_func(P(self)->server,
135
login_dialog_update_bind_type,
137
g_signal_handlers_disconnect_by_func(P(self)->server,
138
login_dialog_update_server_name,
140
g_object_unref(P(self)->server);
141
P(self)->server = NULL;
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);
155
login_dialog_update_bind_dn(self);
156
login_dialog_update_bind_type(self);
157
login_dialog_update_server_name(self);
160
g_object_notify(G_OBJECT(self), "server");
164
G_DEFINE_TYPE(GqLoginDialog, gq_login_dialog, HERZI_TYPE_GLADE_DIALOG);
172
gq_login_dialog_init(GqLoginDialog* self)
176
login_dialog_connect_widgets(HerziGladeDialog* dialog,
179
GtkSizeGroup* group_left = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
180
GtkSizeGroup* group_right = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
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"));
191
if(!gq_keyring_can_save()) {
192
gtk_widget_set_sensitive(glade_xml_get_widget(xml, "checkbutton_save_password"),
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"));
205
login_dialog_dispose(GObject* object)
207
if(P(object)->server) {
208
login_dialog_set_server(GQ_LOGIN_DIALOG(object), NULL);
211
G_OBJECT_CLASS(gq_login_dialog_parent_class)->dispose(object);
215
login_dialog_get_property(GObject * object,
222
g_value_set_object(value, P(object)->server);
225
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
231
login_dialog_set_property(GObject * object,
238
login_dialog_set_server(GQ_LOGIN_DIALOG(object), g_value_get_object(value));
241
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
247
gq_login_dialog_class_init(GqLoginDialogClass* self_class)
249
GObjectClass * object_class = G_OBJECT_CLASS(self_class);
250
HerziGladeDialogClass* glade_dialog_class = HERZI_GLADE_DIALOG_CLASS(self_class);
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,
258
g_param_spec_object("server",
260
_("The server to be connected to"),
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";
269
/* GqLoginDialogClass */
270
g_type_class_add_private(self_class, sizeof(struct GqLoginDialogPrivate));