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

« back to all changes in this revision

Viewing changes to nautilus/u1-contacts-picker.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:
21
21
 
22
22
#include <glib/gi18n.h>
23
23
#include "u1-contacts-picker.h"
 
24
#include "add-contact-dialog.h"
24
25
#include "contacts-view.h"
25
26
 
26
27
struct _U1ContactsPickerPrivate {
83
84
        text = gtk_entry_get_text (GTK_ENTRY (entry));
84
85
        contacts_view_search (CONTACTS_VIEW (picker->priv->contacts_view), text);
85
86
 
86
 
        /* If no contacts offer the user to add it to the contacts database */
87
 
        if (contacts_view_get_matched_contacts_count (CONTACTS_VIEW (picker->priv->contacts_view)) == 0)
 
87
        /* If no contacts, offer the user to add it to the contacts database */
 
88
        if (contacts_view_get_matched_contacts_count (CONTACTS_VIEW (picker->priv->contacts_view)) == 0 &&
 
89
            g_strrstr (text, "@") != NULL)
88
90
                gtk_widget_show (picker->priv->add_contact_button);
89
91
        else
90
92
                gtk_widget_hide (picker->priv->add_contact_button);
116
118
static void
117
119
add_contact_cb (GtkButton *button, gpointer user_data)
118
120
{
119
 
        GtkWidget *dialog, *table, *label, *name_entry, *email_entry;
 
121
        GtkWidget *dialog;
120
122
        const gchar *search_text;
121
123
        U1ContactsPicker *picker = (U1ContactsPicker *) user_data;
122
124
 
123
 
        /* Build the dialog */
124
 
        dialog = gtk_dialog_new_with_buttons (_("Add contact"),
125
 
                                              GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (picker))),
126
 
                                              GTK_DIALOG_NO_SEPARATOR,
127
 
                                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
128
 
                                              GTK_STOCK_ADD, GTK_RESPONSE_OK,
129
 
                                              NULL);
130
 
        table = gtk_table_new (2, 2, FALSE);
131
 
        gtk_widget_show (table);
132
 
        gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
133
 
                            table, TRUE, TRUE, 3);
134
 
 
135
 
        label = gtk_label_new (_("Contact name"));
136
 
        gtk_widget_show (label);
137
 
        gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 3, 3);
138
 
        name_entry = gtk_entry_new ();
139
 
        gtk_widget_show (name_entry);
140
 
        gtk_table_attach (GTK_TABLE (table), name_entry, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 3, 3);
141
 
 
142
 
        label = gtk_label_new (_("Email address"));
143
 
        gtk_widget_show (label);
144
 
        gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 3, 3);
145
 
        email_entry = gtk_entry_new ();
146
 
        gtk_widget_show (email_entry);
147
 
        gtk_table_attach (GTK_TABLE (table), email_entry, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 3, 3);
148
 
 
 
125
        /* Create the dialog */
149
126
        search_text = gtk_entry_get_text (GTK_ENTRY (picker->priv->search_entry));
150
 
        if (g_strrstr (search_text, "@") != NULL)
151
 
                gtk_entry_set_text (GTK_ENTRY (email_entry), search_text);
152
 
        else
153
 
                gtk_entry_set_text (GTK_ENTRY (name_entry), search_text);
 
127
        dialog = add_contact_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (picker))), search_text);
154
128
 
155
129
        /* Run the dialog */
156
 
        gtk_widget_grab_focus (name_entry);
157
130
        if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
158
131
                contacts_view_add_contact (CONTACTS_VIEW (picker->priv->contacts_view),
159
 
                                           gtk_entry_get_text (GTK_ENTRY (name_entry)),
160
 
                                           gtk_entry_get_text (GTK_ENTRY (email_entry)));
 
132
                                           add_contact_dialog_get_name_text (dialog),
 
133
                                           add_contact_dialog_get_email_text (dialog));
161
134
                gtk_entry_set_text (GTK_ENTRY (picker->priv->search_entry), "");
162
135
        }
163
136