[gnome-calendar/gbsneto/event-preview-popover: 1/2] utils: Add Google extractor




commit 01ee4a2b49db66213122c0ffd6649b3fe20becb6
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Jun 25 15:07:19 2021 -0300

    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.

 src/utils/gcal-utils.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/utils/gcal-utils.h |  4 ++++
 2 files changed, 54 insertions(+)
---
diff --git a/src/utils/gcal-utils.c b/src/utils/gcal-utils.c
index 3bba164f..b1b76877 100644
--- a/src/utils/gcal-utils.c
+++ b/src/utils/gcal-utils.c
@@ -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);
+}
diff --git a/src/utils/gcal-utils.h b/src/utils/gcal-utils.h
index 78e9f9cb..d2d3631d 100644
--- a/src/utils/gcal-utils.h
+++ b/src/utils/gcal-utils.h
@@ -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__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]