summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e2c8e28)
raw | patch | inline | side by side (parent: e2c8e28)
author | Max Kellermann <max@duempel.org> | |
Fri, 3 Oct 2008 09:56:00 +0000 (11:56 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Fri, 3 Oct 2008 09:56:00 +0000 (11:56 +0200) |
We do not need to save a stack of list window states. When we return
to a parent directory, we just have to find the directory which we
come from in the parent list. Note that this patch resets the cursor
when going to the root directory, but I think it's not that important,
and I will deal with that later.
to a parent directory, we just have to find the directory which we
come from in the parent list. Note that this patch resets the cursor
when going to the root directory, but I think it's not that important,
and I will deal with that later.
diff --git a/src/list_window.c b/src/list_window.c
index 93bed86667db070332e3da3bb344dca1b28fa57e..55b621b4a7fffa7ce9e8b855f03737387b956ba4 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
return 0;
}
#endif
-
-list_window_state_t *
-list_window_init_state(void)
-{
- return g_malloc0(sizeof(list_window_state_t));
-}
-
-void
-list_window_free_state(list_window_state_t *state)
-{
- if (state) {
- if (state->list) {
- GList *list = state->list;
-
- while (list) {
- g_free(list->data);
- list->data = NULL;
- list = list->next;
- }
-
- g_list_free(state->list);
- state->list = NULL;
- }
-
- g_free(state);
- }
-}
-
-void
-list_window_push_state(list_window_state_t *state, struct list_window *lw)
-{
- if (state) {
- struct list_window *tmp = g_malloc(sizeof(list_window_t));
- memcpy(tmp, lw, sizeof(list_window_t));
- state->list = g_list_prepend(state->list, (gpointer) tmp);
- list_window_reset(lw);
- }
-}
-
-bool
-list_window_pop_state(list_window_state_t *state, struct list_window *lw)
-{
- if (state && state->list) {
- struct list_window *tmp = state->list->data;
-
- memcpy(lw, tmp, sizeof(list_window_t));
- g_free(tmp);
- state->list->data = NULL;
- state->list = g_list_delete_link(state->list, state->list);
- }
-
- // return TRUE if there are still states in the list
- return (state && state->list) ? TRUE : FALSE;
-}
diff --git a/src/list_window.h b/src/list_window.h
index 6bfe5db5d1e5953fc72ebd48d44a624d15fd4d5b..1d93a363ef8d2634c037ce98c8a46af01966af4b 100644 (file)
--- a/src/list_window.h
+++ b/src/list_window.h
int flags;
} list_window_t;
-typedef struct list_window_state {
- GList *list;
-} list_window_state_t;
-
/* create a new list window */
struct list_window *list_window_init(WINDOW *w,
int wrap,
unsigned rows);
-/* list window states */
-list_window_state_t *list_window_init_state(void);
-void list_window_free_state(list_window_state_t *state);
-void list_window_push_state(list_window_state_t *state,
- struct list_window *lw);
-bool list_window_pop_state(list_window_state_t *state, struct list_window *lw);
-
-
-
#endif
diff --git a/src/screen_artist.c b/src/screen_artist.c
index 8c5636f57f39b482ab9832269f35d32c7fe7065a..e488a3a08e5512610725a560713e2512a5fda420 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.c
init(WINDOW *w, int cols, int rows)
{
browser.lw = list_window_init(w, cols, rows);
- browser.lw_state = list_window_init_state();
artist = NULL;
album = NULL;
}
{
free_state(NULL);
list_window_free(browser.lw);
- list_window_free_state(browser.lw_state);
}
static void
return 0;
}
+static int
+string_array_find(GPtrArray *array, const char *value)
+{
+ guint i;
+
+ for (i = 0; i < array->len; ++i)
+ if (strcmp((const char*)g_ptr_array_index(array, i),
+ value) == 0)
+ return i;
+
+ return -1;
+}
+
static int
artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
{
char *selected;
+ char *old;
+ int idx;
switch(cmd) {
case CMD_PLAY:
selected = g_ptr_array_index(artist_list,
browser.lw->selected);
open_album_list(c, g_strdup(selected));
- list_window_push_state(browser.lw_state, browser.lw);
+ list_window_reset(browser.lw);
artist_repaint();
return true;
case LIST_ALBUMS:
if (browser.lw->selected == 0) {
/* handle ".." */
+ old = g_strdup(artist);
open_artist_list(c);
list_window_reset(browser.lw);
/* restore previous list window state */
- list_window_pop_state(browser.lw_state, browser.lw);
+ idx = string_array_find(artist_list, old);
+ g_free(old);
+
+ if (idx >= 0) {
+ list_window_set_selected(browser.lw, idx);
+ list_window_center(browser.lw,
+ artist_list->len, idx);
+ }
} else if (browser.lw->selected == album_list->len + 1) {
/* handle "show all" */
open_song_list(c, g_strdup(artist), g_strdup("\0"));
- list_window_push_state(browser.lw_state, browser.lw);
+ list_window_reset(browser.lw);
} else {
/* select album */
selected = g_ptr_array_index(album_list,
browser.lw->selected - 1);
open_song_list(c, g_strdup(artist), g_strdup(selected));
- list_window_push_state(browser.lw_state, browser.lw);
+ list_window_reset(browser.lw);
}
artist_repaint();
case LIST_SONGS:
if (browser.lw->selected == 0) {
/* handle ".." */
+ old = g_strdup(album);
open_album_list(c, g_strdup(artist));
list_window_reset(browser.lw);
/* restore previous list window state */
- list_window_pop_state(browser.lw_state,
- browser.lw);
+ idx = *old == 0
+ ? (int)album_list->len
+ : string_array_find(album_list, old);
+ g_free(old);
+
+ if (idx >= 0) {
+ ++idx;
+ list_window_set_selected(browser.lw, idx);
+ list_window_center(browser.lw,
+ album_list->len, idx);
+ }
artist_repaint();
return true;
break;
case LIST_ALBUMS:
+ old = g_strdup(artist);
+
open_artist_list(c);
list_window_reset(browser.lw);
/* restore previous list window state */
- list_window_pop_state(browser.lw_state, browser.lw);
+ idx = string_array_find(artist_list, old);
+ g_free(old);
+
+ if (idx >= 0) {
+ list_window_set_selected(browser.lw, idx);
+ list_window_center(browser.lw,
+ artist_list->len, idx);
+ }
break;
case LIST_SONGS:
+ old = g_strdup(album);
+
open_album_list(c, g_strdup(artist));
list_window_reset(browser.lw);
/* restore previous list window state */
- list_window_pop_state(browser.lw_state, browser.lw);
+ idx = *old == 0
+ ? (int)album_list->len
+ : string_array_find(album_list, old);
+ g_free(old);
+
+ if (idx >= 0) {
+ ++idx;
+ list_window_set_selected(browser.lw, idx);
+ list_window_center(browser.lw,
+ album_list->len, idx);
+ }
break;
}
open_artist_list(c);
list_window_reset(browser.lw);
/* restore first list window state (pop while returning true) */
- while(list_window_pop_state(browser.lw_state, browser.lw));
+ /* XXX */
break;
}
diff --git a/src/screen_browser.c b/src/screen_browser.c
index da0dc897c088093376c289f856a3399fe065da56..4457e7e5954628dc03d15588b7f32a75a30cc71e 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.c
{
mpd_InfoEntity *entity = NULL;
gchar *path = NULL;
+ char *old_path;
+ int idx;
if( entry!=NULL )
entity = entry->entity;
if( strcmp(parent, ".") == 0 )
parent[0] = '\0';
path = g_strdup(parent);
- list_window_reset(browser->lw);
- /* restore previous list window state */
- list_window_pop_state(browser->lw_state, browser->lw);
} else {
/* entry==NULL, then new_path ("" is root) */
path = g_strdup(new_path);
- list_window_reset(browser->lw);
- /* restore first list window state (pop while returning true) */
- while(list_window_pop_state(browser->lw_state, browser->lw));
}
} else if( entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY) {
/* enter sub */
mpd_Directory *dir = entity->info.directory;
path = utf8_to_locale(dir->path);
- /* save current list window state */
- list_window_push_state(browser->lw_state, browser->lw);
} else
return -1;
+ old_path = g_strdup(browser->filelist->path);
+
filelist_free(browser->filelist);
browser->filelist = mpdclient_filelist_get(c, path);
sync_highlights(c, browser->filelist);
- list_window_check_selected(browser->lw, filelist_length(browser->filelist));
+
+ idx = filelist_find_directory(browser->filelist, old_path);
+ g_free(old_path);
+
+ list_window_reset(browser->lw);
+ if (idx >= 0) {
+ list_window_set_selected(browser->lw, idx);
+ list_window_center(browser->lw,
+ filelist_length(browser->filelist), idx);
+ }
+
g_free(path);
return 0;
}
diff --git a/src/screen_browser.h b/src/screen_browser.h
index 2b825c03a0e9985dedfc0dd2bc72ac78173880ac..cd218bc48dc23e51e1633fe291cf6d9be67af66f 100644 (file)
--- a/src/screen_browser.h
+++ b/src/screen_browser.h
struct screen_browser {
struct list_window *lw;
- struct list_window_state *lw_state;
mpdclient_filelist_t *filelist;
};
diff --git a/src/screen_file.c b/src/screen_file.c
index 95510a516759dfd466a2f8f072bf617886c0d123..1ba96403a8ab3ac4e8b1f921834e985c13a3484e 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
browse_init(WINDOW *w, int cols, int rows)
{
browser.lw = list_window_init(w, cols, rows);
- browser.lw_state = list_window_init_state();
}
static void
if (browser.filelist)
filelist_free(browser.filelist);
list_window_free(browser.lw);
- list_window_free_state(browser.lw_state);
}
static void