Exemple #1
0
/**
 * gedit_document_set_content_type:
 * @doc:
 * @content_type: (allow-none):
 */
void
gedit_document_set_content_type (GeditDocument *doc,
                                 const gchar   *content_type)
{
	g_return_if_fail (GEDIT_IS_DOCUMENT (doc));

	gedit_debug (DEBUG_DOCUMENT);

	if (content_type == NULL)
	{
		GFile *location;
		gchar *guessed_type = NULL;

		/* If content type is null, we guess from the filename */
		location = gtk_source_file_get_location (doc->priv->file);
		if (location != NULL)
		{
			gchar *basename;

			basename = g_file_get_basename (location);
			guessed_type = g_content_type_guess (basename, NULL, 0, NULL);

			g_free (basename);
		}

		set_content_type_no_guess (doc, guessed_type);
		g_free (guessed_type);
	}
	else
	{
		set_content_type_no_guess (doc, content_type);
	}
}
NS_IMETHODIMP
nsGIOService::GetMimeTypeFromExtension(const nsACString& aExtension,
                                             nsACString& aMimeType)
{
  nsCAutoString fileExtToUse("file.");
  fileExtToUse.Append(aExtension);

  gboolean result_uncertain;
  char *content_type = g_content_type_guess(fileExtToUse.get(),
                                            NULL,
                                            0,
                                            &result_uncertain);
  if (!content_type)
    return NS_ERROR_FAILURE;

  char *mime_type = g_content_type_get_mime_type(content_type);
  if (!mime_type) {
    g_free(content_type);
    return NS_ERROR_FAILURE;
  }

  aMimeType.Assign(mime_type);

  g_free(mime_type);
  g_free(content_type);

  return NS_OK;
}
Exemple #3
0
static gchar *
get_content_type_from_content (GeditDocument *doc)
{
	gchar *content_type;
	gchar *data;
	GtkTextBuffer *buffer;
	GtkTextIter start;
	GtkTextIter end;

	buffer = GTK_TEXT_BUFFER (doc);

	gtk_text_buffer_get_start_iter (buffer, &start);
	end = start;
	gtk_text_iter_forward_chars (&end, 255);

	data = gtk_text_buffer_get_text (buffer, &start, &end, TRUE);

	content_type = g_content_type_guess (NULL,
	                                     (const guchar *)data,
	                                     strlen (data),
	                                     NULL);

	g_free (data);

	return content_type;
}
static const char *
create_res_for_file (const char          *file_path,
                     GUPnPDIDLLiteObject *object)
{
        GUPnPDIDLLiteResource *res;
        GUPnPProtocolInfo *info;
        char *content_type;
        char *mime_type;
        const char *upnp_class;

        res = gupnp_didl_lite_object_add_resource (object);
        gupnp_didl_lite_resource_set_uri (res, "");

        content_type = g_content_type_guess (file_path, NULL, 0, NULL);
        mime_type = g_content_type_get_mime_type (content_type);
        upnp_class = guess_upnp_class_for_mime_type (mime_type);

        info = gupnp_protocol_info_new ();
        gupnp_protocol_info_set_mime_type (info, mime_type);
        gupnp_protocol_info_set_protocol (info, "*");

        gupnp_didl_lite_resource_set_protocol_info (res, info);

        g_object_unref (info);
        g_object_unref (res);
        g_free (mime_type);
        g_free (content_type);

        return upnp_class;
}
	foreach_slist (elem, file_list)
	{
		GtkTreeIter iter;
		gchar **path_arr = elem->data;
		GIcon *icon = NULL;
		gchar *content_type = g_content_type_guess(path_arr[level], NULL, 0, NULL);

		if (content_type)
		{
			icon = g_content_type_get_icon(content_type);
			if (icon) 
			{
				GtkIconInfo *icon_info;

				icon_info = gtk_icon_theme_lookup_by_gicon(gtk_icon_theme_get_default(), icon, 16, 0);
				if (!icon_info)
				{
					g_object_unref(icon);
					icon = NULL;
				}
				else
					gtk_icon_info_free(icon_info);
			}
			g_free(content_type);
		}

		if (patterns_match(header_patterns, path_arr[level]))
		{
			if (! icon)
				icon = g_icon_new_for_string("prjorg-header", NULL);

			gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0,
				FILEVIEW_COLUMN_ICON, icon,
				FILEVIEW_COLUMN_NAME, path_arr[level],
				FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1);
		}
		else if (patterns_match(source_patterns, path_arr[level]))
		{
			if (! icon)
				icon = g_icon_new_for_string("prjorg-source", NULL);

			gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0,
				FILEVIEW_COLUMN_ICON, icon,
				FILEVIEW_COLUMN_NAME, path_arr[level],
				FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1);
		}
		else
		{
			if (! icon)
				icon = g_icon_new_for_string("prjorg-file", NULL);

			gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0,
				FILEVIEW_COLUMN_ICON, icon,
				FILEVIEW_COLUMN_NAME, path_arr[level],
				FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1);
		}

		if (icon)
			g_object_unref(icon);
	}
