1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-25 04:06:03 +00:00

fs_bar, fs_bar_free: merge init and print routines

This commit is contained in:
Phil Sutter 2009-10-04 15:50:47 +02:00
parent b9a28c37a8
commit 4d70cf07b8
4 changed files with 55 additions and 83 deletions

View File

@ -1744,34 +1744,7 @@ static void generate_text_internal(char *p, int p_max_size,
}
}
OBJ(fs_bar) {
if (obj->data.fs != NULL) {
if (obj->data.fs->size == 0) {
#ifdef X11
if(output_methods & TO_X) {
new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
}else{
#endif /* X11 */
if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
new_bar_in_shell(p, p_max_size, 100, obj->data.fsbar.w);
#ifdef X11
}
#endif /* X11 */
} else {
#ifdef X11
if(output_methods & TO_X) {
new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
(int) (255 - obj->data.fsbar.fs->avail * 255 /
obj->data.fs->size));
}else{
#endif /* X11 */
if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
new_bar_in_shell(p, p_max_size,
(int) (100 - obj->data.fsbar.fs->avail * 100 / obj->data.fs->size), obj->data.fsbar.w);
#ifdef X11
}
#endif /* X11 */
}
}
print_fs_bar(obj, 0, p, p_max_size);
}
OBJ(fs_free) {
if (obj->data.fs != NULL) {
@ -1805,34 +1778,7 @@ static void generate_text_internal(char *p, int p_max_size,
}
}
OBJ(fs_bar_free) {
if (obj->data.fs != NULL) {
if (obj->data.fs->size == 0) {
#ifdef X11
if(output_methods & TO_X) {
new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
}else{
#endif /* X11 */
if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
new_bar_in_shell(p, p_max_size, 100, obj->data.fsbar.w);
#ifdef X11
}
#endif /* X11 */
} else {
#ifdef X11
if(output_methods & TO_X) {
new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
(int) (obj->data.fsbar.fs->avail * 255 /
obj->data.fs->size));
}else{
#endif /* X11 */
if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
new_bar_in_shell(p, p_max_size,
(int) (obj->data.fsbar.fs->avail * 100 / obj->data.fs->size), obj->data.fsbar.w);
#ifdef X11
}
#endif /* X11 */
}
}
print_fs_bar(obj, 1, p, p_max_size);
}
OBJ(fs_used_perc) {
if (obj->data.fs != NULL) {

View File

@ -713,34 +713,9 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
obj->data.s = strndup("", text_buffer_size);
}
END OBJ(fs_bar, &update_fs_stats)
SIZE_DEFAULTS(bar);
arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
if (arg) {
while (isspace(*arg)) {
arg++;
}
if (*arg == '\0') {
arg = "/";
}
} else {
arg = "/";
}
obj->data.fsbar.fs = prepare_fs_stat(arg);
init_fs_bar(obj, arg);
END OBJ(fs_bar_free, &update_fs_stats)
SIZE_DEFAULTS(bar);
arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
if (arg) {
while (isspace(*arg)) {
arg++;
}
if (*arg == '\0') {
arg = "/";
}
} else {
arg = "/";
}
obj->data.fsbar.fs = prepare_fs_stat(arg);
init_fs_bar(obj, arg);
END OBJ(fs_free, &update_fs_stats)
if (!arg) {
arg = "/";

View File

@ -31,6 +31,9 @@
#include "conky.h"
#include "logging.h"
#include "fs.h"
#include "specials.h"
#include "text_object.h"
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
@ -191,3 +194,46 @@ void get_fs_type(const char *path, char *result)
strncpy(result, "unknown", DEFAULT_TEXT_BUFFER_SIZE);
}
void init_fs_bar(struct text_object *obj, const char *arg)
{
SIZE_DEFAULTS(bar);
arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
if (arg) {
while (isspace(*arg)) {
arg++;
}
if (*arg == '\0') {
arg = "/";
}
} else {
arg = "/";
}
obj->data.fsbar.fs = prepare_fs_stat(arg);
}
void print_fs_bar(struct text_object *obj, int be_free_bar, char *p, int p_max_size)
{
double val;
if (!obj->data.fsbar.fs)
return;
if (!obj->data.fsbar.fs->size)
val = 1.0;
else
val = (double)obj->data.fsbar.fs->avail / (double)obj->data.fsbar.fs->size;
if (!be_free_bar)
val = 1.0 - val;
#ifdef X11
if(output_methods & TO_X) {
new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, (int)(255 * val));
}else
#endif /* X11 */
{
if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
new_bar_in_shell(p, p_max_size, (int)(100 * val), obj->data.fsbar.w);
}
}

View File

@ -15,6 +15,11 @@ struct fs_stat {
char set;
};
/* forward declare to make gcc happy (fs.h <-> text_object.h include) */
struct text_object;
void init_fs_bar(struct text_object *, const char *);
void print_fs_bar(struct text_object *, int, char *, int);
void update_fs_stats(void);
struct fs_stat *prepare_fs_stat(const char *path);
void clear_fs_stats(void);