Пример #1
0
void
compare3_to(GtkAction* action, GtkWidget* window) {
  GList* files = g_list_first((GList*)g_object_get_data(G_OBJECT(action), "xdiff-ext::compare_to"));
  GList* saved = (GList*)g_object_get_data(G_OBJECT(action), "xdiff-ext::saved");
  gchar* f1 = 0;
  gchar* f2 = 0;
  gchar* f3 = (gchar*)saved->data;
  gboolean keep_file = FALSE;
  gchar* uri;
  xdiff_ext_preferences* p = xdiff_ext_preferences_instance();
  
  g_object_get(G_OBJECT(p), "keep-files-in-list", &keep_file, NULL);
  
  g_object_unref(p);

  uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
  f1 = g_filename_from_uri(uri, NULL, NULL);
  g_free(uri);
  files = g_list_next(files);
  uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
  f2 = g_filename_from_uri(uri, NULL, NULL);
  g_free(uri);

  diff3(f1, f2, f3);

  g_free(f1);
  g_free(f2);
  
  if(!keep_file) {
    clear_queue(_saved);
  }
}
Пример #2
0
void
compare3(GtkAction* action, GtkWidget* window) {
  GList* files = g_list_first((GList*)g_object_get_data(G_OBJECT(action), "xdiff-ext::compare3"));
  gchar* f1 = 0;
  gchar* f2 = 0;
  gchar* f3 = 0;
  gchar* uri;

  uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
  f1 = g_filename_from_uri(uri, NULL, NULL);
  g_free(uri);
  files = g_list_next(files);
  uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
  f2 = g_filename_from_uri(uri, NULL, NULL);
  g_free(uri);
  files = g_list_next(files);
  uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
  f3 = g_filename_from_uri(uri, NULL, NULL);
  g_free(uri);

  diff3(f1, f2, f3);
  g_free(f1);
  g_free(f2);
  g_free(f3);
}
Пример #3
0
static void
on_drag_data_received (GtkWidget * widget,
    GdkDragContext * context, int x, int y,
    GtkSelectionData * seldata, guint inf, guint time, gpointer data)
{
  SourceData *userdata = g_new0 (SourceData, 1);
#ifdef G_OS_WIN32
  gchar *filename =
      g_filename_from_uri ((const gchar *) seldata->data, NULL, NULL);
#else
  GdkPixbufFormat *format;
  gchar **uris = gtk_selection_data_get_uris (seldata);
  gchar *filename = NULL;

  g_return_if_fail (uris != NULL);
  filename = g_filename_from_uri (uris[0], NULL, NULL);
  g_return_if_fail (filename != NULL);
  format = gdk_pixbuf_get_file_info (filename, NULL, NULL);
  g_return_if_fail (format);
  g_print ("received %s image: %s\n", filename,
      gdk_pixbuf_format_get_name (format));
#endif

  userdata->nick = "location";
  userdata->value = g_strdup (filename);
  userdata->data = data;
  saveddelay = delay;
  if (delay > 0) {
    g_print ("%d\n", delay);
    g_timeout_add_seconds (1, set_location_delayed, userdata);
  } else
    g_object_set (G_OBJECT (userdata->data), userdata->nick, userdata->value,
        NULL);
  g_free (filename);
}
Пример #4
0
/// return current path if a directory, path to file if file, also handles x-caja-desktop
/// on failure (smb:///, sftp, ...) returns empty string
inline std::string get_path(CajaFileInfo* file_info){
	if(caja_file_info_is_directory(file_info)){
		const gchar_handle uri(caja_file_info_get_uri(file_info));
		const std::size_t len = std::strlen(uri.get());
		if(len >= caja_desktop.size() && caja_desktop.compare(0, caja_desktop.size(), uri.get(), caja_desktop.size()) == 0){
			const char* home = g_get_home_dir();
			return to_string(home);
		}
		const gchar_handle path(g_filename_from_uri(uri.get(), nullptr, nullptr));
		return to_string(path.get());
	}
	const gchar_handle uri(caja_file_info_get_parent_uri(file_info));
	const gchar_handle path(g_filename_from_uri(uri.get(), nullptr, nullptr));
	return to_string(path.get());
}
Пример #5
0
static GTokenType
gimp_color_profile_store_load_profile (GimpColorProfileStore *store,
                                       GScanner              *scanner,
                                       gint                   index)
{
  GtkTreeIter  iter;
  gchar       *label = NULL;
  gchar       *uri   = NULL;

  if (gimp_scanner_parse_string (scanner, &label) &&
      gimp_scanner_parse_string (scanner, &uri))
    {
      gchar *filename = g_filename_from_uri (uri, NULL, NULL);

      if (filename && g_file_test (filename, G_FILE_TEST_IS_REGULAR))
        {
          gimp_color_profile_store_history_insert (store, &iter,
                                                   filename, label, index);
        }

      g_free (filename);
      g_free (label);
      g_free (uri);

      return G_TOKEN_RIGHT_PAREN;
    }

  g_free (label);
  g_free (uri);

  return G_TOKEN_STRING;
}
Пример #6
0
NS_METHOD nsSound::Play(nsIURL *aURL)
{
    if (!mInited)
        Init();

    if (!libcanberra)
        return NS_ERROR_NOT_AVAILABLE;

    bool isFile;
    nsresult rv = aURL->SchemeIs("file", &isFile);
    if (NS_SUCCEEDED(rv) && isFile) {
        ca_context* ctx = ca_context_get_default();
        if (!ctx) {
            return NS_ERROR_OUT_OF_MEMORY;
        }

        nsAutoCString spec;
        rv = aURL->GetSpec(spec);
        if (NS_FAILED(rv)) {
            return rv;
        }
        gchar *path = g_filename_from_uri(spec.get(), NULL, NULL);
        if (!path) {
            return NS_ERROR_FILE_UNRECOGNIZED_PATH;
        }

        ca_context_play(ctx, 0, "media.filename", path, NULL);
        g_free(path);
    } else {
        nsCOMPtr<nsIStreamLoader> loader;
        rv = NS_NewStreamLoader(getter_AddRefs(loader), aURL, this);
    }

    return rv;
}
Пример #7
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);
}
Пример #8
0
/**
 * cadp_writer_iexporter_export_to_file:
 * @instance: this #NAIExporter instance.
 * @parms: a #NAIExporterFileParmsv2 structure.
 *
 * Export the specified 'item' to a newly created file.
 */
