Code

screen_browser: added browser_cmd()
authorMax Kellermann <max@duempel.org>
Thu, 2 Oct 2008 13:20:18 +0000 (15:20 +0200)
committerMax Kellermann <max@duempel.org>
Thu, 2 Oct 2008 13:20:18 +0000 (15:20 +0200)
Merge a lot of code from the 3 browser screen into browser_cmd().

src/screen_artist.c
src/screen_browser.c
src/screen_browser.h
src/screen_file.c
src/screen_search.c

index c9c6f9b019a1acc4e569f8aebe8cc07d361f2796..972de8f455b0af121a17eabc1bdbf737ab91b458 100644 (file)
@@ -427,7 +427,7 @@ metalist_length(void)
 }
 
 static int
-artist_lw_cmd(command_t cmd)
+artist_lw_cmd(struct screen *screen, struct mpdclient *c, command_t cmd)
 {
        switch (mode) {
        case LIST_ARTISTS:
@@ -435,9 +435,7 @@ artist_lw_cmd(command_t cmd)
                return list_window_cmd(browser.lw, metalist_length(), cmd);
 
        case LIST_SONGS:
-               return list_window_cmd(browser.lw,
-                                      filelist_length(browser.filelist),
-                                      cmd);
+               return browser_cmd(&browser, screen, c, cmd);
        }
 
        assert(0);
@@ -448,7 +446,6 @@ static int
 artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
 {
        char *selected;
-       int ret;
 
        switch(cmd) {
        case CMD_PLAY:
@@ -460,7 +457,7 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
                        list_window_push_state(browser.lw_state, browser.lw);
 
                        artist_repaint();
-                       break;
+                       return true;
 
                case LIST_ALBUMS:
                        if (browser.lw->selected == 0) {
@@ -483,7 +480,7 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
                        }
 
                        artist_repaint();
-                       break;
+                       return true;
 
                case LIST_SONGS:
                        if (browser.lw->selected == 0) {
@@ -496,12 +493,11 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
                                                      browser.lw);
 
                                artist_repaint();
-                       } else
-                               browser_handle_enter(&browser, c);
+                               return true;
+                       }
                        break;
                }
-               return 1;
-
+               break;
 
                /* FIXME? CMD_GO_* handling duplicates code from CMD_PLAY */
 
@@ -567,12 +563,7 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
                        break;
 
                case LIST_SONGS:
-                       ret = cmd == CMD_SELECT
-                               ? browser_handle_select(&browser, c)
-                               : browser_handle_add(&browser, c);
-                       if (ret == 0)
-                               /* continue and select next item... */
-                               cmd = CMD_LIST_NEXT;
+                       /* handled by browser_cmd() */
                        break;
                }
                break;
@@ -592,34 +583,28 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
                        screen_find(screen,
                                    browser.lw, artist_list->len,
                                    cmd, artist_lw_callback, artist_list);
-                       break;
+                       artist_repaint();
+                       return 1;
 
                case LIST_ALBUMS:
                        screen_find(screen,
                                    browser.lw, album_list->len + 2,
                                    cmd, artist_lw_callback, album_list);
-                       break;
+                       artist_repaint();
+                       return 1;
 
                case LIST_SONGS:
-                       screen_find(screen,
-                                   browser.lw,
-                                   filelist_length(browser.filelist),
-                                   cmd, browser_lw_callback,
-                                   browser.filelist);
+                       /* handled by browser_cmd() */
                        break;
                }
 
-               artist_repaint();
-               return 1;
-
-       case CMD_MOUSE_EVENT:
-               return browser_handle_mouse_event(&browser, c);
+               break;
 
        default:
                break;
        }
 
-       if (artist_lw_cmd(cmd)) {
+       if (artist_lw_cmd(screen, c, cmd)) {
                artist_repaint();
                return 1;
        }
index bad13ea0294bb3a7bb48030f629904a0bd9da335..d7dea635e320a3ad903e96a48c15de1e2d30f2fe 100644 (file)
@@ -451,3 +451,56 @@ browser_handle_mouse_event(struct screen_browser *browser, mpdclient_t *c)
 }
 #endif
 
+bool
+browser_cmd(struct screen_browser *browser, struct screen *screen,
+           struct mpdclient *c, command_t cmd)
+{
+       switch (cmd) {
+       case CMD_PLAY:
+               browser_handle_enter(browser, c);
+               return true;
+
+       case CMD_SELECT:
+               if (browser_handle_select(browser, c) == 0)
+                       /* continue and select next item... */
+                       cmd = CMD_LIST_NEXT;
+
+               /* call list_window_cmd to go to the next item */
+               break;
+
+       case CMD_ADD:
+               if (browser_handle_add(browser, c) == 0)
+                       /* continue and select next item... */
+                       cmd = CMD_LIST_NEXT;
+
+               /* call list_window_cmd to go to the next item */
+               break;
+
+       case CMD_SELECT_ALL:
+               browser_handle_select_all(browser, c);
+               return true;
+
+       case CMD_LIST_FIND:
+       case CMD_LIST_RFIND:
+       case CMD_LIST_FIND_NEXT:
+       case CMD_LIST_RFIND_NEXT:
+               screen_find(screen,
+                           browser->lw, filelist_length(browser->filelist),
+                           cmd, browser_lw_callback,
+                           browser->filelist);
+               return true;
+
+       case CMD_MOUSE_EVENT:
+               browser_handle_mouse_event(browser, c);
+               return true;
+
+       default:
+               break;
+       }
+
+       if (list_window_cmd(browser->lw, filelist_length(browser->filelist),
+                           cmd))
+               return true;
+
+       return false;
+}
index 5441f41c758ae3d1385ed23c3f1d424f2e4c8b89..eb1133610b4a8b794d8f08e948c5d065cf07ef4e 100644 (file)
@@ -26,6 +26,8 @@
 #include "mpdclient.h"
 #include "config.h"
 
