Changeset 28ca31ed in mainline for uspace/lib/tbarcfg/src/tbarcfg.c
- Timestamp:
- 2024-02-13T20:13:48Z (16 months ago)
- Branches:
- master
- Children:
- 10657856
- Parents:
- 242e3c3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/tbarcfg/src/tbarcfg.c
r242e3c3 r28ca31ed 101 101 * @return EOK on success or an error code 102 102 */ 103 #include <stdio.h>104 103 errno_t tbarcfg_open(const char *repopath, tbarcfg_t **rtbcfg) 105 104 { … … 160 159 terminal = "n"; 161 160 162 printf("terminal=%s\n", terminal);163 164 161 rc = smenu_entry_new(tbcfg, nentry, caption, cmd, 165 162 str_cmp(terminal, "y") == 0, NULL); … … 230 227 } 231 228 229 /** Get last start menu entry. 230 * 231 * @param tbcfg Taskbar configuration 232 * @return Previous entry or @c NULL if the menu is empty 233 */ 234 smenu_entry_t *tbarcfg_smenu_last(tbarcfg_t *tbcfg) 235 { 236 link_t *link; 237 238 link = list_last(&tbcfg->entries); 239 if (link == NULL) 240 return NULL; 241 242 return list_get_instance(link, smenu_entry_t, lentries); 243 } 244 245 /** Get previous start menu entry. 246 * 247 * @param cur Current entry 248 * @return Previous entry or @c NULL if @a cur is the last entry 249 */ 250 smenu_entry_t *tbarcfg_smenu_prev(smenu_entry_t *cur) 251 { 252 link_t *link; 253 254 link = list_prev(&cur->lentries, &cur->smenu->entries); 255 if (link == NULL) 256 return NULL; 257 258 return list_get_instance(link, smenu_entry_t, lentries); 259 } 260 232 261 /** Get start menu entry caption. 233 262 * … … 317 346 } 318 347 319 /** Save any changes to start menu entry. 320 * 321 * @param entry Start menu entry 322 */ 323 errno_t smenu_entry_save(smenu_entry_t *entry) 324 { 325 sif_trans_t *trans = NULL; 326 errno_t rc; 327 328 rc = sif_trans_begin(entry->smenu->repo, &trans); 329 if (rc != EOK) 330 goto error; 348 /** Save start menu entry using transaction. 349 * 350 * @param entry Start menu entry 351 * @param trans Transaction 352 */ 353 static errno_t smenu_entry_save_trans(smenu_entry_t *entry, sif_trans_t *trans) 354 { 355 errno_t rc; 331 356 332 357 rc = sif_node_set_attr(trans, entry->nentry, "cmd", entry->cmd); … … 340 365 rc = sif_node_set_attr(trans, entry->nentry, "terminal", 341 366 entry->terminal ? "y" : "n"); 367 if (rc != EOK) 368 goto error; 369 370 return EOK; 371 error: 372 return rc; 373 } 374 375 /** Save any changes to start menu entry. 376 * 377 * @param entry Start menu entry 378 */ 379 errno_t smenu_entry_save(smenu_entry_t *entry) 380 { 381 sif_trans_t *trans = NULL; 382 errno_t rc; 383 384 rc = sif_trans_begin(entry->smenu->repo, &trans); 385 if (rc != EOK) 386 goto error; 387 388 rc = smenu_entry_save_trans(entry, trans); 342 389 if (rc != EOK) 343 390 goto error; … … 463 510 goto error; 464 511 465 rc = smenu_entry_new(smenu, nentry, caption, cmd, terminal ? "y" : "n", 466 &entry); 512 rc = smenu_entry_new(smenu, nentry, caption, cmd, terminal, &entry); 467 513 if (rc != EOK) 468 514 goto error; … … 481 527 } 482 528 483 /** Destroy start menu entry. .529 /** Destroy start menu entry. 484 530 * 485 531 * @param entry Start menu entry … … 509 555 } 510 556 557 /** Move start menu entry up. 558 * 559 * @param entry Start menu entry 560 * @return EOK on success or an error code 561 */ 562 errno_t smenu_entry_move_up(smenu_entry_t *entry) 563 { 564 errno_t rc; 565 sif_trans_t *trans = NULL; 566 sif_node_t *nnode = NULL; 567 sif_node_t *old_node; 568 smenu_entry_t *prev; 569 570 rc = sif_trans_begin(entry->smenu->repo, &trans); 571 if (rc != EOK) 572 goto error; 573 574 prev = tbarcfg_smenu_prev(entry); 575 if (prev == NULL) { 576 /* Entry is already at first position, nothing to do. */ 577 return EOK; 578 } 579 580 rc = sif_node_insert_before(trans, prev->nentry, "entry", &nnode); 581 if (rc != EOK) 582 goto error; 583 584 old_node = entry->nentry; 585 entry->nentry = nnode; 586 587 rc = smenu_entry_save_trans(entry, trans); 588 if (rc != EOK) { 589 entry->nentry = old_node; 590 goto error; 591 } 592 593 sif_node_destroy(trans, old_node); 594 595 rc = sif_trans_end(trans); 596 if (rc != EOK) { 597 entry->nentry = old_node; 598 goto error; 599 } 600 601 list_remove(&entry->lentries); 602 list_insert_before(&entry->lentries, &prev->lentries); 603 return EOK; 604 error: 605 if (nnode != NULL) 606 sif_node_destroy(trans, nnode); 607 if (trans != NULL) 608 sif_trans_abort(trans); 609 return rc; 610 } 611 612 /** Move start menu entry down. 613 * 614 * @param entry Start menu entry 615 * @return EOK on success or an error code 616 */ 617 errno_t smenu_entry_move_down(smenu_entry_t *entry) 618 { 619 errno_t rc; 620 sif_trans_t *trans = NULL; 621 sif_node_t *nnode = NULL; 622 sif_node_t *old_node; 623 smenu_entry_t *next; 624 625 rc = sif_trans_begin(entry->smenu->repo, &trans); 626 if (rc != EOK) 627 goto error; 628 629 next = tbarcfg_smenu_next(entry); 630 if (next == NULL) { 631 /* Entry is already at last position, nothing to do. */ 632 return EOK; 633 } 634 635 rc = sif_node_insert_after(trans, next->nentry, "entry", &nnode); 636 if (rc != EOK) 637 goto error; 638 639 old_node = entry->nentry; 640 entry->nentry = nnode; 641 642 rc = smenu_entry_save_trans(entry, trans); 643 if (rc != EOK) { 644 entry->nentry = old_node; 645 goto error; 646 } 647 648 sif_node_destroy(trans, old_node); 649 650 rc = sif_trans_end(trans); 651 if (rc != EOK) { 652 entry->nentry = old_node; 653 goto error; 654 } 655 656 list_remove(&entry->lentries); 657 list_insert_after(&entry->lentries, &next->lentries); 658 return EOK; 659 error: 660 if (nnode != NULL) 661 sif_node_destroy(trans, nnode); 662 if (trans != NULL) 663 sif_trans_abort(trans); 664 return rc; 665 } 666 511 667 /** @} 512 668 */
Note:
See TracChangeset
for help on using the changeset viewer.