[evolution-data-server] ESourceComboBox: Add e_source_combo_box_ref_active().



commit c6d06963380e52c6b76e3a2b8e45327709e555d4
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat Apr 21 16:27:49 2012 -0400

    ESourceComboBox: Add e_source_combo_box_ref_active().
    
    Replaces e_source_combo_box_get_active().
    
    Returns a new ESource reference that the caller must unreference.

 .../libedataserverui/libedataserverui-sections.txt |    2 +-
 libedataserverui/e-name-selector-dialog.c          |    4 +++-
 libedataserverui/e-source-combo-box.c              |   12 ++++++------
 libedataserverui/e-source-combo-box.h              |    6 ++----
 tests/libedataserverui/test-source-combo-box.c     |   11 +++++++++--
 5 files changed, 21 insertions(+), 14 deletions(-)
---
diff --git a/docs/reference/libedataserverui/libedataserverui-sections.txt b/docs/reference/libedataserverui/libedataserverui-sections.txt
index b743ca1..40af382 100644
--- a/docs/reference/libedataserverui/libedataserverui-sections.txt
+++ b/docs/reference/libedataserverui/libedataserverui-sections.txt
@@ -344,7 +344,7 @@ ESourceComboBox
 e_source_combo_box_new
 e_source_combo_box_get_source_list
 e_source_combo_box_set_source_list
-e_source_combo_box_get_active
+e_source_combo_box_ref_active
 e_source_combo_box_set_active
 <SUBSECTION Standard>
 E_SOURCE_COMBO_BOX
diff --git a/libedataserverui/e-name-selector-dialog.c b/libedataserverui/e-name-selector-dialog.c
index 428764a..f595d37 100644
--- a/libedataserverui/e-name-selector-dialog.c
+++ b/libedataserverui/e-name-selector-dialog.c
@@ -994,7 +994,7 @@ source_changed (ENameSelectorDialog *name_selector_dialog,
 	ESource *source;
 	gpointer parent;
 
-	source = e_source_combo_box_get_active (source_combo_box);
+	source = e_source_combo_box_ref_active (source_combo_box);
 
 	parent = gtk_widget_get_toplevel (GTK_WIDGET (name_selector_dialog));
 	parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
@@ -1013,6 +1013,8 @@ source_changed (ENameSelectorDialog *name_selector_dialog,
 		source, E_CLIENT_SOURCE_TYPE_CONTACTS, TRUE, cancellable,
 		e_client_utils_authenticate_handler, parent,
 		book_loaded_cb, g_object_ref (name_selector_dialog));
+
+	g_object_unref (source);
 }
 
 /* --------------- *
diff --git a/libedataserverui/e-source-combo-box.c b/libedataserverui/e-source-combo-box.c
index 4f15a2e..1717009 100644
--- a/libedataserverui/e-source-combo-box.c
+++ b/libedataserverui/e-source-combo-box.c
@@ -425,18 +425,21 @@ e_source_combo_box_set_source_list (ESourceComboBox *combo_box,
 }
 
 /**
- * e_source_combo_box_get_active:
+ * e_source_combo_box_ref_active:
  * @combo_box: an #ESourceComboBox
  *
  * Returns the #ESource corresponding to the currently active item,
  * or %NULL if there is no active item.
  *
+ * The returned #ESource is referenced for thread-safety and must be
+ * unreferenced with g_object_unref() when finished with it.
+ *
  * Returns: an #ESource or %NULL
  *
- * Since: 2.22
+ * Since: 3.6
  **/
 ESource *
-e_source_combo_box_get_active (ESourceComboBox *combo_box)
+e_source_combo_box_ref_active (ESourceComboBox *combo_box)
 {
 	GtkComboBox *gtk_combo_box;
 	GtkTreeIter iter;
@@ -453,9 +456,6 @@ e_source_combo_box_get_active (ESourceComboBox *combo_box)
 		gtk_combo_box_get_model (gtk_combo_box),
 		&iter, COLUMN_SOURCE, &source, -1);
 
-	if (source != NULL)
-		g_object_unref (source);
-
 	return source;
 }
 
diff --git a/libedataserverui/e-source-combo-box.h b/libedataserverui/e-source-combo-box.h
index 405b488..f5a9c81 100644
--- a/libedataserverui/e-source-combo-box.h
+++ b/libedataserverui/e-source-combo-box.h
@@ -67,10 +67,8 @@ ESourceList *	e_source_combo_box_get_source_list
 void		e_source_combo_box_set_source_list
 						(ESourceComboBox *combo_box,
 						 ESourceList *source_list);
-ESource *	e_source_combo_box_get_active
-						(ESourceComboBox *combo_box);
-void		e_source_combo_box_set_active
-						(ESourceComboBox *combo_box,
+ESource *	e_source_combo_box_ref_active	(ESourceComboBox *combo_box);
+void		e_source_combo_box_set_active	(ESourceComboBox *combo_box,
 						 ESource *source);
 
 G_END_DECLS
diff --git a/tests/libedataserverui/test-source-combo-box.c b/tests/libedataserverui/test-source-combo-box.c
index 348d001..873f1e2 100644
--- a/tests/libedataserverui/test-source-combo-box.c
+++ b/tests/libedataserverui/test-source-combo-box.c
@@ -27,8 +27,15 @@ source_changed_cb (ESourceComboBox *combo_box)
 {
 	ESource *source;
 
-	source = e_source_combo_box_get_active (combo_box);
-	g_print ("source selected: \"%s\"\n", e_source_get_display_name (source));
+	source = e_source_combo_box_ref_active (combo_box);
+	if (source != NULL) {
+		const gchar *display_name;
+		display_name = e_source_get_display_name (source);
+		g_print ("source selected: \"%s\"\n", display_name);
+		g_object_unref (source);
+	} else {
+		g_print ("source selected: (none)\n");
+	}
 }
 
 static gint



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]