Example #1
0
static gboolean
ide_git_vcs_is_ignored (IdeVcs  *vcs,
                        GFile   *file,
                        GError **error)
{
  g_autofree gchar *name = NULL;
  IdeGitVcs *self = (IdeGitVcs *)vcs;
  gboolean ret = FALSE;

  g_assert (IDE_IS_GIT_VCS (self));
  g_assert (G_IS_FILE (file));

  name = g_file_get_relative_path (self->working_directory, file);
  if (g_strcmp0 (name, ".git") == 0)
    return TRUE;

  if (name != NULL)
    return ggit_repository_path_is_ignored (self->repository, name, error);

  return ret;
}
static gboolean
compare_to_file (gconstpointer a,
                 gconstpointer b)
{
  GFile *file = (GFile *)a;
  GObject *item = (GObject *)b;

  /*
   * Our key (the GFile) is always @a.
   * The potential match (maybe a GbProjectFile) is @b.
   * @b may also be NULL.
   */

  g_assert (G_IS_FILE (file));
  g_assert (!item || G_IS_OBJECT (item));

  if (GB_IS_PROJECT_FILE (item))
    return g_file_equal (file, gb_project_file_get_file (GB_PROJECT_FILE (item)));

  return FALSE;
}
/**
 * ide_build_system_new_async:
 * @context: #IdeBuildSystem
 * @project_file: A #GFile containing the directory or project file.
 * @cancellable: (allow-none): A #GCancellable
 * @callback: A callback to execute upon completion
 * @user_data: User data for @callback.
 *
 * Asynchronously creates a new #IdeBuildSystem instance using the registered
 * #GIOExtensionPoint system. Each extension point will be tried asynchronously
 * by priority until one has been found that supports @project_file.
 *
 * If no build system could be found, then ide_build_system_new_finish() will
 * return %NULL.
 */
void
ide_build_system_new_async (IdeContext          *context,
                            GFile               *project_file,
                            GCancellable        *cancellable,
                            GAsyncReadyCallback  callback,
                            gpointer             user_data)
{
  g_return_if_fail (IDE_IS_CONTEXT (context));
  g_return_if_fail (G_IS_FILE (project_file));
  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));

  ide_object_new_for_extension_async (IDE_TYPE_BUILD_SYSTEM,
                                      sort_priority, NULL,
                                      G_PRIORITY_DEFAULT,
                                      cancellable,
                                      callback,
                                      user_data,
                                      "context", context,
                                      "project-file", project_file,
                                      NULL);
}
Example #4
0
/**
 * ide_project_files_find_file:
 * @self: (in): A #IdeProjectFiles.
 * @file: A #GFile.
 *
 * Tries to locate an #IdeProjectFile matching the given file.
 * If @file is the working directory, @self is returned.
 *
 * Returns: (transfer none) (nullable): An #IdeProjectItem or %NULL.
 */
IdeProjectItem *
ide_project_files_find_file (IdeProjectFiles *self,
                             GFile           *file)
{
  IdeProjectItem *item;
  IdeContext *context;
  IdeVcs *vcs;
  GFile *workdir;
  gchar **parts;
  gchar *path;
  gsize i;

  g_return_val_if_fail (IDE_IS_PROJECT_FILES (self), NULL);
  g_return_val_if_fail (G_IS_FILE (file), NULL);

  item = IDE_PROJECT_ITEM (self);
  context = ide_object_get_context (IDE_OBJECT (self));
  vcs = ide_context_get_vcs (context);
  workdir = ide_vcs_get_working_directory (vcs);

  if (g_file_equal (workdir, file))
    return IDE_PROJECT_ITEM (self);

  path = g_file_get_relative_path (workdir, file);
  if (path == NULL)
    return NULL;

  parts = g_strsplit (path, G_DIR_SEPARATOR_S, 0);

  for (i = 0; parts [i]; i++)
    {
      if (!(item = ide_project_files_find_child (item, parts [i])))
        break;
    }

  g_strfreev (parts);
  g_free (path);

  return item;
}
/**
 * gimp_color_profile_combo_box_set_active_file:
 * @combo: a #GimpColorProfileComboBox
 * @file:  file of the profile to select
 * @label: label to use when adding a new entry (can be %NULL)
 *
 * Selects a color profile from the @combo and makes it the active
 * item.  If the profile is not listed in the @combo, then it is added
 * with the given @label (or @file in case that @label is %NULL).
 *
 * Since: 2.10
 **/
