+ playlist_close();
+ ret = load_playlist(row, ¤t_playlist);
+ return (ret == -E_PLAYLIST_LOADED)? current_playlist.length : ret;
+}
+
+static int search_path(char *path, void *data)
+{
+ if (strcmp(path, data))
+ return 1;
+ return -E_PATH_FOUND;
+}
+
+static int handle_audio_file_event(enum afs_events event, void *data)
+{
+ int ret, was_admissible = 0, is_admissible;
+ struct osl_object playlist_def;
+ char *new_path;
+ const struct osl_row *row = data;
+
+ if (!current_playlist.name)
+ return 1;
+ if (event == AUDIO_FILE_RENAME) {
+ ret = row_belongs_to_score_table(row, NULL);
+ if (ret < 0)
+ return ret;
+ was_admissible = ret;
+ }
+ ret = get_audio_file_path_of_row(row, &new_path);
+ if (ret < 0)
+ return ret;
+ ret = pl_get_def_by_name(current_playlist.name, &playlist_def);
+ if (ret < 0)
+ return ret;
+ ret = for_each_line_ro(playlist_def.data, playlist_def.size,
+ search_path, new_path);
+ osl_close_disk_object(&playlist_def);
+ is_admissible = (ret < 0);
+ if (was_admissible && is_admissible)
+ return 1;
+ if (!was_admissible && !is_admissible)
+ return 1;
+ if (was_admissible && !is_admissible) {
+ current_playlist.length--;
+ return score_delete(row);
+ }
+ /* !was_admissible && is_admissible */
+ current_playlist.length++;
+ return score_add(row, 0); /* play it immediately */
+}
+
+/**
+ * Handle afs events relevant to playlists.
+ *
+ * \param event The event type.
+ * \param pb Unused.
+ * \param data Depends on the event type.
+ *
+ * \return Standard.
+ */
+int playlists_event_handler(enum afs_events event,
+ __a_unused struct para_buffer *pb, void *data)
+{
+ int ret;
+ struct afsi_change_event_data *aced = data;
+
+ switch(event) {
+ case AFSI_CHANGE:
+ return playlist_update_audio_file(aced->aft_row);
+ case AUDIO_FILE_RENAME:
+ case AUDIO_FILE_ADD:
+ return handle_audio_file_event(event, data);
+ case AUDIO_FILE_REMOVE:
+ ret = row_belongs_to_score_table(data, NULL);
+ if (ret < 0)
+ return ret;
+ if (!ret)
+ return 1;
+ current_playlist.length--;
+ return score_delete(data);
+ default:
+ return 1;
+ }