utils: Add Google extractor
Google events have an exotic section at the end of their event descriptions, we can parse that to find some information like the meeting URL.
This commit is contained in:
@@ -1279,3 +1279,53 @@ gcal_utils_format_filename_for_display (const gchar *filename)
|
||||
|
||||
return g_steal_pointer (&display_name);
|
||||
}
|
||||
|
||||
void
|
||||
gcal_utils_extract_google_section (const gchar *description,
|
||||
gchar **out_description,
|
||||
gchar **out_meeting_url)
|
||||
{
|
||||
g_autofree gchar *actual_description = NULL;
|
||||
g_autofree gchar *meeting_url = NULL;
|
||||
gssize description_len;
|
||||
gsize delimiter_len;
|
||||
gchar *first_delimiter;
|
||||
gchar *last_delimiter;
|
||||
|
||||
#define GOOGLE_DELIMITER "-::~:~::~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~::~:~::-"
|
||||
|
||||
description_len = strlen (description);
|
||||
first_delimiter = g_strstr_len (description, description_len, GOOGLE_DELIMITER);
|
||||
if (!first_delimiter)
|
||||
goto out;
|
||||
|
||||
delimiter_len = strlen (GOOGLE_DELIMITER);
|
||||
last_delimiter = g_strstr_len (first_delimiter + delimiter_len,
|
||||
description_len,
|
||||
GOOGLE_DELIMITER);
|
||||
if (!last_delimiter)
|
||||
goto out;
|
||||
|
||||
if (out_description)
|
||||
actual_description = g_utf8_substring (description, 0, first_delimiter - description);
|
||||
|
||||
if (out_meeting_url)
|
||||
{
|
||||
gchar *google_section_start;
|
||||
gchar *meet_url_start;
|
||||
|
||||
google_section_start = first_delimiter + delimiter_len;
|
||||
meet_url_start = g_strstr_len (google_section_start,
|
||||
first_delimiter - description - delimiter_len,
|
||||
"https://meet.google.com");
|
||||
if (meet_url_start)
|
||||
meeting_url = g_utf8_substring (meet_url_start, 0, strlen ("https://meet.google.com/xxx-xxx-xxx"));
|
||||
}
|
||||
|
||||
out:
|
||||
if (out_description)
|
||||
*out_description = actual_description ? g_steal_pointer (&actual_description) : g_strdup (description);
|
||||
|
||||
if (out_meeting_url)
|
||||
*out_meeting_url = g_steal_pointer (&meeting_url);
|
||||
}
|
||||
|
||||
@@ -131,4 +131,8 @@ void gcal_utils_launch_online_accounts_panel (GDBusConnectio
|
||||
|
||||
gchar* gcal_utils_format_filename_for_display (const gchar *filename);
|
||||
|
||||
void gcal_utils_extract_google_section (const gchar *description,
|
||||
gchar **out_description,
|
||||
gchar **out_meeting_url);
|
||||
|
||||
#endif /* __GCAL_UTILS_H__ */
|
||||
|
||||
Reference in New Issue
Block a user