DBus goodness! Drive detection is more reliable now, need to implement some detection of the volume characteristics now.

This commit is contained in:
Jaime Thomas 2009-04-18 23:18:17 +00:00
parent 2a9fb5100f
commit b7cf7fc4b9
12 changed files with 450 additions and 181 deletions

View File

@ -100,6 +100,8 @@ PKG_CHECK_MODULES(ECDB, [
edje edje
efreet-mime efreet-mime
efreet efreet
edbus
ehal
libburn-1 >= $LIBBURN_REQUIRED libburn-1 >= $LIBBURN_REQUIRED
libisofs-1 >= $LIBISOFS_REQUIRED libisofs-1 >= $LIBISOFS_REQUIRED
]) ])

View File

@ -19,6 +19,7 @@ ecdb_SOURCES = \
ecdb_filelist_custom.c ecdb_filelist_custom.h \ ecdb_filelist_custom.c ecdb_filelist_custom.h \
ecdb_about.c ecdb_about.h \ ecdb_about.c ecdb_about.h \
ecdb_config_dialog.c ecdb_config_dialog.h \ ecdb_config_dialog.c ecdb_config_dialog.h \
ecdb_hal.c ecdb_hal.h \
ecdb_common.h ecdb_common.h
ecdb_CFLAGS = @ECDB_CFLAGS@ ecdb_CFLAGS = @ECDB_CFLAGS@

View File

