static gboolean
ignore_mount (GMount *mount)
{
  GFile *root;
  GVolume *volume;
  gboolean ret = TRUE;

  root = g_mount_get_root (mount);

  if (g_file_has_uri_scheme (root, "burn") != FALSE || g_file_has_uri_scheme (root, "cdda") != FALSE) {
    /* We don't add Audio CDs, or blank media */
    g_object_unref (root);
    GRL_DEBUG ("%s: Not adding mount %s as is burn or cdda", __FUNCTION__,
               g_mount_get_name (mount));
    return TRUE;
  }
  g_object_unref (root);

  volume = g_mount_get_volume (mount);
  if (volume == NULL)
    return ret;

  ret = ignore_volume (volume);
  g_object_unref (volume);

  return ret;
}
示例#2
0
/**
 * gs_file_get_path_cached:
 *
 * Like g_file_get_path(), but returns a constant copy so callers
 * don't need to free the result.
 */
const char *
gs_file_get_path_cached (GFile *file)
{
    const char *path;
    static GQuark _file_path_quark = 0;

    if (G_UNLIKELY (_file_path_quark) == 0)
        _file_path_quark = g_quark_from_static_string ("gsystem-file-path");

    G_LOCK (pathname_cache);

    path = g_object_get_qdata ((GObject*)file, _file_path_quark);
    if (!path)
    {
        if (g_file_has_uri_scheme (file, "trash") ||
                g_file_has_uri_scheme (file, "recent"))
            path = gs_file_get_target_path (file);
        else
            path = g_file_get_path (file);
        if (path == NULL)
        {
            G_UNLOCK (pathname_cache);
            return NULL;
        }
        g_object_set_qdata_full ((GObject*)file, _file_path_quark, (char*)path, (GDestroyNotify)g_free);
    }

    G_UNLOCK (pathname_cache);

    return path;
}
static GList *
add_volume (GList *media_list,
            GVolume *volume,
            GDrive *drive,
            GrlOpticalMediaSource *source)
{
  char *name, *icon_uri;
  GIcon *icon;
  char *device_path, *id;
  GrlMedia * media;
  GMount *mount;

  device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
  if (device_path == NULL)
    return media_list;

  /* Is it an audio CD or a blank media */
  mount = g_volume_get_mount (volume);
  if (mount != NULL) {
    GFile *root;

    root = g_mount_get_root (mount);
    g_object_unref (mount);

    if (g_file_has_uri_scheme (root, "burn") != FALSE || g_file_has_uri_scheme (root, "cdda") != FALSE) {
      /* We don't add Audio CDs, or blank media */
      g_object_unref (root);
      g_free (device_path);
      return media_list;
    }
    g_object_unref (root);
  }

  media = grl_media_video_new ();

  id = g_filename_to_uri (device_path, NULL, NULL);
  g_free (device_path);

  grl_media_set_id (media, id);
  g_free (id);

  /* Work out an icon to display */
  icon = g_volume_get_icon (volume);
  icon_uri = get_uri_for_gicon (icon);
  g_object_unref (icon);
  grl_media_set_thumbnail (media, icon_uri);
  g_free (icon_uri);

  /* Get the volume's pretty name for the menu label */
  name = g_volume_get_name (volume);
  g_strstrip (name);
  grl_media_set_title (media, name);
  g_free (name);

  grl_media_set_mime (media, "x-special/device-block");

  return g_list_prepend (media_list, media);
}
示例#4
0
static void append_file_to_cmd(GFile* gf, GString* cmd)
{
    char* file = g_file_get_path(gf);
    char* quote;
    if(file == NULL) /* trash:// gvfs is incomplete in resolving it */
    {
        /* we can retrieve real path from GVFS >= 1.13.3 */
        if(g_file_has_uri_scheme(gf, "trash"))
        {
            GFileInfo *inf;
            const char *orig_path;

            inf = g_file_query_info(gf, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI,
                                    G_FILE_QUERY_INFO_NONE, NULL, NULL);
            if(inf == NULL) /* failed */
                return;
            orig_path = g_file_info_get_attribute_string(inf, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
            if(orig_path != NULL) /* success */
                file = g_filename_from_uri(orig_path, NULL, NULL);
            g_object_unref(inf);
        }
        if(file == NULL)
            return;
    }
    quote = g_shell_quote(file);
    g_string_append(cmd, quote);
    g_string_append_c(cmd, ' ');
    g_free(quote);
    g_free(file);
}
示例#5
0
static void
unmount_all_with_scheme (const char *scheme)
{
  GVolumeMonitor *volume_monitor;
  GList *mounts;
  GList *l;

  volume_monitor = g_volume_monitor_get();

  /* populate gvfs network mounts */
  iterate_gmain();

  mounts = g_volume_monitor_get_mounts (volume_monitor);
  for (l = mounts; l != NULL; l = l->next) {
    GMount *mount = G_MOUNT (l->data);
    GFile *root;

    root = g_mount_get_root (mount);
    if (g_file_has_uri_scheme (root, scheme)) {
            unmount (root);
    }
    g_object_unref (root);
  }
  g_list_foreach (mounts, (GFunc)g_object_unref, NULL);
  g_list_free (mounts);

  g_object_unref (volume_monitor);
}
示例#6
0
文件: gtkutils.c 项目: endlessm/gtk
GBytes *
gtk_file_load_bytes (GFile         *file,
                     GCancellable  *cancellable,
                     GError       **error)
{
  gchar *contents;
  gsize len;

  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);

  if (g_file_has_uri_scheme (file, "resource"))
    {
      gchar *uri, *unescaped;
      GBytes *bytes;

      uri = g_file_get_uri (file);
      unescaped = g_uri_unescape_string (uri + strlen ("resource://"), NULL);
      g_free (uri);

      bytes = g_resources_lookup_data (unescaped, 0, error);
      g_free (unescaped);

      return bytes;
    }

  /* contents is always \0 terminated, but we don't include that in the bytes */
  if (g_file_load_contents (file, cancellable, &contents, &len, NULL, error))
    return g_bytes_new_take (contents, len);

  return NULL;
}
static guint
impl_want_uri (RBSource *source, const char *uri)
{
	GVolume *volume;
	GMount *mount;
	GFile *file;
	int retval;

	retval = 0;

	file = g_file_new_for_uri (uri);
	if (g_file_has_uri_scheme (file, "cdda") == FALSE) {
		g_object_unref (file);
		return 0;
	}

	g_object_get (G_OBJECT (source),
		      "volume", &volume,
		      NULL);
	if (volume == NULL)
		return 0;

	mount = g_volume_get_mount (volume);
	if (mount) {
		GFile *root;

		root = g_mount_get_root (mount);
		retval = g_file_equal (root, file) ? 100 : 0;
		g_object_unref (mount);
		g_object_unref (root);
	}
	g_object_unref (file);

	return retval;
}
示例#8
0
文件: utils.c 项目: ylatuya/snappy
gchar *
clean_uri (gchar * input_arg)
{
  GFile *gfile;
  gchar *fileuri;

  if (gst_uri_is_valid (input_arg))
    fileuri = g_strdup (input_arg);
  else {
    gfile = g_file_new_for_commandline_arg (input_arg);
    if (g_file_has_uri_scheme (gfile, "archive") != FALSE) {
      g_print ("ERROR: %s isn't a file\n", input_arg);
    }

    fileuri = g_file_get_path (gfile);

    if (g_str_has_suffix (fileuri, ".iso")) {
      fileuri = g_strdup_printf ("dvd://%s", fileuri);
    } else {
      fileuri = g_strdup_printf ("file://%s", fileuri);
    }
  }

  return fileuri;
}
示例#9
0
static gboolean
gtk_css_image_url_parse (GtkCssImage  *image,
                         GtkCssParser *parser)
{
  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);
  GdkPixbuf *pixbuf;
  GFile *file;
  cairo_t *cr;
  GError *error = NULL;
  GFileInputStream *input;

  file = _gtk_css_parser_read_url (parser);
  if (file == NULL)
    return FALSE;

  /* We special case resources here so we can use
     gdk_pixbuf_new_from_resource, which in turn has some special casing
     for GdkPixdata files to avoid duplicating the memory for the pixbufs */
  if (g_file_has_uri_scheme (file, "resource"))
    {
      char *uri = g_file_get_uri (file);
      char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);

      pixbuf = gdk_pixbuf_new_from_resource (resource_path, &error);
      g_free (resource_path);
      g_free (uri);
    }
  else
    {
      input = g_file_read (file, NULL, &error);
      if (input == NULL)
	{
	  _gtk_css_parser_take_error (parser, error);
	  return FALSE;
	}

      pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &error);
      g_object_unref (input);
    }
  g_object_unref (file);

  if (pixbuf == NULL)
    {
      _gtk_css_parser_take_error (parser, error);
      return FALSE;
    }

  url->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                             gdk_pixbuf_get_width (pixbuf),
                                             gdk_pixbuf_get_height (pixbuf));
  cr = cairo_create (url->surface);
  gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
  cairo_paint (cr);
  cairo_destroy (cr);
  g_object_unref (pixbuf);

  return TRUE;
}
示例#10
0
gboolean
rb_ipod_helpers_is_ipod (GMount *mount, MPIDDevice *device_info)
{
	GFile *root;
	gboolean result = FALSE;
	char **protocols;

	/* if we have specific information about the device, use it.
	 * otherwise, check if the device has an ipod device directory on it.
	 */
	g_object_get (device_info, "access-protocols", &protocols, NULL);
	if (protocols != NULL && g_strv_length (protocols) > 0) {
		int i;

		for (i = 0; protocols[i] != NULL; i++) {
			if (g_str_equal (protocols[i], "ipod")) {
				result = TRUE;
				break;
			}
		}
	} else {
		root = g_mount_get_root (mount);
		if (root != NULL) {
			gchar *device_dir;

			if (g_file_has_uri_scheme (root, "afc") != FALSE) {
				gchar *uri;
				uri = g_file_get_uri (root);
				/* afc://<40 chars>:stuff */
				g_assert (strlen (uri) >= 46);
				if (uri[6 + 40] == ':' &&
				    uri[6 + 40 + 1] != '1') {
					result = FALSE;
				} else {
					result = TRUE;
				}
				g_free (uri);
			} else {
				gchar *mount_point;
				mount_point = g_file_get_path (root);
				if (mount_point != NULL) {
					device_dir = itdb_get_device_dir (mount_point);
					if (device_dir != NULL)  {
						result = g_file_test (device_dir,
								      G_FILE_TEST_IS_DIR);
						g_free (device_dir);
					}
				}

				g_free (mount_point);
			}
			g_object_unref (root);
		}
	}

	g_strfreev (protocols);
	return result;
}
示例#11
0
static GtkCssImage *
gtk_css_image_url_load_image (GtkCssImageUrl *url)
{
  GdkPixbuf *pixbuf;
  GError *error = NULL;
  GFileInputStream *input;

  if (url->loaded_image)
    return url->loaded_image;

  /* We special case resources here so we can use
     gdk_pixbuf_new_from_resource, which in turn has some special casing
     for GdkPixdata files to avoid duplicating the memory for the pixbufs */
  if (g_file_has_uri_scheme (url->file, "resource"))
    {
      char *uri = g_file_get_uri (url->file);
      char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);

      pixbuf = gdk_pixbuf_new_from_resource (resource_path, &error);
      g_free (resource_path);
      g_free (uri);
    }
  else
    {
      input = g_file_read (url->file, NULL, &error);
      if (input != NULL)
	{
          pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (input), NULL, &error);
          g_object_unref (input);
	}
      else
        {
          pixbuf = NULL;
        }
    }

  if (pixbuf == NULL)
    {
      cairo_surface_t *empty = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0);

      /* XXX: Can we get the error somehow sent to the CssProvider?
       * I don't like just dumping it to stderr or losing it completely. */
      g_warning ("Error loading image: %s", error->message);
      g_error_free (error);
      url->loaded_image = _gtk_css_image_surface_new (empty);
      cairo_surface_destroy (empty);
      return url->loaded_image; 
    }

  url->loaded_image = _gtk_css_image_surface_new_for_pixbuf (pixbuf);
  g_object_unref (pixbuf);

  return url->loaded_image;
}
示例#12
0
static GtkCssImage *
gtk_css_image_url_load_image (GtkCssImageUrl  *url,
                              GError         **error)
{
  GdkTexture *texture;
  GError *local_error = NULL;

  if (url->loaded_image)
    return url->loaded_image;

  /* We special case resources here so we can use
     gdk_pixbuf_new_from_resource, which in turn has some special casing
     for GdkPixdata files to avoid duplicating the memory for the pixbufs */
  if (g_file_has_uri_scheme (url->file, "resource"))
    {
      char *uri = g_file_get_uri (url->file);
      char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);

      texture = gdk_texture_new_from_resource (resource_path);

      g_free (resource_path);
      g_free (uri);
    }
  else
    {
      texture = gdk_texture_new_from_file (url->file, &local_error);
    }

  if (texture == NULL)
    {
      if (error)
        {
          char *uri;

          uri = g_file_get_uri (url->file);
          g_set_error (error,
                       GTK_CSS_PARSER_ERROR,
                       GTK_CSS_PARSER_ERROR_FAILED,
                       "Error loading image '%s': %s", uri, local_error->message);
          g_free (uri);
       }
      
      url->loaded_image = gtk_css_image_invalid_new ();
    }
  else
    {
      url->loaded_image = gtk_css_image_paintable_new (GDK_PAINTABLE (texture), GDK_PAINTABLE (texture));
      g_object_unref (texture);
    }

  g_clear_error (&local_error);

  return url->loaded_image;
}
示例#13
0
gboolean
nemo_directory_is_in_recent (NemoDirectory *directory)
{
   g_assert (NEMO_IS_DIRECTORY (directory));

   if (directory->details->location == NULL) {
       return FALSE;
   }

   return g_file_has_uri_scheme (directory->details->location, "recent");
}
示例#14
0
gboolean
nautilus_directory_is_in_trash (NautilusDirectory *directory)
{
	g_assert (NAUTILUS_IS_DIRECTORY (directory));
	
	if (directory->details->location == NULL) {
		return FALSE;
	}

	return g_file_has_uri_scheme (directory->details->location, "trash");
}
IdolPlParserResult
idol_pl_parser_add_itms (IdolPlParser *parser,
			  GFile *file,
			  GFile *base_file,
			  IdolPlParseData *parse_data,
			  gpointer data)
{
#ifndef HAVE_GMIME
	WARN_NO_GMIME;
#else
	GByteArray *content;
	char *itms_uri;
	GFile *feed_file;
	IdolPlParserResult ret;

	if (g_file_has_uri_scheme (file, "itms") != FALSE) {
		itms_uri= g_file_get_uri (file);
		memcpy (itms_uri, "http", 4);
	} else if (g_file_has_uri_scheme (file, "http") != FALSE) {
		itms_uri = g_file_get_uri (file);
	} else {
		return IDOL_PL_PARSER_RESULT_ERROR;
	}

	/* Load the file using iTunes user-agent */
	content = idol_pl_parser_load_http_itunes (itms_uri);

	/* And look in the file for the feedURL */
	feed_file = idol_pl_parser_get_feed_uri ((char *) content->data, content->len);
	g_byte_array_free (content, TRUE);
	if (feed_file == NULL)
		return IDOL_PL_PARSER_RESULT_ERROR;

	DEBUG(feed_file, g_print ("Found feed URI: %s\n", uri));

	ret = idol_pl_parser_add_rss (parser, feed_file, NULL, parse_data, NULL);
	g_object_unref (feed_file);

	return ret;
#endif /* !HAVE_GMIME */
}
示例#16
0
/* Returns true if uri is a file: uri and is not a chained uri */
gboolean
gedit_utils_uri_has_file_scheme (const gchar *uri)
{
	GFile *gfile;
	gboolean res;

	gfile = g_file_new_for_uri (uri);
	res = g_file_has_uri_scheme (gfile, "file");
	
	g_object_unref (gfile);
	return res;
}
示例#17
0
/**
 * gtk_source_file_is_local:
 * @file: a #GtkSourceFile.
 *
 * Returns whether the file is local. If the #GtkSourceFile:location is %NULL,
 * returns %FALSE.
 *
 * Returns: whether the file is local.
 * Since: 3.18
 */
