ESourceComboBox: Add e_source_combo_box_ref_active().
authorMatthew Barnes <mbarnes@redhat.com>
Sat, 21 Apr 2012 20:27:49 +0000 (16:27 -0400)
committerMatthew Barnes <mbarnes@redhat.com>
Sat, 21 Apr 2012 20:27:49 +0000 (16:27 -0400)
Replaces e_source_combo_box_get_active().

Returns a new ESource reference that the caller must unreference.

docs/reference/libedataserverui/libedataserverui-sections.txt
libedataserverui/e-name-selector-dialog.c
libedataserverui/e-source-combo-box.c
libedataserverui/e-source-combo-box.h
tests/libedataserverui/test-source-combo-box.c

index b743ca1..40af382 100644 (file)
@@ -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
index 428764a..f595d37 100644 (file)
@@ -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);
 }
 
 /* --------------- *
index 4f15a2e..1717009 100644 (file)
@@ -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;
 }
 
index 405b488..f5a9c81 100644 (file)
@@ -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
index 348d001..873f1e2 100644 (file)
@@ -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