Code

screen_client: move functions to callbacks.c
authorMax Kellermann <max.kellermann@gmail.com>
Fri, 17 Mar 2017 21:14:11 +0000 (22:14 +0100)
committerMax Kellermann <max.kellermann@gmail.com>
Fri, 17 Mar 2017 21:41:26 +0000 (22:41 +0100)
Makefile.am
src/callbacks.c [new file with mode: 0644]
src/callbacks.h [new file with mode: 0644]
src/mpdclient.c
src/mpdclient.h
src/screen_client.c

index f808ec63d396febd5d2dda357022171ece06476d..cf10d00ce431b3b9722bc8b0c90b4a77bbdd21bf 100644 (file)
@@ -28,6 +28,7 @@ src_ncmpc_SOURCES = \
        src/main.c \
        src/gidle.c src/gidle.h \
        src/mpdclient.c src/mpdclient.h \
+       src/callbacks.c src/callbacks.h \
        src/playlist.c src/playlist.h \
        src/filelist.c src/filelist.h \
        src/options.c src/options.h \
diff --git a/src/callbacks.c b/src/callbacks.c
new file mode 100644 (file)
index 0000000..dd5d15b
--- /dev/null
@@ -0,0 +1,69 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2017 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "callbacks.h"
+#include "screen_utils.h"
+#include "screen_status.h"
+#include "mpdclient.h"
+#include "charset.h"
+
+static bool
+_screen_auth(struct mpdclient *c, gint recursion)
+{
+       struct mpd_connection *connection = mpdclient_get_connection(c);
+       if (connection == NULL)
+               return false;
+
+       mpd_connection_clear_error(connection);
+       if (recursion > 2)
+               return false;
+
+       char *password = screen_read_password(NULL);
+       if (password == NULL)
+               return false;
+
+       mpd_send_password(connection, password);
+       g_free(password);
+
+       mpd_response_finish(connection);
+       mpdclient_update(c);
+
+       if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
+           mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_PASSWORD)
+               return  _screen_auth(c, ++recursion);
+
+       return true;
+}
+
+bool
+screen_auth(struct mpdclient *c)
+{
+       return _screen_auth(c, 0);
+}
+
+void
+mpdclient_ui_error(const char *message_utf8)
+{
+       char *message_locale = utf8_to_locale(message_utf8);
+       screen_status_printf("%s", message_locale);
+       g_free(message_locale);
+
+       screen_bell();
+       doupdate();
+}
diff --git a/src/callbacks.h b/src/callbacks.h
new file mode 100644 (file)
index 0000000..2dbe9ba
--- /dev/null
@@ -0,0 +1,37 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2017 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef NCMPC_CALLBACKS_H
+#define NCMPC_CALLBACKS_H
+
+#include <stdbool.h>
+
+struct mpdclient;
+
+/**
+ * To be implemented by the application: mpdclient.c calls this to
+ * display an error message.
+ */
+void
+mpdclient_ui_error(const char *message);
+
+bool
+screen_auth(struct mpdclient *c);
+
+#endif
index 164a08dd927e40b121072929610ef875125c9c1d..7ef34d2a592f0fd3f9e47ff1e9bb61fbcf913f11 100644 (file)
@@ -18,8 +18,8 @@
  */
 
 #include "mpdclient.h"
+#include "callbacks.h"
 #include "filelist.h"
-#include "screen_client.h"
 #include "config.h"
 #include "options.h"
 #include "strfsong.h"
index f2204fb4a44230d6c8091ea3b973dc529a008beb..f7ec9260e3dfea229025232557e2f6862619199d 100644 (file)
@@ -124,13 +124,6 @@ mpdclient_get_connection(struct mpdclient *c);
 void
 mpdclient_put_connection(struct mpdclient *c);
 
-/**
- * To be implemented by the application: mpdclient.c calls this to
- * display an error message.
- */
-void
-mpdclient_ui_error(const char *message);
-
 /*** MPD Commands  **********************************************************/
 
 bool
index 7bde290e54160877fb5b0e956f5b8e7c624f1a2e..f291c7c57380b21bcf842aadf3001046114a599d 100644 (file)
  */
 
 #include "screen_client.h"
-#include "screen_utils.h"
 #include "screen_status.h"
 #include "mpdclient.h"
 #include "i18n.h"
 #include "charset.h"
 
-static bool
-_screen_auth(struct mpdclient *c, gint recursion)
-{
-       struct mpd_connection *connection = mpdclient_get_connection(c);
-       if (connection == NULL)
-               return false;
-
-       mpd_connection_clear_error(connection);
-       if (recursion > 2)
-               return false;
-
-       char *password = screen_read_password(NULL);
-       if (password == NULL)
-               return false;
-
-       mpd_send_password(connection, password);
-       g_free(password);
-
-       mpd_response_finish(connection);
-       mpdclient_update(c);
-
-       if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
-           mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_PASSWORD)
-               return  _screen_auth(c, ++recursion);
-
-       return true;
-}
-
-bool
-screen_auth(struct mpdclient *c)
-{
-       return _screen_auth(c, 0);
-}
-
-void
-mpdclient_ui_error(const char *message_utf8)
-{
-       char *message_locale = utf8_to_locale(message_utf8);
-       screen_status_printf("%s", message_locale);
-       g_free(message_locale);
-
-       screen_bell();
-       doupdate();
-}
-
 void
 screen_database_update(struct mpdclient *c, const char *path)
 {