X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/6f23269f26ebf9a875c3e32bcf0cd2d23ba93a5d..e18c4734744e56b738ca2918dffe071f95f4c14b:/disobedience/users.c diff --git a/disobedience/users.c b/disobedience/users.c index 3e6cc86..d162e14 100644 --- a/disobedience/users.c +++ b/disobedience/users.c @@ -32,6 +32,13 @@ * * When you select 'add' a new empty set of details are displayed to be edited. * Again Apply will commit them. + * + * TODO: @ref RIGHT_ADMIN and @ref RIGHT_USERINFO should be applied here, so we + * can give decent error messages. + * + * 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" @@ -274,6 +281,20 @@ static void users_add_right_group(const char *title, gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(random), !!(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 * @param name User name (users_edit()) or NULL (users_add()) * @param email Email address @@ -289,8 +310,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, @@ -557,13 +581,13 @@ static void users_selection_changed(GtkTreeSelection attribute((unused)) *treese /** @brief Table of buttons below the user list */ static struct button users_buttons[] = { { - "Add user", + GTK_STOCK_ADD, users_add, "Create a new user", 0 }, { - "Delete user", + GTK_STOCK_REMOVE, users_delete, "Delete a user", 0 @@ -573,7 +597,7 @@ static struct button users_buttons[] = { /** @brief Pop up the user management window */ void manage_users(void) { - GtkWidget *tree, *buttons, *hbox, *vbox, *vbox2; + GtkWidget *tree, *buttons, *hbox, *hbox2, *vbox, *vbox2; GtkCellRenderer *cr; GtkTreeViewColumn *col; @@ -617,8 +641,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 */ @@ -626,20 +650,26 @@ void manage_users(void) { users_makedetails("", "", "", "", DETAIL_VISIBLE, DETAIL_VISIBLE); - /* TODO apply button is much too wide right now... */ g_signal_connect(users_apply_button, "clicked", G_CALLBACK(users_apply), NULL); - vbox2 = gtk_vbox_new(FALSE, 2); + hbox2 = gtk_hbox_new(FALSE, 0); + gtk_box_pack_end(GTK_BOX(hbox2), users_apply_button, + FALSE/*expand*/, FALSE, 0); + + vbox2 = gtk_vbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox2), users_details_table, TRUE/*expand*/, TRUE/*fill*/, 0); - gtk_box_pack_start(GTK_BOX(vbox2), users_apply_button, + 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); + /* 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), hbox); + gtk_container_add(GTK_CONTAINER(users_window), frame_widget(hbox, NULL)); } /*