+ plugin->priv->usb_on = FALSE;
+ plugin->priv->net_on = FALSE;
+
+ plugin->priv->enable_button = hildon_button_new(HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
+ if (plugin->priv->enable_button) {
+ GError *err = NULL;
+ GdkPixbuf *icon = gdk_pixbuf_new_from_file(IMAGE_DIR "/mtetherd-net-icon.png", &err);
+ if (err) {
+ g_warning("Can't load mtetherd icon: %s", err->message);
+ hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Can't load mtetherd icon: %s", err->message);
+ g_error_free(err);
+ err = NULL;
+ }
+ if (icon) {
+ GtkWidget *image = gtk_image_new_from_pixbuf(icon);
+ hildon_button_set_image(HILDON_BUTTON(plugin->priv->enable_button), image);
+ hildon_button_set_image_position(HILDON_BUTTON(plugin->priv->enable_button), GTK_POS_LEFT);
+ g_object_unref(icon);
+ }
+ gboolean enabled = get_usbnet_enabled(plugin);
+ enable_button_set_text(plugin->priv->enable_button, enabled);
+ g_signal_connect(plugin->priv->enable_button, "clicked", G_CALLBACK(enable_button_clicked), plugin);
+ gtk_container_add(GTK_CONTAINER(plugin), plugin->priv->enable_button);
+ gtk_widget_show_all(plugin->priv->enable_button);
+ }
+ //g_signal_connect(plugin, "expose-event", G_CALLBACK(mtetherd_status_plugin_event), NULL);
+
+ //hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Initialized mtetherd status plugin");
+ GError *err = NULL;
+ plugin->priv->dbus_connection = hd_status_plugin_item_get_dbus_g_connection(HD_STATUS_PLUGIN_ITEM(plugin), DBUS_BUS_SYSTEM, &err);
+ if (err) {
+ g_warning("Can't open DBUS connection: %s", err->message);
+ hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Error opening DBUS connection: %s", err->message);
+ g_error_free(err);
+ err = NULL;
+ } else {
+ g_message("Got DBUS Glib connection: %p", plugin->priv->dbus_connection);
+ }
+ if (plugin->priv->dbus_connection) {
+ plugin->priv->hal_context = libhal_ctx_new();
+ if (plugin->priv->hal_context) {
+ if (libhal_ctx_set_dbus_connection(plugin->priv->hal_context, dbus_g_connection_get_connection(plugin->priv->dbus_connection))) {
+ if (!libhal_ctx_set_user_data(plugin->priv->hal_context, plugin)) {
+ g_warning("Can't set user data of HAL context");
+ hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Can't set user data of HAL context");
+ }
+ if (!libhal_ctx_set_device_condition(plugin->priv->hal_context, mtetherd_status_plugin_device_condition)) {
+ g_warning("Error assigning device condition callback");
+ hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Error assigning device condition callback");
+ }
+ DBusError derr;
+ dbus_error_init(&derr);
+ if (!libhal_ctx_init(plugin->priv->hal_context, &derr)) {
+ if (dbus_error_is_set(&derr)) {
+ g_warning("Error initializing HAL context (%s): %s", derr.name, derr.message);
+ hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Error initializing HAL context (%s): %s", derr.name, derr.message);
+ dbus_error_free(&derr);
+ } else {
+ g_warning("Error initializing HAL context: unknown error");
+ //hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Error initializing HAL context: unknown error");
+ }
+ libhal_ctx_free(plugin->priv->hal_context);
+ plugin->priv->hal_context = NULL;
+ }
+ } else {
+ g_warning("Can't set DBUS connection of HAL context");
+ hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Can't set DBUS connection of HAL context");
+ libhal_ctx_free(plugin->priv->hal_context);
+ plugin->priv->hal_context = NULL;
+ }
+ } else {
+ g_warning("Can't allocate HAL context");
+ hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Can't allocate HAL context");
+ }
+ }
+
+ mtetherd_status_plugin_usb_plugged_show(plugin);