mirror of
https://github.com/netfun2000/lcd4linux.git
synced 2026-02-27 09:44:34 +08:00
indentation
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1150 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
This commit is contained in:
@@ -391,7 +391,7 @@ static int drv_MO_start(const char *section, const int quiet)
|
|||||||
|
|
||||||
char cmd[5];
|
char cmd[5];
|
||||||
if (Protocol == 4) {
|
if (Protocol == 4) {
|
||||||
/* send init string */
|
/* send init string */
|
||||||
cmd[0] = '\376';
|
cmd[0] = '\376';
|
||||||
cmd[1] = 'S';
|
cmd[1] = 'S';
|
||||||
cmd[2] = 'u';
|
cmd[2] = 'u';
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ static void drv_PICGraphic_blit(const int row, const int col, const int height,
|
|||||||
delayDone = 0;
|
delayDone = 0;
|
||||||
int row8, height8;
|
int row8, height8;
|
||||||
row8 = 8 * (row / 8);
|
row8 = 8 * (row / 8);
|
||||||
height8 = 8 * (height / 8) + !!(height % 8);
|
height8 = 8 * (height / 8) + ! !(height % 8);
|
||||||
info("sending blit");
|
info("sending blit");
|
||||||
cmd[0] = 'b';
|
cmd[0] = 'b';
|
||||||
cmd[1] = row8;
|
cmd[1] = row8;
|
||||||
|
|||||||
@@ -262,14 +262,14 @@ static void my_i2c_sensors_path(const char *method)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!strcmp(file->d_name, "device")) {
|
if (!strcmp(file->d_name, "device")) {
|
||||||
char fname[PATH_MAX];
|
char fname[PATH_MAX];
|
||||||
snprintf(fname, PATH_MAX, "%sdevice/temp1_input", dname);
|
snprintf(fname, PATH_MAX, "%sdevice/temp1_input", dname);
|
||||||
if (access(fname, R_OK) == 0) {
|
if (access(fname, R_OK) == 0) {
|
||||||
path = realloc(path, strlen(dname) + 7);
|
path = realloc(path, strlen(dname) + 7);
|
||||||
sprintf(path, "%sdevice/", dname);
|
sprintf(path, "%sdevice/", dname);
|
||||||
done = 1;
|
done = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(fd2);
|
closedir(fd2);
|
||||||
|
|||||||
602
plugin_mpd.c
602
plugin_mpd.c
@@ -139,102 +139,97 @@ static char Section[] = "Plugin:MPD";
|
|||||||
static int errorcnt = 0;
|
static int errorcnt = 0;
|
||||||
|
|
||||||
static iconv_t char_conv_iconv;
|
static iconv_t char_conv_iconv;
|
||||||
static char * char_conv_to;
|
static char *char_conv_to;
|
||||||
static char * char_conv_from;
|
static char *char_conv_from;
|
||||||
|
|
||||||
#define BUFFER_SIZE 1024
|
#define BUFFER_SIZE 1024
|
||||||
|
|
||||||
static void
|
static void charset_close(void)
|
||||||
charset_close(void)
|
|
||||||
{
|
{
|
||||||
if(char_conv_to) {
|
if (char_conv_to) {
|
||||||
iconv_close(char_conv_iconv);
|
iconv_close(char_conv_iconv);
|
||||||
free(char_conv_to);
|
free(char_conv_to);
|
||||||
free(char_conv_from);
|
free(char_conv_from);
|
||||||
char_conv_to = NULL;
|
char_conv_to = NULL;
|
||||||
char_conv_from = NULL;
|
char_conv_from = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int charset_set(const char *to, const char *from)
|
||||||
charset_set(const char *to, const char *from)
|
|
||||||
{
|
{
|
||||||
if(char_conv_to && strcmp(to,char_conv_to)==0 &&
|
if (char_conv_to && strcmp(to, char_conv_to) == 0 && char_conv_from && strcmp(from, char_conv_from) == 0)
|
||||||
char_conv_from && strcmp(from,char_conv_from)==0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
charset_close();
|
|
||||||
|
|
||||||
if ((char_conv_iconv = iconv_open(to,from))==(iconv_t)(-1))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
char_conv_to = strdup(to);
|
|
||||||
char_conv_from = strdup(from);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
charset_close();
|
||||||
|
|
||||||
|
if ((char_conv_iconv = iconv_open(to, from)) == (iconv_t) (-1))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
char_conv_to = strdup(to);
|
||||||
|
char_conv_from = strdup(from);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline size_t deconst_iconv(iconv_t cd,
|
static inline size_t deconst_iconv(iconv_t cd,
|
||||||
const char **inbuf, size_t *inbytesleft,
|
const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft)
|
||||||
char **outbuf, size_t *outbytesleft)
|
|
||||||
{
|
{
|
||||||
union {
|
union {
|
||||||
const char **a;
|
const char **a;
|
||||||
char **b;
|
char **b;
|
||||||
} deconst;
|
} deconst;
|
||||||
|
|
||||||
deconst.a = inbuf;
|
deconst.a = inbuf;
|
||||||
|
|
||||||
return iconv(cd, deconst.b, inbytesleft, outbuf, outbytesleft);
|
return iconv(cd, deconst.b, inbytesleft, outbuf, outbytesleft);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *charset_conv_strdup(const char *string)
|
||||||
charset_conv_strdup(const char *string)
|
|
||||||
{
|
{
|
||||||
char buffer[BUFFER_SIZE];
|
char buffer[BUFFER_SIZE];
|
||||||
size_t inleft = strlen(string);
|
size_t inleft = strlen(string);
|
||||||
char * ret;
|
char *ret;
|
||||||
size_t outleft;
|
size_t outleft;
|
||||||
size_t retlen = 0;
|
size_t retlen = 0;
|
||||||
size_t err;
|
size_t err;
|
||||||
char * bufferPtr;
|
char *bufferPtr;
|
||||||
|
|
||||||
if(!char_conv_to) return NULL;
|
if (!char_conv_to)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
ret = strdup("");
|
ret = strdup("");
|
||||||
|
|
||||||
while(inleft) {
|
while (inleft) {
|
||||||
bufferPtr = buffer;
|
bufferPtr = buffer;
|
||||||
outleft = BUFFER_SIZE;
|
outleft = BUFFER_SIZE;
|
||||||
err = deconst_iconv(char_conv_iconv,&string,&inleft,&bufferPtr,
|
err = deconst_iconv(char_conv_iconv, &string, &inleft, &bufferPtr, &outleft);
|
||||||
&outleft);
|
if (outleft == BUFFER_SIZE || (err == (size_t) - 1 /* && errno != E2BIG */ )) {
|
||||||
if (outleft == BUFFER_SIZE ||
|
free(ret);
|
||||||
(err == (size_t)-1/* && errno != E2BIG*/)) {
|
return NULL;
|
||||||
free(ret);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = realloc(ret,retlen+BUFFER_SIZE-outleft+1);
|
|
||||||
memcpy(ret+retlen,buffer,BUFFER_SIZE-outleft);
|
|
||||||
retlen+=BUFFER_SIZE-outleft;
|
|
||||||
ret[retlen] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
ret = realloc(ret, retlen + BUFFER_SIZE - outleft + 1);
|
||||||
|
memcpy(ret + retlen, buffer, BUFFER_SIZE - outleft);
|
||||||
|
retlen += BUFFER_SIZE - outleft;
|
||||||
|
ret[retlen] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *charset_from_utf8(const char *from)
|
||||||
charset_from_utf8(const char *from) {
|
{
|
||||||
static char * to = NULL;
|
static char *to = NULL;
|
||||||
|
|
||||||
if(to) free(to);
|
if (to)
|
||||||
|
free(to);
|
||||||
|
|
||||||
charset_set("ISO−8859−1", "UTF-8");
|
charset_set("ISO−8859−1", "UTF-8");
|
||||||
to = charset_conv_strdup(from);
|
to = charset_conv_strdup(from);
|
||||||
|
|
||||||
if (to == NULL)
|
if (to == NULL)
|
||||||
return from;
|
return from;
|
||||||
|
|
||||||
return to;
|
return to;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int configure_mpd(void)
|
static int configure_mpd(void)
|
||||||
@@ -244,49 +239,49 @@ static int configure_mpd(void)
|
|||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
if (configured != 0)
|
if (configured != 0)
|
||||||
return configured;
|
return configured;
|
||||||
|
|
||||||
/* read enabled */
|
/* read enabled */
|
||||||
if (cfg_number(Section, "enabled", 0, 0, 1, &plugin_enabled) < 1) {
|
if (cfg_number(Section, "enabled", 0, 0, 1, &plugin_enabled) < 1) {
|
||||||
plugin_enabled = 0;
|
plugin_enabled = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin_enabled != 1) {
|
if (plugin_enabled != 1) {
|
||||||
info("[MPD] WARNING: Plugin is not enabled! (set 'enabled 1' to enable this plugin)");
|
info("[MPD] WARNING: Plugin is not enabled! (set 'enabled 1' to enable this plugin)");
|
||||||
configured = 1;
|
configured = 1;
|
||||||
return configured;
|
return configured;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read server */
|
/* read server */
|
||||||
s = cfg_get(Section, "server", "localhost");
|
s = cfg_get(Section, "server", "localhost");
|
||||||
if (!s || *s == '\0') {
|
if (!s || *s == '\0') {
|
||||||
info("[MPD] empty '%s.server' entry from %s, assuming 'localhost'", Section, cfg_source());
|
info("[MPD] empty '%s.server' entry from %s, assuming 'localhost'", Section, cfg_source());
|
||||||
strcpy(host, "localhost");
|
strcpy(host, "localhost");
|
||||||
} else
|
} else
|
||||||
strcpy(host, s);
|
strcpy(host, s);
|
||||||
if(s)
|
if (s)
|
||||||
free(s);
|
free(s);
|
||||||
|
|
||||||
/* read port */
|
/* read port */
|
||||||
if (cfg_number(Section, "port", 6600, 1, 65536, &iport) < 1) {
|
if (cfg_number(Section, "port", 6600, 1, 65536, &iport) < 1) {
|
||||||
info("[MPD] no '%s.port' entry from %s using MPD's default", Section, cfg_source());
|
info("[MPD] no '%s.port' entry from %s using MPD's default", Section, cfg_source());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read minUpdateTime in ms */
|
/* read minUpdateTime in ms */
|
||||||
if (cfg_number(Section, "minUpdateTime", 500, 1, 10000, &waittime) < 1) {
|
if (cfg_number(Section, "minUpdateTime", 500, 1, 10000, &waittime) < 1) {
|
||||||
info("[MPD] no '%s.minUpdateTime' entry from %s using MPD's default", Section, cfg_source());
|
info("[MPD] no '%s.minUpdateTime' entry from %s using MPD's default", Section, cfg_source());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* read password */
|
/* read password */
|
||||||
s = cfg_get(Section, "password", "");
|
s = cfg_get(Section, "password", "");
|
||||||
if (!s || *s == '\0') {
|
if (!s || *s == '\0') {
|
||||||
info("[MPD] empty '%s.password' entry in %s, assuming none", Section, cfg_source());
|
info("[MPD] empty '%s.password' entry in %s, assuming none", Section, cfg_source());
|
||||||
memset(pw, 0, sizeof(pw));
|
memset(pw, 0, sizeof(pw));
|
||||||
} else
|
} else
|
||||||
strcpy(pw, s);
|
strcpy(pw, s);
|
||||||
if(s)
|
if (s)
|
||||||
free(s);
|
free(s);
|
||||||
|
|
||||||
debug("[MPD] connection detail: [%s:%d]", host, iport);
|
debug("[MPD] connection detail: [%s:%d]", host, iport);
|
||||||
configured = 1;
|
configured = 1;
|
||||||
@@ -294,134 +289,129 @@ static int configure_mpd(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void mpd_printerror(const char* cmd)
|
static void mpd_printerror(const char *cmd)
|
||||||
{
|
{
|
||||||
const char *s;
|
const char *s;
|
||||||
if(conn) {
|
if (conn) {
|
||||||
//assert(mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS);
|
//assert(mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS);
|
||||||
|
|
||||||
s = mpd_connection_get_error_message(conn);
|
s = mpd_connection_get_error_message(conn);
|
||||||
if (mpd_connection_get_error(conn) == MPD_ERROR_SERVER)
|
if (mpd_connection_get_error(conn) == MPD_ERROR_SERVER)
|
||||||
/* messages received from the server are UTF-8; the
|
/* messages received from the server are UTF-8; the
|
||||||
rest is either US-ASCII or locale */
|
rest is either US-ASCII or locale */
|
||||||
s = charset_from_utf8(s);
|
s = charset_from_utf8(s);
|
||||||
|
|
||||||
error("[MPD] %s to [%s]:[%i] failed : [%s]", cmd, host, iport, s);
|
error("[MPD] %s to [%s]:[%i] failed : [%s]", cmd, host, iport, s);
|
||||||
mpd_connection_free(conn);
|
mpd_connection_free(conn);
|
||||||
conn = NULL;
|
conn = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mpd_query_status(struct mpd_connection *conn)
|
void mpd_query_status(struct mpd_connection *conn)
|
||||||
{
|
{
|
||||||
struct mpd_status *status;
|
struct mpd_status *status;
|
||||||
struct mpd_song *song;
|
struct mpd_song *song;
|
||||||
const struct mpd_audio_format * audio;
|
const struct mpd_audio_format *audio;
|
||||||
|
|
||||||
if(!conn)
|
if (!conn)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!mpd_command_list_begin(conn, true) ||
|
if (!mpd_command_list_begin(conn, true) ||
|
||||||
!mpd_send_status(conn) ||
|
!mpd_send_status(conn) || !mpd_send_current_song(conn) || !mpd_command_list_end(conn)) {
|
||||||
!mpd_send_current_song(conn) ||
|
mpd_printerror("queue_commands");
|
||||||
!mpd_command_list_end(conn)) {
|
return;
|
||||||
mpd_printerror("queue_commands");
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = mpd_recv_status(conn);
|
status = mpd_recv_status(conn);
|
||||||
if (status == NULL) {
|
if (status == NULL) {
|
||||||
mpd_printerror("recv_status");
|
mpd_printerror("recv_status");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
mpd_song_free(currentSong);
|
mpd_song_free(currentSong);
|
||||||
currentSong = NULL;
|
currentSong = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mpd_response_next(conn)) {
|
if (!mpd_response_next(conn)) {
|
||||||
mpd_printerror("response_next");
|
mpd_printerror("response_next");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
song = mpd_recv_song(conn);
|
song = mpd_recv_song(conn);
|
||||||
if (song != NULL) {
|
if (song != NULL) {
|
||||||
currentSong = mpd_song_dup(song);
|
currentSong = mpd_song_dup(song);
|
||||||
mpd_song_free(song);
|
mpd_song_free(song);
|
||||||
|
|
||||||
l_elapsedTimeSec = mpd_status_get_elapsed_time(status);
|
l_elapsedTimeSec = mpd_status_get_elapsed_time(status);
|
||||||
l_totalTimeSec = mpd_status_get_total_time(status);
|
l_totalTimeSec = mpd_status_get_total_time(status);
|
||||||
l_bitRate = mpd_status_get_kbit_rate(status);
|
l_bitRate = mpd_status_get_kbit_rate(status);
|
||||||
} else {
|
} else {
|
||||||
l_elapsedTimeSec = 0;
|
l_elapsedTimeSec = 0;
|
||||||
l_totalTimeSec = 0;
|
l_totalTimeSec = 0;
|
||||||
l_bitRate = 0;
|
l_bitRate = 0;
|
||||||
}
|
}
|
||||||
l_state = mpd_status_get_state(status);
|
l_state = mpd_status_get_state(status);
|
||||||
|
|
||||||
l_repeatEnabled = mpd_status_get_repeat(status);
|
l_repeatEnabled = mpd_status_get_repeat(status);
|
||||||
l_randomEnabled = mpd_status_get_random(status);
|
l_randomEnabled = mpd_status_get_random(status);
|
||||||
l_singleEnabled = mpd_status_get_single(status);
|
l_singleEnabled = mpd_status_get_single(status);
|
||||||
l_consumeEnabled = mpd_status_get_consume(status);
|
l_consumeEnabled = mpd_status_get_consume(status);
|
||||||
|
|
||||||
l_volume = mpd_status_get_volume(status);
|
l_volume = mpd_status_get_volume(status);
|
||||||
|
|
||||||
l_currentSongPos = mpd_status_get_song_pos(status) + 1;
|
l_currentSongPos = mpd_status_get_song_pos(status) + 1;
|
||||||
l_playlistLength = mpd_status_get_queue_length(status);
|
l_playlistLength = mpd_status_get_queue_length(status);
|
||||||
|
|
||||||
|
|
||||||
audio = mpd_status_get_audio_format(status);
|
audio = mpd_status_get_audio_format(status);
|
||||||
if(audio) {
|
if (audio) {
|
||||||
l_sampleRate = audio->sample_rate;
|
l_sampleRate = audio->sample_rate;
|
||||||
l_channels = audio->channels;
|
l_channels = audio->channels;
|
||||||
} else {
|
} else {
|
||||||
l_sampleRate = 0;
|
l_sampleRate = 0;
|
||||||
l_channels = 0;
|
l_channels = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mpd_status_get_error(status) != NULL)
|
if (mpd_status_get_error(status) != NULL)
|
||||||
error("[MPD] query status : %s",
|
error("[MPD] query status : %s", charset_from_utf8(mpd_status_get_error(status)));
|
||||||
charset_from_utf8(mpd_status_get_error(status)));
|
|
||||||
|
|
||||||
mpd_status_free(status);
|
mpd_status_free(status);
|
||||||
|
|
||||||
if (!mpd_response_finish(conn)) {
|
if (!mpd_response_finish(conn)) {
|
||||||
mpd_printerror("response_finish");
|
mpd_printerror("response_finish");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mpd_query_stats(struct mpd_connection *conn)
|
void mpd_query_stats(struct mpd_connection *conn)
|
||||||
{
|
{
|
||||||
struct mpd_stats *stats;
|
struct mpd_stats *stats;
|
||||||
|
|
||||||
if(!conn)
|
if (!conn)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!mpd_command_list_begin(conn, true) ||
|
if (!mpd_command_list_begin(conn, true) || !mpd_send_stats(conn) || !mpd_command_list_end(conn)) {
|
||||||
!mpd_send_stats(conn) ||
|
mpd_printerror("queue_commands");
|
||||||
!mpd_command_list_end(conn)) {
|
return;
|
||||||
mpd_printerror("queue_commands");
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
stats = mpd_recv_stats(conn);
|
stats = mpd_recv_stats(conn);
|
||||||
if (stats == NULL) {
|
if (stats == NULL) {
|
||||||
mpd_printerror("recv_stats");
|
mpd_printerror("recv_stats");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
l_numberOfSongs = mpd_stats_get_number_of_songs(stats);
|
l_numberOfSongs = mpd_stats_get_number_of_songs(stats);
|
||||||
l_uptime = mpd_stats_get_uptime(stats);
|
l_uptime = mpd_stats_get_uptime(stats);
|
||||||
l_playTime = mpd_stats_get_play_time(stats);
|
l_playTime = mpd_stats_get_play_time(stats);
|
||||||
l_dbPlayTime = mpd_stats_get_db_play_time(stats);
|
l_dbPlayTime = mpd_stats_get_db_play_time(stats);
|
||||||
|
|
||||||
mpd_stats_free(stats);
|
|
||||||
|
|
||||||
if (!mpd_response_finish(conn)) {
|
mpd_stats_free(stats);
|
||||||
mpd_printerror("response_finish");
|
|
||||||
return;
|
if (!mpd_response_finish(conn)) {
|
||||||
}
|
mpd_printerror("response_finish");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mpd_update()
|
static int mpd_update()
|
||||||
@@ -444,33 +434,33 @@ static int mpd_update()
|
|||||||
|
|
||||||
/* check if connected */
|
/* check if connected */
|
||||||
if (conn == NULL || mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) {
|
if (conn == NULL || mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) {
|
||||||
if (conn) {
|
if (conn) {
|
||||||
if (errorcnt < ERROR_DISPLAY)
|
if (errorcnt < ERROR_DISPLAY)
|
||||||
mpd_printerror("reconnect");
|
mpd_printerror("reconnect");
|
||||||
} else
|
} else
|
||||||
debug("[MPD] initialize connect to [%s]:[%i]", host, iport);
|
debug("[MPD] initialize connect to [%s]:[%i]", host, iport);
|
||||||
}
|
}
|
||||||
if(!conn) {
|
if (!conn) {
|
||||||
conn = mpd_connection_new(host, iport, TIMEOUT_IN_S * 1000);
|
conn = mpd_connection_new(host, iport, TIMEOUT_IN_S * 1000);
|
||||||
if (conn == NULL || mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) {
|
if (conn == NULL || mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) {
|
||||||
if (conn) {
|
if (conn) {
|
||||||
if (errorcnt < ERROR_DISPLAY)
|
if (errorcnt < ERROR_DISPLAY)
|
||||||
mpd_printerror("connect");
|
mpd_printerror("connect");
|
||||||
}
|
|
||||||
if (errorcnt == ERROR_DISPLAY)
|
|
||||||
error("[MPD] stop logging, until connection is fixed!");
|
|
||||||
errorcnt++;
|
|
||||||
gettimeofday(×tamp, NULL);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
if (errorcnt == ERROR_DISPLAY)
|
||||||
if (*pw && !mpd_run_password(conn, pw)) {
|
error("[MPD] stop logging, until connection is fixed!");
|
||||||
errorcnt++;
|
errorcnt++;
|
||||||
mpd_printerror("run_password");
|
gettimeofday(×tamp, NULL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
errorcnt = 0;
|
|
||||||
debug("[MPD] connection fixed...");
|
if (*pw && !mpd_run_password(conn, pw)) {
|
||||||
|
errorcnt++;
|
||||||
|
mpd_printerror("run_password");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
errorcnt = 0;
|
||||||
|
debug("[MPD] connection fixed...");
|
||||||
}
|
}
|
||||||
|
|
||||||
mpd_query_status(conn);
|
mpd_query_status(conn);
|
||||||
@@ -543,60 +533,60 @@ static void getConsumeInt(RESULT * result)
|
|||||||
/* if no tag is availabe, use filename */
|
/* if no tag is availabe, use filename */
|
||||||
static void getArtist(RESULT * result)
|
static void getArtist(RESULT * result)
|
||||||
{
|
{
|
||||||
const char * value = NULL;
|
const char *value = NULL;
|
||||||
mpd_update();
|
mpd_update();
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
value = mpd_song_get_tag(currentSong, MPD_TAG_ARTIST, 0);
|
value = mpd_song_get_tag(currentSong, MPD_TAG_ARTIST, 0);
|
||||||
if(!value) {
|
if (!value) {
|
||||||
value = mpd_song_get_tag(currentSong, MPD_TAG_ALBUM_ARTIST, 0);
|
value = mpd_song_get_tag(currentSong, MPD_TAG_ALBUM_ARTIST, 0);
|
||||||
}
|
}
|
||||||
if(!value) {
|
if (!value) {
|
||||||
value = mpd_song_get_uri(currentSong);
|
value = mpd_song_get_uri(currentSong);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(value)
|
if (value)
|
||||||
SetResult(&result, R_STRING, charset_from_utf8(value));
|
SetResult(&result, R_STRING, charset_from_utf8(value));
|
||||||
else
|
else
|
||||||
SetResult(&result, R_STRING, "");
|
SetResult(&result, R_STRING, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getTitle(RESULT * result)
|
static void getTitle(RESULT * result)
|
||||||
{
|
{
|
||||||
const char * value = NULL;
|
const char *value = NULL;
|
||||||
mpd_update();
|
mpd_update();
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
value = mpd_song_get_tag(currentSong, MPD_TAG_TITLE, 0);
|
value = mpd_song_get_tag(currentSong, MPD_TAG_TITLE, 0);
|
||||||
}
|
}
|
||||||
if(value)
|
if (value)
|
||||||
SetResult(&result, R_STRING, charset_from_utf8(value));
|
SetResult(&result, R_STRING, charset_from_utf8(value));
|
||||||
else
|
else
|
||||||
SetResult(&result, R_STRING, "");
|
SetResult(&result, R_STRING, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getAlbum(RESULT * result)
|
static void getAlbum(RESULT * result)
|
||||||
{
|
{
|
||||||
const char * value = NULL;
|
const char *value = NULL;
|
||||||
mpd_update();
|
mpd_update();
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
value = mpd_song_get_tag(currentSong, MPD_TAG_ALBUM, 0);
|
value = mpd_song_get_tag(currentSong, MPD_TAG_ALBUM, 0);
|
||||||
}
|
}
|
||||||
if(value)
|
if (value)
|
||||||
SetResult(&result, R_STRING, charset_from_utf8(value));
|
SetResult(&result, R_STRING, charset_from_utf8(value));
|
||||||
else
|
else
|
||||||
SetResult(&result, R_STRING, "");
|
SetResult(&result, R_STRING, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getFilename(RESULT * result)
|
static void getFilename(RESULT * result)
|
||||||
{
|
{
|
||||||
const char * value = NULL;
|
const char *value = NULL;
|
||||||
mpd_update();
|
mpd_update();
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
value = mpd_song_get_uri(currentSong);
|
value = mpd_song_get_uri(currentSong);
|
||||||
}
|
}
|
||||||
if(value)
|
if (value)
|
||||||
SetResult(&result, R_STRING, charset_from_utf8(value));
|
SetResult(&result, R_STRING, charset_from_utf8(value));
|
||||||
else
|
else
|
||||||
SetResult(&result, R_STRING, "");
|
SetResult(&result, R_STRING, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -708,125 +698,125 @@ static void getSamplerateHz(RESULT * result)
|
|||||||
|
|
||||||
static void nextSong()
|
static void nextSong()
|
||||||
{
|
{
|
||||||
mpd_update();
|
mpd_update();
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
if ((!mpd_run_next(conn))
|
if ((!mpd_run_next(conn))
|
||||||
|| (!mpd_response_finish(conn))) {
|
|| (!mpd_response_finish(conn))) {
|
||||||
mpd_printerror("run_next");
|
mpd_printerror("run_next");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prevSong()
|
static void prevSong()
|
||||||
{
|
{
|
||||||
mpd_update();
|
mpd_update();
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
if ((!mpd_run_previous(conn))
|
if ((!mpd_run_previous(conn))
|
||||||
|| (!mpd_response_finish(conn))) {
|
|| (!mpd_response_finish(conn))) {
|
||||||
mpd_printerror("run_previous");
|
mpd_printerror("run_previous");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stopSong()
|
static void stopSong()
|
||||||
{
|
{
|
||||||
mpd_update();
|
mpd_update();
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
if ((!mpd_run_stop(conn))
|
if ((!mpd_run_stop(conn))
|
||||||
|| (!mpd_response_finish(conn))) {
|
|| (!mpd_response_finish(conn))) {
|
||||||
mpd_printerror("run_stop");
|
mpd_printerror("run_stop");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pauseSong()
|
static void pauseSong()
|
||||||
{
|
{
|
||||||
mpd_update();
|
mpd_update();
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
if ((!mpd_send_pause(conn, l_state == MPD_STATE_PAUSE ? 0 : 1))
|
if ((!mpd_send_pause(conn, l_state == MPD_STATE_PAUSE ? 0 : 1))
|
||||||
|| (!mpd_response_finish(conn))) {
|
|| (!mpd_response_finish(conn))) {
|
||||||
mpd_printerror("send_pause");
|
mpd_printerror("send_pause");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void volUp()
|
static void volUp()
|
||||||
{
|
{
|
||||||
mpd_update();
|
mpd_update();
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
l_volume += 5;
|
l_volume += 5;
|
||||||
if (l_volume > 100)
|
if (l_volume > 100)
|
||||||
l_volume = 100;
|
l_volume = 100;
|
||||||
|
|
||||||
if ((!mpd_run_set_volume(conn, l_volume))
|
if ((!mpd_run_set_volume(conn, l_volume))
|
||||||
|| (!mpd_response_finish(conn))) {
|
|| (!mpd_response_finish(conn))) {
|
||||||
mpd_printerror("set_volume");
|
mpd_printerror("set_volume");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void volDown()
|
static void volDown()
|
||||||
{
|
{
|
||||||
mpd_update();
|
mpd_update();
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
if (l_volume > 5)
|
if (l_volume > 5)
|
||||||
l_volume -= 5;
|
l_volume -= 5;
|
||||||
else
|
else
|
||||||
l_volume = 0;
|
l_volume = 0;
|
||||||
|
|
||||||
if ((!mpd_run_set_volume(conn, l_volume))
|
if ((!mpd_run_set_volume(conn, l_volume))
|
||||||
|| (!mpd_response_finish(conn))) {
|
|| (!mpd_response_finish(conn))) {
|
||||||
mpd_printerror("set_volume");
|
mpd_printerror("set_volume");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void toggleRepeat()
|
static void toggleRepeat()
|
||||||
{
|
{
|
||||||
mpd_update();
|
mpd_update();
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
l_repeatEnabled = !l_repeatEnabled;
|
l_repeatEnabled = !l_repeatEnabled;
|
||||||
if ((!mpd_run_repeat(conn, l_repeatEnabled))
|
if ((!mpd_run_repeat(conn, l_repeatEnabled))
|
||||||
|| (!mpd_response_finish(conn))) {
|
|| (!mpd_response_finish(conn))) {
|
||||||
mpd_printerror("run_repeat");
|
mpd_printerror("run_repeat");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void toggleRandom()
|
static void toggleRandom()
|
||||||
{
|
{
|
||||||
mpd_update();
|
mpd_update();
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
l_randomEnabled = !l_randomEnabled;
|
l_randomEnabled = !l_randomEnabled;
|
||||||
if ((!mpd_run_random(conn, l_randomEnabled))
|
if ((!mpd_run_random(conn, l_randomEnabled))
|
||||||
|| (!mpd_response_finish(conn))) {
|
|| (!mpd_response_finish(conn))) {
|
||||||
mpd_printerror("run_random");
|
mpd_printerror("run_random");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void toggleSingle()
|
static void toggleSingle()
|
||||||
{
|
{
|
||||||
mpd_update();
|
mpd_update();
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
l_singleEnabled = !l_singleEnabled;
|
l_singleEnabled = !l_singleEnabled;
|
||||||
if ((!mpd_run_single(conn, l_singleEnabled))
|
if ((!mpd_run_single(conn, l_singleEnabled))
|
||||||
|| (!mpd_response_finish(conn))) {
|
|| (!mpd_response_finish(conn))) {
|
||||||
mpd_printerror("run_single");
|
mpd_printerror("run_single");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void toggleConsume()
|
static void toggleConsume()
|
||||||
{
|
{
|
||||||
mpd_update();
|
mpd_update();
|
||||||
if (currentSong != NULL) {
|
if (currentSong != NULL) {
|
||||||
l_consumeEnabled = !l_consumeEnabled;
|
l_consumeEnabled = !l_consumeEnabled;
|
||||||
if ((!mpd_run_consume(conn, l_consumeEnabled))
|
if ((!mpd_run_consume(conn, l_consumeEnabled))
|
||||||
|| (!mpd_response_finish(conn))) {
|
|| (!mpd_response_finish(conn))) {
|
||||||
mpd_printerror("run_consume");
|
mpd_printerror("run_consume");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void formatTimeMMSS(RESULT * result, RESULT * param)
|
static void formatTimeMMSS(RESULT * result, RESULT * param)
|
||||||
@@ -935,7 +925,7 @@ void plugin_exit_mpd(void)
|
|||||||
if (currentSong != NULL)
|
if (currentSong != NULL)
|
||||||
mpd_song_free(currentSong);
|
mpd_song_free(currentSong);
|
||||||
}
|
}
|
||||||
if (conn != NULL)
|
if (conn != NULL)
|
||||||
mpd_connection_free(conn);
|
mpd_connection_free(conn);
|
||||||
charset_close();
|
charset_close();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user