Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/tbarcfg/src/tbarcfg.c

    r84d29a2 rb1397ab  
    4141#include "../private/tbarcfg.h"
    4242
    43 /** Create taskbar configuration.
    44  *
    45  * @param repopath Pathname of the new menu repository
     43/** Open taskbar configuration.
     44 *
     45 * @param repopath Pathname of the menu repository
    4646 * @param rtbcfg Place to store pointer to taskbar configuration
    4747 * @return EOK on success or an error code
    4848 */
    49 errno_t tbarcfg_create(const char *repopath, tbarcfg_t **rtbcfg)
     49errno_t tbarcfg_open(const char *repopath, tbarcfg_t **rtbcfg)
    5050{
    5151        tbarcfg_t *tbcfg;
    5252        sif_sess_t *repo = NULL;
    5353        sif_node_t *rnode;
    54         errno_t rc;
    55         sif_trans_t *trans = NULL;
    56 
    57         tbcfg = calloc(1, sizeof(tbarcfg_t));
    58         if (tbcfg == NULL) {
    59                 rc = ENOMEM;
    60                 goto error;
    61         }
    62 
    63         list_initialize(&tbcfg->entries);
    64 
    65         rc = sif_create(repopath, &repo);
    66         if (rc != EOK)
    67                 goto error;
    68 
    69         tbcfg->repo = repo;
    70 
    71         rnode = sif_get_root(repo);
    72 
    73         rc = sif_trans_begin(repo, &trans);
    74         if (rc != EOK)
    75                 goto error;
    76 
    77         rc = sif_node_append_child(trans, rnode, "entries", &tbcfg->nentries);
    78         if (rc != EOK)
    79                 goto error;
    80 
    81         rc = sif_trans_end(trans);
    82         if (rc != EOK)
    83                 goto error;
    84 
    85         *rtbcfg = tbcfg;
    86         return EOK;
    87 error:
    88         if (trans != NULL)
    89                 sif_trans_abort(trans);
    90         if (repo != NULL)
    91                 sif_close(repo);
    92         if (tbcfg != NULL)
    93                 free(tbcfg);
    94         return rc;
    95 }
    96 
    97 /** Open taskbar configuration.
    98  *
    99  * @param repopath Pathname of the menu repository
    100  * @param rtbcfg Place to store pointer to taskbar configuration
    101  * @return EOK on success or an error code
    102  */
    103 errno_t tbarcfg_open(const char *repopath, tbarcfg_t **rtbcfg)
    104 {
    105         tbarcfg_t *tbcfg;
    106         sif_sess_t *repo = NULL;
    107         sif_node_t *rnode;
     54        sif_node_t *nentries;
    10855        sif_node_t *nentry;
    10956        const char *ntype;
     
    12774
    12875        rnode = sif_get_root(repo);
    129         tbcfg->nentries = sif_node_first_child(rnode);
    130         ntype = sif_node_get_type(tbcfg->nentries);
     76        nentries = sif_node_first_child(rnode);
     77        ntype = sif_node_get_type(nentries);
    13178        if (str_cmp(ntype, "entries") != 0) {
    13279                rc = EIO;
     
    13481        }
    13582
    136         nentry = sif_node_first_child(tbcfg->nentries);
     83        nentry = sif_node_first_child(nentries);
    13784        while (nentry != NULL) {
    13885                ntype = sif_node_get_type(nentry);
     
    154101                }
    155102
    156                 rc = smenu_entry_new(tbcfg, nentry, caption, cmd);
     103                rc = smenu_entry_create(tbcfg, nentry, caption, cmd);
    157104                if (rc != EOK)
    158105                        goto error;
     
    177124void tbarcfg_close(tbarcfg_t *tbcfg)
    178125{
    179         smenu_entry_t *entry;
    180 
    181         entry = tbarcfg_smenu_first(tbcfg);
    182         while (entry != NULL) {
    183                 smenu_entry_delete(entry);
    184                 entry = tbarcfg_smenu_first(tbcfg);
    185         }
    186 
    187126        (void)sif_close(tbcfg->repo);
    188         free(tbcfg);
    189127}
    190128
     
    291229errno_t smenu_entry_save(smenu_entry_t *entry)
    292230{
    293         sif_trans_t *trans = NULL;
     231        sif_trans_t *trans;
    294232        errno_t rc;
    295233
     
    317255}
    318256
    319 /** Allocate a start menu entry and append it to the start menu (internal).
     257/** Create a start menu entry and append it to the start menu (internal).
    320258 *
    321259 * This only creates the entry in memory, but does not update the repository.
     
    326264 * @param cmd Command to run
    327265 */
    328 errno_t smenu_entry_new(tbarcfg_t *smenu, sif_node_t *nentry,
     266errno_t smenu_entry_create(tbarcfg_t *smenu, sif_node_t *nentry,
    329267    const char *caption, const char *cmd)
    330268{
     
    367305}
    368306
    369 /** Delete start menu entry.
    370  *
    371  * This only deletes the entry from, but does not update the
    372  * repository.
    373  *
    374  * @param entry Start menu entry
    375  */
    376 void smenu_entry_delete(smenu_entry_t *entry)
    377 {
    378         list_remove(&entry->lentries);
    379         free(entry->caption);
    380         free(entry->cmd);
    381         free(entry);
    382 }
    383 
    384 /** Create new start menu entry.
    385  *
    386  * @param smenu Start menu
    387  * @param nentry Backing SIF node
    388  * @param caption Caption
    389  * @param cmd Command to run
    390  */
    391 errno_t smenu_entry_create(tbarcfg_t *smenu, const char *caption,
    392     const char *cmd)
    393 {
    394         sif_node_t *nentry;
    395         errno_t rc;
    396         sif_trans_t *trans = NULL;
    397 
    398         rc = sif_trans_begin(smenu->repo, &trans);
    399         if (rc != EOK)
    400                 goto error;
    401 
    402         rc = sif_node_append_child(trans, smenu->nentries, "entry",
    403             &nentry);
    404         if (rc != EOK)
    405                 goto error;
    406 
    407         rc = smenu_entry_new(smenu, nentry, caption, cmd);
    408         if (rc != EOK)
    409                 goto error;
    410 
    411         rc = sif_trans_end(trans);
    412         if (rc != EOK)
    413                 goto error;
    414 
    415         return EOK;
    416 error:
    417         if (trans != NULL)
    418                 sif_trans_abort(trans);
    419         return rc;
    420 }
    421 
    422 /** Destroy start menu entry..
    423  *
    424  * @param entry Start menu entry
    425  * @return EOK on success or an error code
    426  */
    427 errno_t smenu_entry_destroy(smenu_entry_t *entry)
    428 {
    429         errno_t rc;
    430         sif_trans_t *trans = NULL;
    431 
    432         rc = sif_trans_begin(entry->smenu->repo, &trans);
    433         if (rc != EOK)
    434                 goto error;
    435 
    436         sif_node_destroy(trans, entry->nentry);
    437 
    438         rc = sif_trans_end(trans);
    439         if (rc != EOK)
    440                 goto error;
    441 
    442         smenu_entry_delete(entry);
    443 error:
    444         if (trans != NULL)
    445                 sif_trans_abort(trans);
    446         return rc;
    447 }
    448 
    449307/** @}
    450308 */
Note: See TracChangeset for help on using the changeset viewer.