From: Max Kellermann Date: Sun, 13 Sep 2009 09:06:07 +0000 (+0200) Subject: filelist: removed "path" attribute X-Git-Tag: release-0.15~14 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6103d38413279e648cba591aa9c5b3c68b629361;p=ncmpc.git filelist: removed "path" attribute Callers should track their current path manually, instead of relying on an the filelist object. --- diff --git a/src/filelist.c b/src/filelist.c index 100db88..e3e1cb1 100644 --- a/src/filelist.c +++ b/src/filelist.c @@ -25,11 +25,10 @@ #include struct filelist * -filelist_new(const char *path) +filelist_new(void) { struct filelist *filelist = g_malloc(sizeof(*filelist)); - filelist->path = g_strdup(path); filelist->entries = g_ptr_array_new(); return filelist; @@ -50,7 +49,6 @@ filelist_free(struct filelist *filelist) } g_ptr_array_free(filelist->entries, TRUE); - g_free(filelist->path); g_free(filelist); } diff --git a/src/filelist.h b/src/filelist.h index 3ad6cc2..6e13b23 100644 --- a/src/filelist.h +++ b/src/filelist.h @@ -30,15 +30,12 @@ typedef struct filelist_entry { } filelist_entry_t; typedef struct filelist { - /* path */ - gchar *path; - /* the list */ GPtrArray *entries; } mpdclient_filelist_t; struct filelist * -filelist_new(const char *path); +filelist_new(void); void filelist_free(struct filelist *filelist); diff --git a/src/mpdclient.c b/src/mpdclient.c index 42cc576..eaef01f 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -785,7 +785,7 @@ mpdclient_filelist_get(mpdclient_t *c, const gchar *path) mpd_InfoEntity *entity; mpd_sendLsInfoCommand(c->connection, path); - filelist = filelist_new(path); + filelist = filelist_new(); if (path && path[0] && strcmp(path, "/")) /* add a dummy entry for ./.. */ filelist_append(filelist, NULL); @@ -815,7 +815,7 @@ mpdclient_filelist_search(mpdclient_t *c, mpd_sendFindCommand(c->connection, table, filter_utf8); else mpd_sendSearchCommand(c->connection, table, filter_utf8); - filelist = filelist_new(NULL); + filelist = filelist_new(); while ((entity=mpd_getNextInfoEntity(c->connection))) filelist_append(filelist, entity); @@ -828,20 +828,6 @@ mpdclient_filelist_search(mpdclient_t *c, return filelist; } -mpdclient_filelist_t * -mpdclient_filelist_update(mpdclient_t *c, mpdclient_filelist_t *filelist) -{ - if (filelist != NULL) { - gchar *path = g_strdup(filelist->path); - - filelist_free(filelist); - filelist = mpdclient_filelist_get(c, path); - g_free(path); - return filelist; - } - return NULL; -} - int mpdclient_filelist_add_all(mpdclient_t *c, mpdclient_filelist_t *fl) { diff --git a/src/mpdclient.h b/src/mpdclient.h index 1abe2f6..a25c890 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -130,8 +130,6 @@ mpdclient_filelist_t *mpdclient_filelist_search(mpdclient_t *c, int exact_match, int table, gchar *filter_utf8); -mpdclient_filelist_t *mpdclient_filelist_update(mpdclient_t *c, - mpdclient_filelist_t *flist); /* add all songs in filelist to the playlist */ int mpdclient_filelist_add_all(mpdclient_t *c, mpdclient_filelist_t *fl); diff --git a/src/screen_artist.c b/src/screen_artist.c index be32dac..1dc300a 100644 --- a/src/screen_artist.c +++ b/src/screen_artist.c @@ -228,7 +228,7 @@ load_song_list(struct mpdclient *c) MPD_TABLE_ALBUM, album); if (browser.filelist == NULL) - browser.filelist = filelist_new(NULL); + browser.filelist = filelist_new(); /* add a dummy entry for ".." */ filelist_prepend(browser.filelist, NULL); diff --git a/src/screen_file.c b/src/screen_file.c index 9507272..00b505f 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -33,6 +33,7 @@ #include static struct screen_browser browser; +static char *current_path; static void browse_paint(void); @@ -51,12 +52,22 @@ file_repaint_if_active(void) file_repaint(); } +static void +file_reload(struct mpdclient *c) +{ + if (browser.filelist != NULL) + filelist_free(browser.filelist); + + browser.filelist = mpdclient_filelist_get(c, current_path); +} + /* the db has changed -> update the filelist */ static void file_changed_callback(mpdclient_t *c, G_GNUC_UNUSED int event, G_GNUC_UNUSED gpointer data) { - browser.filelist = mpdclient_filelist_update(c, browser.filelist); + file_reload(c); + #ifndef NCMPC_MINI sync_highlights(c, browser.filelist); #endif @@ -93,7 +104,7 @@ file_change_directory(mpdclient_t *c, filelist_entry_t *entry, if( entity==NULL ) { if( entry || 0==strcmp(new_path, "..") ) { /* return to parent */ - char *parent = g_path_get_dirname(browser.filelist->path); + char *parent = g_path_get_dirname(current_path); if( strcmp(parent, ".") == 0 ) parent[0] = '\0'; path = g_strdup(parent); @@ -109,13 +120,11 @@ file_change_directory(mpdclient_t *c, filelist_entry_t *entry, } else return false; - if (browser.filelist != NULL) { - old_path = g_strdup(browser.filelist->path); - filelist_free(browser.filelist); - } else - old_path = NULL; + old_path = current_path; + current_path = g_strdup(path); + + file_reload(c); - browser.filelist = mpdclient_filelist_get(c, path); #ifndef NCMPC_MINI sync_highlights(c, browser.filelist); #endif @@ -238,6 +247,8 @@ handle_delete(mpdclient_t *c) static void browse_init(WINDOW *w, int cols, int rows) { + current_path = g_strdup(""); + browser.lw = list_window_init(w, cols, rows); } @@ -254,6 +265,8 @@ browse_exit(void) if (browser.filelist) filelist_free(browser.filelist); list_window_free(browser.lw); + + g_free(current_path); } static void @@ -271,7 +284,7 @@ browse_open(G_GNUC_UNUSED mpdclient_t *c) static const char * browse_title(char *str, size_t size) { - const char *path = NULL, *prev = NULL, *slash = browser.filelist->path; + const char *path = NULL, *prev = NULL, *slash = current_path; char *path_locale; /* determine the last 2 parts of the path */ @@ -282,7 +295,7 @@ browse_title(char *str, size_t size) if (path == NULL) /* fall back to full path */ - path = browser.filelist->path; + path = current_path; path_locale = utf8_to_locale(path); g_snprintf(str, size, "%s: %s", @@ -303,8 +316,11 @@ browse_cmd(mpdclient_t *c, command_t cmd) { switch(cmd) { case CMD_PLAY: - if (file_handle_enter(c)) + if (file_handle_enter(c)) { + file_repaint(); return true; + } + break; case CMD_GO_ROOT_DIRECTORY: @@ -330,7 +346,7 @@ browse_cmd(mpdclient_t *c, command_t cmd) handle_save(c); break; case CMD_SCREEN_UPDATE: - browser.filelist = mpdclient_filelist_update(c, browser.filelist); + file_reload(c); #ifndef NCMPC_MINI sync_highlights(c, browser.filelist); #endif @@ -344,10 +360,10 @@ browse_cmd(mpdclient_t *c, command_t cmd) return true; if (!c->status->updatingDb) { - if (mpdclient_cmd_db_update(c, browser.filelist->path) == 0) { - if (strcmp(browser.filelist->path, "")) { + if (mpdclient_cmd_db_update(c, current_path) == 0) { + if (strcmp(current_path, "") != 0) { char *path_locale = - utf8_to_locale(browser.filelist->path); + utf8_to_locale(current_path); screen_status_printf(_("Database update of %s started"), path_locale); g_free(path_locale); diff --git a/src/screen_search.c b/src/screen_search.c index 00d1388..b8ebbd5 100644 --- a/src/screen_search.c +++ b/src/screen_search.c @@ -160,7 +160,7 @@ search_clear(mpdclient_t *c, if (browser.filelist) { mpdclient_remove_playlist_callback(c, playlist_changed_callback); filelist_free(browser.filelist); - browser.filelist = filelist_new(NULL); + browser.filelist = filelist_new(); } if (clear_pattern && pattern) { g_free(pattern); @@ -179,7 +179,7 @@ filelist_search(mpdclient_t *c, G_GNUC_UNUSED int exact_match, int table, list = mpdclient_filelist_search(c, FALSE, MPD_TABLE_ARTIST, filter_utf8); if (list == NULL) - list = filelist_new(NULL); + list = filelist_new(); list2 = mpdclient_filelist_search(c, FALSE, MPD_TABLE_TITLE, filter_utf8); @@ -192,7 +192,7 @@ filelist_search(mpdclient_t *c, G_GNUC_UNUSED int exact_match, int table, } else { list = mpdclient_filelist_search(c, FALSE, table, filter_utf8); if (list == NULL) - list = filelist_new(NULL); + list = filelist_new(); } g_free(filter_utf8); @@ -278,7 +278,7 @@ search_advanced_query(char *query, mpdclient_t *c) mpd_commitSearch(c->connection); - fl = filelist_new(NULL); + fl = filelist_new(); while ((entity=mpd_getNextInfoEntity(c->connection))) filelist_append(fl, entity); @@ -325,7 +325,7 @@ search_new(mpdclient_t *c) pattern); if (browser.filelist == NULL) - browser.filelist = filelist_new(NULL); + browser.filelist = filelist_new(); sync_highlights(c, browser.filelist); mpdclient_install_playlist_callback(c, playlist_changed_callback);