[maemo-commits] [maemo-commits] r12831 - in projects/haf/trunk/hildon-fm: . debian hildon-fm

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Wed Jul 25 14:14:13 EEST 2007
Author: kihamala
Date: 2007-07-25 14:14:11 +0300 (Wed, 25 Jul 2007)
New Revision: 12831

Modified:
   projects/haf/trunk/hildon-fm/ChangeLog
   projects/haf/trunk/hildon-fm/debian/changelog
   projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-system-private.c
   projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-system-voldev.c
   projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-system-voldev.h
Log:
some bug fixes


Modified: projects/haf/trunk/hildon-fm/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-fm/ChangeLog	2007-07-25 10:30:45 UTC (rev 12830)
+++ projects/haf/trunk/hildon-fm/ChangeLog	2007-07-25 11:14:11 UTC (rev 12831)
@@ -1,3 +1,25 @@
+2007-07-25  Kimmo Hämäläinen <kimmo.hamalainen at nokia.com>
+
+	* hildon-file-system-private.c
+	(_hildon_file_system_create_display_name): Add check for NULL
+	mime_type. Fixes: NB#63350
+
+	* hildon-file-system-voldev.h: Add new members to struct
+	_HildonFileSystemVoldev: used_over_usb, internal_card,
+	card_type_valid. Add a member to the class struct to store the GConf
+	client.
+
+	* hildon-file-system-voldev.c: Add init_card_type and
+	gconf_value_changed functions.
+	(hildon_file_system_voldev_class_init): Get default GConf client
+	and call gconf_client_add_dir for the relevant directory.
+	(hildon_file_system_voldev_init): Install GConf notification callback.
+	(hildon_file_system_voldev_is_visible): Check the GConf keys to
+	determine whether the memory cards are used over USB.
+	(hildon_file_system_voldev_volumes_changed): Use the new struct
+	member internal_card instead of the earlier hacky way.
+	Fixes: NB#62440, NB#60259, NB#51728, NB#59097, NB#61292
+
 2007-07-18  Marius Vollmer  <marius.vollmer at nokia.com>
 
 	Released 1.9.34

Modified: projects/haf/trunk/hildon-fm/debian/changelog
===================================================================
--- projects/haf/trunk/hildon-fm/debian/changelog	2007-07-25 10:30:45 UTC (rev 12830)
+++ projects/haf/trunk/hildon-fm/debian/changelog	2007-07-25 11:14:11 UTC (rev 12831)
@@ -1,3 +1,12 @@
+libhildonfm (1:1.9.35~unreleased) unstable; urgency=low
+
+  * Added code to detect whether memory cards are shared over USB and should
+    not be visible. This requires two new GConf keys from ke-recv:
+    /system/osso/af/mmc-mount-point and /system/osso/af/mmc-device-name
+    Fixes: NB#62440, NB#60259, NB#51728, NB#59097, NB#61292
+
+ -- Marius Vollmer <marius.vollmer at nokia.com>  Wed, 25 Jul 2007 11:33:08 +0300
+
 libhildonfm (1:1.9.34) unstable; urgency=low
 
   [ Richard Hult ]

Modified: projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-system-private.c
===================================================================
--- projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-system-private.c	2007-07-25 10:30:45 UTC (rev 12830)
+++ projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-system-private.c	2007-07-25 11:14:11 UTC (rev 12831)
@@ -600,13 +600,14 @@
        to gtk_file_info_get_is_folder, but have a mime-type of
        x-directory/normal.
 
-       This is a VERY gross hack and I appologize formally.  My only
+       This is a VERY gross hack and I apologize formally.  My only
        defense is that I don't want to mess with the
        GtkFileSystemMemory itself at this point.  I only feel
        comfortable changing what is displayed and not what the
        filesystem tells is stored in it.
     */
-    if (!is_folder && strcmp (mime_type, "x-directory/normal") == 0)
+    if (!is_folder && mime_type &&
+        strcmp (mime_type, "x-directory/normal") == 0)
       only_known = FALSE;
 
     dot = _hildon_file_system_search_extension (str, only_known, is_folder);

Modified: projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-system-voldev.c
===================================================================
--- projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-system-voldev.c	2007-07-25 10:30:45 UTC (rev 12830)
+++ projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-system-voldev.c	2007-07-25 11:14:11 UTC (rev 12831)
@@ -31,6 +31,10 @@
 #include "hildon-file-common-private.h"
 #include "hildon-file-system-private.h"
 
+#define GCONF_PATH "/system/osso/af"
+#define USED_OVER_USB_KEY GCONF_PATH "/mmc-used-over-usb"
+#define USED_OVER_USB_INTERNAL_KEY GCONF_PATH "/internal-mmc-used-over-usb"
+
 static void
 hildon_file_system_voldev_class_init (HildonFileSystemVoldevClass *klass);
 static void
