[evolution-kolab] EPlugin: implemented ACL entry removal, cleanup



commit ee5044e4dcf5cb7f223f92b925cba23ad384320b
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Mon Oct 15 14:45:42 2012 +0200

    EPlugin: implemented ACL entry removal, cleanup
    
    * implemented the "Remove" action in the ACL
      editor tab of the "Kolab Folder Properties..."
      dialog
    * prevent edit sub-dialog from opening if we do
      not have an ACL entry selected in the treeview

 src/eplugin/e-kolab-folder-permissions.c |  124 ++++++++++++++++++++++++------
 1 files changed, 100 insertions(+), 24 deletions(-)
---
diff --git a/src/eplugin/e-kolab-folder-permissions.c b/src/eplugin/e-kolab-folder-permissions.c
index b61b9c5..71d6db4 100644
--- a/src/eplugin/e-kolab-folder-permissions.c
+++ b/src/eplugin/e-kolab-folder-permissions.c
@@ -141,6 +141,45 @@ kolab_folder_permissions_ui_get_active_perm (KolabFolderPermUIData *uidata,
 }
 
 static gboolean
+kolab_folder_permissions_ui_treeview_get_selected (KolabFolderPermUIData *uidata,
+                                                   gchar **access_id,
+                                                   gchar **rights)
+{
+	GtkTreeView *treeview = NULL;
+	GtkTreeSelection *treesel = NULL;
+	GtkTreeModel *treemodel = NULL;
+	GtkTreeIter treeiter;
+	gboolean have_sel = FALSE;
+
+	g_return_val_if_fail (uidata != NULL, FALSE);
+	g_return_val_if_fail (uidata->widgets != NULL, FALSE);
+	g_return_val_if_fail (GTK_IS_TREE_VIEW (uidata->widgets->treeview), FALSE);
+	g_return_val_if_fail (access_id != NULL && *access_id == NULL, FALSE);
+	g_return_val_if_fail (rights != NULL && *rights == NULL, FALSE);
+
+	treeview = GTK_TREE_VIEW (uidata->widgets->treeview);
+	treesel = gtk_tree_view_get_selection (treeview);
+	g_return_val_if_fail (GTK_IS_TREE_SELECTION (treesel), FALSE);
+
+	have_sel = gtk_tree_selection_get_selected (treesel,
+	                                            &treemodel,
+	                                            &treeiter);
+	if (! have_sel)
+		return FALSE;
+
+	g_return_val_if_fail (GTK_IS_TREE_MODEL (treemodel), FALSE);
+
+	gtk_tree_model_get (treemodel, &treeiter,
+	                    0, access_id,
+	                    1, rights,
+	                    -1);
+	g_return_val_if_fail (*access_id != NULL, FALSE);
+	/* rights may be NULL */
+
+	return TRUE;
+}
+
+static gboolean
 kolab_folder_permissions_ui_add_edit_have_changes (KolabFolderPermUIData *uidata,
                                                    KolabFolderPermID perm_id)
 {
@@ -308,13 +347,9 @@ static void
 kolab_folder_permissions_ui_update_edit_dialog (KolabFolderPermUIData *uidata)
 {
 	GtkComboBoxText *entrybox = NULL;
-	GtkTreeView *treeview = NULL;
-	GtkTreeSelection *treesel = NULL;
-	GtkTreeModel *treemodel = NULL;
-	GtkTreeIter treeiter;
 	gchar *access_id = NULL;
 	gchar *rights = NULL;
-	gboolean have_sel = FALSE;
+	gboolean ok = FALSE;
 
 	g_return_if_fail (uidata != NULL);
 	g_return_if_fail (uidata->widgets != NULL);
@@ -327,23 +362,11 @@ kolab_folder_permissions_ui_update_edit_dialog (KolabFolderPermUIData *uidata)
 	                          FALSE);
 
 	/* get the access_id and rights string from the tree selection */
-
-	treeview = GTK_TREE_VIEW (uidata->widgets->treeview);
-	treesel = gtk_tree_view_get_selection (treeview);
-	g_return_if_fail (treesel != NULL);
-
-	have_sel = gtk_tree_selection_get_selected (treesel,
-	                                            &treemodel,
-	                                            &treeiter);
-	g_return_if_fail (have_sel);
-	g_return_if_fail (GTK_IS_TREE_MODEL (treemodel));
-
-	gtk_tree_model_get (treemodel, &treeiter,
-	                    0, &access_id,
-	                    1, &rights,
-	                    -1);
-	g_return_if_fail (access_id != NULL);
-	/* rights may be NULL */
+	ok = kolab_folder_permissions_ui_treeview_get_selected (uidata,
+	                                                        &access_id,
+	                                                        &rights);
+	if (! ok)
+		return;
 
 	/* update dialog */
 	entrybox = GTK_COMBO_BOX_TEXT (uidata->widgets->edit_entry_box);
@@ -692,7 +715,6 @@ static void
 kolab_folder_permissions_ui_add_dialog_cb (KolabFolderPermUIData *uidata)
 {
 	g_assert (uidata != NULL);
-	g_assert (uidata->widgets != NULL);
 
 	uidata->editing = FALSE;
 	kolab_folder_permissions_ui_add_edit_dialog (uidata);
@@ -701,13 +723,63 @@ kolab_folder_permissions_ui_add_dialog_cb (KolabFolderPermUIData *uidata)
 static void
 kolab_folder_permissions_ui_edit_dialog_cb (KolabFolderPermUIData *uidata)
 {
+	gchar *access_id = NULL;
+	gchar *rights = NULL;
+	gboolean ok = FALSE;
+
 	g_assert (uidata != NULL);
-	g_assert (uidata->widgets != NULL);
 
+	/* check whether we have a valid treeview selection */
+	ok = kolab_folder_permissions_ui_treeview_get_selected (uidata,
+	                                                        &access_id,
+	                                                        &rights);
+	if (! ok)
+		return;
+
+	g_free (access_id);
+	g_free (rights);
+
+	/* show edit dialog */
 	uidata->editing = TRUE;
 	kolab_folder_permissions_ui_add_edit_dialog (uidata);
 }
 
+static void
+kolab_folder_permissions_ui_acl_remove_cb (KolabFolderPermUIData *uidata)
+{
+	gchar *access_id = NULL;
+	gchar *rights = NULL;
+	GError *tmp_err = NULL;
+	gboolean ok = FALSE;
+
+	g_assert (uidata != NULL);
+
+	/* remove selected entry from payload data */
+	ok = kolab_folder_permissions_ui_treeview_get_selected (uidata,
+	                                                        &access_id,
+	                                                        &rights);
+	if (! ok)
+		return;
+
+	ok = camel_imapx_acl_list_remove_entry (&(uidata->permissions->acl),
+	                                        access_id,
+	                                        &tmp_err);
+	if (tmp_err != NULL) {
+		g_warning ("%s()[%u] %s",
+		           __func__, __LINE__, tmp_err->message);
+		g_error_free (tmp_err);
+	}
+
+	g_free (access_id);
+	if (rights != NULL)
+		g_free (rights);
+
+	/* update treeview */
+	if (ok) {
+		kolab_folder_permissions_ui_update_treeview (uidata);
+	}
+}
+
 static GtkWidget*
 kolab_folder_permissions_ui_create_tree_view (KolabFolderPermUIData *uidata)
 {
@@ -849,6 +921,10 @@ e_kolab_folder_permissions_ui_new (void)
 	                          "clicked",
 	                          G_CALLBACK (kolab_folder_permissions_ui_edit_dialog_cb),
 	                          uidata);
+	g_signal_connect_swapped (G_OBJECT (uidata->widgets->btn_remove),
+	                          "clicked",
+	                          G_CALLBACK (kolab_folder_permissions_ui_acl_remove_cb),
+	                          uidata);
 	return uidata;
 }
 



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