DBusHandlerResult FcitxNotificationItemDBusFilter(DBusConnection* connection, DBusMessage* msg, void* user_data) { FcitxNotificationItem* notificationitem = (FcitxNotificationItem*) user_data; if (dbus_message_is_signal(msg, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) { const char* service, *oldowner, *newowner; DBusError error; dbus_error_init(&error); do { if (!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &service , DBUS_TYPE_STRING, &oldowner , DBUS_TYPE_STRING, &newowner , DBUS_TYPE_INVALID)) { break; } /* old die and no new one */ if (strcmp(service, NOTIFICATION_WATCHER_DBUS_ADDR) != 0) { break; } FcitxNotificationItemSetAvailable (notificationitem, strlen(newowner) > 0); return DBUS_HANDLER_RESULT_HANDLED; } while(0); dbus_error_free(&error); } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; }
void FcitxNotificationItemOwnerChanged(void* user_data, void* arg, const char* serviceName, const char* oldName, const char* newName) { FcitxNotificationItem* notificationitem = (FcitxNotificationItem*) user_data; /* old die and no new one */ if (strcmp(serviceName, NOTIFICATION_WATCHER_DBUS_ADDR) != 0) { return; } FcitxNotificationItemSetAvailable (notificationitem, strlen(newName) > 0); }
void NotificationWatcherServiceExistCallback(DBusPendingCall *call, void *data) { FcitxNotificationItem *notificationitem = (FcitxNotificationItem*)data; DBusMessage *msg = dbus_pending_call_steal_reply(call); if (msg) { dbus_bool_t has = FALSE; DBusError error; dbus_error_init(&error); dbus_message_get_args(msg, &error, DBUS_TYPE_BOOLEAN, &has, DBUS_TYPE_INVALID); dbus_message_unref(msg); dbus_error_free(&error); FcitxNotificationItemSetAvailable(notificationitem, has); } }