From ff0644ad76bf9134f47e61d7971b5b67b8f035fd Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Sat, 13 Jul 2019 15:59:15 -0300 Subject: [PATCH] utils: Add auxiliary function to format display names This will be used by the web source discoverer to format any URLs that contain a file name in their path. --- src/utils/gcal-utils.c | 23 +++++++++++++++++++++++ src/utils/gcal-utils.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/src/utils/gcal-utils.c b/src/utils/gcal-utils.c index 16dbe307..003a61f5 100644 --- a/src/utils/gcal-utils.c +++ b/src/utils/gcal-utils.c @@ -1240,3 +1240,26 @@ gcal_utils_launch_online_accounts_panel (GDBusConnection *connection, NULL, NULL); } + +gchar* +gcal_utils_format_filename_for_display (const gchar *filename) +{ + /* + * Foo_bar-something-cool.ics + */ + g_autofree gchar *display_name = NULL; + gchar *file_extension; + + display_name = g_strdup (filename); + + /* Strip out the file extension */ + file_extension = g_strrstr (display_name, "."); + if (file_extension) + *file_extension = '\0'; + + /* Replace underscores with spaces */ + display_name = g_strdelimit (display_name, "_", ' '); + display_name = g_strstrip (display_name); + + return g_steal_pointer (&display_name); +} diff --git a/src/utils/gcal-utils.h b/src/utils/gcal-utils.h index 9dd751e4..5d01e3b9 100644 --- a/src/utils/gcal-utils.h +++ b/src/utils/gcal-utils.h @@ -126,4 +126,6 @@ void gcal_utils_launch_online_accounts_panel (GDBusConnectio const gchar *action, const gchar *arg); +gchar* gcal_utils_format_filename_for_display (const gchar *filename); + #endif /* __GCAL_UTILS_H__ */