summaryrefslogtreecommitdiff
path: root/src/trg-files-tree.c
blob: 1c93a8f4f2de47d4a92d4d3c0e9fe935770dc8fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * transmission-remote-gtk - A GTK RPC client to Transmission
 * Copyright (C) 2011  Alan Fitton

 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/* This is the stuff common between both files trees, built up before
 * populating the model.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdlib.h>
#include <string.h>

#include <glib.h>

#include "trg-files-tree.h"

void trg_files_tree_node_add_child(trg_files_tree_node* node, trg_files_tree_node* child)
{
  if (!node->childrenHash) {
    node->childrenHash = g_hash_table_new(g_str_hash, g_str_equal);
  }
  g_hash_table_insert(node->childrenHash, child->name, child);
  node->children = g_list_append(node->children, child);
}

void trg_files_tree_node_free(trg_files_tree_node * node)
{
    GList *li;

    for (li = node->children; li; li = g_list_next(li))
        trg_files_tree_node_free((trg_files_tree_node *) li->data);

    if (node->childrenHash)
      g_hash_table_destroy(node->childrenHash);
    
    g_list_free(node->children);
    g_free(node->name);
    g_free(node);
}