[Xfce4-commits] r24037 - in xfburn/branches/libburn_trial: . xfburn

Jean-François Wauthy pollux at xfce.org
Sun Dec 3 19:35:23 CET 2006


Author: pollux
Date: 2006-12-03 18:35:22 +0000 (Sun, 03 Dec 2006)
New Revision: 24037

Modified:
   xfburn/branches/libburn_trial/configure.in.in
   xfburn/branches/libburn_trial/xfburn/Makefile.am
   xfburn/branches/libburn_trial/xfburn/xfburn-device-list.c
   xfburn/branches/libburn_trial/xfburn/xfburn-device-list.h
   xfburn/branches/libburn_trial/xfburn/xfburn-main.c
   xfburn/branches/libburn_trial/xfburn/xfburn-preferences-dialog.c
   xfburn/branches/libburn_trial/xfburn/xfburn-preferences-dialog.h
Log:
use libburn to detect devices

Modified: xfburn/branches/libburn_trial/configure.in.in
===================================================================
--- xfburn/branches/libburn_trial/configure.in.in	2006-12-03 15:58:41 UTC (rev 24036)
+++ xfburn/branches/libburn_trial/configure.in.in	2006-12-03 18:35:22 UTC (rev 24037)
@@ -23,28 +23,12 @@
 AC_PROG_LIBTOOL()
 AC_PROG_INTLTOOL([0.31], [no-xml])
 
-dnl check for needed programs
-AC_CHECK_PROG(cdrecord_found, [cdrecord], yes, no)
-if test x"$cdrecord_found" = x"no"; then
-  AC_MSG_ERROR([You need cdrecord to be able to write CDs with xfburn])
-fi
-AC_CHECK_PROG(readcd_found, [readcd], yes, no)
-if test x"$readcd_found" = x"no"; then
-  AC_MSG_ERROR([You need readcd to be able to create ISOs with xfburn])
-fi
-AC_CHECK_PROG(cdrdao_found, [cdrdao], yes, no)
-if test x"$cdrdao_found" = x"no"; then
-  AC_MSG_ERROR([You need cdrdao to be able to copy CDs with xfburn])
-fi
-AC_CHECK_PROG(mkisofs_found, [mkisofs], yes, no)
-if test x"$mkisofs_found" = x"no"; then
-  AC_MSG_ERROR([You need mkisofs to be able to create ISOs with xfburn])
-fi
-
 dnl check for i18n support
 XDT_I18N([@LINGUAS@])
 
 dnl check for required packages
+XDT_CHECK_PACKAGE([LIBBURN], [libburn-1], [0.2.6.1])
+XDT_CHECK_PACKAGE([LIBISOFS], [libisofs-1], [0.2.3])
 XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.6.0])
 XDT_CHECK_PACKAGE([LIBXFCEGUI4], [libxfcegui4-1.0], [4.3.90])
 XDT_CHECK_PACKAGE([EXO], [exo-0.3], [0.3.0])

Modified: xfburn/branches/libburn_trial/xfburn/Makefile.am
===================================================================
--- xfburn/branches/libburn_trial/xfburn/Makefile.am	2006-12-03 15:58:41 UTC (rev 24036)
+++ xfburn/branches/libburn_trial/xfburn/Makefile.am	2006-12-03 18:35:22 UTC (rev 24037)
@@ -76,11 +76,15 @@
 	xfburn-write-mode-combo-box.c				
 
 xfburn_CFLAGS =								\
+	$(LIBBURN_CFLAGS)						\
+	$(LIBISOFS_CFLAGS)						\
 	$(LIBXFCEGUI4_CFLAGS)						\
 	$(EXO_CFLAGS)							\
-	$(THUNAR_VFS_CFLAGS)
+	$(THUNAR_VFS_CFLAGS)						
 
 xfburn_LDFLAGS = 							\
+	$(LIBBURN_LIBS)							\
+	$(LIBISOFS_LIBS)						\
 	$(LIBXFCEGUI4_LIBS)						\
 	$(EXO_LIBS)							\
 	$(THUNAR_VFS_LIBS)

Modified: xfburn/branches/libburn_trial/xfburn/xfburn-device-list.c
===================================================================
--- xfburn/branches/libburn_trial/xfburn/xfburn-device-list.c	2006-12-03 15:58:41 UTC (rev 24036)
+++ xfburn/branches/libburn_trial/xfburn/xfburn-device-list.c	2006-12-03 18:35:22 UTC (rev 24037)
@@ -29,12 +29,10 @@
 #include <libxfce4util/libxfce4util.h>
 
 #include <stdlib.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <linux/cdrom.h>