gboolean
gtk_source_file_is_local (GtkSourceFile *file)
{
	g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);

	if (file->priv->location == NULL)
	{
		return FALSE;
	}

	return g_file_has_uri_scheme (file->priv->location, "file");
}
gboolean
idol_pl_parser_is_itms_feed (GFile *file)
{
	char *uri;

	g_return_val_if_fail (file != NULL, FALSE);

	uri = g_file_get_uri (file);

	if (g_file_has_uri_scheme (file, "itms") != FALSE ||
	    (g_file_has_uri_scheme (file, "http") != FALSE &&
	     strstr (uri, ".apple.com/") != FALSE)) {
		if (strstr (uri, "/podcast/") != NULL ||
		    strstr (uri, "viewPodcast") != NULL) {
			g_free (uri);
			return TRUE;
		}
	}

	g_free (uri);

	return FALSE;
}
示例#19
0
文件: gitg.c 项目: epronk/gitg
static void
link_button_uri_hook (GtkLinkButton *button,
                      gchar const   *link_,
                      GitgWindow    *window)
{
	GFile *file;
	GitgRepository *repository;

	file = g_file_new_for_uri (link_);
	repository = gitg_window_get_repository (window);

	if (!g_file_has_uri_scheme (file, "gitg"))
	{
		original_link_button_hook (button, link_, NULL);
	}
	else if (repository)
	{
		gchar *work_tree_path;
		gchar *selection;
		gchar *activatable;
		gchar *action;

		if (gitg_uri_parse (link_, &work_tree_path, &selection, &activatable, &action))
		{
			GFile *wt;
			GFile *work_tree;
			gboolean equal;

			wt = gitg_repository_get_work_tree (repository);
			work_tree = g_file_new_for_path (work_tree_path);
			equal = g_file_equal (wt, work_tree);

			g_object_unref (wt);
			g_object_unref (work_tree);

			if (equal)
			{
				gitg_window_select (window, selection);
				gitg_window_activate (window, activatable, action);
			}

			g_free (work_tree_path);
			g_free (selection);
			g_free (activatable);
			g_free (action);
		}
	}

	g_object_unref (file);
}
示例#20
0
文件: utils.c 项目: phako/snappy
gchar *
clean_uri (gchar * input_arg)
{
  GFile *gfile;
  gchar *filepath;

  gfile = g_file_new_for_commandline_arg (input_arg);
  if (g_file_has_uri_scheme (gfile, "archive") != FALSE) {
    g_print ("ERROR: %s isn't a file\n", input_arg);
  }

  filepath = g_file_get_path (gfile);

  return filepath;
}
static GIcon *
xfdesktop_special_file_icon_load_icon(XfdesktopIcon *icon)
{
    XfdesktopSpecialFileIcon *special_icon = XFDESKTOP_SPECIAL_FILE_ICON(icon);
    XfdesktopFileIcon *file_icon = XFDESKTOP_FILE_ICON(icon);
    gchar *icon_name = NULL;
    GFile *parent = NULL;
    GIcon *gicon = NULL;

    TRACE("entering");

    /* use a custom icon name for the local filesystem root */
    parent = g_file_get_parent(special_icon->priv->file);
    if(!parent && g_file_has_uri_scheme(special_icon->priv->file, "file"))
        icon_name = g_strdup("drive-harddisk");

    if(parent)
        g_object_unref(parent);

    /* use a custom icon for the trash, based on it having files
     * the user can delete */
    if(special_icon->priv->type == XFDESKTOP_SPECIAL_FILE_ICON_TRASH) {
        if(special_icon->priv->trash_item_count == 0)
            icon_name = g_strdup("user-trash");
        else
            icon_name = g_strdup("user-trash-full");
    }

    /* Create the themed icon for it */
    if(icon_name) {
        gicon = g_themed_icon_new(icon_name);
        g_free(icon_name);
    }

    /* If we still don't have an icon, use the default */
    if(!G_IS_ICON(gicon)) {
        gicon = g_file_info_get_icon(special_icon->priv->file_info);
        if(G_IS_ICON(gicon))
            g_object_ref(gicon);
    }

    g_object_set(file_icon, "gicon", gicon, NULL);

    /* Add any user set emblems */
    gicon = xfdesktop_file_icon_add_emblems(file_icon);

    return gicon;
}
示例#22
0
gboolean
gedit_document_is_local (GeditDocument *doc)
{
	GFile *location;

	g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);

	location = gtk_source_file_get_location (doc->priv->file);

	if (location == NULL)
	{
		return FALSE;
	}

	return g_file_has_uri_scheme (location, "file");
}
示例#23
0
static void
ensure_monitor_for_file (StTextureCache *cache,
                         GFile          *file)
{
  StTextureCachePrivate *priv = cache->priv;

  /* No point in trying to monitor files that are part of a
   * GResource, since it does not support file monitoring.
   */
  if (g_file_has_uri_scheme (file, "resource"))
    return;

  if (g_hash_table_lookup (priv->file_monitors, file) == NULL)
    {
      GFileMonitor *monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE,
                                                   NULL, NULL);
      g_signal_connect (monitor, "changed",
                        G_CALLBACK (file_changed_cb), cache);
      g_hash_table_insert (priv->file_monitors, g_object_ref (file), monitor);
    }
}
示例#24
0
void
gedit_recent_remove_if_local (GFile *location)
{
    g_return_if_fail (G_IS_FILE (location));

    /* If a file is local chances are that if load/save fails the file has
     * beed removed and the failure is permanent so we remove it from the
     * list of recent files. For remote files the failure may be just
     * transitory and we keep the file in the list.
     */
    if (g_file_has_uri_scheme (location, "file"))
    {
        GtkRecentManager *recent_manager;
        gchar *uri;

        recent_manager = gtk_recent_manager_get_default ();

        uri = g_file_get_uri (location);
        gtk_recent_manager_remove_item (recent_manager, uri, NULL);
        g_free (uri);
    }
}
示例#25
0
static void
folder_changed_cb (GthMonitor      *monitor,
                   GFile           *parent,
                   GList           *list /* GFile list */,
                   int              position,
                   GthMonitorEvent  event,
                   gpointer         user_data)
{
    BrowserData *data = user_data;
    int          n_selection;

    if (event == GTH_MONITOR_EVENT_CHANGED)
        return;

    if (! g_file_has_uri_scheme (parent, "selection"))
        return;

    n_selection = _g_file_get_n_selection (parent);
    if (n_selection <= 0)
        return;

    gtk_widget_set_sensitive (data->selection_buttons[n_selection - 1], ! gth_selections_manager_get_is_empty (n_selection));
}
示例#26
0
static GList*
twp_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
                               GtkWidget           *window,
                               GList               *files)
{
  GtkWidget *action = NULL;
  GFile     *location;
  GList     *actions = NULL;
  gchar      selection_name[100];
  Atom       xfce_selection_atom;
  Atom       nautilus_selection_atom;
  GdkScreen *gdk_screen = gdk_screen_get_default();
  gint       xscreen = gdk_screen_get_number(gdk_screen);

  desktop_type = DESKTOP_TYPE_NONE;

  /* we can only set a single wallpaper */
  if (files->next == NULL)
    {
      /* get the location of the file */
      location = thunarx_file_info_get_location (files->data);

      /* unable to handle non-local files */
      if (G_UNLIKELY (!g_file_has_uri_scheme (location, "file")))
        {
          g_object_unref (location);
          return NULL;
        }

      /* release the location */
      g_object_unref (location);

      if (!thunarx_file_info_is_directory (files->data))
        {
          if (thunarx_file_info_has_mime_type (files->data, "image/jpeg")
              ||thunarx_file_info_has_mime_type (files->data, "image/png")
              ||thunarx_file_info_has_mime_type (files->data, "image/svg+xml")
              ||thunarx_file_info_has_mime_type (files->data, "image/svg+xml-compressed"))
            {
              action = g_object_new (GTK_TYPE_ACTION,
                                     "name", "Twp::setwallpaper",
                                     "icon-name", "background",
                                     "label", _("Set as wallpaper"),
                                     NULL);
              g_signal_connect (action, "activate", G_CALLBACK (twp_action_set_wallpaper), files->data);

              actions = g_list_append (actions, action);
            }
        }
    }

  g_snprintf(selection_name, 100, XFDESKTOP_SELECTION_FMT, xscreen);
  xfce_selection_atom = XInternAtom (gdk_display, selection_name, False);

  if ((XGetSelectionOwner(GDK_DISPLAY(), xfce_selection_atom)))
    {
      if (_has_xfconf_query)
          desktop_type = DESKTOP_TYPE_XFCE;
    }
  else
    {
      /* FIXME: This is wrong, nautilus WINDOW_ID is not a selection */
      g_snprintf(selection_name, 100, NAUTILUS_SELECTION_FMT);
      nautilus_selection_atom = XInternAtom (gdk_display, selection_name, False);
      if((XGetSelectionOwner(GDK_DISPLAY(), nautilus_selection_atom)))
      {
          if (_has_gconftool)
              desktop_type = DESKTOP_TYPE_NAUTILUS;
      }
    }

  if ((desktop_type == DESKTOP_TYPE_NONE) && (action != NULL))
    {
        /* gtk_widget_set_sensitive (action, FALSE); */
    }

  return actions;
}
示例#27
0
/**
 * rb_device_source_want_uri:
 * @source: a #RBDeviceSource
 * @uri: a URI to consider
 *
 * Checks whether @uri identifies a path underneath the
 * device's mount point.  Should be used to implement
 * the #RBSource impl_want_uri method.
 *
 * Return value: URI match strength
 */
