summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Kareh <[email protected]>2025-09-22 22:23:09 +0000
committerGitHub <[email protected]>2025-09-22 22:23:09 +0000
commitcf2f458dd8b70450c3fdffb10d4a45c8c369b3e9 (patch)
tree1bfd5fb81bf88684653315aaad11f37532ab4fa9
parentd68c23bd8e07612f305dcc7825f3a8ee448544f5 (diff)
downloadmate-panel-cf2f458dd8b70450c3fdffb10d4a45c8c369b3e9.tar.bz2
mate-panel-cf2f458dd8b70450c3fdffb10d4a45c8c369b3e9.tar.xz
clock: Store calendar client in ClockData (#1516)HEADmaster
* clock: Store calendar client in ClockData This simplifies the evolution calendar client architecture and makes the popup show up faster, since we don't need to create a new one every time we open it. * clock: Fix calendar data refresh when opening popup The calendar popup was not showing recently added Evolution events/tasks. Added a refresh timeout call every time the calendar popup opens. That way the popup opens immediately and the data is refresh after a small delay.
-rw-r--r--applets/clock/calendar-client.c9
-rw-r--r--applets/clock/calendar-client.h3
-rw-r--r--applets/clock/calendar-window.c107
-rw-r--r--applets/clock/calendar-window.h8
-rw-r--r--applets/clock/clock.c22
5 files changed, 94 insertions, 55 deletions
diff --git a/applets/clock/calendar-client.c b/applets/clock/calendar-client.c
index 8bd9a2f3..562234fd 100644
--- a/applets/clock/calendar-client.c
+++ b/applets/clock/calendar-client.c
@@ -116,11 +116,6 @@ static void calendar_client_start_query (CalendarClient *client,
static void calendar_client_source_finalize (CalendarClientSource *source);
static void calendar_client_query_finalize (CalendarClientQuery *query);
-static void
-calendar_client_update_appointments (CalendarClient *client);
-static void
-calendar_client_update_tasks (CalendarClient *client);
-
enum
{
PROP_O,
@@ -1420,7 +1415,7 @@ calendar_client_start_query (CalendarClient *client,
}
}
-static void
+void
calendar_client_update_appointments (CalendarClient *client)
{
GSList *l;
@@ -1458,7 +1453,7 @@ calendar_client_update_appointments (CalendarClient *client)
/* FIXME:
* perhaps we should use evo's "hide_completed_tasks" pref?
*/
-static void
+void
calendar_client_update_tasks (CalendarClient *client)
{
GSList *l;
diff --git a/applets/clock/calendar-client.h b/applets/clock/calendar-client.h
index 7747d23f..f74ac2c3 100644
--- a/applets/clock/calendar-client.h
+++ b/applets/clock/calendar-client.h
@@ -144,6 +144,9 @@ void calendar_client_set_task_completed (CalendarClient *cl
gboolean calendar_client_create_task (CalendarClient *client,
const char *summary);
+void calendar_client_update_appointments (CalendarClient *client);
+void calendar_client_update_tasks (CalendarClient *client);
+
void calendar_event_free (CalendarEvent *event);
G_END_DECLS
diff --git a/applets/clock/calendar-window.c b/applets/clock/calendar-window.c
index ae9f1d7c..9f794dce 100644
--- a/applets/clock/calendar-window.c
+++ b/applets/clock/calendar-window.c
@@ -447,10 +447,6 @@ calendar_window_fill (CalendarWindow *calwin)
calwin->priv->calendar = calendar_window_create_calendar (calwin);
gtk_widget_show (calwin->priv->calendar);
-#ifdef HAVE_EDS
- /* Calendar client will be initialized later in calendar_window_pack_pim */
-#endif
-
if (!calwin->priv->invert_order) {
gtk_box_pack_start (GTK_BOX (vbox),
calwin->priv->calendar, TRUE, FALSE, 0);
@@ -597,7 +593,8 @@ calendar_window_dispose (GObject *object)
calwin->priv->client_tasks_changed_id = 0;
}
g_signal_handlers_disconnect_by_data (calwin->priv->client, calwin);
- g_object_unref (calwin->priv->client);
+
+ /* Client is owned by ClockData, don't unref it */
calwin->priv->client = NULL;
}
#endif
@@ -714,12 +711,32 @@ calendar_window_new (time_t *static_current_time,
return GTK_WIDGET (calwin);
}
+#ifdef HAVE_EDS
+static void
+refresh_once (gpointer user_data)
+{
+ CalendarWindow *calwin = CALENDAR_WINDOW (user_data);
+ if (calwin->priv->client) {
+ calendar_client_update_appointments (calwin->priv->client);
+ calendar_client_update_tasks (calwin->priv->client);
+
+ handle_appointments_changed (calwin);
+ handle_tasks_changed (calwin);
+ }
+}
+#endif
+
void
calendar_window_refresh (CalendarWindow *calwin)
{
g_return_if_fail (CALENDAR_IS_WINDOW (calwin));
#ifdef HAVE_EDS
+ /* Reload evolution calendar data after a small delay to not slow down the UI */
+ if (calwin->priv->client) {
+ g_timeout_add_once (100, refresh_once, calwin);
+ }
+
if (calwin->priv->appointments_filter && calwin->priv->appointment_list)
gtk_tree_model_filter_refilter (calwin->priv->appointments_filter);
@@ -1137,30 +1154,22 @@ calendar_window_pack_pim (CalendarWindow *calwin,
return;
}
- /* Initialize calendar client if not already done */
- if (!calwin->priv->client && calwin->priv->settings) {
- calwin->priv->client = calendar_client_new (calwin->priv->settings);
-
- if (calwin->priv->client) {
- if (show_calendar_events) {
- calwin->priv->client_appointments_changed_id = g_signal_connect_swapped (calwin->priv->client,
- "appointments-changed",
- G_CALLBACK (handle_appointments_changed),
- calwin);
- }
- if (show_tasks) {
- calwin->priv->client_tasks_changed_id = g_signal_connect_swapped (calwin->priv->client,
- "tasks-changed",
- G_CALLBACK (handle_tasks_changed),
- calwin);
- }
+ /* Connect signals if client is available */
+ if (calwin->priv->client) {
+ if (show_calendar_events && calwin->priv->client_appointments_changed_id == 0) {
+ calwin->priv->client_appointments_changed_id = g_signal_connect_swapped (calwin->priv->client,
+ "appointments-changed",
+ G_CALLBACK (handle_appointments_changed),
+ calwin);
+ }
+ if (show_tasks && calwin->priv->client_tasks_changed_id == 0) {
+ calwin->priv->client_tasks_changed_id = g_signal_connect_swapped (calwin->priv->client,
+ "tasks-changed",
+ G_CALLBACK (handle_tasks_changed),
+ calwin);
}
}
- if (!calwin->priv->client) {
- g_warning ("Failed to create calendar client in calendar_window_pack_pim");
- return;
- }
/* Create and pack appointments list if enabled */
if (show_calendar_events) {
@@ -1187,28 +1196,6 @@ calendar_window_pack_pim (CalendarWindow *calwin,
calwin->priv->task_list,
TRUE, TRUE, 0);
}
-
- /* Initialize calendar client with current date now that client is ready */
- if (calwin->priv->client && calwin->priv->calendar) {
- guint year, month, day;
- gtk_calendar_get_date (GTK_CALENDAR (calwin->priv->calendar), &year, &month, &day);
- /* Set a flag to indicate we're initializing to prevent redundant calls */
- g_object_set_data (G_OBJECT (calwin), "initializing", GINT_TO_POINTER (1));
-
- calendar_client_select_month (calwin->priv->client, month, year);
- calendar_client_select_day (calwin->priv->client, day);
-
- /* Clear the initialization flag and trigger initial load */
- g_object_set_data (G_OBJECT (calwin), "initializing", GINT_TO_POINTER (0));
-
- /* Now trigger the initial appointments and tasks load */
- if (show_calendar_events) {
- handle_appointments_changed (calwin);
- }
- if (show_tasks) {
- handle_tasks_changed (calwin);
- }
- }
}
static gboolean
@@ -1742,4 +1729,28 @@ task_entry_activate_cb (GtkEntry *entry,
}
}
+void
+calendar_window_set_client (CalendarWindow *calwin, CalendarClient *client)
+{
+ g_return_if_fail (CALENDAR_IS_WINDOW (calwin));
+ calwin->priv->client = client;
+
+ /* If we have a client, initialize the calendar data */
+ if (client && calwin->priv->calendar) {
+ guint year, month, day;
+ gtk_calendar_get_date (GTK_CALENDAR (calwin->priv->calendar), &year, &month, &day);
+
+ calendar_client_select_month (calwin->priv->client, month, year);
+ calendar_client_select_day (calwin->priv->client, day);
+
+ /* Trigger initial data load if widgets exist */
+ if (calwin->priv->appointment_list) {
+ handle_appointments_changed (calwin);
+ }
+ if (calwin->priv->task_list) {
+ handle_tasks_changed (calwin);
+ }
+ }
+}
+
#endif /* HAVE_EDS */
diff --git a/applets/clock/calendar-window.h b/applets/clock/calendar-window.h
index e24fdfc3..226353ba 100644
--- a/applets/clock/calendar-window.h
+++ b/applets/clock/calendar-window.h
@@ -31,6 +31,10 @@
#include <gtk/gtk.h>
#include "clock-utils.h"
+#ifdef HAVE_EDS
+#include "calendar-client.h"
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -78,6 +82,10 @@ ClockFormat calendar_window_get_time_format (CalendarWindow *calwin);
void calendar_window_set_time_format (CalendarWindow *calwin,
ClockFormat time_format);
+#ifdef HAVE_EDS
+void calendar_window_set_client (CalendarWindow *calwin, CalendarClient *client);
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/applets/clock/clock.c b/applets/clock/clock.c
index cc5ea999..2e26b39f 100644
--- a/applets/clock/clock.c
+++ b/applets/clock/clock.c
@@ -211,6 +211,10 @@ struct _ClockData {
const gchar *weather_icon_name;
GDBusProxy *system_manager_proxy;
+
+#ifdef HAVE_EDS
+ CalendarClient *calendar_client;
+#endif
};
/* Used to count the number of clock instances. It's there to know when we
@@ -828,6 +832,13 @@ destroy_clock (GtkWidget * widget, ClockData *cd)
cd->builder = NULL;
}
+#ifdef HAVE_EDS
+ if (cd->calendar_client) {
+ g_object_unref (cd->calendar_client);
+ cd->calendar_client = NULL;
+ }
+#endif
+
g_free (cd);
}
@@ -887,6 +898,12 @@ create_calendar (ClockData *cd)
cd->settings);
g_free (prefs_path);
+#ifdef HAVE_EDS
+ if (cd->calendar_client) {
+ calendar_window_set_client (CALENDAR_WINDOW (window), cd->calendar_client);
+ }
+#endif
+
calendar_window_set_show_weeks (CALENDAR_WINDOW (window),
cd->showweek);
@@ -2763,6 +2780,11 @@ fill_clock_applet (MatePanelApplet *applet)
* hibernate). */
setup_monitor_for_resume (cd);
+#ifdef HAVE_EDS
+ /* Initialize persistent calendar client */
+ cd->calendar_client = calendar_client_new (cd->settings);
+#endif
+
return TRUE;
}