1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-16 18:15:17 +00:00

* Fixed potential issue on FreeBSD when nprocs < 10 (thanks zotrix)

* Added support for multiple batteries when using acpi (thanks Phil)
    * a bunch of code cleanups (thanks Psychon)
    * added max length paramater to mpd_title (thinks fow)
    * a number of small bug fixes


git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@889 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Brenden Matthews 2007-08-05 04:47:21 +00:00
parent 906e7e8bfd
commit f95d63bf56
13 changed files with 456 additions and 520 deletions

12
AUTHORS
View File

@ -80,6 +80,9 @@ Fanat1k
flitsch <flitsch at users dot sourceforge dot net>
hwmon support
fow <facadedewalls at yahoo dot com>
mpd_title max length
Gwenhael LE MOINE <cycojesus at yahoo dot fr>
Manual setting of the position
WM_CLASS for window when drawing to own window
@ -176,6 +179,12 @@ Philip Kovacs <pkovacs at users dot sourceforge dot net>
Audacious, Xmms, BMP, Infopipe stuff
Various Xlib changes, e.g. own_window hints, etc.
Phil <n0-1 at users dot sourceforge dot net>
multiple batteries support
Psychon <psychon at users dot sourceforge dot net>
a bunch of code cleanups
roiban adi <adiroiban at users dot sourceforge dot net>
hex colour patch
@ -217,3 +226,6 @@ William DiPlacido <bimbasaari at yahoo dot com>
zimba-tm <zimba-tm at users dot sourceforge dot net>
alignment none patch
zotrix <zotrix at users dot sourceforge dot net>
FreeBSD patch for <10 procs

View File

@ -1,5 +1,12 @@
# $Id$
2007-08-04
* Fixed potential issue on FreeBSD when nprocs < 10 (thanks zotrix)
* Added support for multiple batteries when using acpi (thanks Phil)
* a bunch of code cleanups (thanks Psychon)
* added max length paramater to mpd_title (thinks fow)
* a number of small bug fixes
2007-07-15
* Fix PID display, patch #1753934. thanks sohalt.
* Fix displaying 4 GB traffic after reloading network driver,

View File

@ -1192,6 +1192,7 @@
<varlistentry>
<term>
<command><option>mpd_title</option></command>
<option>(max length)</option>
</term>
<listitem>
Title of current MPD song

View File

@ -5,7 +5,7 @@
* $Id$
*/
#include <bmp/dbus.h>
#include <bmp/dbus.hh>
#include <dbus/dbus-glib.h>
#include <stdio.h>

View File