void
gimp_color_profile_combo_box_set_active_file (GimpColorProfileComboBox *combo,
                                              GFile                    *file,
                                              const gchar              *label)
{
  GimpColorProfile *profile = NULL;
  GtkTreeModel     *model;
  GtkTreeIter       iter;

  g_return_if_fail (GIMP_IS_COLOR_PROFILE_COMBO_BOX (combo));
  g_return_if_fail (file == NULL || G_IS_FILE (file));

  model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));

  if (file && ! (label && *label))
    {
      GError *error = NULL;

      profile = gimp_color_profile_new_from_file (file, &error);

      if (! profile)
        {
          g_message ("%s", error->message);
          g_clear_error (&error);
        }
      else
        {
          label = gimp_color_profile_get_label (profile);
        }
    }

  if (_gimp_color_profile_store_history_add (GIMP_COLOR_PROFILE_STORE (model),
                                             file, label, &iter))
    {
      gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
    }

  if (profile)
    g_object_unref (profile);
}
Example #6
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);
    }
}
Example #7
0
/**
 * gimp_config_serialize_to_gfile:
 * @config: a #GObject that implements the #GimpConfigInterface.
 * @file:   the #GFile to write the configuration to.
 * @header: optional file header (must be ASCII only)
 * @footer: optional file footer (must be ASCII only)
 * @data: user data passed to the serialize implementation.
 * @error: return location for a possible error
 *
 * Serializes the object properties of @config to the file specified
 * by @file. If a file with that name already exists, it is
 * overwritten. Basically this function opens @file for you and calls
 * the serialize function of the @config's #GimpConfigInterface.
 *
 * Return value: %TRUE if serialization succeeded, %FALSE otherwise.
 *
 * Since: 2.10
 **/
gboolean
gimp_config_serialize_to_gfile (GimpConfig   *config,
                                GFile        *file,
                                const gchar  *header,
                                const gchar  *footer,
                                gpointer      data,
                                GError      **error)
{
  GimpConfigWriter *writer;

  g_return_val_if_fail (GIMP_IS_CONFIG (config), FALSE);
  g_return_val_if_fail (G_IS_FILE (file), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  writer = gimp_config_writer_new_gfile (file, TRUE, header, error);
  if (!writer)
    return FALSE;

  GIMP_CONFIG_GET_INTERFACE (config)->serialize (config, writer, data);

  return gimp_config_writer_finish (writer, footer, error);
}
Example #8
0
void
photos_glib_file_create_async (GFile *file,
                               GFileCreateFlags flags,
                               gint io_priority,
                               GCancellable *cancellable,
                               GAsyncReadyCallback callback,
                               gpointer user_data)
{
  g_autoptr (GTask) task = NULL;
  g_autoptr (PhotosGLibFileCreateData) data = NULL;

  g_return_if_fail (G_IS_FILE (file));
  g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));

  task = g_task_new (file, cancellable, callback, user_data);
  g_task_set_source_tag (task, photos_glib_file_create_async);

  data = photos_glib_file_create_data_new (file, flags, io_priority);
  g_task_set_task_data (task, g_steal_pointer (&data), (GDestroyNotify) photos_glib_file_create_data_free);

  g_file_create_async (file, flags, io_priority, cancellable, photos_glib_file_create_create, g_object_ref (task));
}
Example #9
0
void
logview_prefs_store_log (LogviewPrefs *prefs, GFile *file)
{
  gchar **stored_logs;
  GFile *stored;
  gboolean found = FALSE;
  gint idx, old_size;

  g_assert (LOGVIEW_IS_PREFS (prefs));
  g_assert (G_IS_FILE (file));

  stored_logs = logview_prefs_get_stored_logfiles (prefs);

  for (idx = 0; stored_logs[idx] != NULL; idx++) {
    stored = g_file_parse_name (stored_logs[idx]);
    if (g_file_equal (file, stored)) {
      found = TRUE;
    }

    g_object_unref (stored);

    if (found) {
      break;
    }
  }

  if (!found) {
    old_size = g_strv_length (stored_logs);
    stored_logs = g_realloc (stored_logs, (old_size + 2) * sizeof (gchar *));
    stored_logs[old_size] = g_file_get_parse_name (file);
    stored_logs[old_size + 1] = NULL;

    g_settings_set_strv (prefs->priv->logview_prefs,
                         PREF_LOGFILES,
                         (const gchar **) stored_logs);
  }

  g_strfreev (stored_logs);
}
static gboolean
gtk_hotkey_key_file_registry_real_has_hotkey (GtkHotkeyRegistry	*base,
											const gchar			*app_id,
											const gchar			*key_id)
{
	GFile					*file;
	gboolean				exists;
	
	g_return_val_if_fail (app_id != NULL, FALSE);
	g_return_val_if_fail (key_id != NULL, FALSE);
	
	file = get_hotkey_file (app_id);
	g_return_val_if_fail (G_IS_FILE(file), FALSE);
	
	if (g_file_query_exists (file, NULL))
		exists = TRUE;
	else
		exists = FALSE;
	
	g_object_unref (file);
	return exists;
}
/**
 * empathy_tp_file_offer:
 * @self: an outgoing #EmpathyTpFile
 * @gfile: the source #GFile for the transfer
 * @cancellable: a #GCancellable
 * @progress_callback: function to callback with progress information
 * @progress_user_data: user_data to pass to @progress_callback
 * @op_callback: function to callback when the transfer ends
 * @op_user_data: user_data to pass to @op_callback
 *
 * Offers an outgoing file transfer, reading data from @gfile.
 * The callback @op_callback will be called both when the transfer is
 * successful and in case of an error. Note that cancelling @cancellable,
 * closes the socket of the file operation in progress, but doesn't
 * guarantee that the transfer channel will be closed as well. Thus,
 * empathy_tp_file_cancel() or empathy_tp_file_close() should be used to
 * actually cancel an ongoing #EmpathyTpFile.
 */