Exemple #6
0
static GtkSourceLanguage *
ide_file_create_language (IdeFile *self)
{
  GtkSourceLanguageManager *manager;
  GtkSourceLanguage *srclang;
  g_autofree gchar *content_type = NULL;
  const gchar *filename;
  gboolean uncertain = FALSE;

  g_assert (IDE_IS_FILE (self));

  filename = g_file_get_basename (self->file);

  if (self->content_type)
    content_type = g_strdup (self->content_type);
  else
    content_type = g_content_type_guess (filename, NULL, 0, &uncertain);

  if (uncertain)
    g_clear_pointer (&content_type, g_free);
  else if (self->content_type == NULL)
    self->content_type = g_strdup (content_type);

  manager = gtk_source_language_manager_get_default ();
  srclang = gtk_source_language_manager_guess_language (manager, filename, content_type);

  return srclang;
}
static char *
_content_mime_prefix (const gchar *uri)
{
  char *pfx = NULL;

  g_return_val_if_fail (uri, NULL);

  if (g_str_has_prefix (uri, "dvd") ||
      g_str_has_prefix (uri, "vcd"))
    {
      pfx = g_strdup ("video");
      return pfx;
    }
  else
    {
      gchar *guess;

      if ((guess = g_content_type_guess (uri, NULL, 0, NULL)))
        {
          char *p;

          if ((p = strchr (guess, '/')))
            *p = 0;

          pfx = guess;
        }
    }

  return pfx;
}
Exemple #8
0
static char *
rsvg_acquire_file_data (const char *filename,
                        const char *base_uri,
                        char **out_mime_type,
                        gsize *out_len,
                        GCancellable *cancellable,
                        GError **error)
{
    gchar *path, *data;
    gsize len;
    char *content_type;

    rsvg_return_val_if_fail (filename != NULL, NULL, error);
    g_assert (out_len != NULL);

    path = _rsvg_io_get_file_path (filename, base_uri);
    if (path == NULL)
        return NULL;

    if (!g_file_get_contents (path, &data, &len, error)) {
        g_free (path);
        return NULL;
    }

    if (out_mime_type &&
        (content_type = g_content_type_guess (path, (guchar *) data, len, NULL))) {
        *out_mime_type = g_content_type_get_mime_type (content_type);
        g_free (content_type);
    }

    g_free (path);

    *out_len = len;
    return data;
}
static void
trg_cell_renderer_file_icon_refresh(TrgCellRendererFileIcon * fi)
{
    TrgCellRendererFileIconPrivate *priv =
        TRG_CELL_RENDERER_FILE_ICON_GET_PRIVATE(fi);

    if (priv->file_id == -2) {
        return;
    } else if (priv->file_id == -1) {
        g_object_set(fi, "stock-id", GTK_STOCK_DIRECTORY, NULL);
    } else if (priv->text) {
#ifndef WIN32
        gboolean uncertain;
        gchar *mimetype =
            g_content_type_guess(priv->text, NULL, 0, &uncertain);
        GIcon *icon = NULL;

        if (!uncertain && mimetype)
            icon = g_content_type_get_icon(mimetype);

        g_free(mimetype);

        if (icon) {
            g_object_set(fi, "gicon", icon, NULL);
            g_object_unref(icon);
        } else {
            g_object_set(fi, "stock-id", GTK_STOCK_FILE, NULL);
        }
#else
        g_object_set(fi, "stock-id", GTK_STOCK_FILE, NULL);
#endif
    }
}
int main (int argc, char **argv)
{
	GdkPixbuf *pixbuf;
	GnomeDesktopThumbnailFactory *factory;
	GtkWidget *window, *image;
	char *content_type;

	gtk_init (&argc, &argv);

	if (argc < 2) {
		g_print ("Usage: %s FILE...\n", argv[0]);
		return 1;
	}

	content_type = g_content_type_guess (argv[1], NULL, 0, NULL);
	factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
	pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (factory, argv[1], content_type);
	g_free (content_type);

	if (pixbuf == NULL) {
		g_warning ("gnome_desktop_thumbnail_factory_generate_thumbnail() failed to generate a thumbnail for %s", argv[1]);
		return 1;
	}

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	image = gtk_image_new_from_pixbuf (pixbuf);
	gtk_container_add (GTK_CONTAINER (window), image);
	gtk_widget_show_all (window);

	gtk_main ();

	return 0;
}
Exemple #11
0
static VALUE
rg_m_guess(int argc, VALUE *argv, G_GNUC_UNUSED VALUE self)
{
        VALUE rbfilename,
              rbdata;
        const char *filename;
        const guchar *data;
        gboolean result_uncertain;
        char *type;

        rb_scan_args(argc, argv, "02", &rbfilename, &rbdata);

        if (NIL_P(rbfilename) && NIL_P(rbdata))
                rb_raise(rb_eArgError,
                         "Either filename or data can be nil but not both");

        filename = RVAL2CSTR_ACCEPT_NIL(rbfilename);
        data = (guchar *)RVAL2CSTR_ACCEPT_NIL(rbdata);

        type = g_content_type_guess(filename,
                                    data,
                                    (gsize)((data != NULL) ? RSTRING_LEN(rbdata) : 0),
                                    &result_uncertain);

        return rb_assoc_new(CSTR2RVAL_FREE(type), CBOOL2RVAL(result_uncertain));
}
Exemple #12
0
static void
set_content_type (GeditDocument *doc,
		  const gchar   *content_type)
{
	GeditDocumentPrivate *priv;

	gedit_debug (DEBUG_DOCUMENT);

	priv = gedit_document_get_instance_private (doc);

	if (content_type == NULL)
	{
		GFile *location;
		gchar *guessed_type = NULL;

		/* If content type is null, we guess from the filename */
		location = gtk_source_file_get_location (priv->file);
		if (location != NULL)
		{
			gchar *basename;

			basename = g_file_get_basename (location);
			guessed_type = g_content_type_guess (basename, NULL, 0, NULL);

			g_free (basename);
		}

		set_content_type_no_guess (doc, guessed_type);
		g_free (guessed_type);
	}
	else
	{
		set_content_type_no_guess (doc, content_type);
	}
}
Exemple #13
0
const char *
gtr_get_mime_type_from_filename (const char * file)
{
    char * tmp = g_content_type_guess (file, NULL, 0, NULL);
    const char * ret = get_static_string (tmp);
    g_free (tmp);
    return ret;
}
Exemple #14
0
void
file_data_update_content_type (FileData *fdata)
{
	if (fdata->dir)
		fdata->content_type = MIME_TYPE_DIRECTORY;
	else
		fdata->content_type = _g_str_get_static (g_content_type_guess (fdata->full_path, NULL, 0, NULL));
}
Exemple #15
0
gchar* get_mime_type (const gchar *file)
{
	gboolean uncertain;
	gchar *result = NULL;

	result = g_content_type_guess(file, NULL, 0, &uncertain);

	return result;
}
Exemple #16
0
void
file_data_update_content_type (FileData *fdata)
{
	g_free (fdata->content_type);

	if (fdata->dir)
		fdata->content_type = g_strdup (MIME_TYPE_DIRECTORY);
	else
		fdata->content_type = g_content_type_guess (fdata->full_path, NULL, 0, NULL);
}
Exemple #17
0
static gchar *
get_content_type (GFile *file)
{
  g_autofree gchar *name = NULL;

  g_assert (G_IS_FILE (file));

  name = g_file_get_basename (file);

  return g_content_type_guess (name, NULL, 0, NULL);
}
Exemple #18
0
static dlr_host_file_t *prv_host_file_new(const gchar *file, unsigned int id,
					  GError **error)
{
	dlr_host_file_t *hf = NULL;
	gchar *extension;
	gchar *content_type = NULL;

	if (!g_file_test(file, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_EXISTS)) {
		*error = g_error_new(DLEYNA_SERVER_ERROR,
				     DLEYNA_ERROR_OBJECT_NOT_FOUND,
				     "File %s does not exist or is not a regular file",
				     file);
		goto on_error;
	}

	hf = g_new0(dlr_host_file_t, 1);
	hf->id = id;
	hf->clients = g_ptr_array_new_with_free_func(g_free);

	content_type = g_content_type_guess(file, NULL, 0, NULL);

	if (!content_type) {
		*error = g_error_new(DLEYNA_SERVER_ERROR, DLEYNA_ERROR_BAD_MIME,
				     "Unable to determine Content Type for %s",
				     file);
		goto on_error;
	}

	hf->mime_type =  g_content_type_get_mime_type(content_type);

	if (!hf->mime_type) {
		*error = g_error_new(DLEYNA_SERVER_ERROR, DLEYNA_ERROR_BAD_MIME,
				     "Unable to determine MIME Type for %s",
				     file);
		goto on_error;
	}

	g_free(content_type);

	extension = strrchr(file, '.');
	hf->path = g_strdup_printf(DLR_HOST_SERVICE_ROOT"/%d%s",
				   hf->id, extension ? extension : "");

	hf->dlna_header = prv_compute_dlna_header(file);

	return hf;

on_error:

	g_free(content_type);
	prv_host_file_delete(hf);

	return NULL;
}
Exemple #19
0
/**
 * e_icon_factory_create_thumbnail
 * @filename: the file name to create the thumbnail for
 *
 * Creates system thumbnail for @filename.
 *
 * Returns: Path to system thumbnail of the file; %NULL if couldn't
 *          create it. Free it with g_free().
 **/