@@ -48,17 +52,54 @@
 static char *
 hildon_file_system_voldev_get_extra_info (HildonFileSystemSpecialLocation
 					  *location);
+static void init_card_type (const char *path,
+                            HildonFileSystemVoldev *voldev);
 
 G_DEFINE_TYPE (HildonFileSystemVoldev,
                hildon_file_system_voldev,
                HILDON_TYPE_FILE_SYSTEM_SPECIAL_LOCATION);
 
+enum {
+    PROP_USED_OVER_USB = 1
+};
+
 static void
+gconf_value_changed(GConfClient *client, guint cnxn_id,
+                    GConfEntry *entry, gpointer data)
+{
+    HildonFileSystemVoldev *voldev;
+    HildonFileSystemSpecialLocation *location;
+    gboolean change = FALSE;
+
+    voldev = HILDON_FILE_SYSTEM_VOLDEV (data);
+    location = HILDON_FILE_SYSTEM_SPECIAL_LOCATION (voldev);
+
+    if (!voldev->card_type_valid)
+      init_card_type (location->basepath, voldev);
+
+    if (voldev->internal_card &&
+        g_ascii_strcasecmp (entry->key, USED_OVER_USB_INTERNAL_KEY) == 0)
+      change = TRUE;
+    else if (!voldev->internal_card &&
+             g_ascii_strcasecmp (entry->key, USED_OVER_USB_KEY) == 0)
+      change = TRUE;
+
+    if (change)
+      {
+        voldev->used_over_usb = gconf_value_get_bool (entry->value);
+        ULOG_DEBUG_F("%s = %d", entry->key, voldev->used_over_usb);
+        g_signal_emit_by_name (location, "changed");
+        g_signal_emit_by_name (data, "rescan");
+      }
+}
+
+static void
 hildon_file_system_voldev_class_init (HildonFileSystemVoldevClass *klass)
 {
     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
     HildonFileSystemSpecialLocationClass *location =
             HILDON_FILE_SYSTEM_SPECIAL_LOCATION_CLASS (klass);
+    GError *error = NULL;
 
     gobject_class->finalize = hildon_file_system_voldev_finalize;
 
@@ -66,16 +107,36 @@
     location->is_visible = hildon_file_system_voldev_is_visible;
     location->volumes_changed = hildon_file_system_voldev_volumes_changed;
     location->get_extra_info = hildon_file_system_voldev_get_extra_info;
+
+    klass->gconf = gconf_client_get_default ();
+    gconf_client_add_dir (klass->gconf, GCONF_PATH,
+                          GCONF_CLIENT_PRELOAD_NONE, &error);
+    if (error != NULL)
+      {
+        ULOG_ERR_F ("gconf_client_add_dir failed: %s", error->message);
+        g_error_free (error);
+      }
 }
 
 static void
 hildon_file_system_voldev_init (HildonFileSystemVoldev *device)
 {
     HildonFileSystemSpecialLocation *location;
+    GError *error = NULL;
+    HildonFileSystemVoldevClass *klass =
+            HILDON_FILE_SYSTEM_VOLDEV_GET_CLASS (device);
 
     location = HILDON_FILE_SYSTEM_SPECIAL_LOCATION (device);
     location->compatibility_type = HILDON_FILE_SYSTEM_MODEL_MMC;
     location->failed_access_message = NULL;
+
+    gconf_client_notify_add (klass->gconf, GCONF_PATH,
+                             gconf_value_changed, device, NULL, &error);
+    if (error != NULL)
+      {
+        ULOG_ERR_F ("gconf_client_notify_add failed: %s", error->message);
+        g_error_free (error);
+      }
 }
 
 static void
@@ -97,11 +158,34 @@
 hildon_file_system_voldev_is_visible (HildonFileSystemSpecialLocation *location)
 {
   HildonFileSystemVoldev *voldev = HILDON_FILE_SYSTEM_VOLDEV (location);
+  HildonFileSystemVoldevClass *klass =
+          HILDON_FILE_SYSTEM_VOLDEV_GET_CLASS (voldev);
   gboolean visible = FALSE;
+  GError *error = NULL;
+  gboolean value;
 
-  if (voldev->volume)
+  if (!voldev->card_type_valid)
+    init_card_type (location->basepath, voldev);
+
+  if (voldev->internal_card)
+    value = gconf_client_get_bool (klass->gconf,
+                                   USED_OVER_USB_INTERNAL_KEY, &error);
+  else
+    value = gconf_client_get_bool (klass->gconf,
+                                   USED_OVER_USB_KEY, &error);
+
+  if (error)
+    {
+      ULOG_ERR_F ("gconf_client_get_bool failed: %s", error->message);
+      g_error_free (error);
+    }
+  else
+    voldev->used_over_usb = value;
+
+  ULOG_DEBUG_F("voldev->used_over_usb == %d", voldev->used_over_usb);
+  if (voldev->volume && !voldev->used_over_usb)
     visible = gnome_vfs_volume_is_mounted (voldev->volume);
-  else if (voldev->drive)
+  else if (voldev->drive && !voldev->used_over_usb)
     visible = (gnome_vfs_drive_is_connected (voldev->drive)
                && !gnome_vfs_drive_is_mounted (voldev->drive));
 
@@ -211,6 +295,64 @@
   return name;
 }
 