void
empathy_tp_file_offer (EmpathyTpFile *self,
    GFile *gfile,
    GCancellable *cancellable,
    EmpathyTpFileProgressCallback progress_callback,
    gpointer progress_user_data,
    EmpathyTpFileOperationCallback op_callback,
    gpointer op_user_data)
{
  g_return_if_fail (EMPATHY_IS_TP_FILE (self));
  g_return_if_fail (G_IS_FILE (gfile));
  g_return_if_fail (G_IS_CANCELLABLE (cancellable));

  self->priv->cancellable = g_object_ref (cancellable);
  self->priv->progress_callback = progress_callback;
  self->priv->progress_user_data = progress_user_data;
  self->priv->op_callback = op_callback;
  self->priv->op_user_data = op_user_data;

  g_file_read_async (gfile, G_PRIORITY_DEFAULT, cancellable,
      file_read_async_cb, self);
}
/**
 * empathy_ft_handler_incoming_set_destination:
 * @handler: an #EmpathyFTHandler
 * @destination: the #GFile where the transfer should be saved
 *
 * Sets the destination of the incoming handler to be @destination.
 * Note that calling this method is mandatory before starting the transfer
 * for incoming handlers.
 */
void
empathy_ft_handler_incoming_set_destination (EmpathyFTHandler *handler,
    GFile *destination)
{
  EmpathyFTHandlerPriv *priv;

  g_return_if_fail (EMPATHY_IS_FT_HANDLER (handler));
  g_return_if_fail (G_IS_FILE (destination));

  priv = GET_PRIV (handler);

  g_object_set (handler, "gfile", destination, NULL);

  /* check if hash is supported. if it isn't, set use_hash to FALSE
   * anyway, so that clients won't be expecting us to checksum.
   */
  if (EMP_STR_EMPTY (priv->content_hash) ||
      priv->content_hash_type == TP_FILE_HASH_TYPE_NONE)
    priv->use_hash = FALSE;
  else
    priv->use_hash = TRUE;
}
Example #13
0
/*
 * what_failed_on_file_operation_failure:
 * @file: the file reference that failed.
 * @transient: %TRUE if this failure is likely to be permanent, i.e. a malformed
 * path. %FALSE if the action might succeed on subsequent attempts.
 * @what: indicates whether it was an open, save, or other operation that
 * failed.
 *
 * Helper function that picks a suitable error message describing what failed.
 * Based on code from Conglomerate.
 *
 * Returns: (transfer full): a newly-allocated string.
 */
