Code

filelist: removed "path" attribute
authorMax Kellermann <max@duempel.org>
Sun, 13 Sep 2009 09:06:07 +0000 (11:06 +0200)
committerMax 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.

src/filelist.c
src/filelist.h
src/mpdclient.c
src/mpdclient.h
src/screen_artist.c
src/screen_file.c
src/screen_search.c

index 100db88b7458e004ff2164f1ce7c4307ee747956..e3e1cb1636668e49c26c0624180903eebdf90b47 100644 (file)
 #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;
@@ -50,7 +49,6 @@ filelist_free(struct filelist *filelist)
        }
 
        g_ptr_array_free(filelist->entries, TRUE);
-       g_free(filelist->path);
        g_free(filelist);
 }
 
index 3ad6cc2acbe72305d791a7b7121d3e819f9a6c30..6e13b23e5979b9e5e4d745d3c9a3fde60b867ec9 100644 (file)
@@ -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);
index 42cc576d3a31e297543f27b371f77d372a1df015..eaef01f65399208d360c208535fa6fb2fc3d5bcd 100644 (file)
@@ -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)
 {
index 1abe2f6bc7ab1350b8f04f04e5d024daf7919245..a25c890cb4f04ff7fd758b422dfecea3240ad9bd 100644 (file)
@@ -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);
index be32dacb4ba7f0c7e20ef25d6f686f193c9cd335..1dc300a9d24394612972dd74c3abba32052ba497 100644 (file)
@@ -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);
index 9507272f376922d1bc7e93e0d7499798f105870e..00b505f9b909cc82d3df6a8a08e8fe2ed38e71b0 100644 (file)
@@ -33,6 +33,7 @@
 #include <glib.h>
 
 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);
index 00d1388ceb6f425067495c1fda3d2bd9dcd0cffc..b8ebbd50927bfcbf9ba49180046b3020cc4f45e1 100644 (file)
@@ -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);