summaryrefslogtreecommitdiff
path: root/src/fruits
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-05-07 16:52:14 -0400
committerAndrew Opalach <andrew@akon.city> 2025-05-07 16:55:39 -0400
commit8f9ddafb128eabe346b48adebdeb1f34da05b005 (patch)
treea50ff8be72277bdfe942c32317805128f424040f /src/fruits
parentefbe4b52a22ea3c4458401a7acbce89a5bf29299 (diff)
downloadcamu-8f9ddafb128eabe346b48adebdeb1f34da05b005.tar.gz
camu-8f9ddafb128eabe346b48adebdeb1f34da05b005.tar.bz2
camu-8f9ddafb128eabe346b48adebdeb1f34da05b005.zip
Make server resource a fat entity
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/fruits')
-rw-r--r--src/fruits/cmc/cmc.c10
-rw-r--r--src/fruits/cmc/cmc.h2
-rw-r--r--src/fruits/cmc/ui/panes/list.c244
-rw-r--r--src/fruits/cmc/ui/widgets/now_playing.c4
-rw-r--r--src/fruits/cmsrv/cmsrv.c16
-rw-r--r--src/fruits/cmsrv/ui.c9
-rw-r--r--src/fruits/cmv/cmv.c16
7 files changed, 19 insertions, 282 deletions
diff --git a/src/fruits/cmc/cmc.c b/src/fruits/cmc/cmc.c
index 43f1144..39423c1 100644
--- a/src/fruits/cmc/cmc.c
+++ b/src/fruits/cmc/cmc.c
@@ -37,11 +37,11 @@ static void read_list_entry(struct nn_packet *packet, struct cmc_list_entry *ent
entry->start = nn_packet_read_u64(packet);
entry->paused_at = nn_packet_read_u64(packet);
entry->offset = nn_packet_read_u64(packet);
- wstr w;
- nn_packet_read_wstr(packet, &w);
- if (!al_wstr_eq(&entry->name, &w)) {
- al_wstr_free(&entry->name);
- al_wstr_clone(&entry->name, &w);
+ str brief;
+ nn_packet_read_str(packet, &brief);
+ if (!al_str_eq(&entry->brief, &brief)) {
+ al_str_free(&entry->brief);
+ al_str_clone(&entry->brief, &brief);
}
}
diff --git a/src/fruits/cmc/cmc.h b/src/fruits/cmc/cmc.h
index 817b8b0..b65b336 100644
--- a/src/fruits/cmc/cmc.h
+++ b/src/fruits/cmc/cmc.h
@@ -29,7 +29,7 @@ struct cmc_list_entry {
u64 start;
u64 paused_at;
u64 offset;
- wstr name;
+ str brief;
struct {
struct camu_audio_format fmt;
u8 *data;
diff --git a/src/fruits/cmc/ui/panes/list.c b/src/fruits/cmc/ui/panes/list.c
index 34e18f9..15554b6 100644
--- a/src/fruits/cmc/ui/panes/list.c
+++ b/src/fruits/cmc/ui/panes/list.c
@@ -265,15 +265,16 @@ static void render_list_entries(struct cmc_list_pane *lp, struct cmc_list_tab *t
ncplane_set_fg_palindex(n, 4);
}
s32 y = i - top;
- u32 length = entry->name.length;
+ char *c_str = al_str_to_c_str(&entry->brief);
if (tab->move.active && i == tracked) {
- cmc_ui_putnwstr_yx(n, y, 0, length, &entry->name);
+ ncplane_putstr_yx(n, y, 0, c_str);
} else if (on_current) {
ncplane_putchar_yx(n, y, 1, '>');
- cmc_ui_putnwstr_yx(n, y, 3, length, &entry->name);
+ ncplane_putstr_yx(n, y, 3, c_str);
} else {
- cmc_ui_putnwstr_yx(n, y, 1, length, &entry->name);
+ ncplane_putstr_yx(n, y, 1, c_str);
}
+ al_free(c_str);
if (styled) {
ncplane_set_styles(n, NCSTYLE_NONE);
ncplane_set_fg_default(n);
@@ -291,229 +292,6 @@ void cmc_list_pane_render(struct cmc_list_pane *lp)
cmc_now_playing_render(&lp->np, tab_current_entry(tab));
}
-//void cmc_lp_init(struct cmc_ui *ui)
-//{
-// al_array_init(ui->lp.tabs);
-// ui->lp.current = 0;
-//}
-//
-//void cmc_lp_layout(struct cmc_ui *ui, struct ncplane *parent)
-//{
-// if (ui->lp.n) ncplane_destroy(ui->lp.n);
-// struct ncplane_options nopts = { 0 };
-// nopts.rows = ncplane_dim_y(parent);
-// nopts.cols = ncplane_dim_x(parent);
-// ui->lp.n = ncplane_create(parent, &nopts);
-//}
-//
-//void cmc_lp_add_list(struct cmc_ui *ui, struct cmc_list *list)
-//{
-// struct cmc_list_tab tab = {
-// .list = list,
-// .selected = list->current,
-// .leader_pressed = false
-// };
-// al_array_push(ui->lp.tabs, tab);
-//}
-//
-//bool cmc_lp_handle_input(struct cmc_ui *ui, struct ncinput *input)
-//{
-// if (!ui->lp.tabs.count) return false;
-//
-// struct cmc_list_tab *tab = &al_array_at(ui->lp.tabs, ui->lp.current);
-// s32 count = (s32)tab->list->entries.count;
-// bool leader = tab->leader_pressed;
-// if (cmc_ui_consider_input(input, false)) {
-// tab->leader_pressed = false;
-// }
-//
-// switch (input->id) {
-// case 'g':
-// CONSIDER_INPUT();
-// if (leader) {
-// if (tab->move.active) {
-// tab->move.offset = -tab->move.selected;
-// } else {
-// tab->selected = 0;
-// }
-// } else {
-// tab->leader_pressed = true;
-// }
-// break;
-// case 'G':
-// CONSIDER_INPUT();
-// if (tab->move.active) {
-// tab->move.offset = count - 1 - tab->move.selected;
-// } else {
-// tab->selected = count - 1;
-// }
-// break;
-// case 'f':
-// //CONSIDER_INPUT_MOD_CTRL();
-// CONSIDER_INPUT_REPEAT();
-// if (tab->move.active) {
-// if (tab->selected + tab->move.offset < count - tab->page_length) {
-// tab->move.offset += tab->page_length;
-// } else {
-// tab->move.offset = count - 1 - tab->move.selected;
-// }
-// } else {
-// if (tab->selected < count - tab->page_length) {
-// tab->selected += tab->page_length;
-// } else {
-// tab->selected = count - 1;
-// }
-// }
-// break;
-// case 'b':
-// //CONSIDER_INPUT_MOD_CTRL();
-// CONSIDER_INPUT_REPEAT();
-// if (tab->move.active) {
-// if (tab->selected + tab->move.offset > tab->page_length) {
-// tab->move.offset -= tab->page_length;
-// } else {
-// tab->move.offset = -tab->selected;
-// }
-// } else {
-// if (tab->selected > tab->page_length) {
-// tab->selected -= tab->page_length;
-// } else {
-// tab->selected = 0;
-// }
-// }
-// break;
-// case 'j':
-// CONSIDER_INPUT_REPEAT();
-// if (tab->move.active) {
-// if (tab->selected + tab->move.offset < count - 1) {
-// tab->move.offset++;
-// }
-// } else {
-// if (tab->selected < count - 1) {
-// tab->selected++;
-// }
-// }
-// break;
-// case 'k':
-// CONSIDER_INPUT_REPEAT();
-// if (tab->move.active) {
-// if (tab->selected + tab->move.offset > 0) {
-// tab->move.offset--;
-// }
-// } else {
-// if (tab->selected > 0) {
-// tab->selected--;
-// }
-// }
-// break;
-// case 'i':
-// CONSIDER_INPUT();
-// if (!tab->move.active) {
-// tab->move.active = true;
-// tab->move.selected = tab->selected;
-// tab->move.offset = 0;
-// }
-// break;
-// case NCKEY_ESC:
-// CONSIDER_INPUT();
-// if (tab->move.active) {
-// tab->move.active = false;
-// }
-// break;
-// case NCKEY_RETURN:
-// CONSIDER_INPUT();
-// if (tab->move.active) {
-// tab->move.active = false;
-// } else if (tab->selected != tab->list->current) {
-// camu_client_skipto(&ui->c->client, &tab->list->name, tab->selected);
-// }
-// break;
-// case NCKEY_BUTTON1:
-// CONSIDER_INPUT();
-// if (input->x < 0 || input->y < 0) return false;
-// u32 x = (u32)input->x;
-// u32 y = (u32)input->y;
-// ui->last_mouse_x = x;
-// ui->last_mouse_y = y;
-// u64 now = nn_get_timestamp();
-// u64 last = ui->last_mouse_ts;
-// if (last != (u64)-1 && now - last < 100000) {
-// return false;
-// }
-// ui->last_mouse_ts = now;
-// u32 width = ncplane_dim_x(ui->lp.n);
-// u32 height = ncplane_dim_y(ui->lp.n);
-// if (x >= 2 && x <= width && y > height - 3) { // @TODO: Make this defined, more to nowplaying.
-// struct cmc_list_entry *entry = al_array_at(tab->list->entries, tab->list->current);
-// u64 pos = ((x - 2) / (f64)(width - 2)) * entry->duration;
-// camu_client_seek(&ui->c->client, &tab->list->name, entry->id, pos);
-// }
-// break;
-// }
-//
-// return true;
-//}
-//
-//void cmc_lp_erase(struct cmc_ui *ui)
-//{
-// ncplane_erase(ui->lp.n);
-//}
-//
-//static void render_list_entries(struct cmc_ui *ui, struct cmc_list_tab *tab, s32 max_height)
-//{
-// struct cmc_list *list = tab->list;
-// struct ncplane *n = ui->lp.n;
-// s32 tracked = tab->move.active ? tab->move.selected + tab->move.offset : tab->selected;
-// s32 count = (s32)list->entries.count;
-// s32 midpoint = max_height / 2;
-// s32 rounded = (max_height + 1) / 2;
-// s32 top, end;
-// if (tracked < midpoint) {
-// top = 0;
-// end = MIN(top + max_height, count);
-// } else if (tracked + rounded >= count) {
-// top = count - max_height;
-// end = count;
-// } else {
-// top = tracked - midpoint;
-// end = tracked + rounded;
-// }
-// s32 index;
-// struct cmc_list_entry *entry;
-// for (s32 i = top; i < end; i++) {
-// index = i;
-// if (tab->move.active) {
-// if (index == tracked) {
-// index = tab->move.selected;
-// } else {
-// if (index > tracked) index--;
-// if (index >= tab->move.selected) index++;
-// }
-// }
-// entry = al_array_at(list->entries, index);
-// bool on_current = list->current >= 0 && index == list->current;
-// bool styled = i == tracked;
-// if (styled) {
-// ncplane_set_styles(n, NCSTYLE_BOLD);
-// ncplane_set_fg_palindex(n, 4);
-// }
-// s32 y = i - top;
-// u32 length = entry->name.length;
-// if (tab->move.active && i == tracked) {
-// cmc_ui_putnwstr_yx(n, y, 0, length, &entry->name);
-// } else if (on_current) {
-// ncplane_putchar_yx(n, y, 1, '>');
-// cmc_ui_putnwstr_yx(n, y, 3, length, &entry->name);
-// } else {
-// cmc_ui_putnwstr_yx(n, y, 1, length, &entry->name);
-// }
-// if (styled) {
-// ncplane_set_styles(n, NCSTYLE_NONE);
-// ncplane_set_fg_default(n);
-// }
-// }
-//}
-//
//static void render_now_playing(struct cmc_ui *ui, struct cmc_list_tab *tab, u32 y, u32 height)
//{
// struct ncplane *n = ui->lp.n;
@@ -676,15 +454,3 @@ void cmc_list_pane_render(struct cmc_list_pane *lp)
// ncplane_cursor_move_yx(n, y, 0);
// ncplane_light_box(n, NCSTYLE_NONE, c, height - 1, width - 1, 0);
//}
-//
-//void cmc_lp_render(struct cmc_ui *ui)
-//{
-// u32 height = ncplane_dim_y(ui->lp.n);
-//
-// if (ui->lp.tabs.count <= ui->lp.current) return;
-// struct cmc_list_tab *tab = &al_array_at(ui->lp.tabs, ui->lp.current);
-//
-// tab->page_length = height - 9;
-// render_list_entries(ui, tab, tab->page_length);
-// render_now_playing(ui, tab, tab->page_length, height);
-//}
diff --git a/src/fruits/cmc/ui/widgets/now_playing.c b/src/fruits/cmc/ui/widgets/now_playing.c
index ebb8361..a90c7e0 100644
--- a/src/fruits/cmc/ui/widgets/now_playing.c
+++ b/src/fruits/cmc/ui/widgets/now_playing.c
@@ -145,7 +145,9 @@ void cmc_now_playing_render(struct cmc_now_playing *np, struct cmc_list_entry *e
ncplane_putstr_yx(np->n, 1, 4 + offset, "⎹");
if (entry) {
- cmc_ui_putnwstr_yx(np->n, 1, 6 + offset, MIN(entry->name.length, (u32)60), &entry->name);
+ char *c_str = al_str_to_c_str(&entry->brief);
+ ncplane_putnstr_yx(np->n, 1, 6 + offset, MIN(al_strlen(c_str), (size_t)60), c_str);
+ al_free(c_str);
}
bool show_remaining = false;
diff --git a/src/fruits/cmsrv/cmsrv.c b/src/fruits/cmsrv/cmsrv.c
index e830831..ca65beb 100644
--- a/src/fruits/cmsrv/cmsrv.c
+++ b/src/fruits/cmsrv/cmsrv.c
@@ -57,22 +57,6 @@ static u8 server_line_callback(void *userdata, str *line)
//lia_list_clear(list);
} else {
struct nn_packet *packet = nn_packet_create();
-#ifdef CAMU_HAVE_PORTAL
- if (al_str_at(line, 0) == ';' || camu_is_url(line, 0)) {
- nn_packet_write_u8(packet, CAMU_RESOURCE_SIMPLE_SEARCH);
-#elif defined NAUNET_HAS_CURL
- if (camu_is_url(line, 0)) {
- nn_packet_write_u8(packet, CAMU_RESOURCE_HTTP);
-#else
- if (0) {
-#endif
-#if CACHE_HAVE_CDIO
- } else if (al_str_cmp(line, &al_str_c("cdda://"), 0, 7) == 0) {
- nn_packet_write_u8(packet, CAMU_RESOURCE_CDIO);
-#endif
- } else {
- nn_packet_write_u8(packet, CAMU_RESOURCE_FILE);
- }
nn_packet_write_str(packet, line);
camu_server_local_add(&s->server, packet);
}
diff --git a/src/fruits/cmsrv/ui.c b/src/fruits/cmsrv/ui.c
index 0a41bfc..c8e9dcb 100644
--- a/src/fruits/cmsrv/ui.c
+++ b/src/fruits/cmsrv/ui.c
@@ -156,15 +156,16 @@ static void render_lists(struct cmsrv_ui *ui)
ncplane_putchar_yx(n, y, 1, '>');
x += 2;
}
- wstr *name = &entry->name;
#ifdef CAMU_HAVE_PORTAL
struct camu_resource *resource = (struct camu_resource *)entry->opaque;
if (resource->type == CAMU_RESOURCE_PORTAL) {
- struct camu_resource_portal *portal = (struct camu_resource_portal *)resource;
- name = &portal->post->title;
+ putnwstr_maxwidth_yx(n, y, x, max_width - x, &resource->post->title);
+ } else {
+ char *c_str = al_str_to_c_str(&entry->brief);
+ ncplane_putstr_yx(n, y, x, c_str);
+ al_free(c_str);
}
#endif
- putnwstr_maxwidth_yx(n, y, x, max_width - x, name);
if (++current_line >= max_height) break;
}
}
diff --git a/src/fruits/cmv/cmv.c b/src/fruits/cmv/cmv.c
index 2dda139..1b9c8c1 100644
--- a/src/fruits/cmv/cmv.c
+++ b/src/fruits/cmv/cmv.c
@@ -185,22 +185,6 @@ s32 window_system_main(u32 argc, str *argv, void *extra)
if (local) {
for (u32 i = 1; i < argc; i++) {
struct nn_packet *packet = nn_packet_create();
-#if defined CAMU_HAVE_PORTAL
- if (al_str_at(&argv[i], 0) == ';' || camu_is_url(&argv[i], 0)) {
- nn_packet_write_u8(packet, CAMU_RESOURCE_SIMPLE_SEARCH);
-#elif defined NAUNET_HAS_CURL
- if (camu_is_url(&argv[i], 0)) {
- nn_packet_write_u8(packet, CAMU_RESOURCE_HTTP);
-#else
- if (0) {
-#endif
-#if CACHE_HAVE_CDIO
- } else if (al_str_cmp(&argv[i], &al_str_c("cdda://"), 0, 7) == 0) {
- nn_packet_write_u8(packet, CAMU_RESOURCE_CDIO);
-#endif
- } else {
- nn_packet_write_u8(packet, CAMU_RESOURCE_FILE);
- }
nn_packet_write_str(packet, &argv[i]);
camu_server_local_add(&c.server, packet);
nn_packet_free(packet);