guint
cadp_writer_iexporter_export_to_file( const NAIExporter *instance, NAIExporterFileParmsv2 *parms )
{
	static const gchar *thisfn = "cadp_writer_iexporter_export_to_file";
	guint code, write_code;
	gchar *id, *folder_path, *dest_path;
	ExportFormatFn *fmt;
	CappDesktopFile *ndf;

	g_debug( "%s: instance=%p, parms=%p", thisfn, ( void * ) instance, ( void * ) parms );

	parms->basename = NULL;
	code = NA_IEXPORTER_CODE_OK;

	if( !parms->exported || !NA_IS_OBJECT_ITEM( parms->exported )){
		code = NA_IEXPORTER_CODE_INVALID_ITEM;
	}

	if( code == NA_IEXPORTER_CODE_OK ){

#ifdef NA_ENABLE_DEPRECATED
		if( parms->version == 1 ){
			fmt = find_export_format_fn_from_quark((( NAIExporterFileParms * ) parms )->format );
		} else {
			fmt = find_export_format_fn( parms->format );
		}
#else
		fmt = find_export_format_fn( parms->format );
#endif

		if( !fmt ){
			code = NA_IEXPORTER_CODE_INVALID_FORMAT;

		} else {
			id = na_object_get_id( parms->exported );
			parms->basename = g_strdup_printf( "%s%s", id, CADP_DESKTOP_FILE_SUFFIX );
			g_free( id );

			folder_path = g_filename_from_uri( parms->folder, NULL, NULL );
			dest_path = g_strdup_printf( "%s/%s", folder_path, parms->basename );
			g_free( folder_path );

			ndf = cadp_desktop_file_new_for_write( dest_path );
			write_code = na_ifactory_provider_write_item( NA_IFACTORY_PROVIDER( instance ), ndf, NA_IFACTORY_OBJECT( parms->exported ), &parms->messages );

			if( write_code != NA_IIO_PROVIDER_CODE_OK ){
				code = NA_IEXPORTER_CODE_ERROR;

			} else if( !cadp_desktop_file_write( ndf )){
				code = NA_IEXPORTER_CODE_UNABLE_TO_WRITE;
			}

			g_free( dest_path );
			g_object_unref( ndf );
		}
	}

	g_debug( "%s: returning code=%u", thisfn, code );
	return( code );
}
/* Setup the fileitem, depending uri's scheme
 * Return a string to search in.
 */