@ -24,78 +24,94 @@ main(int argc, char **argv)
if (!eina_error_init()) if (!eina_error_init())
{ {
fprintf(stderr, "Cannot initialize Eina!\n"); fprintf(stderr, "Cannot initialize Eina Error!\n");
ret = 1; ret = 1;
goto SHUTDOWN; goto SHUTDOWN;
} }
/* Do I really need all of these? */ eina_error_log_level_set(EINA_ERROR_LEVEL_DBG);
eina_error_print_cb_set(eina_error_print_cb_file, stderr);
if (!ecore_init()) if (!ecore_init())
{ {
fprintf(stderr, "Cannot initialize Ecore!\n"); EINA_ERROR_PERR("Cannot initialize Ecore!\n");
ret = 1; ret = 1;
goto SHUTDOWN; goto SHUTDOWN;
} }
if (!ecore_file_init()) if (!ecore_file_init())
{ {
fprintf(stderr, "Cannot initialize Ecore_File!\n"); EINA_ERROR_PERR("Cannot initialize Ecore_File!\n");
ret = 1; ret = 1;
goto SHUTDOWN; goto SHUTDOWN;
} }
if (ecore_config_init("ecdb") != ECORE_CONFIG_ERR_SUCC) if (ecore_config_init("ecdb") != ECORE_CONFIG_ERR_SUCC)
{ {
fprintf(stderr, "Cannot intialize Ecore_Config!\n"); EINA_ERROR_PERR("Cannot intialize Ecore_Config!\n");
ret = 1; ret = 1;
goto SHUTDOWN; goto SHUTDOWN;
} }
if (!ecore_evas_init()) if (!ecore_evas_init())
{ {
fprintf(stderr, "Cannot initialize Ecore_Evas!\n"); EINA_ERROR_PERR("Cannot initialize Ecore_Evas!\n");
ret = 1; ret = 1;
goto SHUTDOWN; goto SHUTDOWN;
} }
if (!edje_init()) if (!edje_init())
{ {
fprintf(stderr, "Cannot initialize Edje!\n"); EINA_ERROR_PERR("Cannot initialize Edje!\n");
ret = 1; ret = 1;
goto SHUTDOWN; goto SHUTDOWN;
} }
if (!efreet_init()) if (!efreet_init())
{ {
fprintf(stderr, "Cannot initialize Efreet!\n"); EINA_ERROR_PERR("Cannot initialize Efreet!\n");
ret = 1; ret = 1;
goto SHUTDOWN; goto SHUTDOWN;
} }
if (!ewl_init(&argc, argv)) if (!ewl_init(&argc, argv))
{ {
fprintf(stderr, "Connot initialize Ewl!\n"); EINA_ERROR_PERR("Connot initialize Ewl!\n");
ret = 1;
goto SHUTDOWN;
}
if (!e_dbus_init())
{
EINA_ERROR_PERR("Cannot initialize E_DBus!\n");
ret = 1; ret = 1;
goto SHUTDOWN; goto SHUTDOWN;
} }
if (!ecdb_image_init()) if (!ecdb_image_init())
{ {
fprintf(stderr, "Cannot initialize libisofs!\n"); EINA_ERROR_PERR("Cannot initialize libisofs!\n");
ret = 1; ret = 1;
goto SHUTDOWN; goto SHUTDOWN;
} }
if (!ecdb_burn_init()) if (!ecdb_burn_init())
{ {
fprintf(stderr, "Cannot initialize libburn!\n"); EINA_ERROR_PERR("Cannot initialize libburn!\n");
ret = 1; ret = 1;
goto SHUTDOWN; goto SHUTDOWN;
} }
if (!ecdb_setup()) if (!ecdb_setup())
{ {
fprintf(stderr, "Setup failed\n"); EINA_ERROR_PERR("Setup failed\n");
ret = 1;
goto SHUTDOWN;
}
if (!ecdb_hal_init())
{
EINA_ERROR_PERR("Ecdb_Hal initialization failed!\n");
ret = 1; ret = 1;
goto SHUTDOWN; goto SHUTDOWN;
} }
@ -104,8 +120,9 @@ main(int argc, char **argv)
if (!ecdb_create_main_gui()) if (!ecdb_create_main_gui())
{ {
fprintf(stderr, "Cannot create main window\n"); EINA_ERROR_PERR("Cannot create main window\n");
ret = 1; ret = 1;
ecdb_drive_info_list_free(em->drives);
goto SHUTDOWN; goto SHUTDOWN;
} }
@ -159,6 +176,7 @@ main(int argc, char **argv)
SHUTDOWN: SHUTDOWN:
burn_finish(); burn_finish();
iso_finish(); iso_finish();
e_dbus_shutdown();
ewl_shutdown(); ewl_shutdown();
ecore_file_shutdown(); ecore_file_shutdown();
ecore_config_shutdown(); ecore_config_shutdown();
@ -196,15 +214,6 @@ ecdb_setup(void)
ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY, ecdb_dnd_selection, ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY, ecdb_dnd_selection,
em); em);
eina_error_log_level_set(EINA_ERROR_LEVEL_DBG);
eina_error_print_cb_set(eina_error_print_cb_file, stderr);
if (!ecdb_aquire_drive_info())
{
EINA_ERROR_PERR("Aquiring drives failed!\n");
return FALSE;
}
if (!ecdb_initialize_config()) if (!ecdb_initialize_config())
{ {
EINA_ERROR_PERR("Initializing the configuration failed!\n"); EINA_ERROR_PERR("Initializing the configuration failed!\n");

View File

@ -15,6 +15,8 @@
#include <Efreet_Mime.h> #include <Efreet_Mime.h>
#include <Efreet.h> #include <Efreet.h>
#include <Ewl.h> #include <Ewl.h>
#include <E_DBus.h>
#include <E_Hal.h>
#include <libburn/libburn.h> #include <libburn/libburn.h>
#include <libisofs/libisofs.h> #include <libisofs/libisofs.h>
@ -63,6 +65,13 @@ struct _Ecdb_Main
* and leave it singular * and leave it singular
*/ */
Ecdb_Page *page; Ecdb_Page *page;
/* System dbus connection */
E_DBus_Connection *conn;
/* E_DBus signal handlers */
E_DBus_Signal_Handler *dev_added;
E_DBus_Signal_Handler *dev_removed;
}; };
extern Ecdb_Main *em; extern Ecdb_Main *em;
@ -89,6 +98,7 @@ extern unsigned int ECDB_FILELIST_SIZE_CHANGED;
#include "ecdb_filelist_custom.h" #include "ecdb_filelist_custom.h"
#include "ecdb_about.h" #include "ecdb_about.h"
#include "ecdb_config_dialog.h" #include "ecdb_config_dialog.h"
#include "ecdb_hal.h"
#endif #endif

View File

