summaryrefslogtreecommitdiff
path: root/applets/clock/clock.c
diff options
context:
space:
mode:
Diffstat (limited to 'applets/clock/clock.c')
-rw-r--r--applets/clock/clock.c88
1 files changed, 82 insertions, 6 deletions
diff --git a/applets/clock/clock.c b/applets/clock/clock.c
index fee7edf2..2e26b39f 100644
--- a/applets/clock/clock.c
+++ b/applets/clock/clock.c
@@ -60,6 +60,11 @@
#include <gdk/gdkx.h>
#endif
+#ifndef HAVE_X11
+#include <gdk/gdkwayland.h>
+#define GDK_IS_X11_DISPLAY(object) !(G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_WAYLAND_DISPLAY))
+#endif
+
#include <libmateweather/mateweather-prefs.h>
#include <libmateweather/location-entry.h>
#include <libmateweather/timezone-menu.h>
@@ -89,6 +94,8 @@
#define KEY_CITIES "cities"
#define KEY_TEMPERATURE_UNIT "temperature-unit"
#define KEY_SPEED_UNIT "speed-unit"
+#define KEY_SHOW_CALENDAR_EVENTS "show-calendar-events"
+#define KEY_SHOW_TASKS "show-tasks"
/* For watching for when the system resumes from sleep mode (e.g. suspend)
* and updating the clock as soon as that happens. */
@@ -127,6 +134,7 @@ struct _ClockData {
GtkWidget *props;
GtkWidget *calendar_popup;
+ gboolean calendar_popup_destroying;
GtkWidget *clock_vbox;
GtkSizeGroup *clock_group;
@@ -203,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
@@ -788,9 +800,12 @@ destroy_clock (GtkWidget * widget, ClockData *cd)
gtk_widget_destroy (cd->props);
cd->props = NULL;
- if (cd->calendar_popup)
+ if (cd->calendar_popup && !cd->calendar_popup_destroying) {
+ cd->calendar_popup_destroying = TRUE;
gtk_widget_destroy (cd->calendar_popup);
+ }
cd->calendar_popup = NULL;
+ cd->calendar_popup_destroying = FALSE;
g_free (cd->timeformat);
@@ -817,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);
}
@@ -857,13 +879,31 @@ create_calendar (ClockData *cd)
{
GtkWidget *window;
char *prefs_path;
+ char *fallback_path = NULL;
prefs_path = mate_panel_applet_get_preferences_path (MATE_PANEL_APPLET (cd->applet));
+
+ /* Provide a fallback preferences path in case the applet doesn't
+ * provide one. This happens when running outside the actual panel,
+ * like in mate-panel-test-applets */
+ if (!prefs_path || !prefs_path[0]) {
+ fallback_path = g_strdup ("/org/mate/panel/applets/clock/");
+ g_free (prefs_path);
+ prefs_path = fallback_path;
+ }
+
window = calendar_window_new (&cd->current_time,
prefs_path,
- cd->orient == MATE_PANEL_APPLET_ORIENT_UP);
+ cd->orient == MATE_PANEL_APPLET_ORIENT_UP,
+ 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);
@@ -922,8 +962,8 @@ position_calendar_popup (ClockData *cd)
button_w = allocation.width;
button_h = allocation.height;
- screen = gtk_window_get_screen (GTK_WINDOW (cd->calendar_popup));
- display = gdk_screen_get_display (screen);
+ screen = gtk_widget_get_screen (GTK_WIDGET (cd->calendar_popup));
+ display = gtk_widget_get_display (GTK_WIDGET (cd->calendar_popup));
n = gdk_display_get_n_monitors (display);
for (i = 0; i < n; i++) {
@@ -1349,9 +1389,11 @@ static void
update_calendar_popup (ClockData *cd)
{
if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cd->panel_button))) {
- if (cd->calendar_popup) {
+ if (cd->calendar_popup && !cd->calendar_popup_destroying) {
+ cd->calendar_popup_destroying = TRUE;
gtk_widget_destroy (cd->calendar_popup);
cd->calendar_popup = NULL;
+ cd->calendar_popup_destroying = FALSE;
cd->cities_section = NULL;
cd->map_widget = NULL;
cd->clock_vbox = NULL;
@@ -1364,7 +1406,7 @@ update_calendar_popup (ClockData *cd)
return;
}
- if (!cd->calendar_popup) {
+ if (!cd->calendar_popup && !cd->calendar_popup_destroying) {
cd->calendar_popup = create_calendar (cd);
g_object_add_weak_pointer (G_OBJECT (cd->calendar_popup),
(gpointer *) &cd->calendar_popup);
@@ -2738,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;
}
@@ -3287,6 +3334,35 @@ fill_prefs_window (ClockData *cd)
g_settings_bind (cd->settings, KEY_SHOW_TEMPERATURE, widget, "active",
G_SETTINGS_BIND_DEFAULT);
+#ifdef HAVE_EDS
+ /* Set the EDS calendar event checkboxes */
+ widget = _clock_get_widget (cd, "show_calendar_events_check");
+ if (widget) {
+ /* Bind to gsettings - this should sync with calendar window automatically */
+ g_settings_bind (cd->settings, KEY_SHOW_CALENDAR_EVENTS, widget, "active",
+ G_SETTINGS_BIND_DEFAULT);
+ } else {
+ g_warning ("Could not find show_calendar_events_check widget in preferences");
+ }
+
+ /* Set the EDS tasks checkboxes */
+ widget = _clock_get_widget (cd, "show_tasks_check");
+ if (widget) {
+ /* Bind to gsettings - this should sync with calendar window automatically */
+ g_settings_bind (cd->settings, KEY_SHOW_TASKS, widget, "active",
+ G_SETTINGS_BIND_DEFAULT);
+ } else {
+ g_warning ("Could not find show_tasks_check widget in preferences");
+ }
+
+#else
+ /* Hide the Calendar tab if EDS is not available */
+ widget = _clock_get_widget (cd, "vbox-calendar");
+ gtk_widget_hide (widget);
+ widget = _clock_get_widget (cd, "label-calendar-tab");
+ gtk_widget_hide (widget);
+#endif
+
/* Fill the Cities list */
widget = _clock_get_widget (cd, "cities_list");