Code

screen_file: moved update code to screen_client.c
authorMax Kellermann <max@duempel.org>
Tue, 29 Sep 2009 18:57:27 +0000 (20:57 +0200)
committerMax Kellermann <max@duempel.org>
Tue, 29 Sep 2009 18:57:27 +0000 (20:57 +0200)
Moved code from screen_file.c and player_command.c.

src/player_command.c
src/screen_client.c
src/screen_client.h
src/screen_file.c

index dab3d525def6462bea0943296843f58a1dd5969c..678d13a07343232d380ee004dd891ebefa6351fc 100644 (file)
@@ -22,6 +22,7 @@
 #include "options.h"
 #include "screen.h"
 #include "i18n.h"
+#include "screen_client.h"
 
 #define IS_PLAYING(s) (s==MPD_STATE_PLAY)
 #define IS_PAUSED(s) (s==MPD_STATE_PAUSE)
@@ -159,11 +160,7 @@ handle_player_command(struct mpdclient *c, command_t cmd)
                        mpdclient_cmd_crossfade(c, options.crossfade_time);
                break;
        case CMD_DB_UPDATE:
-               if (!mpd_status_get_update_id(c->status)) {
-                       if( mpdclient_cmd_db_update(c,NULL)==0 )
-                               screen_status_printf(_("Database update started"));
-               } else
-                       screen_status_printf(_("Database update running..."));
+               screen_database_update(c, NULL);
                break;
        case CMD_VOLUME_UP:
                mpdclient_cmd_volume_up(c);
index 7583e8a15e476d434a6f1c62dd507ee483acdf48..b5b31b5256b475e058d99b70e496be9d106e8183 100644 (file)
 
 #include "screen_client.h"
 #include "screen_utils.h"
+#include "screen.h"
 #include "mpdclient.h"
+#include "i18n.h"
+#include "charset.h"
 
 static bool
 _screen_auth(struct mpdclient *c, gint recursion)
@@ -52,3 +55,26 @@ screen_auth(struct mpdclient *c)
 {
        return _screen_auth(c, 0);
 }
+
+void
+screen_database_update(struct mpdclient *c, const char *path)
+{
+       assert(c != NULL);
+       assert(c->connection != NULL);
+       assert(c->status != NULL);
+
+       if (mpd_status_get_update_id(c->status) != 0) {
+               screen_status_printf(_("Database update running..."));
+               return;
+       }
+
+       if (mpdclient_cmd_db_update(c, path) != 0)
+               return;
+
+       if (path != NULL && *path != 0) {
+               char *path_locale = utf8_to_locale(path);
+               screen_status_printf(_("Database update of %s started"), path);
+               g_free(path_locale);
+       } else
+               screen_status_message(_("Database update started"));
+}
index 9b419d148e175ddf84b86de383e56f95217cab9b..e98f7721777c90f165ed1d75a86a54039244e113 100644 (file)
@@ -27,4 +27,11 @@ struct mpdclient;
 bool
 screen_auth(struct mpdclient *c);
 
+/**
+ * Starts a (server-side) database update and displays a status
+ * message.
+ */
+void
+screen_database_update(struct mpdclient *c, const char *path);
+
 #endif
index ed3d26a2610bba51ed1364fab640da84792566e1..a9d5e6a7ad3346e6939c3aae61345a1b2efc1237 100644 (file)
@@ -28,6 +28,7 @@
 #include "screen_utils.h"
 #include "screen_browser.h"
 #include "screen_play.h"
+#include "screen_client.h"
 
 #include <mpd/client.h>
 
@@ -374,19 +375,7 @@ browse_cmd(struct mpdclient *c, command_t cmd)
                if (c->status == NULL)
                        return true;
 
-               if (mpd_status_get_update_id(c->status) == 0) {
-                       if (mpdclient_cmd_db_update(c, current_path) == 0) {
-                               if (strcmp(current_path, "")) {
-                                       char *path_locale =
-                                               utf8_to_locale(current_path);
-                                       screen_status_printf(_("Database update of %s started"),
-                                                            path_locale);
-                                       g_free(path_locale);
-                               } else
-                                       screen_status_printf(_("Database update started"));
-                       }
-               } else
-                       screen_status_printf(_("Database update running..."));
+               screen_database_update(c, current_path);
                return true;
 
        default: