]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - mood.c
Kill code for loading the first available playlist.
[paraslash.git] / mood.c
diff --git a/mood.c b/mood.c
index a8d87cde122c9bc03d6cab301695fe97bf2896e8..08c2c222e84f69bd794ea7c4598b83fe0051ac06 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -523,35 +523,6 @@ static int load_mood(const struct osl_row *mood_row, struct mood **m)
        return 1;
 }
 
-/*
- * Calls load_mood() and reverts its error value: It returns -E_MOOD_LOADED
- * on _success_, and 1 on errors. This way the loop over all moods stops at the
- * first valid mood.
- */
-static int load_mood_loop_func(struct osl_row *mood_row, void *data)
-{
-       struct mood **m = data;
-       int ret = load_mood(mood_row, m);
-       if (ret < 0) {
-               if (ret != -E_DUMMY_ROW)
-                       PARA_NOTICE_LOG("invalid mood (%d), trying next mood\n", ret);
-               return 1;
-       }
-       return -E_MOOD_LOADED;
-}
-
-static int load_first_available_mood(struct mood **m)
-{
-       int ret = osl_rbtree_loop(moods_table, BLOBCOL_NAME, m,
-               load_mood_loop_func);
-       if (ret == -E_MOOD_LOADED) /* success */
-               return 1;
-       if (ret < 0)
-               return ret; /* error */
-       PARA_NOTICE_LOG("no valid mood found\n");
-       return -E_NO_MOOD;
-}
-
 static int check_mood(struct osl_row *mood_row, void *data)
 {
        struct para_buffer *pb = data;
@@ -946,10 +917,8 @@ static void log_statistics(void)
  *
  * \param mood_name The name of the mood to open.
  *
- * There are two special cases: If \a mood_name is \a NULL, load the
- * first available mood. If \a mood_name is the empty string "", load
- * the dummy mood that accepts every audio file and uses a scoring method
- * based only on the \a last_played information.
+ * If \a mood_name is \a NULL, load the dummy mood that accepts every audio file
+ * and uses a scoring method based only on the \a last_played information.
  *
  * If there is already an open mood, it will be closed first.
  *
@@ -967,14 +936,7 @@ int change_current_mood(char *mood_name)
                .array = NULL
        };
 
-       if (!mood_name) {
-               struct mood *m;
-               ret = load_first_available_mood(&m);
-               if (ret < 0)
-                       return ret;
-               destroy_mood(current_mood);
-               current_mood = m;
-       } else if (*mood_name) {
+       if (mood_name) {
                struct mood *m;
                struct osl_row *row;
                struct osl_object obj = {
@@ -1047,10 +1009,15 @@ int reload_current_mood(void)
        int ret;
        char *mood_name;
 
+       PARA_NOTICE_LOG("reloading current mood\n");
        if (!current_mood)
                return 1;
-       mood_name = para_strdup(current_mood->name);
+       if (current_mood->name)
+               mood_name = para_strdup(current_mood->name);
        close_current_mood();
+       ret = clear_score_table();
+       if (ret < 0)
+               return ret;
        ret = change_current_mood(mood_name);
        free(mood_name);
        return ret;
@@ -1060,10 +1027,22 @@ int moods_event_handler(enum afs_events event, struct para_buffer *pb,
                void *data)
 {
        switch(event) {
+       /*
+        * The three blob events might change the set of admissible files,
+        * so we must reload the score list.
+        */
+       case BLOB_RENAME:
+       case BLOB_REMOVE:
+       case BLOB_ADD:
+               if (data == moods_table || data == playlists_table)
+                       return 1; /* no reload necessary for these */
+               return reload_current_mood();
+       /* these also require reload of the score table */
        case ATTRIBUTE_ADD:
        case ATTRIBUTE_REMOVE:
        case ATTRIBUTE_RENAME:
                return reload_current_mood();
+       /* changes to the aft only require to re-examine the audio file */
        case AFSI_CHANGE: {
                struct afsi_change_event_data *aced = data;
                return mood_update_audio_file(aced->aft_row, aced->old_afsi);