app-manager/localmedia.c
changeset 10 8b50be3e2998
parent 9 8d3b1ddf789c
child 12 1d18b9c34d26
     1.1 --- a/app-manager/localmedia.c	Sat Feb 20 12:11:02 2010 +0000
     1.2 +++ b/app-manager/localmedia.c	Fri Apr 30 20:37:08 2010 +0100
     1.3 @@ -19,10 +19,14 @@
     1.4  #include "config.h"
     1.5  #include <stdlib.h>
     1.6  #include <string.h>
     1.7 +#ifdef WIN32
     1.8 +#include <windows.h>
     1.9 +#endif
    1.10  #include <glib.h>
    1.11  #include <gio/gio.h>
    1.12  #include <gtk/gtk.h>
    1.13  #include <plover-gtk/packagestore.h>
    1.14 +#include "app-manager.h"
    1.15  #include "localmedia.h"
    1.16  
    1.17  G_DEFINE_TYPE(PloverLocalMediaStore,plover_local_media_store,
    1.18 @@ -56,12 +60,37 @@
    1.19  {
    1.20      GFile *root;
    1.21      gchar *path;
    1.22 +#ifdef WIN32
    1.23 +    gunichar2 *path2;
    1.24 +    UINT type;
    1.25 +#endif
    1.26      PloverPackageSet *set;
    1.27      root=g_mount_get_root(mount);
    1.28      path=g_file_get_path(root);
    1.29 +#ifdef WIN32
    1.30      if (path)
    1.31      {
    1.32 -	set=plover_package_set_new_from_repository(path,NULL);
    1.33 +	path2=g_utf8_to_utf16(path,-1,NULL,NULL,NULL);
    1.34 +	if (path2)
    1.35 +	{
    1.36 +	    type=GetDriveTypeW(path2);
    1.37 +	    g_free(path2);
    1.38 +	}
    1.39 +	else
    1.40 +	    type=DRIVE_UNKNOWN;
    1.41 +	if (type!=DRIVE_REMOVABLE && type!=DRIVE_CDROM)
    1.42 +	{
    1.43 +	    gchar *name=g_mount_get_name(mount);
    1.44 +	    g_debug("Skipping non-local mount \"%s\"",name);
    1.45 +	    g_free(name);
    1.46 +	    g_free(path);
    1.47 +	    path=NULL;
    1.48 +	}
    1.49 +    }
    1.50 +#endif
    1.51 +    if (path)
    1.52 +    {
    1.53 +	set=plover_package_set_new_from_repository(path,relocations,NULL);
    1.54  	if (set)
    1.55  	{
    1.56  	    g_object_set_data(G_OBJECT(mount),"plover-local-media-set",set);
    1.57 @@ -94,25 +123,38 @@
    1.58  {
    1.59      GVolume *volume;
    1.60      GMount *mount;
    1.61 -    GList *volumes,*link;
    1.62 -    if (g_drive_has_media(drive))
    1.63 +    GList *volumes,*mounts,*link;
    1.64 +    if (!drive)
    1.65 +	volumes=g_volume_monitor_get_volumes(store->monitor);
    1.66 +    else if (g_drive_has_media(drive))
    1.67 +	volumes=g_drive_get_volumes(drive);
    1.68 +    else
    1.69 +	volumes=NULL;
    1.70 +    for(link=volumes;link;link=link->next)
    1.71      {
    1.72 -	volumes=g_drive_get_volumes(drive);
    1.73 -	for(link=volumes;link;link=link->next)
    1.74 +	volume=G_VOLUME(link->data);
    1.75 +	mount=g_volume_get_mount(volume);
    1.76 +	if (mount)
    1.77  	{
    1.78 -	    volume=G_VOLUME(link->data);
    1.79 -	    mount=g_volume_get_mount(volume);
    1.80 -	    if (mount)
    1.81 -	    {
    1.82 -		local_media_scan_mount(store,mount);
    1.83 -		g_object_unref(mount);
    1.84 -	    }
    1.85 -	    else if (!store->implicit_scan && g_volume_can_mount(volume))
    1.86 -		g_volume_mount(volume,G_MOUNT_MOUNT_NONE,NULL,NULL,
    1.87 -		  local_media_mounted,store);
    1.88 -	    g_object_unref(volume);
    1.89 +	    local_media_scan_mount(store,mount);
    1.90 +	    g_object_unref(mount);
    1.91  	}
    1.92 -	g_list_free(volumes);
    1.93 +	else if (!store->implicit_scan && g_volume_can_mount(volume))
    1.94 +	    g_volume_mount(volume,G_MOUNT_MOUNT_NONE,NULL,NULL,
    1.95 +	      local_media_mounted,store);
    1.96 +	g_object_unref(volume);
    1.97 +    }
    1.98 +    g_list_free(volumes);
    1.99 +    if (!drive)
   1.100 +    {
   1.101 +	mounts=g_volume_monitor_get_mounts(store->monitor);
   1.102 +	for(link=mounts;link;link=link->next)
   1.103 +	{
   1.104 +	    mount=G_MOUNT(link->data);
   1.105 +	    local_media_scan_mount(store,mount);
   1.106 +	    g_object_unref(mount);
   1.107 +	}
   1.108 +	g_list_free(mounts);
   1.109      }
   1.110  }
   1.111  
   1.112 @@ -127,9 +169,15 @@
   1.113  
   1.114  void plover_local_media_store_scan(PloverLocalMediaStore *store)
   1.115  {
   1.116 -    GList *drives,*link;
   1.117 +    GList *sets,*drives,*link;
   1.118      GDrive *drive;
   1.119      g_return_if_fail(PLOVER_IS_LOCAL_MEDIA_STORE(store));
   1.120 +    sets=
   1.121 +      g_slist_copy(plover_package_store_get_sets(PLOVER_PACKAGE_STORE(store)));
   1.122 +    for(link=sets;link;link=link->next)
   1.123 +	plover_package_store_remove_set(PLOVER_PACKAGE_STORE(store),
   1.124 +	  PLOVER_PACKAGE_SET(link->data));
   1.125 +    g_slist_free(sets);
   1.126      drives=g_volume_monitor_get_connected_drives(store->monitor);
   1.127      for(link=drives;link;link=link->next)
   1.128      {
   1.129 @@ -149,6 +197,7 @@
   1.130  	g_object_unref(drive);
   1.131      }
   1.132      g_list_free(drives);
   1.133 +    local_media_scan_drive(store,NULL);
   1.134  }
   1.135  
   1.136  static void local_media_mount_added(GVolumeMonitor *volume_monitor,