static gchar *
fileitem_setup (FileItem *item)
{
	gchar *scheme;
	gchar *filename;
	gchar *candidate = NULL;
	gchar *path;
	gchar *name;

	scheme = g_uri_parse_scheme (item->uri);
	if (g_strcmp0 (scheme, "file") == 0)
	{
		filename = g_filename_from_uri ((const gchar *)item->uri, NULL, NULL);
		if (filename)
		{
			path = g_path_get_dirname (filename);
			item->path = g_filename_to_utf8 (path, -1, NULL, NULL, NULL);
			g_free (path);

			name = g_path_get_basename (filename);
			item->name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
			g_free (name);

			candidate = g_utf8_strdown (filename, -1);
			g_free (filename);
		}
	}

	g_free (scheme);

	return candidate;
}
Пример #10
0
static void
check_uri_for_location (GstElement * e, const gchar * location,
    const gchar * uri)
{
  GstQuery *query;
  gchar *query_uri = NULL;

  g_object_set (e, "location", location, NULL);
  query = gst_query_new_uri ();
  fail_unless (gst_element_query (e, query));
  gst_query_parse_uri (query, &query_uri);
  gst_query_unref (query);

  if (uri != NULL) {
    fail_unless_equals_string (query_uri, uri);
  } else {
    gchar *fn;

    fail_unless (gst_uri_is_valid (query_uri));
    fn = g_filename_from_uri (query_uri, NULL, NULL);
    fail_unless (g_path_is_absolute (fn));
    fail_unless (fn != NULL);
    g_free (fn);
  }

  g_free (query_uri);
}
Пример #11
0
static gboolean
save_to_uri (GESFormatter * formatter, GESTimeline * timeline,
    const gchar * uri)
{
  gchar *location;
  GError *e = NULL;
  gboolean ret = TRUE;
  GESFormatterPrivate *priv = GES_FORMATTER (formatter)->priv;

  if (!(location = g_filename_from_uri (uri, NULL, NULL))) {
    return FALSE;
  }

  if (!ges_formatter_save (formatter, timeline)) {
    GST_ERROR ("couldn't serialize formatter");
  } else {
    if (!g_file_set_contents (location, priv->data, priv->length, &e)) {
      GST_ERROR ("couldn't write file '%s': %s", location, e->message);
      ret = FALSE;
    }
  }

  if (e)
    g_error_free (e);
  g_free (location);

  return ret;
}
Пример #12
0
GMount *
totem_get_mount_for_media (const char *uri)
{
	GMount *ret;
	char *mount_path;

	if (uri == NULL)
		return NULL;

	mount_path = NULL;

	if (g_str_has_prefix (uri, "dvd://") != FALSE)
		return totem_get_mount_for_dvd (uri);
	else if (g_str_has_prefix (uri, "vcd:") != FALSE)
		mount_path = totem_get_mountpoint_for_vcd (uri);
	else if (g_str_has_prefix (uri, "file:") != FALSE)
		mount_path = g_filename_from_uri (uri, NULL, NULL);

	if (mount_path == NULL)
		return NULL;

	ret = totem_get_mount_for_uri (mount_path);
	g_free (mount_path);

	return ret;
}
Пример #13
0
static void
_button_clicked_cb (MxButton *button,
                    gpointer  userdata)
{
  PengeAppTilePrivate *priv = GET_PRIVATE (userdata);
  GError *error = NULL;
  gchar *path = NULL;

  path = g_filename_from_uri (priv->bookmark, NULL, &error);

  if (!path)
  {
    if (error)
    {
      g_warning (G_STRLOC ": Error getting path from uri: %s",
                 error->message);
      g_clear_error (&error);
    }

    return;
  }

  if (penge_utils_launch_for_desktop_file ((ClutterActor *)button, path))
    penge_utils_signal_activated ((ClutterActor *)button);
  else
    g_warning (G_STRLOC ": Unable to launch for desktop file: %s", path);

  g_free (path);
}
Пример #14
0
static gboolean
pitivi_can_load_uri (GESFormatter * dummy_instance, const gchar * uri,
    GError ** error)
{
  xmlDocPtr doc;
  gboolean ret = TRUE;
  xmlXPathObjectPtr xpathObj;
  xmlXPathContextPtr xpathCtx;
  gchar *filename = g_filename_from_uri (uri, NULL, NULL);

  if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
    g_free (filename);
    return FALSE;
  }

  g_free (filename);

  if (!(doc = xmlParseFile (uri))) {
    GST_ERROR ("The xptv file for uri %s was badly formed", uri);
    return FALSE;
  }

  xpathCtx = xmlXPathNewContext (doc);
  xpathObj = xmlXPathEvalExpression ((const xmlChar *) "/pitivi", xpathCtx);
  if (!xpathObj || !xpathObj->nodesetval || xpathObj->nodesetval->nodeNr == 0)
    ret = FALSE;

  xmlFreeDoc (doc);
  xmlXPathFreeObject (xpathObj);
  xmlXPathFreeContext (xpathCtx);

  return ret;
}
Пример #15
0
void
compare_later(GtkAction* action, GtkWidget* window) {
  GList* files = g_list_first((GList*)g_object_get_data(G_OBJECT(action), "xdiff-ext::save"));
    
  while(files) {
    gchar* uri;
    gchar* path;
    GList* link;

    uri = thunarx_file_info_get_uri((ThunarxFileInfo*)files->data);
    path = g_filename_from_uri(uri, NULL, NULL);
    g_free(uri);
    
    link = g_queue_find_custom(_saved, path, (GCompareFunc)strcmp);
    
    if(link == NULL) {
      g_queue_push_head(_saved, path);
    } else {
      g_queue_unlink(_saved, link);
      g_queue_push_head_link(_saved, link);
    }
    // g_free(path) ???
    files = g_list_next(files);
  }
}
gchar *
get_package_name_from_desktop_item (MateDesktopItem * desktop_item)
{
	gchar *argv[6];
	gchar *package_name;
	gint retval;
	GError *error;

	argv[0] = "rpm";
	argv[1] = "-qf";
	argv[2] = "--qf";
	argv[3] = "%{NAME}";
	argv[4] = g_filename_from_uri (mate_desktop_item_get_location (desktop_item), NULL, NULL);
	argv[5] = NULL;

	error = NULL;

	if (!g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &package_name, NULL,
			&retval, &error))
	{
		g_warning ("error: [%s]\n", error->message);
		g_error_free (error);
		retval = -1;
	}

	g_free (argv[4]);

	if (!retval)
		return package_name;
	else
		return NULL;
}
Пример #17
0
static void
fm_ditem_page_url_drag_data_received (GtkWidget *widget, GdkDragContext *context,
				      int x, int y,
				      GtkSelectionData *selection_data,
				      guint info, guint time,
				      GtkEntry *entry)
{
	char **uris;
	gboolean exactly_one;
	char *path;
	
	uris = g_strsplit (selection_data->data, "\r\n", 0);
        exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0');

	if (!exactly_one) {
		g_strfreev (uris);
		return;
	}

	path = g_filename_from_uri (uris[0], NULL, NULL);
	if (path != NULL) {
		gtk_entry_set_text (entry, path);
		g_free (path);
	} else {
		gtk_entry_set_text (entry, uris[0]);
	}
	
	g_strfreev (uris);
}
Пример #18
0
/* Encode a "text/plain" selection; this is a broken URL -- just
 * "file:" with a path after it (no escaping or anything). We are
 * trying to make the old gnome_uri_list_extract_filenames function
 * happy, so this is coded to its idiosyncrasises.
 */
