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.
27
#include <glib/gi18n-lib.h>
28
#include "add-contact-dialog.h"
30
G_DEFINE_TYPE(AddContactDialog, add_contact_dialog, GTK_TYPE_DIALOG)
33
add_contact_dialog_finalize (GObject *object)
35
G_OBJECT_CLASS (add_contact_dialog_parent_class)->finalize (object);
39
add_contact_dialog_class_init (AddContactDialogClass *klass)
41
GObjectClass *object_class = G_OBJECT_CLASS (klass);
43
object_class->finalize = add_contact_dialog_finalize;
47
entry_changed_cb (GtkEditable *entry, gpointer user_data)
49
const gchar *text_name, *text_email;
50
AddContactDialog *dialog = (AddContactDialog *) user_data;
52
text_name = gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
53
text_email = gtk_entry_get_text (GTK_ENTRY (dialog->email_entry));
54
if (strlen (text_name) > 0 && strlen (text_email) > 0)
55
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
57
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
61
entry_activated_cb (GtkEntry *entry, gpointer user_data)
63
const gchar *text_name, *text_email;
64
AddContactDialog *dialog = (AddContactDialog *) user_data;
66
text_name = gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
67
text_email = gtk_entry_get_text (GTK_ENTRY (dialog->email_entry));
68
if (strlen (text_name) > 0 && strlen (text_email) > 0)
69
gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
73
add_contact_dialog_init (AddContactDialog *dialog)
75
GtkWidget *table, *label;
77
/* Build the dialog */
78
gtk_window_set_title (GTK_WINDOW (dialog), _("Add contact"));
79
gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
80
gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_ADD, GTK_RESPONSE_OK);
82
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
83
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
85
table = gtk_table_new (2, 2, FALSE);
86
gtk_widget_show (table);
87
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
88
table, TRUE, TRUE, 3);
90
label = gtk_label_new (_("Contact name"));
91
gtk_widget_show (label);
92
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 3, 3);
94
dialog->name_entry = gtk_entry_new ();
95
g_signal_connect (G_OBJECT (dialog->name_entry), "changed", G_CALLBACK (entry_changed_cb), dialog);
96
g_signal_connect (G_OBJECT (dialog->name_entry), "activate", G_CALLBACK (entry_activated_cb), dialog);
97
gtk_widget_show (dialog->name_entry);
98
gtk_table_attach (GTK_TABLE (table), dialog->name_entry, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 3, 3);
100
label = gtk_label_new (_("Email address"));
101
gtk_widget_show (label);
102
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 3, 3);
104
dialog->email_entry = gtk_entry_new ();
105
g_signal_connect (G_OBJECT (dialog->email_entry), "changed", G_CALLBACK (entry_changed_cb), dialog);
106
g_signal_connect (G_OBJECT (dialog->email_entry), "activate", G_CALLBACK (entry_activated_cb), dialog);
107
gtk_widget_show (dialog->email_entry);
108
gtk_table_attach (GTK_TABLE (table), dialog->email_entry, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 3, 3);
112
add_contact_dialog_new (GtkWindow *parent, const gchar *initial_text)
114
AddContactDialog *dialog;
116
dialog = g_object_new (TYPE_ADD_CONTACT_DIALOG, NULL);
117
if (g_strrstr (initial_text, "@") != NULL)
118
gtk_entry_set_text (GTK_ENTRY (dialog->email_entry), initial_text);
120
gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), initial_text);
122
gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
124
return GTK_WIDGET (dialog);
128
add_contact_dialog_get_name_text (AddContactDialog *dialog)
130
return gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
134
add_contact_dialog_get_email_text (AddContactDialog *dialog)
136
return gtk_entry_get_text (GTK_ENTRY (dialog->email_entry));