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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2014-2016 Richard Hughes <richard@hughsie.com>
*
* SPDX-License-Identifier: LGPL-2.1+
*/
/**
* 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"
#include "as-app.h"
#include "as-ref-string.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* 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)
{
return as_app_kind_to_string (id_kind);
}
/**
* 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)
{
return as_app_kind_from_string (id_kind);
}
G_GNUC_END_IGNORE_DEPRECATIONS
/**
* 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 as_ref_string_new_static ("homepage");
if (url_kind == AS_URL_KIND_BUGTRACKER)
return as_ref_string_new_static ("bugtracker");
if (url_kind == AS_URL_KIND_FAQ)
return as_ref_string_new_static ("faq");
if (url_kind == AS_URL_KIND_DONATION)
return as_ref_string_new_static ("donation");
if (url_kind == AS_URL_KIND_HELP)
return as_ref_string_new_static ("help");
if (url_kind == AS_URL_KIND_MISSING)
return as_ref_string_new_static ("missing");
if (url_kind == AS_URL_KIND_TRANSLATE)
return as_ref_string_new_static ("translate");
if (url_kind == AS_URL_KIND_DETAILS)
return as_ref_string_new_static ("details");
if (url_kind == AS_URL_KIND_SOURCE)
return as_ref_string_new_static ("source");
if (url_kind == AS_URL_KIND_CONTACT)
return as_ref_string_new_static ("contact");
return as_ref_string_new_static ("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;
if (g_strcmp0 (url_kind, "translate") == 0)
return AS_URL_KIND_TRANSLATE;
if (g_strcmp0 (url_kind, "details") == 0)
return AS_URL_KIND_DETAILS;
if (g_strcmp0 (url_kind, "source") == 0)
return AS_URL_KIND_SOURCE;
if (g_strcmp0 (url_kind, "contact") == 0)
return AS_URL_KIND_CONTACT;
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 as_ref_string_new_static ("SearchProvider");
if (kudo_kind == AS_KUDO_KIND_USER_DOCS)
return as_ref_string_new_static ("UserDocs");
if (kudo_kind == AS_KUDO_KIND_APP_MENU)
return as_ref_string_new_static ("AppMenu");
if (kudo_kind == AS_KUDO_KIND_MODERN_TOOLKIT)
return as_ref_string_new_static ("ModernToolkit");
if (kudo_kind == AS_KUDO_KIND_NOTIFICATIONS)
return as_ref_string_new_static ("Notifications");
if (kudo_kind == AS_KUDO_KIND_HIGH_CONTRAST)
return as_ref_string_new_static ("HighContrast");
if (kudo_kind == AS_KUDO_KIND_HI_DPI_ICON)
return as_ref_string_new_static ("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;
}
/**
* as_size_kind_to_string:
* @size_kind: the #AsSizeKind.
*
* Converts the enumerated value to an text representation.
*
* Returns: string version of @size_kind
*
* Since: 0.5.2
**/
const gchar *
as_size_kind_to_string (AsSizeKind size_kind)
{
if (size_kind == AS_SIZE_KIND_INSTALLED)
return as_ref_string_new_static ("installed");
if (size_kind == AS_SIZE_KIND_DOWNLOAD)
return as_ref_string_new_static ("download");
return as_ref_string_new_static ("unknown");
}
/**
* as_size_kind_from_string:
* @size_kind: the string.
*
* Converts the text representation to an enumerated value.
*
* Returns: a #AsSizeKind or %AS_SIZE_KIND_UNKNOWN for unknown
*
* Since: 0.5.2
**/
AsSizeKind
as_size_kind_from_string (const gchar *size_kind)
{
if (g_strcmp0 (size_kind, "installed") == 0)
return AS_SIZE_KIND_INSTALLED;
if (g_strcmp0 (size_kind, "download") == 0)
return AS_SIZE_KIND_DOWNLOAD;
return AS_SIZE_KIND_UNKNOWN;
}
/**
* as_urgency_kind_to_string:
* @urgency_kind: the #AsUrgencyKind.
*
* Converts the enumerated value to an text representation.
*
* Returns: string version of @urgency_kind
*
* Since: 0.5.1
**/
const gchar *
as_urgency_kind_to_string (AsUrgencyKind urgency_kind)
{
if (urgency_kind == AS_URGENCY_KIND_LOW)
return as_ref_string_new_static ("low");
if (urgency_kind == AS_URGENCY_KIND_MEDIUM)
return as_ref_string_new_static ("medium");
if (urgency_kind == AS_URGENCY_KIND_HIGH)
return as_ref_string_new_static ("high");
if (urgency_kind == AS_URGENCY_KIND_CRITICAL)
return as_ref_string_new_static ("critical");
return as_ref_string_new_static ("unknown");
}
/**
* as_urgency_kind_from_string:
* @urgency_kind: the string.
*
* Converts the text representation to an enumerated value.
*
* Returns: a #AsUrgencyKind or %AS_URGENCY_KIND_UNKNOWN for unknown
*
* Since: 0.5.1
**/
AsUrgencyKind
as_urgency_kind_from_string (const gchar *urgency_kind)
{
if (g_strcmp0 (urgency_kind, "low") == 0)
return AS_URGENCY_KIND_LOW;
if (g_strcmp0 (urgency_kind, "medium") == 0)
return AS_URGENCY_KIND_MEDIUM;
if (g_strcmp0 (urgency_kind, "high") == 0)
return AS_URGENCY_KIND_HIGH;
if (g_strcmp0 (urgency_kind, "critical") == 0)
return AS_URGENCY_KIND_CRITICAL;
return AS_URGENCY_KIND_UNKNOWN;
}
|