~ubuntu-branches/ubuntu/oneiric/ubuntuone-client/oneiric

« back to all changes in this revision

Viewing changes to nautilus/add-contact-dialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2010-06-08 17:31:18 UTC
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: james.westby@ubuntu.com-20100608173118-o8s897ll11rtne99
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

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) 2009 Canonical Services Ltd (www.canonical.com)
 
4
 *
 
5
 * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
 
6
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 */
 
21
 
 
22
#include <string.h>
 
23
#include <glib/gi18n.h>
 
24
#include "add-contact-dialog.h"
 
25
 
 
26
G_DEFINE_TYPE(AddContactDialog, add_contact_dialog, GTK_TYPE_DIALOG)
 
27
 
 
28
static void
 
29
add_contact_dialog_finalize (GObject *object)
 
30
{
 
31
        G_OBJECT_CLASS (add_contact_dialog_parent_class)->finalize (object);
 
32
}
 
33
 
 
34
static void
 
35
add_contact_dialog_class_init (AddContactDialogClass *klass)
 
36
{
 
37
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
38
 
 
39
        object_class->finalize = add_contact_dialog_finalize;
 
40
}
 
41
 
 
42
static void
 
43
entry_changed_cb (GtkEditable *entry, gpointer user_data)
 
44
{
 
45
        const gchar *text_name, *text_email;
 
46
        AddContactDialog *dialog = (AddContactDialog *) user_data;
 
47
 
 
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);
 
52
        else
 
53
                gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
 
54
}
 
55
 
 
56
static void
 
57
entry_activated_cb (GtkEntry *entry, gpointer user_data)
 
58
{
 
59
        const gchar *text_name, *text_email;
 
60
        AddContactDialog *dialog = (AddContactDialog *) user_data;
 
61
 
 
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);
 
66
}
 
67
 
 
68
static void
 
69
add_contact_dialog_init (AddContactDialog *dialog)
 
70
{
 
71
        GtkWidget *table, *label;
 
72
 
 
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);
 
78
 
 
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);
 
81
 
 
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);
 
86
 
 
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);
 
90
 
 
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);
 
96
 
 
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);
 
100
 
 
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);
 
106
}
 
107
 
 
108
GtkWidget *
 
109
add_contact_dialog_new (GtkWindow *parent, const gchar *initial_text)
 
110
{
 
111
        AddContactDialog *dialog;
 
112
 
 
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);
 
116
        else
 
117
                gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), initial_text);
 
118
 
 
119
        gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
 
120
 
 
121
        return dialog;
 
122
}
 
123
 
 
124
const gchar *
 
125
add_contact_dialog_get_name_text (AddContactDialog *dialog)
 
126
{
 
127
        return gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
 
128
}
 
129
 
 
130
const gchar *
 
131
add_contact_dialog_get_email_text (AddContactDialog *dialog)
 
132
{
 
133
        return gtk_entry_get_text (GTK_ENTRY (dialog->email_entry));
 
134
}