[evolution-kolab/ek-wip-acl] EPlugin: added util function for ref'ing a button in a GtkDialog



commit 58cb486c14e3a7ddc3356ae68d788b9fbe2e3c99
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Tue Sep 25 18:37:54 2012 +0200

    EPlugin: added util function for ref'ing a button in a GtkDialog
    
    * function returns a reference to a button of the given name
      within a GtkDialog
    * a check whether the label name refers to a stock item
      can be performed

 src/eplugin/e-kolab-plugin-util.c |   49 +++++++++++++++++++++++++++++++++++++
 src/eplugin/e-kolab-plugin-util.h |    5 ++++
 2 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/src/eplugin/e-kolab-plugin-util.c b/src/eplugin/e-kolab-plugin-util.c
index 2d8a73f..c5bd30b 100644
--- a/src/eplugin/e-kolab-plugin-util.c
+++ b/src/eplugin/e-kolab-plugin-util.c
@@ -190,6 +190,55 @@ e_kolab_plugin_util_ui_selected_folder_widget (const gchar *foldername,
 	return GTK_WIDGET (grid);
 }
 
+GtkWidget*
+e_kolab_plugin_util_ui_dialog_ref_button (GtkDialog *dialog,
+                                          const gchar *button_label,
+                                          gboolean stock_check)
+{
+	GtkWidget *action_area = NULL;
+	GList *btn_lst = NULL;
+	GList *btn_lst_ptr = NULL;
+	GtkWidget *btn = NULL;
+	
+	g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
+	g_return_val_if_fail (button_label != NULL, NULL);
+
+	action_area = gtk_dialog_get_action_area (dialog);
+	g_return_val_if_fail (GTK_IS_BUTTON_BOX (action_area), NULL);
+
+	btn_lst = gtk_container_get_children (GTK_CONTAINER (action_area));
+
+	btn_lst_ptr = btn_lst;
+	while (btn_lst_ptr != NULL) {
+		GtkButton *btn_cand = NULL;
+		const gchar *label = NULL;
+		
+		if (! GTK_IS_BUTTON (btn_lst_ptr->data)) {
+			g_warning ("%s()[%u] GtkButtonBox contains non-GtkButton child, skipping",
+			           __func__, __LINE__);
+			continue;
+		}
+
+		btn_cand = GTK_BUTTON (btn_lst_ptr->data);
+
+		if (stock_check && (! gtk_button_get_use_stock (btn_cand)))
+			continue;
+
+		label = gtk_button_get_label (btn_cand);
+		if (g_strcmp0 (label, button_label) == 0) {
+			btn = g_object_ref (btn_cand);
+			break;
+		}
+
+		btn_lst_ptr = g_list_next (btn_lst_ptr);
+	}
+
+	if (btn_lst != NULL)
+		g_list_free (btn_lst);
+	
+	return btn;
+}
+
 gboolean
 e_kolab_plugin_util_ui_get_selected_source (EShellView *shell_view,
                                             ESource **selected_source)
diff --git a/src/eplugin/e-kolab-plugin-util.h b/src/eplugin/e-kolab-plugin-util.h
index 1d7b2cf..bcea0ac 100644
--- a/src/eplugin/e-kolab-plugin-util.h
+++ b/src/eplugin/e-kolab-plugin-util.h
@@ -48,6 +48,11 @@ GtkWidget*
 e_kolab_plugin_util_ui_selected_folder_widget (const gchar *foldername,
                                                const gchar *sourcename);
 
+GtkWidget*
+e_kolab_plugin_util_ui_dialog_ref_button (GtkDialog *dialog,
+                                          const gchar *button_label,
+                                          gboolean stock_check);
+
 gboolean
 e_kolab_plugin_util_ui_get_selected_source (EShellView *shell_view,
                                             ESource **selected_source);



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