summaryrefslogtreecommitdiff
path: root/libappstream-glib/as-enums.c
blob: e0bb12898075557025b5c3e18c4a6e560c0706fa (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 * Copyright (C) 2014 Richard Hughes <richard@hughsie.com>
 *
 * Licensed under the GNU Lesser General Public License Version 2.1
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 */

/**
 * SECTION:as-enums
 * @short_description: Helper functions for converting to and from enum strings
 * @include: appstream-glib.h
 * @stability: Stable
 *
 * These helper functions may be useful if implementing an AppStream parser.
 */

#include "config.h"

#include "as-enums.h"

/**
 * as_id_kind_to_string:
 * @id_kind: the #AsIdKind.
 *
 * Converts the enumerated value to an text representation.
 *
 * Returns: string version of @id_kind
 *
 * Since: 0.1.0
 **/
const gchar *
as_id_kind_to_string (AsIdKind id_kind)
{
	if (id_kind == AS_ID_KIND_DESKTOP)
		return "desktop";
	if (id_kind == AS_ID_KIND_CODEC)
		return "codec";
	if (id_kind == AS_ID_KIND_FONT)
		return "font";
	if (id_kind == AS_ID_KIND_INPUT_METHOD)
		return "inputmethod";
	if (id_kind == AS_ID_KIND_WEB_APP)
		return "webapp";
	if (id_kind == AS_ID_KIND_SOURCE)
		return "source";
	if (id_kind == AS_ID_KIND_ADDON)
		return "addon";
	if (id_kind == AS_ID_KIND_FIRMWARE)
		return "firmware";
	return "unknown";
}

/**
 * as_id_kind_from_string:
 * @id_kind: the string.
 *
 * Converts the text representation to an enumerated value.
 *
 * Returns: a #AsIdKind or %AS_ID_KIND_UNKNOWN for unknown
 *
 * Since: 0.1.0
 **/
AsIdKind
as_id_kind_from_string (const gchar *id_kind)
{
	if (g_strcmp0 (id_kind, "desktop") == 0)
		return AS_ID_KIND_DESKTOP;
	if (g_strcmp0 (id_kind, "codec") == 0)
		return AS_ID_KIND_CODEC;
	if (g_strcmp0 (id_kind, "font") == 0)
		return AS_ID_KIND_FONT;
	if (g_strcmp0 (id_kind, "inputmethod") == 0)
		return AS_ID_KIND_INPUT_METHOD;
	if (g_strcmp0 (id_kind, "webapp") == 0)
		return AS_ID_KIND_WEB_APP;
	if (g_strcmp0 (id_kind, "source") == 0)
		return AS_ID_KIND_SOURCE;
	if (g_strcmp0 (id_kind, "addon") == 0)
		return AS_ID_KIND_ADDON;
	if (g_strcmp0 (id_kind, "firmware") == 0)
		return AS_ID_KIND_FIRMWARE;
	return AS_ID_KIND_UNKNOWN;
}

/**
 * as_url_kind_to_string:
 * @url_kind: the @AsUrlKind.
 *
 * Converts the enumerated value to an text representation.
 *
 * Returns: string version of @url_kind
 *
 * Since: 0.1.0
 **/
const gchar *
as_url_kind_to_string (AsUrlKind url_kind)
{
	if (url_kind == AS_URL_KIND_HOMEPAGE)
		return "homepage";
	if (url_kind == AS_URL_KIND_BUGTRACKER)
		return "bugtracker";
	if (url_kind == AS_URL_KIND_FAQ)
		return "faq";
	if (url_kind == AS_URL_KIND_DONATION)
		return "donation";
	if (url_kind == AS_URL_KIND_HELP)
		return "help";
	if (url_kind == AS_URL_KIND_MISSING)
		return "missing";
	return "unknown";
}

/**
 * as_url_kind_from_string:
 * @url_kind: the string.
 *
 * Converts the text representation to an enumerated value.
 *
 * Returns: a #AsUrlKind or %AS_URL_KIND_UNKNOWN for unknown
 *
 * Since: 0.1.0
 **/
AsUrlKind
as_url_kind_from_string (const gchar *url_kind)
{
	if (g_strcmp0 (url_kind, "homepage") == 0)
		return AS_URL_KIND_HOMEPAGE;
	if (g_strcmp0 (url_kind, "bugtracker") == 0)
		return AS_URL_KIND_BUGTRACKER;
	if (g_strcmp0 (url_kind, "faq") == 0)
		return AS_URL_KIND_FAQ;
	if (g_strcmp0 (url_kind, "donation") == 0)
		return AS_URL_KIND_DONATION;
	if (g_strcmp0 (url_kind, "help") == 0)
		return AS_URL_KIND_HELP;
	if (g_strcmp0 (url_kind, "missing") == 0)
		return AS_URL_KIND_MISSING;
	return AS_URL_KIND_UNKNOWN;
}

/**
 * as_kudo_kind_to_string:
 * @kudo_kind: the @AsKudoKind.
 *
 * Converts the enumerated value to an text representation.
 *
 * Returns: string version of @kudo_kind
 *
 * Since: 0.2.2
 **/
const gchar *
as_kudo_kind_to_string (AsKudoKind kudo_kind)
{
	if (kudo_kind == AS_KUDO_KIND_SEARCH_PROVIDER)
		return "SearchProvider";
	if (kudo_kind == AS_KUDO_KIND_USER_DOCS)
		return "UserDocs";
	if (kudo_kind == AS_KUDO_KIND_APP_MENU)
		return "AppMenu";
	if (kudo_kind == AS_KUDO_KIND_MODERN_TOOLKIT)
		return "ModernToolkit";
	if (kudo_kind == AS_KUDO_KIND_NOTIFICATIONS)
		return "Notifications";
	if (kudo_kind == AS_KUDO_KIND_HIGH_CONTRAST)
		return "HighContrast";
	if (kudo_kind == AS_KUDO_KIND_HI_DPI_ICON)
		return "HiDpiIcon";
	return NULL;
}

/**
 * as_kudo_kind_from_string:
 * @kudo_kind: the string.
 *
 * Converts the text representation to an enumerated value.
 *
 * Returns: a #AsKudoKind or %AS_KUDO_KIND_UNKNOWN for unknown
 *
 * Since: 0.2.2
 **/
AsKudoKind
as_kudo_kind_from_string (const gchar *kudo_kind)
{
	if (g_strcmp0 (kudo_kind, "SearchProvider") == 0)
		return AS_KUDO_KIND_SEARCH_PROVIDER;
	if (g_strcmp0 (kudo_kind, "UserDocs") == 0)
		return AS_KUDO_KIND_USER_DOCS;
	if (g_strcmp0 (kudo_kind, "AppMenu") == 0)
		return AS_KUDO_KIND_APP_MENU;
	if (g_strcmp0 (kudo_kind, "ModernToolkit") == 0)
		return AS_KUDO_KIND_MODERN_TOOLKIT;
	if (g_strcmp0 (kudo_kind, "Notifications") == 0)
		return AS_KUDO_KIND_NOTIFICATIONS;
	if (g_strcmp0 (kudo_kind, "HighContrast") == 0)
		return AS_KUDO_KIND_HIGH_CONTRAST;
	if (g_strcmp0 (kudo_kind, "HiDpiIcon") == 0)
		return AS_KUDO_KIND_HI_DPI_ICON;
	return AS_KUDO_KIND_UNKNOWN;
}