Merge lp:~rodrigo-moya/ubuntuone-client/add-contacts-fixes into lp:ubuntuone-client

Proposed by Rodrigo Moya
Status: Merged
Approved by: Rodrigo Moya
Approved revision: 531
Merged at revision: 532
Proposed branch: lp:~rodrigo-moya/ubuntuone-client/add-contacts-fixes
Merge into: lp:ubuntuone-client
Diff against target: 306 lines (+198/-37)
5 files modified
nautilus/Makefile.am (+4/-0)
nautilus/add-contact-dialog.c (+134/-0)
nautilus/add-contact-dialog.h (+50/-0)
nautilus/u1-contacts-picker.c (+9/-36)
po/POTFILES.in (+1/-1)
To merge this branch: bzr merge lp:~rodrigo-moya/ubuntuone-client/add-contacts-fixes
Reviewer Review Type Date Requested Status
dobey (community) Needs Fixing
Rick McBride (community) Approve
Roman Yepishev (community) Approve
Review via email: mp+26600@code.launchpad.net

Commit message

Several fixes in adding contacts logic

Description of the change

Several fixes in adding contacts logic

To post a comment you must log in.
Revision history for this message
Roman Yepishev (rye) wrote :

Tested & it works the way it should according to bug reports.

review: Approve
Revision history for this message
Rick McBride (rmcbride) wrote :

+1

review: Approve
Revision history for this message
dobey (dobey) wrote :

The following files contain translations and are currently not in use. Please
consider adding these to the POTFILES.in file, located in the po/ directory.

nautilus/add-contact-dialog.c

review: Needs Fixing
531. By Rodrigo Moya

