[evolution-kolab] EPlugin: implemented signals inside ACL add/edit sub-dialog, internal rework
- From: Christian Hilberg <chilberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-kolab] EPlugin: implemented signals inside ACL add/edit sub-dialog, internal rework
- Date: Tue, 9 Oct 2012 18:13:19 +0000 (UTC)
commit 639fe4c3b679329c072f42c1b05b66cb458e7195
Author: Christian Hilberg <hilberg kernelconcepts de>
Date: Tue Oct 9 20:05:17 2012 +0200
EPlugin: implemented signals inside ACL add/edit sub-dialog,
internal rework
* merged ACL permission type GtkRadioButtons
into an array (same as in metadata)
* implemented callbacks for signalling
(set sensitive the OK dialog buttons
only when we have a real change)
src/eplugin/e-kolab-folder-permissions.c | 237 +++++++++++++++++++++++++-----
src/eplugin/e-kolab-folder-permissions.h | 12 +-
2 files changed, 208 insertions(+), 41 deletions(-)
---
diff --git a/src/eplugin/e-kolab-folder-permissions.c b/src/eplugin/e-kolab-folder-permissions.c
index 7cf35bd..372216b 100644
--- a/src/eplugin/e-kolab-folder-permissions.c
+++ b/src/eplugin/e-kolab-folder-permissions.c
@@ -33,7 +33,10 @@
#include <e-util/e-config.h>
#include <e-util/e-plugin.h>
+#include <libekolab/camel-kolab-imapx-store.h>
+
#include <libekolabutil/kolab-util-error.h>
+#include <libekolabutil/kolab-util-folder.h>
#include "e-kolab-plugin-util.h"
#include "e-kolab-folder-permissions.h"
@@ -53,6 +56,161 @@ enum {
/* internal statics (UI) */
static void
+kolab_folder_permissions_ui_create_folder_perms_map (KolabFolderPermUIData *uidata)
+{
+ GHashTable *map = NULL;
+
+ g_assert (uidata != NULL);
+ g_assert (uidata->widgets != NULL);
+
+ map = g_hash_table_new_full (g_direct_hash,
+ g_direct_equal,
+ NULL, /* radio button addresses as keys */
+ NULL); /* numeric Kolab folder perms as values */;
+
+ g_hash_table_insert (map,
+ uidata->widgets->radio_btn_perm[0],
+ GUINT_TO_POINTER (KOLAB_FOLDER_PERM_NOCHANGE));
+ g_hash_table_insert (map,
+ uidata->widgets->radio_btn_perm[1],
+ GUINT_TO_POINTER (KOLAB_FOLDER_PERM_READ));
+ g_hash_table_insert (map,
+ uidata->widgets->radio_btn_perm[2],
+ GUINT_TO_POINTER (KOLAB_FOLDER_PERM_APPEND));
+ g_hash_table_insert (map,
+ uidata->widgets->radio_btn_perm[3],
+ GUINT_TO_POINTER (KOLAB_FOLDER_PERM_WRITE));
+ g_hash_table_insert (map,
+ uidata->widgets->radio_btn_perm[4],
+ GUINT_TO_POINTER (KOLAB_FOLDER_PERM_ALL));
+
+ if (uidata->widgets->folder_perm_map != NULL)
+ g_hash_table_destroy (uidata->widgets->folder_perm_map);
+ uidata->widgets->folder_perm_map = map;
+}
+
+static gboolean
+kolab_folder_permissions_ui_add_edit_have_changes (KolabFolderPermUIData *uidata,
+ KolabFolderPermID perm_id)
+{
+ GtkComboBoxText *entry = NULL;
+ gchar *text = NULL;
+ gboolean have_changes = FALSE;
+
+ g_return_val_if_fail (uidata != NULL, FALSE);
+ g_return_val_if_fail (uidata->widgets != NULL, FALSE);
+ g_return_val_if_fail (uidata->widgets->edit_entry_box != NULL, FALSE);
+
+ if (uidata->editing) {
+ have_changes =
+ (perm_id != KOLAB_FOLDER_PERM_NOCHANGE);
+ } else {
+ entry = GTK_COMBO_BOX_TEXT (uidata->widgets->edit_entry_box);
+ text = gtk_combo_box_text_get_active_text (entry);
+ have_changes =
+ ((perm_id != KOLAB_FOLDER_PERM_NOCHANGE) &&
+ (text != NULL) &&
+ (g_strcmp0 (text, "") != 0));
+ if (text != NULL)
+ g_free (text);
+ }
+
+ return have_changes;
+}
+
+static void
+kolab_folder_permissions_ui_add_edit_update_ok_buttons (KolabFolderPermUIData *uidata,
+ KolabFolderPermID perm_id)
+{
+ GtkDialog *edit_dialog = NULL;
+ gboolean activate_ok_btn = FALSE;
+
+ g_return_if_fail (uidata != NULL);
+ g_return_if_fail (GTK_IS_DIALOG (uidata->dialog));
+ g_return_if_fail (uidata->widgets != NULL);
+ g_return_if_fail (GTK_IS_DIALOG (uidata->widgets->edit_dialog));
+
+ edit_dialog = GTK_DIALOG (uidata->widgets->edit_dialog);
+
+ activate_ok_btn =
+ kolab_folder_permissions_ui_add_edit_have_changes (uidata,
+ perm_id);
+
+ if (activate_ok_btn) {
+ e_kolab_plugin_util_ui_dialog_set_button_sensitive (uidata->dialog,
+ GTK_STOCK_OK,
+ TRUE,
+ TRUE);
+ e_kolab_plugin_util_ui_dialog_set_button_sensitive (edit_dialog,
+ GTK_STOCK_OK,
+ TRUE,
+ TRUE);
+ } else {
+ /* The "Kolab Folder Permissions..." dialog button,
+ * once activated, is not deactivated here, since we
+ * may have some changes pending in the Metadata tab.
+ * Hence, we only deactivate the add/edit sub-dialog
+ * button as long as we do not have any changes pending
+ * in the add/edit dialog
+ */
+ e_kolab_plugin_util_ui_dialog_set_button_sensitive (edit_dialog,
+ GTK_STOCK_OK,
+ TRUE,
+ FALSE);
+ }
+}
+
+static void
+kolab_folder_permissions_ui_folderperm_cb (GtkRadioButton *btn,
+ gpointer userdata)
+{
+ KolabFolderPermUIData *uidata = NULL;
+ KolabFolderPermID perm_id = KOLAB_FOLDER_PERM_NOCHANGE;
+ gpointer perm = NULL;
+
+ g_return_if_fail (GTK_IS_RADIO_BUTTON (btn));
+ g_return_if_fail (userdata != NULL);
+
+ uidata = (KolabFolderPermUIData *) userdata;
+ g_return_if_fail (uidata->widgets != NULL);
+
+ perm = g_hash_table_lookup (uidata->widgets->folder_perm_map,
+ (gpointer) btn);
+ if (perm != NULL)
+ perm_id = GPOINTER_TO_UINT (perm);
+
+ kolab_folder_permissions_ui_add_edit_update_ok_buttons (uidata,
+ perm_id);
+}
+
+static void
+kolab_folder_permissions_ui_edit_entry_box_cb (GtkComboBoxText *box,
+ gpointer userdata)
+{
+ KolabFolderPermUIData *uidata = NULL;
+ GtkRadioButton *btn = NULL;
+ GtkToggleButton *cur_btn = NULL;
+ gint ii = 0;
+
+ g_return_if_fail (GTK_IS_COMBO_BOX_TEXT (box));
+ g_return_if_fail (userdata != NULL);
+
+ uidata = (KolabFolderPermUIData *) userdata;
+ g_return_if_fail (uidata->widgets != NULL);
+
+ for (ii = 0; ii < KOLAB_FOLDER_LAST_PERM; ii++) {
+ cur_btn = GTK_TOGGLE_BUTTON (uidata->widgets->radio_btn_perm[ii]);
+ if (gtk_toggle_button_get_active (cur_btn)) {
+ btn = GTK_RADIO_BUTTON (cur_btn);
+ break;
+ }
+ }
+
+ kolab_folder_permissions_ui_folderperm_cb (btn,
+ userdata);
+}
+
+static void
kolab_folder_permissions_ui_edit_dialog_response_cb (GObject *dialog,
gint response_id)
{
@@ -85,6 +243,12 @@ kolab_folder_permissions_ui_update_add_dialog (KolabFolderPermUIData *uidata)
*/
gtk_widget_hide (uidata->widgets->access_rights);
+ /* when adding a new ACL entry, the "Keep the
+ * current permission settings" selection is
+ * meaningless, so we hide it here
+ */
+ gtk_widget_hide (uidata->widgets->radio_btn_perm[KOLAB_FOLDER_PERM_NOCHANGE]);
+
g_return_if_fail (GTK_IS_COMBO_BOX_TEXT (uidata->widgets->edit_entry_box));
entrybox = GTK_COMBO_BOX_TEXT (uidata->widgets->edit_entry_box);
@@ -199,6 +363,7 @@ kolab_folder_permissions_ui_add_edit_dialog (KolabFolderPermUIData *uidata)
GtkWidget *grid = NULL;
GtkWidget *widget = NULL;
gint row = 0;
+ gint ii = 0;
g_assert (uidata != NULL);
g_assert (uidata->widgets != NULL);
@@ -264,41 +429,29 @@ kolab_folder_permissions_ui_add_edit_dialog (KolabFolderPermUIData *uidata)
row = 0;
- if (uidata->editing) {
- btn_loco = gtk_radio_button_new_with_label (uidata->widgets->radio_group,
- C_("Kolab Folder Permissions",
- "Keep the current permission settings"));
- uidata->widgets->radio_btn_perm_nochange = btn_loco;
- gtk_grid_attach (GTK_GRID (grid), btn_loco, 0, row, 2, 1);
-
- row++;
-
- btn = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (btn_loco),
- C_("Kolab Folder Permissions",
- "Read"));
- uidata->widgets->radio_btn_perm_read = btn;
- gtk_grid_attach (GTK_GRID (grid), btn, 0, row, 1, 1);
- widget = gtk_label_new ("(lrsip)");
- gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
- gtk_grid_attach (GTK_GRID (grid), widget, 1, row, 1, 1);
- } else {
- uidata->widgets->radio_btn_perm_nochange = NULL;
- btn_loco = gtk_radio_button_new_with_label (uidata->widgets->radio_group,
- C_("Kolab Folder Permissions",
- "Read"));
- uidata->widgets->radio_btn_perm_read = btn_loco;
- gtk_grid_attach (GTK_GRID (grid), btn_loco, 0, row, 1, 1);
- widget = gtk_label_new ("(lrsip)");
- gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
- gtk_grid_attach (GTK_GRID (grid), widget, 1, row, 1, 1);
- }
+ btn_loco = gtk_radio_button_new_with_label (uidata->widgets->radio_group,
+ C_("Kolab Folder Permissions",
+ "Keep the current permission settings"));
+ uidata->widgets->radio_btn_perm[KOLAB_FOLDER_PERM_NOCHANGE] = btn_loco;
+ gtk_grid_attach (GTK_GRID (grid), btn_loco, 0, row, 2, 1);
+
+ row++;
+
+ btn = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (btn_loco),
+ C_("Kolab Folder Permissions",
+ "Read"));
+ uidata->widgets->radio_btn_perm[KOLAB_FOLDER_PERM_READ] = btn;
+ gtk_grid_attach (GTK_GRID (grid), btn, 0, row, 1, 1);
+ widget = gtk_label_new ("(lrsip)");
+ gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
+ gtk_grid_attach (GTK_GRID (grid), widget, 1, row, 1, 1);
row++;
btn = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (btn_loco),
C_("Kolab Folder Permissions",
"Append"));
- uidata->widgets->radio_btn_perm_append = btn;
+ uidata->widgets->radio_btn_perm[KOLAB_FOLDER_PERM_APPEND] = btn;
gtk_grid_attach (GTK_GRID (grid), btn, 0, row, 1, 1);
widget = gtk_label_new ("(lrsip)");
gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
@@ -309,7 +462,7 @@ kolab_folder_permissions_ui_add_edit_dialog (KolabFolderPermUIData *uidata)
btn = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (btn_loco),
C_("Kolab Folder Permissions",
"Write"));
- uidata->widgets->radio_btn_perm_write = btn;
+ uidata->widgets->radio_btn_perm[KOLAB_FOLDER_PERM_WRITE] = btn;
gtk_grid_attach (GTK_GRID (grid), btn, 0, row, 1, 1);
widget = gtk_label_new ("(lrswipte)");
gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
@@ -320,14 +473,29 @@ kolab_folder_permissions_ui_add_edit_dialog (KolabFolderPermUIData *uidata)
btn = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (btn_loco),
C_("Kolab Folder Permissions",
"All"));
- uidata->widgets->radio_btn_perm_all = btn;
+ uidata->widgets->radio_btn_perm[KOLAB_FOLDER_PERM_ALL] = btn;
gtk_grid_attach (GTK_GRID (grid), btn, 0, row, 1, 1);
widget = gtk_label_new ("(lrswipakxte)");
gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
gtk_grid_attach (GTK_GRID (grid), widget, 1, row, 1, 1);
- /* FIXME connect signals */
- g_warning ("%s: FIXME connect signals", __func__);
+ kolab_folder_permissions_ui_create_folder_perms_map (uidata);
+
+
+ /* folder perms radio buttons */
+ for (ii = 0; ii < KOLAB_FOLDER_PERM_UI_NUM_PERMS; ii++) {
+ uidata->widgets->radio_btn_handler_id[ii] =
+ g_signal_connect (G_OBJECT (uidata->widgets->radio_btn_perm[ii]),
+ "toggled",
+ G_CALLBACK (kolab_folder_permissions_ui_folderperm_cb),
+ uidata);
+ }
+
+ /* access_id combo box */
+ g_signal_connect (G_OBJECT (uidata->widgets->edit_entry_box),
+ "changed",
+ G_CALLBACK (kolab_folder_permissions_ui_edit_entry_box_cb),
+ uidata);
g_signal_connect (dialog,
"response",
@@ -564,9 +732,6 @@ e_kolab_folder_permissions_ui_new (void)
gtk_box_pack_start (GTK_BOX (vbox), uidata->widgets->btn_remove, FALSE, FALSE, 0);
gtk_grid_attach (GTK_GRID (grid), vbox, 1, row, 1, 1);
- /* FIXME connect signals */
- g_warning ("%s: FIXME connect signals", __func__);
-
g_signal_connect_swapped (G_OBJECT (uidata->widgets->btn_add),
"clicked",
G_CALLBACK (kolab_folder_permissions_ui_add_dialog_cb),
diff --git a/src/eplugin/e-kolab-folder-permissions.h b/src/eplugin/e-kolab-folder-permissions.h
index 96ce784..a98c975 100644
--- a/src/eplugin/e-kolab-folder-permissions.h
+++ b/src/eplugin/e-kolab-folder-permissions.h
@@ -44,6 +44,10 @@
/*----------------------------------------------------------------------------*/
+#define KOLAB_FOLDER_PERM_UI_NUM_PERMS 5
+
+/*----------------------------------------------------------------------------*/
+
typedef struct _KolabFolderPermUIWidgets KolabFolderPermUIWidgets;
struct _KolabFolderPermUIWidgets {
GtkWidget *container;
@@ -61,12 +65,10 @@ struct _KolabFolderPermUIWidgets {
GtkWidget *edit_btn_retrieve;
GtkWidget *access_rights;
GtkWidget *access_rights_lbl;
+ GHashTable *folder_perm_map;
GSList *radio_group;
- GtkWidget *radio_btn_perm_nochange;
- GtkWidget *radio_btn_perm_read;
- GtkWidget *radio_btn_perm_append;
- GtkWidget *radio_btn_perm_write;
- GtkWidget *radio_btn_perm_all;
+ gulong radio_btn_handler_id[KOLAB_FOLDER_PERM_UI_NUM_PERMS];
+ GtkWidget *radio_btn_perm[KOLAB_FOLDER_PERM_UI_NUM_PERMS];
};
typedef struct _KolabFolderPermUIData KolabFolderPermUIData;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]