chiark / gitweb /
Select newly created user automatically. User editing now works.
[disorder] / disobedience / users.c
1 /*
2  * This file is part of DisOrder
3  * Copyright (C) 2008 Richard Kettlewell
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20 /** @file disobedience/users.c
21  * @brief User management for Disobedience
22  *
23  * The user management window contains:
24  * - a list of all the users
25  * - an add button
26  * - a delete button
27  * - a user details panel
28  * - an apply button
29  *
30  * When you select a user that user's details are displayed to the right of the
31  * list.  Hit the Apply button and any changes are applied.
32  *
33  * When you select 'add' a new empty set of details are displayed to be edited.
34  * Again Apply will commit them.
35  */
36
37 #include "disobedience.h"
38 #include "bits.h"
39
40 static GtkWidget *users_window;
41 static GtkListStore *users_list;
42 static GtkTreeSelection *users_selection;
43
44 static GtkWidget *users_details_table;
45 static GtkWidget *users_apply_button;
46 static GtkWidget *users_delete_button;
47 static GtkWidget *users_details_name;
48 static GtkWidget *users_details_email;
49 static GtkWidget *users_details_password;
50 static GtkWidget *users_details_password2;
51 static GtkWidget *users_details_rights[32];
52 static int users_details_row;
53 static const char *users_selected;
54 static const char *users_deferred_select;
55
56 static int users_mode;
57 #define MODE_NONE 0
58 #define MODE_ADD 1
59 #define MODE_EDIT 2
60
61 #define mode(X) do {                                    \
62   users_mode = MODE_##X;                                \
63   if(0) fprintf(stderr, "%s:%d: %s(): mode -> %s\n",    \
64           __FILE__, __LINE__, __FUNCTION__, #X);        \
65   users_details_sensitize_all();                        \
66 } while(0)
67
68 static const char *users_email, *users_rights, *users_password;
69
70 /** @brief qsort() callback for username comparison */
71 static int usercmp(const void *a, const void *b) {
72   return strcmp(*(char **)a, *(char **)b);
73 }
74
75 /** @brief Find a user
76  * @param user User to find
77  * @param iter Iterator to point at user
78  * @return 0 on success, -1 if not found
79  */
80 static int users_find_user(const char *user,
81                            GtkTreeIter *iter) {
82   char *who;
83
84   /* Find the user */
85   if(!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(users_list), iter))
86     return -1;
87   do {
88     gtk_tree_model_get(GTK_TREE_MODEL(users_list), iter,
89                        0, &who, -1);
90     if(!strcmp(who, user)) {
91       g_free(who);
92       return 0;
93     }
94     g_free(who);
95   } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(users_list), iter));
96   return -1;
97 }
98
99 /** @brief Called with the list of users
100  *
101  * Called:
102  * - at startup to populate the initial list
103  * - when we add a user
104  * - maybe in the future when we delete a user
105  *
106  * If users_deferred_select is set then that user is selected.
107  */
108 static void users_got_list(void attribute((unused)) *v, int nvec, char **vec) {
109   int n;
110   GtkTreeIter iter;
111
112   /* Present users in alphabetical order */
113   qsort(vec, nvec, sizeof (char *), usercmp);
114   /* Set the list contents */
115   gtk_list_store_clear(users_list);
116   for(n = 0; n < nvec; ++n)
117     gtk_list_store_insert_with_values(users_list, &iter, n/*position*/,
118                                       0, vec[n], /* column 0 */
119                                       -1);       /* no more columns */
120   /* Only show the window when the list is populated */
121   gtk_widget_show_all(users_window);
122   if(users_deferred_select) {
123     if(!users_find_user(users_deferred_select, &iter))
124       gtk_tree_selection_select_iter(users_selection, &iter);
125     users_deferred_select = 0;
126   }
127 }
128
129 /** @brief Text should be visible */
130 #define DETAIL_VISIBLE 1
131
132 /** @brief Text should be editable */
133 #define DETAIL_EDITABLE 2
134
135 /** @brief Add a row to the user detail table */
136 static void users_detail_generic(const char *title,
137                                  GtkWidget *selector) {
138   const int row = users_details_row++;
139   GtkWidget *const label = gtk_label_new(title);
140   gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
141   gtk_table_attach(GTK_TABLE(users_details_table),
142                    label,
143                    0, 1,                /* left/right_attach */
144                    row, row+1,          /* top/bottom_attach */
145                    GTK_FILL,            /* xoptions */
146                    0,                   /* yoptions */
147                    1, 1);               /* x/ypadding */
148   gtk_table_attach(GTK_TABLE(users_details_table),
149                    selector,
150                    1, 2,                /* left/right_attach */
151                    row, row + 1,        /* top/bottom_attach */
152                    GTK_EXPAND|GTK_FILL, /* xoptions */
153                    GTK_FILL,            /* yoptions */
154                    1, 1);               /* x/ypadding */
155 }
156
157 /** @brief Add a row to the user details table
158  * @param entryp Where to put GtkEntry
159  * @param title Label for this row
160  * @param value Initial value or NULL
161  * @param flags Flags word
162  */
163 static void users_add_detail(GtkWidget **entryp,
164                              const char *title,
165                              const char *value,
166                              unsigned flags) {
167   GtkWidget *entry;
168
169   if(!(entry = *entryp)) {
170     *entryp = entry = gtk_entry_new();
171     users_detail_generic(title, entry);
172   }
173   gtk_entry_set_visibility(GTK_ENTRY(entry),
174                            !!(flags & DETAIL_VISIBLE));
175   gtk_editable_set_editable(GTK_EDITABLE(entry),
176                             !!(flags & DETAIL_EDITABLE));
177   gtk_entry_set_text(GTK_ENTRY(entry), value ? value : "");
178 }
179
180 /** @brief Add a checkbox for a right
181  * @param title Label for this row
182  * @param value Current value
183  * @param right Right bit
184  */
185 static void users_add_right(const char *title,
186                             rights_type value,
187                             rights_type right) {
188   GtkWidget *check;
189   GtkWidget **checkp = &users_details_rights[leftmost_bit(right)];
190
191   if(!(check = *checkp)) {
192     *checkp = check = gtk_check_button_new();
193     users_detail_generic(title, check);
194   }
195   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), !!(value & right));
196 }
197
198 /** @brief Set sensitivity of particular mine/random rights bits */
199 static void users_details_sensitize(rights_type r) {
200   const int bit = leftmost_bit(r);
201   const GtkWidget *all = users_details_rights[bit];
202   const int sensitive = (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(all))
203                          && users_mode != MODE_NONE);
204
205   gtk_widget_set_sensitive(users_details_rights[bit + 1], sensitive);
206   gtk_widget_set_sensitive(users_details_rights[bit + 2], sensitive);
207 }
208
209 /** @brief Set sensitivity of everything in sight */
210 static void users_details_sensitize_all(void) {
211   int n;
212
213   for(n = 0; n < 32; ++n)
214     if(users_details_rights[n])
215       gtk_widget_set_sensitive(users_details_rights[n], users_mode != MODE_NONE);
216   gtk_widget_set_sensitive(users_details_name, users_mode != MODE_NONE);
217   gtk_widget_set_sensitive(users_details_email, users_mode != MODE_NONE);
218   gtk_widget_set_sensitive(users_details_password, users_mode != MODE_NONE);
219   gtk_widget_set_sensitive(users_details_password2, users_mode != MODE_NONE);
220   users_details_sensitize(RIGHT_MOVE_ANY);
221   users_details_sensitize(RIGHT_REMOVE_ANY);
222   users_details_sensitize(RIGHT_SCRATCH_ANY);
223   gtk_widget_set_sensitive(users_apply_button, users_mode != MODE_NONE);
224   gtk_widget_set_sensitive(users_delete_button, !!users_selected);
225 }
226
227 /** @brief Called when an _ALL widget is toggled
228  *
229  * Modifies sensitivity of the corresponding _MINE and _RANDOM widgets.  We
230  * just do the lot rather than trying to figure out which one changed,
231  */
232 static void users_any_toggled(GtkToggleButton attribute((unused)) *togglebutton,
233                               gpointer attribute((unused)) user_data) {
234   users_details_sensitize_all();
235 }
236
237 /** @brief Add a checkbox for a three-right group
238  * @param title Label for this row
239  * @param bits Rights bits (not masked or normalized)
240  * @param mask Mask for this group (must be 7*2^n)
241  */
242 static void users_add_right_group(const char *title,
243                                   rights_type bits,
244                                   rights_type mask) {
245   const uint32_t first = mask / 7;
246   const int bit = leftmost_bit(first);
247   GtkWidget **widgets = &users_details_rights[bit], *any, *mine, *random;
248
249   if(!*widgets) {
250     GtkWidget *hbox = gtk_hbox_new(FALSE, 2);
251
252     any = widgets[0] = gtk_check_button_new_with_label("Any");
253     mine = widgets[1] = gtk_check_button_new_with_label("Own");
254     random = widgets[2] = gtk_check_button_new_with_label("Random");
255     gtk_box_pack_start(GTK_BOX(hbox), any, FALSE, FALSE, 0);
256     gtk_box_pack_start(GTK_BOX(hbox), mine, FALSE, FALSE, 0);
257     gtk_box_pack_start(GTK_BOX(hbox), random, FALSE, FALSE, 0);
258     users_detail_generic(title, hbox);
259     g_signal_connect(any, "toggled", G_CALLBACK(users_any_toggled), NULL);
260     users_details_rights[bit] = any;
261     users_details_rights[bit + 1] = mine;
262     users_details_rights[bit + 2] = random;
263   } else {
264     any = widgets[0];
265     mine = widgets[1];
266     random = widgets[2];
267   }
268   /* Discard irrelevant bits */
269   bits &= mask;
270   /* Shift down to bits 0-2; the mask is always 3 contiguous bits */
271   bits >>= bit;
272   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(any), !!(bits & 1));
273   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mine), !!(bits & 2));
274   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(random), !!(bits & 4));
275 }
276
277 /** @brief Create or modify the user details table
278  * @param name User name (users_edit()) or NULL (users_add())
279  * @param email Email address
280  * @param rights User rights string
281  * @param password Password
282  */
283 static void users_makedetails(const char *name,
284                               const char *email,
285                               const char *rights,
286                               const char *password,
287                               unsigned nameflags,
288                               unsigned flags) {
289   rights_type r = 0;
290   
291   /* Create the table if it doesn't already exist */
292   if(!users_details_table)
293     users_details_table = gtk_table_new(4, 2, FALSE/*!homogeneous*/);
294
295   /* Create or update the widgets */
296   users_add_detail(&users_details_name, "Username", name,
297                    (DETAIL_EDITABLE|DETAIL_VISIBLE) & nameflags);
298
299   users_add_detail(&users_details_email, "Email", email,
300                    (DETAIL_EDITABLE|DETAIL_VISIBLE) & flags);
301
302   users_add_detail(&users_details_password, "Password", password,
303                    DETAIL_EDITABLE & flags);
304   users_add_detail(&users_details_password2, "Password", password,
305                    DETAIL_EDITABLE & flags);
306
307   parse_rights(rights, &r, 0);
308   users_add_right("Read operations", r, RIGHT_READ);
309   users_add_right("Play track", r, RIGHT_PLAY);
310   users_add_right_group("Move", r, RIGHT_MOVE__MASK);
311   users_add_right_group("Remove", r, RIGHT_REMOVE__MASK);
312   users_add_right_group("Scratch", r, RIGHT_SCRATCH__MASK);
313   users_add_right("Set volume", r, RIGHT_VOLUME);
314   users_add_right("Admin operations", r, RIGHT_ADMIN);
315   users_add_right("Rescan", r, RIGHT_RESCAN);
316   users_add_right("Register new users", r, RIGHT_REGISTER);
317   users_add_right("Modify own userinfo", r, RIGHT_USERINFO);
318   users_add_right("Modify track preferences", r, RIGHT_PREFS);
319   users_add_right("Modify global preferences", r, RIGHT_GLOBAL_PREFS);
320   users_add_right("Pause/resume tracks", r, RIGHT_PAUSE);
321   users_details_sensitize_all();
322 }
323
324 /** @brief Called when the 'add' button is pressed */
325 static void users_add(GtkButton attribute((unused)) *button,
326                       gpointer attribute((unused)) userdata) {
327   /* Unselect whatever is selected */
328   gtk_tree_selection_unselect_all(users_selection);
329   /* Reset the form */
330   /* TODO it would be better to use the server default_rights if there's no
331    * client setting. */
332   users_makedetails("",
333                     "",
334                     config->default_rights,
335                     "",
336                     DETAIL_EDITABLE|DETAIL_VISIBLE,
337                     DETAIL_EDITABLE|DETAIL_VISIBLE);
338   /* Remember we're adding a user */
339   mode(ADD);
340 }
341
342 static rights_type users_get_rights(void) {
343   rights_type r = 0;
344   int n;
345
346   /* Extract the rights value */
347   for(n = 0; n < 32; ++n) {
348     if(users_details_rights[n])
349       if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(users_details_rights[n])))
350          r |= 1 << n;
351   }
352   /* Throw out redundant bits */
353   if(r & RIGHT_REMOVE_ANY)
354     r &= ~(rights_type)(RIGHT_REMOVE_MINE|RIGHT_REMOVE_RANDOM);
355   if(r & RIGHT_MOVE_ANY)
356     r &= ~(rights_type)(RIGHT_MOVE_MINE|RIGHT_MOVE_RANDOM);
357   if(r & RIGHT_SCRATCH_ANY)
358     r &= ~(rights_type)(RIGHT_SCRATCH_MINE|RIGHT_SCRATCH_RANDOM);
359   return r;
360 }
361
362 /** @brief Called when various things fail */
363 static void users_op_failed(struct callbackdata attribute((unused)) *cbd,
364                             int attribute((unused)) code,
365                             const char *msg) {
366   popup_submsg(users_window, GTK_MESSAGE_ERROR, msg);
367 }
368
369 /** @brief Called when a new user has been created */
370 static void users_adduser_completed(void *v) {
371   struct callbackdata *cbd = v;
372
373   /* Now the user is created we can go ahead and set the email address */
374   if(*cbd->u.edituser.email) {
375     struct callbackdata *ncbd = xmalloc(sizeof *cbd);
376     ncbd->onerror = users_op_failed;
377     disorder_eclient_edituser(client, NULL, cbd->u.edituser.user,
378                               "email", cbd->u.edituser.email, ncbd);
379   }
380   /* Refresh the list of users */
381   disorder_eclient_users(client, users_got_list, 0);
382   /* We'll select the newly created user */
383   users_deferred_select = cbd->u.edituser.user;
384 }
385
386 /** @brief Called if creating a new user fails */
387 static void users_adduser_failed(struct callbackdata attribute((unused)) *cbd,
388                                  int attribute((unused)) code,
389                                  const char *msg) {
390   popup_submsg(users_window, GTK_MESSAGE_ERROR, msg);
391   mode(ADD);                            /* Let the user try again */
392 }
393
394 /** @brief Called when the 'Apply' button is pressed */
395 static void users_apply(GtkButton attribute((unused)) *button,
396                         gpointer attribute((unused)) userdata) {
397   struct callbackdata *cbd;
398   const char *password;
399   const char *password2;
400   const char *name;
401   const char *email;
402
403   switch(users_mode) {
404   case MODE_NONE:
405     return;
406   case MODE_ADD:
407     name = xstrdup(gtk_entry_get_text(GTK_ENTRY(users_details_name)));
408     email = xstrdup(gtk_entry_get_text(GTK_ENTRY(users_details_email)));
409     password = xstrdup(gtk_entry_get_text(GTK_ENTRY(users_details_password)));
410     password2 = xstrdup(gtk_entry_get_text(GTK_ENTRY(users_details_password2)));
411     if(!*name) {
412       /* No username.  Really we wanted to desensitize the Apply button when
413        * there's no userame but there doesn't seem to be a signal to detect
414        * changes to the entry text.  Consequently we have error messages
415        * instead.  */
416       popup_submsg(users_window, GTK_MESSAGE_ERROR, "Must enter a username");
417       return;
418     }
419     if(strcmp(password, password2)) {
420       popup_submsg(users_window, GTK_MESSAGE_ERROR, "Passwords do not match");
421       return;
422     }
423     if(*email && !strchr(email, '@')) {
424       /* The server will complain about this but we can give a better error
425        * message this way */
426       popup_submsg(users_window, GTK_MESSAGE_ERROR, "Invalid email address");
427       return;
428     }
429     cbd = xmalloc(sizeof *cbd);
430     cbd->onerror = users_adduser_failed;
431     cbd->u.edituser.user = name;
432     cbd->u.edituser.email = email;
433     disorder_eclient_adduser(client, users_adduser_completed,
434                              name,
435                              password,
436                              rights_string(users_get_rights()),
437                              cbd);
438     /* We switch to no-op mode while creating the user */
439     mode(NONE);
440     break;
441   case MODE_EDIT:
442     /* Ugh, can we de-dupe with above? */
443     email = xstrdup(gtk_entry_get_text(GTK_ENTRY(users_details_email)));
444     password = xstrdup(gtk_entry_get_text(GTK_ENTRY(users_details_password)));
445     password2 = xstrdup(gtk_entry_get_text(GTK_ENTRY(users_details_password2)));
446     if(strcmp(password, password2)) {
447       popup_submsg(users_window, GTK_MESSAGE_ERROR, "Passwords do not match");
448       return;
449     }
450     if(*email && !strchr(email, '@')) {
451       popup_submsg(users_window, GTK_MESSAGE_ERROR, "Invalid email address");
452       return;
453     }
454     cbd = xmalloc(sizeof *cbd);
455     cbd->onerror = users_op_failed;
456     disorder_eclient_edituser(client, NULL, users_selected,
457                               "email", email, cbd);
458     disorder_eclient_edituser(client, NULL, users_selected,
459                               "password", password, cbd);
460     disorder_eclient_edituser(client, NULL, users_selected,
461                               "rights", rights_string(users_get_rights()), cbd);
462     /* We remain in edit mode */
463     break;
464   }
465 }
466
467 /** @brief Called when a user has been deleted */
468 static void users_deleted(void *v) {
469   const struct callbackdata *const cbd = v;
470   GtkTreeIter iter[1];
471
472   if(!users_find_user(cbd->u.user, iter))    /* Find the user... */
473     gtk_list_store_remove(users_list, iter); /* ...and remove them */
474 }
475
476 /** @brief Called when the 'Delete' button is pressed */
477 static void users_delete(GtkButton attribute((unused)) *button,
478                          gpointer attribute((unused)) userdata) {
479   GtkWidget *yesno;
480   int res;
481   struct callbackdata *cbd;
482
483   if(!users_selected)
484     return;
485   yesno = gtk_message_dialog_new(GTK_WINDOW(users_window),
486                                  GTK_DIALOG_MODAL,
487                                  GTK_MESSAGE_QUESTION,
488                                  GTK_BUTTONS_YES_NO,
489                                  "Do you really want to delete user %s?"
490                                  " This action cannot be undone.",
491                                  users_selected);
492   res = gtk_dialog_run(GTK_DIALOG(yesno));
493   gtk_widget_destroy(yesno);
494   if(res == GTK_RESPONSE_YES) {
495     cbd = xmalloc(sizeof *cbd);
496     cbd->onerror = users_op_failed;
497     cbd->u.user = users_selected;
498     disorder_eclient_deluser(client, users_deleted, cbd->u.user, cbd);
499   }
500 }
501
502 static void users_got_email(void attribute((unused)) *v, const char *value) {
503   users_email = value;
504 }
505
506 static void users_got_rights(void attribute((unused)) *v, const char *value) {
507   users_rights = value;
508 }
509
510 static void users_got_password(void attribute((unused)) *v, const char *value) {
511   users_password = value;
512   users_makedetails(users_selected,
513                     users_email,
514                     users_rights,
515                     users_password,
516                     DETAIL_VISIBLE,
517                     DETAIL_EDITABLE|DETAIL_VISIBLE);
518   mode(EDIT);
519 }
520
521 /** @brief Called when the selection MIGHT have changed */
522 static void users_selection_changed(GtkTreeSelection attribute((unused)) *treeselection,
523                                     gpointer attribute((unused)) user_data) {
524   GtkTreeIter iter;
525   char *gselected, *selected;
526   
527   /* Identify the current selection */
528   if(gtk_tree_selection_get_selected(users_selection, 0, &iter)) {
529     gtk_tree_model_get(GTK_TREE_MODEL(users_list), &iter,
530                        0, &gselected, -1);
531     selected = xstrdup(gselected);
532     g_free(gselected);
533   } else
534     selected = 0;
535   /* Eliminate no-change cases */
536   if(!selected && !users_selected)
537     return;
538   if(selected && users_selected && !strcmp(selected, users_selected))
539     return;
540   /* There's been a change; junk the old data and fetch new data in
541    * background. */
542   users_selected = selected;
543   users_makedetails("", "", "", "",
544                     DETAIL_VISIBLE,
545                     DETAIL_VISIBLE);
546   if(users_selected) {
547     disorder_eclient_userinfo(client, users_got_email, users_selected,
548                               "email", 0);
549     disorder_eclient_userinfo(client, users_got_rights, users_selected,
550                               "rights", 0);
551     disorder_eclient_userinfo(client, users_got_password, users_selected,
552                               "password", 0);
553   }
554   mode(NONE);                           /* not editing *yet* */
555 }
556
557 /** @brief Table of buttons below the user list */
558 static struct button users_buttons[] = {
559   {
560     "Add user",
561     users_add,
562     "Create a new user",
563     0
564   },
565   {
566     "Delete user",
567     users_delete,
568     "Delete a user",
569     0
570   },
571 };
572 #define NUSERS_BUTTONS (sizeof users_buttons / sizeof *users_buttons)
573
574 /** @brief Pop up the user management window */
575 void manage_users(void) {
576   GtkWidget *tree, *buttons, *hbox, *vbox, *vbox2;
577   GtkCellRenderer *cr;
578   GtkTreeViewColumn *col;
579   
580   /* If the window already exists just raise it */
581   if(users_window) {
582     gtk_window_present(GTK_WINDOW(users_window));
583     return;
584   }
585   /* Create the window */
586   users_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
587   gtk_widget_set_style(users_window, tool_style);
588   g_signal_connect(users_window, "destroy",
589                    G_CALLBACK(gtk_widget_destroyed), &users_window);
590   gtk_window_set_title(GTK_WINDOW(users_window), "User Management");
591   /* default size is too small */
592   gtk_window_set_default_size(GTK_WINDOW(users_window), 240, 240);
593
594   /* Create the list of users and populate it asynchronously */
595   users_list = gtk_list_store_new(1, G_TYPE_STRING);
596   disorder_eclient_users(client, users_got_list, 0);
597   /* Create the view */
598   tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(users_list));
599   /* ...and the renderers for it */
600   cr = gtk_cell_renderer_text_new();
601   col = gtk_tree_view_column_new_with_attributes("Username",
602                                                  cr,
603                                                  "text", 0,
604                                                  NULL);
605   gtk_tree_view_append_column(GTK_TREE_VIEW(tree), col);
606   /* Get the selection for the view; set its mode; arrange for a callback when
607    * it changes */
608   users_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
609   gtk_tree_selection_set_mode(users_selection, GTK_SELECTION_BROWSE);
610   g_signal_connect(users_selection, "changed",
611                    G_CALLBACK(users_selection_changed), NULL);
612
613   /* Create the control buttons */
614   buttons = create_buttons_box(users_buttons,
615                                NUSERS_BUTTONS,
616                                gtk_hbox_new(FALSE, 1));
617   users_delete_button = users_buttons[1].widget;
618
619   /* Buttons live below the list */
620   vbox = gtk_vbox_new(FALSE, 2);
621   gtk_box_pack_start(GTK_BOX(vbox), tree, TRUE/*expand*/, TRUE/*fill*/, 0);
622   gtk_box_pack_start(GTK_BOX(vbox), buttons, FALSE/*expand*/, FALSE, 0);
623
624   /* Create an empty user details table, and put an apply button below it */
625   users_apply_button = gtk_button_new_from_stock(GTK_STOCK_APPLY);
626   users_makedetails("", "", "", "",
627                     DETAIL_VISIBLE,
628                     DETAIL_VISIBLE);
629   /* TODO apply button is much too wide right now... */
630   g_signal_connect(users_apply_button, "clicked",
631                    G_CALLBACK(users_apply), NULL);
632   vbox2 = gtk_vbox_new(FALSE, 2);
633   gtk_box_pack_start(GTK_BOX(vbox2), users_details_table,
634                      TRUE/*expand*/, TRUE/*fill*/, 0);
635   gtk_box_pack_start(GTK_BOX(vbox2), users_apply_button,
636                      FALSE/*expand*/, FALSE, 0);
637   
638   /* User details are to the right of the list */
639   hbox = gtk_hbox_new(FALSE, 2);
640   gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE/*expand*/, FALSE, 0);
641   gtk_box_pack_start(GTK_BOX(hbox), vbox2, TRUE/*expand*/, TRUE/*fill*/, 0);
642   gtk_container_add(GTK_CONTAINER(users_window), hbox);
643 }
644
645 /*
646 Local Variables:
647 c-basic-offset:2
648 comment-column:40
649 fill-column:79
650 indent-tabs-mode:nil
651 End:
652 */