soylent r85 - trunk/src
- From: treitter svn gnome org
- To: svn-commits-list gnome org
- Subject: soylent r85 - trunk/src
- Date: Wed, 20 Feb 2008 07:50:50 +0000 (GMT)
Author: treitter
Date: Wed Feb 20 07:50:50 2008
New Revision: 85
URL: http://svn.gnome.org/viewvc/soylent?rev=85&view=rev
Log:
fortify some functions in soylent-browser-person-view.c
Modified:
trunk/src/soylent-browser-person-view.c
trunk/src/soylent-browser-person-view.h
Modified: trunk/src/soylent-browser-person-view.c
==============================================================================
--- trunk/src/soylent-browser-person-view.c (original)
+++ trunk/src/soylent-browser-person-view.c Wed Feb 20 07:50:50 2008
@@ -40,10 +40,13 @@
(EBookView *book_view,
const GList *e_contacts,
cb_data_pre_person *pre_person_to_match);
+static gboolean soylent_browser_person_action_chat_menu_shell_cb
+ (GtkMenuShell *menu_email,
+ gpointer user_data);
static gboolean soylent_browser_person_action_chat_menu_item_cb
(GtkMenuItem *item,
gpointer user_data);
-static void soylent_browser_person_selected_chat_menu_update_cb
+static gboolean soylent_browser_person_selected_chat_menu_update_cb
(GtkMenuToolButton *btntb,
gpointer user_data);
static gboolean soylent_browser_person_action_email_menu_shell_cb
@@ -52,7 +55,7 @@
static gboolean soylent_browser_person_action_email_menu_item_cb
(GtkMenuItem *item,
gpointer user_data);
-static void soylent_browser_person_selected_email_menu_update_cb
+static gboolean soylent_browser_person_selected_email_menu_update_cb
(GtkMenuToolButton *btntb_email,
gpointer user_data);
static gboolean person_apply_edits_from_widgets_switch (gpointer key,
@@ -223,7 +226,9 @@
return retval;
}
-/* Prompt "Delete person?" when we select one or more people and hit Delete */
+/* Prompt "Delete person?" when we select one or more people and hit Delete
+ *
+ * Return TRUE for success, FALSE for any failure. */
gboolean
soylent_browser_person_action_delete_selected_cb (GtkButton *btn,
gpointer user_data)
@@ -261,46 +266,67 @@
return retval;
}
-/* Hide the "Confirm delete?" window when we click the "Cancel" button */
+/* Hide the "Confirm delete?" window when we click the "Cancel" button
+ *
+ * Return TRUE for success, FALSE for any failure. */
gboolean
soylent_browser_person_action_delete_selected_hide_dialog_cb
(GtkButton *btn,
gpointer user_data)
{
+ gboolean retval = FALSE;
SoylentBrowser *browser = NULL;
GladeXML *wtree = NULL;
- GtkWidget *dia_delete_person_confirm = NULL;
- browser = (SoylentBrowser *) user_data;
+ g_return_val_if_fail (user_data != NULL, retval);
+ /* FIXME: when SoylentBrowser is a GObject, check SOYLENT_IS_BROWSER */
+ browser = (SoylentBrowser*) user_data;
+
wtree = soylent_browser_get_widget_tree (browser);
+ if (wtree && GLADE_IS_XML (wtree))
+ {
+ GtkWidget *dia_delete_person = NULL;
- dia_delete_person_confirm = glade_xml_get_widget (wtree,
- "dia_delete_person_confirm");
- gtk_widget_hide (dia_delete_person_confirm);
+ dia_delete_person = glade_xml_get_widget (wtree,
+ "dia_delete_person_confirm");
+ if (dia_delete_person)
+ {
+ gtk_widget_hide (dia_delete_person);
+ retval = TRUE;
+ }
+ }
- return TRUE;
+ return retval;
}
-/* Handle clicks on the Edit button in the Browse view */
-int
+/* Handle clicks on the Edit button in the Browse view
+ *
+ * Return TRUE for success, FALSE for any failure. */
+gboolean
soylent_browser_person_action_edit_selected_cb (GtkButton *btn,
gpointer user_data)
{
- int retval = -1;
+ gboolean retval = FALSE;
SoylentBrowser *browser = NULL;
SoylentPerson *person = NULL;
- browser = (SoylentBrowser *) user_data;
+ g_return_val_if_fail (user_data != NULL, retval);
+ /* FIXME: when SoylentBrowser is a GObject, check SOYLENT_IS_BROWSER */
+ browser = (SoylentBrowser*) user_data;
+
+ /* FIXME: when SoylentPerson is a GObject, check SOYLENT_IS_PERSON */
person = soylent_browser_get_selected_person (browser);
if (person)
{
#ifdef HAVE_CONTACTS_APP
{
const gchar *e_uid = NULL;
+ EContact *e_contact = NULL;
- if (person->e_contact)
+ e_contact = soylent_person_get_e_contact (person);
+ if (e_contact && E_IS_CONTACT (e_contact))
{
- e_uid = e_contact_get_const (person->e_contact, E_CONTACT_UID);
+ e_uid = e_contact_get_const (e_contact, E_CONTACT_UID);
}
else
{
@@ -313,21 +339,27 @@
GError *error = NULL;
command_line = g_strdup_printf ("contacts --edit-uid=%s", e_uid);
+ if (command_line)
+ {
+ g_spawn_command_line_async (command_line, &error);
- g_spawn_command_line_async (command_line, &error);
+ if (error)
+ {
+ g_warning ("Failed to launch Contacts to edit this person: "
+ "%s", error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ retval = TRUE;
+ }
- if (error)
- {
- g_warning ("Failed to launch Contacts to edit this person: %s",
- error->message);
- g_clear_error (&error);
+ g_free (command_line);
}
else
{
- retval = 0;
+ g_critical ("failed to allocate memory");
}
-
- g_free (command_line);
}
else
{
@@ -336,16 +368,10 @@
}
#else
{
- gboolean set_mode_retval = FALSE;
-
soylent_browser_person_view_update (browser, person);
- set_mode_retval = soylent_browser_view_set_mode
- (browser,
- SB_PEOPLE_VIEW_MODE_EDIT);
-
- /* FIXME: ugly work-around until this function returns gboolean */
- retval = (set_mode_retval == TRUE) ? 0 : -1;
+ retval = soylent_browser_view_set_mode (browser,
+ SB_PEOPLE_VIEW_MODE_EDIT);
}
#endif /* HAVE_CONTACTS_APP */
}
@@ -357,7 +383,6 @@
return retval;
}
-/* FIXME: collapse these three following functions if possible */
/* Handle clicks on the button part of the Email action MenuToolButton
*
* Return TRUE for success, FALSE for any failure */
@@ -367,16 +392,21 @@
gpointer user_data)
{
gboolean retval = FALSE;
+ GtkMenuShell *menu_shell = NULL;
- retval = soylent_browser_person_action_email_menu_shell_cb
- (GTK_MENU_SHELL (gtk_menu_tool_button_get_menu (btntb)),
- user_data);
+ menu_shell = GTK_MENU_SHELL (gtk_menu_tool_button_get_menu (btntb));
+ if (menu_shell)
+ {
+ retval = soylent_browser_person_action_email_menu_shell_cb (menu_shell,
+ user_data);
+ }
return retval;
}
-/* FIXME: use this to replace the few functions before it */
-/* FIXME: should this just be in soylent-browser.c ? */
+/* Open a chat session with the given person
+ *
+ * Return TRUE for success, FALSE for any failure */
gboolean
soylent_browser_person_action_communicate_email (SoylentBrowser *browser,
SoylentPerson *person)
@@ -393,10 +423,11 @@
wtree = soylent_browser_get_widget_tree (browser);
if (wtree && GLADE_IS_XML (wtree))
{
- btntb = GTK_MENU_TOOL_BUTTON (glade_xml_get_widget (wtree, "btntb_email"));
+ btntb = GTK_MENU_TOOL_BUTTON (glade_xml_get_widget (wtree,
+ "btntb_email"));
if (btntb && GTK_IS_MENU_TOOL_BUTTON (btntb))
{
- retval = soylent_browser_person_action_chat_menu_tool_button_cb
+ retval = soylent_browser_person_action_email_menu_tool_button_cb
(btntb,
browser);
}
@@ -413,7 +444,6 @@
return retval;
}
-/* FIXME: collapse these three following functions if possible */
/* Handle clicks on the button part of the Chat action MenuToolButton
*
* Return TRUE for success, FALSE for any failure */
@@ -423,45 +453,21 @@
gpointer user_data)
{
gboolean retval = FALSE;
+ GtkMenuShell *menu_shell = NULL;
- retval = soylent_browser_person_action_chat_menu_shell_cb
- (GTK_MENU_SHELL (gtk_menu_tool_button_get_menu (btntb)),
- user_data);
-
- return retval;
-}
-
-/* Handle activation of an item in the Chat action MenuToolButton
- *
- * Return TRUE for success, FALSE for any failure */
-gboolean
-soylent_browser_person_action_chat_menu_shell_cb (GtkMenuShell *menu_chat,
- gpointer user_data)
-{
- gboolean retval = FALSE;
- GtkMenu *menu = NULL;
- GtkMenuItem *selected_item = NULL;
-
- g_return_val_if_fail (menu_chat, retval);
- g_return_val_if_fail (GTK_IS_MENU_SHELL (menu_chat), retval);
-
- menu = GTK_MENU (menu_chat);
- selected_item = GTK_MENU_ITEM (gtk_menu_get_active (menu));
- if (selected_item)
- {
- retval = soylent_browser_person_action_chat_menu_item_cb (selected_item,
- user_data);
- }
- else
+ menu_shell = GTK_MENU_SHELL (gtk_menu_tool_button_get_menu (btntb));
+ if (menu_shell)
{
- g_warning ("failed to get the selected Chat menu item");
+ retval = soylent_browser_person_action_chat_menu_shell_cb (menu_shell,
+ user_data);
}
return retval;
}
-/* FIXME: use this to replace the few functions before it */
-/* FIXME: should this just be in soylent-browser.c ? */
+/* Open a chat session with the given person
+ *
+ * Return TRUE for success, FALSE for any failure */
gboolean
soylent_browser_person_action_communicate_chat (SoylentBrowser *browser,
SoylentPerson *person)
@@ -498,11 +504,15 @@
return retval;
}
-/* Handle a change of who is selected */
-void
+/* Handle a change of who is selected
+ *
+ * Return TRUE for success, FALSE for any failure. */
+gboolean
soylent_browser_person_selection_changed_cb (GtkIconView *iv,
gpointer user_data)
{
+ gboolean retval = FALSE;
+ gboolean email_retval = FALSE;
SoylentBrowser *browser = NULL;
GladeXML *wtree = NULL;
GtkWidget *btn_delete_people = NULL;
@@ -510,43 +520,59 @@
GtkMenuToolButton *btntb_email = NULL;
GtkMenuToolButton *btntb_chat = NULL;
GList *selected_people = NULL;
- gboolean selection_empty = TRUE;
- browser = (SoylentBrowser *) user_data;
+ browser = (SoylentBrowser*) user_data;
+ g_return_val_if_fail (browser != NULL, retval);
+ /* FIXME: uncomment once SoylentBrowser is a GObject:
+ g_return_val_if_fail (SOYLENT_IS_BROWSER (browser), NULL);
+ */
+
wtree = soylent_browser_get_widget_tree (browser);
+ g_return_val_if_fail (wtree != NULL, retval);
+ g_return_val_if_fail (GLADE_IS_XML (wtree), retval);
+
btn_delete_people = glade_xml_get_widget (wtree, "btn_delete_people");
+ g_return_val_if_fail (btn_delete_people != NULL, retval);
+
btn_edit_person = glade_xml_get_widget (wtree, "btn_edit_person");
+ g_return_val_if_fail (btn_edit_person != NULL, retval);
+
btntb_email = GTK_MENU_TOOL_BUTTON (glade_xml_get_widget (wtree,
"btntb_email"));
+ g_return_val_if_fail (btntb_email != NULL, retval);
+
btntb_chat = GTK_MENU_TOOL_BUTTON (glade_xml_get_widget (wtree,
"btntb_chat"));
+ g_return_val_if_fail (btntb_chat != NULL, retval);
selected_people = gtk_icon_view_get_selected_items (iv);
-
if (selected_people && selected_people->data)
{
- selection_empty = FALSE;
+ gtk_widget_set_sensitive (btn_delete_people, TRUE);
+ gtk_widget_set_sensitive (btn_edit_person, TRUE);
}
-
- if (selection_empty)
+ else
{
gtk_widget_set_sensitive (btn_delete_people, FALSE);
gtk_widget_set_sensitive (btn_edit_person, FALSE);
}
- else
+
+ email_retval = soylent_browser_person_selected_email_menu_update_cb
+ (btntb_email,
+ browser);
+ if (email_retval)
{
- gtk_widget_set_sensitive (btn_delete_people, TRUE);
- gtk_widget_set_sensitive (btn_edit_person, TRUE);
+ retval = soylent_browser_person_selected_chat_menu_update_cb (btntb_chat,
+ browser);
}
- soylent_browser_person_selected_email_menu_update_cb (btntb_email, browser);
- soylent_browser_person_selected_chat_menu_update_cb (btntb_chat, browser);
-
if (selected_people)
{
g_list_foreach (selected_people, (GFunc) gtk_tree_path_free, NULL);
g_list_free (selected_people);
}
+
+ return retval;
}
/* Handle a person's (simple, GtkEntry-based) detail's edit */
@@ -1141,7 +1167,7 @@
/* Handle activation of an item in the Email action MenuToolButton
*
* Return TRUE for success, FALSE for any failure */
-gboolean
+static gboolean
soylent_browser_person_action_email_menu_shell_cb (GtkMenuShell *menu_chat,
gpointer user_data)
{
@@ -1235,6 +1261,35 @@
return retval;
}
+/* Handle activation of an item in the Chat action MenuToolButton
+ *
+ * Return TRUE for success, FALSE for any failure */
+static gboolean
+soylent_browser_person_action_chat_menu_shell_cb (GtkMenuShell *menu_chat,
+ gpointer user_data)
+{
+ gboolean retval = FALSE;
+ GtkMenu *menu = NULL;
+ GtkMenuItem *selected_item = NULL;
+
+ g_return_val_if_fail (menu_chat, retval);
+ g_return_val_if_fail (GTK_IS_MENU_SHELL (menu_chat), retval);
+
+ menu = GTK_MENU (menu_chat);
+ selected_item = GTK_MENU_ITEM (gtk_menu_get_active (menu));
+ if (selected_item)
+ {
+ retval = soylent_browser_person_action_chat_menu_item_cb (selected_item,
+ user_data);
+ }
+ else
+ {
+ g_warning ("failed to get the selected Chat menu item");
+ }
+
+ return retval;
+}
+
/* FIXME: this function has way too many levels of logic; split it up */
/* Perform the actual action for an Chat action MenuToolButton item
*
@@ -1365,12 +1420,15 @@
return retval;
}
-/* Fill the Email action MenuToolButton's menu based on the selected person */
-static void
+/* Fill the Email action MenuToolButton's menu based on the selected person
+ *
+ * Return TRUE for success, FALSE for any failure. */
+static gboolean
soylent_browser_person_selected_email_menu_update_cb
(GtkMenuToolButton *btntb_email,
gpointer user_data)
{
+ gboolean retval = FALSE;
SoylentBrowser *browser = NULL;
EContact *e_contact = NULL;
const GList *email_addrs = NULL;
@@ -1397,17 +1455,20 @@
e_contact = e_contacts->data;
if (!e_contact || !E_CONTACT (e_contact))
{
- return;
+ /* FIXME: don't short out here; set retval appropriately */
+ return TRUE;
}
}
else
{
- return;
+ /* FIXME: don't short out here; set retval appropriately */
+ return TRUE;
}
}
else
{
- return;
+ /* FIXME: don't short out here; set retval appropriately */
+ return TRUE;
}
email_addrs = e_contact_get (e_contact, E_CONTACT_EMAIL);
@@ -1426,14 +1487,22 @@
gtk_widget_show (GTK_WIDGET (item));
gtk_widget_set_sensitive (GTK_WIDGET (btntb_email), TRUE);
}
+
+ /* FIXME: actually set this above, as appropriate */
+ retval = TRUE;
+
+ return retval;
}
-/* Fill the Chat action MenuToolButton's menu based on the selected person */
-static void
+/* Fill the Chat action MenuToolButton's menu based on the selected person
+ *
+ * Return TRUE for success, FALSE for any failure. */
+static gboolean
soylent_browser_person_selected_chat_menu_update_cb
(GtkMenuToolButton *btntb_chat,
gpointer user_data)
{
+ gboolean retval = FALSE;
SoylentBrowser *browser = NULL;
const GList *people = NULL;
const GList *live_contacts = NULL;
@@ -1441,10 +1510,7 @@
EmpathyContact *live_contact_cur = NULL;
SoylentPerson *person = NULL;
- if (!btntb_chat)
- {
- return;
- }
+ g_return_val_if_fail (btntb_chat != NULL, retval);
menu_chat = GTK_MENU (gtk_menu_tool_button_get_menu (btntb_chat));
@@ -1464,18 +1530,21 @@
if (!person)
{
- return;
+ /* FIXME: set retval as appropriate instead */
+ return TRUE;
}
}
else
{
- return;
+ /* FIXME: set retval as appropriate instead */
+ return TRUE;
}
}
if (!menu_chat)
{
- return;
+ /* FIXME: set retval as appropriate instead */
+ return TRUE;
}
/* Clear out the menutoolbutton's pull-down menu and make it insensitive */
@@ -1485,7 +1554,8 @@
if (!person)
{
- return;
+ /* FIXME: set retval as appropriate instead */
+ return TRUE;
}
live_contacts = soylent_person_get_live_contacts (person);
@@ -1508,6 +1578,10 @@
gtk_widget_show (GTK_WIDGET (item));
gtk_widget_set_sensitive (GTK_WIDGET (btntb_chat), TRUE);
}
+
+ retval = TRUE;
+
+ return retval;
}
/* After we create this new Person, automatically select them and open an edit
Modified: trunk/src/soylent-browser-person-view.h
==============================================================================
--- trunk/src/soylent-browser-person-view.h (original)
+++ trunk/src/soylent-browser-person-view.h Wed Feb 20 07:50:50 2008
@@ -52,13 +52,10 @@
gboolean soylent_browser_person_action_chat_menu_tool_button_cb
(GtkMenuToolButton *btntb,
gpointer user_data);
-gboolean soylent_browser_person_action_chat_menu_shell_cb
- (GtkMenuShell *menu_email,
- gpointer user_data);
gboolean soylent_browser_person_action_email_menu_tool_button_cb
(GtkMenuToolButton *btntb,
gpointer user_data);
-void soylent_browser_person_selection_changed_cb (GtkIconView *iv,
+gboolean soylent_browser_person_selection_changed_cb (GtkIconView *iv,
gpointer user_data);
gboolean soylent_browser_person_action_communicate_email
(SoylentBrowser *browser,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]