summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 129559c)
raw | patch | inline | side by side (parent: 129559c)
author | Max Kellermann <max@duempel.org> | |
Sun, 13 Sep 2009 09:06:07 +0000 (11:06 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Sun, 13 Sep 2009 09:06:07 +0000 (11:06 +0200) |
Callers should track their current path manually, instead of relying
on an the filelist object.
on an the filelist object.
diff --git a/src/filelist.c b/src/filelist.c
index 100db88b7458e004ff2164f1ce7c4307ee747956..e3e1cb1636668e49c26c0624180903eebdf90b47 100644 (file)
--- a/src/filelist.c
+++ b/src/filelist.c
#include <assert.h>
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;
}
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 3ad6cc2acbe72305d791a7b7121d3e819f9a6c30..6e13b23e5979b9e5e4d745d3c9a3fde60b867ec9 100644 (file)
--- a/src/filelist.h
+++ b/src/filelist.h
} 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 42cc576d3a31e297543f27b371f77d372a1df015..eaef01f65399208d360c208535fa6fb2fc3d5bcd 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
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);
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);
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 1abe2f6bc7ab1350b8f04f04e5d024daf7919245..a25c890cb4f04ff7fd758b422dfecea3240ad9bd 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
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 be32dacb4ba7f0c7e20ef25d6f686f193c9cd335..1dc300a9d24394612972dd74c3abba32052ba497 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.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 9507272f376922d1bc7e93e0d7499798f105870e..00b505f9b909cc82d3df6a8a08e8fe2ed38e71b0 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
#include <glib.h>
static struct screen_browser browser;
+static char *current_path;
static void
browse_paint(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
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);
} 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
static void
browse_init(WINDOW *w, int cols, int rows)
{
+ current_path = g_strdup("");
+
browser.lw = list_window_init(w, cols, rows);
}
if (browser.filelist)
filelist_free(browser.filelist);
list_window_free(browser.lw);
+
+ g_free(current_path);
}
static void
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 */
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",
{
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:
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
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 00d1388ceb6f425067495c1fda3d2bd9dcd0cffc..b8ebbd50927bfcbf9ba49180046b3020cc4f45e1 100644 (file)
--- a/src/screen_search.c
+++ b/src/screen_search.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);
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);
} else {
list = mpdclient_filelist_search(c, FALSE, table, filter_utf8);
if (list == NULL)
- list = filelist_new(NULL);
+ list = filelist_new();
}
g_free(filter_utf8);
mpd_commitSearch(c->connection);
- fl = filelist_new(NULL);
+ fl = filelist_new();
while ((entity=mpd_getNextInfoEntity(c->connection)))
filelist_append(fl, entity);
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);