gchar *
e_icon_factory_create_thumbnail (const gchar *filename)
{
#ifdef HAVE_GNOME_DESKTOP
	static GnomeDesktopThumbnailFactory *thumbnail_factory = NULL;
	struct stat file_stat;
	gchar *thumbnail = NULL;

	g_return_val_if_fail (filename != NULL, NULL);

	if (thumbnail_factory == NULL) {
		thumbnail_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
	}

	if (g_stat (filename, &file_stat) != -1 && S_ISREG (file_stat.st_mode)) {
		gchar *content_type, *mime = NULL;
		gboolean uncertain = FALSE;

		content_type = g_content_type_guess (filename, NULL, 0, &uncertain);
		if (content_type)
			mime = g_content_type_get_mime_type (content_type);

		if (mime) {
			gchar *uri = g_filename_to_uri (filename, NULL, NULL);

			g_return_val_if_fail (uri != NULL, NULL);

			thumbnail = gnome_desktop_thumbnail_factory_lookup (thumbnail_factory, uri, file_stat.st_mtime);
			if (!thumbnail && gnome_desktop_thumbnail_factory_can_thumbnail (thumbnail_factory, uri, mime, file_stat.st_mtime)) {
				GdkPixbuf *pixbuf;

				pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (thumbnail_factory, uri, mime);

				if (pixbuf) {
					gnome_desktop_thumbnail_factory_save_thumbnail (thumbnail_factory, pixbuf, uri, file_stat.st_mtime);
					g_object_unref (pixbuf);

					thumbnail = gnome_desktop_thumbnail_factory_lookup (thumbnail_factory, uri, file_stat.st_mtime);
				}
			}

			g_free (uri);
		}

		g_free (content_type);
		g_free (mime);
	}

	return thumbnail;
#else
	return NULL;
#endif /* HAVE_GNOME_DESKTOP */
}
gboolean
launch_file (const gchar * file)
{
	const char * content_type = g_content_type_guess (file, NULL, 0, NULL);
	gboolean result = FALSE;

	if ((g_file_test (file, G_FILE_TEST_IS_EXECUTABLE)) &&
	    (g_ascii_strcasecmp (content_type, BINARY_EXEC_MIME_TYPE) == 0)) {
		result = g_spawn_command_line_async (file, NULL);
	}

	return result;
}
static gboolean
is_image (const char *url)
{
	char *content_type;
	gboolean retval = FALSE;

	content_type = g_content_type_guess (url, NULL, 0, NULL);
	if (content_type == NULL)
		return FALSE;
	if (g_content_type_is_a (content_type, "image/*"))
		retval = TRUE;
	g_free (content_type);
	return retval;
}
Exemple #22
0
/**
 * seahorse_util_detect_data_type:
 * @data: The buffer to test for content type
 * @length: The length of this buffer
 *
 * Returns: SEAHORSE_PGP, SEAHORSE_SSH or 0
 */
