diff --git a/src/Makefile.am b/src/Makefile.am index 0dc7241f..a984f64a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -65,7 +65,7 @@ ibm = ibm.c ibm.h smapi.c smapi.h mpd = mpd.c mpd.h libmpdclient.c libmpdclient.h moc = moc.c moc.h xmms2 = xmms2.c xmms2.h -linux = linux.c linux.h top.c top.h users.c sony.c sony.h i8k.c i8k.h +linux = linux.c linux.h top.c top.h users.c users.h sony.c sony.h i8k.c i8k.h solaris = solaris.c freebsd = freebsd.c freebsd.h netbsd = netbsd.c netbsd.h diff --git a/src/conky.c b/src/conky.c index 53dd3cd7..9a8ce42c 100644 --- a/src/conky.c +++ b/src/conky.c @@ -1273,24 +1273,6 @@ void generate_text_internal(char *p, int p_max_size, DO_JUMP; } } -#ifdef __linux__ - OBJ(user_names) { - snprintf(p, p_max_size, "%s", cur->users.names); - } - OBJ(user_terms) { - snprintf(p, p_max_size, "%s", cur->users.terms); - } - OBJ(user_times) { - snprintf(p, p_max_size, "%s", cur->users.times); - } - OBJ(user_time) { - update_user_time(obj->data.s); - snprintf(p, p_max_size, "%s", cur->users.ctime); - } - OBJ(user_number) { - snprintf(p, p_max_size, "%d", cur->users.number); - } -#endif /* __linux__ */ #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \ || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__)) OBJ(apm_adapter) { diff --git a/src/conky.h b/src/conky.h index 78782884..6ba7026c 100644 --- a/src/conky.h +++ b/src/conky.h @@ -307,10 +307,6 @@ extern int cpu_separate; * instances of the same text object */ extern struct information info; -/* defined in users.c */ -void update_users(void); -void update_user_time(char *tty); - /* defined in conky.c */ extern double current_update_time, last_update_time, update_interval; diff --git a/src/core.c b/src/core.c index 1b724d2f..d3df6fd7 100644 --- a/src/core.c +++ b/src/core.c @@ -63,6 +63,7 @@ #include "tailhead.h" #include "timeinfo.h" #include "top.h" +#include "users.h" #ifdef NCURSES #include @@ -1047,11 +1048,20 @@ struct text_object *construct_text_object(const char *s, const char *arg, long obj->callbacks.print = &print_uptime; #if defined(__linux__) END OBJ(user_names, &update_users) + obj->callbacks.print = &print_user_names; + obj->callbacks.free = &free_user_names; END OBJ(user_times, &update_users) + obj->callbacks.print = &print_user_times; + obj->callbacks.free = &free_user_times; END OBJ_ARG(user_time, 0, "user time needs a console name as argument") obj->data.s = strndup(arg, text_buffer_size); + obj->callbacks.print = &print_user_time; + obj->callbacks.free = &free_user_time; END OBJ(user_terms, &update_users) + obj->callbacks.print = &print_user_terms; + obj->callbacks.free = &free_user_terms; END OBJ(user_number, &update_users) + obj->callbacks.print = &print_user_number; END OBJ(gw_iface, &update_gateway_info) obj->callbacks.print = &print_gateway_iface; END OBJ(gw_ip, &update_gateway_info) @@ -1885,33 +1895,6 @@ void free_text_objects(struct text_object *root, int internal) free_top(obj, internal); break; #endif /* __linux__ */ - case OBJ_user_names: - if (info.users.names) { - free(info.users.names); - info.users.names = 0; - } - break; - case OBJ_user_terms: - if (info.users.terms) { - free(info.users.terms); - info.users.terms = 0; - } - break; - case OBJ_user_times: - if (info.users.times) { - free(info.users.times); - info.users.times = 0; - } - break; - case OBJ_user_time: - if (info.users.ctime) { - free(info.users.ctime); - info.users.ctime = 0; - } - if (data.s) { - free(data.s); - } - break; #ifdef MPD case OBJ_mpd_title: case OBJ_mpd_artist: diff --git a/src/users.c b/src/users.c index 73e8d08a..576488e1 100644 --- a/src/users.c +++ b/src/users.c @@ -129,7 +129,7 @@ static void users_alloc(struct information *ptr) } } -void update_user_time(char *tty) +static void update_user_time(char *tty) { struct information *current_info = &info; char temp[BUFLEN] = ""; @@ -222,3 +222,70 @@ void update_users(void) strncpy(current_info->users.times, "broken", text_buffer_size); } } + +void print_user_names(struct text_object *obj, char *p, int p_max_size) +{ + (void)obj; + snprintf(p, p_max_size, "%s", info.users.names); +} + +void print_user_terms(struct text_object *obj, char *p, int p_max_size) +{ + (void)obj; + snprintf(p, p_max_size, "%s", info.users.terms); +} + +void print_user_times(struct text_object *obj, char *p, int p_max_size) +{ + (void)obj; + snprintf(p, p_max_size, "%s", info.users.times); +} + +void print_user_time(struct text_object *obj, char *p, int p_max_size) +{ + update_user_time(obj->data.s); + snprintf(p, p_max_size, "%s", info.users.ctime); +} + +void print_user_number(struct text_object *obj, char *p, int p_max_size) +{ + (void)obj; + snprintf(p, p_max_size, "%d", info.users.number); +} + +void free_user_names(struct text_object *obj) +{ + (void)obj; + if (info.users.names) { + free(info.users.names); + info.users.names = 0; + } +} + +void free_user_terms(struct text_object *obj) +{ + (void)obj; + if (info.users.terms) { + free(info.users.terms); + info.users.terms = 0; + } +} + +void free_user_times(struct text_object *obj) +{ + (void)obj; + if (info.users.times) { + free(info.users.times); + info.users.times = 0; + } +} + +void free_user_time(struct text_object *obj) +{ + if (info.users.ctime) { + free(info.users.ctime); + info.users.ctime = 0; + } + if (obj->data.s) + free(obj->data.s); +} diff --git a/src/users.h b/src/users.h new file mode 100644 index 00000000..885fbc1c --- /dev/null +++ b/src/users.h @@ -0,0 +1,47 @@ +/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- + * vim: ts=4 sw=4 noet ai cindent syntax=c + * + * Conky, a system monitor, based on torsmo + * + * Any original torsmo code is licensed under the BSD license + * + * All code written since the fork of torsmo is licensed under the GPL + * + * Please see COPYING for details + * + * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen + * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al. + * (see AUTHORS) + * All rights reserved. + * + * 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 3 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, see . + * + */ + +#ifndef _USERS_H +#define _USERS_H + +void update_users(void); + +void print_user_names(struct text_object *, char *, int); +void print_user_terms(struct text_object *, char *, int); +void print_user_times(struct text_object *, char *, int); +void print_user_time(struct text_object *, char *, int); +void print_user_number(struct text_object *, char *, int); + +void free_user_names(struct text_object *); +void free_user_terms(struct text_object *); +void free_user_times(struct text_object *); +void free_user_time(struct text_object *); + +#endif /* _USERS_H */