static char *
what_failed_on_file_operation_failure(GFile *file, gboolean transient, I7FileErrorWhat what)
{
	char *displayname, *what_failed, *path;
	GFile *parent;

	g_return_val_if_fail(file || G_IS_FILE(file), NULL);

	displayname = file_get_display_name(file);

	parent = g_file_get_parent(file);
	path = g_file_get_path(parent);
	g_object_unref(parent);

	if(what == I7_FILE_ERROR_OTHER) {
		/* Generic file error */
		what_failed = g_strdup_printf(_("Inform got an error while accessing \"%s\" from %s."), displayname, path);
	} else if(transient) {
		/* A "what failed" message when the failure is likely to be
		permanent; this URI won't be accessible */
		if(what == I7_FILE_ERROR_OPEN)
			what_failed = g_strdup_printf(_("Inform cannot read \"%s\" from %s."), displayname, path);
		else
			what_failed = g_strdup_printf(_("Inform cannot save \"%s\" to %s."), displayname, path);
	} else {
		/* A "what failed" message when the failure is likely to be
		transient; this URI might be accessible on subsequent attempts, or
		with some troubleshooting. */
		if(what == I7_FILE_ERROR_OPEN)
			what_failed = g_strdup_printf(_("Inform could not read \"%s\" from %s."), displayname, path);
		else
			what_failed = g_strdup_printf(_("Inform could not save \"%s\" to %s."), displayname, path);
	}

	g_free(path);
	g_free(displayname);

	return what_failed;
}
Example #14
0
static void
photos_glib_file_copy_create (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GCancellable *cancellable;
  g_autoptr (GFile) unique_file = NULL;
  GFile *destination = G_FILE (source_object);
  GFile *source;
  g_autoptr (GFileOutputStream) ostream = NULL;
  g_autoptr (GTask) task = G_TASK (user_data);
  PhotosGLibFileCopyData *data;

  cancellable = g_task_get_cancellable (task);
  data = (PhotosGLibFileCopyData *) g_task_get_task_data (task);
  source = G_FILE (g_task_get_source_object (task));

  {
    g_autoptr (GError) error = NULL;

    ostream = photos_glib_file_create_finish (destination, res, &unique_file, &error);
    if (error != NULL)
      {
        g_task_return_error (task, g_steal_pointer (&error));
        goto out;
      }
  }

  g_assert_null (data->ostream);
  g_assert_true (G_IS_FILE_OUTPUT_STREAM (ostream));
  data->ostream = g_object_ref (ostream);

  g_assert_null (data->unique_file);
  g_assert_true (G_IS_FILE (unique_file));
  data->unique_file = g_object_ref (unique_file);

  g_file_read_async (source, data->io_priority, cancellable, photos_glib_file_copy_read, g_object_ref (task));

 out:
  return;
}
Example #15
0
gboolean
xml_reader_load_from_file (XmlReader     *reader,
                           GFile         *file,
                           GCancellable  *cancellable,
                           GError       **error)
{
  GFileInputStream *stream;
  gboolean ret;

  g_return_val_if_fail (XML_IS_READER (reader), FALSE);
  g_return_val_if_fail (G_IS_FILE (file), FALSE);
  g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);

  if (!(stream = g_file_read (file, cancellable, error)))
    return FALSE;

  ret = xml_reader_load_from_stream (reader, G_INPUT_STREAM (stream), error);

  g_clear_object (&stream);

  return ret;
}
Example #16
0
/**
 * ggit_index_entries_get_by_path:
 * @entries: a #GgitIndexEntries.
 * @file: the path to search.
 * @stage: stage to search.
 *
 * Get a #GgitIndexEntry by index. Note that the returned #GgitIndexEntry is
 * _only_ valid as long as:
 *
 * 1) The associated index has not been closed
 * 2) The entry has not been removed (see ggit_index_remove())
 * 3) The index has not been refreshed (see ggit_index_read())
 *
 * Changes to the #GgitIndexEntry will be reflected in the index once written
 * back to disk using ggit_index_write().
 *
 * @stage indicates the stage to search the file for. Stages are used in the
 * index when merge conflicts occur, such that multiple versions of the same
 * file can be represented in the index. Stage 0 is associated with the working
 * tree, while stages 1 to 3 are associated with the various versions of the
 * file in a merge conflict. The special value -1 can be used to match the first
 * file encountered in any stage.
 *
 * Returns: (transfer full): a #GgitIndexEntry or %NULL if it was not found.
 *
 **/
GgitIndexEntry *
ggit_index_entries_get_by_path (GgitIndexEntries *entries,
                                GFile            *file,
                                gint              stage)
{
	git_index *gidx;
	const git_index_entry *entry;
	gchar *path;
	GgitRepository *repo;
	GFile *wd;

	g_return_val_if_fail (entries != NULL, NULL);
	g_return_val_if_fail (G_IS_FILE (file), NULL);
	g_return_val_if_fail (stage >= 0 && stage <= 3, NULL);

	repo = ggit_index_get_owner (entries->owner);

	wd = ggit_repository_get_workdir (repo);
	path = g_file_get_relative_path (wd, file);

	g_object_unref (wd);
	g_object_unref (repo);

	g_return_val_if_fail (path != NULL, NULL);

	gidx = _ggit_index_get_index (entries->owner);
	entry = git_index_get_bypath (gidx, path, stage);
	g_free (path);

	if (entry)
	{
		return ggit_index_entry_wrap ((git_index_entry *)entry, FALSE);
	}
	else
	{
		return NULL;
	}
}
Example #17
0
GList *
gimp_pattern_load_pixbuf (GimpContext   *context,
                          GFile         *file,
                          GInputStream  *input,
                          GError       **error)
{
  GimpPattern *pattern;
  GdkPixbuf   *pixbuf;
  gchar       *name;

  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  pixbuf = gdk_pixbuf_new_from_stream (input, NULL, error);
  if (! pixbuf)
    return NULL;

  name = g_strdup (gdk_pixbuf_get_option (pixbuf, "tEXt::Title"));

  if (! name)
    name = g_strdup (gdk_pixbuf_get_option (pixbuf, "tEXt::Comment"));

  if (! name)
    name = g_path_get_basename (gimp_file_get_utf8_name (file));

  pattern = g_object_new (GIMP_TYPE_PATTERN,
                          "name",      name,
                          "mime-type", NULL, /* FIXME!! */
                          NULL);
  g_free (name);

  pattern->mask = gimp_temp_buf_new_from_pixbuf (pixbuf, NULL);

  g_object_unref (pixbuf);

  return g_list_prepend (NULL, pattern);
}
Example #18
0
static gboolean
ide_git_vcs_is_ignored (IdeVcs  *vcs,
                        GFile   *file,
                        GError **error)
{
  g_autofree gchar *name = NULL;
  IdeGitVcs *self = (IdeGitVcs *)vcs;
  gboolean ret = FALSE;

  g_assert (IDE_IS_GIT_VCS (self));
  g_assert (G_IS_FILE (file));

  /* Note: this function is required to be thread-safe so that workers
   *       can check if files are ignored from a thread without
   *       round-tripping to the main thread.
   */

  /* self->working_directory is not changed after creation, so safe
   * to access it from a thread.
   */
  name = g_file_get_relative_path (self->working_directory, file);
  if (g_strcmp0 (name, ".git") == 0)
    return TRUE;

  /*
   * If we have a valid name to work with, we want to query the
   * repository. But this could be called from a thread, so ensure
   * we are the only thread accessing self->repository right now.
   */
  if (name != NULL)
    {
      g_mutex_lock (&self->repository_mutex);
      ret = ggit_repository_path_is_ignored (self->repository, name, error);
      g_mutex_unlock (&self->repository_mutex);
    }

  return ret;
}
Example #19
0
/**
 * e_file_replace_contents_finish:
 * @file: input #GFile
 * @result: a #GAsyncResult
 * @new_etag: return location for a new entity tag
 * @error: return location for a #GError, or %NULL
 *
 * Finishes an asynchronous replace of the given @file.  See
 * e_file_replace_contents_async().  Sets @new_etag to the new entity
 * tag for the document, if present.  Free it with g_free() when it is
 * no longer needed.
 *
 * Returns: %TRUE on success, %FALSE on failure
 **/
