FormatDialog* format_dialog_new(void) { FormatDialog *dialog; dialog = g_new0 (FormatDialog, 1); const char* xmlpath = GLADEDIR "/gformat.glade"; dialog->xml = glade_xml_new (xmlpath, "toplevel", NULL); /* Try uninstalled next */ if (!dialog->xml) { xmlpath = "./gformat.glade"; dialog->xml = glade_xml_new (xmlpath, "toplevel", NULL); } if (dialog->xml == NULL){ GtkWidget *f_dialog; f_dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Glade file for the format program is missing.\n" "Please check your installation of gnome-utils"); gtk_dialog_run (GTK_DIALOG (f_dialog)); gtk_widget_destroy (f_dialog); exit (1); } /* Grab some widgets */ dialog->toplevel = glade_xml_get_widget (dialog->xml, "toplevel"); dialog->volume_combo = GTK_COMBO_BOX(glade_xml_get_widget(dialog->xml, "volume_combo")); dialog->show_partitions = GTK_TOGGLE_BUTTON(glade_xml_get_widget(dialog->xml, "show_partitions")); dialog->fs_combo = GTK_COMBO_BOX(glade_xml_get_widget(dialog->xml, "fs_combo")); dialog->extra_volume_info = GTK_LABEL(glade_xml_get_widget(dialog->xml, "extra_volume_info")); dialog->extra_volume_hbox = GTK_HBOX(glade_xml_get_widget(dialog->xml, "extra_volume_hbox")); dialog->progress_bar = GTK_PROGRESS_BAR(glade_xml_get_widget(dialog->xml, "progress_bar")); dialog->format_button = GTK_BUTTON(glade_xml_get_widget(dialog->xml, "format_button")); dialog->cancel_button = GTK_BUTTON(glade_xml_get_widget(dialog->xml, "cancel_button")); dialog->luks_subwindow = GTK_BOX(glade_xml_get_widget (dialog->xml, "luks_subwindow")); dialog->floppy_subwindow = GTK_BOX(glade_xml_get_widget (dialog->xml, "floppy_subwindow")); g_assert(dialog->toplevel != NULL); /* Get a HAL context; if we can't, bail */ dialog->hal_context = libhal_context_alloc(); glade_xml_signal_autoconnect(dialog->xml); g_object_set_data(G_OBJECT(dialog->toplevel), "userdata", dialog); /* Set stuff in the dialog up */ setup_volume_treeview(dialog); setup_filesystem_menu(dialog); gtk_widget_show_all (dialog->toplevel); update_dialog(dialog); /* We do this here so they at least see the window before we die */ if( !dialog->hal_context ) { show_error_dialog(dialog->toplevel, _("Cannot get list of disks"), _("Make sure the HAL daemon is running and configured correctly")); return NULL; } /* Get the HAL version and register the HAL device callbacks */ get_hal_version(dialog); g_debug("Registering callback!"); libhal_ctx_set_user_data(dialog->hal_context, dialog); if (libhal_ctx_set_device_added(dialog->hal_context, on_libhal_device_added_removed) == TRUE) printf("libhal_ctx_set_device_added called"); libhal_ctx_set_device_removed(dialog->hal_context, on_libhal_device_added_removed); libhal_ctx_set_device_property_modified(dialog->hal_context, on_libhal_prop_modified); libhal_ctx_set_device_new_capability(dialog->hal_context, NULL); libhal_ctx_set_device_lost_capability(dialog->hal_context, NULL); libhal_ctx_set_device_condition(dialog->hal_context, NULL); return dialog; }
// Initialize basic HAL connection LibHalContext *CHALManager::InitializeHal() { LibHalContext *ctx; char **devices; int nr; if (!InitializeDBus()) return NULL; if (!(ctx = libhal_ctx_new())) { CLog::Log(LOGERROR, "HAL: failed to create a HAL context!"); return NULL; } if (!libhal_ctx_set_dbus_connection(ctx, m_DBusSystemConnection)) CLog::Log(LOGERROR, "HAL: Failed to connect with dbus"); libhal_ctx_set_device_added(ctx, DeviceAdded); libhal_ctx_set_device_removed(ctx, DeviceRemoved); libhal_ctx_set_device_new_capability(ctx, DeviceNewCapability); libhal_ctx_set_device_lost_capability(ctx, DeviceLostCapability); libhal_ctx_set_device_property_modified(ctx, DevicePropertyModified); libhal_ctx_set_device_condition(ctx, DeviceCondition); if (!libhal_device_property_watch_all(ctx, &m_Error)) { CLog::Log(LOGERROR, "HAL: Failed to set property watch %s", m_Error.message); dbus_error_free(&m_Error); libhal_ctx_free(ctx); return NULL; } if (!libhal_ctx_init(ctx, &m_Error)) { CLog::Log(LOGERROR, "HAL: Failed to initialize hal context: %s", m_Error.message); dbus_error_free(&m_Error); libhal_ctx_free(ctx); return NULL; } /* * Do something to ping the HAL daemon - the above functions will * succeed even if hald is not running, so long as DBUS is. But we * want to exit silently if hald is not running, to behave on * pre-2.6 systems. */ if (!(devices = libhal_get_all_devices(ctx, &nr, &m_Error))) { CLog::Log(LOGERROR, "HAL: seems that Hal daemon is not running: %s", m_Error.message); dbus_error_free(&m_Error); libhal_ctx_shutdown(ctx, NULL); libhal_ctx_free(ctx); return NULL; } libhal_free_string_array(devices); return ctx; }
static void thunar_vfs_volume_manager_hal_init (ThunarVfsVolumeManagerHal *manager_hal) { LibHalDrive *hd; DBusError error; gchar **drive_udis; gchar **udis; gint n_drive_udis; gint n_udis; gint n, m; /* initialize the D-BUS error */ dbus_error_init (&error); /* allocate a HAL context */ manager_hal->context = libhal_ctx_new (); if (G_UNLIKELY (manager_hal->context == NULL)) return; /* try to connect to the system bus */ manager_hal->dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error); if (G_UNLIKELY (manager_hal->dbus_connection == NULL)) goto failed; /* setup the D-BUS connection for the HAL context */ libhal_ctx_set_dbus_connection (manager_hal->context, manager_hal->dbus_connection); /* connect our manager object to the HAL context */ libhal_ctx_set_user_data (manager_hal->context, manager_hal); /* setup callbacks */ libhal_ctx_set_device_added (manager_hal->context, thunar_vfs_volume_manager_hal_device_added); libhal_ctx_set_device_removed (manager_hal->context, thunar_vfs_volume_manager_hal_device_removed); libhal_ctx_set_device_new_capability (manager_hal->context, thunar_vfs_volume_manager_hal_device_new_capability); libhal_ctx_set_device_lost_capability (manager_hal->context, thunar_vfs_volume_manager_hal_device_lost_capability); libhal_ctx_set_device_property_modified (manager_hal->context, thunar_vfs_volume_manager_hal_device_property_modified); libhal_ctx_set_device_condition (manager_hal->context, thunar_vfs_volume_manager_hal_device_condition); /* try to initialize the HAL context */ if (!libhal_ctx_init (manager_hal->context, &error)) goto failed; /* setup the D-BUS connection with the GLib main loop */ dbus_connection_setup_with_g_main (manager_hal->dbus_connection, NULL); /* lookup all drives currently known to HAL */ drive_udis = libhal_find_device_by_capability (manager_hal->context, "storage", &n_drive_udis, &error); if (G_LIKELY (drive_udis != NULL)) { /* process all drives UDIs */ for (m = 0; m < n_drive_udis; ++m) { /* determine the LibHalDrive for the drive UDI */ hd = libhal_drive_from_udi (manager_hal->context, drive_udis[m]); if (G_UNLIKELY (hd == NULL)) continue; /* check if we have a floppy disk here */ if (libhal_drive_get_type (hd) == LIBHAL_DRIVE_TYPE_FLOPPY) { /* add the drive based on the UDI */ thunar_vfs_volume_manager_hal_device_added (manager_hal->context, drive_udis[m]); } else { /* determine all volumes for the given drive */ udis = libhal_drive_find_all_volumes (manager_hal->context, hd, &n_udis); if (G_LIKELY (udis != NULL)) { /* add volumes for all given UDIs */ for (n = 0; n < n_udis; ++n) { /* add the volume based on the UDI */ thunar_vfs_volume_manager_hal_device_added (manager_hal->context, udis[n]); /* release the UDI (HAL bug #5279) */ free (udis[n]); } /* release the UDIs array (HAL bug #5279) */ free (udis); } } /* release the hal drive */ libhal_drive_free (hd); } /* release the drive UDIs */ libhal_free_string_array (drive_udis); } /* watch all devices for changes */ if (!libhal_device_property_watch_all (manager_hal->context, &error)) goto failed; return; failed: /* release the HAL context */ if (G_LIKELY (manager_hal->context != NULL)) { libhal_ctx_free (manager_hal->context); manager_hal->context = NULL; } /* print a warning message */ if (dbus_error_is_set (&error)) { g_warning (_("Failed to connect to the HAL daemon: %s"), error.message); dbus_error_free (&error); } }