Changeset e63e74a in mainline for uspace/lib/tbarcfg/src/tbarcfg.c
- Timestamp:
- 2024-02-21T20:26:35Z (12 months ago)
- Branches:
- master
- Children:
- 95e2967
- Parents:
- 5f3188b8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 *
Note:
See TracChangeset
for help on using the changeset viewer.