diff options
Diffstat (limited to '')
-rw-r--r-- | src/PlaylistState.cxx (renamed from src/playlist_state.c) | 74 |
1 files changed, 30 insertions, 44 deletions
diff --git a/src/playlist_state.c b/src/PlaylistState.cxx index 4aa2c2c92..14c6d231e 100644 --- a/src/playlist_state.c +++ b/src/PlaylistState.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2011 The Music Player Daemon Project + * Copyright (C) 2003-2013 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -23,12 +23,11 @@ */ #include "config.h" -#include "playlist_state.h" -#include "playlist.h" -#include "player_control.h" -#include "queue_save.h" -#include "path.h" -#include "text_file.h" +#include "PlaylistState.hxx" +#include "Playlist.hxx" +#include "QueueSave.hxx" +#include "TextFile.hxx" +#include "PlayerControl.hxx" #include "conf.h" #include <string.h> @@ -72,8 +71,7 @@ playlist_state_save(FILE *fp, const struct playlist *playlist, fputs(PLAYLIST_STATE_FILE_STATE_PLAY "\n", fp); } fprintf(fp, PLAYLIST_STATE_FILE_CURRENT "%i\n", - queue_order_to_position(&playlist->queue, - playlist->current)); + playlist->queue.OrderToPosition(playlist->current)); fprintf(fp, PLAYLIST_STATE_FILE_TIME "%i\n", (int)player_status.elapsed_time); } else { @@ -81,8 +79,7 @@ playlist_state_save(FILE *fp, const struct playlist *playlist, if (playlist->current >= 0) fprintf(fp, PLAYLIST_STATE_FILE_CURRENT "%i\n", - queue_order_to_position(&playlist->queue, - playlist->current)); + playlist->queue.OrderToPosition(playlist->current)); } fprintf(fp, PLAYLIST_STATE_FILE_RANDOM "%i\n", playlist->queue.random); @@ -102,18 +99,18 @@ playlist_state_save(FILE *fp, const struct playlist *playlist, } static void -playlist_state_load(FILE *fp, GString *buffer, struct playlist *playlist) +playlist_state_load(TextFile &file, struct playlist *playlist) { - const char *line = read_text_line(fp, buffer); + const char *line = file.ReadLine(); if (line == NULL) { g_warning("No playlist in state file"); return; } while (!g_str_has_prefix(line, PLAYLIST_STATE_FILE_PLAYLIST_END)) { - queue_load_song(fp, buffer, line, &playlist->queue); + queue_load_song(file, line, &playlist->queue); - line = read_text_line(fp, buffer); + line = file.ReadLine(); if (line == NULL) { g_warning("'" PLAYLIST_STATE_FILE_PLAYLIST_END "' not found in state file"); @@ -121,11 +118,11 @@ playlist_state_load(FILE *fp, GString *buffer, struct playlist *playlist) } } - queue_increment_version(&playlist->queue); + playlist->queue.IncrementVersion(); } bool -playlist_state_restore(const char *line, FILE *fp, GString *buffer, +playlist_state_restore(const char *line, TextFile &file, struct playlist *playlist, struct player_control *pc) { int current = -1; @@ -143,31 +140,21 @@ playlist_state_restore(const char *line, FILE *fp, GString *buffer, else if (strcmp(line, PLAYLIST_STATE_FILE_STATE_PAUSE) == 0) state = PLAYER_STATE_PAUSE; - while ((line = read_text_line(fp, buffer)) != NULL) { + while ((line = file.ReadLine()) != NULL) { if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_TIME)) { seek_time = atoi(&(line[strlen(PLAYLIST_STATE_FILE_TIME)])); } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_REPEAT)) { - if (strcmp - (&(line[strlen(PLAYLIST_STATE_FILE_REPEAT)]), - "1") == 0) { - playlist_set_repeat(playlist, pc, true); - } else - playlist_set_repeat(playlist, pc, false); + playlist->SetRepeat(*pc, + strcmp(&(line[strlen(PLAYLIST_STATE_FILE_REPEAT)]), + "1") == 0); } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_SINGLE)) { - if (strcmp - (&(line[strlen(PLAYLIST_STATE_FILE_SINGLE)]), - "1") == 0) { - playlist_set_single(playlist, pc, true); - } else - playlist_set_single(playlist, pc, false); + playlist->SetSingle(*pc, + strcmp(&(line[strlen(PLAYLIST_STATE_FILE_SINGLE)]), + "1") == 0); } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_CONSUME)) { - if (strcmp - (&(line[strlen(PLAYLIST_STATE_FILE_CONSUME)]), - "1") == 0) { - playlist_set_consume(playlist, true); - } else - playlist_set_consume(playlist, false); + playlist->SetConsume(strcmp(&(line[strlen(PLAYLIST_STATE_FILE_CONSUME)]), + "1") == 0); } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_CROSSFADE)) { pc_set_cross_fade(pc, atoi(line + strlen(PLAYLIST_STATE_FILE_CROSSFADE))); @@ -187,14 +174,14 @@ playlist_state_restore(const char *line, FILE *fp, GString *buffer, (PLAYLIST_STATE_FILE_CURRENT)])); } else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_PLAYLIST_BEGIN)) { - playlist_state_load(fp, buffer, playlist); + playlist_state_load(file, playlist); } } - playlist_set_random(playlist, pc, random_mode); + playlist->SetRandom(*pc, random_mode); - if (!queue_is_empty(&playlist->queue)) { - if (!queue_valid_position(&playlist->queue, current)) + if (!playlist->queue.IsEmpty()) { + if (!playlist->queue.IsValidPosition(current)) current = 0; if (state == PLAYER_STATE_PLAY && @@ -213,9 +200,9 @@ playlist_state_restore(const char *line, FILE *fp, GString *buffer, if (state == PLAYER_STATE_STOP /* && config_option */) playlist->current = current; else if (seek_time == 0) - playlist_play(playlist, pc, current); + playlist->PlayPosition(*pc, current); else - playlist_seek_song(playlist, pc, current, seek_time); + playlist->SeekSongPosition(*pc, current, seek_time); if (state == PLAYER_STATE_PAUSE) pc_pause(pc); @@ -237,8 +224,7 @@ playlist_state_get_hash(const struct playlist *playlist, ? ((int)player_status.elapsed_time << 8) : 0) ^ (playlist->current >= 0 - ? (queue_order_to_position(&playlist->queue, - playlist->current) << 16) + ? (playlist->queue.OrderToPosition(playlist->current) << 16) : 0) ^ ((int)pc_get_cross_fade(pc) << 20) ^ (player_status.state << 24) ^ |