+#include <unistd.h>
 
+#include <libburn.h>
+
 #include "xfburn-device-list.h"
 
 /* private */
@@ -46,164 +44,13 @@
 static void
 device_content_free (XfburnDevice * device, gpointer user_data)
 {
+  burn_drive_info_forget (device->drive_info, 1);
+  burn_drive_info_free (device->drive_info);
+
   g_free (device->name);
-  g_free (device->id);
   g_free (device->node_path);
 }
 
-static gchar **
-get_file_as_list (const gchar * file)
-{
-  /* from GnomeBaker */
-  gchar **ret = NULL;
-  gchar *contents = NULL;
-
-  g_return_val_if_fail (file != NULL, NULL);
-  if (g_file_get_contents (file, &contents, NULL, NULL))
-    ret = g_strsplit (contents, "\n", 0);
-  else
-    g_critical ("Failed to get contents of file [%s]", file);
-
-  g_free (contents);
-  return ret;
-}
-
-static GHashTable *
-get_cdrominfo (gchar ** proccdrominfo, gint deviceindex)
-{
-  /* from GnomeBaker */
-  GHashTable *ret = NULL;
-  gchar **info = proccdrominfo;
-
-  g_return_val_if_fail (proccdrominfo != NULL, NULL);
-  g_return_val_if_fail (deviceindex >= 1, NULL);
-
-  g_message ("looking for device [%d]", deviceindex);
-
-  while (*info != NULL) {
-    g_strstrip (*info);
-    if (strlen (*info) > 0) {
-      if (strstr (*info, "drive name:") != NULL)
-        ret = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
-
-      if (ret != NULL) {
-        gint columnindex = 0;
-        gchar *key = NULL;
-        gchar **columns = g_strsplit_set (*info, "\t", 0);
-        gchar **column = columns;
-        while (*column != NULL) {
-          g_strstrip (*column);
-          if (strlen (*column) > 0) {
-            if (columnindex == 0)
-              key = *column;
-            else if (columnindex == deviceindex)
-              g_hash_table_insert (ret, g_strdup (key), g_strdup (*column));
-            ++columnindex;
-          }
-          ++column;
-        }
-
-        /* We must check if we found the device index we were
-           looking for */
-        if (columnindex <= deviceindex) {
-          g_message ("Requested device index [%d] is out of bounds. " "All devices have been read.", deviceindex);
-          g_hash_table_destroy (ret);
-          ret = NULL;
-
-	  g_strfreev (columns);
-          break;
-        }
-
-        g_strfreev (columns);
-      }
-    }
-    ++info;
-  }
-
-  return ret;
-}
-
-static void
-get_ide_device (const gchar * devicenode, const gchar * devicenodepath, gchar ** modelname, gchar ** deviceid)
-{
-  /* from GnomeBaker */
-  gchar *contents = NULL;
-  gchar *file = g_strdup_printf ("/proc/ide/%s/model", devicenode);
-
-  g_return_if_fail (devicenode != NULL);
-  g_return_if_fail (modelname != NULL);
-  g_return_if_fail (deviceid != NULL);
-
-  if (g_file_get_contents (file, &contents, NULL, NULL)) {
-    g_strstrip (contents);
-    *modelname = g_strdup (contents);
-    *deviceid = g_strdup (devicenodepath);
-    g_free (contents);
-  }
-  else {
-    g_critical ("Failed to open %s", file);
-  }
-  g_free (file);
-}
-
-
-static void
-get_scsi_device (const gchar * devicenode, const gchar * devicenodepath, gchar ** modelname, gchar ** deviceid)
-{
-  /* from GnomeBaker */
-  gchar **device_strs = NULL, **devices = NULL;
-
-  g_return_if_fail (devicenode != NULL);
-  g_return_if_fail (modelname != NULL);
-  g_return_if_fail (deviceid != NULL);
-  DBG ("probing [%s]", devicenode);
-
-  if ((devices = get_file_as_list ("/proc/scsi/sg/devices")) == NULL) {
-    g_critical (_("Failed to open /proc/scsi/sg/devices"));
-  }
-  else if ((device_strs = get_file_as_list ("/proc/scsi/sg/device_strs")) == NULL) {
-    g_critical (_("Failed to open /proc/scsi/sg/device_strs"));
-  }
-  else {
-    const gint scsicdromnum = atoi (&devicenode[strlen (devicenode) - 1]);
-    gint cddevice = 0;
-    gchar **device = devices;
-    gchar **device_str = device_strs;
-    while ((*device != NULL) && (*device_str) != NULL) {
-      if ((strcmp (*device, "<no active device>") != 0) && (strlen (*device) > 0)) {
-        gint scsihost, scsiid, scsilun, scsitype;
-        if (sscanf (*device, "%d\t%*d\t%d\t%d\t%d", &scsihost, &scsiid, &scsilun, &scsitype) != 4) {
-          g_critical (_("Error reading scsi information from /proc/scsi/sg/devices"));
-        }
-        /* 5 is the magic number according to lib-nautilus-burn */
-        else if (scsitype == 5) {
-          /* is the device the one we are looking for */
-          if (cddevice == scsicdromnum) {
-            gchar vendor[9], model[17];
-            if (sscanf (*device_str, "%8c\t%16c", vendor, model) == 2) {
-              vendor[8] = '\0';
-              g_strstrip (vendor);
-
-              model[16] = '\0';
-              g_strstrip (model);
-
-              *modelname = g_strdup_printf ("%s %s", vendor, model);
-              *deviceid = g_strdup_printf ("%d,%d,%d", scsihost, scsiid, scsilun);
-              break;
-            }
-          }
-          ++cddevice;
-        }
-      }
-      ++device_str;
-      ++device;
-    }
-  }
-
-  g_strfreev (devices);
-  g_strfreev (device_strs);
-}
-
 /**************/
 /* public API */
 /**************/