static void
add_one_compatible_uri (const char *uri, int x, int y, int w, int h, gpointer data)
{
	GString *result;
	char *local_path;
	
	result = (GString *) data;

	/* For URLs that do not have a file: scheme, there's no harm
	 * in passing the real URL. But for URLs that do have a file:
	 * scheme, we have to send a URL that will work with the old
	 * gnome-libs function or nothing will be able to understand
	 * it.
	 */
	if (!eel_istr_has_prefix (uri, "file:")) {
		g_string_append (result, uri);
		g_string_append (result, "\r\n");
	} else {
		local_path = g_filename_from_uri (uri, NULL, NULL);

		/* Check for characters that confuse the old
		 * gnome_uri_list_extract_filenames implementation, and just leave
		 * out any paths with those in them.
		 */
		if (is_path_that_gnome_uri_list_extract_filenames_can_parse (local_path)) {
			g_string_append (result, "file:");
			g_string_append (result, local_path);
			g_string_append (result, "\r\n");
		}

		g_free (local_path);
	}
}
Пример #19
0
void onDone(const boost::shared_ptr<Samoyed::Worker> &worker)
{
    Samoyed::TextFileSaver *saver =
        static_cast<Samoyed::TextFileSaver *>(worker.get());
    if (saver->error())
    {
        printf("Text file saver error: %s.\n", saver->error()->message);
        return;
    }
    GError *error = NULL;
    char *fileName = g_filename_from_uri(saver->uri(), NULL, &error);
    if (!fileName)
    {
        printf("URI to file name conversion error: %s.\n", error->message);
        g_error_free(error);
        return;
    }
    char *text;
    if (!g_file_get_contents(fileName, &text, NULL, &error))
    {
        printf("Text file read error: %s.\n", error->message);
        g_error_free(error);
        return;
    }
    if (strcmp(strrchr(saver->uri(), '.'), ".GBK") == 0)
        assert(strcmp(text, TEXT_GBK) == 0);
    else if (strcmp(strrchr(saver->uri(), '.'), ".UTF-8") == 0)
        assert(strcmp(text, TEXT_UTF8) == 0);
    else
        assert(0);
    g_unlink(fileName);
    g_free(text);
    g_free(fileName);
}
static gchar *
play_uri_get_display_name (GstPlay * play, const gchar * uri)
{
  gchar *loc;

  if (gst_uri_has_protocol (uri, "file")) {
    loc = g_filename_from_uri (uri, NULL, NULL);
  } else if (gst_uri_has_protocol (uri, "pushfile")) {
    loc = g_filename_from_uri (uri + 4, NULL, NULL);
  } else {
    loc = g_strdup (uri);
  }

  /* Maybe additionally use glib's filename to display name function */
  return loc;
}
Пример #21
0
static void
check_uri_for_uri (GstElement * e, const gchar * in_uri, const gchar * uri)
{
  GstQuery *query;
  gchar *query_uri = NULL;

  gst_uri_handler_set_uri (GST_URI_HANDLER (e), in_uri, NULL);

  query = gst_query_new_uri ();
  fail_unless (gst_element_query (e, query));
  gst_query_parse_uri (query, &query_uri);
  gst_query_unref (query);

  if (uri != NULL) {
    fail_unless_equals_string (query_uri, uri);
  } else {
    gchar *fn;

    fail_unless (gst_uri_is_valid (query_uri));
    fn = g_filename_from_uri (query_uri, NULL, NULL);
    fail_unless (g_path_is_absolute (fn));
    fail_unless (fn != NULL);
    g_free (fn);
  }

  g_free (query_uri);
}
Пример #22
0
/**
 * file_utils_filename_from_uri:
 * @uri: a URI
 *
 * A utility function to be used as a replacement for
 * g_filename_from_uri(). It deals with file: URIs with hostname in a
 * platform-specific way. On Win32, a UNC path is created and
 * returned, on other platforms the URI is detected as non-local and
 * NULL is returned.
 *
 * Returns: newly allocated filename or %NULL if @uri is a remote file
 **/
