~ubuntu-branches/ubuntu/precise/ubuntuone-client/precise-201112142106

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-08-09 12:47:56 UTC
  • mfrom: (1.1.53 upstream)
  • Revision ID: james.westby@ubuntu.com-20110809124756-7nzilp3oix0a1yl9
Tags: 1.7.1-0ubuntu1
* New upstream release.
* debian/*:
  - Removed obsolete pycompat file
  - Removed ubuntuone-client-gnome deps and binary packaging, as it was
    moved out to separate project upstream.
  - Updated copyright to remove obsolete file reference
* debian/patches:
  - Removed patches which have been included upstream.

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
 
#ifdef HAVE_CONFIG_H
24
 
#include <config.h>
25
 
#endif
26
 
 
27
 
#include <glib/gi18n-lib.h>
28
 
#include "add-contact-dialog.h"
29
 
 
30
 
G_DEFINE_TYPE(AddContactDialog, add_contact_dialog, GTK_TYPE_DIALOG)
31
 
 
32
 
static void
33
 
add_contact_dialog_finalize (GObject *object)
34
 
{
35
 
        G_OBJECT_CLASS (add_contact_dialog_parent_class)->finalize (object);
36
 
}
37
 
 
38
 
static void
39
 
add_contact_dialog_class_init (AddContactDialogClass *klass)
40
 
{
41
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
42
 
 
43
 
        object_class->finalize = add_contact_dialog_finalize;
44
 
}
45
 
 
46
 
static void
47
 
entry_changed_cb (GtkEditable *entry, gpointer user_data)
48
 
{
49
 
        const gchar *text_name, *text_email;
50
 
        AddContactDialog *dialog = (AddContactDialog *) user_data;
51
 
 
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);
56
 
        else
57
 
                gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
58
 
}
59
 
 
60
 
static void
61
 
entry_activated_cb (GtkEntry *entry, gpointer user_data)
62
 
{
63
 
        const gchar *text_name, *text_email;
64
 
        AddContactDialog *dialog = (AddContactDialog *) user_data;
65
 
 
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);
70
 
}
71
 
 
72
 
static void
73
 
add_contact_dialog_init (AddContactDialog *dialog)
74
 
{
75
 
        GtkWidget *table, *label;
76
 
 
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);
81
 
 
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);
84
 
 
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);
89
 
 
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);
93
 
 
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);
99
 
 
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);
103
 
 
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);
109
 
}
110
 
 
111
 
GtkWidget *
112
 
add_contact_dialog_new (GtkWindow *parent, const gchar *initial_text)
113
 
{
114
 
        AddContactDialog *dialog;
115
 
 
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);
119
 
        else
120
 
                gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), initial_text);
121
 
 
122
 
        gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
123
 
 
124
 
        return GTK_WIDGET (dialog);
125
 
}
126
 
 
127
 
const gchar *
128
 
add_contact_dialog_get_name_text (AddContactDialog *dialog)
129
 
{
130
 
        return gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
131
 
}
132
 
 
133
 
const gchar *
134
 
add_contact_dialog_get_email_text (AddContactDialog *dialog)
135
 
{
136
 
        return gtk_entry_get_text (GTK_ENTRY (dialog->email_entry));
137
 
}