Code

screen_utils: moved screen_auth() to screen_client.c
authorMax Kellermann <max@duempel.org>
Tue, 29 Sep 2009 18:36:05 +0000 (20:36 +0200)
committerMax Kellermann <max@duempel.org>
Tue, 29 Sep 2009 18:36:05 +0000 (20:36 +0200)
screen_client.c is a new library for MPD specific screen functions.

Makefile.am
src/mpdclient.c
src/screen_client.c [new file with mode: 0644]
src/screen_client.h [new file with mode: 0644]
src/screen_utils.c
src/screen_utils.h

index a39d435dfaa7bcc6e77a64eeff159f16c5071b8d..995d01f9bd8a8bb602bc47629e1de3a07373cdaf 100644 (file)
@@ -25,6 +25,7 @@ ncmpc_headers = \
        src/screen_list.h \
        src/screen_play.h \
        src/screen_utils.h \
+       src/screen_client.h \
        src/list_window.h \
        src/colors.h \
        src/hscroll.h \
@@ -64,6 +65,7 @@ src_ncmpc_SOURCES = \
        src/screen.c \
        src/screen_list.c \
        src/screen_utils.c \
+       src/screen_client.c \
        src/screen_play.c \
        src/screen_browser.c \
        src/screen_file.c \
index 1728303c52e4c97595971fff9a7a1876b74c04fb..1434d172acd62f926c1acd630d455a3f2d62a6d0 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "mpdclient.h"
 #include "filelist.h"
-#include "screen_utils.h"
+#include "screen_client.h"
 #include "config.h"
 #include "options.h"
 #include "strfsong.h"
diff --git a/src/screen_client.c b/src/screen_client.c
new file mode 100644 (file)
index 0000000..e4cc7cd
--- /dev/null
@@ -0,0 +1,56 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2009 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 "screen_client.h"
+#include "screen_utils.h"
+#include "mpdclient.h"
+
+static gint
+_screen_auth(struct mpdclient *c, gint recursion)
+{
+       char *password;
+
+       mpd_connection_clear_error(c->connection);
+       if (recursion > 2)
+               return 1;
+
+       password = screen_read_password(NULL, NULL);
+       if (password == NULL)
+               return 1;
+
+       mpd_send_password(c->connection, password);
+       g_free(password);
+
+       mpd_response_finish(c->connection);
+       mpdclient_update(c);
+
+       if (mpd_connection_get_error(c->connection) == MPD_ERROR_SERVER &&
+           mpd_connection_get_server_error(c->connection) == MPD_SERVER_ERROR_PASSWORD)
+               return  _screen_auth(c, ++recursion);
+       return 0;
+}
+
+gint
+screen_auth(struct mpdclient *c)
+{
+       gint ret = _screen_auth(c, 0);
+       mpdclient_update(c);
+       curs_set(0);
+       return ret;
+}
diff --git a/src/screen_client.h b/src/screen_client.h
new file mode 100644 (file)
index 0000000..73e90d5
--- /dev/null
@@ -0,0 +1,30 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2009 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_SCREEN_CLIENT_H
+#define NCMPC_SCREEN_CLIENT_H
+
+#include <glib.h>
+
+struct mpdclient;
+
+gint
+screen_auth(struct mpdclient *c);
+
+#endif
index d8e56df5821671114f9ffadd35dd19b663991924..9b70369fc60a9257ffdb8bcff05bb00d637123fb 100644 (file)
@@ -98,7 +98,7 @@ screen_getstr(WINDOW *w, const char *prompt)
        return screen_readln(w, prompt, NULL, NULL, NULL);
 }
 
-static char *
+char *
 screen_read_password(WINDOW *w, const char *prompt)
 {
        char *ret;
@@ -124,40 +124,6 @@ screen_read_password(WINDOW *w, const char *prompt)
        return ret;
 }
 
-static gint
-_screen_auth(struct mpdclient *c, gint recursion)
-{
-       char *password;
-
-       mpd_connection_clear_error(c->connection);
-       if (recursion > 2)
-               return 1;
-
-       password = screen_read_password(NULL, NULL);
-       if (password == NULL)
-               return 1;
-
-       mpd_send_password(c->connection, password);
-       g_free(password);
-
-       mpd_response_finish(c->connection);
-       mpdclient_update(c);
-
-       if (mpd_connection_get_error(c->connection) == MPD_ERROR_SERVER &&
-           mpd_connection_get_server_error(c->connection) == MPD_SERVER_ERROR_PASSWORD)
-               return  _screen_auth(c, ++recursion);
-       return 0;
-}
-
-gint
-screen_auth(struct mpdclient *c)
-{
-       gint ret = _screen_auth(c, 0);
-       mpdclient_update(c);
-       curs_set(0);
-       return ret;
-}
-
 /* query user for a string and find it in a list window */
 int
 screen_find(list_window_t *lw,
index 6aacd5d62f7f37702146959e29a284aac3fd28ff..c87827339abc2d405408188015780d98c77e5dad 100644 (file)
@@ -40,6 +40,10 @@ int screen_getch(WINDOW *w, const char *prompt);
 
 /* read a string from the status window */
 char *screen_getstr(WINDOW *w, const char *prompt);
+
+char *
+screen_read_password(WINDOW *w, const char *prompt);
+
 char *screen_readln(WINDOW *w, const char *prompt, const char *value,
                    GList **history, GCompletion *gcmp);
 char *screen_readln_masked(WINDOW *w, const char *prompt);
@@ -57,8 +61,6 @@ void screen_jump(struct list_window *lw,
                list_window_callback_fn_t callback_fn,
                void *callback_data);
 
-gint screen_auth(struct mpdclient *c);
-
 void screen_display_completion_list(GList *list);
 
 #ifndef NCMPC_MINI