"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "xdiskusage.C" between
xdiskusage-1.50.tgz and xdiskusage-1.51.tgz

About: Grapical display of disk usage (requires fltk)

xdiskusage.C  (xdiskusage-1.50.tgz):xdiskusage.C  (xdiskusage-1.51.tgz)
// xdiskusage.C // xdiskusage.C
const char* copyright = const char* copyright =
"xdiskusage version 1.50\n" "xdiskusage version 1.51\n"
"Copyright (C) 2014 Bill Spitzak\n" "Copyright (C) 2014 Bill Spitzak\n"
"Based on xdu by Phillip C. Dykstra\n" "Based on xdu by Phillip C. Dykstra\n"
"\n" "\n"
"This program is free software; you can redistribute it and/or modify " "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 " "it under the terms of the GNU General Public License as published by "
"the Free Software Foundation; either version 2 of the License, or " "the Free Software Foundation; either version 2 of the License, or "
"(at your option) any later version.\n" "(at your option) any later version.\n"
"\n" "\n"
"This program is distributed in the hope that it will be useful, " "This program is distributed in the hope that it will be useful, "
"but WITHOUT ANY WARRANTY; without even the implied warranty of " "but WITHOUT ANY WARRANTY; without even the implied warranty of "
skipping to change at line 59 skipping to change at line 59
#include <FL/Fl_Box.H> #include <FL/Fl_Box.H>
#include <FL/Fl_Menu_Button.H> #include <FL/Fl_Menu_Button.H>
#include <FL/fl_ask.H> #include <FL/fl_ask.H>
#include <FL/math.h> #include <FL/math.h>
typedef unsigned long long ull; typedef unsigned long long ull;
// turn number of K into user-friendly text: // turn number of K into user-friendly text:
const char* formatk(ull k) { const char* formatk(ull k) {
static char buffer[32]; static char buffer[32];
if (k >= 1024*1024*1024) sprintf(buffer,"%.4gT",(double)k/(1024*1024*1024)); int index = 0;
else if (k >= 1024*1024) sprintf(buffer,"%.4gG",(double)k/(1024*1024)); double dk = k;
else if (k >= 1024) sprintf(buffer,"%.4gM",(double)k/1024); while (dk >= 1024.0) {
else sprintf(buffer,"%.0fK",(double)k); index++;
dk /= 1024.0;
}
if (index)
sprintf(buffer, "%.4g%c", dk, "KMGTPEZY"[index]);
else
sprintf(buffer, "%dK", (int)k);
return buffer; return buffer;
} }
// Holds data read from 'df' for each disk // Holds data read from 'df' for each disk
struct Disk { struct Disk {
const char* mount; const char* mount;
ull total; ull total;
ull used; ull used;
ull avail; ull avail;
Disk* next; Disk* next;
skipping to change at line 136 skipping to change at line 142
d->used = strtoul(word[n-4],0,10); d->used = strtoul(word[n-4],0,10);
d->avail = strtoul(word[n-3],0,10); d->avail = strtoul(word[n-3],0,10);
*pointer = d; *pointer = d;
d->next = 0; d->next = 0;
pointer = &d->next; pointer = &d->next;
} }
pclose(f); pclose(f);
if (!firstdisk) { if (!firstdisk) {
alert("Something went wrong with df, no disks found."); alert("Something went wrong with df, no disks found.");
} else { return; // leave browser as-is
if (disk_browser) disk_browser->clear();
} }
// There is no browser widget if a file was given on the command line
if (!disk_browser)
return;
disk_browser->clear();
for (Disk* d = firstdisk; d; d = d->next) { for (Disk* d = firstdisk; d; d = d->next) {
char buf[512]; char buf[512];
int pct; int pct;
ull sum = d->used + d->avail; ull sum = d->used + d->avail;
if (!sum) { if (!sum) {
pct = 100; pct = 100;
} else { } else {
pct = int((d->used*100.0)/sum+.5); pct = int((d->used*100.0)/sum+.5);
if (!pct && d->used) pct = 1; if (!pct && d->used) pct = 1;
} }
const char* mount = d->mount; const char* mount = d->mount;
if (strlen(mount) > 255) mount = d->mount + strlen(mount) - 255; if (strlen(mount) > 255) mount = d->mount + strlen(mount) - 255;
#if FL_MAJOR_VERSION > 1 #if FL_MAJOR_VERSION > 1 || FL_MINOR_VERSION >= 3
static const char* labels[] = {"mounted at", "size", "usage", 0}; static int widths[] = {0, 0, 0};
static int widths[] = {-1, 50, 50, 0};
if (d==firstdisk) { if (d==firstdisk) {
if (widths[0] == 0) {
int n = disk_browser->textsize();
fl_font(disk_browser->textfont(), n);
widths[0] = fl_width("2.222Mn");
widths[1] = fl_width("00% n");
}
disk_browser->column_widths(widths); disk_browser->column_widths(widths);
disk_browser->column_labels(labels);
} }
sprintf(buf, "@b;%s\t@n@r;%s\t@r;%2d%% \t", d->mount, formatk(d->total), pct ); sprintf(buf, "@r%s\t@r%d%% \t@b%s", formatk(d->total), pct, d->mount);
#else #else
#if FL_MINOR_VERSION >= 3 sprintf(buf, "%s %02d%% %s", formatk(d->total), pct, d->mount);
static int widths[] = {280, 0};
if (d==firstdisk)
disk_browser->column_widths(widths);
#endif #endif
sprintf(buf, "@b%s\t@r%s %2d%%", d->mount, formatk(d->total), pct); disk_browser->add(buf);
#endif
if (disk_browser) disk_browser->add(buf);
} }
if (disk_browser) { disk_browser->position(0);
disk_browser->position(0);
#if FL_MAJOR_VERSION > 1 #if FL_MAJOR_VERSION > 1
disk_browser->deselect(); disk_browser->deselect();
#endif #endif
}
} }
Fl_Window *copyright_window; Fl_Window *copyright_window;
void copyright_cb(Fl_Button*, void*) { void copyright_cb(Fl_Button*, void*) {
if (!copyright_window) { if (!copyright_window) {
copyright_window = new Fl_Window(400,360,"About xdiskusage"); copyright_window = new Fl_Window(400,360,"About xdiskusage");
copyright_window->color(FL_WHITE); copyright_window->color(FL_WHITE);
Fl_Box *b = new Fl_Box(10,0,380,360,copyright); Fl_Box *b = new Fl_Box(10,0,380,360,copyright);
#ifdef FL_NORMAL_SIZE #ifdef FL_NORMAL_SIZE
b->labelsize(12); b->labelsize(12);
skipping to change at line 331 skipping to change at line 339
make_diskchooser(); make_diskchooser();
reload_cb(0,0); reload_cb(0,0);
disk_chooser->show(argc,argv); disk_chooser->show(argc,argv);
} }
return Fl::run(); return Fl::run();
} }
void disk_browser_cb(Fl_Browser*b, void*) { void disk_browser_cb(Fl_Browser*b, void*) {
int i = b->value(); int i = b->value();
//printf("disk browser cb %d\n", i); //printf("disk browser cb %d\n", i);
#if FL_MAJOR_VERSION > 1 #if FL_MAJOR_VERSION < 2
if (i < 0) return;
#else
i--; i--;
#endif #endif
if (i < 0) return;
Disk* d; Disk* d;
for (d = firstdisk; i > 0; i--) d = d->next; for (d = firstdisk; i > 0; i--) d = d->next;
all_files = all_files_button->value(); all_files = all_files_button->value();
OutputWindow* w = OutputWindow::make(d->mount, d); OutputWindow* w = OutputWindow::make(d->mount, d);
if (w) w->show(); if (w) w->show();
//b->value(0); //b->value(0);
} }
#include <FL/filename.H> #include <FL/filename.H>
 End of changes. 15 change blocks. 
26 lines changed or deleted 33 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS