1 /*
2  * Copyright (C) 2014 Michal Ratajsky <michal.ratajsky@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the licence, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "matemixer-app-info.h"
19 #include "matemixer-app-info-private.h"
20 
21 /**
22  * SECTION:matemixer-app-info
23  * @short_description: Application information
24  * @include: libmatemixer/matemixer.h
25  * @see_also: #MateMixerStreamControl
26  *
27  * The #MateMixerAppInfo structure describes application properties.
28  *
29  * See #MateMixerStreamControl and the mate_mixer_stream_control_get_app_info()
30  * function for more information.
31  */
32 
33 /**
34  * MateMixerAppInfo:
35  *
36  * The #MateMixerAppInfo structure contains only private data and should only
37  * be accessed using the provided API.
38  */
G_DEFINE_BOXED_TYPE(MateMixerAppInfo,mate_mixer_app_info,_mate_mixer_app_info_copy,_mate_mixer_app_info_free)39 G_DEFINE_BOXED_TYPE (MateMixerAppInfo, mate_mixer_app_info,
40                      _mate_mixer_app_info_copy,
41                      _mate_mixer_app_info_free)
42 
43 /**
44  * mate_mixer_app_info_get_name:
45  * @info: a #MateMixerAppInfo
46  *
47  * Gets the name of the application described by @info.
48  *
49  * Returns: name of the application or %NULL if it is unknown.
50  */
51 const gchar *
52 mate_mixer_app_info_get_name (MateMixerAppInfo *info)
53 {
54     g_return_val_if_fail (info != NULL, NULL);
55 
56     return info->name;
57 }
58 
59 /**
60  * mate_mixer_app_info_get_id:
61  * @info: a #MateMixerAppInfo
62  *
63  * Gets the identifier of the application described by @info
64  * (e.g. org.example.app).
65  *
66  * Returns: identifier of the application or %NULL if it is unknown.
67  */
68 const gchar *
mate_mixer_app_info_get_id(MateMixerAppInfo * info)69 mate_mixer_app_info_get_id (MateMixerAppInfo *info)
70 {
71     g_return_val_if_fail (info != NULL, NULL);
72 
73     return info->id;
74 }
75 
76 /**
77  * mate_mixer_app_info_get_version:
78  * @info: a #MateMixerAppInfo
79  *
80  * Gets the version of the application described by @info.
81  *
82  * Returns: version of the application or %NULL if it is unknown.
83  */
84 const gchar *
mate_mixer_app_info_get_version(MateMixerAppInfo * info)85 mate_mixer_app_info_get_version (MateMixerAppInfo *info)
86 {
87     g_return_val_if_fail (info != NULL, NULL);
88 
89     return info->version;
90 }
91 
92 /**
93  * mate_mixer_app_info_get_icon:
94  * @info: a #MateMixerAppInfo
95  *
96  * Gets the XDG icon name of the application described by @info.
97  *
98  * Returns: icon name of the application or %NULL if it is unknown.
99  */
100 const gchar *
mate_mixer_app_info_get_icon(MateMixerAppInfo * info)101 mate_mixer_app_info_get_icon (MateMixerAppInfo *info)
102 {
103     g_return_val_if_fail (info != NULL, NULL);
104 
105     return info->icon;
106 }
107 
108 /**
109  * _mate_mixer_app_info_new:
110  *
111  * Creates a new empty #MateMixerAppInfo structure.
112  *
113  * Returns: a new #MateMixerAppInfo.
114  */
115 MateMixerAppInfo *
_mate_mixer_app_info_new(void)116 _mate_mixer_app_info_new (void)
117 {
118     return g_slice_new0 (MateMixerAppInfo);
119 }
120 
121 /**
122  * _mate_mixer_app_info_set_name:
123  * @info: a #MateMixerAppInfo
124  * @name: the application name to set
125  *
126  * Sets the name of the application described by @info.
127  */
128 void
_mate_mixer_app_info_set_name(MateMixerAppInfo * info,const gchar * name)129 _mate_mixer_app_info_set_name (MateMixerAppInfo *info, const gchar *name)
130 {
131     g_return_if_fail (info != NULL);
132 
133     g_free (info->name);
134 
135     info->name = g_strdup (name);
136 }
137 
138 /**
139  * _mate_mixer_app_info_set_id:
140  * @info: a #MateMixerAppInfo
141  * @id: the application identifier to set
142  *
143  * Sets the identifier of the application described by @info.
144  */
145 void
_mate_mixer_app_info_set_id(MateMixerAppInfo * info,const gchar * id)146 _mate_mixer_app_info_set_id (MateMixerAppInfo *info, const gchar *id)
147 {
148     g_return_if_fail (info != NULL);
149 
150     g_free (info->id);
151 
152     info->id = g_strdup (id);
153 }
154 
155 /**
156  * _mate_mixer_app_info_set_version:
157  * @info: a #MateMixerAppInfo
158  * @version: the application version to set
159  *
160  * Sets the version of the application described by @info.
161  */
162 void
_mate_mixer_app_info_set_version(MateMixerAppInfo * info,const gchar * version)163 _mate_mixer_app_info_set_version (MateMixerAppInfo *info, const gchar *version)
164 {
165     g_return_if_fail (info != NULL);
166 
167     g_free (info->version);
168 
169     info->version = g_strdup (version);
170 }
171 
172 /**
173  * _mate_mixer_app_info_set_version:
174  * @info: a #MateMixerAppInfo
175  * @icon: the application icon name to set
176  *
177  * Sets the XDG icon name of the application described by @info.
178  */
179 void
_mate_mixer_app_info_set_icon(MateMixerAppInfo * info,const gchar * icon)180 _mate_mixer_app_info_set_icon (MateMixerAppInfo *info, const gchar *icon)
181 {
182     g_return_if_fail (info != NULL);
183 
184     g_free (info->icon);
185 
186     info->icon = g_strdup (icon);
187 }
188 
189 /**
190  * _mate_mixer_app_info_copy:
191  * @info: a #MateMixerAppInfo
192  *
193  * Creates a copy of the #MateMixerAppInfo.
194  *
195  * Returns: a copy of the given @info.
196  */
197 MateMixerAppInfo *
_mate_mixer_app_info_copy(MateMixerAppInfo * info)198 _mate_mixer_app_info_copy (MateMixerAppInfo *info)
199 {
200     MateMixerAppInfo *info2;
201 
202     g_return_val_if_fail (info != NULL, NULL);
203 
204     info2 = _mate_mixer_app_info_new ();
205     info2->name     = g_strdup (info->name);
206     info2->id       = g_strdup (info->id);
207     info2->version  = g_strdup (info->version);
208     info2->icon     = g_strdup (info->icon);
209 
210     return info2;
211 }
212 
213 /**
214  * _mate_mixer_app_info_free:
215  * @info: a #MateMixerAppInfo
216  *
217  * Frees the #MateMixerAppInfo.
218  */
219 void
_mate_mixer_app_info_free(MateMixerAppInfo * info)220 _mate_mixer_app_info_free (MateMixerAppInfo *info)
221 {
222     g_return_if_fail (info != NULL);
223 
224     g_free (info->name);
225     g_free (info->id);
226     g_free (info->version);
227     g_free (info->icon);
228 
229     g_slice_free (MateMixerAppInfo, info);
230 }
231