Changes in uspace/lib/tbarcfg/src/tbarcfg.c [bff8619:ee3b28a9] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/tbarcfg/src/tbarcfg.c
rbff8619 ree3b28a9 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 *);50 49 51 50 /** Create taskbar configuration. … … 58 57 { 59 58 tbarcfg_t *tbcfg; 60 sif_ doc_t *doc= NULL;59 sif_sess_t *repo = NULL; 61 60 sif_node_t *rnode; 62 sif_node_t *nentries;63 errno_t rc;61 errno_t rc; 62 sif_trans_t *trans = NULL; 64 63 65 64 tbcfg = calloc(1, sizeof(tbarcfg_t)); … … 70 69 71 70 list_initialize(&tbcfg->entries); 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); 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; 95 91 96 92 *rtbcfg = tbcfg; 97 93 return EOK; 98 94 error: 99 if ( doc!= NULL)100 sif_ delete(doc);101 if ( tbcfg != NULL && tbcfg->cfgpath!= NULL)102 free(tbcfg->cfgpath);95 if (trans != NULL) 96 sif_trans_abort(trans); 97 if (repo != NULL) 98 sif_close(repo); 103 99 if (tbcfg != NULL) 104 100 free(tbcfg); … … 115 111 { 116 112 tbarcfg_t *tbcfg; 117 sif_doc_t *doc = NULL; 118 sif_node_t *nentries; 113 sif_sess_t *repo = NULL; 119 114 sif_node_t *rnode; 120 115 sif_node_t *nentry; … … 133 128 134 129 list_initialize(&tbcfg->entries); 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); 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); 148 140 if (str_cmp(ntype, "entries") != 0) { 149 141 rc = EIO; … … 151 143 } 152 144 153 nentry = sif_node_first_child( nentries);145 nentry = sif_node_first_child(tbcfg->nentries); 154 146 while (nentry != NULL) { 155 147 ntype = sif_node_get_type(nentry); … … 182 174 terminal = "n"; 183 175 184 rc = smenu_entry_ create(tbcfg, caption, cmd,176 rc = smenu_entry_new(tbcfg, nentry, caption, cmd, 185 177 str_cmp(terminal, "y") == 0, NULL); 186 178 if (rc != EOK) 187 179 goto error; 188 180 } else { 189 rc = smenu_entry_sep_ create(tbcfg, NULL);181 rc = smenu_entry_sep_new(tbcfg, nentry, NULL); 190 182 if (rc != EOK) 191 183 goto error; … … 195 187 } 196 188 197 sif_delete(doc);198 189 *rtbcfg = tbcfg; 199 190 return EOK; 200 191 error: 201 if (doc != NULL) 202 sif_delete(doc); 203 if (tbcfg != NULL && tbcfg->cfgpath != NULL) 204 free(tbcfg->cfgpath); 192 if (repo != NULL) 193 sif_close(repo); 205 194 if (tbcfg != NULL) 206 195 free(tbcfg); … … 218 207 entry = tbarcfg_smenu_first(tbcfg); 219 208 while (entry != NULL) { 220 smenu_entry_de stroy(entry);209 smenu_entry_delete(entry); 221 210 entry = tbarcfg_smenu_first(tbcfg); 222 211 } 223 212 224 free(tbcfg->cfgpath);213 (void)sif_close(tbcfg->repo); 225 214 free(tbcfg); 226 }227 228 /** Synchronize taskbar configuration to config file.229 *230 * @param repopath Pathname of the menu repository231 * @param rtbcfg Place to store pointer to taskbar configuration232 * @return EOK on success or an error code233 */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;275 215 } 276 216 … … 385 325 * 386 326 * Note: To make the change visible to others and persistent, 387 * you must call @c tbarcfg_sync()327 * you must call @c smenu_entry_save() 388 328 * 389 329 * @param entry Start menu entry … … 409 349 * 410 350 * Note: To make the change visible to others and persistent, 411 * you must call @c tbarcfg_sync()351 * you must call @c smenu_entry_save() 412 352 * 413 353 * @param entry Start menu entry … … 433 373 * 434 374 * Note: To make the change visible to others and persistent, 435 * you must call @c tbarcfg_sync()375 * you must call @c smenu_entry_save() 436 376 * 437 377 * @param entry Start menu entry … … 447 387 * 448 388 * @param entry Start menu entry 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; 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; 459 394 460 395 if (entry->separator) { 461 rc = sif_node_set_attr( nentry, "separator", "y");396 rc = sif_node_set_attr(trans, entry->nentry, "separator", "y"); 462 397 if (rc != EOK) 463 398 goto error; 464 399 } else { 465 rc = sif_node_set_attr(nentry, "cmd", entry->cmd); 400 sif_node_unset_attr(trans, entry->nentry, "separator"); 401 402 rc = sif_node_set_attr(trans, entry->nentry, "cmd", entry->cmd); 466 403 if (rc != EOK) 467 404 goto error; 468 405 469 rc = sif_node_set_attr( nentry, "caption",406 rc = sif_node_set_attr(trans, entry->nentry, "caption", 470 407 entry->caption); 471 408 if (rc != EOK) 472 409 goto error; 473 410 474 rc = sif_node_set_attr( nentry, "terminal",411 rc = sif_node_set_attr(trans, entry->nentry, "terminal", 475 412 entry->terminal ? "y" : "n"); 476 413 if (rc != EOK) … … 480 417 return EOK; 481 418 error: 482 if (nentry != NULL) 483 sif_node_destroy(nentry); 484 return rc; 485 } 486 487 /** Create new start menu entry and append it to the start menu (internal). 419 return rc; 420 } 421 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). 488 451 * 489 452 * This only creates the entry in memory, but does not update the repository. 490 453 * 491 454 * @param smenu Start menu 455 * @param nentry Backing SIF node 492 456 * @param caption Caption 493 457 * @param cmd Command to run … … 495 459 * @param rentry Place to store pointer to new entry or @c NULL 496 460 */ 497 errno_t smenu_entry_ create(tbarcfg_t *smenu, const char *caption,498 const char *c md, bool terminal, smenu_entry_t **rentry)461 errno_t smenu_entry_new(tbarcfg_t *smenu, sif_node_t *nentry, 462 const char *caption, const char *cmd, bool terminal, smenu_entry_t **rentry) 499 463 { 500 464 smenu_entry_t *entry; … … 506 470 goto error; 507 471 } 472 473 entry->nentry = nentry; 508 474 509 475 entry->caption = str_dup(caption); … … 538 504 } 539 505 540 /** Create newstart menu separator entry and append it to the start menu506 /** Allocate a start menu separator entry and append it to the start menu 541 507 * (internal). 542 508 * … … 544 510 * 545 511 * @param smenu Start menu 512 * @param nentry Backing SIF node 546 513 * @param rentry Place to store pointer to new entry or @c NULL 547 514 */ 548 errno_t smenu_entry_sep_create(tbarcfg_t *smenu, smenu_entry_t **rentry) 515 errno_t smenu_entry_sep_new(tbarcfg_t *smenu, sif_node_t *nentry, 516 smenu_entry_t **rentry) 549 517 { 550 518 smenu_entry_t *entry; … … 557 525 } 558 526 527 entry->nentry = nentry; 559 528 entry->separator = true; 560 529 … … 569 538 } 570 539 571 /** De stroystart menu entry.540 /** Delete start menu entry. 572 541 * 573 542 * This only deletes the entry from, but does not update the … … 576 545 * @param entry Start menu entry 577 546 */ 578 void smenu_entry_de stroy(smenu_entry_t *entry)547 void smenu_entry_delete(smenu_entry_t *entry) 579 548 { 580 549 list_remove(&entry->lentries); … … 586 555 } 587 556 557 /** Create new start menu entry. 558 * 559 * @param smenu Start menu 560 * @param nentry Backing SIF node 561 * @param caption Caption 562 * @param cmd Command to run 563 * @param terminal Start in terminal 564 * @param rentry Place to store pointer to new entry or @c NULL 565 */ 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 menu 615 * @param nentry Backing SIF node 616 * @param rentry Place to store pointer to new entry or @c NULL 617 */ 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 entry 658 * @return EOK on success or an error code 659 */ 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 588 683 /** Move start menu entry up. 589 684 * 590 685 * @param entry Start menu entry 591 */ 592 void smenu_entry_move_up(smenu_entry_t *entry) 593 { 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; 594 694 smenu_entry_t *prev; 695 696 rc = sif_trans_begin(entry->smenu->repo, &trans); 697 if (rc != EOK) 698 goto error; 595 699 596 700 prev = tbarcfg_smenu_prev(entry); 597 701 if (prev == NULL) { 598 702 /* Entry is already at first position, nothing to do. */ 599 return; 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; 600 725 } 601 726 602 727 list_remove(&entry->lentries); 603 728 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; 604 736 } 605 737 … … 607 739 * 608 740 * @param entry Start menu entry 609 */ 610 void smenu_entry_move_down(smenu_entry_t *entry) 611 { 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; 612 749 smenu_entry_t *next; 750 751 rc = sif_trans_begin(entry->smenu->repo, &trans); 752 if (rc != EOK) 753 goto error; 613 754 614 755 next = tbarcfg_smenu_next(entry); 615 756 if (next == NULL) { 616 757 /* Entry is already at last position, nothing to do. */ 617 return; 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; 618 780 } 619 781 620 782 list_remove(&entry->lentries); 621 783 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; 622 791 } 623 792
Note:
See TracChangeset
for help on using the changeset viewer.