int
rb_device_source_want_uri (RBDeviceSource *source, const char *uri)
{
	GMount *mount = NULL;
	GVolume *volume = NULL;
	GFile *file;
	char *device_path, *uri_path;
	int retval;
	int len;

	retval = 0;

	/* ignore anything that isn't a local file */
	file = g_file_new_for_uri (uri);
	if (g_file_has_uri_scheme (file, "file") == FALSE) {
		g_object_unref (file);
		return 0;
	}

	/* Deal with the mount root being passed, eg. file:///media/IPODNAME */
	if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "mount")) {
		g_object_get (source, "mount", &volume, NULL);
	}
	if (mount != NULL) {
		GFile *root;

		root = g_mount_get_root (mount);
		retval = g_file_equal (root, file) ? 100 : 0;
		g_object_unref (root);
		if (retval) {
			g_object_unref (file);
			g_object_unref (mount);
			return retval;
		}
		volume = g_mount_get_volume (mount);
		g_object_unref (mount);
	} else {
		if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "volume")) {
			g_object_get (source, "volume", &volume, NULL);
		}
	}

	if (volume == NULL) {
		g_object_unref (file);
		return 0;
	}

	/* Deal with the path to the device node being passed */
	device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
	g_object_unref (volume);
	if (device_path == NULL) {
		g_object_unref (file);
		return 0;
	}

	uri_path = g_file_get_path (file);
	g_object_unref (file);
	if (uri_path == NULL)
		return 0;
	len = strlen (uri_path);
	if (uri_path[len - 1] == '/') {
		if (strncmp (uri_path, device_path, len - 1) == 0) {
			retval = 100;
		}
	} else if (strcmp (uri_path, device_path) == 0) {
		retval = 100;
	}

	g_free (device_path);
	g_free (uri_path);
	return retval;
}
static gboolean rotation_plugin_try_restore_state_co (RotationPluginTryRestoreStateData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = NULL;
	_data_->_tmp0_ = _data_->mrl;
	_data_->_tmp1_ = NULL;
	_data_->_tmp1_ = g_file_new_for_uri (_data_->_tmp0_);
	_data_->file = _data_->_tmp1_;
	_data_->_tmp3_ = NULL;
	_data_->_tmp3_ = _data_->file;
	_data_->_tmp4_ = FALSE;
	_data_->_tmp4_ = g_file_has_uri_scheme (_data_->_tmp3_, "http");
	if (_data_->_tmp4_) {
		_data_->_tmp2_ = TRUE;
	} else {
		_data_->_tmp5_ = NULL;
		_data_->_tmp5_ = _data_->file;
		_data_->_tmp6_ = FALSE;
		_data_->_tmp6_ = g_file_has_uri_scheme (_data_->_tmp5_, "dvd");
		_data_->_tmp2_ = _data_->_tmp6_;
	}
	if (_data_->_tmp2_) {
		_g_object_unref0 (_data_->file);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		_data_->_tmp7_ = NULL;
		_data_->_tmp7_ = _data_->file;
		_data_->_state_ = 1;
		g_file_query_info_async (_data_->_tmp7_, GIO_ROTATION_FILE_ATTRIBUTE, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, NULL, rotation_plugin_try_restore_state_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp8_ = NULL;
		_data_->_tmp8_ = g_file_query_info_finish (_data_->_tmp7_, _data_->_res_, &_data_->_inner_error_);
		_data_->file_info = _data_->_tmp8_;
		if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
			if (g_error_matches (_data_->_inner_error_, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) {
				goto __catch1_g_io_error_not_supported;
			}
			goto __catch1_g_error;
		}
		_data_->_tmp9_ = NULL;
		_data_->_tmp9_ = _data_->file_info;
		_data_->_tmp10_ = NULL;
		_data_->_tmp10_ = g_file_info_get_attribute_string (_data_->_tmp9_, GIO_ROTATION_FILE_ATTRIBUTE);
		_data_->_tmp11_ = NULL;
		_data_->_tmp11_ = g_strdup (_data_->_tmp10_);
		_data_->state_str = _data_->_tmp11_;
		_data_->_tmp12_ = NULL;
		_data_->_tmp12_ = _data_->state_str;
		if (_data_->_tmp12_ != NULL) {
			_data_->_tmp13_ = NULL;
			_data_->_tmp13_ = _data_->state_str;
			_data_->_tmp14_ = 0ULL;
			_data_->_tmp14_ = uint64_parse (_data_->_tmp13_);
			_data_->state = (gint) ((BvwRotation) _data_->_tmp14_);
			_data_->_tmp15_ = NULL;
			_data_->_tmp15_ = _data_->self->priv->bvw;
			_data_->_tmp16_ = 0;
			_data_->_tmp16_ = _data_->state;
			bacon_video_widget_set_rotation (_data_->_tmp15_, (BvwRotation) _data_->_tmp16_);
		}
		_g_free0 (_data_->state_str);
		_g_object_unref0 (_data_->file_info);
	}
	goto __finally1;
	__catch1_g_io_error_not_supported:
	{
		_data_->e = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_g_error_free0 (_data_->e);
	}
	goto __finally1;
	__catch1_g_error:
	{
		_data_->_vala1_e = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp17_ = NULL;
		_data_->_tmp17_ = _data_->_vala1_e;
		_data_->_tmp18_ = NULL;
		_data_->_tmp18_ = _data_->_tmp17_->message;
		g_warning ("totem-rotation-plugin.vala:175: Could not query file attribute: %s", _data_->_tmp18_);
		_g_error_free0 (_data_->_vala1_e);
	}
	__finally1:
	if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
		_g_object_unref0 (_data_->file);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
		g_clear_error (&_data_->_inner_error_);
		return FALSE;
	}
	_g_object_unref0 (_data_->file);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}