@ -216,7 +216,7 @@ _combo_cb_clicked(void *data, Evas_Object *obj __UNUSED__,
Evas_Object *b; Evas_Object *b;
Ecdb_Data_Project *proj; Ecdb_Data_Project *proj;
Ecdb_Project *base_proj; Ecdb_Project *base_proj;
int sel, i, num_speeds, speed; int sel, i, num_speeds;
char buf[1024]; char buf[1024];
proj = data; proj = data;
@ -245,24 +245,7 @@ _combo_cb_clicked(void *data, Evas_Object *obj __UNUSED__,
continue; continue;
b = ecdb_combo_item_add(ECDB_BURN(proj)->speed_combo, NULL); b = ecdb_combo_item_add(ECDB_BURN(proj)->speed_combo, NULL);
snprintf(buf, sizeof(buf), "%dkb/s", base_proj->drive->write_speeds[i]);
if ((base_proj->drive->profile_name) &&
(base_proj->drive->profile_name[0] != '\0'))
{
if (base_proj->drive->profile_name[0] == 'C')
speed = base_proj->drive->write_speeds[i] / 150;
else if (base_proj->drive->profile_name[0] == 'D')
speed = base_proj->drive->write_speeds[i] / 1352;
else
speed = base_proj->drive->write_speeds[i] / 4500;
}
else
{
speed = 0;
}
snprintf(buf, sizeof(buf), "%dX (%dkb/s)", speed,
base_proj->drive->write_speeds[i]);
ecdb_combo_item_label_set(b, buf); ecdb_combo_item_label_set(b, buf);
ecdb_combo_append(ECDB_BURN(proj)->speed_combo, b); ecdb_combo_append(ECDB_BURN(proj)->speed_combo, b);
evas_object_show(b); evas_object_show(b);

View File

@ -149,7 +149,7 @@ _combo_cb_clicked(void *data, Evas_Object *obj __UNUSED__,
Evas_Object *b; Evas_Object *b;
Ecdb_Burn_Project *bp; Ecdb_Burn_Project *bp;
Ecdb_Drive_Info *drive; Ecdb_Drive_Info *drive;
int sel, i, num_speeds, speed; int sel, i, num_speeds;
char buf[1024]; char buf[1024];
bp = data; bp = data;
@ -171,22 +171,7 @@ _combo_cb_clicked(void *data, Evas_Object *obj __UNUSED__,
continue; continue;
b = ecdb_combo_item_add(bp->speed_combo, NULL); b = ecdb_combo_item_add(bp->speed_combo, NULL);
snprintf(buf, sizeof(buf), "%dkb/s", drive->write_speeds[i]);
if ((drive->profile_name) && (drive->profile_name[0] != '\0'))
{
if (drive->profile_name[0] == 'C')
speed = drive->write_speeds[i] / 150;
else if (drive->profile_name[0] == 'D')
speed = drive->write_speeds[i] / 1352;
else
speed = drive->write_speeds[i] / 4500;
}
else
{
speed = 0;
}
snprintf(buf, sizeof(buf), "%dX (%dkb/s)", speed, drive->write_speeds[i]);
ecdb_combo_item_label_set(b, buf); ecdb_combo_item_label_set(b, buf);
ecdb_combo_append(bp->speed_combo, b); ecdb_combo_append(bp->speed_combo, b);
evas_object_show(b); evas_object_show(b);

View File

@ -48,28 +48,36 @@ typedef struct _Ecdb_Drive_Info Ecdb_Drive_Info;
struct _Ecdb_Drive_Info struct _Ecdb_Drive_Info
{ {
/* Speeds */ /* Speeds */
int *read_speeds;
int *write_speeds; int *write_speeds;
/* Profiles */
const char *profile_name;
int profile_loaded;
/* Drive info */ /* Drive info */
const char *vendor; char *vendor;
const char *product; char *product;
const char *revision; char *revision;
char *location; char *location;
char *udi;
unsigned char read_dvdram:1;
unsigned char read_dvdr:1;
unsigned char read_dvdrom:1;
unsigned char read_cdr:1;
unsigned char read_cdrw:1;
unsigned char write_dvdram:1;
unsigned char write_dvdr:1;
unsigned char write_cdr:1; unsigned char write_cdr:1;
unsigned char write_simulate:1; unsigned char write_cdrw:1;
unsigned char write_dvdr:1;
unsigned char write_dvdrw:1;
unsigned char write_dvdram:1;
unsigned char write_dvdplusr:1;
unsigned char write_dvdplusrw:1;
unsigned char write_dvdplusrwdl:1;
unsigned char write_dvdplusrdl:1;
unsigned char write_bdr:1;
unsigned char write_bdre:1;
unsigned char write_hddvdr:1;
unsigned char write_hddvdrw:1;
unsigned char support_multisession:1;
/* Mark this as being stale */
unsigned char fresh_info:1;
/* Capacity */ /* Capacity */
long long capacity; long long capacity;

View File

@ -1,86 +1,91 @@
/* vim: set sw=3 ts=3 sts=3 expandtab: */ /* vim: set sw=3 ts=3 sts=3 expandtab: */
#include "ecdb.h" #include "ecdb.h"
int void
ecdb_aquire_drive_info(void) _ecdb_drive_set_capabilities(Ecdb_Drive_Info *drive,
E_Hal_Device_Get_All_Properties_Return *ret)
{ {
int ret, i; Eina_List *write_speeds, *l;
unsigned int drive_num; char *val;
struct burn_drive_info *drives_current; int i;
struct burn_speed_descriptor *speeds;
ret = 0; /* Drive Capabilities */
if (em->drives) drive->write_cdr = e_hal_property_bool_get(ret, "storage.cdrom.cdr", NULL);
drive->write_cdrw = e_hal_property_bool_get(ret, "storage.cdrom.cdrw", NULL);
drive->write_dvdr = e_hal_property_bool_get(ret, "storage.cdrom.dvdr", NULL);
drive->write_dvdrw = e_hal_property_bool_get(ret,
"storage.cdrom.dvdrw", NULL);
drive->write_dvdram = e_hal_property_bool_get(ret,
"storage.cdrom.dvdram", NULL);
drive->write_dvdplusrw = e_hal_property_bool_get(ret,
"storage.cdrom.dvdplusrw", NULL);
drive->write_dvdplusrwdl = e_hal_property_bool_get(ret,
"storage.cdrom.dvdplusrwdl", NULL);
drive->write_dvdplusrdl = e_hal_property_bool_get(ret,
"storage.cdrom.dvdplusrdl", NULL);
drive->write_bdr = e_hal_property_bool_get(ret, "storage.cdrom.bdr", NULL);
drive->write_bdre = e_hal_property_bool_get(ret, "storage.cdrom.bdre", NULL);
drive->write_hddvdr = e_hal_property_bool_get(ret,
"storage.cdrom.hddvdr", NULL);
drive->write_hddvdrw = e_hal_property_bool_get(ret,
"storage.cdrom.hddvdrw", NULL);
drive->support_multisession = e_hal_property_bool_get(ret,
"storage.cdrom.support_multisession",
NULL);
/* Write speeds */
write_speeds = e_hal_property_strlist_get(ret, "storage.cdrom.write_speeds",
NULL);
drive->write_speeds = calloc(eina_list_count(write_speeds) + 1, sizeof(int));
drive->write_speeds[0] = eina_list_count(write_speeds) + 1;
i = 1;
EINA_LIST_FOREACH(write_speeds, l, val)
{ {
ecdb_drive_info_list_free(em->drives); drive->write_speeds[i] = atoi(val);
i++;
}
}
int
ecdb_update_drive_info(Ecdb_Drive_Info *drive,
E_Hal_Device_Get_All_Properties_Return *ret,
char *udi)
{
/* Assume that nothing about the physical hardware has changed */
drive->udi = udi;
/* Update the drive directories */
FREE(drive->write_speeds);
_ecdb_drive_set_capabilities(drive, ret);
return TRUE;
}
int
ecdb_aquire_drive_info(E_Hal_Device_Get_All_Properties_Return *ret,
char *mnt, char *udi)
{
Ecdb_Drive_Info *drive;
drive = calloc(1, sizeof(Ecdb_Drive_Info));
if (!drive)
{
return FALSE;
} }
while (!ret) /* General Info */
{ drive->vendor = e_hal_property_string_get(ret, "storage.vendor", NULL);
ret = burn_drive_scan(&drives_current, &drive_num); drive->product = e_hal_property_string_get(ret, "storage.model", NULL);
} drive->revision = e_hal_property_string_get(ret,
"storage.firmware_revision", NULL);
drive->location = mnt;
drive->udi = udi;
for (i = 0; i < drive_num; i++) /* Update current directories */
{ _ecdb_drive_set_capabilities(drive, ret);
Ecdb_Drive_Info *drive;
drive = calloc(1, sizeof(Ecdb_Drive_Info)); em->drives = eina_list_append(em->drives, drive);
if (!drive)
{
return FALSE;
}
drive->product = eina_stringshare_add(drives_current[i].product);
drive->vendor = eina_stringshare_add(drives_current[i].vendor);
drive->revision = eina_stringshare_add(drives_current[i].revision);
drive->location = strdup(drives_current[i].location);
drive->read_dvdram = drives_current[i].read_dvdram;
drive->read_dvdr = drives_current[i].read_dvdr;
drive->read_dvdrom = drives_current[i].read_dvdrom;
drive->read_cdr = drives_current[i].read_cdr;
drive->read_cdrw = drives_current[i].read_cdrw;
drive->write_dvdram = drives_current[i].write_dvdram;
drive->write_dvdr = drives_current[i].write_dvdr;
drive->write_cdr = drives_current[i].write_cdr;
drive->write_simulate = drives_current[i].write_simulate;
burn_drive_get_speedlist(drives_current[i].drive, &speeds);
drive->profile_name = eina_stringshare_add(speeds->profile_name);
drive->profile_loaded = speeds->profile_loaded;
if (burn_drive_grab(drives_current[i].drive, 1))
{
drive->capacity = burn_disc_available_space(drives_current[i].drive,
NULL);
burn_drive_release(drives_current[i].drive, 0);
}
while (speeds->next)
{
i++;
speeds = speeds->next;
}
drive->read_speeds = calloc(i + 2, sizeof(int));
drive->write_speeds = calloc(i + 2, sizeof(int));
drive->read_speeds[0] = i + 1;
drive->write_speeds[0] = i + 1;
for (ret = 1; ret <= i; ret++)
{
drive->write_speeds[ret] = speeds->write_speed;
drive->read_speeds[ret] = speeds->read_speed;
speeds = speeds->prev;
}
burn_drive_free_speedlist(&speeds);
em->drives = eina_list_append(em->drives, drive);
}
burn_drive_info_free(drives_current);
return TRUE; return TRUE;
} }
@ -92,14 +97,16 @@ ecdb_drive_info_list_free(Eina_List *list)
EINA_LIST_FREE(list, info) EINA_LIST_FREE(list, info)
{ {
FREE(info->read_speeds); if (!info)
continue;
FREE(info->write_speeds); FREE(info->write_speeds);
FREE(info->vendor);
FREE(info->product);
FREE(info->revision);
FREE(info->location); FREE(info->location);
eina_stringshare_del(info->vendor); FREE(info->udi);
eina_stringshare_del(info->product); free(info);
eina_stringshare_del(info->revision);
eina_stringshare_del(info->profile_name);
FREE(info);
} }
} }
@ -108,7 +115,7 @@ ecdb_print_drive_info(void)
{ {
Eina_List *l; Eina_List *l;
Ecdb_Drive_Info *drive; Ecdb_Drive_Info *drive;
int j, i, h; int j, i;
em->drives = eina_list_nth_list(em->drives, 0); em->drives = eina_list_nth_list(em->drives, 0);
EINA_LIST_FOREACH(em->drives, l, drive) EINA_LIST_FOREACH(em->drives, l, drive)
@ -118,35 +125,31 @@ ecdb_print_drive_info(void)
"Location: %s\n", "Location: %s\n",
drive->vendor, drive->product, drive->vendor, drive->product,
drive->revision, drive->location); drive->revision, drive->location);
printf("Profile name: %s, Loaded: %d\n", printf("Write CD-R: %d, Write CD-RW: %d\n",
drive->profile_name,
drive->profile_loaded);
printf("Read DVDRAM: %d, Read DVDR: %d, Read DVDROM: %d, "
"Read CDR: %d, Read CDRW: %d\n",
drive->read_dvdram,
drive->read_dvdr,
drive->read_dvdrom,
drive->read_cdr,
drive->read_cdrw);
printf("Write DVDRAM: %d, Write DVDR: %d, Write CDR: %d, "
"Write Simulate: %d\n",
drive->write_dvdram,
drive->write_dvdr,
drive->write_cdr, drive->write_cdr,
drive->write_simulate); drive->write_cdrw);
printf("Write DVD-R: %d, Write DVD-RW: %d, Write DVD-RAM: %d\n",
drive->write_dvdr,
drive->write_dvdrw,
drive->write_dvdram);
printf("Write DVD+R: %d, Write DVD+RW: %d, Write DVD+RWDL: %d\n",
drive->write_dvdplusr,
drive->write_dvdplusrw,
drive->write_dvdplusrwdl);
printf("Write DVD+DL: %d\n",
drive->write_dvdplusrdl);
printf("Write BR-R: %d, Write BR-RW: %d\n",
drive->write_bdr,
drive->write_bdre);
printf("Write HDDVD-R: %d, Write HDDVD-RW: %d\n",
drive->write_hddvdr,
drive->write_hddvdrw);
j = drive->read_speeds[0]; j = drive->write_speeds[0];
for (i = 1; i < j; i ++) for (i = 1; i < j; i ++)
{ {
if ((h = drive->write_speeds[i])) printf("Write: %d\n", drive->write_speeds[i]);
{
printf("Write: %d\n", h);
}
if ((h = drive->read_speeds[i]))
{
printf("Read: %d\n", h);
}
} }
} }
} }

