static void
thunar_uca_provider_child_watch (GPid     pid,
                                 gint     status,
                                 gpointer user_data)
{
  ThunarUcaProvider *uca_provider = THUNAR_UCA_PROVIDER (user_data);
  ThunarVfsMonitor  *monitor;
  ThunarVfsPath     *path;

  GDK_THREADS_ENTER ();

  /* verify that we still have a valid child_watch_path */
  if (G_LIKELY (uca_provider->child_watch_path != NULL))
    {
      /* determine the corresponding ThunarVfsPath */
      path = thunar_vfs_path_new (uca_provider->child_watch_path, NULL);
      if (G_LIKELY (path != NULL))
        {
          /* schedule a changed notification on the path */
          monitor = thunar_vfs_monitor_get_default ();
          thunar_vfs_monitor_feed (monitor, THUNAR_VFS_MONITOR_EVENT_CHANGED, path);
          g_object_unref (G_OBJECT (monitor));

          /* release the ThunarVfsPath */
          thunar_vfs_path_unref (path);
        }
    }

  /* need to cleanup */
  g_spawn_close_pid (pid);

  GDK_THREADS_LEAVE ();
}
static void
thunar_preferences_resume_monitor (ThunarPreferences *preferences)
{
  ThunarVfsPath *path;
  gchar         *filename;

  /* verify that the monitor is suspended */
  if (G_LIKELY (preferences->handle == NULL))
    {
      /* determine the save location for thunarrc to monitor */
      filename = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, "Thunar/thunarrc", TRUE);
      if (G_LIKELY (filename != NULL))
        {
          /* determine the VFS path for the filename */
          path = thunar_vfs_path_new (filename, NULL);
          if (G_LIKELY (path != NULL))
            {
              /* add the monitor handle for the file */
              preferences->handle = thunar_vfs_monitor_add_file (preferences->monitor, path, thunar_preferences_monitor, preferences);
              thunar_vfs_path_unref (path);
            }

          /* release the filename */
          g_free (filename);
        }
    }
}
示例#3
0
文件: main.c 项目: jmenashe/diff-ext
static void
add_compare_to_menu(GList* actions, GtkWidget* window, GList* files, char* menu_name, GString* (*make_hint)(va_list, char*), GCallback callback, ...) {
  GtkAction* action;    
  GtkIconTheme* theme = gtk_icon_theme_get_default();
  GList* head = g_queue_peek_head_link(_saved);
  xdiff_ext_submenu_action* submenu;
  GString* name = g_string_new("");
  int n = 1;
  va_list args;
  
  va_start(args, callback);
  
  submenu = xdiff_ext_submenu_action_new("xdiff-ext::compare_to_menu", menu_name, "", NULL);
  actions = g_list_append(actions, submenu);

  while(head) {
    gchar* head_file = (gchar*)head->data;    
    ThunarVfsPath* vfs_path = thunar_vfs_path_new(head_file, NULL);
    ThunarVfsInfo* vfs_info = thunar_vfs_info_new_for_path(vfs_path, NULL);
    const gchar* icon_name = thunar_vfs_info_get_custom_icon(vfs_info);
    GString* hint = make_hint(args, head_file);
    
    if(icon_name == NULL) {
      icon_name = thunar_vfs_mime_info_lookup_icon_name(vfs_info->mime_info, theme);
    }
    
    thunar_vfs_path_unref(vfs_path);
    thunar_vfs_info_unref(vfs_info);
    
    g_string_printf(name, "xdiff-ext::compare_to_%d", n);
    
    action = gtk_action_new(name->str, head_file, hint->str, icon_name);
    g_signal_connect(G_OBJECT(action), "activate", callback, window);
    g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare_to", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
    g_object_set_data(G_OBJECT(action), "xdiff-ext::saved", head);
    xdiff_ext_submenu_action_add(submenu, action);
    
    g_string_free(hint, TRUE);

    head = g_list_next(head);
    n++;
  }
  
  xdiff_ext_submenu_action_add(submenu, NULL);
  
  action = gtk_action_new("xdiff-ext::clear", _("Clear"), _("Clear selected files list"), GTK_STOCK_CLEAR);
  g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(clear), window);
  xdiff_ext_submenu_action_add(submenu, action);
  
  g_string_free(name, TRUE);
  va_end(args);
}
static void
thunar_vfs_volume_hal_finalize (GObject *object)
{
  ThunarVfsVolumeHal *volume_hal = THUNAR_VFS_VOLUME_HAL (object);

  g_free (volume_hal->udi);

  g_free (volume_hal->device_file);
  g_free (volume_hal->device_label);

  g_list_foreach (volume_hal->icon_list, (GFunc) g_free, NULL);
  g_list_free (volume_hal->icon_list);

  /* release the mount point (if any) */
  if (G_LIKELY (volume_hal->mount_point != NULL))
    thunar_vfs_path_unref (volume_hal->mount_point);

  (*G_OBJECT_CLASS (thunar_vfs_volume_hal_parent_class)->finalize) (object);
}
static gboolean
thunar_vfs_volume_hal_mount (ThunarVfsVolume *volume,
                             GtkWidget       *window,
                             GError         **error)
{
  ThunarVfsVolumeHal *volume_hal = THUNAR_VFS_VOLUME_HAL (volume);
  ThunarVfsPath      *path;
  gboolean            result;
  gchar              *quoted;

  /* use exo-mount to mount the device */
  quoted = g_shell_quote (volume_hal->udi);
  result = thunar_vfs_exec_sync ("exo-mount -n -h %s", error, quoted);
  g_free (quoted);

  /* check if we were successfull */
  if (G_LIKELY (result))
    {
      /* try to figure out where the device was mounted */
      path = thunar_vfs_volume_hal_find_active_mount_point (volume_hal);
      if (G_LIKELY (path != NULL))
        {
          /* we must have been mounted successfully */
          volume_hal->status |= THUNAR_VFS_VOLUME_STATUS_MOUNTED | THUNAR_VFS_VOLUME_STATUS_PRESENT;

          /* replace the existing mount point */
          thunar_vfs_path_unref (volume_hal->mount_point);
          volume_hal->mount_point = path;

          /* tell everybody that we have a new state */
          thunar_vfs_volume_changed (THUNAR_VFS_VOLUME (volume_hal));
        }
      else
        {
          /* something went wrong, for sure */
          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Failed to determine the mount point for %s"), volume_hal->device_file);
          result = FALSE;
        }
    }

  return result;
}
static ThunarVfsVolume*
thunar_vfs_volume_manager_real_get_volume_by_info (ThunarVfsVolumeManager *manager, 
                                                   const ThunarVfsInfo    *info)
{
  ThunarVfsVolume *best_volume = NULL;
  ThunarVfsPath   *best_path = NULL;
  ThunarVfsPath   *info_path;
  ThunarVfsPath   *path;
  GList           *lp;

  /* translate the info's path to a local path */
  info_path = _thunar_vfs_path_translate (info->path, THUNAR_VFS_PATH_SCHEME_FILE, NULL);
  if (G_LIKELY (info_path != NULL))
    {
      /* otherwise try to find it the hard way */
      for (lp = manager->volumes; lp != NULL; lp = lp->next)
        {
          /* check if the volume is mounted */
          if (!thunar_vfs_volume_is_mounted (lp->data))
            continue;

          /* check if the mount point is an ancestor of the info path */
          path = thunar_vfs_volume_get_mount_point (lp->data);
          if (path == NULL || (!thunar_vfs_path_equal (info_path, path) && !thunar_vfs_path_is_ancestor (info_path, path)))
            continue;

          /* possible match, check if better than previous match */
          if (best_volume == NULL || thunar_vfs_path_equal (path, best_path) || thunar_vfs_path_is_ancestor (path, best_path))
            {
              best_volume = lp->data;
              best_path = path;
            }
        }

      /* cleanup */
      thunar_vfs_path_unref (info_path);
    }

  return best_volume;
}
示例#7
0
文件: main.c 项目: jmenashe/diff-ext
static GList*
get_file_actions(ThunarxMenuProvider* provider, GtkWidget* window, GList* files) {
  GList* actions = 0;
  
  if(files != 0) {
    GtkIconTheme* theme = gtk_icon_theme_get_default();
    guint n = g_list_length(files);
    gchar* three_way_compare_command;
    xdiff_ext_preferences* p = xdiff_ext_preferences_instance();

    g_object_get(G_OBJECT(p), "three-way-compare-command", &three_way_compare_command, NULL);

    g_object_unref(p);
     
    GList* scan = files;
    gboolean go = TRUE;
    
    while(scan && go) {
      gchar* scheme;

      scheme = thunarx_file_info_get_uri_scheme((ThunarxFileInfo*)(scan->data));
      go = strncmp(scheme, "file", 4) == 0;
      g_free(scheme);
      
      scan = g_list_next(scan);
    }
    
    if(go) {
      GtkAction* action = gtk_action_new("xdiff-ext::save", _("Compare later"), _("Select file for comparison"), DIFF_EXT_DATA_DIR"/icons/hicolor/16x16/actions/diff_later.png");
      g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare_later), window);
      g_object_set_data_full(G_OBJECT(action), "xdiff-ext::save", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
      actions = g_list_append(actions, action);
      
      if(n == 1) {
        if(!g_queue_is_empty(_saved)) {
          GString* caption = g_string_new("");
          GString* hint = g_string_new("");
          GList* head = g_queue_peek_head_link(_saved);
          gchar* head_file = (gchar*)head->data;
          ThunarVfsInfo* vfs_info = NULL;
          ThunarVfsPath* vfs_path = NULL;
          const gchar* icon_name;
          
          gchar* uri;
          gchar* path;

          uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
          path = g_filename_from_uri(uri, NULL, NULL);
          g_free(uri);
          
          g_string_printf(caption,_("Compare to '%s'"), head_file);
          g_string_printf(hint, _("Compare '%s' and '%s'"), path, head_file);
          
          vfs_path = thunar_vfs_path_new(head_file, NULL);
          vfs_info = thunar_vfs_info_new_for_path(vfs_path, NULL);
          icon_name = thunar_vfs_info_get_custom_icon(vfs_info);
          if(icon_name == NULL) {
            icon_name = thunar_vfs_mime_info_lookup_icon_name(vfs_info->mime_info, theme);
          }
          
          g_message("icon name: '%s'", icon_name);
          thunar_vfs_path_unref(vfs_path);
          thunar_vfs_info_unref(vfs_info);
          
          action = gtk_action_new("xdiff-ext::compare_to", caption->str, hint->str, "gaim.png");
          g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare_to), window);
          g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare_to", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
          g_object_set_data(G_OBJECT(action), "xdiff-ext::saved", head);
          actions = g_list_append(actions, action);
          
          if(_saved->length > 1) {
            add_compare_to_menu(actions, window, files, _("Compare to"), make_hint, G_CALLBACK(compare_to), path);
          }
          
          g_string_free(caption, TRUE);
          g_string_free(hint, TRUE);
        }
      } else if(n == 2) {
        GtkAction* action = gtk_action_new("xdiff-ext::compare", _("Compare"), _("Compare selected files"), "diff");
        g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare), window);
        g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
        actions = g_list_append(actions, action);

        if(strcmp("", three_way_compare_command) != 0) {
          if(!g_queue_is_empty(_saved)) {
            GString* caption = g_string_new("");
            GString* hint = g_string_new("");
            GList* head = g_queue_peek_head_link(_saved);
            gchar* head_file = (gchar*)head->data;
            gchar* uri;
            gchar* path1;
            gchar* path2;

            uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
            path1 = g_filename_from_uri(uri, NULL, NULL);
            g_free(uri);
            files = g_list_next(files);
            uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
            path2 = g_filename_from_uri(uri, NULL, NULL);
            g_free(uri);
            
            g_string_printf(caption, _("3-way compare to '%s'"), head_file);
            g_string_printf(hint, _("3-way compare '%s', '%s' and '%s'"), path1, path2, head_file);
            
            action = gtk_action_new("xdiff-ext::compare_to", caption->str, hint->str, "diff3_with");
            g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare3_to), window);
            g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare_to", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
            g_object_set_data(G_OBJECT(action), "xdiff-ext::saved", head);
            actions = g_list_append(actions, action);

            if(_saved->length > 1) {
              add_compare_to_menu(actions, window, files, _("3-way compare to"), make_hint3, G_CALLBACK(compare3_to), path1, path2);
            }
            
            g_string_free(caption, TRUE);
            g_string_free(hint, TRUE);
          }
        }
      } else if(n == 3) {
        if(strcmp("", three_way_compare_command) != 0) {
          GtkAction* action = gtk_action_new("xdiff-ext::compare3", _("3-way Compare"), _("Compare selected files"), "diff3");
          g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(compare3), window);
          g_object_set_data_full(G_OBJECT(action), "xdiff-ext::compare3", thunarx_file_info_list_copy(files),(GDestroyNotify)thunarx_file_info_list_free);
          actions = g_list_append(actions, action);
        }
      }
    }
    
    g_free(three_way_compare_command);
  }
          
  return actions;
}
static void
thunar_vfs_volume_hal_update (ThunarVfsVolumeHal *volume_hal,
                              LibHalContext      *context,
                              LibHalVolume       *hv,
                              LibHalDrive        *hd)
{
  gchar *desired_mount_point;
  gchar *mount_root;
  gchar *basename;
  gchar *filename;

  _thunar_vfs_return_if_fail (THUNAR_VFS_IS_VOLUME_HAL (volume_hal));
  _thunar_vfs_return_if_fail (hd != NULL);

  /* reset the volume status */
  volume_hal->status = 0;

  /* determine the new device file */
  g_free (volume_hal->device_file);
  volume_hal->device_file = g_strdup ((hv != NULL) ? libhal_volume_get_device_file (hv) : libhal_drive_get_device_file (hd));

  /* compute a usable display name for the volume/drive */
  g_free (volume_hal->device_label);
  volume_hal->device_label = (hv == NULL)
    ? exo_hal_drive_compute_display_name (context, hd)
    : exo_hal_volume_compute_display_name (context, hv, hd);
  if (G_UNLIKELY (volume_hal->device_label == NULL))
    {
      /* use the basename of the device file as label */
      volume_hal->device_label = g_path_get_basename (volume_hal->device_file);
    }

  /* compute a usable list of icon names for the volume/drive */
  g_list_foreach (volume_hal->icon_list, (GFunc) g_free, NULL);
  g_list_free (volume_hal->icon_list);
  volume_hal->icon_list = (hv == NULL)
    ? exo_hal_drive_compute_icon_list (context, hd)
    : exo_hal_volume_compute_icon_list (context, hv, hd);

  /* release the previous mount point (if any) */
  if (G_LIKELY (volume_hal->mount_point != NULL))
    {
      thunar_vfs_path_unref (volume_hal->mount_point);
      volume_hal->mount_point = NULL;
    }

  /* determine the type of the volume */
  switch (libhal_drive_get_type (hd))
    {
    case LIBHAL_DRIVE_TYPE_CDROM:
      /* check if we have a pure audio CD without any data track */
      if (libhal_volume_disc_has_audio (hv) && !libhal_volume_disc_has_data (hv))
        {
          /* special treatment for pure audio CDs */
          volume_hal->kind = THUNAR_VFS_VOLUME_KIND_AUDIO_CD;
        }
      else
        {
          /* check which kind of CD-ROM/DVD we have */
          switch (libhal_volume_get_disc_type (hv))
            {
            case LIBHAL_VOLUME_DISC_TYPE_CDROM:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_CDROM;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_CDR:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_CDR;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_CDRW:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_CDRW;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDROM:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDROM;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDRAM:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDRAM;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDR:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDR;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDRW:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDRW;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDPLUSR:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDPLUSR;
              break;

            case LIBHAL_VOLUME_DISC_TYPE_DVDPLUSRW:
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_DVDPLUSRW;
              break;

            default:
              /* unsupported disc type */
              volume_hal->kind = THUNAR_VFS_VOLUME_KIND_UNKNOWN;
              break;
            }
        }
      break;

    case LIBHAL_DRIVE_TYPE_FLOPPY:
      volume_hal->kind = THUNAR_VFS_VOLUME_KIND_FLOPPY;
      break;

    case LIBHAL_DRIVE_TYPE_PORTABLE_AUDIO_PLAYER:
      volume_hal->kind = THUNAR_VFS_VOLUME_KIND_AUDIO_PLAYER;
      break;

    case LIBHAL_DRIVE_TYPE_SMART_MEDIA:
    case LIBHAL_DRIVE_TYPE_SD_MMC:
      volume_hal->kind = THUNAR_VFS_VOLUME_KIND_MEMORY_CARD;
      break;

    default:
      /* check if the drive is connected to the USB bus */
      if (libhal_drive_get_bus (hd) == LIBHAL_DRIVE_BUS_USB)
        {
          /* we consider the drive to be an USB stick */
          volume_hal->kind = THUNAR_VFS_VOLUME_KIND_USBSTICK;
        }
      else if (libhal_drive_uses_removable_media (hd)
            || libhal_drive_is_hotpluggable (hd))
        {
          /* fallback to generic removable disk */
          volume_hal->kind = THUNAR_VFS_VOLUME_KIND_REMOVABLE_DISK;
        }
      else
        {
          /* fallback to harddisk drive */
          volume_hal->kind = THUNAR_VFS_VOLUME_KIND_HARDDISK;
        }
      break;
    }

  /* either we have a volume, which means we have media, or
   * a drive, which means non-pollable then, so it's present
   */
  volume_hal->status |= THUNAR_VFS_VOLUME_STATUS_PRESENT;
  
  /* figure out if the volume is mountable */
  if(hv != NULL && libhal_volume_get_fsusage (hv) == LIBHAL_VOLUME_USAGE_MOUNTABLE_FILESYSTEM)
    volume_hal->status |= THUNAR_VFS_VOLUME_STATUS_MOUNTABLE;

  /* check if the drive requires eject */
  volume_hal->requires_eject = libhal_drive_requires_eject (hd);

  /* check if the volume is currently mounted */
  if (hv != NULL && libhal_volume_is_mounted (hv))
    {
      /* try to determine the new mount point */
      volume_hal->mount_point = thunar_vfs_path_new (libhal_volume_get_mount_point (hv), NULL);

      /* we only mark the volume as mounted if we have a valid mount point */
      if (G_LIKELY (volume_hal->mount_point != NULL))
        volume_hal->status |= THUNAR_VFS_VOLUME_STATUS_MOUNTED | THUNAR_VFS_VOLUME_STATUS_PRESENT;
    }
  else
    {
      /* we don't trust HAL, so let's see what the kernel says about the volume */
      volume_hal->mount_point = thunar_vfs_volume_hal_find_active_mount_point (volume_hal);

      /* we must have been mounted successfully if we have a mount point */
      if (G_LIKELY (volume_hal->mount_point != NULL))
        volume_hal->status |= THUNAR_VFS_VOLUME_STATUS_MOUNTED | THUNAR_VFS_VOLUME_STATUS_PRESENT;
    }

  /* check if we have to figure out the mount point ourself */
  if (G_UNLIKELY (volume_hal->mount_point == NULL))
    {
      /* ask HAL for the default mount root (falling back to /media otherwise) */
      mount_root = libhal_device_get_property_string (context, "/org/freedesktop/Hal/devices/computer", "storage.policy.default.mount_root", NULL);
      if (G_UNLIKELY (mount_root == NULL || !g_path_is_absolute (mount_root)))
        {
          /* fallback to /media (seems to be sane) */
          g_free (mount_root);
          mount_root = g_strdup ("/media");
        }

      /* lets see, maybe /etc/fstab knows where to mount */
      volume_hal->mount_point = thunar_vfs_volume_hal_find_fstab_mount_point (volume_hal);

      /* if we still don't have a mount point, ask HAL */
      if (G_UNLIKELY (volume_hal->mount_point == NULL))
        {
          /* determine the desired mount point and prepend the mount root */
          desired_mount_point = libhal_device_get_property_string (context, volume_hal->udi, "volume.policy.desired_mount_point", NULL);
          if (G_LIKELY (desired_mount_point != NULL && *desired_mount_point != '\0'))
            {
              filename = g_build_filename (mount_root, desired_mount_point, NULL);
              volume_hal->mount_point = thunar_vfs_path_new (filename, NULL);
              g_free (filename);
            }
          libhal_free_string (desired_mount_point);
        }

      /* ok, last fallback, just use <mount-root>/<device> */
      if (G_UNLIKELY (volume_hal->mount_point == NULL))
        {
          /* <mount-root>/<device> looks like a good idea */
          basename = g_path_get_basename (volume_hal->device_file);
          filename = g_build_filename (mount_root, basename, NULL);
          volume_hal->mount_point = thunar_vfs_path_new (filename, NULL);
          g_free (filename);
          g_free (basename);
        }

      /* release the mount root */
      g_free (mount_root);
    }

  /* if we get here, we must have a valid mount point */
  g_assert (volume_hal->mount_point != NULL);

  /* emit the "changed" signal */
  thunar_vfs_volume_changed (THUNAR_VFS_VOLUME (volume_hal));
}