From ffc4dbaf1ee655263fd979d6c554ead000bef8e1 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sat, 12 Apr 2008 17:13:07 +0100 Subject: [PATCH] Disobedience user management window (nonfunctional) Organization: Straylight/Edgeware From: Richard Kettlewell --- disobedience/Makefile.am | 2 +- disobedience/disobedience.h | 7 ++ disobedience/menu.c | 15 +++++ disobedience/misc.c | 21 ++++-- disobedience/users.c | 129 ++++++++++++++++++++++++++++++++++++ lib/eclient.c | 14 ++++ lib/eclient.h | 4 ++ 7 files changed, 185 insertions(+), 7 deletions(-) create mode 100644 disobedience/users.c diff --git a/disobedience/Makefile.am b/disobedience/Makefile.am index 031d68d..0b1433b 100644 --- a/disobedience/Makefile.am +++ b/disobedience/Makefile.am @@ -28,7 +28,7 @@ PNGS:=$(shell export LC_COLLATE=C;echo ${top_srcdir}/images/*.png) disobedience_SOURCES=disobedience.h disobedience.c client.c queue.c \ choose.c misc.c control.c properties.c menu.c \ log.c progress.c login.c rtp.c help.c \ - ../lib/memgc.c settings.c + ../lib/memgc.c settings.c users.c disobedience_LDADD=../lib/libdisorder.a $(LIBPCRE) $(LIBGC) $(LIBGCRYPT) \ $(LIBASOUND) $(COREAUDIO) $(LIBDB) disobedience_LDFLAGS=$(GTK_LIBS) diff --git a/disobedience/disobedience.h b/disobedience/disobedience.h index a9c801c..8190565 100644 --- a/disobedience/disobedience.h +++ b/disobedience/disobedience.h @@ -159,6 +159,9 @@ GtkWidget *iconbutton(const char *path, const char *tip); GtkWidget *create_buttons(const struct button *buttons, size_t nbuttons); +GtkWidget *create_buttons_box(const struct button *buttons, + size_t nbuttons, + GtkWidget *box); void register_monitor(monitor_callback *callback, void *u, @@ -242,6 +245,10 @@ void login_box(void); GtkWidget *login_window; +/* User management */ + +void manage_users(void); + /* Help */ void popup_help(void); diff --git a/disobedience/menu.c b/disobedience/menu.c index f93e2f7..ab32f36 100644 --- a/disobedience/menu.c +++ b/disobedience/menu.c @@ -94,6 +94,13 @@ static void login(gpointer attribute((unused)) callback_data, login_box(); } +/** @brief Called when the login option is activated */ +static void users(gpointer attribute((unused)) callback_data, + guint attribute((unused)) callback_action, + GtkWidget attribute((unused)) *menu_item) { + manage_users(); +} + #if 0 /** @brief Called when the settings option is activated */ static void settings(gpointer attribute((unused)) callback_data, @@ -228,6 +235,14 @@ GtkWidget *menubar(GtkWidget *w) { 0, /* item_type */ 0 /* extra_data */ }, + { + (char *)"/File/Users", /* path */ + 0, /* accelerator */ + users, /* callback */ + 0, /* callback_action */ + 0, /* item_type */ + 0 /* extra_data */ + }, #if 0 { (char *)"/File/Settings", /* path */ diff --git a/disobedience/misc.c b/disobedience/misc.c index db1f6ab..cc23814 100644 --- a/disobedience/misc.c +++ b/disobedience/misc.c @@ -161,23 +161,32 @@ GtkWidget *iconbutton(const char *path, const char *tip) { return button; } -/** @brief Create buttons and pack them into an hbox */ -GtkWidget *create_buttons(const struct button *buttons, - size_t nbuttons) { +/** @brief Create buttons and pack them into a box, which is returned */ +GtkWidget *create_buttons_box(const struct button *buttons, + size_t nbuttons, + GtkWidget *box) { size_t n; - GtkWidget *const hbox = gtk_hbox_new(FALSE, 1); for(n = 0; n < nbuttons; ++n) { GtkWidget *const button = gtk_button_new_from_stock(buttons[n].stock); gtk_widget_set_style(button, tool_style); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(buttons[n].clicked), 0); - gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 1); + gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 1); gtk_tooltips_set_tip(tips, button, buttons[n].tip, ""); } - return hbox; + return box; +} + +/** @brief Create buttons and pack them into an hbox */ +GtkWidget *create_buttons(const struct button *buttons, + size_t nbuttons) { + return create_buttons_box(buttons, nbuttons, + gtk_hbox_new(FALSE, 1)); } + + /* Local Variables: c-basic-offset:2 diff --git a/disobedience/users.c b/disobedience/users.c new file mode 100644 index 0000000..a262460 --- /dev/null +++ b/disobedience/users.c @@ -0,0 +1,129 @@ +/* + * This file is part of DisOrder + * Copyright (C) 2008 Richard Kettlewell + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ +/** @file disobedience/users.c + * @brief User management for Disobedience + */ + +#include "disobedience.h" + +static GtkWidget *users_window; +static GtkListStore *users_list; + +static int usercmp(const void *a, const void *b) { + return strcmp(*(char **)a, *(char **)b); +} + +static void users_got_list(void attribute((unused)) *v, int nvec, char **vec) { + int n; + GtkTreeIter iter; + + /* Present users in alphabetical order */ + qsort(vec, nvec, sizeof (char *), usercmp); + /* Set the list contents */ + gtk_list_store_clear(users_list); + for(n = 0; n < nvec; ++n) + gtk_list_store_insert_with_values(users_list, &iter, n/*position*/, + 0, vec[n], /* column 0 */ + -1); /* no more columns */ + /* Only show the window when the list is populated */ + gtk_widget_show_all(users_window); +} + +static void users_add(GtkButton attribute((unused)) *button, + gpointer attribute((unused)) userdata) { +} + +static void users_delete(GtkButton attribute((unused)) *button, + gpointer attribute((unused)) userdata) { +} + +static void users_edit(GtkButton attribute((unused)) *button, + gpointer attribute((unused)) userdata) { +} + +static const struct button users_buttons[] = { + { + "Add user", + users_add, + "Create a new user" + }, + { + "Edit user", + users_edit, + "Edit a user" + }, + { + "Delete user", + users_delete, + "Delete a user" + }, +}; +#define NUSERS_BUTTONS (sizeof users_buttons / sizeof *users_buttons) + +void manage_users(void) { + GtkWidget *tree, *buttons, *hbox; + GtkCellRenderer *cr; + GtkTreeViewColumn *col; + + /* If the window already exists just raise it */ + if(users_window) { + gtk_window_present(GTK_WINDOW(users_window)); + return; + } + /* Create the window */ + users_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_widget_set_style(users_window, tool_style); + g_signal_connect(users_window, "destroy", + G_CALLBACK(gtk_widget_destroyed), &users_window); + gtk_window_set_title(GTK_WINDOW(users_window), "User Management"); + /* default size is too small */ + gtk_window_set_default_size(GTK_WINDOW(users_window), 240, 240); + + /* Create the list of users and populate it asynchronously */ + users_list = gtk_list_store_new(1, G_TYPE_STRING); + disorder_eclient_users(client, users_got_list, 0); + /* Create the view */ + tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(users_list)); + /* ...and the renderers for it */ + cr = gtk_cell_renderer_text_new(); + col = gtk_tree_view_column_new_with_attributes("Username", + cr, + "text", 0, + NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW(tree), col); + /* Create the control buttons */ + buttons = create_buttons_box(users_buttons, + NUSERS_BUTTONS, + gtk_vbox_new(FALSE, 1)); + /* Put it all together in an hbox */ + hbox = gtk_hbox_new(FALSE, 2); + gtk_box_pack_start(GTK_BOX(hbox), tree, TRUE/*expand*/, TRUE/*fill*/, 0); + gtk_box_pack_start(GTK_BOX(hbox), buttons, FALSE, FALSE, 0); + gtk_container_add(GTK_CONTAINER(users_window), hbox); +} + +/* +Local Variables: +c-basic-offset:2 +comment-column:40 +fill-column:79 +indent-tabs-mode:nil +End: +*/ diff --git a/lib/eclient.c b/lib/eclient.c index 98f60a8..7023187 100644 --- a/lib/eclient.c +++ b/lib/eclient.c @@ -1263,6 +1263,20 @@ int disorder_eclient_rtp_address(disorder_eclient *c, "rtp-address", (char *)0); } +/** @brief Get the list of users + * @param c Client + * @param completed Called with list of users + * @param v Passed to @p completed + * + * The user list is not sorted in any particular order. + */ +int disorder_eclient_users(disorder_eclient *c, + disorder_eclient_list_response *completed, + void *v) { + return simple(c, list_response_opcallback, (void (*)())completed, v, + "users", (char *)0); +} + /* Log clients ***************************************************************/ /** @brief Monitor the server log diff --git a/lib/eclient.h b/lib/eclient.h index 37ec9cb..176abaf 100644 --- a/lib/eclient.h +++ b/lib/eclient.h @@ -326,6 +326,10 @@ int disorder_eclient_rtp_address(disorder_eclient *c, disorder_eclient_list_response *completed, void *v); +int disorder_eclient_users(disorder_eclient *c, + disorder_eclient_list_response *completed, + void *v); + #endif /* -- [mdw]