X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Ffs.c;h=2152552b6be8243dc4246e3d4a4d5ad2810841ea;hb=3293e076c500eef4ca11a72bfb6954412c341228;hp=044317aaeb2ae8437d6711b08609324a63de8c4a;hpb=44b82311b9a16e4134242cd5f8d4acbeb881b08a;p=monky diff --git a/src/fs.c b/src/fs.c index 044317a..2152552 100644 --- a/src/fs.c +++ b/src/fs.c @@ -1,4 +1,5 @@ /* -*- 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 * @@ -9,7 +10,7 @@ * Please see COPYING for details * * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen - * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al. + * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al. * (see AUTHORS) * All rights reserved. * @@ -25,13 +26,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * - * vim: ts=4 sw=4 noet ai cindent syntax=c - * */ #include "conky.h" #include "logging.h" #include "fs.h" +#include "specials.h" +#include "text_object.h" +#include #include #include #include @@ -63,15 +65,21 @@ static void update_fs_stat(struct fs_stat *fs); void get_fs_type(const char *path, char *result); -void update_fs_stats(void) +int update_fs_stats(void) { unsigned i; + static double last_fs_update = 0.0; + + if (current_update_time - last_fs_update < 13) + return 0; for (i = 0; i < MAX_FS_STATS; ++i) { if (fs_stats[i].set) { update_fs_stat(&fs_stats[i]); } } + last_fs_update = current_update_time; + return 0; } void clear_fs_stats(void) @@ -187,3 +195,69 @@ 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) +{ + arg = scan_bar(obj, arg); + if (arg) { + while (isspace(*arg)) { + arg++; + } + if (*arg == '\0') { + arg = "/"; + } + } else { + arg = "/"; + } + obj->data.opaque = prepare_fs_stat(arg); +} + +static double get_fs_perc(struct fs_stat *fs, int get_free) +{ + double ret = 0.0; + + if(fs && fs->size) { + if(get_free) + ret = fs->avail; + else + ret = fs->size - fs->free; + ret /= fs->size; + } + + return ret; +} + +void print_fs_bar(struct text_object *obj, int be_free_bar, char *p, int p_max_size) +{ + new_bar(obj, p, p_max_size, (int)(get_fs_perc(obj->data.opaque, be_free_bar) * 255) ); +} + +void init_fs(struct text_object *obj, const char *arg) +{ + obj->data.opaque = prepare_fs_stat(arg ? arg : "/"); +} + +void print_fs_perc(struct text_object *obj, int be_free, char *p, int p_max_size) +{ + percent_print(p, p_max_size, (int)(get_fs_perc(obj->data.opaque, be_free) * 100) ); +} + +#define HUMAN_PRINT_FS_GENERATOR(name, expr) \ +void print_fs_##name(struct text_object *obj, char *p, int p_max_size) \ +{ \ + struct fs_stat *fs = obj->data.opaque; \ + if (fs) \ + human_readable(expr, p, p_max_size); \ +} + +HUMAN_PRINT_FS_GENERATOR(free, fs->avail) +HUMAN_PRINT_FS_GENERATOR(size, fs->size) +HUMAN_PRINT_FS_GENERATOR(used, fs->size - fs->free) + +void print_fs_type(struct text_object *obj, char *p, int p_max_size) +{ + struct fs_stat *fs = obj->data.opaque; + + if (fs) + snprintf(p, p_max_size, "%s", fs->type); +}