#include #include #include #include #include #include #include "generated.h" #include "rcm-client-main.h" #include "rcm-client-hardware-list.h" #define WINDOW_WIDTH 300 #define WINDOW_HEIGHT 300 static GDBusObjectManager *mgr = NULL; struct global_variables *global; void poke_objects() { GList *objects; GList *l; GDBusObjectManager *manager = mgr; objects = g_dbus_object_manager_get_objects (manager); for (l = objects; l != NULL; l = l->next) { GDBusInterface *interface; interface = g_dbus_object_get_interface(G_DBUS_OBJECT(l->data), "org.gnome.RemoteControlManager.Device"); if (!interface) { g_print("That's weird, an object which is not a device...\n"); continue; } RCDevice *object = RCDEVICE(interface); gchar *reply = NULL; rcdevice_call_echo_string_sync(object, "Roeven", &reply, NULL, NULL); printf("Called object %s: %s\n", g_dbus_object_get_object_path (G_DBUS_OBJECT(l->data)), reply); printf("Driver name is: %s\n", rcdevice_get_driver_name(object)); printf("Keymap name is: %s\n", rcdevice_get_kernel_keymap_name(object)); g_free(reply); g_object_unref(interface); } g_list_free_full (objects, g_object_unref); } void poke_objects2() { GList *objects; GList *l; GDBusObjectManager *manager = mgr; objects = g_dbus_object_manager_get_objects (manager); for (l = objects; l != NULL; l = l->next) { GDBusInterface *interface; interface = g_dbus_object_get_interface(G_DBUS_OBJECT(l->data), "org.gnome.RemoteControlManager.IRDevice"); if (!interface) { g_print("That's weird, an object which is not an ir device...\n"); continue; } RCIRDevice *object = RCIRDEVICE(interface); GVariant *reply = NULL; rcirdevice_call_get_irrxparameters_sync(object, &reply, NULL, NULL); printf("Got a reply %p\n", reply); gchar *ans = NULL; g_variant_lookup(reply, "name", "s", &ans); printf("The rsult is %s\n", ans); /* printf("Called object %s: %s\n", g_dbus_object_get_object_path (G_DBUS_OBJECT(l->data)), reply); printf("Driver name is: %s\n", rcdevice_get_driver_name(object)); printf("Keymap name is: %s\n", rcdevice_get_kernel_keymap_name(object)); */ //g_free(reply); g_object_unref(interface); } g_list_free_full (objects, g_object_unref); } static void on_object_added(GDBusObjectManager *manager, GDBusObject *object, gpointer user_data) { g_print("Added object at %s\n", g_dbus_object_get_object_path(object)); rcng_client_hardware_list_add(object); } static void on_object_removed(GDBusObjectManager *manager, GDBusObject *object, gpointer user_data) { g_print("Removed object at %s\n", g_dbus_object_get_object_path(object)); rcng_client_hardware_list_remove(object); } static void on_owner_change(GDBusObjectManager *manager, gpointer user_data) { g_print("Owner changed, now: %s\n", g_dbus_object_manager_client_get_name_owner(G_DBUS_OBJECT_MANAGER_CLIENT(manager))); if (!g_dbus_object_manager_client_get_name_owner(G_DBUS_OBJECT_MANAGER_CLIENT(manager))) rcng_client_hardware_list_update_status("Server not running...\n"); else rcng_client_hardware_list_update_status("No hardware connected..."); } static void manager_ready_cb(GObject *source, GAsyncResult *res, gpointer user_data) { GError *error = NULL; GList *objects; GList *l; mgr = object_manager_client_new_for_bus_finish(res, &error); if (!mgr) { gchar *msg; msg = g_strdup_printf("Error creating object manager client: %s", error->message); rcng_client_hardware_list_update_status(msg); g_free(msg); g_error_free(error); return; } g_signal_connect(mgr, "object-added", G_CALLBACK(on_object_added), NULL); g_signal_connect(mgr, "object-removed", G_CALLBACK(on_object_removed), NULL); g_signal_connect(mgr, "notify::name-owner", G_CALLBACK(on_owner_change), NULL); on_owner_change(mgr, NULL); g_print("Object manager at %s\n", g_dbus_object_manager_get_object_path(mgr)); objects = g_dbus_object_manager_get_objects(mgr); for (l = objects; l != NULL; l = l->next) { rcng_client_hardware_list_add(G_DBUS_OBJECT(l->data)); rcng_client_hardware_list_add(G_DBUS_OBJECT(l->data)); } g_list_free_full (objects, g_object_unref); } int main (int argc, char *argv[]) { GtkWidget *win; GdkScreen *screen; gint monitor; GdkRectangle rect; global = g_malloc(sizeof(*global)); gtk_init (&argc, &argv); object_manager_client_new_for_bus(G_BUS_TYPE_SESSION, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, "org.gnome.RemoteControlManager", "/org/gnome/RemoteControlManager", NULL, manager_ready_cb, NULL); win = gtk_window_new(GTK_WINDOW_TOPLEVEL); global->window = GTK_WINDOW(win); g_signal_connect(win, "destroy", G_CALLBACK (gtk_main_quit), NULL); screen = gtk_window_get_screen(global->window); monitor = gdk_screen_get_monitor_at_point(screen, 0, 0); gdk_screen_get_monitor_geometry(screen, monitor, &rect); gtk_window_set_default_size(global->window, rect.width * 4 / 5, rect.height * 1 / 2); global->header = GTK_HEADER_BAR(gtk_header_bar_new()); gtk_header_bar_set_title(global->header, "Remote Control Configuration"); gtk_header_bar_set_has_subtitle(global->header, FALSE); gtk_header_bar_set_show_close_button(global->header, TRUE); gtk_window_set_titlebar(global->window, GTK_WIDGET(global->header)); /* GtkWidget *label; label = gtk_label_new("Pack Start"); gtk_header_bar_pack_start(GTK_HEADER_BAR(header), label); label = gtk_label_new("Pack End"); gtk_header_bar_pack_end(GTK_HEADER_BAR(header), label); GtkWidget *test = gtk_button_new_from_icon_name("gtk-add", GTK_ICON_SIZE_BUTTON); gtk_button_set_label(GTK_BUTTON(test), "Test"); gtk_button_set_always_show_image(GTK_BUTTON(test), TRUE); gtk_header_bar_pack_end(GTK_HEADER_BAR(header), test); */ global->notebook = GTK_NOTEBOOK(gtk_notebook_new()); gtk_notebook_set_tab_pos(global->notebook, GTK_POS_LEFT); rcng_client_hardware_list_init_ui(global->notebook); gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(global->notebook)); //gtk_window_set_title(window, "Remote Control Configuration"); gtk_window_set_icon_name(global->window, "gnome-multimedia"); gtk_widget_show_all(win); gtk_main(); return 0; }