예제 #1
0
static void
force_probe (void)
{
	GnomeVFSVolumeMonitor *volume_monitor;
	GnomeVFSDaemonForceProbeCallback callback;
	
	volume_monitor = gnome_vfs_get_volume_monitor ();

	if (gnome_vfs_get_is_daemon ()) {
		callback = _gnome_vfs_get_daemon_force_probe_callback();
		(*callback) (GNOME_VFS_VOLUME_MONITOR (volume_monitor));
	} else {
		_gnome_vfs_volume_monitor_client_dbus_force_probe (
			GNOME_VFS_VOLUME_MONITOR_CLIENT (volume_monitor));
	}
}
예제 #2
0
static void
mount_unmount_operation (const char *mount_point,
			 const char *device_path,
			 const char *hal_udi,
			 GnomeVFSDeviceType device_type,
			 gboolean should_mount,
			 gboolean should_unmount,
			 gboolean should_eject,
			 GnomeVFSVolumeOpCallback  callback,
			 gpointer                  user_data)
{
#ifndef G_OS_WIN32
	const char *command = NULL;
	const char *argument = NULL;
	MountThreadInfo *mount_info;
	pthread_t mount_thread;
	const char *name;
	int i;
	gboolean is_in_media;

#ifdef USE_VOLRMMOUNT
	if (mount_point != NULL) {
		name = strrchr (mount_point, '/');
	if (name != NULL) {
		name = name + 1;
	} else {
		name = mount_point;
	}
#else

# ifdef USE_HAL
	if (hal_udi != NULL) {
		name = device_path;
	} else
		name = mount_point;
# else
	name = mount_point;
# endif

#endif

	is_in_media = mount_point != NULL ? g_str_has_prefix (mount_point, "/media") : FALSE;

	command = NULL;

	if (should_mount) {
#if defined(USE_HAL)
	       if (hal_udi != NULL && g_file_test (GNOME_VFS_BINDIR "/gnome-mount", G_FILE_TEST_IS_EXECUTABLE)) {
		       command = GNOME_VFS_BINDIR "/gnome-mount";
		       argument = "--hal-udi";
		       name = hal_udi;
	       } else {
# if defined(HAL_MOUNT)
		       if (hal_udi != NULL && g_file_test (HAL_MOUNT, G_FILE_TEST_IS_EXECUTABLE))
			       command = HAL_MOUNT;
		       else
			       command = find_command (MOUNT_COMMAND);
# else
		       ;
# endif
	       }
#endif
	       if (command == NULL)
		       command = find_command (is_in_media ? PMOUNT_COMMAND : MOUNT_COMMAND);
#ifdef  MOUNT_ARGUMENT
	       argument = MOUNT_ARGUMENT;
#endif
       }

       if (should_unmount) {
#if defined(USE_HAL)
	       if (hal_udi != NULL && g_file_test (GNOME_VFS_BINDIR "/gnome-umount", G_FILE_TEST_IS_EXECUTABLE)) {
		       command = GNOME_VFS_BINDIR "/gnome-umount";
		       argument = "--hal-udi";
		       name = hal_udi;
	       } else {
# if defined(HAL_UMOUNT)
		       if (hal_udi != NULL && g_file_test (HAL_UMOUNT, G_FILE_TEST_IS_EXECUTABLE))
			       command = HAL_UMOUNT;
		       else
			       command = find_command (UMOUNT_COMMAND);
# else
		       ;
#endif
	       }
#endif
	       if (command == NULL)
		       command = find_command (is_in_media ? PUMOUNT_COMMAND : UMOUNT_COMMAND);
#ifdef  UNMOUNT_ARGUMENT
		argument = UNMOUNT_ARGUMENT;
#endif
       }

	mount_info = g_new0 (MountThreadInfo, 1);

	if (command) {
		i = 0;
		mount_info->argv[i++] = g_strdup (command);
		if (argument) {
			mount_info->argv[i++] = g_strdup (argument);
		}
		mount_info->argv[i++] = g_strdup (name);
		mount_info->argv[i++] = NULL;
	}
	
	mount_info->mount_point = g_strdup (mount_point != NULL ? mount_point : "");
	mount_info->device_path = g_strdup (device_path);
	mount_info->device_type = device_type;
	mount_info->hal_udi = g_strdup (hal_udi);
	mount_info->should_mount = should_mount;
	mount_info->should_unmount = should_unmount;
	mount_info->should_eject = should_eject;
	mount_info->callback = callback;
	mount_info->user_data = user_data;
	
	pthread_create (&mount_thread, NULL, mount_unmount_thread, mount_info);
#else
	g_warning ("Not implemented: mount_unmount_operation()\n");
#endif
}


/* TODO: check if already mounted/unmounted, emit pre_unmount, check for mount types */

static void
emit_pre_unmount (GnomeVFSVolume *volume)
{
	GnomeVFSVolumeMonitor *volume_monitor;
	
	volume_monitor = gnome_vfs_get_volume_monitor ();

	if (gnome_vfs_get_is_daemon ()) {
		gnome_vfs_volume_monitor_emit_pre_unmount (volume_monitor,
							   volume);
	} else {
		_gnome_vfs_volume_monitor_client_dbus_emit_pre_unmount (
			GNOME_VFS_VOLUME_MONITOR_CLIENT (volume_monitor), volume);

		/* Do a synchronous pre_unmount for this client too, avoiding
		 * races at least in this process
		 */
		gnome_vfs_volume_monitor_emit_pre_unmount (volume_monitor,
							   volume);
		/* sleep for a while to get other apps to release their
		 * hold on the device */
		g_usleep (0.5*G_USEC_PER_SEC);
				
	}
}
예제 #3
0
static void update_places(Menu_list_item **p, char* file_manager)
{
  static GnomeVFSVolumeMonitor* vfsvolumes = NULL;
  Menu_list_item * sublist = *p;
  Menu_list_item * item;


  sublist = g_slist_append(sublist, get_blank());


  item = g_malloc(sizeof(Menu_list_item));
  item->item_type = MENU_ITEM_ENTRY;
  item->name = g_strdup("Home");
  item->icon = g_strdup("stock_home");
  const char *homedir = g_getenv("HOME");

  if (!homedir)
    homedir = g_get_home_dir();

  item->exec = g_strdup_printf("%s %s", file_manager, homedir);

  item->comment = g_strdup("Your Home Directory");

  item->desktop = g_strdup("");

  sublist = g_slist_append(sublist, item);

  item = g_malloc(sizeof(Menu_list_item));

  item->item_type = MENU_ITEM_ENTRY;

  item->name = g_strdup("File System");

  item->icon = g_strdup("stock_folder");

  item->exec = g_strdup_printf("%s /", file_manager);

  item->comment = g_strdup("Root File System");

  item->desktop = g_strdup("");

  sublist = g_slist_append(sublist, item);

//mount monitor
  if (!vfsvolumes)
  {
    vfsvolumes = gnome_vfs_get_volume_monitor();
    g_signal_connect(G_OBJECT(vfsvolumes), "volume-mounted", G_CALLBACK(_vfs_changed_v_m), NULL);
    g_signal_connect(G_OBJECT(vfsvolumes), "volume-unmounted", G_CALLBACK(_vfs_changed_v_u), NULL);
    g_signal_connect(G_OBJECT(vfsvolumes), "drive-disconnected" , G_CALLBACK(_vfs_changed_d_d), NULL);
    g_signal_connect(G_OBJECT(vfsvolumes), "drive-connected", G_CALLBACK(_vfs_changed_d_c), NULL);
  }

  GList *connected = gnome_vfs_volume_monitor_get_connected_drives(vfsvolumes);

  if (connected)
    g_list_foreach(connected, _fillin_connected, &sublist);

  g_list_free(connected);


  sublist = g_slist_append(sublist, get_separator());

/*bookmarks*/
  FILE* handle;

  gchar *  filename = g_strdup_printf("%s/.gtk-bookmarks", homedir);

  handle = g_fopen(filename, "r");

  if (handle)
  {
    char * line = NULL;
    size_t  len = 0;

    while (getline(&line, &len, handle) != -1)
    {
      gchar ** tokens;
      tokens = g_strsplit(line, " ", 2);

      if (tokens)
      {
        if (tokens[0])
        {
          gchar * shell_quoted;
          g_strstrip(tokens[0]);
          item = g_malloc(sizeof(Menu_list_item));
          item->item_type = MENU_ITEM_ENTRY;

          if (tokens[1])
          {
            g_strstrip(tokens[1]);
            item->name = g_strdup(tokens[1]);
          }
          else
          {
            item->name = urldecode(g_path_get_basename(tokens[0]), NULL);
          }

          item->icon = g_strdup("stock_folder");

          shell_quoted = g_shell_quote(tokens[0]);
          item->exec = g_strdup_printf("%s %s", file_manager, shell_quoted);
          item->comment = urldecode(g_strdup(shell_quoted),NULL);
          g_free(shell_quoted);
          item->desktop = g_strdup("");
          sublist = g_slist_append(sublist, item);

        }

      }

      g_strfreev(tokens);

      free(line);

      line = NULL;
    }

    fclose(handle);

    g_free(filename);
  }
  else
  {
    printf("Unable to open bookmark file: %s/.gtk-bookmarks\n", homedir);
  }
  sublist = g_slist_append(sublist, get_blank());

  *p = sublist;
}