@@ -212,69 +59,36 @@
 {
   return devices;
 }
-  
+
 void
 xfburn_device_list_init ()
 {
-  /* adapted from GnomeBaker */
-  gchar **info = NULL;
+  struct burn_drive_info *drives;
+  gint i;
+  guint n_drives = 0;
 
-  /* clear current devices list */
-  g_list_foreach (devices, (GFunc) xfburn_device_free, NULL);
-  g_list_free (devices);
-  devices = NULL;
-
-#ifdef __linux__
-  if (!(info = get_file_as_list ("/proc/sys/dev/cdrom/info"))) {
-    g_critical ("Failed to open /proc/sys/dev/cdrom/info");
+  if (devices) {
+    g_list_foreach (devices, (GFunc) device_content_free, NULL);
+    g_list_free (devices);
+    devices = NULL;
   }
-  else {
-    gint devicenum = 1;
-    GHashTable *devinfo = NULL;
 
-    while ((devinfo = get_cdrominfo (info, devicenum)) != NULL) {
-      XfburnDevice *device_entry;
-      const gchar *device = g_hash_table_lookup (devinfo, "drive name:");
-      gchar *devicenodepath = g_strdup_printf ("/dev/%s", device);
+  while (!burn_drive_scan (&drives, &n_drives))
+    usleep (1002);
 
-      gchar *modelname = NULL, *deviceid = NULL;
+  for (i = 0; i < n_drives; i++) {
+    XfburnDevice *device = g_new0 (XfburnDevice, 1);
 
-      if (device[0] == 'h')
-        get_ide_device (device, devicenodepath, &modelname, &deviceid);
-      else
-        get_scsi_device (device, devicenodepath, &modelname, &deviceid);
-
-      device_entry = g_new0 (XfburnDevice, 1);
-      device_entry->name = modelname;
-      device_entry->id = deviceid;
-      device_entry->node_path = devicenodepath;
-
-      if (g_ascii_strcasecmp (g_hash_table_lookup (devinfo, "Can write CD-R:"), "1") == 0)
-        device_entry->cdr = TRUE;
-      if (g_ascii_strcasecmp (g_hash_table_lookup (devinfo, "Can write CD-RW:"), "1") == 0)
-        device_entry->cdrw = TRUE;
-      if (g_ascii_strcasecmp (g_hash_table_lookup (devinfo, "Can write DVD-R:"), "1") == 0)
-        device_entry->dvdr = TRUE;
-      if (g_ascii_strcasecmp (g_hash_table_lookup (devinfo, "Can write DVD-RAM:"), "1") == 0)
-        device_entry->dvdram = TRUE;
-
-      devices = g_list_prepend (devices, device_entry);
-
-      g_message ("device [%d] found : %s (%s)", devicenum, modelname, devicenodepath);
-      g_message ("device [%d] capabilities :%s%s%s%s", devicenum, device_entry->cdr ? " CD-R" : "",
-                 device_entry->cdrw ? " CD-RW" : "", device_entry->dvdr ? " DVD-R" : "",
-                 device_entry->dvdram ? " DVD-RAM" : "");
-
-      g_hash_table_destroy (devinfo);
-      devinfo = NULL;
-      ++devicenum;
-    }
+    device->name = g_strconcat (drives[i].vendor, " ", drives[i].product, NULL);
+    device->node_path = g_strdup (drives[i].location);
+    device->cdr = drives[i].write_cdr;
+    device->cdrw = drives[i].write_cdrw;
+    device->dvdr = drives[i].write_dvdr;
+    device->dvdram = drives[i].write_dvdram;
+    device->drive_info = &(drives[i]);
+     
+    devices = g_list_append (devices, device);
   }
-
-  g_strfreev (info);
-#else
-#error this program currently supports only Linux sorry :-(
-#endif
 }
 
 void
@@ -304,47 +118,6 @@
   return NULL;
 }
 
-
-/* CDS_NO_DISC
- * CDS_TRAY_OPEN
- * CDS_DRIVE_NOT_READY
- * CDS_DISC_OK
- */
-gint
-xfburn_device_query_cdstatus (XfburnDevice * device)
-{
-  int fd, ret;
-   
-  /* adapted from GnomeBaker */
-  g_return_val_if_fail (device != NULL, FALSE);
-
-  fd = open (device->node_path, O_RDONLY | O_NONBLOCK);
-
-  ret = ioctl (fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
-  
-  
-  if (ret == -1)
-    g_critical ("xfburn_device_query_cdstatus - ioctl failed");
-  
-  return ret;
-}
-
-gchar *
-xfburn_device_cdstatus_to_string (gint status)
-{
-  gchar *message = NULL;
-  
-  switch (status) {
-    case CDS_NO_DISC:
-      message = g_strdup (_("No disc in the cdrom drive"));
-    break;
-    default:
-      message = g_strdup (_("No message..."));
-  }
-  
-  return message;
-}
-
 void
 xfburn_device_list_free ()
 {

Modified: xfburn/branches/libburn_trial/xfburn/xfburn-device-list.h
===================================================================
--- xfburn/branches/libburn_trial/xfburn/xfburn-device-list.h	2006-12-03 15:58:41 UTC (rev 24036)
+++ xfburn/branches/libburn_trial/xfburn/xfburn-device-list.h	2006-12-03 18:35:22 UTC (rev 24037)
@@ -24,15 +24,18 @@
 #include <config.h>
 #endif
 
+#include <libburn.h>
+
 typedef struct
 {
   gchar *name;
-  gchar *id;
   gchar *node_path;
   gboolean cdr;
   gboolean cdrw;
   gboolean dvdr;
   gboolean dvdram;
+
+  struct burn_drive_info *drive_info;
 } XfburnDevice;
 
 void xfburn_device_list_init ();
@@ -40,9 +43,6 @@
 GList * xfburn_device_list_get_list ();
 void xfburn_device_list_free ();
 
-gint xfburn_device_query_cdstatus (XfburnDevice * device);
-gchar * xfburn_device_cdstatus_to_string (gint status);
-
 void xfburn_device_free (XfburnDevice * device);
 
 #endif /* __XFBURN_DEVICE_LIST_H__ */

Modified: xfburn/branches/libburn_trial/xfburn/xfburn-main.c
===================================================================
--- xfburn/branches/libburn_trial/xfburn/xfburn-main.c	2006-12-03 15:58:41 UTC (rev 24036)
+++ xfburn/branches/libburn_trial/xfburn/xfburn-main.c	2006-12-03 18:35:22 UTC (rev 24037)
@@ -32,6 +32,8 @@
 #include <libxfce4util/libxfce4util.h>
 #include <libxfcegui4/libxfcegui4.h>
 
+#include <libburn.h>
+
 #ifdef HAVE_THUNAR_VFS
 #include <thunar-vfs/thunar-vfs.h>
 #endif
@@ -50,7 +52,7 @@
   GtkWidget *mainwin;
 
 #if DEBUG > 0
-  g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
+  g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
 #endif
   
   g_set_application_name (_("Xfburn"));
@@ -63,6 +65,7 @@
     exit (EXIT_SUCCESS);
   }
 
+  burn_initialize ();
   gtk_init (&argc, &argv);
 
   xfburn_settings_init ();
@@ -93,5 +96,6 @@
   
   xfburn_device_list_free ();
 
+  burn_finish ();
   return EXIT_SUCCESS;
 }

Modified: xfburn/branches/libburn_trial/xfburn/xfburn-preferences-dialog.c
===================================================================
--- xfburn/branches/libburn_trial/xfburn/xfburn-preferences-dialog.c	2006-12-03 15:58:41 UTC (rev 24036)
+++ xfburn/branches/libburn_trial/xfburn/xfburn-preferences-dialog.c	2006-12-03 18:35:22 UTC (rev 24037)
@@ -60,6 +60,18 @@
   SETTINGS_LIST_N_COLUMNS,
 };
 