gchar *
file_utils_filename_from_uri (const gchar *uri)
{
    gchar *filename;
    gchar *hostname;

    g_return_val_if_fail (uri != NULL, NULL);

    filename = g_filename_from_uri (uri, &hostname, NULL);

    if (!filename)
        return NULL;

    if (hostname)
    {
        /*  we have a file: URI with a hostname                           */
#ifdef G_OS_WIN32
        /*  on Win32, create a valid UNC path and use it as the filename  */

        gchar *tmp = g_build_filename ("//", hostname, filename, NULL);

        g_free (filename);
        filename = tmp;
#else
        /*  otherwise return NULL, caller should use URI then             */
        g_free (filename);
        filename = NULL;
#endif

        g_free (hostname);
    }

    return filename;
}
Пример #23
0
GList *
pragha_dnd_uri_list_get_mobj_list (GtkSelectionData *data)
{
	PraghaMusicobject *mobj = NULL;
	gchar **uris = NULL, *filename = NULL;
	GList *list = NULL;
	gint i = 0;

	CDEBUG(DBG_VERBOSE, "Target: URI_LIST");

	uris = gtk_selection_data_get_uris(data);

	if(uris){
		for(i = 0; uris[i] != NULL; i++) {
			filename = g_filename_from_uri(uris[i], NULL, NULL);
			if (g_file_test(filename, G_FILE_TEST_IS_DIR)){
				list = append_mobj_list_from_folder(list, filename);
			}
			else {
				mobj = new_musicobject_from_file(filename, NULL);
				if (G_LIKELY(mobj))
					list = g_list_prepend(list, mobj);
			}

			/* Have to give control to GTK periodically ... */
			pragha_process_gtk_events ();

			g_free(filename);
		}
		g_strfreev(uris);
	}

	return g_list_reverse (list);
}
Пример #24
0
gchar *
_rsvg_io_get_file_path (const gchar * filename,
                        const gchar * base_uri)
{
    gchar *absolute_filename;

    if (g_file_test (filename, G_FILE_TEST_EXISTS) || g_path_is_absolute (filename)) {
        absolute_filename = g_strdup (filename);
    } else {
        gchar *tmpcdir;
        gchar *base_filename;

        if (base_uri) {
            base_filename = g_filename_from_uri (base_uri, NULL, NULL);
            if (base_filename != NULL) {
                tmpcdir = g_path_get_dirname (base_filename);
                g_free (base_filename);
            } else 
                return NULL;
        } else
            tmpcdir = g_get_current_dir ();

        absolute_filename = g_build_filename (tmpcdir, filename, NULL);
        g_free (tmpcdir);
    }

    return absolute_filename;
}
Пример #25
0
static GSList *
translate_document_list (EggDesktopFile *desktop_file, GSList *documents)
{
  gboolean accepts_uris = egg_desktop_file_accepts_uris (desktop_file);
  GSList *ret, *d;

  for (d = documents, ret = NULL; d; d = d->next)
    {
      const char *document = d->data;
      gboolean is_uri = !g_path_is_absolute (document);
      char *translated;

      if (accepts_uris)
	{
	  if (is_uri)
	    translated = g_strdup (document);
	  else
	    translated = g_filename_to_uri (document, NULL, NULL);
	}
      else
	{
	  if (is_uri)
	    translated = g_filename_from_uri (document, NULL, NULL);
	  else
	    translated = g_strdup (document);
	}

      if (translated)
	ret = g_slist_prepend (ret, translated);
    }

  return g_slist_reverse (ret);
}
Пример #26
0
static gboolean
vcard_supported (EImport *ei,
                 EImportTarget *target,
                 EImportImporter *im)
{
	EImportTargetURI *s;
	gchar *filename;
	gboolean retval;

	if (target->type != E_IMPORT_TARGET_URI)
		return FALSE;

	s = (EImportTargetURI *) target;
	if (s->uri_src == NULL)
		return TRUE;

	if (strncmp(s->uri_src, "file:///", 8) != 0)
		return FALSE;

	filename = g_filename_from_uri (s->uri_src, NULL, NULL);
	if (filename == NULL)
		return FALSE;
	retval = (guess_vcard_encoding (filename) != VCARD_ENCODING_NONE);
	g_free (filename);

	return retval;
}
Пример #27
0
gchar *
file_utils_any_to_uri (Gimp         *gimp,
                       const gchar  *filename_or_uri,
                       GError      **error)
{
    gchar *uri;

    g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
    g_return_val_if_fail (filename_or_uri != NULL, NULL);
    g_return_val_if_fail (error == NULL || *error == NULL, NULL);

    /*  first try if we got a file uri  */
    uri = g_filename_from_uri (filename_or_uri, NULL, NULL);

    if (uri)
    {
        g_free (uri);
        uri = g_strdup (filename_or_uri);
    }
    else
    {
        uri = file_utils_filename_to_uri (gimp, filename_or_uri, error);
    }

    return uri;
}
Пример #28
0
static void
set_resource_limits (const char *input)
{
	struct rlimit limit;
	struct stat buf;
	rlim_t max;

	max = MAX_HELPER_MEMORY;

	/* Set the maximum virtual size depending on the size
	 * of the file to process, as we wouldn't be able to
	 * mmap it otherwise */
	if (input == NULL) {
		max = MAX_HELPER_MEMORY;
	} else if (g_stat (input, &buf) == 0) {
		max = MAX_HELPER_MEMORY + buf.st_size;
	} else if (g_str_has_prefix (input, "file://") != FALSE) {
		char *file;
		file = g_filename_from_uri (input, NULL, NULL);
		if (file != NULL && g_stat (file, &buf) == 0)
			max = MAX_HELPER_MEMORY + buf.st_size;
		g_free (file);
	}

	limit.rlim_cur = max;
	limit.rlim_max = max;

	setrlimit (RLIMIT_DATA, &limit);

	limit.rlim_cur = MAX_HELPER_SECONDS;
	limit.rlim_max = MAX_HELPER_SECONDS;
	setrlimit (RLIMIT_CPU, &limit);
}
Пример #29
0
static const char *
shell_util_get_icon_for_uri_known_folders (const char *uri)
{
  const char *icon;
  char *path;
  int len;

  icon = NULL;

  if (!g_str_has_prefix (uri, "file:"))
    return NULL;

  path = g_filename_from_uri (uri, NULL, NULL);

  len = strlen (path);
  if (path[len] == '/')
    path[len] = '\0';

  if (strcmp (path, "/") == 0)
    icon = "drive-harddisk";
  else if (strcmp (path, g_get_home_dir ()) == 0)
    icon = "user-home";
  else if (strcmp (path, g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP))
      == 0)
    icon = "user-desktop";

  g_free (path);

  return icon;
}
static gboolean
check_file_size (GstValidateMediaInfo * mi)
{
  GStatBuf statbuf;
  gchar *filepath;
  guint64 size = 0;
  gboolean ret = TRUE;
  GError *err = NULL;

  filepath = g_filename_from_uri (mi->uri, NULL, &err);
  if (!filepath) {
    g_error_free (err);
    return FALSE;
  }

  if (g_stat (filepath, &statbuf) == 0) {
    size = statbuf.st_size;
  } else {
    ret = FALSE;
    goto end;
  }

  mi->file_size = size;

end:
  g_free (filepath);
  return ret;
}