]> git.sur5r.net Git - glabels/blob - libglabels/category.c
Imported Upstream version 2.2.8
[glabels] / libglabels / category.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
3 /*
4  *  (LIBGLABELS) Template library for GLABELS
5  *
6  *  category.c:  template category module
7  *
8  *  Copyright (C) 2001-2006  Jim Evins <evins@snaught.com>.
9  *
10  *  This file is part of the LIBGLABELS library.
11  *
12  *  This library is free software; you can redistribute it and/or
13  *  modify it under the terms of the GNU Library General Public
14  *  License as published by the Free Software Foundation; either
15  *  version 2 of the License, or (at your option) any later version.
16  *
17  *  This library is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  *  Library General Public License for more details.
21  *
22  *  You should have received a copy of the GNU Library General Public
23  *  License along with this library; if not, write to the Free
24  *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25  *  MA 02111-1307, USA
26  */
27 #include <config.h>
28
29 #include "category.h"
30
31 #include <glib/gi18n.h>
32 #include <glib/gmem.h>
33 #include <glib/gstrfuncs.h>
34 #include <glib/gmessages.h>
35 #include <string.h>
36
37 #include "libglabels-private.h"
38
39 /*===========================================*/
40 /* Private types                             */
41 /*===========================================*/
42
43
44 /*===========================================*/
45 /* Private globals                           */
46 /*===========================================*/
47
48
49 /*===========================================*/
50 /* Local function prototypes                 */
51 /*===========================================*/
52
53
54 /*===========================================*/
55 /* Functions.                                */
56 /*===========================================*/
57 /**
58  * lgl_category_new:
59  * @id:     Id of category definition. (E.g. label, card, etc.)  Should be
60  *          unique.
61  * @name:   Localized name of category.
62  *
63  * Allocates and constructs a new #lglCategory structure.
64  *
65  * Returns: a pointer to a newly allocated #lglCategory structure.
66  *
67  */
68 lglCategory *
69 lgl_category_new (gchar             *id,
70                   gchar             *name)
71 {
72         lglCategory *category;
73
74         category         = g_new0 (lglCategory,1);
75         category->id     = g_strdup (id);
76         category->name   = g_strdup (name);
77
78         return category;
79 }
80
81
82 /**
83  * lgl_category_dup:
84  * @orig:  #lglCategory structure to be duplicated.
85  *
86  * Duplicates an existing #lglCategory structure.
87  *
88  * Returns: a pointer to a newly allocated #lglCategory structure.
89  *
90  */
91 lglCategory *lgl_category_dup (const lglCategory *orig)
92 {
93         lglCategory       *category;
94
95         g_return_val_if_fail (orig, NULL);
96
97         category = g_new0 (lglCategory,1);
98
99         category->id     = g_strdup (orig->id);
100         category->name   = g_strdup (orig->name);
101
102         return category;
103 }
104
105
106 /**
107  * lgl_category_free:
108  * @category:  pointer to #lglCategory structure to be freed.
109  *
110  * Free all memory associated with an existing #lglCategory structure.
111  *
112  */
113 void lgl_category_free (lglCategory *category)
114 {
115
116         if ( category != NULL ) {
117
118                 g_free (category->id);
119                 category->id = NULL;
120
121                 g_free (category->name);
122                 category->name = NULL;
123
124                 g_free (category);
125         }
126
127 }
128
129