From 41ab418ed2d6de02ade2c4ee6c1bf99956affcf9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 17 Mar 2017 22:14:11 +0100 Subject: [PATCH] screen_client: move functions to callbacks.c --- Makefile.am | 1 + src/callbacks.c | 69 +++++++++++++++++++++++++++++++++++++++++++++ src/callbacks.h | 37 ++++++++++++++++++++++++ src/mpdclient.c | 2 +- src/mpdclient.h | 7 ----- src/screen_client.c | 46 ------------------------------ 6 files changed, 108 insertions(+), 54 deletions(-) create mode 100644 src/callbacks.c create mode 100644 src/callbacks.h diff --git a/Makefile.am b/Makefile.am index f808ec6..cf10d00 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 0000000..dd5d15b --- /dev/null +++ b/src/callbacks.c @@ -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 index 0000000..2dbe9ba --- /dev/null +++ b/src/callbacks.h @@ -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 + +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 diff --git a/src/mpdclient.c b/src/mpdclient.c index 164a08d..7ef34d2 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -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" diff --git a/src/mpdclient.h b/src/mpdclient.h index f2204fb..f7ec926 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -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 diff --git a/src/screen_client.c b/src/screen_client.c index 7bde290..f291c7c 100644 --- a/src/screen_client.c +++ b/src/screen_client.c @@ -18,57 +18,11 @@ */ #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) { -- 2.30.2