Revision: 2041
          http://gtkpod.svn.sourceforge.net/gtkpod/?rev=2041&view=rev
Author:   teuf
Date:     2008-07-06 07:04:46 -0700 (Sun, 06 Jul 2008)

Log Message:
-----------
Pick itdb_device_get_storage_info from songbird

Modified Paths:
--------------
    libgpod/trunk/ChangeLog
    libgpod/trunk/src/itdb_device.c
    libgpod/trunk/src/itdb_device.h
    libgpod/trunk/src/itdb_itunesdb.c

Modified: libgpod/trunk/ChangeLog
===================================================================
--- libgpod/trunk/ChangeLog     2008-07-06 14:04:33 UTC (rev 2040)
+++ libgpod/trunk/ChangeLog     2008-07-06 14:04:46 UTC (rev 2041)
@@ -1,5 +1,14 @@
 2008-07-06  Christophe Fergeau <[EMAIL PROTECTED]>
 
+       * src/itdb_device.c:
+       * src/itdb_device.h: add itdb_device_get_storage_info method
+       * src/itdb_itunesdb.c: use that method instead of directly using
+       statvfs, makes it easier to port things over to MSVC8
+
+2008-07-05  Christophe Fergeau <[EMAIL PROTECTED]>
+
+       Patch from: Songbird (http://getsongbird.com/)
+
        * src/db-itunes-parser.h: remove unused constant
        * src/db-parse-context.c:
        * src/db-parse-context.h: use GMappedFile instead of directly using

Modified: libgpod/trunk/src/itdb_device.c
===================================================================
--- libgpod/trunk/src/itdb_device.c     2008-07-06 14:04:33 UTC (rev 2040)
+++ libgpod/trunk/src/itdb_device.c     2008-07-06 14:04:46 UTC (rev 2041)
@@ -1413,3 +1413,57 @@
 
     return FALSE;
 }
+
+#ifdef WIN32
+#include <windows.h>
+#else
+#include <sys/statvfs.h>
+#endif
+
+/**
+ * itdb_device_get_storage_info:
+ *
+ * @device: an #Itdb_Device
+ * @capacity: returned capacity in bytes
+ * @free: returned free space in bytes
+ *
+ * Return the storage info for this iPod
+ *
+ * Return value: TRUE if storage info could be obtained, FALSE otherwise
+ **/
+gboolean itdb_device_get_storage_info (Itdb_Device *device, guint64 *capacity, 
guint64 *free)
+{
+#ifdef WIN32
+    ULARGE_INTEGER u_free, u_capacity;
+#else
+    struct statvfs info;
+    guint64 block_size;
+#endif
+
+    g_return_val_if_fail (device, FALSE);
+    g_return_val_if_fail (capacity, FALSE);
+    g_return_val_if_fail (free, FALSE);
+
+#ifdef WIN32
+    if (GetDiskFreeSpaceEx(device->mountpoint, &u_free, &u_capacity, NULL) == 
0) {
+       return FALSE;
+    }
+    *free = u_free.QuadPart;
+    *capacity = u_capacity.QuadPart;
+    return TRUE;
+#else
+    if (statvfs(device->mountpoint, &info))
+       return FALSE;
+
+    if (info.f_frsize > 0)
+       block_size = info.f_frsize;
+    else
+       block_size = info.f_bsize;
+
+    *capacity = info.f_blocks * block_size;
+    *free = info.f_bfree * block_size;
+
+    return TRUE;
+#endif
+}
+

Modified: libgpod/trunk/src/itdb_device.h
===================================================================
--- libgpod/trunk/src/itdb_device.h     2008-07-06 14:04:33 UTC (rev 2040)
+++ libgpod/trunk/src/itdb_device.h     2008-07-06 14:04:46 UTC (rev 2041)
@@ -119,6 +119,7 @@
 G_GNUC_INTERNAL void itdb_device_autodetect_endianess (Itdb_Device *device);
 G_GNUC_INTERNAL guint64 itdb_device_get_firewire_id (const Itdb_Device 
*device);
 G_GNUC_INTERNAL gboolean itdb_device_supports_sparse_artwork (const 
Itdb_Device *device);
+G_GNUC_INTERNAL gboolean itdb_device_get_storage_info (Itdb_Device *device, 
guint64 *capacity, guint64 *free);
 G_END_DECLS
 
 #endif

Modified: libgpod/trunk/src/itdb_itunesdb.c
===================================================================
--- libgpod/trunk/src/itdb_itunesdb.c   2008-07-06 14:04:33 UTC (rev 2040)
+++ libgpod/trunk/src/itdb_itunesdb.c   2008-07-06 14:04:46 UTC (rev 2041)
@@ -119,7 +119,6 @@
 #include <glib/gstdio.h>
 #include <stdio.h>
 #include <string.h>
-#include <sys/statvfs.h>
 #include <sys/types.h>
 #include <time.h>
 #ifdef HAVE_UNISTD_H
@@ -6911,17 +6910,14 @@
     /* Build the directories that hold the music files */
     dirnum = info->musicdirs;
     if (dirnum == 0)
-    {   /* do a guess */
-       struct statvfs stat;
-       if (statvfs (mp, &stat) != 0)
-       {   /* why should this fail !? */
-           dirnum = 20;
-       }
-       else
-       {
-           gdouble size = ((gdouble)stat.f_blocks * stat.f_frsize) / 
1073741824;
+    {
+       guint64 capacity, free_space;
+       if (itdb_device_get_storage_info(device, &capacity, &free_space)) {
+           gdouble size = ((gdouble)capacity) / 1073741824;
            if (size < 20)  dirnum = 20;
            else            dirnum = 50;
+       } else {
+           dirnum = 20;
        }
     }
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to