示例#29
0
void
nautilus_drag_default_drop_action_for_icons (GdkDragContext *context,
					     const char *target_uri_string, const GList *items,
					     int *action)
{
	gboolean same_fs;
	gboolean target_is_source_parent;
	const char *dropped_uri;
	GFile *target, *dropped;
	GdkDragAction actions;
	NautilusFile *target_file;

	if (target_uri_string == NULL) {
		*action = 0;
		return;
	}

	actions = context->actions & (GDK_ACTION_MOVE | GDK_ACTION_COPY);
	if (actions == 0) {
		 /* We can't use copy or move, just go with the suggested action. */
		*action = context->suggested_action;
		return;
	}

	if (context->suggested_action == GDK_ACTION_ASK) {
		/* Don't override ask */
		*action = context->suggested_action;
		return;
	}
	
	dropped_uri = ((NautilusDragSelectionItem *)items->data)->uri;
	target_file = nautilus_file_get_existing_by_uri (dropped_uri);
	
	/*
	 * Check for trash URI.  We do a find_directory for any Trash directory.
	 * Passing 0 permissions as gnome-vfs would override the permissions
	 * passed with 700 while creating .Trash directory
	 */
	if (eel_uri_is_trash (target_uri_string)) {
		/* Only move to Trash */
		if (actions & GDK_ACTION_MOVE) {
			*action = GDK_ACTION_MOVE;
		}

		nautilus_file_unref (target_file);
		return;

	} else if (target_file != NULL && nautilus_file_is_launcher (target_file)) {
		if (actions & GDK_ACTION_MOVE) {
			*action = GDK_ACTION_MOVE;
		}
		nautilus_file_unref (target_file);
		return;
	} else if (eel_uri_is_desktop (target_uri_string)) {
		target = nautilus_get_desktop_location ();
		if (eel_uri_is_desktop (dropped_uri)) {
			/* Only move to Desktop icons */
			if (actions & GDK_ACTION_MOVE) {
				*action = GDK_ACTION_MOVE;
			}
			
			nautilus_file_unref (target_file);
			return;
		}
	} else {
		target = g_file_new_for_uri (target_uri_string);
	}

	nautilus_file_unref (target_file);
	
	/* Compare the first dropped uri with the target uri for same fs match. */
	dropped = g_file_new_for_uri (dropped_uri);
	same_fs = check_same_fs (target, dropped);
	target_is_source_parent = g_file_has_prefix (dropped, target);
	
	if (same_fs || target_is_source_parent ||
	    g_file_has_uri_scheme (dropped, "trash")) {
		if (actions & GDK_ACTION_MOVE) {
			*action = GDK_ACTION_MOVE;
		} else {
			*action = context->suggested_action;
		}
	} else {
		if (actions & GDK_ACTION_COPY) {
			*action = GDK_ACTION_COPY;
		} else {
			*action = context->suggested_action;
		}
	}

	g_object_unref (target);
	g_object_unref (dropped);
	
}
示例#30
0
/**
 * gedit_utils_basename_for_display:
 * @location: location for which the basename should be displayed
 *
 * Returns: (transfer full): the basename of a file suitable for display to users.
 */
