Changeset e63e74a in mainline for uspace/lib
- Timestamp:
- 2024-02-21T20:26:35Z (17 months ago)
- Branches:
- master
- Children:
- 95e2967
- Parents:
- 5f3188b8
- Location:
- uspace/lib/tbarcfg
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/tbarcfg/include/tbarcfg/tbarcfg.h
r5f3188b8 re63e74a 52 52 extern const char *smenu_entry_get_cmd(smenu_entry_t *); 53 53 extern bool smenu_entry_get_terminal(smenu_entry_t *); 54 extern bool smenu_entry_get_separator(smenu_entry_t *); 54 55 extern errno_t smenu_entry_set_caption(smenu_entry_t *, const char *); 55 56 extern errno_t smenu_entry_set_cmd(smenu_entry_t *, const char *); … … 58 59 extern errno_t smenu_entry_create(tbarcfg_t *, const char *, const char *, 59 60 bool, smenu_entry_t **); 61 extern errno_t smenu_entry_sep_create(tbarcfg_t *, smenu_entry_t **); 60 62 extern errno_t smenu_entry_destroy(smenu_entry_t *); 61 63 extern errno_t smenu_entry_move_up(smenu_entry_t *); -
uspace/lib/tbarcfg/private/tbarcfg.h
r5f3188b8 re63e74a 61 61 /** SIF node (persistent storage) */ 62 62 sif_node_t *nentry; 63 /** Is this a separator entry */ 64 bool separator; 63 65 /** Entry caption (with accelerator markup) */ 64 66 char *caption; … … 71 73 extern errno_t smenu_entry_new(tbarcfg_t *, sif_node_t *, const char *, 72 74 const char *, bool, smenu_entry_t **); 75 extern errno_t smenu_entry_sep_new(tbarcfg_t *, sif_node_t *, smenu_entry_t **); 73 76 extern void smenu_entry_delete(smenu_entry_t *); 74 77 -
uspace/lib/tbarcfg/src/tbarcfg.c
r5f3188b8 re63e74a 108 108 sif_node_t *nentry; 109 109 const char *ntype; 110 const char *separator; 110 111 const char *caption; 111 112 const char *cmd; … … 143 144 } 144 145 145 caption = sif_node_get_attr(nentry, "caption");146 if ( caption == NULL) {146 separator = sif_node_get_attr(nentry, "separator"); 147 if (separator != NULL && str_cmp(separator, "y") != 0) { 147 148 rc = EIO; 148 149 goto error; 149 150 } 150 151 151 cmd = sif_node_get_attr(nentry, "cmd"); 152 if (cmd == NULL) { 153 rc = EIO; 154 goto error; 152 if (separator == NULL) { 153 caption = sif_node_get_attr(nentry, "caption"); 154 if (caption == NULL) { 155 rc = EIO; 156 goto error; 157 } 158 159 cmd = sif_node_get_attr(nentry, "cmd"); 160 if (cmd == NULL) { 161 rc = EIO; 162 goto error; 163 } 164 165 terminal = sif_node_get_attr(nentry, "terminal"); 166 if (terminal == NULL) 167 terminal = "n"; 168 169 rc = smenu_entry_new(tbcfg, nentry, caption, cmd, 170 str_cmp(terminal, "y") == 0, NULL); 171 if (rc != EOK) 172 goto error; 173 } else { 174 rc = smenu_entry_sep_new(tbcfg, nentry, NULL); 175 if (rc != EOK) 176 goto error; 155 177 } 156 157 terminal = sif_node_get_attr(nentry, "terminal");158 if (terminal == NULL)159 terminal = "n";160 161 rc = smenu_entry_new(tbcfg, nentry, caption, cmd,162 str_cmp(terminal, "y") == 0, NULL);163 if (rc != EOK)164 goto error;165 178 166 179 nentry = sif_node_next_child(nentry); … … 266 279 const char *smenu_entry_get_caption(smenu_entry_t *entry) 267 280 { 281 assert(!entry->separator); 268 282 return entry->caption; 269 283 } … … 276 290 const char *smenu_entry_get_cmd(smenu_entry_t *entry) 277 291 { 292 assert(!entry->separator); 278 293 return entry->cmd; 279 294 } 280 295 281 /** Get start menu start in terminal flag.296 /** Get start menu entry start in terminal flag. 282 297 * 283 298 * @param entry Start menu entry … … 286 301 bool smenu_entry_get_terminal(smenu_entry_t *entry) 287 302 { 303 assert(!entry->separator); 288 304 return entry->terminal; 305 } 306 307 /** Get start menu entry separator flag. 308 * 309 * @param entry Start menu entry 310 * @return Separator flag 311 */ 312 bool smenu_entry_get_separator(smenu_entry_t *entry) 313 { 314 return entry->separator; 289 315 } 290 316 … … 301 327 { 302 328 char *dcap; 329 330 assert(!entry->separator); 303 331 304 332 dcap = str_dup(caption); … … 324 352 char *dcmd; 325 353 354 assert(!entry->separator); 355 326 356 dcmd = str_dup(cmd); 327 357 if (dcmd == NULL) … … 343 373 void smenu_entry_set_terminal(smenu_entry_t *entry, bool terminal) 344 374 { 375 assert(!entry->separator); 345 376 entry->terminal = terminal; 346 377 } … … 355 386 errno_t rc; 356 387 357 rc = sif_node_set_attr(trans, entry->nentry, "cmd", entry->cmd); 358 if (rc != EOK) 359 goto error; 360 361 rc = sif_node_set_attr(trans, entry->nentry, "caption", entry->caption); 362 if (rc != EOK) 363 goto error; 364 365 rc = sif_node_set_attr(trans, entry->nentry, "terminal", 366 entry->terminal ? "y" : "n"); 367 if (rc != EOK) 368 goto error; 388 if (entry->separator) { 389 rc = sif_node_set_attr(trans, entry->nentry, "separator", "y"); 390 if (rc != EOK) 391 goto error; 392 } else { 393 sif_node_unset_attr(trans, entry->nentry, "separator"); 394 395 rc = sif_node_set_attr(trans, entry->nentry, "cmd", entry->cmd); 396 if (rc != EOK) 397 goto error; 398 399 rc = sif_node_set_attr(trans, entry->nentry, "caption", 400 entry->caption); 401 if (rc != EOK) 402 goto error; 403 404 rc = sif_node_set_attr(trans, entry->nentry, "terminal", 405 entry->terminal ? "y" : "n"); 406 if (rc != EOK) 407 goto error; 408 } 369 409 370 410 return EOK; … … 457 497 } 458 498 499 /** Allocate a start menu separator entry and append it to the start menu 500 * (internal). 501 * 502 * This only creates the entry in memory, but does not update the repository. 503 * 504 * @param smenu Start menu 505 * @param nentry Backing SIF node 506 * @param rentry Place to store pointer to new entry or @c NULL 507 */ 508 errno_t smenu_entry_sep_new(tbarcfg_t *smenu, sif_node_t *nentry, 509 smenu_entry_t **rentry) 510 { 511 smenu_entry_t *entry; 512 errno_t rc; 513 514 entry = calloc(1, sizeof(smenu_entry_t)); 515 if (entry == NULL) { 516 rc = ENOMEM; 517 goto error; 518 } 519 520 entry->nentry = nentry; 521 entry->separator = true; 522 523 entry->smenu = smenu; 524 list_append(&entry->lentries, &smenu->entries); 525 if (rentry != NULL) 526 *rentry = entry; 527 528 return EOK; 529 error: 530 return rc; 531 } 532 459 533 /** Delete start menu entry. 460 534 * … … 467 541 { 468 542 list_remove(&entry->lentries); 469 free(entry->caption); 470 free(entry->cmd); 543 if (entry->caption != NULL) 544 free(entry->caption); 545 if (entry->cmd != NULL) 546 free(entry->cmd); 471 547 free(entry); 472 548 } … … 527 603 } 528 604 605 /** Create new start menu separator entry. 606 * 607 * @param smenu Start menu 608 * @param nentry Backing SIF node 609 * @param rentry Place to store pointer to new entry or @c NULL 610 */ 611 errno_t smenu_entry_sep_create(tbarcfg_t *smenu, smenu_entry_t **rentry) 612 { 613 sif_node_t *nentry; 614 smenu_entry_t *entry; 615 errno_t rc; 616 sif_trans_t *trans = NULL; 617 618 rc = sif_trans_begin(smenu->repo, &trans); 619 if (rc != EOK) 620 goto error; 621 622 rc = sif_node_append_child(trans, smenu->nentries, "entry", 623 &nentry); 624 if (rc != EOK) 625 goto error; 626 627 rc = sif_node_set_attr(trans, nentry, "separator", "y"); 628 if (rc != EOK) 629 goto error; 630 631 rc = smenu_entry_sep_new(smenu, nentry, &entry); 632 if (rc != EOK) 633 goto error; 634 635 rc = sif_trans_end(trans); 636 if (rc != EOK) 637 goto error; 638 639 if (rentry != NULL) 640 *rentry = entry; 641 return EOK; 642 error: 643 if (trans != NULL) 644 sif_trans_abort(trans); 645 return rc; 646 } 647 529 648 /** Destroy start menu entry. 530 649 * -
uspace/lib/tbarcfg/test/tbarcfg.c
r5f3188b8 re63e74a 135 135 } 136 136 137 /** Separator entry */ 138 PCUT_TEST(separator) 139 { 140 errno_t rc; 141 tbarcfg_t *tbcfg; 142 char fname[L_tmpnam], *p; 143 const char *caption; 144 const char *cmd; 145 smenu_entry_t *e1 = NULL, *e2 = NULL; 146 smenu_entry_t *e; 147 148 p = tmpnam(fname); 149 PCUT_ASSERT_NOT_NULL(p); 150 151 rc = tbarcfg_create(fname, &tbcfg); 152 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 153 154 rc = smenu_entry_create(tbcfg, "A", "a", false, &e1); 155 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 156 PCUT_ASSERT_NOT_NULL(e1); 157 158 rc = smenu_entry_sep_create(tbcfg, &e2); 159 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 160 PCUT_ASSERT_NOT_NULL(e2); 161 162 PCUT_ASSERT_FALSE(smenu_entry_get_separator(e1)); 163 PCUT_ASSERT_TRUE(smenu_entry_get_separator(e2)); 164 165 tbarcfg_close(tbcfg); 166 167 /* Re-open repository */ 168 169 rc = tbarcfg_open(fname, &tbcfg); 170 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 171 172 e = tbarcfg_smenu_first(tbcfg); 173 PCUT_ASSERT_NOT_NULL(e); 174 175 /* Check that new values of properties have persisted */ 176 PCUT_ASSERT_FALSE(smenu_entry_get_separator(e)); 177 caption = smenu_entry_get_caption(e); 178 PCUT_ASSERT_STR_EQUALS("A", caption); 179 cmd = smenu_entry_get_cmd(e); 180 PCUT_ASSERT_STR_EQUALS("a", cmd); 181 182 e = tbarcfg_smenu_next(e); 183 184 /* Check that entry is still a separator */ 185 PCUT_ASSERT_TRUE(smenu_entry_get_separator(e)); 186 187 tbarcfg_close(tbcfg); 188 remove(fname); 189 } 190 137 191 /** Getting menu entry properties */ 138 192 PCUT_TEST(get_caption_cmd_term)
Note:
See TracChangeset
for help on using the changeset viewer.