summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f522f83)
raw | patch | inline | side by side (parent: f522f83)
author | Kalle Wallin <kaw@linux.se> | |
Tue, 14 Jun 2005 17:30:17 +0000 (17:30 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Tue, 14 Jun 2005 17:30:17 +0000 (17:30 +0000) |
ChangeLog | patch | blob | history | |
src/list_window.c | patch | blob | history | |
src/list_window.h | patch | blob | history | |
src/screen_artist.c | patch | blob | history | |
src/screen_file.c | patch | blob | history |
diff --git a/ChangeLog b/ChangeLog
index 964bfcbafdbb43d93c7b8181ae8e6420b20db16c..393bb68094325e890a9eb1395ef5cb7097a6c25d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
+2005-06-14: Kalle Wallin <kaw@linux.se>
+ * Moved list window state code to list_window.c
+
2005-06-11: Kalle Wallin <kaw@linux.se>
* configure.ac: support wide-char ncurses library (--with-ncursesw)
+ * support.c: added my_strlen for wide-char strings
2005-06-06: Kalle Wallin <kaw@linux.se>
* Added Norwegian translations from Ole R. Thorsen
diff --git a/src/list_window.c b/src/list_window.c
index 8966622925ee12bb45a2815f0e27880a38a16786..5ee81d0697e90ce05ecdd68832348589fee4bf79 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
}
+
+
+
+list_window_state_t *
+list_window_init_state(void)
+{
+ return g_malloc0(sizeof(list_window_state_t));
+}
+
+list_window_state_t *
+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);
+ }
+ return NULL;
+}
+
+void
+list_window_push_state(list_window_state_t *state, list_window_t *lw)
+{
+ if( state )
+ {
+ list_window_t *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);
+ }
+}
+
+void
+list_window_pop_state(list_window_state_t *state, list_window_t *lw)
+{
+ if( state && state->list )
+ {
+ list_window_t *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);
+ }
+}
+
+
+
diff --git a/src/list_window.h b/src/list_window.h
index 8374e53d7235e781f25f8fef5ea51adacab60062..2061e81aa9d6ddf4f8fc5b0dbf6388c2ffc64bc4 100644 (file)
--- a/src/list_window.h
+++ b/src/list_window.h
} list_window_t;
+typedef struct
+{
+ GList *list;
+} list_window_state_t;
+
/* create a new list window */
list_window_t *list_window_init(WINDOW *w, int width, int height);
int wrap,
int rows);
+/* list window states */
+list_window_state_t *list_window_init_state(void);
+list_window_state_t *list_window_free_state(list_window_state_t *state);
+void list_window_push_state(list_window_state_t *state, list_window_t *lw);
+void list_window_pop_state(list_window_state_t *state, list_window_t *lw);
+
+
+
#endif
diff --git a/src/screen_artist.c b/src/screen_artist.c
index e09d9f04927779ba0ff4481b9cc42a30f3ec3713..a363304f52d5a4f5caa9c651b615597b8019219a 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.c
/*
* $Id$
*
- * (c) 2004 by Kalle Wallin <kaw@linux.se>
+ * (c) 2005 by Kalle Wallin <kaw@linux.se>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
static mpdclient_filelist_t *filelist = NULL;
static int metalist_length = 0;
static GList *metalist = NULL;
-static GList *lw_state_list = NULL;
-
-/* store current state when entering a subdirectory */
-static void
-push_lw_state(void)
-{
- list_window_t *tmp = g_malloc(sizeof(list_window_t));
-
- memcpy(tmp, lw, sizeof(list_window_t));
- lw_state_list = g_list_prepend(lw_state_list, (gpointer) tmp);
-}
-
-/* get previous state when leaving a directory */
-static void
-pop_lw_state(void)
-{
- if( lw_state_list )
- {
- list_window_t *tmp = lw_state_list->data;
-
- memcpy(lw, tmp, sizeof(list_window_t));
- g_free(tmp);
- lw_state_list->data = NULL;
- lw_state_list = g_list_delete_link(lw_state_list, lw_state_list);
- }
-}
+static list_window_state_t *lw_state = NULL;
/* list_window callback */
static char *
}
}
+/* fetch artists/albums/songs from mpd */
static void
update_metalist(mpdclient_t *c, char *m_artist, char *m_album)
{
metalist = mpdclient_get_artists_utf8(c);
}
metalist_length = g_list_length(metalist);
+ lw->clear = TRUE;
+}
+
+/* db updated */
+static void
+browse_callback(mpdclient_t *c, int event, gpointer data)
+{
+ switch(event)
+ {
+ case BROWSE_DB_UPDATED:
+ D("screen_artist.c> browse_callback() [BROWSE_DB_UPDATED]\n");
+ lw->clear = 1;
+ lw->repaint = 1;
+ update_metalist(c, g_strdup(artist), g_strdup(album));
+ break;
+ default:
+ break;
+ }
}
static void
init(WINDOW *w, int cols, int rows)
{
lw = list_window_init(w, cols, rows);
+ lw_state = list_window_init_state();
artist = NULL;
album = NULL;
}
static void
quit(void)
{
- /* clear list window state */
- if( lw_state_list )
- {
- GList *list = lw_state_list;
- while( list )
- {
- g_free(list->data);
- list->data = NULL;
- list = list->next;
- }
- g_list_free(lw_state_list);
- lw_state_list = NULL;
- }
-
if( filelist )
filelist = mpdclient_filelist_free(filelist);
if( metalist )
g_free(album);
artist = NULL;
album = NULL;
- list_window_free(lw);
+ lw = list_window_free(lw);
+ lw_state = list_window_free_state(lw_state);
}
static void
open(screen_t *screen, mpdclient_t *c)
{
+ static gboolean callback_installed = FALSE;
+
if( metalist==NULL && filelist ==NULL)
update_metalist(c, NULL, NULL);
+ if( !callback_installed )
+ {
+ mpdclient_install_browse_callback(c, browse_callback);
+ callback_installed = TRUE;
+ }
}
static void
static void
update(screen_t *screen, mpdclient_t *c)
{
- if( filelist==NULL || filelist->updated )
+ if( filelist && !filelist->updated )
+ {
+ list_window_paint(lw, browse_lw_callback, (void *) filelist);
+ }
+ else if( metalist )
+ {
+ list_window_paint(lw, artist_lw_callback, (void *) metalist);
+ }
+ else
{
paint(screen, c);
- return;
}
- list_window_paint(lw, browse_lw_callback, (void *) filelist);
wnoutrefresh(lw->w);
}
update_metalist(c, g_strdup(artist), NULL);
list_window_reset(lw);
/* restore previous list window state */
- pop_lw_state();
+ list_window_pop_state(lw_state,lw);
}
else
browse_handle_enter(screen, c, lw, filelist);
update_metalist(c, NULL, NULL);
list_window_reset(lw);
/* restore previous list window state */
- pop_lw_state();
+ list_window_pop_state(lw_state,lw);
}
else if( lw->selected == metalist_length-1) /* handle "show all" */
{
update_metalist(c, g_strdup(artist), g_strdup("\0"));
- push_lw_state();
- list_window_reset(lw);
+ list_window_push_state(lw_state,lw);
}
else /* select album */
{
char *selected = (char *) g_list_nth_data(metalist, lw->selected);
update_metalist(c, g_strdup(artist), g_strdup(selected));
- push_lw_state();
- list_window_reset(lw);
+ list_window_push_state(lw_state,lw);
}
}
else
{
char *selected = (char *) g_list_nth_data(metalist, lw->selected);
update_metalist(c, g_strdup(selected), NULL);
- push_lw_state();
- list_window_reset(lw);
+ list_window_push_state(lw_state,lw);
}
return 1;
/* continue and update... */
case CMD_SCREEN_UPDATE:
+ screen->painted = 0;
+ lw->clear = 1;
+ lw->repaint = 1;
+ update_metalist(c, g_strdup(artist), g_strdup(album));
+ screen_status_printf(_("Screen updated!"));
return 0;
case CMD_LIST_FIND:
diff --git a/src/screen_file.c b/src/screen_file.c
index 002e9cd73261132d5bf3704e2f90194f9d3d411c..b2ca1b6cd9c6c5acd0bf72f9935f116ce9e55a82 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
static list_window_t *lw = NULL;
-static GList *lw_state_list = NULL;
+static list_window_state_t *lw_state = NULL;
static mpdclient_filelist_t *filelist = NULL;
}
}
-/* store current state when entering a subdirectory */
-static void
-push_lw_state(void)
-{
- list_window_t *tmp = g_malloc(sizeof(list_window_t));
-
- memcpy(tmp, lw, sizeof(list_window_t));
- lw_state_list = g_list_prepend(lw_state_list, (gpointer) tmp);
-}
-
-/* get previous state when leaving a directory */
-static void
-pop_lw_state(void)
-{
- if( lw_state_list )
- {
- list_window_t *tmp = lw_state_list->data;
-
- memcpy(lw, tmp, sizeof(list_window_t));
- g_free(tmp);
- lw_state_list->data = NULL;
- lw_state_list = g_list_delete_link(lw_state_list, lw_state_list);
- }
-}
-
/* list_window callback */
char *
browse_lw_callback(int index, int *highlight, void *data)
path = g_strdup(parent);
list_window_reset(lw);
/* restore previous list window state */
- pop_lw_state();
+ list_window_pop_state(lw_state,lw);
}
else
if( entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY)
mpd_Directory *dir = entity->info.directory;
path = utf8_to_locale(dir->path);
/* save current list window state */
- push_lw_state();
- list_window_reset(lw);
+ list_window_push_state(lw_state,lw);
}
else
return -1;
browse_init(WINDOW *w, int cols, int rows)
{
lw = list_window_init(w, cols, rows);
+ lw_state = list_window_init_state();
}
static void
static void
browse_exit(void)
{
- if( lw_state_list )
- {
- GList *list = lw_state_list;
- while( list )
- {
- g_free(list->data);
- list->data = NULL;
- list = list->next;
- }
- g_list_free(lw_state_list);
- lw_state_list = NULL;
-
- }
if( filelist )
filelist = mpdclient_filelist_free(filelist);
- list_window_free(lw);
+ lw = list_window_free(lw);
+ lw_state = list_window_free_state(lw_state);
}
static void