chiark / gitweb /
More comments.
[disorder] / disobedience / users.c
index bb099f2d7ac27ab39ea7e57f2941a282809f5bc4..1d2a169c3910c7134a85df084b128cb81e5e1591 100644 (file)
@@ -2,20 +2,18 @@
  * This file is part of DisOrder
  * Copyright (C) 2008 Richard Kettlewell
  *
- * This program is free software; you can redistribute it and/or modify
+ * 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
+ * the Free Software Foundation, either version 3 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.
- *
+ * 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
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 /** @file disobedience/users.c
  * @brief User management for Disobedience
@@ -35,7 +33,6 @@
  *
  * TODO:
  * - enter new username in the GtkTreeView
- * - escape and enter keys should work
  * - should have a cancel or close button, consistent with properties and login
  */
 
@@ -116,13 +113,13 @@ static int users_find_user(const char *user,
  * If users_deferred_select is set then that user is selected.
  */
 static void users_got_list(void attribute((unused)) *v,
-                           const char *error,
+                           const char *err,
                            int nvec, char **vec) {
   int n;
   GtkTreeIter iter;
 
-  if(error) {
-    popup_protocol_error(0, error);
+  if(err) {
+    popup_protocol_error(0, err);
     return;
   }
   /* Present users in alphabetical order */
@@ -351,6 +348,8 @@ static void users_details_destroyed(GtkWidget attribute((unused)) *widget,
  * @param email Email address
  * @param rights User rights string
  * @param password Password
+ * @param nameflags Visibility/editability for username
+ * @param flags Visibility/editability for other fields
  */
 static void users_makedetails(const char *name,
                               const char *email,
@@ -436,16 +435,16 @@ static rights_type users_get_rights(void) {
 
 /** @brief Called when a user setting has been edited */
 static void users_edituser_completed(void attribute((unused)) *v,
-                                     const char *error) {
-  if(error)
-    popup_submsg(users_window, GTK_MESSAGE_ERROR, error);
+                                     const char *err) {
+  if(err)
+    popup_submsg(users_window, GTK_MESSAGE_ERROR, err);
 }
 
 /** @brief Called when a new user has been created */
 static void users_adduser_completed(void *v,
-                                    const char *error) {
-  if(error) {
-    popup_submsg(users_window, GTK_MESSAGE_ERROR, error);
+                                    const char *err) {
+  if(err) {
+    popup_submsg(users_window, GTK_MESSAGE_ERROR, err);
     mode(ADD);                          /* Let the user try again */
   } else {
     const struct kvp *const kvp = v;
@@ -534,9 +533,9 @@ static void users_apply(GtkButton attribute((unused)) *button,
 
 /** @brief Called when a user has been deleted */
 static void users_delete_completed(void *v,
-                                   const char *error) {
-  if(error)
-    popup_submsg(users_window, GTK_MESSAGE_ERROR, error);
+                                   const char *err) {
+  if(err)
+    popup_submsg(users_window, GTK_MESSAGE_ERROR, err);
   else {
     const struct kvp *const kvp = v;
     const char *const user = kvp_get(kvp, "user");
@@ -572,26 +571,26 @@ static void users_delete(GtkButton attribute((unused)) *button,
 }
 
 static void users_got_email(void attribute((unused)) *v,
-                            const char *error,
+                            const char *err,
                             const char *value) {
-  if(error)
-    popup_protocol_error(0, error);
+  if(err)
+    popup_protocol_error(0, err);
   users_email = value;
 }
 
 static void users_got_rights(void attribute((unused)) *v,
-                             const char *error,
+                             const char *err,
                              const char *value) {
-  if(error)
-    popup_protocol_error(0, error);
+  if(err)
+    popup_protocol_error(0, err);
   users_rights = value;
 }
 
 static void users_got_password(void attribute((unused)) *v,
-                               const char *error,
+                               const char *err,
                                const char *value) {
-  if(error)
-    popup_protocol_error(0, error);
+  if(err)
+    popup_protocol_error(0, err);
   /* TODO if an error occurred gathering user info, we should react in some
    * different way */
   users_password = value;
@@ -645,6 +644,8 @@ static GtkWidget *users_make_reporter() {
     users_reporter = gtk_label_new("");
     gtk_label_set_ellipsize(GTK_LABEL(users_reporter), PANGO_ELLIPSIZE_END);
     gtk_misc_set_alignment(GTK_MISC(users_reporter), 0.99, 0);
+    g_signal_connect(users_reporter, "destroy",
+                     G_CALLBACK(gtk_widget_destroyed), &users_reporter);
   }
   return users_reporter;
 }
@@ -670,6 +671,21 @@ static struct button users_buttons[] = {
 };
 #define NUSERS_BUTTONS (sizeof users_buttons / sizeof *users_buttons)
 
+/** @brief Keypress handler */
+static gboolean users_keypress(GtkWidget attribute((unused)) *widget,
+                               GdkEventKey *event,
+                               gpointer attribute((unused)) user_data) {
+  if(event->state)
+    return FALSE;
+  switch(event->keyval) {
+  case GDK_Escape:
+    gtk_widget_destroy(users_window);
+    return TRUE;
+  default:
+    return FALSE;
+  }
+}
+
 /** @brief Pop up the user management window */
 void manage_users(void) {
   GtkWidget *tree, *buttons, *hbox, *hbox2, *vbox, *vbox2;
@@ -681,12 +697,18 @@ void manage_users(void) {
     gtk_window_present(GTK_WINDOW(users_window));
     return;
   }
+  /* Destroy old widgets */
+  if(users_reporter)
+    gtk_widget_destroy(users_reporter);
   /* 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");
+  /* Keyboard shortcuts */
+  g_signal_connect(users_window, "key-press-event",
+                   G_CALLBACK(users_keypress), 0);
   /* default size is too small */
   gtk_window_set_default_size(GTK_WINDOW(users_window), 240, 240);