Sun, 07 Dec 2025 20:00:33 +0100
fix settings dialog doesn't open when there is no .dav/config.xml file
/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2025 Olaf Wintermann. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include "wrapper.h" #include "types.h" #include <cx/list.h> #include <string.h> /* ---------------------------- UiObject ---------------------------- */ UiContext* ui_object_get_context(UiObject *obj) { return obj->ctx; } void* ui_object_get_windowdata(UiObject *obj) { return obj->window; } void ui_object_set_windowdata(UiObject *obj, void *windowdata) { obj->window = windowdata; } /* ---------------------------- UiList ---------------------------- */ void* ui_list_get_data(UiList *list) { return list->data; } void ui_list_set_data(UiList *list, void *data) { list->data = data; } void* ui_list_get_iter(UiList *list) { return list->iter; } void ui_list_set_iter(UiList *list, void *iter) { list->iter = iter; } /* ------------------------------ UiSublist ------------------------------ */ UiSubList* ui_sublist_new(void) { UiSubList *sublist = malloc(sizeof(UiSubList)); memset(sublist, 0, sizeof(UiSubList)); return sublist; } void ui_sublist_set_value(UiSubList *sublist, UiList *value) { sublist->value = value; } void ui_sublist_set_varname(UiSubList *sublist, const char *varname) { free((void*)sublist->varname); sublist->varname = strdup(varname); } void ui_sublist_set_header(UiSubList *sublist, const char *header) { free((void*)sublist->header); sublist->header = strdup(header); } void ui_sublist_set_separator(UiSubList *sublist, UiBool separator) { sublist->separator = separator; } void ui_sublist_set_userdata(UiSubList *sublist, void *userdata) { sublist->userdata = userdata; } void ui_sublist_free(UiSubList *sublist) { free((void*)sublist->varname); free((void*)sublist->header); free(sublist); } /* -------------------- Source list (UiList<UiSublist>) -------------------- */ UiList* ui_srclist_new(UiContext *ctx, const char *name) { UiList *list = ui_list_new2(ctx, name, uic_ucx_list_init, NULL); CxList *cxlist = list->data; cxlist->collection.simple_destructor = (cx_destructor_func)ui_sublist_free; return list; } void ui_srclist_add(UiList *list, UiSubList *item) { ui_list_append(list, item); } void ui_srclist_insert(UiList *list, int index, UiSubList *item) { CxList *cxlist = list->data; cxListInsert(cxlist, index, item); } void ui_srclist_remove(UiList *list, int index) { CxList *cxlist = list->data; cxListRemove(cxlist, index); } void ui_srclist_clear(UiList *list) { CxList *cxlist = list->data; cxListClear(cxlist); } int ui_srclist_size(UiList *list) { return ui_list_count(list); } /* * numerates all sublists and sets the sublist index as userdata */ void ui_srclist_generate_sublist_num_data(UiList *list) { CxList *cxlist = list->data; CxIterator i = cxListIterator(cxlist); cx_foreach(UiSubList *, sublist, i) { sublist->userdata = (void*)i.index; } } /* ---------------------------- UiSubListEventData ---------------------------- */ UiList* ui_sublist_event_get_list(UiSubListEventData *event) { return event->list; } int ui_sublist_event_get_sublist_index(UiSubListEventData *event) { return event->sublist_index; } int ui_sublist_event_get_row_index(UiSubListEventData *event) { return event->row_index; } void* ui_sublist_event_get_row_data(UiSubListEventData *event) { return event->row_data; } void* ui_sublist_event_get_sublist_userdata(UiSubListEventData *event) { return event->sublist_userdata; } void* ui_sublist_event_get_event_data(UiSubListEventData *event) { return event->event_data; } /* ---------------------------- UiEvent ---------------------------- */ UiObject* ui_event_get_obj(UiEvent *event) { return event->obj; } void* ui_event_get_document(UiEvent *event) { return event->document; } void* ui_event_get_windowdata(UiEvent *event) { return event->window; } void* ui_event_get_eventdata(UiEvent *event) { return event->eventdata; } int ui_event_get_eventdatatype(UiEvent *event) { return event->eventdatatype; } int ui_event_get_int(UiEvent *event) { return event->intval; } int ui_event_get_set(UiEvent *event) { return event->set; } /* ------------------------- SubListItem (public) ------------------------- */ void ui_sublist_item_set_icon(UiSubListItem *item, const char *icon) { item->icon = icon ? strdup(icon) : NULL; } void ui_sublist_item_set_label(UiSubListItem *item, const char *label) { item->label = label ? strdup(label) : NULL; } void ui_sublist_item_set_button_icon(UiSubListItem *item, const char *button_icon) { item->button_icon = button_icon ? strdup(button_icon) : NULL; } void ui_sublist_item_set_button_label(UiSubListItem *item, const char *button_label) { item->button_label = button_label ? strdup(button_label) : NULL; } void ui_sublist_item_set_button_menu(UiSubListItem *item, UiMenuBuilder *menu) { item->button_menu = menu; } void ui_sublist_item_set_badge(UiSubListItem *item, const char *badge) { item->badge = badge ? strdup(badge) : NULL; } void ui_sublist_item_set_eventdata(UiSubListItem *item, void *eventdata) { item->eventdata = NULL; } /* ---------------------------- UiListSelection ---------------------------- */ UiListSelection* ui_list_get_selection_allocated(UiList *list) { UiListSelection *sel = malloc(sizeof(UiListSelection)); *sel = ui_list_get_selection(list); return sel; } int ui_list_selection_get_count(UiListSelection *sel) { return sel->count; } int* ui_list_selection_get_rows(UiListSelection *sel) { return sel->rows; } UIEXPORT void ui_list_set_selected_indices(UiList *list, int *indices, int num) { UiListSelection sel; sel.rows = indices; sel.count = num; if(list->setselection) { list->setselection(list, sel); } } void ui_list_selection_free(UiListSelection *sel) { ui_listselection_free(*sel); free(sel); } /* ---------------------------- UiFileList ---------------------------- */ int ui_filelist_count(UiFileList *flist) { return flist->nfiles; } char* ui_filelist_get(UiFileList *flist, int index) { if(index >= 0 && index < flist->nfiles) { return flist->files[index]; } return NULL; } /* ---------------------------- UiTextStyle ---------------------------- */ void ui_textstyle_set_bold(UiTextStyle *style, UiBool set) { if(set) { style->text_style |= UI_TEXT_STYLE_BOLD; } else { style->text_style &= ~UI_TEXT_STYLE_BOLD; } } void ui_textstyle_set_underline(UiTextStyle *style, UiBool set) { if(set) { style->text_style |= UI_TEXT_STYLE_UNDERLINE; } else { style->text_style &= ~UI_TEXT_STYLE_UNDERLINE; } } void ui_textstyle_set_italic(UiTextStyle *style, UiBool set) { if(set) { style->text_style |= UI_TEXT_STYLE_ITALIC; } else { style->text_style &= ~UI_TEXT_STYLE_ITALIC; } } void ui_textstyle_set_color(UiTextStyle *style, int r, int g, int b) { style->fg_set = TRUE; style->fg.red = r; style->fg.green = g; style->fg.blue = b; } void ui_textstyle_enable_color(UiTextStyle *style, UiBool enable) { style->fg_set = enable; } /* ---------------------------- UiCellValue ---------------------------- */ UiBool ui_cell_value_is_string(UiCellValue *value) { return value->type == UI_STRING_EDITABLE; } UiBool ui_cell_value_is_int(UiCellValue *value) { return FALSE; // TODO } const char* ui_cell_value_get_string(UiCellValue *value) { return value->string; } int64_t ui_cell_value_get_int(UiCellValue *value) { return value->i; }