summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe <bousset.rudy@gmail.com>2022-07-14 15:02:25 +0200
committerJoe <bousset.rudy@gmail.com>2022-07-14 15:02:25 +0200
commit11ec2346a2eedf3ff477637519ad3b30bbec15cb (patch)
treed66b25eb2dff83875d9637b2b29ee67283d883ef
parentWIP (diff)
downloadmpdview-11ec2346a2eedf3ff477637519ad3b30bbec15cb.tar.gz
mpdview-11ec2346a2eedf3ff477637519ad3b30bbec15cb.tar.bz2
mpdview-11ec2346a2eedf3ff477637519ad3b30bbec15cb.tar.xz
mpdview-11ec2346a2eedf3ff477637519ad3b30bbec15cb.tar.zst
mpdview-11ec2346a2eedf3ff477637519ad3b30bbec15cb.zip
Not bad
-rw-r--r--src/c_defines.h2
-rw-r--r--src/c_mpdview.c40
2 files changed, 30 insertions, 12 deletions
diff --git a/src/c_defines.h b/src/c_defines.h
index 7a32d9b..9f303fb 100644
--- a/src/c_defines.h
+++ b/src/c_defines.h
@@ -72,6 +72,6 @@ enum ret_e {
#define OPTSTRING "hvV"
-#define DEF_MUSIC_DIR "/var/mpd/music"
+#define DEF_MUSIC_DIR "/home/jozan/mu"
#endif /* __C_DEFINES_H__ */
diff --git a/src/c_mpdview.c b/src/c_mpdview.c
index 9456e7b..1fd0d98 100644
--- a/src/c_mpdview.c
+++ b/src/c_mpdview.c
@@ -45,10 +45,10 @@
* This is the entrypoint of the program.
*/
-#include <mpd/idle.h>
#include <sys/param.h>
#include <sys/syslimits.h>
+#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -59,6 +59,9 @@
#include "c_defines.h"
#include "c_mpdview.h"
+
+static bool_t doexit = FALSE;
+
static struct mpdview_s *
c_create_view(bool_t verbose)
{
@@ -157,9 +160,8 @@ static void
c_get_current_dir(struct mpdview_s* v)
{
ptr_t ptr;
- size_t len;
+ const size_t len = strlen(v->music_dir);
- len = strlen(v->current_dir);
strlcpy(v->current_dir, v->music_dir, PATH_MAX);
v->current_dir[len + 1] = 0x00;
v->current_dir[len] = '/';
@@ -172,6 +174,13 @@ c_get_current_dir(struct mpdview_s* v)
*ptr = 0x00;
}
+static void
+c_signal(int signal)
+{
+ (void)signal;
+ doexit = TRUE;
+}
+
int
main
(int argc,
@@ -179,7 +188,6 @@ main
{
struct mpdview_s* view;
char c;
- bool_t doexit;
bool_t verbose;
verbose = FALSE;
@@ -205,14 +213,8 @@ main
if (view == NULL) {
return (EXIT_FAILURE);
}
- doexit = FALSE;
- while (
- doexit == FALSE &&
- mpd_run_idle_mask(view->conn, MPD_IDLE_PLAYER) != 0
- ) {
- }
c_get_music_dir(view);
- if (c_connect_mpd(view) != RET_OK) {
+ if (c_connect_mpd(view) == RET_ERR) {
c_destroy_mpdview(&view);
return (EXIT_FAILURE);
}
@@ -220,6 +222,7 @@ main
c_destroy_mpdview(&view);
return (EXIT_FAILURE);
}
+ signal(SIGINT, c_signal);
if (view->state == MPD_STATE_PLAY || view->state == MPD_STATE_PAUSE) {
if (c_get_mpd_song(view) == RET_ERR) {
c_destroy_mpdview(&view);
@@ -230,6 +233,21 @@ main
dprintf(STDOUT_FILENO, "%s\n", view->current_dir);
}
}
+ while (
+ doexit == FALSE &&
+ mpd_run_idle_mask(view->conn, MPD_IDLE_PLAYER) != 0
+ ) {
+ if (view->state == MPD_STATE_PLAY || view->state == MPD_STATE_PAUSE) {
+ if (c_get_mpd_song(view) == RET_ERR) {
+ c_destroy_mpdview(&view);
+ return (EXIT_FAILURE);
+ }
+ c_get_current_dir(view);
+ if (view->verbose == TRUE) {
+ dprintf(STDOUT_FILENO, "%s\n", view->current_dir);
+ }
+ }
+ }
c_destroy_mpdview(&view);
return (EXIT_SUCCESS);
}