View File

@ -2,7 +2,11 @@
#ifndef ECDB_DRIVES_H #ifndef ECDB_DRIVES_H
#define ECDB_DRIVES_H #define ECDB_DRIVES_H
int ecdb_aquire_drive_info(void); int ecdb_aquire_drive_info(E_Hal_Device_Get_All_Properties_Return *ret,
char *mnt, char *udi);
int ecdb_update_drive_info(Ecdb_Drive_Info *drive,
E_Hal_Device_Get_All_Properties_Return *ret,
char *udi);
void ecdb_print_drive_info(void); void ecdb_print_drive_info(void);
int ecdb_aquire_drive(Ecdb_Project *proj, unsigned int idx); int ecdb_aquire_drive(Ecdb_Project *proj, unsigned int idx);
void ecdb_drive_info_list_free(Eina_List *list); void ecdb_drive_info_list_free(Eina_List *list);

View File

@ -0,0 +1,253 @@
/* vim: set sw=3 ts=3 sts=3 expandtab: */
#include "ecdb.h"
void _ecdb_hal_device_all_cb(void *data, void *reply_data, DBusError *error);
void _ecdb_hal_device_handle(void *data, void *reply_data, DBusError *error);
void _ecdb_hal_volume_removed_cb(void *data, DBusMessage *msg);
void _ecdb_hal_volume_added_cb(void *data, DBusMessage *msg);
void _ecdb_hal_volume_cb(void *data, void *reply_data, DBusError *error);
void _ecdb_hal_volume_handle(void *data, void *reply_data, DBusError *error);
void _ecdb_hal_unmount_cb(void *data, void *reply_data, DBusError *error);
void
_ecdb_hal_volume_handle(void *data, void *reply_data, DBusError *error)
{
E_Hal_Device_Get_All_Properties_Return *ret;
char *udi, *str;
int err;
ret = reply_data;
udi = data;
if ((!ret) || (!udi))
{
EINA_ERROR_PWARN("NULL udi or reply!\n");
return;
}
if (dbus_error_is_set(error))
{
/* XXX Handle this error here */
dbus_error_free(error);
return;
}
if ((e_hal_property_bool_get(ret, "volume.is_disc", &err)) && (!err))
{
str = e_hal_property_string_get(ret, "info.parent", &err);
if ((str) && (!err))
{
e_hal_device_get_all_properties(em->conn, str, _ecdb_hal_device_handle,
str);
}
}
FREE(udi);
}
void
_ecdb_hal_device_handle(void *data, void *reply_data, DBusError *error)
{
E_Hal_Device_Get_All_Properties_Return *ret;
Eina_List *l;
Ecdb_Drive_Info *drive;
char *udi, *str;
int err = 0;
ret = reply_data;
udi = data;
if ((!ret) || (!udi))
{
EINA_ERROR_PWARN("NULL udi or reply!\n");
return;
}
if (dbus_error_is_set(error))
{
/* XXX Handle this here */
dbus_error_free(error);
return;
}
str = e_hal_property_string_get(ret, "block.device", &err);
if (!str)
return;
if (!err)
{
EINA_LIST_FOREACH(em->drives, l, drive)
{
if (!strcmp(drive->location, str))
{
if (!ecdb_update_drive_info(drive, ret, udi))
EINA_ERROR_PWARN("Couldn't update old drive info!\n");
printf("Recreating old...\n");
ecdb_print_drive_info();
return;
}
}
/*
* Create the drive information here, as we will have already
* returned if it previously exists
*/
if (!ecdb_aquire_drive_info(ret, str, udi))
{
EINA_ERROR_PWARN("Couldn't create new drive info!\n");
return;
}
printf("Creating new...\n");
ecdb_print_drive_info();
}
}
void
_ecdb_hal_device_removed_cb(void *data __UNUSED__, DBusMessage *msg)
{
DBusError err;
Eina_List *l;
Ecdb_Drive_Info *drive;
char *udi;
dbus_error_init(&err);
dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi,
DBUS_TYPE_INVALID);
printf("Removed: %s\n", udi);
/*
* 1. Find the drive that has been removed.
* 2. Update it with libburn
*/
}
void
_ecdb_hal_device_added_cb(void *data __UNUSED__, DBusMessage *msg)
{
DBusError err;
char *udi;
dbus_error_init(&err);
dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi,
DBUS_TYPE_INVALID);
/* XXX Do something with the error above? */
e_hal_device_query_capability(em->conn, udi, "volume",
_ecdb_hal_volume_cb,
(void *)strdup(udi));
}
void
_ecdb_hal_volume_cb(void *data, void *reply_data, DBusError *error)
{
char *udi;
E_Hal_Device_Query_Capability_Return *ret;
udi = data;
ret = reply_data;
if (!ret)
return;
if (dbus_error_is_set(error))
{
/* XXX Handle this here */
dbus_error_free(error);
return;
}
if (ret->boolean)
{
e_hal_device_get_all_properties(em->conn, udi, _ecdb_hal_device_handle,
udi);
}
}
void
_ecdb_hal_device_all_cb(void *data, void *reply_data, DBusError *error)
{
char *udi;
Eina_List *l;
E_Hal_Manager_Find_Device_By_Capability_Return *ret;
udi = data;
ret = reply_data;
if ((!ret) || (!ret->strings))
return;
if (dbus_error_is_set(error))
{
/* XXX Handle this here */
dbus_error_free(error);
return;
}
EINA_LIST_FOREACH(ret->strings, l, udi)
{
e_hal_device_get_all_properties(em->conn, udi, _ecdb_hal_device_handle,
(void *)strdup(udi));
}
}
int
ecdb_hal_init(void)
{
em->conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
if (!em->conn)
{
EINA_ERROR_PWARN("Error connecting to system bus!\n");
return 0;
}
em->dev_added = e_dbus_signal_handler_add(em->conn, "org.freedesktop.Hal",
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
"DeviceAdded",
_ecdb_hal_device_added_cb, NULL);
em->dev_removed = e_dbus_signal_handler_add(em->conn,
"org.freedesktop.Hal",
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
"DeviceRemoved",
_ecdb_hal_device_removed_cb, NULL);
e_hal_manager_find_device_by_capability(em->conn, "storage.cdrom",
_ecdb_hal_device_all_cb, NULL);
return 1;
}
void
ecdb_hal_shutdown(void)
{
e_dbus_signal_handler_del(em->conn, em->dev_added);
e_dbus_signal_handler_del(em->conn, em->dev_removed);
e_dbus_connection_close(em->conn);
}
void
ecdb_hal_request_unmount(Ecdb_Drive_Info *drive)
{
e_hal_device_volume_unmount(em->conn, drive->udi, NULL,
_ecdb_hal_unmount_cb, drive);
}
void
_ecdb_hal_unmount_cb(void *data, void *reply_data __UNUSED__, DBusError *error)
{
Ecdb_Drive_Info *drive;
drive = data;
if (dbus_error_is_set(error))
{
EINA_ERROR_PWARN("Cannot unmount volume!\n");
dbus_error_free(error);
}
}

View File

@ -0,0 +1,9 @@
/* vim: set sw=3 ts=3 sts=3 expandtab: */
#ifndef ECDB_HAL_H
#define ECDB_HAL_H
int ecdb_hal_init(void);
void ecdb_hal_shutdown(void);
void ecdb_hal_request_unmount(Ecdb_Drive_Info *drive);
#endif

View File

@ -22,6 +22,8 @@ ecdb_shutdown(void *data, int type, void *event)
eina_list_free(em->ewl_dnd_candidates); eina_list_free(em->ewl_dnd_candidates);
} }
ecdb_hal_shutdown();
FREE(em); FREE(em);
if (!ecore_file_recursive_rm("/tmp/ecdb")) if (!ecore_file_recursive_rm("/tmp/ecdb"))