83
84
text = gtk_entry_get_text (GTK_ENTRY (entry));
84
85
contacts_view_search (CONTACTS_VIEW (picker->priv->contacts_view), text);
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);
90
92
gtk_widget_hide (picker->priv->add_contact_button);
117
119
add_contact_cb (GtkButton *button, gpointer user_data)
119
GtkWidget *dialog, *table, *label, *name_entry, *email_entry;
120
122
const gchar *search_text;
121
123
U1ContactsPicker *picker = (U1ContactsPicker *) user_data;
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,
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);
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);
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);
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);
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);
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), "");