GQuark
seahorse_util_detect_data_type (const gchar *data, guint length)
{
	gboolean uncertain;
	gchar *mime;
	GQuark type;
	
	mime = g_content_type_guess (NULL, (const guchar*)data, length, &uncertain);
	g_return_val_if_fail (mime, 0);
	
	type = seahorse_util_detect_mime_type (mime);
	g_free (mime);
	
	return type;
}
Exemple #23
0
static char *
rsvg_acquire_gvfs_data (const char *uri,
                        const char *base_uri,
                        char **out_mime_type,
                        gsize *out_len,
                        GCancellable *cancellable,
                        GError **error)
{
    GFile *base, *file;
    GError *err;
    char *data;
    gsize len;
    char *content_type;
    gboolean res;

    file = g_file_new_for_uri (uri);

    err = NULL;
    data = NULL;
    if (!(res = g_file_load_contents (file, cancellable, &data, &len, NULL, &err)) &&
        g_error_matches (err, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) &&
        base_uri != NULL) {
        g_clear_error (&err);
        g_object_unref (file);

        base = g_file_new_for_uri (base_uri);
        file = g_file_resolve_relative_path (base, uri);
        g_object_unref (base);

        res = g_file_load_contents (file, cancellable, &data, &len, NULL, &err);
    }

    g_object_unref (file);

    if (err) {
        g_propagate_error (error, err);
        return NULL;
    }

    if (out_mime_type &&
        (content_type = g_content_type_guess (uri, (guchar *) data, len, NULL))) {
        *out_mime_type = g_content_type_get_mime_type (content_type);
        g_free (content_type);
    }

    *out_len = len;
    return data;
}
Exemple #24
0
char* get_mime(const char* fileName)
{
  char *res;
  char *content_type = g_content_type_guess (fileName, NULL, 0, NULL);
  if (content_type == NULL)
    return default_mime_type();
  char *mime_type = g_content_type_get_mime_type (content_type);
  g_free(content_type);
  if (mime_type == NULL)
    return default_mime_type();

  res = g_malloc(sizeof(char) * (strlen(mime_type)+1));
  strcpy(res, mime_type);

  g_free(mime_type);
  return res;
}
Exemple #25
0
gchar *
gitg_utils_guess_content_type(GtkTextBuffer *buffer)
{
    GtkTextIter start;
    GtkTextIter end;

    gtk_text_buffer_get_start_iter(buffer, &start);
    end = start;

    gtk_text_iter_forward_chars(&end, 256);
    gchar *data = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);

    gchar *content_type = g_content_type_guess(NULL, (guchar *)data, strlen(data), NULL);
    g_free(data);

    return content_type;
}
Exemple #26
0
bool
file_valid_extension(zathura_t* zathura, const char* path)
{
  if (zathura == NULL || path == NULL || zathura->plugins.manager == NULL) {
    return false;
  }

  const gchar* content_type = g_content_type_guess(path, NULL, 0, NULL);
  if (content_type == NULL) {
    return false;
  }

  zathura_plugin_t* plugin = zathura_plugin_manager_get_plugin(zathura->plugins.manager, content_type);
  g_free((void*)content_type);

  return (plugin == NULL) ? false : true;
}
Exemple #27
0
void set_language(){
	if(cfg_lang()){
			GtkSourceLanguageManager *lm;
			lm=gtk_source_language_manager_new();
			char* currentfile=(char*)tpad_fp_get_current();
			if(currentfile!=NULL){
				long unsigned int i= 0,pos= 0;
				size_t mlewn = sizeof(currentfile)/sizeof(currentfile[1]);
				size_t blew = strlen(currentfile) + 1;

				if(blew > mlewn) mlewn = blew;

				 char fil[mlewn];

    			for(i=0; currentfile[i]; i++){
        			if(currentfile[i]=='\\') fil[pos++]='\\';
        			fil[pos++]=currentfile[i];
    				}
    			fil[pos]=0;
				gboolean result_uncertain;
				gchar *content_type;
				content_type = g_content_type_guess (fil, NULL, 0, &result_uncertain);
				if (result_uncertain){
					g_free (content_type);
					content_type = NULL;
					}
				GtkSourceLanguage *lang = NULL;
				lang = gtk_source_language_manager_guess_language (lm, fil, content_type);
				gtk_source_buffer_set_language (GTK_SOURCE_BUFFER(mBuff),GTK_SOURCE_LANGUAGE(lang));
				gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER(mBuff), (gboolean) cfg_lang());
				if(cfg_lang()) (lang) ? gtk_source_buffer_set_highlight_syntax(GTK_SOURCE_BUFFER(mBuff),TRUE) : gtk_source_buffer_set_highlight_syntax(GTK_SOURCE_BUFFER(mBuff),FALSE);	
				if(content_type) g_free (content_type);
		}
	}
	else {
		gtk_source_buffer_set_language(GTK_SOURCE_BUFFER(mBuff),NULL);
		gtk_source_buffer_set_highlight_syntax(GTK_SOURCE_BUFFER(mBuff),FALSE); 
	     }
	if(cfg_undo() >= 1 && cfg_undo() <= UNDO_MAX) gtk_source_buffer_set_max_undo_levels ((GtkSourceBuffer *)mBuff,(gint)cfg_undo());
	else {
		gtk_source_buffer_set_max_undo_levels ((GtkSourceBuffer *)mBuff,(gint)-1);
		cfg_set_undo(0);
	}
		(cfg_line_wrap()) ? gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view),GTK_WRAP_WORD) : gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view),GTK_WRAP_NONE);
}
/**
 * flickr_proxy_new_upload_for_file:
 * @proxy: a valid #FlickrProxy
 * @filename: the file to upload
 * @error: #GError to set on error

 * Create a new #RestProxyCall that can be used for uploading.  @filename will
 * be set as the "photo" parameter for you, avoiding you from having to open the
 * file and determine the MIME type.
 *
 * Note that this function can in theory block.
 *
 * See http://www.flickr.com/services/api/upload.api.html for details on
 * uploading to Flickr.
 */
