X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/14f8878f0b35d342f6a51fe84e1d67d720e7347b..159f3470a01211557dcd39f5701dcaf0f43f6683:/disobedience/users.c diff --git a/disobedience/users.c b/disobedience/users.c index f5ab89b..fe90433 100644 --- a/disobedience/users.c +++ b/disobedience/users.c @@ -32,6 +32,10 @@ * * When you select 'add' a new empty set of details are displayed to be edited. * Again Apply will commit them. + * + * TODO: it would be really nice if the Username entry could be removed and new + * user names entered in the list, rather off in the details panel. This may + * be possible with a sufficiently clever GtkCellRenderer. */ #include "disobedience.h" @@ -189,7 +193,7 @@ static void users_add_right(const char *title, GtkWidget **checkp = &users_details_rights[leftmost_bit(right)]; if(!(check = *checkp)) { - *checkp = check = gtk_check_button_new(); + *checkp = check = gtk_check_button_new_with_label(""); users_detail_generic(title, check); } gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), !!(value & right)); @@ -244,26 +248,26 @@ static void users_add_right_group(const char *title, rights_type mask) { const uint32_t first = mask / 7; const int bit = leftmost_bit(first); - GtkWidget **widgets = &users_details_rights[bit], *any, *mine, *random; + GtkWidget **widgets = &users_details_rights[bit], *any, *mine, *rnd; if(!*widgets) { GtkWidget *hbox = gtk_hbox_new(FALSE, 2); any = widgets[0] = gtk_check_button_new_with_label("Any"); mine = widgets[1] = gtk_check_button_new_with_label("Own"); - random = widgets[2] = gtk_check_button_new_with_label("Random"); + rnd = widgets[2] = gtk_check_button_new_with_label("Random"); gtk_box_pack_start(GTK_BOX(hbox), any, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), mine, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(hbox), random, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(hbox), rnd, FALSE, FALSE, 0); users_detail_generic(title, hbox); g_signal_connect(any, "toggled", G_CALLBACK(users_any_toggled), NULL); users_details_rights[bit] = any; users_details_rights[bit + 1] = mine; - users_details_rights[bit + 2] = random; + users_details_rights[bit + 2] = rnd; } else { any = widgets[0]; mine = widgets[1]; - random = widgets[2]; + rnd = widgets[2]; } /* Discard irrelevant bits */ bits &= mask; @@ -271,7 +275,21 @@ static void users_add_right_group(const char *title, bits >>= bit; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(any), !!(bits & 1)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mine), !!(bits & 2)); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(random), !!(bits & 4)); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rnd), !!(bits & 4)); +} + +/** @brief Called when the details table is destroyed */ +static void users_details_destroyed(GtkWidget attribute((unused)) *widget, + GtkWidget attribute((unused)) **wp) { + users_details_table = 0; + g_object_unref(users_list); + users_list = 0; + users_details_name = 0; + users_details_email = 0; + users_details_password = 0; + users_details_password2 = 0; + memset(users_details_rights, 0, sizeof users_details_rights); + /* also users_selection? Not AFAICT; _get_selection does upref */ } /** @brief Create or modify the user details table @@ -289,8 +307,11 @@ static void users_makedetails(const char *name, rights_type r = 0; /* Create the table if it doesn't already exist */ - if(!users_details_table) + if(!users_details_table) { users_details_table = gtk_table_new(4, 2, FALSE/*!homogeneous*/); + g_signal_connect(users_details_table, "destroy", + G_CALLBACK(users_details_destroyed), 0); + } /* Create or update the widgets */ users_add_detail(&users_details_name, "Username", name, @@ -617,8 +638,8 @@ void manage_users(void) { users_delete_button = users_buttons[1].widget; /* Buttons live below the list */ - vbox = gtk_vbox_new(FALSE, 2); - gtk_box_pack_start(GTK_BOX(vbox), tree, TRUE/*expand*/, TRUE/*fill*/, 0); + vbox = gtk_vbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), scroll_widget(tree), TRUE/*expand*/, TRUE/*fill*/, 0); gtk_box_pack_start(GTK_BOX(vbox), buttons, FALSE/*expand*/, FALSE, 0); /* Create an empty user details table, and put an apply button below it */ @@ -638,11 +659,14 @@ void manage_users(void) { gtk_box_pack_start(GTK_BOX(vbox2), hbox2, FALSE/*expand*/, FALSE, 0); - /* User details are to the right of the list */ - hbox = gtk_hbox_new(FALSE, 2); - gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE/*expand*/, FALSE, 2); - gtk_box_pack_start(GTK_BOX(hbox), vbox2, TRUE/*expand*/, TRUE/*fill*/, 2); - gtk_container_add(GTK_CONTAINER(users_window), hbox); + /* User details are to the right of the list. We put in a pointless event + * box as as spacer, so that the longest label in the user details isn't + * cuddled up to the user list. */ + hbox = gtk_hbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE/*expand*/, FALSE, 0); + gtk_box_pack_start(GTK_BOX(hbox), gtk_event_box_new(), FALSE/*expand*/, FALSE, 2); + gtk_box_pack_start(GTK_BOX(hbox), vbox2, TRUE/*expand*/, TRUE/*fill*/, 0); + gtk_container_add(GTK_CONTAINER(users_window), frame_widget(hbox, NULL)); } /*