disks: ....

So, at some point, select a file system then below a panel with
something visual...probbaly for starters some visual indicator
of large folders and ideally activity too...

not done for now...shouldn't break the universe tho
This commit is contained in:
Alastair Poole 2020-11-03 15:38:42 +00:00
parent bc62f73b62
commit 68fa73e599
2 changed files with 232 additions and 201 deletions

View File

@ -88,8 +88,6 @@ typedef struct Ui
struct struct
{ {
Evas_Object *win; Evas_Object *win;
Evas_Object *box;
Ecore_Timer *timer;
} disk; } disk;
struct struct

View File

@ -1,220 +1,210 @@
#include "ui_disk.h" #include "ui_disk.h"
#include "../system/disks.h" #include "../system/disks.h"
Eina_Hash *_mounted; typedef struct
typedef struct _Item_Disk
{ {
Evas_Object *parent; Evas_Object *btn_device;
Evas_Object *pb; Evas_Object *btn_mount;
Evas_Object *lbl; Evas_Object *btn_fs;
Evas_Object *btn_usage;
Evas_Object *btn_used;
Evas_Object *btn_total;
Evas_Object *genlist;
Evisum_Ui_Cache *cache;
Ecore_Timer *timer;
} Widgets;
char *path; static Widgets *_widgets = NULL;
} Item_Disk;
static char *
_file_system_usage_format(File_System *inf)
{
return strdup(eina_slstr_printf("%s / %s",
evisum_size_format(inf->usage.used),
evisum_size_format(inf->usage.total)));
}
static void static void
_separator_add(Evas_Object *box) _item_del(void *data, Evas_Object *obj EINA_UNUSED)
{ {
Evas_Object *hbox, *sep; File_System *inf = data;
hbox = elm_box_add(box); file_system_info_free(inf);
elm_box_horizontal_set(hbox, EINA_TRUE);
evas_object_size_hint_weight_set(hbox, EXPAND, EXPAND);
evas_object_size_hint_align_set(hbox, FILL, FILL);
evas_object_show(hbox);
sep = elm_separator_add(hbox);
evas_object_size_hint_weight_set(sep, EXPAND, EXPAND);
evas_object_size_hint_align_set(sep, FILL, FILL);
elm_separator_horizontal_set(sep, EINA_TRUE);
evas_object_show(sep);
elm_box_pack_end(hbox, sep);
elm_box_pack_end(box, hbox);
} }
static void static Evas_Object *
_ui_item_disk_update(Item_Disk *item, File_System *inf) _item_column_add(Evas_Object *table, const char *text, int col)
{ {
char *usage; Evas_Object *rect, *label;
double ratio, value;
Evas_Object *pb = item->pb;
usage = _file_system_usage_format(inf); label = elm_label_add(table);
if (usage) evas_object_data_set(table, text, label);
evas_object_show(label);
rect = evas_object_rectangle_add(table);
evas_object_data_set(label, "rect", rect);
elm_table_pack(table, label, col, 0, 1, 1);
elm_table_pack(table, rect, col, 0, 1, 1);
return label;
}
static Evas_Object *
_item_create(Evas_Object *parent)
{
Evas_Object *table, *label, *pb;
table = elm_table_add(parent);
evas_object_size_hint_align_set(table, EXPAND, EXPAND);
evas_object_size_hint_weight_set(table, FILL, FILL);
evas_object_show(table);
label = _item_column_add(table, "device", 0);
evas_object_size_hint_align_set(label, 0.5, FILL);
label = _item_column_add(table, "mount", 1);
evas_object_size_hint_align_set(label, 0.5, FILL);
label = _item_column_add(table, "fs", 2);
evas_object_size_hint_align_set(label, 0.5, FILL);
label = _item_column_add(table, "used", 3);
evas_object_size_hint_align_set(label, 0.5, FILL);
label = _item_column_add(table, "total", 4);
evas_object_size_hint_align_set(label, 0.5, FILL);
pb = elm_progressbar_add(table);
evas_object_size_hint_weight_set(pb, EXPAND, EXPAND);
evas_object_size_hint_align_set(pb, FILL, FILL);
evas_object_data_set(table, "usage", pb);
elm_table_pack(table, pb, 5, 0, 1, 1);
return table;
}
static Evas_Object *
_content_get(void *data, Evas_Object *obj, const char *source)
{
Evas_Object *l, *r, *pb;
Evas_Coord w, ow;
Widgets *wig;
File_System *inf = data;
if (!inf) return NULL;
if (strcmp(source, "elm.swallow.content")) return NULL;
wig = evas_object_data_get(obj, "widgets");
if (!wig) return NULL;
Item_Cache *it = evisum_ui_item_cache_item_get(wig->cache);
if (!it)
{ {
elm_progressbar_unit_format_set(pb, usage); fprintf(stderr, "Error: Object cache creation failed.\n");
free(usage); exit(-1);
} }
ratio = inf->usage.total / 100.0; evas_object_geometry_get(wig->btn_device, NULL, NULL, &w, NULL);
value = inf->usage.used / ratio; l = evas_object_data_get(it->obj, "device");
elm_object_text_set(l, eina_slstr_printf("%s", inf->path));
evas_object_geometry_get(l, NULL, NULL, &ow, NULL);
if (ow > w) evas_object_size_hint_min_set(wig->btn_device, w, 1);
r = evas_object_data_get(l, "rect");
evas_object_size_hint_min_set(r, w, 1);
evas_object_show(l);
evas_object_geometry_get(wig->btn_mount, NULL, NULL, &w, NULL);
l = evas_object_data_get(it->obj, "mount");
elm_object_text_set(l, eina_slstr_printf("%s", inf->mount));
evas_object_geometry_get(l, NULL, NULL, &ow, NULL);
if (ow > w) evas_object_size_hint_min_set(wig->btn_mount, w, 1);
r = evas_object_data_get(l, "rect");
evas_object_size_hint_min_set(r, w, 1);
evas_object_show(l);
evas_object_geometry_get(wig->btn_fs, NULL, NULL, &w, NULL);
l = evas_object_data_get(it->obj, "fs");
elm_object_text_set(l, eina_slstr_printf("%s", inf->type_name));
r = evas_object_data_get(l, "rect");
evas_object_size_hint_min_set(r, w, 1);
evas_object_show(l);
evas_object_geometry_get(wig->btn_used, NULL, NULL, &w, NULL);
l = evas_object_data_get(it->obj, "used");
elm_object_text_set(l, eina_slstr_printf("%s", evisum_size_format(inf->usage.used)));
r = evas_object_data_get(l, "rect");
evas_object_size_hint_min_set(r, w, 1);
evas_object_show(l);
evas_object_geometry_get(wig->btn_total, NULL, NULL, &w, NULL);
l = evas_object_data_get(it->obj, "total");
elm_object_text_set(l, eina_slstr_printf("%s", evisum_size_format(inf->usage.total)));
r = evas_object_data_get(l, "rect");
evas_object_size_hint_min_set(r, w, 1);
evas_object_show(l);
pb = evas_object_data_get(it->obj, "usage");
if (inf->usage.used != inf->usage.total) if (inf->usage.used != inf->usage.total)
elm_progressbar_value_set(pb, value / 100.0); elm_progressbar_value_set(pb, (double) (inf->usage.used / (inf->usage.total / 100.0) / 100.0));
else
elm_progressbar_value_set(pb, 1.0);
}
static Item_Disk *
_ui_item_disk_add(Ui *ui, File_System *inf)
{
Evas_Object *frame, *vbox, *hbox, *pb, *ic, *label;
Evas_Object *parent;
const char *type;
type = inf->type_name;
if (!type)
type = file_system_name_by_id(inf->type);
if (!type) type = "unknown";
parent = ui->disk.box;
frame = elm_frame_add(parent);
evas_object_size_hint_align_set(frame, FILL, 0);
evas_object_size_hint_weight_set(frame, EXPAND, 0);
elm_object_style_set(frame, "pad_huge");
evas_object_show(frame);
vbox = elm_box_add(parent);
evas_object_size_hint_align_set(vbox, FILL, FILL);
evas_object_size_hint_weight_set(vbox, EXPAND, EXPAND);
evas_object_show(vbox);
label = elm_label_add(parent);
evas_object_size_hint_align_set(label, 1.0, FILL);
evas_object_size_hint_weight_set(label, EXPAND, EXPAND);
evas_object_show(label);
elm_box_pack_end(vbox, label);
elm_object_text_set(label, eina_slstr_printf("<color=#fff>%s</>",
inf->mount));
hbox = elm_box_add(parent);
evas_object_size_hint_align_set(hbox, FILL, FILL);
evas_object_size_hint_weight_set(hbox, EXPAND, EXPAND);
elm_box_horizontal_set(hbox, EINA_TRUE);
evas_object_show(hbox);
ic = elm_image_add(parent);
elm_image_file_set(ic, evisum_icon_path_get("mount"), NULL);
evas_object_size_hint_min_set(ic, 32 * elm_config_scale_get(),
32 * elm_config_scale_get());
evas_object_show(ic);
elm_box_pack_end(hbox, ic);
pb = elm_progressbar_add(frame);
evas_object_size_hint_align_set(pb, FILL, FILL);
evas_object_size_hint_weight_set(pb, EXPAND, EXPAND);
elm_progressbar_span_size_set(pb, 1.0);
evas_object_show(pb); evas_object_show(pb);
label = elm_label_add(parent); return it->obj;
evas_object_size_hint_align_set(label, 1.0, FILL);
evas_object_size_hint_weight_set(label, EXPAND, EXPAND);
evas_object_show(label);
elm_object_text_set(label,
eina_slstr_printf("<color=#fff>%s <b>(%s)</b></>",
inf->path, type));
elm_box_pack_end(vbox, label);
elm_box_pack_end(hbox, pb);
elm_box_pack_end(vbox, hbox);
_separator_add(vbox);
elm_object_content_set(frame, vbox);
Item_Disk *it = malloc(sizeof(Item_Disk));
if (it)
{
it->parent = frame;
it->pb = pb;
it->lbl = label;
it->path = strdup(inf->path);
_ui_item_disk_update(it, inf);
}
return it;
} }
static void static void
_hash_free_cb(void *data) _genlist_ensure_n_items(Evas_Object *genlist, unsigned int items)
{ {
Item_Disk *it = data; Elm_Object_Item *it;
if (it->path) Elm_Genlist_Item_Class *itc;
free(it->path); unsigned int i, existing = elm_genlist_items_count(genlist);
free(it);
}
static Eina_Bool if (items < existing)
_ignore_path(char *path) {
{ for (i = existing - items; i > 0; i--)
if (!strcmp(path, "devfs")) {
return 1; it = elm_genlist_last_item_get(genlist);
return 0; if (it)
elm_object_item_del(it);
}
}
if (items == existing) return;
itc = elm_genlist_item_class_new();
itc->item_style = "full";
itc->func.text_get = NULL;
itc->func.content_get = _content_get;
itc->func.filter_get = NULL;
itc->func.del = _item_del;
for (i = existing; i < items; i++)
{
elm_genlist_item_append(genlist, itc, NULL, NULL,
ELM_GENLIST_ITEM_NONE, NULL, NULL);
}
elm_genlist_item_class_free(itc);
} }
static Eina_Bool static Eina_Bool
_disks_poll_timer_cb(void *data) _disks_poll_timer_cb(void *data)
{ {
Ui *ui;
Eina_List *disks; Eina_List *disks;
char *path; char *path;
Item_Disk *item; Elm_Object_Item *it;
File_System *fs; File_System *fs;
Eina_List *mounted = NULL;
ui = data;
disks = disks_get(); disks = disks_get();
EINA_LIST_FREE(disks, path) EINA_LIST_FREE(disks, path)
{ {
if (_ignore_path(path))
{
free(path);
continue;
}
fs = file_system_info_get(path); fs = file_system_info_get(path);
if (fs) if (fs)
{ mounted = eina_list_append(mounted, fs);
if ((item = eina_hash_find(_mounted, eina_slstr_printf("%s:%s", fs->path, fs->mount))))
_ui_item_disk_update(item, fs);
else
{
item = _ui_item_disk_add(ui, fs);
eina_hash_add(_mounted, eina_slstr_printf("%s:%s", fs->path, fs->mount), item);
elm_box_pack_end(ui->disk.box, item->parent);
}
file_system_info_free(fs);
}
free(path); free(path);
} }
void *d; _genlist_ensure_n_items(_widgets->genlist, eina_list_count(mounted));
Eina_Iterator *it = eina_hash_iterator_data_new(_mounted);
while (eina_iterator_next(it, &d)) it = elm_genlist_first_item_get(_widgets->genlist);
EINA_LIST_FREE(mounted, fs)
{ {
item = d; File_System *prev = elm_object_item_data_get(it);
fs = file_system_info_get(item->path); if (prev) _item_del(prev, NULL);
if (fs) elm_object_item_data_set(it, fs);
file_system_info_free(fs); elm_genlist_item_update(it);
else it = elm_genlist_item_next_get(it);
{
elm_box_unpack(ui->disk.box, item->parent);
evas_object_del(item->parent);
eina_hash_del(_mounted, NULL, item);
}
} }
eina_iterator_free(it);
elm_box_recalculate(ui->disk.box);
return EINA_TRUE; return EINA_TRUE;
} }
@ -225,12 +215,12 @@ _win_del_cb(void *data, Evas_Object *obj EINA_UNUSED,
{ {
Ui *ui = data; Ui *ui = data;
if (ui->disk.timer) if (_widgets)
ecore_timer_del(ui->disk.timer); {
ui->disk.timer = NULL; ecore_timer_del(_widgets->timer);
evisum_ui_item_cache_free(_widgets->cache);
eina_hash_free(_mounted); free(_widgets);
_mounted = NULL; }
evas_object_del(obj); evas_object_del(obj);
ui->disk.win = NULL; ui->disk.win = NULL;
@ -242,8 +232,9 @@ _win_del_cb(void *data, Evas_Object *obj EINA_UNUSED,
void void
ui_win_disk_add(Ui *ui) ui_win_disk_add(Ui *ui)
{ {
Evas_Object *win, *box, *vbox, *scroller; Evas_Object *win, *box, *tbl, *scroller;
Evas_Object *table, *rect; Evas_Object *genlist, *btn;
int i = 0;
if (ui->disk.win) if (ui->disk.win)
{ {
@ -251,8 +242,6 @@ ui_win_disk_add(Ui *ui)
return; return;
} }
_mounted = eina_hash_string_superfast_new(_hash_free_cb);
ui->disk.win = win = elm_win_util_standard_add("evisum", ui->disk.win = win = elm_win_util_standard_add("evisum",
_("Storage")); _("Storage"));
evas_object_size_hint_weight_set(win, EXPAND, EXPAND); evas_object_size_hint_weight_set(win, EXPAND, EXPAND);
@ -265,10 +254,56 @@ ui_win_disk_add(Ui *ui)
evas_object_size_hint_align_set(box, FILL, FILL); evas_object_size_hint_align_set(box, FILL, FILL);
evas_object_show(box); evas_object_show(box);
ui->disk.box = vbox = elm_box_add(win); tbl = elm_table_add(win);
evas_object_size_hint_weight_set(vbox, EXPAND, 0.0); evas_object_size_hint_weight_set(tbl, EXPAND, 0);
evas_object_size_hint_align_set(vbox, FILL, 0.5); evas_object_size_hint_align_set(tbl, FILL, 0);
evas_object_show(vbox); evas_object_show(tbl);
elm_box_pack_end(box, tbl);
Widgets *w = _widgets = calloc(1, sizeof(Widgets));
w->btn_device = btn = elm_button_add(win);
evas_object_size_hint_weight_set(btn, EXPAND, EXPAND);
evas_object_size_hint_align_set(btn, FILL, FILL);
evas_object_show(btn);
elm_object_text_set(btn, _("Device"));
elm_table_pack(tbl, btn, i++, 0, 1, 1);
w->btn_mount = btn = elm_button_add(win);
evas_object_size_hint_weight_set(btn, EXPAND, EXPAND);
evas_object_size_hint_align_set(btn, FILL, FILL);
evas_object_show(btn);
elm_object_text_set(btn, _("Mount"));
elm_table_pack(tbl, btn, i++, 0, 1, 1);
w->btn_fs = btn = elm_button_add(win);
evas_object_size_hint_weight_set(btn, EXPAND, EXPAND);
evas_object_size_hint_align_set(btn, FILL, FILL);
evas_object_show(btn);
elm_object_text_set(btn, _("FS"));
elm_table_pack(tbl, btn, i++, 0, 1, 1);
w->btn_used = btn = elm_button_add(win);
evas_object_size_hint_weight_set(btn, EXPAND, EXPAND);
evas_object_size_hint_align_set(btn, FILL, FILL);
evas_object_show(btn);
elm_object_text_set(btn, _("Used"));
elm_table_pack(tbl, btn, i++, 0, 1, 1);
w->btn_total = btn = elm_button_add(win);
evas_object_size_hint_weight_set(btn, EXPAND, EXPAND);
evas_object_size_hint_align_set(btn, FILL, FILL);
evas_object_show(btn);
elm_object_text_set(btn, _("Total"));
elm_table_pack(tbl, btn, i++, 0, 1, 1);
w->btn_usage = btn = elm_button_add(win);
evas_object_size_hint_weight_set(btn, EXPAND, EXPAND);
evas_object_size_hint_align_set(btn, FILL, FILL);
evas_object_show(btn);
elm_object_text_set(btn, _("Usage"));
elm_table_pack(tbl, btn, i++, 0, 1, 1);
scroller = elm_scroller_add(win); scroller = elm_scroller_add(win);
evas_object_size_hint_weight_set(scroller, EXPAND, EXPAND); evas_object_size_hint_weight_set(scroller, EXPAND, EXPAND);
@ -277,27 +312,25 @@ ui_win_disk_add(Ui *ui)
ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO); ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
evas_object_show(scroller); evas_object_show(scroller);
table = elm_table_add(win); w->genlist = genlist = elm_genlist_add(win);
evas_object_size_hint_weight_set(table, EXPAND, EXPAND); elm_object_focus_allow_set(genlist, 0);
evas_object_size_hint_align_set(table, FILL, FILL); evas_object_data_set(genlist, "widgets", w);
evas_object_show(table); elm_genlist_select_mode_set(genlist, ELM_OBJECT_SELECT_MODE_NONE);
evas_object_size_hint_weight_set(genlist, EXPAND, EXPAND);
evas_object_size_hint_align_set(genlist, FILL, FILL);
evas_object_show(genlist);
rect = evas_object_rectangle_add(evas_object_rectangle_add(win)); elm_object_content_set(scroller, genlist);
evas_object_size_hint_max_set(rect, MISC_MAX_WIDTH, -1);
evas_object_size_hint_min_set(rect, MISC_MIN_WIDTH, 1);
elm_table_pack(table, rect, 0, 0, 1, 1);
elm_table_pack(table, vbox, 0, 0, 1, 1);
elm_object_content_set(scroller, table);
elm_box_pack_end(box, scroller); elm_box_pack_end(box, scroller);
elm_object_content_set(win, box); elm_object_content_set(win, box);
evas_object_smart_callback_add(win, "delete,request", _win_del_cb, ui); evas_object_smart_callback_add(win, "delete,request", _win_del_cb, ui);
evisum_child_window_show(ui->win, win); evisum_child_window_show(ui->win, win);
w->cache = evisum_ui_item_cache_new(genlist, _item_create, 10);
_disks_poll_timer_cb(ui); _disks_poll_timer_cb(ui);
ui->disk.timer = ecore_timer_add(3.0, _disks_poll_timer_cb, ui); w->timer = ecore_timer_add(3.0, _disks_poll_timer_cb, ui);
} }