gboolean
e_file_replace_contents_finish (GFile *file,
                                GAsyncResult *result,
                                gchar **new_etag,
                                GError **error)
{
	GSimpleAsyncResult *simple;
	AsyncContext *context;

	g_return_val_if_fail (G_IS_FILE (file), FALSE);
	g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE);

	simple = G_SIMPLE_ASYNC_RESULT (result);
	context = g_simple_async_result_get_op_res_gpointer (simple);

	if (g_simple_async_result_propagate_error (simple, error))
		return FALSE;

	if (new_etag != NULL)
		*new_etag = g_strdup (context->new_etag);

	return TRUE;
}
Example #20
0
void
empathy_send_file (EmpathyContact *contact,
    GFile *file)
{
  EmpathyFTFactory *factory;
  GtkRecentManager *manager;
  gchar *uri;

  g_return_if_fail (EMPATHY_IS_CONTACT (contact));
  g_return_if_fail (G_IS_FILE (file));

  factory = empathy_ft_factory_dup_singleton ();

  empathy_ft_factory_new_transfer_outgoing (factory, contact, file,
      empathy_get_current_action_time ());

  uri = g_file_get_uri (file);
  manager = gtk_recent_manager_get_default ();
  gtk_recent_manager_add_item (manager, uri);
  g_free (uri);

  g_object_unref (factory);
}
Example #21
0
gboolean
tmpl_template_parse_file (TmplTemplate  *self,
                          GFile         *file,
                          GCancellable  *cancellable,
                          GError       **error)
{
  GInputStream *stream;
  gboolean ret = FALSE;

  g_return_val_if_fail (TMPL_IS_TEMPLATE (self), FALSE);
  g_return_val_if_fail (G_IS_FILE (file), FALSE);
  g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);

  stream = (GInputStream *)g_file_read (file, cancellable, error);

  if (stream != NULL)
    {
      ret = tmpl_template_parse (self, stream, cancellable, error);
      g_object_unref (stream);
    }

  return ret;
}
Example #22
0
GFile *
file_remote_download_image (Gimp          *gimp,
                            GFile         *file,
                            gboolean      *mounted,
                            GimpProgress  *progress,
                            GError       **error)
{
  GFile *local_file;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (mounted != NULL, NULL);
  g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  local_file = file_remote_mount_file (gimp, file, progress);

  if (local_file)
    {
      *mounted = TRUE;
    }
  else
    {
      *mounted = FALSE;

      local_file = file_remote_get_temp_file (gimp, file);

      if (! file_remote_copy_file (gimp, file, local_file, DOWNLOAD,
                                   progress, error))
        {
          g_object_unref (local_file);
          return NULL;
        }
    }

  return local_file;
}
Example #23
0
/**
 * gel_ui_pixbuf_from_file:
 * @file: (transfer none): A #GFile
 *
 * Creates a #GdkPixbuf from a #GFile
 *
 * Returns: (transfer full): The new #GdkPixbuf or %NULL
 */
