Changeset 61784ed in mainline for uspace/app/nav/panel.c


Ignore:
Timestamp:
2021-10-25T00:32:45Z (3 years ago)
Author:
jxsvoboda <5887334+jxsvoboda@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0e80e40
Parents:
b36ebb42
git-author:
Jiri Svoboda <jiri@…> (2021-10-05 17:07:26)
git-committer:
jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
Message:

Creating and enumerating panel entries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nav/panel.c

    rb36ebb42 r61784ed  
    3838#include <gfx/render.h>
    3939#include <stdlib.h>
     40#include <str.h>
    4041#include <ui/control.h>
    4142#include <ui/paint.h>
     
    8182
    8283        panel->window = window;
     84        list_initialize(&panel->entries);
    8385        *rpanel = panel;
    8486        return EOK;
     
    9597void panel_destroy(panel_t *panel)
    9698{
     99        panel_entry_t *entry;
     100
     101        entry = panel_first(panel);
     102        while (entry != NULL) {
     103                panel_entry_delete(entry);
     104                entry = panel_first(panel);
     105        }
     106
    97107        ui_control_delete(panel->control);
    98108        free(panel);
     
    196206}
    197207
     208/** Append new panel entry.
     209 *
     210 * @param panel Panel
     211 * @param name File name
     212 * @param size File size;
     213 * @return EOK on success or an error code
     214 */
     215errno_t panel_entry_append(panel_t *panel, const char *name, uint64_t size)
     216{
     217        panel_entry_t *entry;
     218
     219        entry = calloc(1, sizeof(panel_entry_t));
     220        if (entry == NULL)
     221                return ENOMEM;
     222
     223        entry->panel = panel;
     224        entry->name = str_dup(name);
     225        if (entry->name == NULL) {
     226                free(entry);
     227                return ENOMEM;
     228        }
     229
     230        entry->size = size;
     231        link_initialize(&entry->lentries);
     232        list_append(&entry->lentries, &panel->entries);
     233        return EOK;
     234}
     235
     236/** Delete panel entry.
     237 *
     238 * @param entry Panel entry
     239 */
     240void panel_entry_delete(panel_entry_t *entry)
     241{
     242        list_remove(&entry->lentries);
     243        free(entry->name);
     244        free(entry);
     245}
     246
     247/** Return first panel entry.
     248 *
     249 * @panel Panel
     250 * @return First panel entry or @c NULL if there are no entries
     251 */
     252panel_entry_t *panel_first(panel_t *panel)
     253{
     254        link_t *link;
     255
     256        link = list_first(&panel->entries);
     257        if (link == NULL)
     258                return NULL;
     259
     260        return list_get_instance(link, panel_entry_t, lentries);
     261}
     262
     263/** Return next panel entry.
     264 *
     265 * @param cur Current entry
     266 * @return Next entry or @c NULL if @a cur is the last entry
     267 */
     268panel_entry_t *panel_next(panel_entry_t *cur)
     269{
     270        link_t *link;
     271
     272        link = list_next(&cur->lentries, &cur->panel->entries);
     273        if (link == NULL)
     274                return NULL;
     275
     276        return list_get_instance(link, panel_entry_t, lentries);
     277}
    198278
    199279/** @}
Note: See TracChangeset for help on using the changeset viewer.