+#include <stdbool.h>
+
 struct list_window;
 struct list_window_state;
 
@@ -67,4 +69,8 @@ int browser_handle_mouse_event(struct screen_browser *browser, mpdclient_t *c);
 #define browser_handle_mouse_event(browser, c) (0)
 #endif
 
+bool
+browser_cmd(struct screen_browser *browser, struct screen *screen,
+           struct mpdclient *c, command_t cmd);
+
 #endif
index 3870cbdc7e9165cc89070deb9084a4fd11818bcf..d12f77ef52b1ca5e57b5d66e463105a2048c4d76 100644 (file)
@@ -205,10 +205,6 @@ static int
 browse_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
 {
        switch(cmd) {
-       case CMD_PLAY:
-               browser_handle_enter(&browser, c);
-               file_repaint();
-               return 1;
        case CMD_GO_ROOT_DIRECTORY:
                browser_change_directory(&browser, c, NULL, "");
                file_repaint();
@@ -217,18 +213,6 @@ browse_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
                browser_change_directory(&browser, c, NULL, "..");
                file_repaint();
                return 1;
-       case CMD_SELECT:
-               if (browser_handle_select(&browser, c) == 0) {
-                       /* continue and select next item... */
-                       cmd = CMD_LIST_NEXT;
-               }
-               break;
-
-       case CMD_ADD:
-               if (browser_handle_add(&browser, c) == 0)
-                       /* continue and select next item... */
-                       cmd = CMD_LIST_NEXT;
-               break;
 
        case CMD_DELETE:
                handle_delete(screen, c);
@@ -266,29 +250,12 @@ browse_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
                } else
                        screen_status_printf(_("Database update running..."));
                return 1;
-       case CMD_LIST_FIND:
-       case CMD_LIST_RFIND:
-       case CMD_LIST_FIND_NEXT:
-       case CMD_LIST_RFIND_NEXT:
-               screen_find(screen,
-                           browser.lw, filelist_length(browser.filelist),
-                           cmd, browser_lw_callback,
-                           browser.filelist);
-               file_repaint();
-               return 1;
-
-       case CMD_MOUSE_EVENT:
-               if (browser_handle_mouse_event(&browser, c))
-                       file_repaint();
-
-               return 1;
 
        default:
                break;
        }
 
-       if (list_window_cmd(browser.lw, filelist_length(browser.filelist),
-                           cmd)) {
+       if (browser_cmd(&browser, screen, c, cmd)) {
                file_repaint();
                return 1;
        }
index 981c0a58bc4a1e332f09ff4d4314b2d2740277dc..b7020c04397ecae1dde586ff35bfbff3bfce9b4f 100644 (file)
@@ -432,32 +432,6 @@ static int
 search_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
 {
        switch (cmd) {
-       case CMD_PLAY:
-               browser_handle_enter(&browser, c);
-               search_repaint();
-               return 1;
-
-       case CMD_SELECT:
-               if (browser_handle_select(&browser, c) == 0) {
-                       /* continue and select next item... */
-                       cmd = CMD_LIST_NEXT;
-               }
-               /* call list_window_cmd to go to the next item */
-               break;
-
-       case CMD_ADD:
-               if (browser_handle_add(&browser, c) == 0)
-                       /* continue and select next item... */
-                       cmd = CMD_LIST_NEXT;
-
-               /* call list_window_cmd to go to the next item */
-               break;
-
-       case CMD_SELECT_ALL:
-               browser_handle_select_all(&browser, c);
-               search_repaint();
-               return 0;
-
        case CMD_SEARCH_MODE:
                options.search_mode++;
                if (mode[options.search_mode].label == NULL)
@@ -488,32 +462,12 @@ search_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
                search_repaint();
                return 1;
 
-       case CMD_LIST_FIND:
-       case CMD_LIST_RFIND:
-       case CMD_LIST_FIND_NEXT:
-       case CMD_LIST_RFIND_NEXT:
-               if (browser.filelist) {
-                       screen_find(screen,
-                                   browser.lw, filelist_length(browser.filelist),
-                                   cmd, browser_lw_callback,
-                                   browser.filelist);
-                       search_repaint();
-               }
-
-               return 1;
-
-       case CMD_MOUSE_EVENT:
-               browser_handle_mouse_event(&browser, c);
-               search_repaint();
-               return 1;
-
        default:
                break;
        }
 
        if (browser.filelist != NULL &&
-           list_window_cmd(browser.lw,
-                           filelist_length(browser.filelist), cmd)) {
+           browser_cmd(&browser, screen, c, cmd)) {
                search_repaint();
                return 1;
        }