GdkPixbuf *
gel_ui_pixbuf_from_file(const GFile *file)
{
	g_return_val_if_fail(G_IS_FILE(file), NULL);

	GFile *f = (GFile *) file;

	GError *error = NULL;
	GInputStream *input = (GInputStream *) g_file_read(f, NULL, &error);

	if (input == NULL)
	{
		gchar *uri = g_file_get_uri(f);
		g_warning(_("Unable to read GFile('%s'): %s"), uri, error->message);
		g_free(uri);
		g_error_free(error);
		return NULL;
	}

	GdkPixbuf *ret = gel_ui_pixbuf_from_stream(input);
	g_object_unref(input);

	return ret;
}
Example #24
0
GtkCssParser *
_gtk_css_parser_new (const char            *data,
                     GFile                 *file,
                     GtkCssParserErrorFunc  error_func,
                     gpointer               user_data)
{
  GtkCssParser *parser;

  g_return_val_if_fail (data != NULL, NULL);
  g_return_val_if_fail (file == NULL || G_IS_FILE (file), NULL);

  parser = g_slice_new0 (GtkCssParser);

  parser->data = data;
  if (file)
    parser->file = g_object_ref (file);
  parser->error_func = error_func;
  parser->user_data = user_data;

  parser->line_start = data;
  parser->line = 0;

  return parser;
}
static void
reload_find_in_ancestors_cb (GFile        *workdir,
                             GAsyncResult *result,
                             gpointer      user_data)
{
  g_autoptr(IdeTask) task = user_data;
  g_autoptr(GError) error = NULL;
  g_autoptr(GFile) vagrantfile = NULL;

  g_assert (G_IS_FILE (workdir));
  g_assert (G_IS_ASYNC_RESULT (result));
  g_assert (IDE_IS_TASK (task));

  if (!(vagrantfile = ide_g_file_find_in_ancestors_finish (result, &error)))
    ide_task_return_error (task, g_steal_pointer (&error));
  else
    gbp_vagrant_runtime_provider_command_async (ide_task_get_source_object (task),
                                                (const gchar * const *)cmd_vagrant_status,
                                                ide_task_get_cancellable (task),
                                                (GAsyncReadyCallback) vagrant_status_cb,
                                                g_object_ref (task));


}
/**
 * empathy_tp_file_accept:
 * @self: an incoming #EmpathyTpFile
 * @offset: the offset of @gfile where we should start writing
 * @gfile: the destination #GFile for the transfer
 * @cancellable: a #GCancellable
 * @progress_callback: function to callback with progress information
 * @progress_user_data: user_data to pass to @progress_callback
 * @op_callback: function to callback when the transfer ends
 * @op_user_data: user_data to pass to @op_callback
 *
 * Accepts an incoming file transfer, saving the result into @gfile.
 * The callback @op_callback will be called both when the transfer is
 * successful and in case of an error. Note that cancelling @cancellable,
 * closes the socket of the file operation in progress, but doesn't
 * guarantee that the transfer channel will be closed as well. Thus,
 * empathy_tp_file_cancel() or empathy_tp_file_close() should be used to
 * actually cancel an ongoing #EmpathyTpFile.
 */
