[Goodies-commits] r2861 - xfce4-cddrive-plugin/trunk/panel-plugin

Sylvain Reynal syl at xfce.org
Tue Jun 26 08:17:49 CEST 2007


Author: syl
Date: 2007-06-26 06:17:49 +0000 (Tue, 26 Jun 2007)
New Revision: 2861

Modified:
   xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-cddb.c
Log:
- add CD-TEXT support
- use cdio_open instead of cdio_open_cd to hopefully extends the range of supported audio CD

Modified: xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-cddb.c
===================================================================
--- xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-cddb.c	2007-06-26 06:08:59 UTC (rev 2860)
+++ xfce4-cddrive-plugin/trunk/panel-plugin/cddrive-cddb.c	2007-06-26 06:17:49 UTC (rev 2861)
@@ -122,6 +122,45 @@
 
 
 
+static CdIo_t*
+cddrive_cddb_new_cdio (const gchar* device)
+{
+  CdIo_t     *res;
+
+  res = cdio_open (device, DRIVER_DEVICE);
+  if (res == NULL)
+    g_warning ("unable to open CDDA in drive '%s'.", device);
+  
+  else
+    {
+      if (cdio_get_discmode (res) == CDIO_DISC_MODE_ERROR ||
+          cdio_get_discmode (res) == CDIO_DISC_MODE_NO_INFO)
+        {
+          cdio_destroy (res);
+          res = NULL;
+        }
+    }
+  
+  return res;
+}
+
+
+
+static gchar*
+cddrive_cddb_get_cdtext_title (CdIo_t *cdio)
+{
+  gchar    *res;
+  cdtext_t *cdtxt;
+
+  cdtxt = cdio_get_cdtext (cdio, 0);
+  res = cdtext_get (CDTEXT_TITLE, cdtxt);
+  cdtext_destroy (cdtxt);
+
+  return res;
+}
+
+
+
 /* Set the cddb id and the length of the audio CD in 'cdda', as well as each
    track and its frame offset.
    Return TRUE on success, FALSE otherwise. */
@@ -191,18 +230,10 @@
 
 
 static cddb_disc_t*
-cddrive_cddb_new_cdda (const gchar* device)
+cddrive_cddb_new_cdda (CdIo_t *cdio)
 {
   cddb_disc_t *res;
-  CdIo_t      *cdio;
 
-  cdio = cdio_open_cd (device);
-  if (cdio == NULL)
-  {
-    g_warning ("unable to open CDDA in drive '%s'.", device);
-    return NULL;
-  }
-
   res = cddb_disc_new ();
   if (res == NULL)
     g_warning ("not enough memory to get CDDA title.");
@@ -215,7 +246,6 @@
         }
     }
   
-  cdio_destroy (cdio);
   return res;
 }
 
@@ -289,34 +319,45 @@
 {
   gchar       *res = NULL;
   cddb_disc_t *cdda;
+  CdIo_t      *cdio;
 
-  cdda = cddrive_cddb_new_cdda (device);
-  if (cdda != NULL)
+  g_assert (device != NULL);
+
+  cdio = cddrive_cddb_new_cdio (device);
+  if (cdio != NULL)
     {
-      res = cddrive_cddb_cache_read (cddb_disc_get_discid (cdda));
+      cdda = cddrive_cddb_new_cdda (cdio);
+      if (cdda != NULL)
+        {
+          res = cddrive_cddb_cache_read (cddb_disc_get_discid (cdda));
       
-      if (res == NULL && connection_allowed)
-        {
-          /* the CDDB disc id was not found in cache. Try to fetch it on freedb.org */
+          if (res == NULL)
+            {
+              res = cddrive_cddb_get_cdtext_title (cdio);
         
+              if (res == NULL && connection_allowed)
+                {
+                  /* the CDDB disc id was not found in cache. Try to fetch it on freedb.org */
+        
 #ifdef HAVE_GTHREAD
-          /* if possible, fetch the title in a thread, so the plugin do not freeze
-             while attempting to connect to the server */          
-          g_thread_create (cddrive_cddb_cache_title_from_server,
-                           cdda,
-                           FALSE,
-                           NULL);
-          /* note: cdda is destroyed in the thread function */
+                  /* if possible, fetch the title in a thread, so the plugin do not freeze
+                     while attempting to connect to the server */          
+                  g_thread_create (cddrive_cddb_cache_title_from_server,
+                                   cdda,
+                                   FALSE,
+                                   NULL);
+                  /* note: cdda is destroyed in the thread function */
         
 #else
-          /* no thread support, plugin freeze will depend on the connection quality */
-          cddrive_cddb_cache_title_from_server (cdda);
-          res = g_strdup (cddb_disc_get_title (cdda));
-          cddb_disc_destroy (cdda);
+                  /* no thread support, plugin freeze will depend on the connection quality */
+                  cddrive_cddb_cache_title_from_server (cdda);
+                  res = g_strdup (cddb_disc_get_title (cdda));
 #endif
+                }
+            }
         }
-      else
-        cddb_disc_destroy (cdda);
+      
+      cdio_destroy (cdio);
     }
 
   return res;




More information about the Goodies-commits mailing list