chiark / gitweb /
Support global prefs through eclient interface.
authorRichard Kettlewell <rjk@terraraq.org.uk>
Sat, 30 Jul 2011 17:50:58 +0000 (18:50 +0100)
committerRichard Kettlewell <rjk@terraraq.org.uk>
Sat, 30 Jul 2011 17:50:58 +0000 (18:50 +0100)
Additionally, cope a bit better with NULL callbacks.

lib/eclient.c
lib/eclient.h

index 5eda674ff03431d62e735c22adc6a3837e04647b..d03306e852347b8d726f3ef9bf116ccb1922109d 100644 (file)
@@ -193,6 +193,7 @@ static void logentry_adopted(disorder_eclient *c, int nvec, char **vec);
 static void logentry_playlist_created(disorder_eclient *c, int nvec, char **vec);
 static void logentry_playlist_deleted(disorder_eclient *c, int nvec, char **vec);
 static void logentry_playlist_modified(disorder_eclient *c, int nvec, char **vec);
+static void logentry_global_pref(disorder_eclient *c, int nvec, char **vec);
 
 /* Tables ********************************************************************/
 
@@ -212,6 +213,7 @@ static const struct logentry_handler logentry_handlers[] = {
   LE(adopted, 2, 2),
   LE(completed, 1, 1),
   LE(failed, 2, 2),
+  LE(global_pref, 1, 2),
   LE(moved, 1, 1),
   LE(playing, 1, 2),
   LE(playlist_created, 2, 2),
@@ -916,8 +918,8 @@ static void string_response_opcallback(disorder_eclient *c,
     = (disorder_eclient_string_response *)op->completed;
     
   D(("string_response_callback"));
-  if(c->rc / 100 == 2 || c->rc == 555) {
-    if(op->completed) {
+  if(completed) {
+    if(c->rc / 100 == 2 || c->rc == 555) {
       if(c->rc == 555)
         completed(op->v, NULL, NULL);
       else if(c->protocol >= 2) {
@@ -931,9 +933,9 @@ static void string_response_opcallback(disorder_eclient *c,
           completed(op->v, "error parsing response", NULL);
       } else
         completed(op->v, NULL, c->line + 4);
-    }
-  } else
-    completed(op->v, errorstring(c), NULL);
+    } else
+      completed(op->v, errorstring(c), NULL);
+  }
 }
 
 /* for commands with a simple integer response */ 
@@ -963,10 +965,12 @@ static void no_response_opcallback(disorder_eclient *c,
     = (disorder_eclient_no_response *)op->completed;
 
   D(("no_response_callback"));
-  if(c->rc / 100 == 2)
-    completed(op->v, NULL);
-  else
-    completed(op->v, errorstring(c));
+  if(completed) {
+    if(c->rc / 100 == 2)
+      completed(op->v, NULL);
+    else
+      completed(op->v, errorstring(c));
+  }
 }
 
 /* error callback for queue_unmarshall */
@@ -1356,6 +1360,31 @@ int disorder_eclient_nop(disorder_eclient *c,
                 "nop", (char *)0);
 }
 
+int disorder_eclient_get_global(disorder_eclient *c,
+                                disorder_eclient_string_response *completed,
+                                const char *pref,
+                                void *v) {
+  return simple(c, string_response_opcallback, (void (*)())completed, v,
+                "get-global", pref, (char *)0);
+}
+
+int disorder_eclient_set_global(disorder_eclient *c,
+                                disorder_eclient_no_response *completed,
+                                const char *pref,
+                                const char *value,
+                                void *v) {
+  return simple(c, no_response_opcallback, (void (*)())completed, v,
+                "set-global", pref, value, (char *)0);
+}
+
+int disorder_eclient_unset_global(disorder_eclient *c,
+                                  disorder_eclient_no_response *completed,
+                                  const char *pref,
+                                  void *v) {
+  return simple(c, no_response_opcallback, (void (*)())completed, v,
+                "unset-global", pref, (char *)0);
+}
+
 /** @brief Get the last @p max added tracks
  * @param c Client
  * @param completed Called with list
@@ -1919,6 +1948,12 @@ static void logentry_adopted(disorder_eclient *c,
     c->log_callbacks->adopted(c->log_v, vec[0], vec[1]);
 }
 
+static void logentry_global_pref(disorder_eclient *c,
+                                 int nvec, char **vec) {
+  if(c->log_callbacks->global_pref) 
+    c->log_callbacks->global_pref(c->log_v, vec[0], nvec > 1 ? vec[1] : 0);
+}
+
 /*
 Local Variables:
 c-basic-offset:2
index b100106c04abd55f25e4ebdf6c1593b957efe140..c44c5dc1dd645568cd6a2b3eed6a017f16d18d34 100644 (file)
@@ -177,6 +177,9 @@ typedef struct disorder_eclient_log_callbacks {
 
   /** @brief Called when a new playlist is deleted */
   void (*playlist_deleted)(void *v, const char *playlist);
+
+  /** @brief Called when a global pref is changed or delete */
+  void (*global_pref)(void *v, const char *pref, const char *value/*or NULL*/);
 } disorder_eclient_log_callbacks;
 
 /* State bits */
@@ -461,6 +464,21 @@ int disorder_eclient_unset(disorder_eclient *c,
                            void *v);
 /* Get/set preference values */
 
+int disorder_eclient_get_global(disorder_eclient *c,
+                                disorder_eclient_string_response *completed,
+                                const char *pref,
+                                void *v);
+int disorder_eclient_set_global(disorder_eclient *c,
+                                disorder_eclient_no_response *completed,
+                                const char *pref,
+                                const char *value,
+                                void *v);
+int disorder_eclient_unset_global(disorder_eclient *c,
+                                  disorder_eclient_no_response *completed,
+                                  const char *pref,
+                                  void *v);
+/* Get/set global prefs */
+
 int disorder_eclient_search(disorder_eclient *c,
                             disorder_eclient_list_response *completed,
                             const char *terms,