@ -299,7 +299,6 @@ static int draw_shades, draw_outline;
static int border_margin, border_width;
static long default_fg_color, default_bg_color, default_out_color;
static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
/* create own window or draw stuff to root? */
static int set_transparent = 0;
@ -321,6 +320,8 @@ static int maximum_width;
static int sensor_device;
#endif
static long color0, color1, color2, color3, color4, color5, color6, color7, color8, color9;
/* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
@ -429,42 +430,6 @@ static int blockdepth = 0;
static int if_jumped = 0;
static int blockstart[MAX_IF_BLOCK_DEPTH];
int check_mount(char *s)
{
#if defined(__linux__)
int ret = 0;
FILE *mtab = fopen("/etc/mtab", "r");
if (mtab) {
char buf1[256], buf2[128];
while (fgets(buf1, 256, mtab)) {
sscanf(buf1, "%*s %128s", buf2);
if (!strcmp(s, buf2)) {
ret = 1;
break;
}
}
fclose(mtab);
} else {
ERR("Could not open mtab");
}
return ret;
#elif defined(__FreeBSD__)
struct statfs *mntbuf;
int i, mntsize;
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
for (i = mntsize - 1; i >= 0; i--)
if (strcmp(mntbuf[i].f_mntonname, s) == 0)
return 1;
return 0;
#elif defined(__OpenBSD__)
/* stub */
return 0;
#endif
}
int check_contains(char *f, char *s)
{
int ret = 0;
@ -1865,7 +1830,8 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
free(objs[i].data.tail.logfile);
free(objs[i].data.tail.buffer);
break;
case OBJ_text: case OBJ_font:
case OBJ_text:
case OBJ_font:
free(objs[i].data.s);
break;
case OBJ_image:
@ -2366,8 +2332,7 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
obj->data.l = color9;
END OBJ(font, 0)
obj->data.s = scan_font(arg);
END
OBJ(downspeed, INFO_NET)
END OBJ(downspeed, INFO_NET)
if(arg) {
obj->data.net = get_net_stat(arg);
}
@ -3032,8 +2997,18 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
}
END
#ifdef MPD
OBJ(mpd_artist, INFO_MPD)
END OBJ(mpd_title, INFO_MPD)
OBJ(mpd_artist, INFO_MPD) END
OBJ(mpd_title, INFO_MPD)
{
if (arg)
{
sscanf (arg, "%d", &info.mpd.max_title_len);
if (info.mpd.max_title_len > 0)
info.mpd.max_title_len++;
else
CRIT_ERR ("mpd_title: invalid length argument");
}
}
END OBJ(mpd_random, INFO_MPD)
END OBJ(mpd_repeat, INFO_MPD)
END OBJ(mpd_elapsed, INFO_MPD)
@ -3718,11 +3693,11 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
}
#endif /* __OpenBSD__ */
#ifdef X11
OBJ(font) {
#ifdef X11
new_font(p, obj->data.s);
}
#endif /* X11 */
}
void format_diskio(unsigned int diskio_value)
{
if (!use_spacer) {
@ -4635,7 +4610,7 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
trans_speed /
1024));
else
snprintf(p, 5, "%d ",
snprintf(p, 6, "%d ",
(int) (obj->data.net->
trans_speed /
1024));
@ -4690,7 +4665,9 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
#ifdef MPD
OBJ(mpd_title) {
snprintf(p, p_max_size, "%s", cur->mpd.title);
snprintf(p, cur->mpd.max_title_len > 0 ?
cur->mpd.max_title_len : p_max_size, "%s",
cur->mpd.title);
}
OBJ(mpd_artist) {
snprintf(p, p_max_size, "%s", cur->mpd.artist);

View File

@ -155,6 +155,7 @@ struct mpd_s {
int bitrate;
int length;
int elapsed;
int max_title_len; /* e.g. ${mpd_title 50} */
};
#endif
@ -462,6 +463,7 @@ extern int no_buffers;
/* system dependant (in linux.c) */
int check_mount(char *s);
void update_diskio(void);
void prepare_update(void);
void update_uptime(void);

View File

@ -113,6 +113,19 @@ update_uptime()
}
}
int check_mount(char *s)
{
struct statfs *mntbuf;
int i, mntsize;
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
for (i = mntsize - 1; i >= 0; i--)
if (strcmp(mntbuf[i].f_mntonname, s) == 0)
return 1;
return 0;
}
void
update_meminfo()
{
@ -753,7 +766,7 @@ proc_find_top(struct process **cpu, struct process **mem)
}
qsort(processes, j - 1, sizeof (struct process), comparemem);
for (i = 0; i < 10; i++) {
for (i = 0; i < 10 && i < n_processes; i++) {
struct process *tmp, *ttmp;
tmp = malloc(sizeof (struct process));
@ -771,7 +784,7 @@ proc_find_top(struct process **cpu, struct process **mem)
}
qsort(processes, j - 1, sizeof (struct process), comparecpu);
for (i = 0; i < 10; i++) {
for (i = 0; i < 10 && i < n_processes; i++) {
struct process *tmp, *ttmp;
tmp = malloc(sizeof (struct process));

View File

@ -75,6 +75,26 @@ void update_uptime()
info.mask |= (1 << INFO_UPTIME);
}
int check_mount(char *s)
{
int ret = 0;
FILE *mtab = fopen("/etc/mtab", "r");
if (mtab) {
char buf1[256], buf2[128];
while (fgets(buf1, 256, mtab)) {
sscanf(buf1, "%*s %128s", buf2);
if (!strcmp(s, buf2)) {
ret = 1;
break;
}
}
fclose(mtab);
} else {
ERR("Could not open mtab");
}
return ret;
}
/* these things are also in sysinfo except Buffers:, that's why I'm reading
* them from proc */
@ -1191,49 +1211,82 @@ present voltage: 16608 mV
#define ACPI_BATTERY_BASE_PATH "/proc/acpi/battery"
#define APM_PATH "/proc/apm"
#define MAX_BATTERY_COUNT 4
static FILE *acpi_bat_fp;
static FILE *apm_bat_fp;
static FILE *acpi_bat_fp[MAX_BATTERY_COUNT];
static FILE *apm_bat_fp[MAX_BATTERY_COUNT];
static int acpi_last_full;
static int acpi_design_capacity;
static int batteries_initialized = 0;
static char batteries[MAX_BATTERY_COUNT][32];
static char last_battery_str[64]; /* e.g. "charging 75%" */
static char last_battery_time_str[64]; /* e.g. "3h 15m" */
static int acpi_last_full[MAX_BATTERY_COUNT];
static int acpi_design_capacity[MAX_BATTERY_COUNT];
static double last_battery_time;
static char last_battery_str[MAX_BATTERY_COUNT][64]; /* e.g. "charging 75%" */
static char last_battery_time_str[MAX_BATTERY_COUNT][64]; /* e.g. "3h 15m" */
static int last_battery_perct;
static double last_battery_perct_time;
static double last_battery_time[MAX_BATTERY_COUNT];
static int last_battery_perct[MAX_BATTERY_COUNT];
static double last_battery_perct_time[MAX_BATTERY_COUNT];
void init_batteries(void)
{
int idx;
if(batteries_initialized)
return;
for(idx = 0; idx < MAX_BATTERY_COUNT; idx++)
batteries[idx][0] = '\0';
batteries_initialized = 1;
}
int get_battery_idx(const char *bat)
{
int idx;
for(idx = 0; idx < MAX_BATTERY_COUNT; idx++)
if(!strlen(batteries[idx]) || !strcmp(batteries[idx], bat))
break;
/* if not found, enter a new entry */
if(!strlen(batteries[idx]))
snprintf(batteries[idx], 31, "%s", bat);
return idx;
}
void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
{
static int rep = 0, rep2 = 0;
static int idx, rep = 0, rep2 = 0;
char acpi_path[128];
snprintf(acpi_path, 127, ACPI_BATTERY_BASE_PATH "/%s/state", bat);
init_batteries();
idx = get_battery_idx(bat);
/* don't update battery too often */
if (current_update_time - last_battery_time < 29.5)
if (current_update_time - last_battery_time[idx] < 29.5)
goto set_return_value;
last_battery_time = current_update_time;
last_battery_time[idx] = current_update_time;
memset (last_battery_str, 0, sizeof (last_battery_str));
memset (last_battery_time_str, 0, sizeof (last_battery_time_str));
memset (last_battery_str[idx], 0, sizeof (last_battery_str[idx]));
memset (last_battery_time_str[idx], 0, sizeof (last_battery_time_str[idx]));
/* first try ACPI */
if (acpi_bat_fp == NULL && apm_bat_fp == NULL)
acpi_bat_fp = open_file(acpi_path, &rep);
if (acpi_bat_fp[idx] == NULL && apm_bat_fp[idx] == NULL)
acpi_bat_fp[idx] = open_file(acpi_path, &rep);
if (acpi_bat_fp != NULL) {
if (acpi_bat_fp[idx] != NULL) {
int present_rate = -1;
int remaining_capacity = -1;
char charging_state[64];
char present[4];
/* read last full capacity if it's zero */
if (acpi_last_full == 0) {
if (acpi_last_full[idx] == 0) {
static int rep = 0;
char path[128];
FILE *fp;
@ -1245,7 +1298,7 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
char b[256];
if (fgets(b, 256, fp) == NULL)
break;
if (sscanf(b, "last full capacity: %d", &acpi_last_full) != 0) {
if (sscanf(b, "last full capacity: %d", &acpi_last_full[idx]) != 0) {
break;
}
}
@ -1254,13 +1307,13 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
}
}
fseek(acpi_bat_fp, 0, SEEK_SET);
fseek(acpi_bat_fp[idx], 0, SEEK_SET);
strcpy(charging_state, "unknown");
while (!feof(acpi_bat_fp)) {
while (!feof(acpi_bat_fp[idx])) {
char buf[256];
if (fgets(buf, 256, acpi_bat_fp) == NULL)
if (fgets(buf, 256, acpi_bat_fp[idx]) == NULL)
break;
/* let's just hope units are ok */
@ -1275,88 +1328,94 @@ void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
}
/* Hellf[i]re notes that remaining capacity can exceed acpi_last_full */
if (remaining_capacity > acpi_last_full)
acpi_last_full = remaining_capacity; /* normalize to 100% */
if (remaining_capacity > acpi_last_full[idx])
acpi_last_full[idx] = remaining_capacity; /* normalize to 100% */
/* not present */
if (strcmp(present, "no") == 0) {
strncpy(last_battery_str, "not present", 64);
strncpy(last_battery_str[idx], "not present", 64);
}
/* charging */
else if (strcmp(charging_state, "charging") == 0) {
if (acpi_last_full != 0 && present_rate > 0) {
if (acpi_last_full[idx] != 0 && present_rate > 0) {
/* e.g. charging 75% */
snprintf(last_battery_str, sizeof(last_battery_str)-1, "charging %i%%",
(int) ((remaining_capacity * 100) / acpi_last_full));
snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "charging %i%%",
(int) ((remaining_capacity * 100) / acpi_last_full[idx]));
/* e.g. 2h 37m */
format_seconds(last_battery_time_str, sizeof(last_battery_time_str)-1,
(long) (((acpi_last_full - remaining_capacity) * 3600) /
format_seconds(last_battery_time_str[idx], sizeof(last_battery_time_str[idx])-1,
(long) (((acpi_last_full[idx] - remaining_capacity) * 3600) /
present_rate));
} else if (acpi_last_full != 0 && present_rate <= 0) {
snprintf(last_battery_str, sizeof(last_battery_str)-1, "charging %d%%",
(int) ((remaining_capacity * 100) / acpi_last_full));
} else if (acpi_last_full[idx] != 0 && present_rate <= 0) {
snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "charging %d%%",
(int) ((remaining_capacity * 100) / acpi_last_full[idx]));
} else {
strncpy(last_battery_str, "charging", sizeof(last_battery_str)-1);
strncpy(last_battery_str[idx], "charging", sizeof(last_battery_str[idx])-1);
}
}
/* discharging */
else if (strncmp(charging_state, "discharging", 64) == 0) {
if (present_rate > 0) {
/* e.g. discharging 35% */
snprintf(last_battery_str, sizeof(last_battery_str)-1, "discharging %i%%",
(int) ((remaining_capacity * 100) / acpi_last_full));
snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "discharging %i%%",
(int) ((remaining_capacity * 100) / acpi_last_full[idx]));
/* e.g. 1h 12m */
format_seconds(last_battery_time_str, sizeof(last_battery_time_str)-1,
format_seconds(last_battery_time_str[idx], sizeof(last_battery_time_str[idx])-1,
(long) ((remaining_capacity * 3600) / present_rate));
} else if (present_rate == 0) { /* Thanks to Nexox for this one */
snprintf(last_battery_str, sizeof(last_battery_str)-1, "full");
snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1, "full");
} else {
snprintf(last_battery_str, sizeof(last_battery_str)-1,
snprintf(last_battery_str[idx], sizeof(last_battery_str[idx])-1,
"discharging %d%%",
(int) ((remaining_capacity * 100) / acpi_last_full));
(int) ((remaining_capacity * 100) / acpi_last_full[idx]));
}
}
/* charged */
/* thanks to Lukas Zapletal <lzap@seznam.cz> */
else if (strncmp(charging_state, "charged", 64) == 0) {
strcpy(last_battery_str, "charged");
/* Below happens with the second battery on my X40,
* when the second one is empty and the first one
* being charged. */
if (remaining_capacity == 0)
strcpy(last_battery_str[idx], "empty");
else
strcpy(last_battery_str[idx], "charged");
}
/* unknown, probably full / AC */
else {
if (acpi_last_full != 0
&& remaining_capacity != acpi_last_full)
snprintf(last_battery_str, 64, "unknown %d%%",
(int) ((remaining_capacity * 100) / acpi_last_full));
if (acpi_last_full[idx] != 0
&& remaining_capacity != acpi_last_full[idx])
snprintf(last_battery_str[idx], 64, "unknown %d%%",
(int) ((remaining_capacity * 100) / acpi_last_full[idx]));
else
strncpy(last_battery_str, "AC", 64);
strncpy(last_battery_str[idx], "AC", 64);
}
} else {
/* APM */
if (apm_bat_fp == NULL)
apm_bat_fp = open_file(APM_PATH, &rep2);
if (apm_bat_fp[idx] == NULL)
apm_bat_fp[idx] = open_file(APM_PATH, &rep2);
if (apm_bat_fp != NULL) {
if (apm_bat_fp[idx] != NULL) {
int ac, status, flag, life;
fscanf(apm_bat_fp,
fscanf(apm_bat_fp[idx],
"%*s %*s %*x %x %x %x %d%%",
&ac, &status, &flag, &life);
if (life == -1) {
/* could check now that there is ac */
snprintf(last_battery_str, 64, "AC");
snprintf(last_battery_str[idx], 64, "AC");
} else if (ac && life != 100) { /* could check that status==3 here? */
snprintf(last_battery_str, 64,
snprintf(last_battery_str[idx], 64,
"charging %d%%", life);
} else {
snprintf(last_battery_str, 64, "%d%%",
snprintf(last_battery_str[idx], 64, "%d%%",
life);
}
/* it seemed to buffer it so file must be closed (or could use syscalls
* directly but I don't feel like coding it now) */
fclose(apm_bat_fp);
apm_bat_fp = NULL;
fclose(apm_bat_fp[idx]);
apm_bat_fp[idx] = NULL;
}
}
@ -1364,12 +1423,12 @@ set_return_value:
switch (item) {
case BATTERY_STATUS:
{
snprintf(buf, n, "%s", last_battery_str);
snprintf(buf, n, "%s", last_battery_str[idx]);
break;
}
case BATTERY_TIME:
{
snprintf(buf, n, "%s", last_battery_time_str);
snprintf(buf, n, "%s", last_battery_time_str[idx]);
break;
}
default:
@ -1381,24 +1440,29 @@ set_return_value:
int get_battery_perct(const char *bat)
{
static int rep;
int idx;
char acpi_path[128];
snprintf(acpi_path, 127, ACPI_BATTERY_BASE_PATH "/%s/state", bat);
init_batteries();
idx = get_battery_idx(bat);
/* don't update battery too often */
if (current_update_time - last_battery_perct_time < 30) {
return last_battery_perct;
if (current_update_time - last_battery_perct_time[idx] < 30) {
return last_battery_perct[idx];
}
last_battery_perct_time = current_update_time;
last_battery_perct_time[idx] = current_update_time;
/* Only check for ACPI */
if (acpi_bat_fp == NULL && apm_bat_fp == NULL)
acpi_bat_fp = open_file(acpi_path, &rep);
acpi_bat_fp[idx] = open_file(acpi_path, &rep);
int remaining_capacity = -1;
if (acpi_bat_fp != NULL) {
if (acpi_bat_fp[idx] != NULL) {
/* read last full capacity if it's zero */
if (acpi_design_capacity == 0) {
if (acpi_design_capacity[idx] == 0) {
static int rep;
char path[128];
FILE *fp;
@ -1410,7 +1474,7 @@ int get_battery_perct(const char *bat)
char b[256];
if (fgets(b, 256, fp) == NULL)
break;
if (sscanf(b, "design capacity: %d", &acpi_design_capacity) != 0) {
if (sscanf(b, "design capacity: %d", &acpi_design_capacity[idx]) != 0) {
break;
}
}
@ -1418,11 +1482,11 @@ int get_battery_perct(const char *bat)
}
}
fseek(acpi_bat_fp, 0, SEEK_SET);
fseek(acpi_bat_fp[idx], 0, SEEK_SET);
while (!feof(acpi_bat_fp)) {
while (!feof(acpi_bat_fp[idx])) {
char buf[256];
if (fgets(buf, 256, acpi_bat_fp) == NULL)
if (fgets(buf, 256, acpi_bat_fp[idx]) == NULL)
break;
if (buf[0] == 'r')
@ -1433,15 +1497,17 @@ int get_battery_perct(const char *bat)
if(remaining_capacity < 0)
return 0;
/* compute the battery percentage */
last_battery_perct =
(int) (((float)remaining_capacity/acpi_design_capacity) * 100);
return last_battery_perct;
last_battery_perct[idx] =
(int) (((float)remaining_capacity/acpi_design_capacity[idx]) * 100);
return last_battery_perct[idx];
}
int get_battery_perct_bar(const char *bar)
{
int idx;
get_battery_perct(bar);
return (int) (last_battery_perct * 2.56 - 1);
idx = get_battery_idx(bar);
return (int) (last_battery_perct[idx] * 2.56 - 1);
}

203
src/mpd.c
View File

@ -10,6 +10,40 @@
#include <stdlib.h>
#include "libmpdclient.h"
static void clear_mpd_stats(struct information *current_info)
{
if (current_info->mpd.artist == NULL)
current_info->mpd.artist = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.album == NULL)
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.title == NULL)
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.random == NULL)
current_info->mpd.random = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.repeat == NULL)
current_info->mpd.repeat = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.track == NULL)
current_info->mpd.track = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.status == NULL)
current_info->mpd.status = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.name == NULL)
current_info->mpd.name = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.file == NULL)
current_info->mpd.file = malloc(TEXT_BUFFER_SIZE);
*current_info->mpd.name=0;
*current_info->mpd.file=0;
*current_info->mpd.artist=0;
*current_info->mpd.album=0;
*current_info->mpd.title=0;
*current_info->mpd.random=0;
*current_info->mpd.repeat=0;
*current_info->mpd.track=0;
current_info->mpd.bitrate = 0;
current_info->mpd.progress = 0;
current_info->mpd.elapsed = 0;
current_info->mpd.length = 0;
}
void update_mpd()
{
@ -22,45 +56,16 @@ void update_mpd()
current_info->mpd.password);
mpd_finishCommand(current_info->conn);
}
// This makes sure everything we need is malloc'ed and clear
clear_mpd_stats(current_info);
if (current_info->conn->error) {
//ERR("%MPD error: s\n", current_info->conn->errorStr);
mpd_closeConnection(current_info->conn);
current_info->conn = 0;
if (current_info->mpd.artist == NULL)
current_info->mpd.artist =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.album == NULL)
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.title == NULL)
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.random == NULL)
current_info->mpd.random =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.repeat == NULL)
current_info->mpd.repeat =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.track == NULL)
current_info->mpd.track = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.status == NULL)
current_info->mpd.status =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.name == NULL)
current_info->mpd.name = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.file == NULL)
current_info->mpd.file = malloc(TEXT_BUFFER_SIZE);
*current_info->mpd.name=0;
*current_info->mpd.file=0;
*current_info->mpd.artist=0;
*current_info->mpd.album=0;
*current_info->mpd.title=0;
*current_info->mpd.random=0;
*current_info->mpd.repeat=0;
*current_info->mpd.track=0;
strncpy(current_info->mpd.status, "MPD not responding", TEXT_BUFFER_SIZE - 1);
current_info->mpd.bitrate = 0;
current_info->mpd.progress = 0;
current_info->mpd.elapsed = 0;
current_info->mpd.length = 0;
return;
}
@ -74,134 +79,29 @@ void update_mpd()
//ERR("MPD error: %s\n", current_info->conn->errorStr);
mpd_closeConnection(current_info->conn);
current_info->conn = 0;
if (current_info->mpd.artist == NULL)
current_info->mpd.artist =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.album == NULL)
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.title == NULL)
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.random == NULL)
current_info->mpd.random =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.repeat == NULL)
current_info->mpd.repeat =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.track == NULL)
current_info->mpd.track = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.status == NULL)
current_info->mpd.status = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.name == NULL)
current_info->mpd.name = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.file == NULL)
current_info->mpd.file = malloc(TEXT_BUFFER_SIZE);
*current_info->mpd.name=0;
*current_info->mpd.file=0;
*current_info->mpd.artist=0;
*current_info->mpd.album=0;
*current_info->mpd.title=0;
*current_info->mpd.random=0;
*current_info->mpd.repeat=0;
*current_info->mpd.track=0;
strncpy(current_info->mpd.status, "MPD not responding", TEXT_BUFFER_SIZE - 1);
current_info->mpd.bitrate = 0;
current_info->mpd.progress = 0;
current_info->mpd.elapsed = 0;
current_info->mpd.length = 0;
return;
}
current_info->mpd.volume = status->volume;
//if (status->error)
//printf("error: %s\n", status->error);
if (status->state == MPD_STATUS_STATE_PLAY) {
if (current_info->mpd.status == NULL)
current_info->mpd.status =
malloc(TEXT_BUFFER_SIZE);
strncpy(current_info->mpd.status, "Playing",
TEXT_BUFFER_SIZE - 1);
}
if (status->state == MPD_STATUS_STATE_STOP) {
current_info->mpd.bitrate = 0;
current_info->mpd.progress = 0;
current_info->mpd.elapsed = 0;
current_info->mpd.length = 0;
if (current_info->mpd.artist == NULL)
current_info->mpd.artist =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.album == NULL)
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.title == NULL)
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.random == NULL)
current_info->mpd.random =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.repeat == NULL)
current_info->mpd.repeat =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.track == NULL)
current_info->mpd.track = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.status == NULL)
current_info->mpd.status =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.name == NULL)
current_info->mpd.name = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.file == NULL)
current_info->mpd.file = malloc(TEXT_BUFFER_SIZE);
*current_info->mpd.name=0;
*current_info->mpd.file=0;
*current_info->mpd.artist=0;
*current_info->mpd.album=0;
*current_info->mpd.title=0;
*current_info->mpd.random=0;
*current_info->mpd.repeat=0;
*current_info->mpd.track=0;
strncpy(current_info->mpd.status, "Stopped",
TEXT_BUFFER_SIZE - 1);
}
if (status->state == MPD_STATUS_STATE_PAUSE) {
if (current_info->mpd.status == NULL)
current_info->mpd.status =
malloc(TEXT_BUFFER_SIZE);
strncpy(current_info->mpd.status, "Paused",
TEXT_BUFFER_SIZE - 1);
}
if (status->state == MPD_STATUS_STATE_UNKNOWN) {
current_info->mpd.bitrate = 0;
current_info->mpd.progress = 0;
current_info->mpd.elapsed = 0;
current_info->mpd.length = 0;
if (current_info->mpd.artist == NULL)
current_info->mpd.artist =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.album == NULL)
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.title == NULL)
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.random == NULL)
current_info->mpd.random =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.repeat == NULL)
current_info->mpd.repeat =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.track == NULL)
current_info->mpd.track = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.status == NULL)
current_info->mpd.status =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.name == NULL)
current_info->mpd.name = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.file == NULL)
current_info->mpd.file = malloc(TEXT_BUFFER_SIZE);
*current_info->mpd.name=0;
*current_info->mpd.file=0;
*current_info->mpd.artist=0;
*current_info->mpd.album=0;
*current_info->mpd.title=0;
*current_info->mpd.random=0;
*current_info->mpd.repeat=0;
*current_info->mpd.track=0;
*current_info->mpd.status=0;
// current_info was already cleaned up by clear_mpd_stats()
}
if (status->state == MPD_STATUS_STATE_PLAY ||
status->state == MPD_STATUS_STATE_PAUSE) {
@ -210,12 +110,6 @@ void update_mpd()
(float) status->elapsedTime / status->totalTime;
current_info->mpd.elapsed = status->elapsedTime;
current_info->mpd.length = status->totalTime;
if (current_info->mpd.random == NULL)
current_info->mpd.random =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.repeat == NULL)
current_info->mpd.repeat =
malloc(TEXT_BUFFER_SIZE);
if (status->random == 0) {
strcpy(current_info->mpd.random, "Off");
} else if (status->random == 1) {
@ -248,19 +142,6 @@ void update_mpd()
continue;
}
if (current_info->mpd.artist == NULL)
current_info->mpd.artist =
malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.album == NULL)
current_info->mpd.album = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.title == NULL)
current_info->mpd.title = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.track == NULL)
current_info->mpd.track = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.name == NULL)
current_info->mpd.name = malloc(TEXT_BUFFER_SIZE);
if (current_info->mpd.file == NULL)
current_info->mpd.file = malloc(TEXT_BUFFER_SIZE);
if (song->artist) {
strncpy(current_info->mpd.artist, song->artist,
TEXT_BUFFER_SIZE - 1);

View File

@ -110,6 +110,11 @@ void update_uptime()
}
}
int check_mount(char *s)
{
/* stub */
return 0;
}
void update_meminfo()
{

View File

@ -105,6 +105,12 @@ swapmode(int *used, int *total)
return 1;
}
int check_mount(char *s)
{
/* stub */
return 0;
}
void
update_uptime()
{

View File

@ -50,3 +50,9 @@ void update_meminfo()
{
/* TODO */
}
int check_mount(char *s)
{
/* stub */
return 0;
}

View File

@ -16,191 +16,195 @@
/* callbacks */
void connection_lost( void *ptr ) {
((struct information *)ptr)->xmms2_conn_state = CONN_NO;
static void xmms_alloc(struct information *ptr)
{
if (ptr->xmms2.status == NULL) {
ptr->xmms2.status = malloc(TEXT_BUFFER_SIZE);
ptr->xmms2.status[0] = '\0';
}
if ( ((struct information *)ptr)->xmms2.status == NULL )
((struct information *)ptr)->xmms2.status = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.status, "xmms2 not responding", TEXT_BUFFER_SIZE - 1 );
if (ptr->xmms2.artist == NULL) {
ptr->xmms2.artist = malloc(TEXT_BUFFER_SIZE);
ptr->xmms2.artist[0] = '\0';
}
if (ptr->xmms2.album == NULL) {
ptr->xmms2.album = malloc(TEXT_BUFFER_SIZE);
ptr->xmms2.album[0] = '\0';
}
if ( ((struct information *)ptr)->xmms2.artist == NULL )
((struct information *)ptr)->xmms2.artist = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.artist, "", TEXT_BUFFER_SIZE - 1 );
if (ptr->xmms2.title == NULL) {
ptr->xmms2.title = malloc(TEXT_BUFFER_SIZE);
ptr->xmms2.title[0] = '\0';
}
if ( ((struct information *)ptr)->xmms2.album == NULL )
((struct information *)ptr)->xmms2.album = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.album, "", TEXT_BUFFER_SIZE - 1 );
if (ptr->xmms2.genre == NULL) {
ptr->xmms2.genre = malloc(TEXT_BUFFER_SIZE);
ptr->xmms2.genre[0] = '\0';
}
if ( ((struct information *)ptr)->xmms2.title == NULL )
((struct information *)ptr)->xmms2.title = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.title, "", TEXT_BUFFER_SIZE - 1 );
if (ptr->xmms2.comment == NULL) {
ptr->xmms2.comment = malloc(TEXT_BUFFER_SIZE);
ptr->xmms2.comment[0] = '\0';
}
if ( ((struct information *)ptr)->xmms2.genre == NULL )
((struct information *)ptr)->xmms2.genre = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.genre, "", TEXT_BUFFER_SIZE - 1 );
if (ptr->xmms2.decoder == NULL) {
ptr->xmms2.decoder = malloc(TEXT_BUFFER_SIZE);
ptr->xmms2.decoder[0] = '\0';
}
if ( ((struct information *)ptr)->xmms2.comment == NULL )
((struct information *)ptr)->xmms2.comment = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.comment, "", TEXT_BUFFER_SIZE - 1 );
if (ptr->xmms2.transport == NULL) {
ptr->xmms2.transport = malloc(TEXT_BUFFER_SIZE);
ptr->xmms2.transport[0] = '\0';
}
if ( ((struct information *)ptr)->xmms2.decoder == NULL )
((struct information *)ptr)->xmms2.decoder = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.decoder, "", TEXT_BUFFER_SIZE - 1 );
if (ptr->xmms2.url == NULL) {
ptr->xmms2.url = malloc(TEXT_BUFFER_SIZE);
ptr->xmms2.url[0] = '\0';
}
if ( ((struct information *)ptr)->xmms2.transport == NULL )
((struct information *)ptr)->xmms2.transport = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.transport, "", TEXT_BUFFER_SIZE - 1 );
if ( ((struct information *)ptr)->xmms2.url == NULL )
((struct information *)ptr)->xmms2.url = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.url, "", TEXT_BUFFER_SIZE - 1 );
if ( ((struct information *)ptr)->xmms2.date == NULL )
((struct information *)ptr)->xmms2.date = malloc( TEXT_BUFFER_SIZE );
strncpy( ((struct information *)ptr)->xmms2.date, "", TEXT_BUFFER_SIZE - 1 );
((struct information *)ptr)->xmms2.tracknr = 0;
((struct information *)ptr)->xmms2.id = 0;
((struct information *)ptr)->xmms2.bitrate = 0;
((struct information *)ptr)->xmms2.duration = 0;
((struct information *)ptr)->xmms2.elapsed = 0;
((struct information *)ptr)->xmms2.size = 0;
((struct information *)ptr)->xmms2.progress = 0;
if (ptr->xmms2.date == NULL) {
ptr->xmms2.date = malloc(TEXT_BUFFER_SIZE);
ptr->xmms2.date[0] = '\0';
}
}
void handle_curent_id( xmmsc_result_t *res, void *ptr ) {
static void xmms_clear(struct information *ptr) {
xmms_alloc(ptr);
ptr->xmms2.status[0] = '\0';
ptr->xmms2.artist[0] = '\0';
ptr->xmms2.album[0] = '\0';
ptr->xmms2.title[0] = '\0';
ptr->xmms2.genre[0] = '\0';
ptr->xmms2.comment[0] = '\0';
ptr->xmms2.decoder[0] = '\0';
ptr->xmms2.transport[0] = '\0';
ptr->xmms2.url[0] = '\0';
ptr->xmms2.date[0] = '\0';
}
void connection_lost(void *p)
{
struct information *ptr = p;
ptr->xmms2_conn_state = CONN_NO;
xmms_clear(ptr);
ptr->xmms2.tracknr = 0;
ptr->xmms2.id = 0;
ptr->xmms2.bitrate = 0;
ptr->xmms2.duration = 0;
ptr->xmms2.elapsed = 0;
ptr->xmms2.size = 0;
ptr->xmms2.progress = 0;
}
void handle_curent_id(xmmsc_result_t *res, void *p)
{
uint current_id;
struct information *ptr = p;
if ( xmmsc_result_get_uint( res, &current_id ) ) {
xmmsc_result_t *res2;
res2 = xmmsc_medialib_get_info( ((struct information *)ptr)->xmms2_conn, current_id );
res2 = xmmsc_medialib_get_info(ptr->xmms2_conn, current_id);
xmmsc_result_wait( res2 );
xmms_clear(ptr);
if ( ((struct information *)ptr)->xmms2.artist == NULL )
((struct information *)ptr)->xmms2.artist = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.album == NULL )
((struct information *)ptr)->xmms2.album = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.title == NULL )
((struct information *)ptr)->xmms2.title = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.genre == NULL )
((struct information *)ptr)->xmms2.genre = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.comment == NULL )
((struct information *)ptr)->xmms2.comment = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.decoder == NULL )
((struct information *)ptr)->xmms2.decoder = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.transport == NULL )
((struct information *)ptr)->xmms2.transport = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.url == NULL )
((struct information *)ptr)->xmms2.url = malloc( TEXT_BUFFER_SIZE );
if ( ((struct information *)ptr)->xmms2.date == NULL )
((struct information *)ptr)->xmms2.date = malloc( TEXT_BUFFER_SIZE );
((struct information *)ptr)->xmms2.id = current_id;
ptr->xmms2.id = current_id;
char *temp;
xmmsc_result_get_dict_entry_string( res2, "artist", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.artist, temp, TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.artist, temp, TEXT_BUFFER_SIZE - 1);
} else {
strncpy( ((struct information *)ptr)->xmms2.artist, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.artist, "[Unknown]", TEXT_BUFFER_SIZE - 1);
}
xmmsc_result_get_dict_entry_string( res2, "title", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.title, temp, TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.title, temp, TEXT_BUFFER_SIZE - 1);
} else {
strncpy( ((struct information *)ptr)->xmms2.title, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.title, "[Unknown]", TEXT_BUFFER_SIZE - 1);
}
xmmsc_result_get_dict_entry_string( res2, "album", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.album, temp, TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.album, temp, TEXT_BUFFER_SIZE - 1);
} else {
strncpy( ((struct information *)ptr)->xmms2.album, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.album, "[Unknown]", TEXT_BUFFER_SIZE - 1);
}
xmmsc_result_get_dict_entry_string( res2, "genre", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.genre, temp, TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.genre, temp, TEXT_BUFFER_SIZE - 1);
} else {
strncpy( ((struct information *)ptr)->xmms2.genre, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.genre, "[Unknown]", TEXT_BUFFER_SIZE - 1);
}
xmmsc_result_get_dict_entry_string( res2, "comment", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.comment, temp, TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.comment, temp, TEXT_BUFFER_SIZE - 1);
} else {
strncpy( ((struct information *)ptr)->xmms2.comment, "", TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.comment, "", TEXT_BUFFER_SIZE - 1);
}
xmmsc_result_get_dict_entry_string( res2, "decoder", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.decoder, temp, TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.decoder, temp, TEXT_BUFFER_SIZE - 1);
} else {
strncpy( ((struct information *)ptr)->xmms2.decoder, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.decoder, "[Unknown]", TEXT_BUFFER_SIZE - 1);
}
xmmsc_result_get_dict_entry_string( res2, "transport", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.transport, temp, TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.transport, temp, TEXT_BUFFER_SIZE - 1);
} else {
strncpy( ((struct information *)ptr)->xmms2.transport, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.transport, "[Unknown]", TEXT_BUFFER_SIZE - 1);
}
xmmsc_result_get_dict_entry_string( res2, "url", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.url, temp, TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.url, temp, TEXT_BUFFER_SIZE - 1);
} else {
strncpy( ((struct information *)ptr)->xmms2.url, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.url, "[Unknown]", TEXT_BUFFER_SIZE - 1);
}
xmmsc_result_get_dict_entry_string( res2, "date", &temp );
if ( temp != NULL ) {
strncpy( ((struct information *)ptr)->xmms2.date, temp, TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.date, temp, TEXT_BUFFER_SIZE - 1);
} else {
strncpy( ((struct information *)ptr)->xmms2.date, "????", TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.date, "????", TEXT_BUFFER_SIZE - 1);
}
int itemp;
xmmsc_result_get_dict_entry_int( res2, "tracknr", &itemp );
((struct information *)ptr)->xmms2.tracknr = itemp;
ptr->xmms2.tracknr = itemp;
xmmsc_result_get_dict_entry_int( res2, "duration", &itemp );
((struct information *)ptr)->xmms2.duration = itemp;
ptr->xmms2.duration = itemp;
xmmsc_result_get_dict_entry_int( res2, "bitrate", &itemp );
((struct information *)ptr)->xmms2.bitrate = itemp / 1000;
ptr->xmms2.bitrate = itemp / 1000;
xmmsc_result_get_dict_entry_int( res2, "size", &itemp );
((struct information *)ptr)->xmms2.size = (float)itemp / 1048576;
ptr->xmms2.size = (float)itemp / 1048576;
xmmsc_result_unref( res2 );
}
}
void handle_playtime( xmmsc_result_t *res, void *ptr ) {
void handle_playtime(xmmsc_result_t *res, void *p) {
struct information *ptr = p;
xmmsc_result_t * res2;
uint play_time;
@ -213,11 +217,12 @@ void handle_playtime( xmmsc_result_t *res, void *ptr ) {
res2 = xmmsc_result_restart( res );
xmmsc_result_unref( res2 );
((struct information *)ptr)->xmms2.elapsed = play_time;
((struct information *)ptr)->xmms2.progress = (float) play_time / ((struct information *)ptr)->xmms2.duration;
ptr->xmms2.elapsed = play_time;
ptr->xmms2.progress = (float) play_time / ptr->xmms2.duration;
}
void handle_playback_state_change( xmmsc_result_t *res, void *ptr ) {
void handle_playback_state_change(xmmsc_result_t *res, void *p) {
struct information *ptr = p;
uint pb_state = 0;
if ( xmmsc_result_iserror( res ) )
return;
@ -225,25 +230,18 @@ void handle_playback_state_change( xmmsc_result_t *res, void *ptr ) {
if ( !xmmsc_result_get_uint( res, &pb_state ) )
return;
if ( ((struct information *)ptr)->xmms2.status == NULL )
((struct information *)ptr)->xmms2.status = malloc( TEXT_BUFFER_SIZE );
switch (pb_state) {
case XMMS_PLAYBACK_STATUS_PLAY:
strncpy( ((struct information *)ptr)->xmms2.status,
"Playing", TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.status, "Playing", TEXT_BUFFER_SIZE - 1);
break;
case XMMS_PLAYBACK_STATUS_PAUSE:
strncpy( ((struct information *)ptr)->xmms2.status,
"Paused", TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.status, "Paused", TEXT_BUFFER_SIZE - 1);
break;
case XMMS_PLAYBACK_STATUS_STOP:
strncpy( ((struct information *)ptr)->xmms2.status,
"Stopped", TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.status, "Stopped", TEXT_BUFFER_SIZE - 1);
break;
default:
strncpy( ((struct information *)ptr)->xmms2.status,
"Unknown", TEXT_BUFFER_SIZE - 1 );
strncpy(ptr->xmms2.status, "Unknown", TEXT_BUFFER_SIZE - 1);
}
}
@ -269,42 +267,7 @@ void update_xmms2() {
current_info->xmms2_conn_state = CONN_NO;
/* clear all values */
if ( current_info->xmms2.artist == NULL )
current_info->xmms2.artist = malloc( TEXT_BUFFER_SIZE );
strncpy( current_info->xmms2.artist, "", TEXT_BUFFER_SIZE - 1 );
if ( current_info->xmms2.album == NULL )
current_info->xmms2.album = malloc( TEXT_BUFFER_SIZE );
strncpy( current_info->xmms2.album, "", TEXT_BUFFER_SIZE - 1 );
if ( current_info->xmms2.title == NULL )
current_info->xmms2.title = malloc( TEXT_BUFFER_SIZE );
strncpy( current_info->xmms2.title, "", TEXT_BUFFER_SIZE - 1 );
if ( current_info->xmms2.genre == NULL )
current_info->xmms2.genre = malloc( TEXT_BUFFER_SIZE );
strncpy( current_info->xmms2.genre, "", TEXT_BUFFER_SIZE - 1 );
if ( current_info->xmms2.comment == NULL )
current_info->xmms2.comment = malloc( TEXT_BUFFER_SIZE );
strncpy( current_info->xmms2.comment, "", TEXT_BUFFER_SIZE - 1 );
if ( current_info->xmms2.decoder == NULL )
current_info->xmms2.decoder = malloc( TEXT_BUFFER_SIZE );
strncpy( current_info->xmms2.decoder, "", TEXT_BUFFER_SIZE - 1 );
if ( current_info->xmms2.transport == NULL )
current_info->xmms2.transport = malloc( TEXT_BUFFER_SIZE );
strncpy( current_info->xmms2.transport, "", TEXT_BUFFER_SIZE - 1 );
if ( current_info->xmms2.url == NULL )
current_info->xmms2.url = malloc( TEXT_BUFFER_SIZE );
strncpy( current_info->xmms2.url, "", TEXT_BUFFER_SIZE - 1 );
if ( current_info->xmms2.date == NULL )
current_info->xmms2.date = malloc( TEXT_BUFFER_SIZE );
strncpy( current_info->xmms2.date, "", TEXT_BUFFER_SIZE - 1 );
xmms_clear(current_info);
current_info->xmms2.tracknr = 0;
current_info->xmms2.id = 0;
@ -342,13 +305,10 @@ void update_xmms2() {
xmmsc_result_wait ( res );
unsigned int pb_state;
if ( current_info->xmms2.status == NULL )
current_info->xmms2.status = malloc( TEXT_BUFFER_SIZE );
xmmsc_result_get_uint( res, &pb_state );
switch (pb_state) {
case XMMS_PLAYBACK_STATUS_PLAY:
strncpy( current_info->xmms2.status,
strncpy(current_info->xmms2.status,
"Playing", TEXT_BUFFER_SIZE - 1 );
break;
case XMMS_PLAYBACK_STATUS_PAUSE: