#include #include #include #include #include #include #include "generated.h" #include "rcm-client-main.h" #include "rcm-client-hardware-list.h" #include "rcm-client-receive.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); printf("DBus object %s\n", g_dbus_object_get_object_path(G_DBUS_OBJECT(l->data))); printf("\tDriver name is: %s\n", rcdevice_get_driver_name(object)); printf("\tKeymap name is: %s\n", rcdevice_get_kernel_keymap_name(object)); 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_signal(GDBusObjectManagerClient *manager, GDBusObjectProxy *object_proxy, GDBusProxy *interface_proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data) { gchar *protocol; guint64 scancode; gchar *keycode; g_print("Signal %s received for obj %s\n", signal_name, g_dbus_object_get_object_path(G_DBUS_OBJECT(object_proxy))); if (!strcmp(signal_name, "KeyReleased")) { g_variant_get(parameters, "(s)", &keycode); rcng_client_receive_key_released(G_DBUS_OBJECT(object_proxy), keycode); g_free(keycode); } else if (!strcmp(signal_name, "KeyPressed")) { g_variant_get(parameters, "(sts)", &protocol, &scancode, &keycode); rcng_client_receive_key_pressed(G_DBUS_OBJECT(object_proxy), protocol, scancode, keycode); g_free(protocol); g_free(keycode); } } 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, "interface-proxy-signal", G_CALLBACK(on_signal), 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)); g_list_free_full (objects, g_object_unref); } int main (int argc, char *argv[]) { GdkDisplay *display; GdkScreen *screen; GtkWidget *win; gint monitor; GdkRectangle rect; GtkCssProvider *css; global = g_malloc(sizeof(*global)); gtk_init (&argc, &argv); display = gdk_display_get_default(); screen = gdk_display_get_default_screen(display); css = gtk_css_provider_new(); gtk_css_provider_load_from_path(css, "rcm.css", NULL); gtk_style_context_add_provider_for_screen(screen, GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); g_object_unref(css); 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); gtk_widget_set_name(win, "RemoteControlClientWindow"); global->window = GTK_WINDOW(win); g_signal_connect(win, "destroy", G_CALLBACK (gtk_main_quit), NULL); 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; }