Added missing translatable file

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nautilus/Makefile.am'
2--- nautilus/Makefile.am 2010-02-08 09:44:21 +0000
3+++ nautilus/Makefile.am 2010-06-03 22:25:40 +0000
4@@ -19,6 +19,8 @@
5 ubuntuone-nautilus.c: ubuntuone-marshallers.h
6
7 libnautilus_ubuntuone_la_SOURCES = \
8+ add-contact-dialog.c \
9+ add-contact-dialog.h \
10 contacts-view.c \
11 contacts-view.h \
12 u1-contacts-picker.c \
13@@ -36,6 +38,8 @@
14 $(NAUTILUS_CFLAGS)
15 test_contacts_picker_SOURCES = \
16 test-contacts-picker.c \
17+ add-contact-dialog.c \
18+ add-contact-dialog.h \
19 contacts-view.c \
20 contacts-view.h \
21 u1-contacts-picker.c \
22
23=== added file 'nautilus/add-contact-dialog.c'
24--- nautilus/add-contact-dialog.c 1970-01-01 00:00:00 +0000
25+++ nautilus/add-contact-dialog.c 2010-06-03 22:25:40 +0000
26@@ -0,0 +1,134 @@
27+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
28+/*
29+ * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com)
30+ *
31+ * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
32+ *
33+ * This library is free software; you can redistribute it and/or
34+ * modify it under the terms of version 2 of the GNU Lesser General Public
35+ * License as published by the Free Software Foundation.
36+ *
37+ * This program is distributed in the hope that it will be useful,
38+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
39+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40+ * General Public License for more details.
41+ *
42+ * You should have received a copy of the GNU Lesser General Public
43+ * License along with this library; if not, write to the
44+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
45+ * Boston, MA 02110-1301, USA.
46+ */
47+
48+#include <string.h>
49+#include <glib/gi18n.h>
50+#include "add-contact-dialog.h"
51+
52+G_DEFINE_TYPE(AddContactDialog, add_contact_dialog, GTK_TYPE_DIALOG)
53+
54+static void
55+add_contact_dialog_finalize (GObject *object)
56+{
57+ G_OBJECT_CLASS (add_contact_dialog_parent_class)->finalize (object);
58+}
59+
60+static void
61+add_contact_dialog_class_init (AddContactDialogClass *klass)
62+{
63+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
64+
65+ object_class->finalize = add_contact_dialog_finalize;
66+}
67+
68+static void
69+entry_changed_cb (GtkEditable *entry, gpointer user_data)
70+{
71+ const gchar *text_name, *text_email;
72+ AddContactDialog *dialog = (AddContactDialog *) user_data;
73+
74+ text_name = gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
75+ text_email = gtk_entry_get_text (GTK_ENTRY (dialog->email_entry));
76+ if (strlen (text_name) > 0 && strlen (text_email) > 0)
77+ gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE);
78+ else
79+ gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
80+}
81+
82+static void
83+entry_activated_cb (GtkEntry *entry, gpointer user_data)
84+{
85+ const gchar *text_name, *text_email;
86+ AddContactDialog *dialog = (AddContactDialog *) user_data;
87+
88+ text_name = gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
89+ text_email = gtk_entry_get_text (GTK_ENTRY (dialog->email_entry));
90+ if (strlen (text_name) > 0 && strlen (text_email) > 0)
91+ gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
92+}
93+
94+static void
95+add_contact_dialog_init (AddContactDialog *dialog)
96+{
97+ GtkWidget *table, *label;
98+
99+ /* Build the dialog */
100+ gtk_window_set_title (GTK_WINDOW (dialog), _("Add contact"));
101+ gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
102+ gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
103+ gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_ADD, GTK_RESPONSE_OK);
104+
105+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
106+ gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
107+
108+ table = gtk_table_new (2, 2, FALSE);
109+ gtk_widget_show (table);
110+ gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
111+ table, TRUE, TRUE, 3);
112+
113+ label = gtk_label_new (_("Contact name"));
114+ gtk_widget_show (label);
115+ gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 3, 3);
116+
117+ dialog->name_entry = gtk_entry_new ();
118+ g_signal_connect (G_OBJECT (dialog->name_entry), "changed", G_CALLBACK (entry_changed_cb), dialog);
119+ g_signal_connect (G_OBJECT (dialog->name_entry), "activate", G_CALLBACK (entry_activated_cb), dialog);
120+ gtk_widget_show (dialog->name_entry);
121+ gtk_table_attach (GTK_TABLE (table), dialog->name_entry, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 3, 3);
122+
123+ label = gtk_label_new (_("Email address"));
124+ gtk_widget_show (label);
125+ gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 3, 3);
126+
127+ dialog->email_entry = gtk_entry_new ();
128+ g_signal_connect (G_OBJECT (dialog->email_entry), "changed", G_CALLBACK (entry_changed_cb), dialog);
129+ g_signal_connect (G_OBJECT (dialog->email_entry), "activate", G_CALLBACK (entry_activated_cb), dialog);
130+ gtk_widget_show (dialog->email_entry);
131+ gtk_table_attach (GTK_TABLE (table), dialog->email_entry, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 3, 3);
132+}
133+
134+GtkWidget *
135+add_contact_dialog_new (GtkWindow *parent, const gchar *initial_text)
136+{
137+ AddContactDialog *dialog;
138+
139+ dialog = g_object_new (TYPE_ADD_CONTACT_DIALOG, NULL);
140+ if (g_strrstr (initial_text, "@") != NULL)
141+ gtk_entry_set_text (GTK_ENTRY (dialog->email_entry), initial_text);
142+ else
143+ gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), initial_text);
144+
145+ gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
146+
147+ return dialog;
148+}
149+
150+const gchar *
151+add_contact_dialog_get_name_text (AddContactDialog *dialog)
152+{
153+ return gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
154+}
155+
156+const gchar *
157+add_contact_dialog_get_email_text (AddContactDialog *dialog)
158+{
159+ return gtk_entry_get_text (GTK_ENTRY (dialog->email_entry));
160+}
161
162=== added file 'nautilus/add-contact-dialog.h'
163--- nautilus/add-contact-dialog.h 1970-01-01 00:00:00 +0000
164+++ nautilus/add-contact-dialog.h 2010-06-03 22:25:40 +0000
165@@ -0,0 +1,50 @@
166+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
167+/*
168+ * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com)
169+ *
170+ * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
171+ *
172+ * This library is free software; you can redistribute it and/or
173+ * modify it under the terms of version 2 of the GNU Lesser General Public
174+ * License as published by the Free Software Foundation.
175+ *
176+ * This program is distributed in the hope that it will be useful,
177+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
178+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
179+ * General Public License for more details.
180+ *
181+ * You should have received a copy of the GNU Lesser General Public
182+ * License along with this library; if not, write to the
183+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
184+ * Boston, MA 02110-1301, USA.
185+ */
186+
187+#ifndef __ADD_CONTACT_DIALOG_H__
188+#define __ADD_CONTACT_DIALOG_H__
189+
190+#include <gtk/gtk.h>
191+
192+#define TYPE_ADD_CONTACT_DIALOG (add_contact_dialog_get_type ())
193+#define ADD_CONTACT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ADD_CONTACT_DIALOG, AddContactDialog))
194+#define IS_ADD_CONTACT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ADD_CONTACT_DIALOG))
195+#define ADD_CONTACT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ADD_CONTACT_DIALOG, AddContactDialogClass))
196+#define IS_ADD_CONTACT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ADD_CONTACT_DIALOG))
197+#define ADD_CONTACT_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ADD_CONTACT_DIALOG, AddContactDialogClass))
198+
199+typedef struct {
200+ GtkDialog parent;
201+
202+ GtkWidget *name_entry;
203+ GtkWidget *email_entry;
204+} AddContactDialog;
205+
206+typedef struct {
207+ GtkDialogClass parent_class;
208+} AddContactDialogClass;
209+
210+GType add_contact_dialog_get_type (void);
211+GtkWidget *add_contact_dialog_new (GtkWindow *parent, const gchar *initial_text);
212+const gchar *add_contact_dialog_get_name_text (AddContactDialog *dialog);
213+const gchar *add_contact_dialog_get_email_text (AddContactDialog *dialog);
214+
215+#endif
216
217=== modified file 'nautilus/u1-contacts-picker.c'
218--- nautilus/u1-contacts-picker.c 2010-04-16 11:52:46 +0000
219+++ nautilus/u1-contacts-picker.c 2010-06-03 22:25:40 +0000
220@@ -21,6 +21,7 @@
221
222 #include <glib/gi18n.h>
223 #include "u1-contacts-picker.h"
224+#include "add-contact-dialog.h"
225 #include "contacts-view.h"
226
227 struct _U1ContactsPickerPrivate {
228@@ -83,8 +84,9 @@
229 text = gtk_entry_get_text (GTK_ENTRY (entry));
230 contacts_view_search (CONTACTS_VIEW (picker->priv->contacts_view), text);
231
232- /* If no contacts offer the user to add it to the contacts database */
233- if (contacts_view_get_matched_contacts_count (CONTACTS_VIEW (picker->priv->contacts_view)) == 0)
234+ /* If no contacts, offer the user to add it to the contacts database */
235+ if (contacts_view_get_matched_contacts_count (CONTACTS_VIEW (picker->priv->contacts_view)) == 0 &&
236+ g_strrstr (text, "@") != NULL)
237 gtk_widget_show (picker->priv->add_contact_button);
238 else
239 gtk_widget_hide (picker->priv->add_contact_button);
240@@ -116,48 +118,19 @@
241 static void
242 add_contact_cb (GtkButton *button, gpointer user_data)
243 {
244- GtkWidget *dialog, *table, *label, *name_entry, *email_entry;
245+ GtkWidget *dialog;
246 const gchar *search_text;
247 U1ContactsPicker *picker = (U1ContactsPicker *) user_data;
248
249- /* Build the dialog */
250- dialog = gtk_dialog_new_with_buttons (_("Add contact"),
251- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (picker))),
252- GTK_DIALOG_NO_SEPARATOR,
253- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
254- GTK_STOCK_ADD, GTK_RESPONSE_OK,
255- NULL);
256- table = gtk_table_new (2, 2, FALSE);
257- gtk_widget_show (table);
258- gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
259- table, TRUE, TRUE, 3);
260-
261- label = gtk_label_new (_("Contact name"));
262- gtk_widget_show (label);
263- gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 3, 3);
264- name_entry = gtk_entry_new ();
265- gtk_widget_show (name_entry);
266- gtk_table_attach (GTK_TABLE (table), name_entry, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 3, 3);
267-
268- label = gtk_label_new (_("Email address"));
269- gtk_widget_show (label);
270- gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 3, 3);
271- email_entry = gtk_entry_new ();
272- gtk_widget_show (email_entry);
273- gtk_table_attach (GTK_TABLE (table), email_entry, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 3, 3);
274-
275+ /* Create the dialog */
276 search_text = gtk_entry_get_text (GTK_ENTRY (picker->priv->search_entry));
277- if (g_strrstr (search_text, "@") != NULL)
278- gtk_entry_set_text (GTK_ENTRY (email_entry), search_text);
279- else
280- gtk_entry_set_text (GTK_ENTRY (name_entry), search_text);
281+ dialog = add_contact_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (picker))), search_text);
282
283 /* Run the dialog */
284- gtk_widget_grab_focus (name_entry);
285 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
286 contacts_view_add_contact (CONTACTS_VIEW (picker->priv->contacts_view),
287- gtk_entry_get_text (GTK_ENTRY (name_entry)),
288- gtk_entry_get_text (GTK_ENTRY (email_entry)));
289+ add_contact_dialog_get_name_text (dialog),
290+ add_contact_dialog_get_email_text (dialog));
291 gtk_entry_set_text (GTK_ENTRY (picker->priv->search_entry), "");
292 }
293
294
295=== modified file 'po/POTFILES.in'
296--- po/POTFILES.in 2010-02-09 22:03:08 +0000
297+++ po/POTFILES.in 2010-06-03 22:25:40 +0000
298@@ -3,7 +3,7 @@
299 data/emblem-ubuntuone-unsynchronized.icon.in
300 data/emblem-ubuntuone-uploading.icon.in
301 data/ubuntuone-preferences.desktop.in
302+nautilus/add-contact-dialog.c
303 nautilus/ubuntuone-nautilus.c
304 nautilus/contacts-view.c
305 nautilus/u1-contacts-picker.c
306-

Subscribers

People subscribed via source and target branches