Code

browser: added function browser_get_selected()
authorMax Kellermann <max@duempel.org>
Fri, 19 Sep 2008 14:24:37 +0000 (16:24 +0200)
committerMax Kellermann <max@duempel.org>
Fri, 19 Sep 2008 14:24:37 +0000 (16:24 +0200)
browser_get_selected() checks if there is a file list and a valid
selection, and returns the selected entry.

src/screen_browser.c

index 40c63998062d32b48d6d29edefe29a8566a3c1b4..b01e70c7ac68e580e14e40c5c523e46c9c9579bf 100644 (file)
@@ -247,16 +247,21 @@ enqueue_and_play(mpdclient_t *c, filelist_entry_t *entry)
        return 0;
 }
 
+static struct filelist_entry *
+browser_get_selected(const struct screen_browser *browser)
+{
+       if (browser->filelist == NULL)
+               return NULL;
+
+       return filelist_get(browser->filelist, browser->lw->selected);
+}
+
 int
 browser_handle_enter(struct screen_browser *browser, mpdclient_t *c)
 {
-       filelist_entry_t *entry;
+       struct filelist_entry *entry = browser_get_selected(browser);
        mpd_InfoEntity *entity;
 
-       if (browser->filelist == NULL)
-               return -1;
-
-       entry = filelist_get(browser->filelist, browser->lw->selected);
        if( entry==NULL )
                return -1;
 
@@ -379,11 +384,8 @@ browser_select_entry(mpdclient_t *c, filelist_entry_t *entry,
 int
 browser_handle_select(struct screen_browser *browser, mpdclient_t *c)
 {
-       filelist_entry_t *entry;
+       struct filelist_entry *entry = browser_get_selected(browser);
 
-       if (browser->filelist == NULL)
-               return -1;
-       entry = filelist_get(browser->filelist, browser->lw->selected);
        if (entry == NULL || entry->entity == NULL)
                return -1;