1 /*
2 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
3 * Copyright (C) 2019 Red Hat, Inc. (www.redhat.com)
4 *
5 * This library is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19 #include "evolution-data-server-config.h"
20
21 /**
22 * SECTION:e-cal-component-text
23 * @short_description: An ECalComponentText structure
24 * @include: libecal/libecal.h
25 *
26 * Contains functions to work with the #ECalComponentText structure.
27 **/
28
29 #include "e-cal-component-text.h"
30
31 G_DEFINE_BOXED_TYPE (ECalComponentText, e_cal_component_text, e_cal_component_text_copy, e_cal_component_text_free)
32
33 struct _ECalComponentText {
34 gchar *value;
35 gchar *altrep;
36 };
37
38 /**
39 * e_cal_component_text_new:
40 * @value: (nullable): description text
41 * @altrep: (nullable): alternate representation URI
42 *
43 * Creates a new #ECalComponentText describing text properties.
44 * The returned structure should be freed with e_cal_component_text_free(),
45 * when no longer needed.
46 *
47 * Returns: (transfer full): a newly allocated #ECalComponentText
48 *
49 * Since: 3.34
50 **/
51 ECalComponentText *
e_cal_component_text_new(const gchar * value,const gchar * altrep)52 e_cal_component_text_new (const gchar *value,
53 const gchar *altrep)
54 {
55 ECalComponentText *text;
56
57 text = g_slice_new0 (ECalComponentText);
58 text->value = g_strdup (value);
59 text->altrep = g_strdup (altrep);
60
61 return text;
62 }
63
64 /**
65 * e_cal_component_text_copy:
66 * @text: (not nullable): an #ECalComponentText to copy
67 *
68 * Returns: (transfer full): a newly allocated #ECalComponentText, copy of @text.
69 * The returned structure should be freed with e_cal_component_text_free(),
70 * when no longer needed.
71 *
72 * Since: 3.34
73 **/
74 ECalComponentText *
e_cal_component_text_copy(const ECalComponentText * text)75 e_cal_component_text_copy (const ECalComponentText *text)
76 {
77 g_return_val_if_fail (text != NULL, NULL);
78
79 return e_cal_component_text_new (text->value, text->altrep);
80 }
81
82 /**
83 * e_cal_component_text_free: (skip)
84 * @text: (type ECalComponentText) (nullable): an #ECalComponentText to free
85 *
86 * Free the @text, previously allocated by e_cal_component_text_new() or
87 * e_cal_component_text_copy().
88 *
89 * Since: 3.34
90 **/
91 void
e_cal_component_text_free(gpointer text)92 e_cal_component_text_free (gpointer text)
93 {
94 ECalComponentText *te = text;
95
96 if (te) {
97 g_free (te->value);
98 g_free (te->altrep);
99 g_slice_free (ECalComponentText, te);
100 }
101 }
102
103 /**
104 * e_cal_component_text_get_value:
105 * @text: an #ECalComponentText
106 *
107 * Returns: the description string of the @text
108 *
109 * Since: 3.34
110 **/
111 const gchar *
e_cal_component_text_get_value(const ECalComponentText * text)112 e_cal_component_text_get_value (const ECalComponentText *text)
113 {
114 g_return_val_if_fail (text != NULL, NULL);
115
116 return text->value;
117 }
118
119 /**
120 * e_cal_component_text_set_value:
121 * @text: an #ECalComponentText
122 * @value: (nullable): description string to set
123 *
124 * Set the @value as the description string of the @text.
125 *
126 * Since: 3.34
127 **/
128 void
e_cal_component_text_set_value(ECalComponentText * text,const gchar * value)129 e_cal_component_text_set_value (ECalComponentText *text,
130 const gchar *value)
131 {
132 g_return_if_fail (text != NULL);
133
134 if (g_strcmp0 (text->value, value) != 0) {
135 g_free (text->value);
136 text->value = g_strdup (value);
137 }
138 }
139
140 /**
141 * e_cal_component_text_get_altrep:
142 * @text: an #ECalComponentText
143 *
144 * Returns: the alternate representation URI of the @text
145 *
146 * Since: 3.34
147 **/
148 const gchar *
e_cal_component_text_get_altrep(const ECalComponentText * text)149 e_cal_component_text_get_altrep (const ECalComponentText *text)
150 {
151 g_return_val_if_fail (text != NULL, NULL);
152
153 return text->altrep;
154 }
155
156 /**
157 * e_cal_component_text_set_altrep:
158 * @text: an #ECalComponentText
159 * @altrep: (nullable): alternate representation URI to set
160 *
161 * Set the @altrep as the alternate representation URI of the @text.
162 *
163 * Since: 3.34
164 **/
165 void
e_cal_component_text_set_altrep(ECalComponentText * text,const gchar * altrep)166 e_cal_component_text_set_altrep (ECalComponentText *text,
167 const gchar *altrep)
168 {
169 g_return_if_fail (text != NULL);
170
171 if (g_strcmp0 (text->altrep, altrep) != 0) {
172 g_free (text->altrep);
173 text->altrep = g_strdup (altrep);
174 }
175 }
176