static void indicator_workrave_init(IndicatorWorkrave *self) { self->priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); priv->label = NULL; priv->image = NULL; // self->priv->sm = NULL; priv->menu = NULL; priv->workrave_proxy = NULL; priv->workrave_proxy_cancel = NULL; priv->owner_id = 0; priv->watch_id = 0; priv->alive = FALSE; priv->timer = 0; priv->timerbox = NULL; priv->update_count = 0; // self->priv->sm = indicator_service_manager_new_version(WORKRAVE_INDICATOR_SERVICE_NAME, WORKRAVE_INDICATOR_SERVICE_VERSION); priv->menu = dbusmenu_gtkmenu_new(WORKRAVE_INDICATOR_MENU_NAME, WORKRAVE_INDICATOR_MENU_OBJ); priv->timerbox = g_object_new(WORKRAVE_TYPE_TIMERBOX, NULL); priv->workrave_proxy_cancel = g_cancellable_new(); g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL, WORKRAVE_INDICATOR_SERVICE_NAME, WORKRAVE_INDICATOR_SERVICE_OBJ, WORKRAVE_INDICATOR_SERVICE_IFACE, priv->workrave_proxy_cancel, on_dbus_ready, self); }
static void on_update_indicator(IndicatorWorkrave *self, GVariant *parameters) { IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); if (! priv->alive) { indicator_workrave_start(self); } priv->update_count++; TimerData td[BREAK_ID_SIZEOF]; g_variant_get(parameters, "((siuuuuuu)(siuuuuuu)(siuuuuuu))", &td[BREAK_ID_MICRO_BREAK].bar_text, &td[BREAK_ID_MICRO_BREAK].slot, &td[BREAK_ID_MICRO_BREAK].bar_secondary_color, &td[BREAK_ID_MICRO_BREAK].bar_secondary_val, &td[BREAK_ID_MICRO_BREAK].bar_secondary_max, &td[BREAK_ID_MICRO_BREAK].bar_primary_color, &td[BREAK_ID_MICRO_BREAK].bar_primary_val, &td[BREAK_ID_MICRO_BREAK].bar_primary_max, &td[BREAK_ID_REST_BREAK].bar_text, &td[BREAK_ID_REST_BREAK].slot, &td[BREAK_ID_REST_BREAK].bar_secondary_color, &td[BREAK_ID_REST_BREAK].bar_secondary_val, &td[BREAK_ID_REST_BREAK].bar_secondary_max, &td[BREAK_ID_REST_BREAK].bar_primary_color, &td[BREAK_ID_REST_BREAK].bar_primary_val, &td[BREAK_ID_REST_BREAK].bar_primary_max, &td[BREAK_ID_DAILY_LIMIT].bar_text, &td[BREAK_ID_DAILY_LIMIT].slot, &td[BREAK_ID_DAILY_LIMIT].bar_secondary_color, &td[BREAK_ID_DAILY_LIMIT].bar_secondary_val, &td[BREAK_ID_DAILY_LIMIT].bar_secondary_max, &td[BREAK_ID_DAILY_LIMIT].bar_primary_color, &td[BREAK_ID_DAILY_LIMIT].bar_primary_val, &td[BREAK_ID_DAILY_LIMIT].bar_primary_max ); for (int i = 0; i < BREAK_ID_SIZEOF; i++) { workrave_timerbox_set_slot(priv->timerbox, i, td[i].slot); } for (int i = 0; i < BREAK_ID_SIZEOF; i++) { WorkraveTimebar *timebar = workrave_timerbox_get_time_bar(priv->timerbox, i); if (timebar != NULL) { workrave_timerbox_set_enabled(priv->timerbox, TRUE); workrave_timebar_set_progress(timebar, td[i].bar_primary_val, td[i].bar_primary_max, td[i].bar_primary_color); workrave_timebar_set_secondary_progress(timebar, td[i].bar_secondary_val, td[i].bar_secondary_max, td[i].bar_secondary_color); workrave_timebar_set_text(timebar, td[i].bar_text); } } workrave_timerbox_update(priv->timerbox, priv->image); }
static void on_dbus_ready(GObject *object, GAsyncResult *res, gpointer user_data) { IndicatorWorkrave *self = INDICATOR_WORKRAVE(user_data); IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); GError *error = NULL; GDBusProxy *proxy = g_dbus_proxy_new_for_bus_finish(res, &error); if (priv->workrave_proxy_cancel != NULL) { g_object_unref(priv->workrave_proxy_cancel); priv->workrave_proxy_cancel = NULL; } if (error != NULL) { g_warning("Could not grab DBus proxy for %s: %s", WORKRAVE_INDICATOR_SERVICE_NAME, error->message); g_error_free(error); } else { g_signal_connect(proxy, "g-signal", G_CALLBACK(on_dbus_signal), self); priv->workrave_proxy = proxy; priv->watch_id = g_bus_watch_name(G_BUS_TYPE_SESSION, "org.workrave.Workrave", G_BUS_NAME_WATCHER_FLAGS_NONE, on_workrave_appeared, on_workrave_vanished, self, NULL); } }
static void on_dbus_signal(GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data) { IndicatorWorkrave *self = INDICATOR_WORKRAVE(user_data); IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); if (g_strcmp0(signal_name, "TimersUpdated") == 0) { on_update_indicator(self, parameters); } else if (g_strcmp0(signal_name, "TrayIconUpdated") == 0) { g_variant_get(parameters, "(b)", &priv->force_icon); workrave_timerbox_set_force_icon(priv->timerbox, priv->force_icon); workrave_timerbox_update(priv->timerbox, priv->image); } else if (g_strcmp0(signal_name, "OperationModeChanged") == 0) { gchar *mode; g_variant_get(parameters, "(s)", &mode); workrave_timerbox_set_operation_mode(priv->timerbox, mode); workrave_timerbox_update(priv->timerbox, priv->image); } }
static void indicator_workrave_create_dbus(IndicatorWorkrave *self) { IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); GSettings *settings = g_settings_new("org.workrave.gui"); gboolean autostart = g_settings_get_boolean(settings, "autostart"); g_object_unref(settings); GDBusProxyFlags flags = autostart ? : G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START; priv->workrave_ui_proxy_cancel = g_cancellable_new(); g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, flags, NULL, WORKRAVE_INDICATOR_SERVICE_NAME, WORKRAVE_INDICATOR_SERVICE_OBJ, WORKRAVE_INDICATOR_SERVICE_IFACE, priv->workrave_ui_proxy_cancel, on_dbus_ui_ready, self); priv->workrave_core_proxy_cancel = g_cancellable_new(); g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, flags, NULL, WORKRAVE_INDICATOR_CORE_NAME, WORKRAVE_INDICATOR_CORE_OBJ, WORKRAVE_INDICATOR_CORE_IFACE, priv->workrave_core_proxy_cancel, on_dbus_core_ready, self); }
static void on_dbus_core_ready(GObject *object, GAsyncResult *res, gpointer user_data) { IndicatorWorkrave *self = INDICATOR_WORKRAVE(user_data); IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); GError *error = NULL; GDBusProxy *proxy = g_dbus_proxy_new_for_bus_finish(res, &error); if (priv->workrave_core_proxy_cancel != NULL) { g_object_unref(priv->workrave_core_proxy_cancel); priv->workrave_core_proxy_cancel = NULL; } if (error != NULL) { g_warning("Could not grab DBus proxy for %s: %s", WORKRAVE_INDICATOR_CORE_NAME, error->message); g_error_free(error); } else { g_signal_connect(proxy, "g-signal", G_CALLBACK(on_dbus_signal), self); priv->workrave_core_proxy = proxy; } indicator_workrave_check(self); }
static void indicator_workrave_stop(IndicatorWorkrave *self) { IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); if (priv->alive) { if (priv->timer != 0) { g_source_remove(priv->timer); priv->timer = 0; } if (priv->startup_timer != 0) { g_source_remove(priv->startup_timer); priv->startup_timer = 0; } if (priv->owner_id != 0) { g_bus_unown_name(priv->owner_id); priv->owner_id = 0; } workrave_timerbox_set_enabled(priv->timerbox, FALSE); workrave_timerbox_set_force_icon(priv->timerbox, FALSE); workrave_timerbox_update(priv->timerbox, priv->image); priv->alive = FALSE; } }
static gboolean on_start_delay(gpointer user_data) { IndicatorWorkrave *self = INDICATOR_WORKRAVE(user_data); IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); indicator_workrave_start(self); priv->startup_count++; return !priv->alive && priv->startup_count < 15; }
static const gchar * get_accessible_desc(IndicatorObject *io) { IndicatorWorkrave *self = INDICATOR_WORKRAVE(io); IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); const gchar *name = NULL; if (priv->label != NULL) { name = "Workrave"; } return name; }
static void indicator_workrave_dispose(GObject *object) { IndicatorWorkrave *self = INDICATOR_WORKRAVE(object); IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); if (priv->watch_id != 0) { g_bus_unwatch_name(priv->watch_id); } if (priv->owner_id != 0) { g_bus_unown_name(priv->owner_id); } if (priv->timer != 0) { g_source_remove(priv->timer); priv->timer = 0; } if (priv->label != NULL) { g_object_unref(priv->label); priv->label = NULL; } if (priv->image != NULL) { g_object_unref(priv->image); priv->image = NULL; } if (priv->menu != NULL) { g_object_unref(G_OBJECT(priv->menu)); priv->menu = NULL; } //if (priv->sm != NULL) // { // g_object_unref(G_OBJECT(priv->sm)); // priv->sm = NULL; // } G_OBJECT_CLASS(indicator_workrave_parent_class)->dispose(object); return; }
static void indicator_workrave_check(IndicatorWorkrave *self) { IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); if (priv->workrave_running && priv->workrave_ui_proxy != NULL && priv->workrave_core_proxy != NULL) { // The Workrave interface may be started after the service becomes // available, so introduce a delay. priv->startup_count = 0; priv->startup_timer = g_timeout_add_seconds(2, on_start_delay, self); } }
static void indicator_workrave_init(IndicatorWorkrave *self) { self->priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); priv->label = NULL; priv->image = NULL; priv->menu = NULL; priv->workrave_ui_proxy = NULL; priv->workrave_ui_proxy_cancel = NULL; priv->workrave_core_proxy = NULL; priv->workrave_core_proxy_cancel = NULL; priv->owner_id = 0; priv->watch_id = 0; priv->workrave_running = FALSE; priv->alive = FALSE; priv->force_icon = FALSE; priv->timer = 0; priv->startup_timer = 0; priv->startup_count = 0; priv->timerbox = NULL; priv->update_count = 0; priv->menu = dbusmenu_gtkmenu_new(WORKRAVE_INDICATOR_MENU_NAME, WORKRAVE_INDICATOR_MENU_OBJ); priv->timerbox = g_object_new(WORKRAVE_TYPE_TIMERBOX, NULL); indicator_workrave_create_dbus(self); priv->watch_id = g_bus_watch_name(G_BUS_TYPE_SESSION, "org.workrave.Workrave", G_BUS_NAME_WATCHER_FLAGS_NONE, on_workrave_appeared, on_workrave_vanished, self, NULL); }
static gboolean on_timer(gpointer user_data) { IndicatorWorkrave *self = INDICATOR_WORKRAVE(user_data); IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); if (priv->alive && priv->update_count == 0) { workrave_timerbox_set_enabled(priv->timerbox, FALSE); workrave_timerbox_update(priv->timerbox, priv->image); } priv->update_count = 0; return priv->alive; }
static GtkImage * get_icon(IndicatorObject *io) { IndicatorWorkrave *self = INDICATOR_WORKRAVE(io); IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); if (priv->image == NULL) { priv->image = GTK_IMAGE(gtk_image_new()); workrave_timerbox_set_enabled(priv->timerbox, FALSE); workrave_timerbox_update(priv->timerbox, priv->image); gtk_widget_show(GTK_WIDGET(priv->image)); } return priv->image; }
static void indicator_workrave_start(IndicatorWorkrave *self) { IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); if (! priv->alive) { priv->owner_id = g_bus_own_name(G_BUS_TYPE_SESSION, DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, NULL, NULL, self, NULL); GError *error = NULL; GVariant *result = g_dbus_proxy_call_sync(priv->workrave_proxy, "Embed", g_variant_new("(bs)", TRUE, DBUS_NAME), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (error != NULL) { g_warning("Could not request embedding for %s: %s", WORKRAVE_INDICATOR_SERVICE_NAME, error->message); g_error_free(error); } else { if (result != NULL) { g_variant_unref(result); } priv->timer = g_timeout_add_seconds(10, on_timer, self); priv->alive = TRUE; priv->update_count = 0; } } }
static void indicator_workrave_start(IndicatorWorkrave *self) { IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); if (priv->alive) { return; } priv->owner_id = g_bus_own_name(G_BUS_TYPE_SESSION, DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, NULL, NULL, self, NULL); GError *error = NULL; if (error == NULL) { GVariant *result = g_dbus_proxy_call_sync(priv->workrave_ui_proxy, "Embed", g_variant_new("(bs)", TRUE, DBUS_NAME), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (error != NULL) { g_warning("Could not request embedding for %s: %s", WORKRAVE_INDICATOR_SERVICE_NAME, error->message); } else { if (result != NULL) { g_variant_unref(result); } } } if (error == NULL) { GVariant *result = g_dbus_proxy_call_sync(priv->workrave_ui_proxy, "GetTrayIconEnabled", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (error != NULL) { g_warning("Could not request tray icon enabled for %s: %s", WORKRAVE_INDICATOR_SERVICE_NAME, error->message); } else { if (result != NULL) { g_variant_get(result, "(b)", &priv->force_icon); g_variant_unref(result); } } } if (error == NULL) { GVariant *result = g_dbus_proxy_call_sync(priv->workrave_core_proxy, "GetOperationMode", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (error != NULL) { g_warning("Could not request operation mode for %s: %s", WORKRAVE_INDICATOR_SERVICE_NAME, error->message); } else { gchar *mode; g_variant_get(result, "(s)", &mode); workrave_timerbox_set_operation_mode(priv->timerbox, mode); g_variant_unref(result); } } if (error == NULL) { priv->timer = g_timeout_add_seconds(10, on_timer, self); priv->alive = TRUE; priv->update_count = 0; } else { g_error_free(error); } }