217
219
unity_webapps_application_info_canonicalize_string (const gchar *str)
219
gchar *canonicalized, **components;
221
canonicalized = g_strdup (str);
222
g_strcanon (canonicalized, UNITY_WEBAPPS_APPLICATION_INFO_VALID_CANONICAL_NAME_CHARACTERS, '%');
224
components = g_strsplit (canonicalized, "%", 0);
226
g_free (canonicalized);
228
canonicalized = g_strjoinv (NULL, components);
230
g_strfreev (components);
221
gchar *it, *canonicalized;
222
GString *res = g_string_sized_new (strlen (str));
224
for (it = (gchar*)str; *it; it = g_utf8_next_char (it))
226
gunichar chr = g_utf8_get_char (it);
227
if (g_unichar_isalnum (chr) || g_unichar_isspace (chr))
228
res = g_string_append_c (res, chr);
230
canonicalized = res->str;
231
g_string_free (res, FALSE);
232
233
return canonicalized;
312
validate_mime_str (const gchar *in)
314
gchar *out = NULL, **it;
319
gchar **mimes = g_strsplit (in, ";", -1);
320
GList *registered = g_content_types_get_registered ();
322
for (it = mimes; it && *it; it++)
324
if (g_list_find_custom (registered, *it, (GCompareFunc)g_strcmp0))
326
gchar *tmp = g_strconcat (*it, ";", out, NULL);
331
g_list_free_full (registered, g_free);
311
338
unity_webapps_application_info_get_desktop_file_contents (UnityWebappsApplicationInfo *info)
313
gchar *contents, *icon_name;
341
gchar **labels, **pages, **il, **ip;
342
gchar *contents, *icon_name, *mime_types;
343
gchar *name = unity_webapps_application_info_canonicalize_string (info->priv->name);
344
gchar *base64_name = g_base64_encode ((guchar*)info->priv->name, strlen (info->priv->name) + 1);
315
346
icon_name = unity_webapps_application_info_get_desktop_icon_name (info, TRUE);
317
contents = g_strdup_printf("[Desktop Entry]\nName=%s\nType=Application\nIcon=%s\nMimeType=%s\nExec=unity-webapps-runner -n '%s' -d '%s' %%u", info->priv->name, icon_name, info->priv->mime_types, info->priv->name, info->priv->domain);
348
mime_types = validate_mime_str (info->priv->mime_types);
350
mime_types = g_strdup ("");
352
contents = g_strdup_printf ("[Desktop Entry]\nName=%s\nType=Application\nIcon=%s\nMimeType=%s\nActions=S0;S1;S2;S3;S4;S5;S6;S7;S8;S9;S10;\nExec=unity-webapps-runner -n '%s' -d '%s' %%u",
353
name, icon_name, mime_types,
354
base64_name, info->priv->domain);
356
unity_webapps_app_db_get_actions (info->priv->name, info->priv->domain, &labels, &pages);
358
for (i = 0, il = labels, ip = pages; il && *il; il++, i++, ip++)
360
gchar *label = unity_webapps_application_info_canonicalize_string (*il);
364
SoupURI *uri = soup_uri_new (*ip);
370
gchar *page = soup_uri_to_string (uri, FALSE);
373
gchar *tmp = g_strdup_printf ("%s\n[Desktop Action S%d]\nName=%s\nOnlyShowIn=Unity;\nExec=xdg-open '%s'\n",
374
contents, i, label, page);
319
381
g_free (icon_name);
383
g_free (base64_name);