void
empathy_tp_file_accept (EmpathyTpFile *self,
    guint64 offset,
    GFile *gfile,
    GCancellable *cancellable,
    EmpathyTpFileProgressCallback progress_callback,
    gpointer progress_user_data,
    EmpathyTpFileOperationCallback op_callback,
    gpointer op_user_data)
{
  g_return_if_fail (EMPATHY_IS_TP_FILE (self));
  g_return_if_fail (G_IS_FILE (gfile));
  g_return_if_fail (G_IS_CANCELLABLE (cancellable));

  self->priv->cancellable = g_object_ref (cancellable);
  self->priv->progress_callback = progress_callback;
  self->priv->progress_user_data = progress_user_data;
  self->priv->op_callback = op_callback;
  self->priv->op_user_data = op_user_data;
  self->priv->offset = offset;

  g_file_replace_async (gfile, NULL, FALSE, G_FILE_CREATE_NONE,
      G_PRIORITY_DEFAULT, cancellable, file_replace_async_cb, self);
}
static gboolean
gimp_color_profile_store_history_insert (GimpColorProfileStore *store,
                                         GtkTreeIter           *iter,
                                         GFile                 *file,
                                         const gchar           *label,
                                         gint                   index)
{
  GtkTreeModel *model = GTK_TREE_MODEL (store);
  GtkTreeIter   sibling;
  gboolean      iter_valid;

  g_return_val_if_fail (G_IS_FILE (file), FALSE);
  g_return_val_if_fail (label != NULL, FALSE);
  g_return_val_if_fail (index > -1, FALSE);

  gimp_color_profile_store_get_separator (store, iter, FALSE);

  for (iter_valid = gtk_tree_model_get_iter_first (model, &sibling);
       iter_valid;
       iter_valid = gtk_tree_model_iter_next (model, &sibling))
    {
      gint type;
      gint this_index;

      gtk_tree_model_get (model, &sibling,
                          GIMP_COLOR_PROFILE_STORE_ITEM_TYPE, &type,
                          GIMP_COLOR_PROFILE_STORE_INDEX,     &this_index,
                          -1);

      if (type == GIMP_COLOR_PROFILE_STORE_ITEM_SEPARATOR_BOTTOM)
        {
          gtk_list_store_insert_before (GTK_LIST_STORE (store),
                                        iter, &sibling);
          break;
        }

      if (type == GIMP_COLOR_PROFILE_STORE_ITEM_FILE && this_index > -1)
        {
          gchar *this_label;

          gtk_tree_model_get (model, &sibling,
                              GIMP_COLOR_PROFILE_STORE_LABEL, &this_label,
                              -1);

          if (this_label && g_utf8_collate (label, this_label) < 0)
            {
              gtk_list_store_insert_before (GTK_LIST_STORE (store),
                                            iter, &sibling);
              g_free (this_label);
              break;
            }

          g_free (this_label);
        }
    }

  if (iter_valid)
    gtk_list_store_set (GTK_LIST_STORE (store), iter,
                        GIMP_COLOR_PROFILE_STORE_ITEM_TYPE,
                        GIMP_COLOR_PROFILE_STORE_ITEM_FILE,
                        GIMP_COLOR_PROFILE_STORE_FILE,  file,
                        GIMP_COLOR_PROFILE_STORE_LABEL, label,
                        GIMP_COLOR_PROFILE_STORE_INDEX, index,
                        -1);

  return iter_valid;
}
static void
rygel_media_export_harvester_on_file_added (RygelMediaExportHarvester *self,
                                            GFile                     *file) {
  gchar *uri;
  GError *error;
  RygelMediaExportMediaCache *cache;
  GFileInfo *info;
  RygelMediaExportHarvesterPrivate *priv;

  g_return_if_fail (RYGEL_MEDIA_EXPORT_IS_HARVESTER (self));
  g_return_if_fail (G_IS_FILE (file));

  uri = g_file_get_uri (file);
  g_debug ("Filesystem events settled for %s, scheduling extraction…", uri);
  g_free (uri);
  cache = rygel_media_export_media_cache_get_default ();
  priv = self->priv;
  error = NULL;
  info = g_file_query_info (file,
                            G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
                            G_FILE_QUERY_INFO_NONE,
                            priv->cancellable,
                            &error);
  if (error) {
    g_warning ("Failed to query file: %s", error->message);
    g_error_free (error);
    error = NULL;

    goto out;
  }
  if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY ||
      rygel_media_export_harvester_is_eligible (info)) {
    RygelMediaContainer *parent_container = NULL;
    GFile *current = g_object_ref (file);
    GeeAbstractCollection *abstract_locations = GEE_ABSTRACT_COLLECTION (priv->locations);

    do {
      GFile *parent = g_file_get_parent (current);
      gchar *id = rygel_media_export_media_cache_get_id (parent);
      RygelMediaObject *tmp_object = rygel_media_export_media_cache_get_object (cache, id, &error);

      if (error) {
        g_warning (_("Error fetching object '%s' from database: %s"),
                   id,
                   error->message);
        g_free (id);
        g_object_unref (parent);

        g_error_free (error);
        error = NULL;

        goto inner_out;
      }
      g_free (id);
      if (parent_container) {
        g_object_unref (parent_container);
        parent_container = NULL;
      }
      if (RYGEL_IS_MEDIA_CONTAINER (tmp_object)) {
        parent_container = RYGEL_MEDIA_CONTAINER (tmp_object);
      } else {
        g_object_unref (tmp_object);
      }
      if (!parent_container) {
        g_object_ref (parent);
        g_object_unref (current);
        current = parent;
      }
      g_object_unref (parent);
      if (!parent_container &&
          gee_abstract_collection_contains (abstract_locations, current)) {
        RygelMediaObject* another_object = rygel_media_export_media_cache_get_object (cache,
                                                                                      RYGEL_MEDIA_EXPORT_ROOT_CONTAINER_FILESYSTEM_FOLDER_ID,
                                                                                      &error);

        if (error) {
          goto inner_out;
        }
        if (parent_container) {
          g_object_unref (parent_container);
          parent_container = NULL;
        }
        if (RYGEL_IS_MEDIA_CONTAINER (another_object)) {
          parent_container = RYGEL_MEDIA_CONTAINER (another_object);
        }

        break;
      }
    } while (!parent_container);
    rygel_media_export_harvester_schedule (self, current, parent_container, NULL);
  inner_out:

    g_object_unref (current);
    if (parent_container) {
      g_object_unref (parent_container);
    }
  } else {
    gchar* file_uri = g_file_get_uri (file);

    g_debug ("%s is not eligible for extraction", file_uri);
    g_free (file_uri);
  }
 out:
  g_object_unref (cache);
}
GList *
gimp_brush_generated_load (GimpContext   *context,
                           GFile         *file,
                           GInputStream  *input,
                           GError       **error)
{
  GimpBrush               *brush;
  GDataInputStream        *data_input;
  gchar                   *string;
  gsize                    string_len;
  gint                     linenum;
  gchar                   *name       = NULL;
  GimpBrushGeneratedShape  shape      = GIMP_BRUSH_GENERATED_CIRCLE;
  gboolean                 have_shape = FALSE;
  gint                     spikes     = 2;
  gdouble                  spacing;
  gdouble                  radius;
  gdouble                  hardness;
  gdouble                  aspect_ratio;
  gdouble                  angle;

  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  data_input = g_data_input_stream_new (input);

  /* make sure the file we are reading is the right type */
  linenum = 1;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;

  if (! g_str_has_prefix (string, "GIMP-VBR"))
    {
      g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                   _("Not a GIMP brush file."));
      g_free (string);
      goto failed;
    }

  g_free (string);

  /* make sure we are reading a compatible version */
  linenum++;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;

  if (! g_str_has_prefix (string, "1.0"))
    {
      if (! g_str_has_prefix (string, "1.5"))
        {
          g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                       _("Unknown GIMP brush version."));
          g_free (string);
          goto failed;
        }
      else
        {
          have_shape = TRUE;
        }
    }

  g_free (string);

  /* read name */
  linenum++;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;

  g_strstrip (string);

  /* the empty string is not an allowed name */
  if (strlen (string) < 1)
    {
      name = g_strdup (_("Untitled"));
    }
  else
    {
      name = gimp_any_to_utf8 (string, -1,
                               _("Invalid UTF-8 string in brush file '%s'."),
                               gimp_file_get_utf8_name (file));
    }

  g_free (string);

  if (have_shape)
    {
      GEnumClass *enum_class;
      GEnumValue *shape_val;

      enum_class = g_type_class_peek (GIMP_TYPE_BRUSH_GENERATED_SHAPE);

      /* read shape */
      linenum++;
      string_len = 256;
      string = g_data_input_stream_read_line (data_input, &string_len,
                                              NULL, error);
      if (! string)
        goto failed;

      g_strstrip (string);
      shape_val = g_enum_get_value_by_nick (enum_class, string);

      if (! shape_val)
        {
          g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                       _("Unknown GIMP brush shape."));
          g_free (string);
          goto failed;
        }

      g_free (string);

      shape = shape_val->value;
    }

  /* read brush spacing */
  linenum++;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;
  spacing = g_ascii_strtod (string, NULL);
  g_free (string);

  /* read brush radius */
  linenum++;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;
  radius = g_ascii_strtod (string, NULL);
  g_free (string);

  if (have_shape)
    {
      /* read number of spikes */
      linenum++;
      string_len = 256;
      string = g_data_input_stream_read_line (data_input, &string_len,
                                              NULL, error);
      if (! string)
        goto failed;
      spikes = CLAMP (atoi (string), 2, 20);
      g_free (string);
    }

  /* read brush hardness */
  linenum++;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;
  hardness = g_ascii_strtod (string, NULL);
  g_free (string);

  /* read brush aspect_ratio */
  linenum++;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;
  aspect_ratio = g_ascii_strtod (string, NULL);
  g_free (string);

  /* read brush angle */
  linenum++;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;
  angle = g_ascii_strtod (string, NULL);
  g_free (string);

  g_object_unref (data_input);

  brush = GIMP_BRUSH (gimp_brush_generated_new (name, shape, radius, spikes,
                                                hardness, aspect_ratio, angle));
  g_free (name);

  gimp_brush_set_spacing (brush, spacing);

  return g_list_prepend (NULL, brush);

 failed:

  g_object_unref (data_input);

  if (name)
    g_free (name);

  g_prefix_error (error, _("In line %d of brush file: "), linenum);

  return NULL;
}
Example #30
0
void
file_import_image (GimpImage    *image,
                   GimpContext  *context,
                   GFile        *file,
                   gboolean      interactive,
                   GimpProgress *progress)
{
  GimpCoreConfig *config;

  g_return_if_fail (GIMP_IS_IMAGE (image));
  g_return_if_fail (GIMP_IS_CONTEXT (context));
  g_return_if_fail (G_IS_FILE (file));
  g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));

  config = image->gimp->config;

  if (interactive && gimp_image_get_base_type (image) != GIMP_INDEXED)
    {
      if (config->import_promote_float)
        {
          GimpPrecision old_precision = gimp_image_get_precision (image);

          if (old_precision != GIMP_PRECISION_FLOAT_LINEAR)
            {
              gimp_image_convert_precision (image,
                                            GIMP_PRECISION_FLOAT_LINEAR,
                                            GEGL_DITHER_NONE,
                                            GEGL_DITHER_NONE,
                                            GEGL_DITHER_NONE,
                                            progress);

              if (config->import_promote_dither &&
                  old_precision == GIMP_PRECISION_U8_NON_LINEAR)
                {
                  gimp_image_convert_dither_u8 (image, progress);
                }
            }
        }

      if (config->import_add_alpha)
        {
          GList *layers = gimp_image_get_layer_list (image);
          GList *list;

          for (list = layers; list; list = g_list_next (list))
            {
              if (! gimp_viewable_get_children (list->data) &&
                  ! gimp_item_is_text_layer (list->data)    &&
                  ! gimp_drawable_has_alpha (list->data))
                {
                  gimp_layer_add_alpha (list->data);
                }
            }

          g_list_free (layers);
        }
    }

  gimp_image_import_color_profile (image, context, progress, interactive);

  /* Remember the import source */
  gimp_image_set_imported_file (image, file);

  /* We shall treat this file as an Untitled file */
  gimp_image_set_file (image, NULL);
}