chiark / gitweb /
Switch Disobedience reset (i.e. fresh login) notification over to
[disorder] / disobedience / menu.c
index b80537e947eeae848d6358554107e954ca3e9bc3..b52190efcb3391306282c7f9b573ddf2b24b1e26 100644 (file)
@@ -30,7 +30,9 @@ static GtkWidget *properties_widget;
 /** @brief Main menu widgets */
 GtkItemFactory *mainmenufactory;
 
-static void about_popup_got_version(void *v, const char *value);
+static void about_popup_got_version(void *v,
+                                    const char *error,
+                                    const char *value);
 
 /** @brief Called when the quit option is activated
  *
@@ -156,12 +158,15 @@ static void manual_popup(gpointer attribute((unused)) callback_data,
 
 /** @brief Called when version arrives, displays about... popup */
 static void about_popup_got_version(void attribute((unused)) *v,
+                                    const char attribute((unused)) *error,
                                     const char *value) {
   GtkWidget *w;
   char *server_version_string;
   char *short_version_string;
   GtkWidget *hbox, *vbox, *title;
 
+  if(!value)
+    value = "[error]";
   byte_xasprintf(&server_version_string, "Server version %s", value);
   byte_xasprintf(&short_version_string, "Disobedience %s",
                  disorder_short_version_string);
@@ -224,16 +229,25 @@ void users_set_sensitive(int sensitive) {
 }
 
 /** @brief Called with current user's rights string */
-static void menu_got_rights(void attribute((unused)) *v, const char *value) {
+static void menu_got_rights(void attribute((unused)) *v,
+                            const char *error,
+                            const char *value) {
   rights_type r;
 
-  if(parse_rights(value, &r, 0))
+  if(error) {
+    popup_protocol_error(0, error);
     r = 0;
+  } else {
+    if(parse_rights(value, &r, 0))
+      r = 0;
+  }
   users_set_sensitive(!!(r & RIGHT_ADMIN));
 }
 
-/** @brief Called when we need to reset state */
-static void menu_reset(void) {
+/** @brief Called after a fresh login */
+static void menu_logged_in(const char attribute((unused)) *event,
+                           void attribute((unused)) *eventdata,
+                           void attribute((unused)) *callbackdata) {
   users_set_sensitive(0);               /* until we know better */
   disorder_eclient_userinfo(client, menu_got_rights, config->username, "rights",
                             0);
@@ -407,8 +421,8 @@ GtkWidget *menubar(GtkWidget *w) {
   assert(selectall_widget != 0);
   assert(selectnone_widget != 0);
   assert(properties_widget != 0);
-  register_reset(menu_reset);
-  menu_reset();
+  event_register("logged-in", menu_logged_in, 0);
+  menu_logged_in(0, 0, 0);
   m = gtk_item_factory_get_widget(mainmenufactory,
                                   "<GdisorderMain>");
   set_tool_colors(m);