1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
* Copyright (C) 2009 Canonical Services Ltd (www.canonical.com)
5
* Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of version 2 of the GNU Lesser General Public
9
* License as published by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the
18
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA.
23
#include <glib/gi18n.h>
24
#include "add-contact-dialog.h"
26
G_DEFINE_TYPE(AddContactDialog, add_contact_dialog, GTK_TYPE_DIALOG)
29
add_contact_dialog_finalize (GObject *object)
31
G_OBJECT_CLASS (add_contact_dialog_parent_class)->finalize (object);
35
add_contact_dialog_class_init (AddContactDialogClass *klass)
37
GObjectClass *object_class = G_OBJECT_CLASS (klass);
39
object_class->finalize = add_contact_dialog_finalize;
43
entry_changed_cb (GtkEditable *entry, gpointer user_data)
45
const gchar *text_name, *text_email;
46
AddContactDialog *dialog = (AddContactDialog *) user_data;
48
text_name = gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
49
text_email = gtk_entry_get_text (GTK_ENTRY (dialog->email_entry));
50
if (strlen (text_name) > 0 && strlen (text_email) > 0)
51
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
53
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
57
entry_activated_cb (GtkEntry *entry, gpointer user_data)
59
const gchar *text_name, *text_email;
60
AddContactDialog *dialog = (AddContactDialog *) user_data;
62
text_name = gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
63
text_email = gtk_entry_get_text (GTK_ENTRY (dialog->email_entry));
64
if (strlen (text_name) > 0 && strlen (text_email) > 0)
65
gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
69
add_contact_dialog_init (AddContactDialog *dialog)
71
GtkWidget *table, *label;
73
/* Build the dialog */
74
gtk_window_set_title (GTK_WINDOW (dialog), _("Add contact"));
75
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
76
gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
77
gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_ADD, GTK_RESPONSE_OK);
79
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
80
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
82
table = gtk_table_new (2, 2, FALSE);
83
gtk_widget_show (table);
84
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
85
table, TRUE, TRUE, 3);
87
label = gtk_label_new (_("Contact name"));
88
gtk_widget_show (label);
89
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 3, 3);
91
dialog->name_entry = gtk_entry_new ();
92
g_signal_connect (G_OBJECT (dialog->name_entry), "changed", G_CALLBACK (entry_changed_cb), dialog);
93
g_signal_connect (G_OBJECT (dialog->name_entry), "activate", G_CALLBACK (entry_activated_cb), dialog);
94
gtk_widget_show (dialog->name_entry);
95
gtk_table_attach (GTK_TABLE (table), dialog->name_entry, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 3, 3);
97
label = gtk_label_new (_("Email address"));
98
gtk_widget_show (label);
99
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 3, 3);
101
dialog->email_entry = gtk_entry_new ();
102
g_signal_connect (G_OBJECT (dialog->email_entry), "changed", G_CALLBACK (entry_changed_cb), dialog);
103
g_signal_connect (G_OBJECT (dialog->email_entry), "activate", G_CALLBACK (entry_activated_cb), dialog);
104
gtk_widget_show (dialog->email_entry);
105
gtk_table_attach (GTK_TABLE (table), dialog->email_entry, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 3, 3);
109
add_contact_dialog_new (GtkWindow *parent, const gchar *initial_text)
111
AddContactDialog *dialog;
113
dialog = g_object_new (TYPE_ADD_CONTACT_DIALOG, NULL);
114
if (g_strrstr (initial_text, "@") != NULL)
115
gtk_entry_set_text (GTK_ENTRY (dialog->email_entry), initial_text);
117
gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), initial_text);
119
gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
125
add_contact_dialog_get_name_text (AddContactDialog *dialog)
127
return gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
131
add_contact_dialog_get_email_text (AddContactDialog *dialog)
133
return gtk_entry_get_text (GTK_ENTRY (dialog->email_entry));