Skip to content
Snippets Groups Projects
Commit 5132d6c4 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Some more work on the Web Lists interface in SyncTERM

I've added a new named_str_list.[ch] thing to xpdev which allows
manipulation the lists you get back from ini_file.c.

Still need to do a thing to write the changes back, and write all
the help text, but it's coming together.

Also, fix formatting errors in the download status window.
parent d2d23d66
No related branches found
No related tags found
No related merge requests found
Pipeline #8017 failed
......@@ -17,6 +17,7 @@
#include "filepick.h"
#include "fonts.h"
#include "menu.h"
#include "named_str_list.h"
#include "syncterm.h"
#include "term.h"
#include "uifcinit.h"
......@@ -2913,6 +2914,12 @@ kbwait(void)
}
}
static void
write_webgets(void)
{
// TODO: Save changes
}
static void
edit_web_lists(void)
{
......@@ -2920,6 +2927,7 @@ edit_web_lists(void)
static int bar = 0;
size_t alloced_size = 0;
char **list = NULL;
bool changed = false;
while (!quitting) {
size_t count;
......@@ -2928,7 +2936,7 @@ edit_web_lists(void)
char **newlist = realloc(list, (count + 1) * sizeof(char *));
if (newlist == NULL) {
free(list);
return;
break;
}
list = newlist;
alloced_size = count;
......@@ -2946,24 +2954,53 @@ edit_web_lists(void)
break;
}
if (i & MSK_DEL) {
// TODO: Functions to amipulate these...
namedStrListDelete(&settings.webgets, i & MSK_OFF);
changed = true;
}
else if (i & MSK_INS) {
// TODO: Functions to amipulate these...
char tmpn[INI_MAX_VALUE_LEN + 1];
char tmpv[INI_MAX_VALUE_LEN + 1];
tmpn[0] = 0;
// TODO: Help
while (uifc.input(WIN_SAV | WIN_MID, 0, 0, "Web List Name", tmpn, sizeof(tmpn) - 1, K_EDIT) != -1
&& tmpn[0]) {
if (namedStrListFindName(settings.webgets, tmpn)) {
// TODO: Help
uifc.msg("Duplicate Name");
continue;
}
else {
tmpv[0] = 0;
// TODO: Help
if (uifc.input(WIN_SAV | WIN_MID, 0, 0, "Web List URI", tmpv, sizeof(tmpv) - 1, K_EDIT) != -1
&& tmpv[0]) {
namedStrListInsert(&settings.webgets, tmpn, tmpv, i & MSK_OFF);
changed = true;
}
break;
}
}
}
else if (i >= 0 && i <= count) {
char tmp[INI_MAX_VALUE_LEN + 1];
strlcpy(tmp, settings.webgets[i]->value, sizeof(tmp));
uifc.changes = false;
// TODO: Help
if (uifc.input(WIN_SAV | WIN_MID, 0, 0, "Web List URI", tmp, sizeof(tmp) - 1, K_EDIT) == -1) {
check_exit(false);
}
else {
free(settings.webgets[i]->value);
settings.webgets[i]->value = strdup(tmp);
if (uifc.changes) {
free(settings.webgets[i]->value);
settings.webgets[i]->value = strdup(tmp);
changed = true;
}
}
}
}
if (changed) {
write_webgets();
}
}
/*
......
......@@ -1634,6 +1634,10 @@ update_webget_progress(struct webget_request *reqs, size_t items, bool leaveup)
pos += added;
}
}
else {
int added = snprintf(&helpbuf[pos], sz - pos, "\r\n");
pos += added;
}
}
}
assert_pthread_mutex_unlock(&reqs[i].mtx);
......
......@@ -534,7 +534,7 @@ typedef struct {
/********************************/
/* Other Pointer-List Macros */
/********************************/
#define COUNT_LIST_ITEMS(list,i) { i=0; if(list!=NULL) while(list[i]!=NULL) i++; }
#define COUNT_LIST_ITEMS(list,i) { i=0; if((list)!=NULL) while((list)[i]!=NULL) i++; }
#if defined(__unix__)
#include <syslog.h>
......
#include <stdlib.h>
#include "gen_defs.h"
#include "genwrap.h"
#include "named_str_list.h"
named_string_t *
namedStrListInsert(named_string_t ***list, const char *name, const char *value, size_t index)
{
size_t count;
COUNT_LIST_ITEMS((*list), count);
if (count == NAMED_STR_LIST_LAST_INDEX)
return NULL;
if (index == NAMED_STR_LIST_LAST_INDEX)
index = count;
if (index > count)
index = count;
named_string_t **newlist = (named_string_t **)realloc(*list, (count + 2) * sizeof(named_string_t*));
if (newlist == NULL)
return NULL;
*list = newlist;
memmove(&(*list)[index + 1], &(*list)[index], (count - index + 1) * sizeof(named_string_t*));
(*list)[index] = malloc(sizeof(named_string_t));
// TODO: If malloc() failed we truncated the list...
if ((*list)[index]) {
(*list)[index]->name = strdup(name);
(*list)[index]->value = strdup(value);
}
return (*list)[count];
}
bool
namedStrListDelete(named_string_t ***list, size_t index)
{
size_t count;
COUNT_LIST_ITEMS(*list, count);
if (index == NAMED_STR_LIST_LAST_INDEX)
index = count - 1;
if (index >= count)
return false;
named_string_t **newlist = (named_string_t **)realloc(*list, (count + 1) * sizeof(named_string_t*));
if (newlist != NULL)
*list = newlist;
named_string_t *old = (*list)[index];
memmove(&(*list)[index], &(*list)[index + 1], (count - index) * sizeof(named_string_t*));
free(old->name);
free(old->value);
free(old);
return true;
}
named_string_t *
namedStrListFindName(named_string_t **list, const char *tmpn)
{
for (size_t i = 0; list[i]; i++) {
if (stricmp(tmpn, list[i]->name) == 0)
return list[i];
}
return NULL;
}
#ifndef NAMED_STR_LIST_H
#define NAMED_STR_LIST_H
#define NAMED_STR_LIST_LAST_INDEX (-((size_t)(1)))
#ifdef __cplusplus
extern "C" {
#endif
named_string_t *namedStrListInsert(named_string_t ***list, const char *name, const char *value, size_t index);
bool namedStrListDelete(named_string_t ***list, size_t index);
named_string_t *namedStrListFindName(named_string_t **list, const char *tmpn);
#ifdef __cplusplus
}
#endif
#endif
......@@ -16,6 +16,7 @@ OBJS = \
$(OBJODIR)$(DIRSEP)ini_file$(OFILE) \
$(OBJODIR)$(DIRSEP)link_list$(OFILE) \
$(OBJODIR)$(DIRSEP)multisock$(OFILE) \
$(OBJODIR)$(DIRSEP)named_str_list$(OFILE) \
$(OBJODIR)$(DIRSEP)netwrap$(OFILE) \
$(OBJODIR)$(DIRSEP)sockwrap$(OFILE) \
$(OBJODIR)$(DIRSEP)semfile$(OFILE) \
......@@ -40,6 +41,7 @@ MTOBJS = \
$(MTOBJODIR)$(DIRSEP)link_list$(OFILE) \
$(MTOBJODIR)$(DIRSEP)msg_queue$(OFILE) \
$(MTOBJODIR)$(DIRSEP)multisock$(OFILE) \
$(MTOBJODIR)$(DIRSEP)named_str_list$(OFILE) \
$(MTOBJODIR)$(DIRSEP)rwlockwrap$(OFILE) \
$(MTOBJODIR)$(DIRSEP)semwrap$(OFILE) \
$(MTOBJODIR)$(DIRSEP)netwrap$(OFILE) \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment