Changeset ebb1489 in mainline for uspace/lib/tbarcfg/src/tbarcfg.c
- Timestamp:
- 2024-10-13T08:23:40Z (2 months ago)
- Children:
- 0472cf17
- Parents:
- 2a0c827c (diff), b3b79981 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- boba-buba <120932204+boba-buba@…> (2024-10-13 08:23:40)
- git-committer:
- GitHub <noreply@…> (2024-10-13 08:23:40)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/tbarcfg/src/tbarcfg.c
r2a0c827c rebb1489 47 47 48 48 static void tbarcfg_notify_conn(ipc_call_t *, void *); 49 static errno_t smenu_entry_save(smenu_entry_t *, sif_node_t *); 49 50 50 51 /** Create taskbar configuration. … … 57 58 { 58 59 tbarcfg_t *tbcfg; 59 sif_ sess_t *repo= NULL;60 sif_doc_t *doc = NULL; 60 61 sif_node_t *rnode; 61 errno_t rc;62 sif_trans_t *trans = NULL;62 sif_node_t *nentries; 63 errno_t rc; 63 64 64 65 tbcfg = calloc(1, sizeof(tbarcfg_t)); … … 69 70 70 71 list_initialize(&tbcfg->entries); 71 72 rc = sif_create(repopath, &repo); 73 if (rc != EOK) 74 goto error; 75 76 tbcfg->repo = repo; 77 78 rnode = sif_get_root(repo); 79 80 rc = sif_trans_begin(repo, &trans); 81 if (rc != EOK) 82 goto error; 83 84 rc = sif_node_append_child(trans, rnode, "entries", &tbcfg->nentries); 85 if (rc != EOK) 86 goto error; 87 88 rc = sif_trans_end(trans); 89 if (rc != EOK) 90 goto error; 72 tbcfg->cfgpath = str_dup(repopath); 73 if (tbcfg->cfgpath == NULL) { 74 rc = ENOMEM; 75 goto error; 76 } 77 78 rc = sif_new(&doc); 79 if (rc != EOK) 80 goto error; 81 82 rnode = sif_get_root(doc); 83 84 rc = sif_node_append_child(rnode, "entries", &nentries); 85 if (rc != EOK) 86 goto error; 87 88 (void)nentries; 89 90 rc = sif_save(doc, repopath); 91 if (rc != EOK) 92 goto error; 93 94 sif_delete(doc); 91 95 92 96 *rtbcfg = tbcfg; 93 97 return EOK; 94 98 error: 95 if ( trans!= NULL)96 sif_ trans_abort(trans);97 if ( repo!= NULL)98 sif_close(repo);99 if (doc != NULL) 100 sif_delete(doc); 101 if (tbcfg != NULL && tbcfg->cfgpath != NULL) 102 free(tbcfg->cfgpath); 99 103 if (tbcfg != NULL) 100 104 free(tbcfg); … … 111 115 { 112 116 tbarcfg_t *tbcfg; 113 sif_sess_t *repo = NULL; 117 sif_doc_t *doc = NULL; 118 sif_node_t *nentries; 114 119 sif_node_t *rnode; 115 120 sif_node_t *nentry; … … 128 133 129 134 list_initialize(&tbcfg->entries); 130 131 rc = sif_open(repopath, &repo); 132 if (rc != EOK) 133 goto error; 134 135 tbcfg->repo = repo; 136 137 rnode = sif_get_root(repo); 138 tbcfg->nentries = sif_node_first_child(rnode); 139 ntype = sif_node_get_type(tbcfg->nentries); 135 tbcfg->cfgpath = str_dup(repopath); 136 if (tbcfg->cfgpath == NULL) { 137 rc = ENOMEM; 138 goto error; 139 } 140 141 rc = sif_load(repopath, &doc); 142 if (rc != EOK) 143 goto error; 144 145 rnode = sif_get_root(doc); 146 nentries = sif_node_first_child(rnode); 147 ntype = sif_node_get_type(nentries); 140 148 if (str_cmp(ntype, "entries") != 0) { 141 149 rc = EIO; … … 143 151 } 144 152 145 nentry = sif_node_first_child( tbcfg->nentries);153 nentry = sif_node_first_child(nentries); 146 154 while (nentry != NULL) { 147 155 ntype = sif_node_get_type(nentry); … … 174 182 terminal = "n"; 175 183 176 rc = smenu_entry_ new(tbcfg, nentry, caption, cmd,184 rc = smenu_entry_create(tbcfg, caption, cmd, 177 185 str_cmp(terminal, "y") == 0, NULL); 178 186 if (rc != EOK) 179 187 goto error; 180 188 } else { 181 rc = smenu_entry_sep_ new(tbcfg, nentry, NULL);189 rc = smenu_entry_sep_create(tbcfg, NULL); 182 190 if (rc != EOK) 183 191 goto error; … … 187 195 } 188 196 197 sif_delete(doc); 189 198 *rtbcfg = tbcfg; 190 199 return EOK; 191 200 error: 192 if (repo != NULL) 193 sif_close(repo); 201 if (doc != NULL) 202 sif_delete(doc); 203 if (tbcfg != NULL && tbcfg->cfgpath != NULL) 204 free(tbcfg->cfgpath); 194 205 if (tbcfg != NULL) 195 206 free(tbcfg); … … 207 218 entry = tbarcfg_smenu_first(tbcfg); 208 219 while (entry != NULL) { 209 smenu_entry_de lete(entry);220 smenu_entry_destroy(entry); 210 221 entry = tbarcfg_smenu_first(tbcfg); 211 222 } 212 223 213 (void)sif_close(tbcfg->repo);224 free(tbcfg->cfgpath); 214 225 free(tbcfg); 226 } 227 228 /** Synchronize taskbar configuration to config file. 229 * 230 * @param repopath Pathname of the menu repository 231 * @param rtbcfg Place to store pointer to taskbar configuration 232 * @return EOK on success or an error code 233 */ 234 errno_t tbarcfg_sync(tbarcfg_t *tbcfg) 235 { 236 sif_doc_t *doc = NULL; 237 sif_node_t *nentries; 238 sif_node_t *rnode; 239 smenu_entry_t *entry; 240 errno_t rc; 241 242 rc = sif_new(&doc); 243 if (rc != EOK) 244 goto error; 245 246 rnode = sif_get_root(doc); 247 248 rc = sif_node_append_child(rnode, "entries", &nentries); 249 if (rc != EOK) 250 goto error; 251 252 entry = tbarcfg_smenu_first(tbcfg); 253 while (entry != NULL) { 254 rc = smenu_entry_save(entry, nentries); 255 if (rc != EOK) 256 goto error; 257 258 entry = tbarcfg_smenu_next(entry); 259 } 260 261 rc = sif_save(doc, tbcfg->cfgpath); 262 if (rc != EOK) 263 goto error; 264 265 sif_delete(doc); 266 return EOK; 267 error: 268 if (doc != NULL) 269 sif_delete(doc); 270 if (tbcfg != NULL && tbcfg->cfgpath != NULL) 271 free(tbcfg->cfgpath); 272 if (tbcfg != NULL) 273 free(tbcfg); 274 return rc; 215 275 } 216 276 … … 325 385 * 326 386 * Note: To make the change visible to others and persistent, 327 * you must call @c smenu_entry_save()387 * you must call @c tbarcfg_sync() 328 388 * 329 389 * @param entry Start menu entry … … 349 409 * 350 410 * Note: To make the change visible to others and persistent, 351 * you must call @c smenu_entry_save()411 * you must call @c tbarcfg_sync() 352 412 * 353 413 * @param entry Start menu entry … … 373 433 * 374 434 * Note: To make the change visible to others and persistent, 375 * you must call @c smenu_entry_save()435 * you must call @c tbarcfg_sync() 376 436 * 377 437 * @param entry Start menu entry … … 387 447 * 388 448 * @param entry Start menu entry 389 * @param trans Transaction 390 */ 391 static errno_t smenu_entry_save_trans(smenu_entry_t *entry, sif_trans_t *trans) 392 { 393 errno_t rc; 449 * @param nentries Entries node 450 */ 451 static errno_t smenu_entry_save(smenu_entry_t *entry, sif_node_t *nentries) 452 { 453 sif_node_t *nentry = NULL; 454 errno_t rc; 455 456 rc = sif_node_append_child(nentries, "entry", &nentry); 457 if (rc != EOK) 458 goto error; 394 459 395 460 if (entry->separator) { 396 rc = sif_node_set_attr( trans, entry->nentry, "separator", "y");461 rc = sif_node_set_attr(nentry, "separator", "y"); 397 462 if (rc != EOK) 398 463 goto error; 399 464 } else { 400 sif_node_unset_attr(trans, entry->nentry, "separator"); 401 402 rc = sif_node_set_attr(trans, entry->nentry, "cmd", entry->cmd); 465 rc = sif_node_set_attr(nentry, "cmd", entry->cmd); 403 466 if (rc != EOK) 404 467 goto error; 405 468 406 rc = sif_node_set_attr( trans, entry->nentry, "caption",469 rc = sif_node_set_attr(nentry, "caption", 407 470 entry->caption); 408 471 if (rc != EOK) 409 472 goto error; 410 473 411 rc = sif_node_set_attr( trans, entry->nentry, "terminal",474 rc = sif_node_set_attr(nentry, "terminal", 412 475 entry->terminal ? "y" : "n"); 413 476 if (rc != EOK) … … 417 480 return EOK; 418 481 error: 482 if (nentry != NULL) 483 sif_node_destroy(nentry); 419 484 return rc; 420 485 } 421 486 422 /** Save any changes to start menu entry. 423 * 424 * @param entry Start menu entry 425 */ 426 errno_t smenu_entry_save(smenu_entry_t *entry) 427 { 428 sif_trans_t *trans = NULL; 429 errno_t rc; 430 431 rc = sif_trans_begin(entry->smenu->repo, &trans); 432 if (rc != EOK) 433 goto error; 434 435 rc = smenu_entry_save_trans(entry, trans); 436 if (rc != EOK) 437 goto error; 438 439 rc = sif_trans_end(trans); 440 if (rc != EOK) 441 goto error; 442 443 return EOK; 444 error: 445 if (trans != NULL) 446 sif_trans_abort(trans); 447 return rc; 448 } 449 450 /** Allocate a start menu entry and append it to the start menu (internal). 487 /** Create new start menu entry and append it to the start menu (internal). 451 488 * 452 489 * This only creates the entry in memory, but does not update the repository. 453 490 * 454 491 * @param smenu Start menu 455 * @param nentry Backing SIF node456 492 * @param caption Caption 457 493 * @param cmd Command to run … … 459 495 * @param rentry Place to store pointer to new entry or @c NULL 460 496 */ 461 errno_t smenu_entry_ new(tbarcfg_t *smenu, sif_node_t *nentry,462 const char *c aption, const char *cmd, bool terminal, smenu_entry_t **rentry)497 errno_t smenu_entry_create(tbarcfg_t *smenu, const char *caption, 498 const char *cmd, bool terminal, smenu_entry_t **rentry) 463 499 { 464 500 smenu_entry_t *entry; … … 470 506 goto error; 471 507 } 472 473 entry->nentry = nentry;474 508 475 509 entry->caption = str_dup(caption); … … 504 538 } 505 539 506 /** Allocate astart menu separator entry and append it to the start menu540 /** Create new start menu separator entry and append it to the start menu 507 541 * (internal). 508 542 * … … 510 544 * 511 545 * @param smenu Start menu 512 * @param nentry Backing SIF node513 546 * @param rentry Place to store pointer to new entry or @c NULL 514 547 */ 515 errno_t smenu_entry_sep_new(tbarcfg_t *smenu, sif_node_t *nentry, 516 smenu_entry_t **rentry) 548 errno_t smenu_entry_sep_create(tbarcfg_t *smenu, smenu_entry_t **rentry) 517 549 { 518 550 smenu_entry_t *entry; … … 525 557 } 526 558 527 entry->nentry = nentry;528 559 entry->separator = true; 529 560 … … 538 569 } 539 570 540 /** De letestart menu entry.571 /** Destroy start menu entry. 541 572 * 542 573 * This only deletes the entry from, but does not update the … … 545 576 * @param entry Start menu entry 546 577 */ 547 void smenu_entry_de lete(smenu_entry_t *entry)578 void smenu_entry_destroy(smenu_entry_t *entry) 548 579 { 549 580 list_remove(&entry->lentries); … … 555 586 } 556 587 557 /** Create new start menu entry.558 *559 * @param smenu Start menu560 * @param nentry Backing SIF node561 * @param caption Caption562 * @param cmd Command to run563 * @param terminal Start in terminal564 * @param rentry Place to store pointer to new entry or @c NULL565 */566 errno_t smenu_entry_create(tbarcfg_t *smenu, const char *caption,567 const char *cmd, bool terminal, smenu_entry_t **rentry)568 {569 sif_node_t *nentry;570 smenu_entry_t *entry;571 errno_t rc;572 sif_trans_t *trans = NULL;573 574 rc = sif_trans_begin(smenu->repo, &trans);575 if (rc != EOK)576 goto error;577 578 rc = sif_node_append_child(trans, smenu->nentries, "entry",579 &nentry);580 if (rc != EOK)581 goto error;582 583 rc = sif_node_set_attr(trans, nentry, "cmd", cmd);584 if (rc != EOK)585 goto error;586 587 rc = sif_node_set_attr(trans, nentry, "caption", caption);588 if (rc != EOK)589 goto error;590 591 rc = sif_node_set_attr(trans, nentry, "terminal", terminal ? "y" : "n");592 if (rc != EOK)593 goto error;594 595 rc = smenu_entry_new(smenu, nentry, caption, cmd, terminal, &entry);596 if (rc != EOK)597 goto error;598 599 rc = sif_trans_end(trans);600 if (rc != EOK)601 goto error;602 603 if (rentry != NULL)604 *rentry = entry;605 return EOK;606 error:607 if (trans != NULL)608 sif_trans_abort(trans);609 return rc;610 }611 612 /** Create new start menu separator entry.613 *614 * @param smenu Start menu615 * @param nentry Backing SIF node616 * @param rentry Place to store pointer to new entry or @c NULL617 */618 errno_t smenu_entry_sep_create(tbarcfg_t *smenu, smenu_entry_t **rentry)619 {620 sif_node_t *nentry;621 smenu_entry_t *entry;622 errno_t rc;623 sif_trans_t *trans = NULL;624 625 rc = sif_trans_begin(smenu->repo, &trans);626 if (rc != EOK)627 goto error;628 629 rc = sif_node_append_child(trans, smenu->nentries, "entry",630 &nentry);631 if (rc != EOK)632 goto error;633 634 rc = sif_node_set_attr(trans, nentry, "separator", "y");635 if (rc != EOK)636 goto error;637 638 rc = smenu_entry_sep_new(smenu, nentry, &entry);639 if (rc != EOK)640 goto error;641 642 rc = sif_trans_end(trans);643 if (rc != EOK)644 goto error;645 646 if (rentry != NULL)647 *rentry = entry;648 return EOK;649 error:650 if (trans != NULL)651 sif_trans_abort(trans);652 return rc;653 }654 655 /** Destroy start menu entry.656 *657 * @param entry Start menu entry658 * @return EOK on success or an error code659 */660 errno_t smenu_entry_destroy(smenu_entry_t *entry)661 {662 errno_t rc;663 sif_trans_t *trans = NULL;664 665 rc = sif_trans_begin(entry->smenu->repo, &trans);666 if (rc != EOK)667 goto error;668 669 sif_node_destroy(trans, entry->nentry);670 671 rc = sif_trans_end(trans);672 if (rc != EOK)673 goto error;674 675 smenu_entry_delete(entry);676 return EOK;677 error:678 if (trans != NULL)679 sif_trans_abort(trans);680 return rc;681 }682 683 588 /** Move start menu entry up. 684 589 * 685 590 * @param entry Start menu entry 686 * @return EOK on success or an error code 687 */ 688 errno_t smenu_entry_move_up(smenu_entry_t *entry) 689 { 690 errno_t rc; 691 sif_trans_t *trans = NULL; 692 sif_node_t *nnode = NULL; 693 sif_node_t *old_node; 591 */ 592 void smenu_entry_move_up(smenu_entry_t *entry) 593 { 694 594 smenu_entry_t *prev; 695 696 rc = sif_trans_begin(entry->smenu->repo, &trans);697 if (rc != EOK)698 goto error;699 595 700 596 prev = tbarcfg_smenu_prev(entry); 701 597 if (prev == NULL) { 702 598 /* Entry is already at first position, nothing to do. */ 703 return EOK; 704 } 705 706 rc = sif_node_insert_before(trans, prev->nentry, "entry", &nnode); 707 if (rc != EOK) 708 goto error; 709 710 old_node = entry->nentry; 711 entry->nentry = nnode; 712 713 rc = smenu_entry_save_trans(entry, trans); 714 if (rc != EOK) { 715 entry->nentry = old_node; 716 goto error; 717 } 718 719 sif_node_destroy(trans, old_node); 720 721 rc = sif_trans_end(trans); 722 if (rc != EOK) { 723 entry->nentry = old_node; 724 goto error; 599 return; 725 600 } 726 601 727 602 list_remove(&entry->lentries); 728 603 list_insert_before(&entry->lentries, &prev->lentries); 729 return EOK;730 error:731 if (nnode != NULL)732 sif_node_destroy(trans, nnode);733 if (trans != NULL)734 sif_trans_abort(trans);735 return rc;736 604 } 737 605 … … 739 607 * 740 608 * @param entry Start menu entry 741 * @return EOK on success or an error code 742 */ 743 errno_t smenu_entry_move_down(smenu_entry_t *entry) 744 { 745 errno_t rc; 746 sif_trans_t *trans = NULL; 747 sif_node_t *nnode = NULL; 748 sif_node_t *old_node; 609 */ 610 void smenu_entry_move_down(smenu_entry_t *entry) 611 { 749 612 smenu_entry_t *next; 750 751 rc = sif_trans_begin(entry->smenu->repo, &trans);752 if (rc != EOK)753 goto error;754 613 755 614 next = tbarcfg_smenu_next(entry); 756 615 if (next == NULL) { 757 616 /* Entry is already at last position, nothing to do. */ 758 return EOK; 759 } 760 761 rc = sif_node_insert_after(trans, next->nentry, "entry", &nnode); 762 if (rc != EOK) 763 goto error; 764 765 old_node = entry->nentry; 766 entry->nentry = nnode; 767 768 rc = smenu_entry_save_trans(entry, trans); 769 if (rc != EOK) { 770 entry->nentry = old_node; 771 goto error; 772 } 773 774 sif_node_destroy(trans, old_node); 775 776 rc = sif_trans_end(trans); 777 if (rc != EOK) { 778 entry->nentry = old_node; 779 goto error; 617 return; 780 618 } 781 619 782 620 list_remove(&entry->lentries); 783 621 list_insert_after(&entry->lentries, &next->lentries); 784 return EOK;785 error:786 if (nnode != NULL)787 sif_node_destroy(trans, nnode);788 if (trans != NULL)789 sif_trans_abort(trans);790 return rc;791 622 } 792 623
Note:
See TracChangeset
for help on using the changeset viewer.