gchar *
gedit_utils_basename_for_display (GFile *location)
{
	gchar *name;
	gchar *hn;
	gchar *uri;

	g_return_val_if_fail (G_IS_FILE (location), NULL);

	uri = g_file_get_uri (location);

	/* First, try to query the display name, but only on local files */
	if (g_file_has_uri_scheme (location, "file"))
	{
		GFileInfo *info;

		info = g_file_query_info (location,
					  G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
					  G_FILE_QUERY_INFO_NONE,
					  NULL,
					  NULL);

		if (info)
		{
			/* Simply get the display name to use as the basename */
			name = g_strdup (g_file_info_get_display_name (info));
			g_object_unref (info);
		}
		else
		{
			/* This is a local file, and therefore we will use
			 * g_filename_display_basename on the local path */
			gchar *local_path;

			local_path = g_file_get_path (location);
			name = g_filename_display_basename (local_path);
			g_free (local_path);
		}
	}
	else if (g_file_has_parent (location, NULL) ||
	          !gedit_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL))
	{
		/* For remote files with a parent (so not just http://foo.com)
		   or remote file for which the decoding of the host name fails,
		   use the _parse_name and take basename of that */
		gchar *parse_name;
		gchar *base;

		parse_name = g_file_get_parse_name (location);
		base = g_filename_display_basename (parse_name);
		name = g_uri_unescape_string (base, NULL);

		g_free (base);
		g_free (parse_name);
	}
	else
	{
		/* display '/ on <host>' using the decoded host */
		gchar *hn_utf8;

		if  (hn != NULL)
		{
			hn_utf8 = gedit_utils_make_valid_utf8 (hn);
		}
		else
		{
			/* we should never get here */
			hn_utf8 = g_strdup ("?");
		}

		/* Translators: '/ on <remote-share>' */
		name = g_strdup_printf (_("/ on %s"), hn_utf8);

		g_free (hn_utf8);
		g_free (hn);
	}

	g_free (uri);

	return name;
}