[cb2894e] | 1 | /*
|
---|
| 2 | * Copyright (c) 2023 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup taskbar-cfg
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file Taskbar configuration utility (UI)
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <gfx/coord.h>
|
---|
| 36 | #include <stdio.h>
|
---|
| 37 | #include <stdlib.h>
|
---|
| 38 | #include <ui/fixed.h>
|
---|
| 39 | #include <ui/resource.h>
|
---|
| 40 | #include <ui/tabset.h>
|
---|
| 41 | #include <ui/ui.h>
|
---|
| 42 | #include <ui/window.h>
|
---|
| 43 | #include "taskbar-cfg.h"
|
---|
| 44 | #include "startmenu.h"
|
---|
| 45 |
|
---|
| 46 | static void wnd_close(ui_window_t *, void *);
|
---|
| 47 |
|
---|
| 48 | static ui_window_cb_t window_cb = {
|
---|
| 49 | .close = wnd_close
|
---|
| 50 | };
|
---|
| 51 |
|
---|
| 52 | /** Window close button was clicked.
|
---|
| 53 | *
|
---|
| 54 | * @param window Window
|
---|
| 55 | * @param arg Argument (tbcfg)
|
---|
| 56 | */
|
---|
| 57 | static void wnd_close(ui_window_t *window, void *arg)
|
---|
| 58 | {
|
---|
| 59 | taskbar_cfg_t *tbcfg = (taskbar_cfg_t *) arg;
|
---|
| 60 |
|
---|
| 61 | ui_quit(tbcfg->ui);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | /** Create Taskbar configuration window.
|
---|
| 65 | *
|
---|
| 66 | * @param display_spec Display specification
|
---|
| 67 | * @param rdcfg Place to store pointer to new taskbar configuration
|
---|
| 68 | * @return EOK on success or an error code
|
---|
| 69 | */
|
---|
| 70 | errno_t taskbar_cfg_create(const char *display_spec, taskbar_cfg_t **rdcfg)
|
---|
| 71 | {
|
---|
| 72 | ui_t *ui = NULL;
|
---|
| 73 | ui_wnd_params_t params;
|
---|
| 74 | ui_window_t *window = NULL;
|
---|
| 75 | taskbar_cfg_t *tbcfg = NULL;
|
---|
| 76 | gfx_rect_t rect;
|
---|
| 77 | ui_resource_t *ui_res;
|
---|
| 78 | errno_t rc;
|
---|
| 79 |
|
---|
| 80 | tbcfg = calloc(1, sizeof(taskbar_cfg_t));
|
---|
| 81 | if (tbcfg == NULL) {
|
---|
| 82 | printf("Out of memory.\n");
|
---|
| 83 | return ENOMEM;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | rc = ui_create(display_spec, &ui);
|
---|
| 87 | if (rc != EOK) {
|
---|
| 88 | printf("Error creating UI on display %s.\n", display_spec);
|
---|
| 89 | goto error;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | ui_wnd_params_init(¶ms);
|
---|
| 93 | params.caption = "Taskbar Configuration";
|
---|
| 94 | if (ui_is_textmode(ui)) {
|
---|
| 95 | params.rect.p0.x = 0;
|
---|
| 96 | params.rect.p0.y = 0;
|
---|
| 97 | params.rect.p1.x = 70;
|
---|
| 98 | params.rect.p1.y = 23;
|
---|
| 99 | } else {
|
---|
| 100 | params.rect.p0.x = 0;
|
---|
| 101 | params.rect.p0.y = 0;
|
---|
| 102 | params.rect.p1.x = 470;
|
---|
| 103 | params.rect.p1.y = 350;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | tbcfg->ui = ui;
|
---|
| 107 |
|
---|
| 108 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 109 | if (rc != EOK) {
|
---|
| 110 | printf("Error creating window.\n");
|
---|
| 111 | goto error;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | ui_window_set_cb(window, &window_cb, (void *)tbcfg);
|
---|
| 115 | tbcfg->window = window;
|
---|
| 116 |
|
---|
| 117 | ui_res = ui_window_get_res(window);
|
---|
| 118 |
|
---|
| 119 | rc = ui_fixed_create(&tbcfg->fixed);
|
---|
| 120 | if (rc != EOK) {
|
---|
| 121 | printf("Error creating fixed layout.\n");
|
---|
| 122 | return rc;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | rc = ui_tab_set_create(ui_res, &tbcfg->tabset);
|
---|
| 126 | if (rc != EOK) {
|
---|
| 127 | printf("Error creating tab set.\n");
|
---|
| 128 | return rc;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | ui_window_get_app_rect(window, &rect);
|
---|
| 132 | ui_tab_set_set_rect(tbcfg->tabset, &rect);
|
---|
| 133 |
|
---|
| 134 | rc = ui_fixed_add(tbcfg->fixed, ui_tab_set_ctl(tbcfg->tabset));
|
---|
| 135 | if (rc != EOK) {
|
---|
| 136 | printf("Error adding control to layout.\n");
|
---|
| 137 | return rc;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | rc = startmenu_create(tbcfg, &tbcfg->startmenu);
|
---|
| 141 | if (rc != EOK)
|
---|
| 142 | goto error;
|
---|
| 143 |
|
---|
| 144 | ui_window_add(window, ui_fixed_ctl(tbcfg->fixed));
|
---|
| 145 |
|
---|
| 146 | *rdcfg = tbcfg;
|
---|
| 147 | return EOK;
|
---|
| 148 | error:
|
---|
| 149 | if (tbcfg->startmenu != NULL)
|
---|
| 150 | startmenu_destroy(tbcfg->startmenu);
|
---|
| 151 | if (tbcfg->tabset != NULL)
|
---|
| 152 | ui_tab_set_destroy(tbcfg->tabset);
|
---|
| 153 | if (tbcfg->fixed != NULL)
|
---|
| 154 | ui_fixed_destroy(tbcfg->fixed);
|
---|
| 155 | if (tbcfg->ui != NULL)
|
---|
| 156 | ui_destroy(ui);
|
---|
| 157 | free(tbcfg);
|
---|
| 158 | return rc;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | /** Open Taskbar configuration.
|
---|
| 162 | *
|
---|
| 163 | * @param tbcfg Taskbar configuration dialog
|
---|
| 164 | * @param cfg_repo Path to configuration repository
|
---|
| 165 | * @return EOK on success or an error code
|
---|
| 166 | */
|
---|
| 167 | errno_t taskbar_cfg_open(taskbar_cfg_t *tbcfg, const char *cfg_repo)
|
---|
| 168 | {
|
---|
| 169 | errno_t rc;
|
---|
| 170 |
|
---|
| 171 | rc = tbarcfg_open(cfg_repo, &tbcfg->tbarcfg);
|
---|
| 172 | if (rc != EOK) {
|
---|
[21a65cca] | 173 | rc = tbarcfg_create(cfg_repo, &tbcfg->tbarcfg);
|
---|
| 174 | if (rc != EOK) {
|
---|
| 175 | printf("Error opening Taskbar configuration.\n");
|
---|
| 176 | goto error;
|
---|
| 177 | }
|
---|
[cb2894e] | 178 | }
|
---|
| 179 |
|
---|
| 180 | return EOK;
|
---|
| 181 | error:
|
---|
| 182 | return rc;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | /** Populate task configuration from configuration repository.
|
---|
| 186 | *
|
---|
| 187 | * @param tbcfg Taskbar configuration dialog
|
---|
| 188 | * @return EOK on success or an error code
|
---|
| 189 | */
|
---|
| 190 | errno_t taskbar_cfg_populate(taskbar_cfg_t *tbcfg)
|
---|
| 191 | {
|
---|
| 192 | errno_t rc;
|
---|
| 193 |
|
---|
| 194 | rc = startmenu_populate(tbcfg->startmenu, tbcfg->tbarcfg);
|
---|
| 195 | if (rc != EOK)
|
---|
| 196 | return rc;
|
---|
| 197 |
|
---|
| 198 | rc = ui_window_paint(tbcfg->window);
|
---|
| 199 | if (rc != EOK) {
|
---|
| 200 | printf("Error painting window.\n");
|
---|
| 201 | return rc;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | return EOK;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | /** Destroy Taskbar configuration window.
|
---|
| 208 | *
|
---|
| 209 | * @param tbcfg Taskbar configuration window
|
---|
| 210 | */
|
---|
| 211 | void taskbar_cfg_destroy(taskbar_cfg_t *tbcfg)
|
---|
| 212 | {
|
---|
| 213 | if (tbcfg->tbarcfg != NULL)
|
---|
| 214 | tbarcfg_close(tbcfg->tbarcfg);
|
---|
| 215 | ui_window_destroy(tbcfg->window);
|
---|
| 216 | ui_destroy(tbcfg->ui);
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | /** @}
|
---|
| 220 | */
|
---|