+enum
+{
+  DEVICE_LIST_COLUMN_ICON,
+  DEVICE_LIST_COLUMN_NAME,
+  DEVICE_LIST_COLUMN_NODE,
+  DEVICE_LIST_COLUMN_CDR,
+  DEVICE_LIST_COLUMN_CDRW,
+  DEVICE_LIST_COLUMN_DVDR,
+  DEVICE_LIST_COLUMN_DVDRAM,
+  DEVICE_LIST_N_COLUMNS
+};
+
 typedef struct
 {
   XfburnPreferencesDialog *object;
@@ -231,7 +243,7 @@
   gtk_box_pack_start (GTK_BOX (vbox2), scrolled_window, TRUE, TRUE, BORDER);
 
   store = gtk_list_store_new (DEVICE_LIST_N_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING,
-                              G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
+                              G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
   priv->treeview_devices = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
   gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), DEVICE_LIST_COLUMN_NAME, GTK_SORT_ASCENDING);
   gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (priv->treeview_devices), TRUE);
@@ -254,8 +266,6 @@
   gtk_tree_view_column_set_attributes (column_name, cell_name, "text", DEVICE_LIST_COLUMN_NAME, NULL);
 
   gtk_tree_view_append_column (GTK_TREE_VIEW (priv->treeview_devices), column_name);
