chiark / gitweb /
Merge from Disobedience branch
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 13 Jul 2008 16:54:07 +0000 (17:54 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 13 Jul 2008 16:54:07 +0000 (17:54 +0100)
disobedience/choose.c
disobedience/login.c
disobedience/queue-menu.c
disobedience/queue.c
doc/disobedience.1.in

index 8d8ac08601c4dd5fc52ffc76ab156783b4311b8b..4cb6f7c500e62c87e677b2f614692f4904094c15 100644 (file)
@@ -505,7 +505,7 @@ static void choose_refill(const char attribute((unused)) *event,
  */
 static gboolean choose_key_event(GtkWidget attribute((unused)) *widget,
                                  GdkEventKey *event,
-                                 gpointer attribute((unused)) user_data) {
+                                 gpointer user_data) {
   /*fprintf(stderr, "choose_key_event type=%d state=%#x keyval=%#x\n",
           event->type, event->state, event->keyval);*/
   switch(event->keyval) {
@@ -535,6 +535,7 @@ static gboolean choose_key_event(GtkWidget attribute((unused)) *widget,
     }
     break;
   }
+  /* Anything not handled we redirected to the search entry field */
   gtk_widget_event(user_data, (GdkEvent *)event);
   return TRUE;                          /* Handled it */
 }
index 73aaada133dc67302b98dab82d8dee775d5cc6ae..9dbbeac21752a8e6df4016ebd7d9ec8f0191b4bb 100644 (file)
@@ -54,6 +54,7 @@ struct login_window_item {
   /** @brief Flags
    * 
    * - @ref LWI_HIDDEN - this is a password
+   * - @ref LWI_REMOTE - this is for remote connections
    */
   unsigned flags;
 
@@ -62,23 +63,43 @@ struct login_window_item {
 /** @brief This is a password */
 #define LWI_HIDDEN 0x0001
 
+/** @brief This is for remote connections */
+#define LWI_REMOTE 0x0002
+
 /** @brief Current login window */
 GtkWidget *login_window;
 
 /** @brief Set connection defaults */
 static void default_connect(void) {
-  if(!config->connect.n) {
-    config->connect.n = 2;
-    config->connect.s = xcalloc(2, sizeof (char *));
-    config->connect.s[0] = xstrdup("localhost");
-    config->connect.s[1] = xstrdup("9999"); /* whatever */
-  }
+  /* If a password is set assume we're good */
+  if(config->password)
+    return;
+  /* If we already have a host and/or port that's good too */
+  if(config->connect.n)
+    return;
+  /* If there's a suitable socket that's probably what we wanted */
+  const char *s = config_get_file("socket");
+  struct stat st;
+  if(s && *s && stat(s, &st) == 0 && S_ISSOCK(st.st_mode))
+    return;
+  /* TODO can we use some mdns thing to find a DisOrder server? */
 }
 
-static const char *get_hostname(void) { return config->connect.s[0]; }
-static const char *get_service(void) { return config->connect.s[1]; }
-static const char *get_username(void) { return config->username; }
-static const char *get_password(void) { return config->password ? config->password : ""; }
+static const char *get_hostname(void) {
+  return config->connect.n >= 2 ? config->connect.s[0] : "";
+}
+
+static const char *get_service(void) {
+  return config->connect.n >= 2 ? config->connect.s[1] : "";
+}
+
+static const char *get_username(void) {
+  return config->username;
+}
+
+static const char *get_password(void) {
+  return config->password ? config->password : "";
+}
 
 static void set_hostname(struct config *c, const char *s) {
   c->connect.s[0] = (char *)s;
@@ -98,24 +119,30 @@ static void set_password(struct config *c, const char *s) {
 
 /** @brief Table used to generate the form */
 static const struct login_window_item lwis[] = {
-  { "Hostname", get_hostname, set_hostname, 0 },
-  { "Service", get_service, set_service, 0 },
+  { "Hostname", get_hostname, set_hostname, LWI_REMOTE },
+  { "Service", get_service, set_service, LWI_REMOTE },
   { "User name", get_username, set_username, 0 },
   { "Password", get_password, set_password, LWI_HIDDEN },
 };
 #define NLWIS (sizeof lwis / sizeof *lwis)
 
+static GtkWidget *lwi_remote;
 static GtkWidget *lwi_entry[NLWIS];
 
 static void login_update_config(struct config *c) {
   size_t n;
+  const gboolean remote = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lwi_remote));
 
-  if(c->connect.n < 2) {
+  if(remote) {
     c->connect.n = 2;
     c->connect.s = xcalloc(2, sizeof (char *));
+  } else {
+    c->connect.n = 0;
+    c->connect.s = 0;
   }
   for(n = 0; n < NLWIS; ++n)
-    lwis[n].set(c, xstrdup(gtk_entry_get_text(GTK_ENTRY(lwi_entry[n]))));
+    if(remote || !(lwis[n].flags & LWI_REMOTE))
+      lwis[n].set(c, xstrdup(gtk_entry_get_text(GTK_ENTRY(lwi_entry[n]))));
 }
 
 /** @brief Save current login details */
@@ -132,13 +159,15 @@ static void login_save_config(void) {
                tmp, strerror(errno));
     goto done;
   }
-  if(fprintf(fp, "username %s\n"
-             "password %s\n"
-             "connect %s %s\n",
-             quoteutf8(config->username),
-             quoteutf8(config->password),
-             quoteutf8(config->connect.s[0]),
-             quoteutf8(config->connect.s[1])) < 0) {
+  int rc = fprintf(fp, "username %s\n"
+                   "password %s\n",
+                   quoteutf8(config->username),
+                   quoteutf8(config->password));
+  if(rc >= 0 && config->connect.n)
+    rc = fprintf(fp, "connect %s %s\n",
+                 quoteutf8(config->connect.s[0]),
+                 quoteutf8(config->connect.s[1]));
+  if(rc < 0) {
     fpopup_msg(GTK_MESSAGE_ERROR, "error writing to %s: %s",
                tmp, strerror(errno));
     fclose(fp);
@@ -165,6 +194,7 @@ static void login_ok(GtkButton attribute((unused)) *button,
   disorder_client *c;
   struct config *tmpconfig = xmalloc(sizeof *tmpconfig);
   
+  tmpconfig->home = xstrdup(pkgstatedir);
   /* Copy the new config into @ref config */
   login_update_config(tmpconfig);
   /* Attempt a login with the new details */
@@ -227,6 +257,19 @@ static struct button buttons[] = {
 
 #define NBUTTONS (int)(sizeof buttons / sizeof *buttons)
 
+/** @brief Called when the remote/local button is toggled (and initially)
+ *
+ * Sets the sensitivity of the host/port entries.
+ */
+static void lwi_remote_toggled(GtkToggleButton *togglebutton,
+                               gpointer attribute((unused)) user_data) {
+  const gboolean remote = gtk_toggle_button_get_active(togglebutton);
+  
+  for(unsigned n = 0; n < NLWIS; ++n)
+    if(lwis[n].flags & LWI_REMOTE)
+      gtk_widget_set_sensitive(lwi_entry[n], remote);
+}
+
 /** @brief Pop up a login box */
 void login_box(void) {
   GtkWidget *table, *label, *entry,  *buttonbox, *vbox;
@@ -245,15 +288,31 @@ void login_box(void) {
                   G_CALLBACK(gtk_widget_destroyed), &login_window);
   gtk_window_set_title(GTK_WINDOW(login_window), "Login Details");
   /* Construct the form */
-  table = gtk_table_new(NLWIS/*rows*/, 2/*columns*/, FALSE/*homogenous*/);
+  table = gtk_table_new(1 + NLWIS/*rows*/, 2/*columns*/, FALSE/*homogenous*/);
   gtk_widget_set_style(table, tool_style);
+  label = gtk_label_new("Remote");
+  gtk_widget_set_style(label, tool_style);
+  gtk_misc_set_alignment(GTK_MISC(label), 1/*right*/, 0/*bottom*/);
+  gtk_table_attach(GTK_TABLE(table), label,
+                   0, 1,                /* left/right_attach */
+                   0, 1,                /* top/bottom_attach */
+                   GTK_FILL, 0,         /* x/yoptions */
+                   1, 1);               /* x/ypadding */
+  lwi_remote = gtk_check_button_new();
+  gtk_widget_set_style(lwi_remote, tool_style);
+  gtk_table_attach(GTK_TABLE(table), lwi_remote,
+                   1, 2,                   /* left/right_attach */
+                   0, 1,                   /* top/bottom_attach */
+                   GTK_EXPAND|GTK_FILL, 0, /* x/yoptions */
+                   1, 1);                  /* x/ypadding */
+  g_signal_connect(lwi_remote, "toggled", G_CALLBACK(lwi_remote_toggled), 0);
   for(n = 0; n < NLWIS; ++n) {
     label = gtk_label_new(lwis[n].description);
     gtk_widget_set_style(label, tool_style);
     gtk_misc_set_alignment(GTK_MISC(label), 1/*right*/, 0/*bottom*/);
     gtk_table_attach(GTK_TABLE(table), label,
                     0, 1,              /* left/right_attach */
-                    n, n+1,            /* top/bottom_attach */
+                    n+1, n+2,          /* top/bottom_attach */
                     GTK_FILL, 0,       /* x/yoptions */
                     1, 1);             /* x/ypadding */
     entry = gtk_entry_new();
@@ -263,11 +322,15 @@ void login_box(void) {
     gtk_entry_set_text(GTK_ENTRY(entry), lwis[n].get());
     gtk_table_attach(GTK_TABLE(table), entry,
                     1, 2,              /* left/right_attach */
-                    n, n+1,            /* top/bottom_attach */
+                    n+1, n+2,          /* top/bottom_attach */
                     GTK_EXPAND|GTK_FILL, 0, /* x/yoptions */
                     1, 1);             /* x/ypadding */
     lwi_entry[n] = entry;
   }
+  /* Initial settings */
+  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lwi_remote),
+                               config->connect.n >= 2);
+  lwi_remote_toggled(GTK_TOGGLE_BUTTON(lwi_remote), 0);
   buttonbox = create_buttons(buttons, NBUTTONS);
   vbox = gtk_vbox_new(FALSE, 1);
   gtk_box_pack_start(GTK_BOX(vbox),
index 75ddeb6c2b664bfc795da7d101d62b9525724ba2..5775ee342d7b68704c1c0c7479e08e9f1d59cdb4 100644 (file)
@@ -127,7 +127,8 @@ static void ql_remove_activate_callback(GtkTreeModel *model,
                                         gpointer attribute((unused)) data) {
   struct queue_entry *q = ql_iter_to_q(model, iter);
 
-  disorder_eclient_remove(client, q->id, ql_remove_completed, q);
+  if(q != playing_track)
+    disorder_eclient_remove(client, q->id, ql_remove_completed, q);
 }
 
 void ql_remove_activate(GtkMenuItem attribute((unused)) *menuitem,
index d69b34dd3e444218af2ce0936c8b9b6b9886fe26..db013d33bad362721e76e307d0003169bf245af7 100644 (file)
@@ -326,6 +326,23 @@ static void queue_row_inserted(GtkTreeModel attribute((unused)) *treemodel,
   }
 }
 
+/** @brief Called when a key is pressed in the queue tree view */
+static gboolean queue_key_press(GtkWidget attribute((unused)) *widget,
+                                GdkEventKey *event,
+                                gpointer user_data) {
+  /*fprintf(stderr, "queue_key_press type=%d state=%#x keyval=%#x\n",
+          event->type, event->state, event->keyval);*/
+  switch(event->keyval) {
+  case GDK_BackSpace:
+  case GDK_Delete:
+    if(event->state)
+      break;                            /* Only take unmodified DEL/<-- */
+    ql_remove_activate(0, user_data);
+    return TRUE;                        /* Do not propagate */
+  }
+  return FALSE;                         /* Propagate */
+}
+
 GtkWidget *queue_widget(void) {
   GtkWidget *const w = init_queuelike(&ql_queue);
 
@@ -337,6 +354,9 @@ GtkWidget *queue_widget(void) {
   g_signal_connect(ql_queue.store,
                    "row-deleted",
                    G_CALLBACK(queue_row_deleted), &ql_queue);
+  /* Catch keypresses */
+  g_signal_connect(ql_queue.view, "key-press-event",
+                   G_CALLBACK(queue_key_press), &ql_queue);
   return w;
 }
 
index a59c7d9b14a1f46fc6c91119bdaec8c8d1a50de5..2d9beb944750b8b0a8a75d696eb4da60da355b68 100644 (file)
@@ -226,7 +226,14 @@ Select all tracks.
 .SS "Login Details Window"
 The login details window allows you to edit the connection details and
 authorization information used by Disobedience.
-It has four text entry fields:
+.PP
+At the top is a 'remote' switch.
+If this is enabled then you can use the \fBHostname\fR and \fBService\fR
+fields to connect to a remote server.
+If it is disabled then then Disobedience will connect to a local server
+instead.
+.PP
+Below this are four text entry fields:
 .TP
 .B Hostname
 The host to connect to.
@@ -242,16 +249,14 @@ The password to use when logging in.
 Note that this is NOT your login password but is your password to the
 DisOrder server.
 .PP
-It has three buttons:
+It has two buttons:
 .TP
 .B Login
 This button attempts to (re-)connect to the server with the currently displayed
 settings.
-The settings are not saved.
-.TP
-.B Save
-This button saves the current settings in 
+The settings are saved in
 .IR $HOME/.disorder/passwd .
+on success.
 .TP
 .B Close
 This button closes the window, discarding any unsaved changes.