chiark / gitweb /
friendlier login details saving
authorRichard Kettlewell <rjk@greenend.org.uk>
Fri, 19 Oct 2007 19:58:38 +0000 (20:58 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Fri, 19 Oct 2007 19:58:38 +0000 (20:58 +0100)
disobedience/client.c
disobedience/disobedience.h
disobedience/login.c
disobedience/misc.c
disobedience/properties.c

index 8539221c11dc69440c21479a9d06276848dc34c1..12dfcb214e58693e17b8da206fdab75d5798a015 100644 (file)
@@ -154,7 +154,7 @@ static void gtkclient_report(void attribute((unused)) *u,
 void popup_protocol_error(int attribute((unused)) code,
                           const char *msg) {
   gtk_label_set_text(GTK_LABEL(report_label), msg);
-  popup_error(msg);
+  popup_msg(GTK_MESSAGE_ERROR, msg);
 }
 
 /** @brief Table of eclient callbacks */
index 37bdda41cd7ebd96db19053d4ddf5f0e8fbd0aa8..70eee1063186dc795643789c7623d014c2892899 100644 (file)
@@ -137,10 +137,10 @@ GdkPixbuf *find_image(const char *name);
 /* Get the pixbuf for an image.  Returns a null pointer if it cannot be
  * found. */
 
-void popup_error(const char *msg);
-/* Pop up an error message */
+void popup_msg(GtkMessageType mt, const char *msg);
+/* Pop up a message */
 
-void fpopup_error(const char *fmt, ...);
+void fpopup_msg(GtkMessageType mt, const char *fmt, ...);
 
 struct progress_window *progress_window_new(const char *title);
 /* Pop up a progress window */
index 729597bac7658cee22d14ffa88b9da481007ca0c..8a00a597265bdb50260a06fac6bc344d61e42164 100644 (file)
@@ -26,6 +26,7 @@
 #include "filepart.h"
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <unistd.h>
 
 /** @brief One field in the login window */
 struct login_window_item {
@@ -87,9 +88,23 @@ static void update_config(void) {
   size_t n;
 
   for(n = 0; n < NLWIS; ++n)
-    lwis[n].set(gtk_entry_get_text(GTK_ENTRY(lwi_entry[n])));
+    lwis[n].set(xstrdup(gtk_entry_get_text(GTK_ENTRY(lwi_entry[n]))));
 }
 
+#if 0
+static int modified_config(void) {
+  size_t n;
+
+  for(n = 0; n < NLWIS; ++n) {
+    const char *entered = gtk_entry_get_text(GTK_ENTRY(lwi_entry[n]));
+    const char *current = lwis[n].get();
+    if(strcmp(entered, current))
+      return 1;
+  }
+  return 0;
+}
+#endif
+
 static void login_ok(GtkButton attribute((unused)) *button,
                      gpointer attribute((unused)) userdata) {
   update_config();
@@ -100,15 +115,34 @@ static void login_save(GtkButton attribute((unused)) *button,
                        gpointer attribute((unused)) userdata) {
   char *path = config_userconf(0, 0), *tmp;
   FILE *fp;
+  GtkWidget *yorn = 0;
 
   update_config();
+  /* See if the file already exists */
+  if(access(path, F_OK) == 0) {
+    yorn = gtk_message_dialog_new
+      (GTK_WINDOW(login_window),
+       GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
+       GTK_MESSAGE_QUESTION,
+       GTK_BUTTONS_NONE,
+       "File %s already exists", path);
+    gtk_dialog_add_buttons(GTK_DIALOG(yorn),
+                           "Overwrite", GTK_RESPONSE_ACCEPT,
+                           "Cancel", GTK_RESPONSE_REJECT,
+                           (char *)0);
+    if(gtk_dialog_run(GTK_DIALOG(yorn)) != GTK_RESPONSE_ACCEPT)
+      goto done;
+    gtk_widget_destroy(yorn);
+    yorn = 0;
+  }
   byte_xasprintf(&tmp, "%s.tmp", path);
   /* Make sure the directory exists; don't care if it already exists. */
   mkdir(d_dirname(tmp), 02700);
   /* Write out the file */
   if(!(fp = fopen(tmp, "w"))) {
-    fpopup_error("error opening %s: %s", tmp, strerror(errno));
-    return;
+    fpopup_msg(GTK_MESSAGE_ERROR, "error opening %s: %s",
+               tmp, strerror(errno));
+    goto done;
   }
   if(fprintf(fp, "username %s\n"
              "password %s\n"
@@ -117,19 +151,30 @@ static void login_save(GtkButton attribute((unused)) *button,
              quoteutf8(config->password),
              quoteutf8(config->connect.s[0]),
              quoteutf8(config->connect.s[1])) < 0) {
-    fpopup_error("error writing to %s: %s", tmp, strerror(errno));
+    fpopup_msg(GTK_MESSAGE_ERROR, "error writing to %s: %s",
+               tmp, strerror(errno));
     fclose(fp);
-    return;
+    goto done;
   }
   if(fclose(fp) < 0) {
-    fpopup_error("error closing %s: %s", tmp, strerror(errno));
-    return;
+    fpopup_msg(GTK_MESSAGE_ERROR, "error closing %s: %s",
+               tmp, strerror(errno));
+    goto done;
   }
   /* Rename into place */
   if(rename(tmp, path) < 0) {
-    fpopup_error("error renaming %s: %s", tmp, strerror(errno));
-    return;
+    fpopup_msg(GTK_MESSAGE_ERROR, "error renaming %s: %s",
+               tmp, strerror(errno));
+    goto done;
   }
+  fpopup_msg(GTK_MESSAGE_INFO, "Saved login configuration to %s", path);
+  gtk_widget_destroy(login_window);
+done:
+  if(yorn)
+    gtk_widget_destroy(yorn);
+  /* OS X WM likes to hide it */
+  if(login_window)
+    gtk_window_present(GTK_WINDOW(login_window));
 }
 
 static void login_cancel(GtkButton attribute((unused)) *button,
@@ -140,7 +185,7 @@ static void login_cancel(GtkButton attribute((unused)) *button,
 /* Buttons that appear at the bottom of the window */
 static const struct button buttons[] = {
   {
-    GTK_STOCK_OK,
+    "Login",
     login_ok,
     "Login with these settings",
   },
index 1cb6d5a0439a839ff4b2dd1f937ffd3b9d8197bb..c2686543eff851c969ec713179f8e58b1d1e1325 100644 (file)
@@ -93,13 +93,13 @@ GdkPixbuf *find_image(const char *name) {
   return pb;
 }
 
-/** @brief Pop up an error message */
-void popup_error(const char *msg) {
+/** @brief Pop up a message */
+void popup_msg(GtkMessageType mt, const char *msg) {
   GtkWidget *w;
 
   w = gtk_message_dialog_new(GTK_WINDOW(toplevel),
                              GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
-                             GTK_MESSAGE_ERROR,
+                             mt,
                              GTK_BUTTONS_CLOSE,
                              "%s", msg);
   gtk_dialog_run(GTK_DIALOG(w));
@@ -107,14 +107,14 @@ void popup_error(const char *msg) {
 }
 
 /** @brief Pop up an error message */
-void fpopup_error(const char *fmt, ...) {
+void fpopup_msg(GtkMessageType mt, const char *fmt, ...) {
   va_list ap;
   char *msg;
 
   va_start(ap, fmt);
   byte_xvasprintf(&msg, fmt, ap);
   va_end(ap);
-  popup_error(msg);
+  popup_msg(mt, msg);
 }
 
 /** @brief Create a button with an icon in it
index aff768eb5290fb19541593a5b165c5b492403854..d306b56cdab5fbce9b261f78e6c10cbf0c99e61c 100644 (file)
@@ -185,7 +185,7 @@ void properties(int ntracks, const char **tracks) {
   }
   assert(properties_table == 0);
   if(ntracks > INT_MAX / NPREFS) {
-    popup_error("Too many tracks selected");
+    popup_msg(GTK_MESSAGE_ERROR, "Too many tracks selected");
     return;
   }
   /* Create a new properties window */