27
21
gtk_window_set_title(GTK_WINDOW(dialog),_("Ubuntu CD detected"));
28
gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE);
29
22
gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog),
30
23
_("<span weight=\"bold\" size=\"larger\">"
31
24
"Ubuntu CD detected</span> \n\n"
32
"You can start the package manager "
33
"application with it now."));
25
"You can automatically upgrade from it, "
26
"start the package manager application "
34
28
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
36
30
GTK_RESPONSE_REJECT,
37
31
_("Start package manager"),
33
_("Automatically upgrade"),
34
RES_UPGRADE_AUTOMATIC,
42
38
int res = gtk_dialog_run (GTK_DIALOG (dialog));
46
cmd = g_strdup_printf("synaptic --add-cdrom %s",mount_point);
47
invoke_with_gksu(cmd, _("Package manager"));
39
if(res == RES_START_PM) {
40
//g_print("trying to start pm\n");
41
char *synaptic = g_strdup_printf("synaptic --add-cdrom %s",mount_point);
42
char *cmd[] = {"/usr/bin/gksudo", synaptic,NULL};
43
g_spawn_async("/",cmd,NULL,0,NULL,NULL,NULL,NULL);
45
} else if (res == RES_UPGRADE_AUTOMATIC) {
46
char *synaptic = g_strdup_printf("synaptic --add-cdrom %s --dist-upgrade-mode --non-interactive",mount_point);
47
char *cmd[] = {"/usr/bin/gksudo", synaptic, NULL};
48
g_spawn_async("/",cmd,NULL,0,NULL,NULL,NULL,NULL);
50
51
gtk_widget_destroy (dialog);
55
up_return_hal_functions ()
57
static const LibHalFunctions hal_functions = {
58
hal_mainloop_integration,
59
NULL /*hal_device_added*/,
60
NULL /*hal_device_removed*/,
61
NULL /*hal_device_new_capability*/,
62
NULL /*hal_device_lost_capability*/,
63
hal_property_modified,
64
NULL /*hal_device_condition*/
66
return &hal_functions;
70
/** Internal UP initialization function
54
/** Internal HAL initialization function
72
56
* @functions The LibHalFunctions to register as callbacks.
73
57
* @return The LibHalContext of the HAL connection or
61
up_do_hal_init (LibHalFunctions *functions)
83
hal_ctx = libhal_ctx_new ();
67
ctx = hal_initialize (functions, FALSE);
85
69
g_warning ("failed to initialize HAL!\n");
89
dbus_error_init (&error);
90
if (!hal_mainloop_integration (hal_ctx, &error)) {
91
g_warning ("hal_initialize failed: %s\n", error.message);
92
dbus_error_free (&error);
96
libhal_ctx_set_device_property_modified (hal_ctx,
97
hal_property_modified);
99
if (!libhal_device_property_watch_all (hal_ctx, &error)) {
100
g_warning ("failed to watch all HAL properties!: %s\n", error.message);
101
libhal_ctx_shutdown (hal_ctx, &error);
105
if (!libhal_ctx_init (hal_ctx, &error)) {
106
warn ("hal_initialize failed: %s\n", error.message);
107
dbus_error_free (&error);
108
libhal_ctx_free (hal_ctx);
73
if (hal_device_property_watch_all (ctx)) {
74
g_warning ("failed to watch all HAL properties!\n");
115
82
* want to exit silently if hald is not running, to behave on
116
83
* pre-2.6 systems.
118
devices = libhal_get_all_devices (hal_ctx, &nr, &error);
85
devices = hal_get_all_devices (ctx, &nr);
120
87
g_warning ("seems that HAL is not running\n");
121
libhal_ctx_shutdown (hal_ctx, &error);
122
if (dbus_error_is_set (&error))
123
dbus_error_free (&error);
124
libhal_ctx_free (hal_ctx);
127
libhal_free_string_array (devices);
91
hal_free_string_array (devices);
132
/** Invoked by GLib in response to a D-BUS disconnect event.
96
/** Invoked by libhal for integration with our mainloop.
134
* @param data Context pointer
98
* @param ctx LibHal context
99
* @param dbus_connection D-BUS connection to integrate
137
up_reconnect_to_hal (gpointer data __attribute__((__unused__)))
139
static unsigned int retries = 0;
141
g_message ("Trying a reconnect ...");
142
hal_ctx = up_do_hal_init ();
143
if (hal_ctx != NULL) {
144
g_message ("Reconnected OK.");
147
} else if (dbus_connection) {
148
dbus_connection_unref (dbus_connection);
149
dbus_connection = NULL;
152
/* Retry later if it failed. */
153
if (retries++ < 6000)
156
/* Too many retries; clean up and bail. */
157
warn("gvm_reconnect_to_hal: no reconnection after 6000 retries, "
160
/* Too many retries; clean up and bail. */
165
static DBusHandlerResult
166
up_do_filter_dbus_msg (DBusConnection *connection __attribute__((__unused__)),
167
DBusMessage *message,
168
void *user_data __attribute__((__unused__)))
172
if (dbus_message_is_signal (message,
173
DBUS_INTERFACE_LOCAL,
175
g_timeout_add(1000, up_reconnect_to_hal, NULL);
176
libhal_ctx_shutdown (hal_ctx, &error);
177
libhal_ctx_free (hal_ctx);
179
dbus_connection_unref (dbus_connection);
180
dbus_connection = NULL;
181
return DBUS_HANDLER_RESULT_HANDLED;
184
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
188
hal_mainloop_integration (LibHalContext *ctx,
193
dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, error);
195
if (dbus_error_is_set (error))
198
dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE);
200
dbus_connection_setup_with_g_main (dbus_connection, NULL);
201
dbus_connection_add_filter (dbus_connection, up_do_filter_dbus_msg,
204
libhal_ctx_set_dbus_connection (ctx, dbus_connection);
102
hal_mainloop_integration (LibHalContext *ctx __attribute__((__unused__)),
103
DBusConnection * dbus_connection)
105
dbus_connection_setup_with_g_main (dbus_connection, NULL);
209
108
/** Type for callback when a property of a device changes.
218
117
dbus_bool_t is_removed, dbus_bool_t is_added)
220
119
char *mount_point;
221
//g_print("hal_device_changed(): %s\n",key);
120
//g_print("hal_device_changed()\n");
223
122
/* we are only interessted in mount events from the cdrom*/
224
123
if (g_strcasecmp (key, "volume.is_mounted") != 0)
226
if(!libhal_device_get_property_bool(ctx, udi, key, NULL))
125
if(!hal_device_get_property_bool(ctx, udi, key))
229
char* storage_device = libhal_device_get_property_string (ctx, udi,
230
"block.storage_device",
128
char* storage_device = hal_device_get_property_string (ctx, udi,
129
"block.storage_device");
232
130
if (!storage_device) {
233
131
g_warning("cannot get storage_device\n");
236
char* media_type = libhal_device_get_property_string (ctx, storage_device,
237
"storage.drive_type",
134
char* media_type = hal_device_get_property_string (ctx, storage_device,
135
"storage.drive_type");
239
136
if(!media_type) {
240
137
g_warning("cannot get storage.drive_type\n");