+static void init_card_type (const char *path,
+                            HildonFileSystemVoldev *voldev)
+{
+  HildonFileSystemVoldevClass *klass;
+  gchar *value;
+  gboolean drive;
+
+  if (voldev->card_type_valid)
+    /* already initialised */
+    return;
+
+  if (path == NULL)
+    {
+      ULOG_WARN_F ("path == NULL");
+      return;
+    }
+
+  klass = HILDON_FILE_SYSTEM_VOLDEV_GET_CLASS (voldev);
+
+  if (g_str_has_prefix (path, "drive://"))
+    {
+      drive = TRUE;
+      value = gconf_client_get_string (klass->gconf,
+                    "/system/osso/af/mmc-device-name", NULL);
+    }
+  else
+    {
+      drive = FALSE;
+      value = gconf_client_get_string (klass->gconf,
+                    "/system/osso/af/mmc-mount-point", NULL);
+    }
+
+  if (value)
+    {
+      char buf[100];
+
+      if (drive)
+        {
+          snprintf (buf, 100, "drive://%s", value);
+          if (g_str_has_prefix (path, buf))
+            voldev->internal_card = FALSE;
+          else
+            voldev->internal_card = TRUE;
+        }
+      else
+        {
+          snprintf (buf, 100, "file://%s", value);
+          if (strncmp (buf, path, 100) == 0)
+            voldev->internal_card = FALSE;
+          else
+            voldev->internal_card = TRUE;
+        }
+
+      voldev->card_type_valid = TRUE;
+      g_free (value);
+    }
+}
+
 static void
 hildon_file_system_voldev_volumes_changed (HildonFileSystemSpecialLocation
                                            *location, GtkFileSystem *fs)
@@ -233,6 +375,9 @@
   else
     voldev->volume = find_volume (location->basepath);
 
+  if (!voldev->card_type_valid)
+    init_card_type (location->basepath, voldev);
+
   if (voldev->volume)
     {
       location->fixed_title =
@@ -256,22 +401,13 @@
       else if (strcmp (location->fixed_icon, "gnome-dev-removable") == 0
 	       || strcmp (location->fixed_icon, "gnome-dev-media-sdmmc") == 0)
 	{
-	  gboolean internal = 
-	    g_str_has_prefix (location->basepath, "file:///media/mmc2");
-	  
-	  /* the following strcmp() is for drives, so that we don't need
-	   * knowledge about device naming */
-	  if (strcmp(location->fixed_title,
-		     "mmc-undefined-name-internal") == 0)
-	    internal = TRUE;
-
-	  if (internal)
+	  if (voldev->internal_card)
 	    location->fixed_icon = "qgn_list_gene_internal_memory_card";
 	  else
 	    location->fixed_icon = "qgn_list_gene_removable_memory_card";
 	  
 	  location->fixed_title = beautify_mmc_name (location->fixed_title,
-						     internal);
+						     voldev->internal_card);
 	}
     }
 

Modified: projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-system-voldev.h
===================================================================
--- projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-system-voldev.h	2007-07-25 10:30:45 UTC (rev 12830)
+++ projects/haf/trunk/hildon-fm/hildon-fm/hildon-file-system-voldev.h	2007-07-25 11:14:11 UTC (rev 12831)
@@ -27,6 +27,7 @@
 #include "hildon-file-system-remote-device.h"
 
 #include <libgnomevfs/gnome-vfs.h>
+#include <gconf/gconf-client.h>
 
 G_BEGIN_DECLS
 
@@ -47,11 +48,15 @@
   HildonFileSystemSpecialLocation parent_instance;
   GnomeVFSVolume *volume;
   GnomeVFSDrive *drive;
+  gboolean used_over_usb;
+  gboolean internal_card;
+  gboolean card_type_valid;
 };
 
 struct _HildonFileSystemVoldevClass
 {
     HildonFileSystemRemoteDeviceClass parent_class;
+    GConfClient *gconf;
 };
 
 GType hildon_file_system_voldev_get_type (void) G_GNUC_CONST;


More information about the maemo-commits mailing list