RestProxyCall *
flickr_proxy_new_upload_for_file (FlickrProxy *proxy, const char *filename, GError **error)
{
  GMappedFile *map;
  GError *err = NULL;
  char *basename = NULL, *content_type = NULL;
  RestParam *param;
  RestProxyCall *call = NULL;

  g_return_val_if_fail (FLICKR_IS_PROXY (proxy), NULL);
  g_return_val_if_fail (filename, NULL);

  /* Open the file */
  map = g_mapped_file_new (filename, FALSE, &err);
  if (err) {
    g_propagate_error (error, err);
    return NULL;
  }

  /* Get the file information */
  basename = g_path_get_basename (filename);
  content_type = g_content_type_guess (filename,
                                       (const guchar*) g_mapped_file_get_contents (map),
                                       g_mapped_file_get_length (map),
                                       NULL);

  /* Make the call */
  call = flickr_proxy_new_upload (proxy);
  param = rest_param_new_with_owner ("photo",
                                     g_mapped_file_get_contents (map),
                                     g_mapped_file_get_length (map),
                                     content_type,
                                     basename,
                                     map,
                                     (GDestroyNotify)g_mapped_file_unref);
  rest_proxy_call_add_param_full (call, param);

  g_free (basename);
  g_free (content_type);

  return call;
}
Exemple #29
0
gboolean is_image_file(const gchar *file)
{
	gboolean uncertain = FALSE, ret = FALSE;
	gchar *result = NULL;

	if (!file)
		return FALSE;

	/* Type: JPG, PNG */

	result = g_content_type_guess(file, NULL, 0, &uncertain);

	if (!result)
		return FALSE;
	else {
		ret = is_valid_mime(result, mime_image);
		g_free(result);
		return ret;
	}
}
Exemple #30
0
static char *
sniff_gio (SoupContentSniffer *sniffer, SoupMessage *msg, SoupBuffer *buffer)
{
    SoupURI *uri;
    char *uri_path;
    char *content_type;
    char *mime_type;
    gboolean uncertain;

    uri = soup_message_get_uri (msg);
    uri_path = soup_uri_to_string (uri, TRUE);

    content_type= g_content_type_guess (uri_path, (const guchar*)buffer->data, buffer->length, &uncertain);
    mime_type = g_content_type_get_mime_type (content_type);

    g_free (uri_path);
    g_free (content_type);

    return mime_type;
}