-  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->treeview_devices), -1, _("Id"),
-                                               gtk_cell_renderer_text_new (), "text", DEVICE_LIST_COLUMN_ID, NULL);
   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->treeview_devices), -1, _("Node"),
                                                gtk_cell_renderer_text_new (), "text", DEVICE_LIST_COLUMN_NODE, NULL);
   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->treeview_devices), -1, _("Write CD-R"),
@@ -367,7 +377,6 @@
     gtk_list_store_append (GTK_LIST_STORE (model), &iter);
     gtk_list_store_set (GTK_LIST_STORE (model), &iter,
                         DEVICE_LIST_COLUMN_NAME, device_data->name,
-                        DEVICE_LIST_COLUMN_ID, device_data->id,
                         DEVICE_LIST_COLUMN_NODE, device_data->node_path,
                         DEVICE_LIST_COLUMN_CDR, device_data->cdr,
                         DEVICE_LIST_COLUMN_CDRW, device_data->cdrw,

Modified: xfburn/branches/libburn_trial/xfburn/xfburn-preferences-dialog.h
===================================================================
--- xfburn/branches/libburn_trial/xfburn/xfburn-preferences-dialog.h	2006-12-03 15:58:41 UTC (rev 24036)
+++ xfburn/branches/libburn_trial/xfburn/xfburn-preferences-dialog.h	2006-12-03 18:35:22 UTC (rev 24037)
@@ -42,19 +42,8 @@
   /* Add Signal Functions Here */
 } XfburnPreferencesDialogClass;
 
-enum
-{
-  DEVICE_LIST_COLUMN_ICON,
-  DEVICE_LIST_COLUMN_NAME,
-  DEVICE_LIST_COLUMN_ID,
-  DEVICE_LIST_COLUMN_NODE,
-  DEVICE_LIST_COLUMN_CDR,
-  DEVICE_LIST_COLUMN_CDRW,
-  DEVICE_LIST_COLUMN_DVDR,
-  DEVICE_LIST_COLUMN_DVDRAM,
-  DEVICE_LIST_N_COLUMNS
-};
 
+
 GtkType xfburn_preferences_dialog_get_type ();
 GtkWidget *xfburn_preferences_dialog_new ();
 



More information about the Xfce4-commits mailing list