Code

screen_play: check connection in screen_playlist_cmd()
authorMax Kellermann <max@duempel.org>
Thu, 1 Oct 2009 21:51:04 +0000 (23:51 +0200)
committerMax Kellermann <max@duempel.org>
Thu, 1 Oct 2009 21:51:04 +0000 (23:51 +0200)
src/screen_play.c

index 4503c37b062efac3bb23e7b3c012c199784ba60c..3adcb6dfd9b6ba2b55da8445fc4f10acc9fba342 100644 (file)
@@ -654,10 +654,80 @@ screen_playlist_cmd(struct mpdclient *c, command_t cmd)
                return true;
        }
 
+       switch(cmd) {
+       case CMD_SCREEN_UPDATE:
+               center_playing_item(c, prev_cmd == CMD_SCREEN_UPDATE);
+               playlist_repaint();
+               return false;
+       case CMD_SELECT_PLAYING:
+               list_window_set_selected(lw, playlist_get_index(&c->playlist,
+                                                               c->song));
+               playlist_save_selection();
+               return true;
+
+       case CMD_LIST_FIND:
+       case CMD_LIST_RFIND:
+       case CMD_LIST_FIND_NEXT:
+       case CMD_LIST_RFIND_NEXT:
+               screen_find(lw, playlist_length(&c->playlist),
+                           cmd, list_callback, NULL);
+               playlist_save_selection();
+               playlist_repaint();
+               return true;
+       case CMD_LIST_JUMP:
+               screen_jump(lw, list_callback, NULL);
+               playlist_save_selection();
+               playlist_repaint();
+               return true;
+
+#ifdef HAVE_GETMOUSE
+       case CMD_MOUSE_EVENT:
+               return handle_mouse_event(c);
+#endif
+
+#ifdef ENABLE_SONG_SCREEN
+       case CMD_SCREEN_SONG:
+               if (playlist_selected_song()) {
+                       screen_song_switch(c, playlist_selected_song());
+                       return true;
+               }
+
+               break;
+#endif
+
+#ifdef ENABLE_LYRICS_SCREEN
+       case CMD_SCREEN_LYRICS:
+               if (lw->selected < playlist_length(&c->playlist)) {
+                       struct mpd_song *selected = playlist_get(&c->playlist, lw->selected);
+                       bool follow = false;
+
+                       if (c->song && selected &&
+                           !strcmp(mpd_song_get_uri(selected),
+                                   mpd_song_get_uri(c->song)))
+                               follow = true;
+
+                       screen_lyrics_switch(c, selected, follow);
+                       return true;
+               }
+
+               break;
+#endif
+       case CMD_SCREEN_SWAP:
+               screen_swap(c, playlist_get(&c->playlist, lw->selected));
+               return true;
+
+       default:
+               break;
+       }
+
+       if (!mpdclient_is_connected(c))
+               return false;
+
        switch(cmd) {
        case CMD_PLAY:
                mpdclient_cmd_play(c, lw->selected);
                return true;
+
        case CMD_DELETE:
                if (lw->range_selection) {
                        mpdclient_cmd_delete_range(c, lw->selected_start,
@@ -673,18 +743,11 @@ screen_playlist_cmd(struct mpdclient *c, command_t cmd)
        case CMD_SAVE_PLAYLIST:
                playlist_save(c, NULL, NULL);
                return true;
+
        case CMD_ADD:
                handle_add_to_playlist(c);
                return true;
-       case CMD_SCREEN_UPDATE:
-               center_playing_item(c, prev_cmd == CMD_SCREEN_UPDATE);
-               playlist_repaint();
-               return false;
-       case CMD_SELECT_PLAYING:
-               list_window_set_selected(lw, playlist_get_index(&c->playlist,
-                                                               c->song));
-               playlist_save_selection();
-               return true;
+
        case CMD_SHUFFLE:
        {
                if(!lw->range_selection)
@@ -698,6 +761,7 @@ screen_playlist_cmd(struct mpdclient *c, command_t cmd)
                        mpdclient_handle_error(c);
                return true;
        }
+
        case CMD_LIST_MOVE_UP:
                if(lw->selected_start == 0)
                        return false;
@@ -722,6 +786,7 @@ screen_playlist_cmd(struct mpdclient *c, command_t cmd)
 
                playlist_save_selection();
                return true;
+
        case CMD_LIST_MOVE_DOWN:
                if(lw->selected_end+1 >= playlist_length(&c->playlist))
                        return false;
@@ -746,35 +811,6 @@ screen_playlist_cmd(struct mpdclient *c, command_t cmd)
 
                playlist_save_selection();
                return true;
-       case CMD_LIST_FIND:
-       case CMD_LIST_RFIND:
-       case CMD_LIST_FIND_NEXT:
-       case CMD_LIST_RFIND_NEXT:
-               screen_find(lw, playlist_length(&c->playlist),
-                           cmd, list_callback, NULL);
-               playlist_save_selection();
-               playlist_repaint();
-               return true;
-       case CMD_LIST_JUMP:
-               screen_jump(lw, list_callback, NULL);
-               playlist_save_selection();
-               playlist_repaint();
-               return true;
-
-#ifdef HAVE_GETMOUSE
-       case CMD_MOUSE_EVENT:
-               return handle_mouse_event(c);
-#endif
-
-#ifdef ENABLE_SONG_SCREEN
-       case CMD_SCREEN_SONG:
-               if (playlist_selected_song()) {
-                       screen_song_switch(c, playlist_selected_song());
-                       return true;
-               }
-
-               break;
-#endif
 
        case CMD_LOCATE:
                if (playlist_selected_song()) {
@@ -784,27 +820,6 @@ screen_playlist_cmd(struct mpdclient *c, command_t cmd)
 
                break;
 
-#ifdef ENABLE_LYRICS_SCREEN
-       case CMD_SCREEN_LYRICS:
-               if (lw->selected < playlist_length(&c->playlist)) {
-                       struct mpd_song *selected = playlist_get(&c->playlist, lw->selected);
-                       bool follow = false;
-
-                       if (c->song && selected &&
-                           !strcmp(mpd_song_get_uri(selected),
-                                   mpd_song_get_uri(c->song)))
-                               follow = true;
-
-                       screen_lyrics_switch(c, selected, follow);
-                       return true;
-               }
-
-               break;
-#endif
-       case CMD_SCREEN_SWAP:
-               screen_swap(c, playlist_get(&c->playlist, lw->selected));
-               return true;
-
        default:
                break;
        }