Esempio n. 1
0
static gboolean
dir_monitor_callback (GFileMonitor* monitor,
		      GFile* child,
		      GFile* other_file,
		      GFileMonitorEvent eflags)
{

  char *name = g_file_get_parse_name (child);

  g_print ("Directory Monitor Event:\n");
  g_print ("Child = %s\n", name);
  g_free (name);

  if (other_file)
    {
      name = g_file_get_parse_name (other_file);
      g_print ("Other = %s\n", name);
      g_free (name);
    }

  switch (eflags)
    {
    case G_FILE_MONITOR_EVENT_CHANGED:
      g_print ("Event = CHANGED\n");
      break;
    case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
      g_print ("Event = CHANGES_DONE_HINT\n");
      break;
    case G_FILE_MONITOR_EVENT_DELETED:
      g_print ("Event = DELETED\n");
      break;
    case G_FILE_MONITOR_EVENT_CREATED:
      g_print ("Event = CREATED\n");
      break;
    case G_FILE_MONITOR_EVENT_PRE_UNMOUNT:
      g_print ("Event = PRE_UNMOUNT\n");
      break;
    case G_FILE_MONITOR_EVENT_UNMOUNTED:
      g_print ("Event = UNMOUNTED\n");
      break;
    case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
      g_print ("Event = ATTRIB CHANGED\n");
      break;
    case G_FILE_MONITOR_EVENT_MOVED:
      g_print ("Event = MOVED\n");
      break;
    case G_FILE_MONITOR_EVENT_MOVED_IN:
      g_print ("Event = MOVED IN\n");
      break;
    case G_FILE_MONITOR_EVENT_MOVED_OUT:
      g_print ("Event = MOVED OUT\n");
      break;
    case G_FILE_MONITOR_EVENT_RENAMED:
      g_print ("Event = RENAMED\n");
      break;
    }

  return TRUE;
}
Esempio n. 2
0
static void oregano_application (GApplication *app, GFile *file)
{
	Schematic *schematic = NULL;
	SchematicView *schematic_view = NULL;

	gchar *msg;
	Splash *splash = NULL;
	GError *error = NULL;

	// Keep non localized input for ngspice
	setlocale (LC_NUMERIC, "C");

	if (oregano.show_splash) {
		splash = oregano_splash_new (&error);
		if (error) {
			msg = g_strdup_printf (_ ("Failed to spawn splash-screen \'%s\''. Code %i - %s"),
			                       OREGANO_UIDIR "splash.ui", error->code, error->message);
			oregano_error (msg);
			g_free (msg);
			g_clear_error (&error);
			// non fatal issue
		}
	}
	// splash == NULL if showing splash is disabled
	oregano_lookup_libraries (splash);

	if (oregano.libraries == NULL) {
		oregano_error (_ ("Could not find a parts library.\n\n"
		                  "Supposed to be in " OREGANO_LIBRARYDIR));
		return;
	}

	oregano.clipboard = NULL;

	schematic = NULL;

	if (file) {
		GError *error = NULL;
		char *fname = g_file_get_parse_name (file);

		schematic = schematic_read (fname, &error);
		if (schematic) {
			schematic_view = schematic_view_new (schematic);

			gtk_widget_show_all (schematic_view_get_toplevel (schematic_view));
			schematic_set_filename (schematic, fname);
			schematic_set_title (schematic, g_path_get_basename (fname));
		}
	} else {
		schematic = schematic_new ();
		schematic_view = schematic_view_new (schematic);
		gtk_widget_show_all (schematic_view_get_toplevel (schematic_view));
	}

	g_signal_add_emission_hook (g_signal_lookup ("last_schematic_destroyed", TYPE_SCHEMATIC), 0,
	                            quit_hook, NULL, NULL);

	if (oregano.show_splash && splash)
		oregano_splash_done (splash, _ ("Welcome to Oregano"));
}
static void
show_bogus_bookmark_window (AthenaWindow *window,
			    AthenaBookmark *bookmark)
{
	GtkDialog *dialog;
	GFile *location;
	char *uri_for_display;
	char *prompt;
	char *detail;

	location = athena_bookmark_get_location (bookmark);
	uri_for_display = g_file_get_parse_name (location);
	
	prompt = _("Do you want to remove any bookmarks with the "
		   "non-existing location from your list?");
	detail = g_strdup_printf (_("The location \"%s\" does not exist."), uri_for_display);
	
	dialog = eel_show_yes_no_dialog (prompt, detail,
					 _("Bookmark for Nonexistent Location"),
					 GTK_STOCK_CANCEL,
					 GTK_WINDOW (window));

	g_signal_connect (dialog, "response",
	                  G_CALLBACK (remove_bookmarks_for_uri_if_yes), window);
	g_object_set_data_full (G_OBJECT (dialog), "uri", g_file_get_uri (location), g_free);

	gtk_dialog_set_default_response (dialog, GTK_RESPONSE_NO);

	g_object_unref (location);
	g_free (uri_for_display);
	g_free (detail);
}
Esempio n. 4
0
void
nemo_location_bar_set_location (NemoLocationBar *bar,
				    const char *location)
{
	char *formatted_location;
	GFile *file;

	g_assert (location != NULL);

	/* Note: This is called in reaction to external changes, and
	 * thus should not emit the LOCATION_CHANGED signal. */

	if (eel_uri_is_search (location)) {
		nemo_location_entry_set_special_text (NEMO_LOCATION_ENTRY (bar->details->entry),
							  "");
	} else {
		file = g_file_new_for_uri (location);
		formatted_location = g_file_get_parse_name (file);
		g_object_unref (file);
		nemo_location_entry_update_current_location (NEMO_LOCATION_ENTRY (bar->details->entry),
								 formatted_location);
		g_free (formatted_location);
	}

	/* remember the original location for later comparison */

	if (bar->details->last_location != location) {
		g_free (bar->details->last_location);
		bar->details->last_location = g_strdup (location);
	}

    nemo_location_bar_update_icon (bar);
}
Esempio n. 5
0
/*static PyObject *Document_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
	bluefish_DocumentObject *self;
	self = (bluefish_DocumentObject *)type->tp_alloc(type, 0);
	if (self != NULL) {
		/ * parse arguments ?? * /
		if (!self->doc) {
			Py_DECREF(self);
			return NULL;
		}
		return (PyObject *)self;
	}
	return NULL;
}*/
static int Document_init(bluefish_DocumentObject *self, PyObject *args, PyObject *kwds) {
	GFile *uri;
	static char *kwlist[] = {"uri", NULL};
	PyObject *PyBfwin;
	Tbfwin *bfwin;

	if (!PyArg_ParseTupleAndKeywords(args, kwds, "|s", kwlist, &uri))
		return -1;

	PyBfwin = GetObjectFromBluefishModule("bfwin");
	bfwin = PyCObject_AsVoidPtr(PyBfwin);

	if (uri) {
		Tdocument *tmpdoc;
		tmpdoc = documentlist_return_document_from_uri(bfwin->documentlist, uri);
		if (!tmpdoc) return -1;
#ifdef DEBUG
		gchar *fullpath = g_file_get_parse_name (uri);
		g_print("found %p for %s\n",tmpdoc,fullpath);
		g_free(fullpath);
#endif
		self->doc = tmpdoc;
	} else {
		self->doc = bfwin->current_document;
	}
	return 0;
}
void
nautilus_location_entry_set_location (NautilusLocationEntry *entry,
				      GFile                 *location)
{
	gchar *uri, *formatted_uri;

	g_assert (location != NULL);

	/* Note: This is called in reaction to external changes, and
	 * thus should not emit the LOCATION_CHANGED signal. */
	uri = g_file_get_uri (location);
	formatted_uri = g_file_get_parse_name (location);

	if (eel_uri_is_search (uri)) {
		nautilus_location_entry_set_special_text (entry, "");
	} else {
		nautilus_location_entry_update_current_uri (entry, formatted_uri);
	}

	/* remember the original location for later comparison */
	if (!entry->details->last_location ||
	    !g_file_equal (entry->details->last_location, location)) {
		g_clear_object (&entry->details->last_location);
		entry->details->last_location = g_object_ref (location);
	}

	nautilus_location_entry_update_action (entry);

	g_free (uri);
	g_free (formatted_uri);
}
static void
update_destination (GthImportPreferencesDialog *self)
{
	GFile              *destination_example;
	char               *uri;
	char               *example;
	GthSubfolderType    subfolder_type;
	GthSubfolderFormat  subfolder_format;

	destination_example = gth_import_preferences_dialog_get_destination_example (self);
	if (destination_example == NULL)
		return;

	uri = g_file_get_parse_name (destination_example);
	example = g_strdup_printf (_("example: %s"), uri);
	gtk_label_set_text (GTK_LABEL (GET_WIDGET ("example_label")), example);

	subfolder_type = get_subfolder_type (self);
	gtk_widget_set_sensitive (GET_WIDGET ("single_subfolder_checkbutton"), subfolder_type != GTH_SUBFOLDER_TYPE_NONE);
	gtk_widget_set_sensitive (self->priv->subfolder_type_list, subfolder_type != GTH_SUBFOLDER_TYPE_NONE);
	gtk_widget_set_sensitive (self->priv->subfolder_format_list, subfolder_type != GTH_SUBFOLDER_TYPE_NONE);
	gtk_widget_set_sensitive (GET_WIDGET ("subfolder_options_notebook"), subfolder_type != GTH_SUBFOLDER_TYPE_NONE);

	subfolder_format = gtk_combo_box_get_active (GTK_COMBO_BOX (self->priv->subfolder_format_list));
	gtk_notebook_set_current_page (GTK_NOTEBOOK (GET_WIDGET ("subfolder_options_notebook")), (subfolder_format == GTH_SUBFOLDER_FORMAT_CUSTOM) ? 1 : 0);

	g_signal_emit (self, signals[DESTINATION_CHANGED], 0);

	g_free (example);
	g_free (uri);
	g_object_unref (destination_example);
}
Esempio n. 8
0
// Returns the row number with matching uri or -1 if not found
int list_find_row(const char *uri)
{
	g_assert(uri);

	GtkTreeIter iter;

	GFile *file = g_file_new_for_uri(uri);
	char *pname = g_file_get_parse_name(file);
	g_object_unref(file);

	if (gtk_tree_model_get_iter_first(gui.treemodel, &iter)) {
		int row = 0;
		do {
			GValue value;
			value.g_type = 0;
			gtk_tree_model_get_value(gui.treemodel, &iter, COL_FILE, &value);
			const char *string = g_value_get_string(&value);

			if (strcmp(string, pname) == 0) {
				g_free(pname);
				g_value_unset(&value);
				return row;
			} else {
				g_value_unset(&value);
				row++;
			}
		} while (gtk_tree_model_iter_next(gui.treemodel, &iter));
	}

	g_free(pname);

	return -1;
}
Esempio n. 9
0
static void
gth_folder_chooser_dialog_construct (GthFolderChooserDialog *self,
				     GList                  *folders)
{
	GtkTreeIter  iter;
	GList       *scan;
	int          idx;

	gtk_list_store_clear (GTK_LIST_STORE (GET_WIDGET ("folders_liststore")));

	for (scan = folders, idx = 0; scan; scan = scan->next, idx++) {
		GFile *folder = scan->data;
		char  *display_name;

		display_name = g_file_get_parse_name (folder);
		gtk_list_store_append (GTK_LIST_STORE (GET_WIDGET ("folders_liststore")), &iter);
		gtk_list_store_set (GTK_LIST_STORE (GET_WIDGET ("folders_liststore")), &iter,
				    FOLDER_FILE_COLUMN, folder,
				    FOLDER_NAME_COLUMN, display_name,
				    FOLDER_SELECTED_COLUMN, FALSE,
				    -1);

		g_free (display_name);
	}
}
Esempio n. 10
0
static void
gth_metadata_provider_file_read (GthMetadataProvider *self,
				 GthFileData         *file_data,
				 const char          *attributes)
{
	GFileAttributeMatcher *matcher;
	char                  *value;
	GTimeVal              *timeval_p;
	const char            *value_s;

	matcher = g_file_attribute_matcher_new (attributes);

	value = g_format_size_for_display (g_file_info_get_size (file_data->info));
	g_file_info_set_attribute_string (file_data->info, "gth::file::display-size", value);
	g_free (value);

	timeval_p = gth_file_data_get_modification_time (file_data);
	value = _g_time_val_strftime (timeval_p, "%x %X");
	g_file_info_set_attribute_string (file_data->info, "gth::file::display-mtime", value);
	g_free (value);

	value = g_file_get_parse_name (file_data->file);
	g_file_info_set_attribute_string (file_data->info, "gth::file::full-name", value);
	g_free (value);

	value_s = get_static_string (g_file_info_get_content_type (file_data->info));
	if (value_s != NULL)
		g_file_info_set_attribute_string (file_data->info, "gth::file::content-type", value_s);

	g_file_attribute_matcher_unref (matcher);
}
Esempio n. 11
0
static JSBool
import_file_on_module(JSContext  *context,
                      JSObject   *obj,
                      const char *name,
                      GFile      *file)
{
    JSObject *module_obj;
    JSBool retval = JS_FALSE;
    char *full_path = NULL;

    module_obj = create_module_object (context);

    if (!define_import(context, obj, module_obj, name))
        goto out;

    if (!import_file(context, name, file, module_obj))
        goto out;

    full_path = g_file_get_parse_name (file);
    if (!define_meta_properties(context, module_obj, full_path, name, obj))
        goto out;

    if (!seal_import(context, obj, name))
        goto out;

    retval = JS_TRUE;

 out:
    if (!retval)
        cancel_import(context, obj, name);

    g_free (full_path);
    return retval;
}
Esempio n. 12
0
void
nautilus_notebook_sync_tab_label (NautilusNotebook *notebook,
				  NautilusWindowSlot *slot)
{
	GtkWidget *hbox, *label;
	char *location_name;

	g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
	g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot));

	hbox = gtk_notebook_get_tab_label (GTK_NOTEBOOK (notebook), GTK_WIDGET (slot));
	g_return_if_fail (GTK_IS_WIDGET (hbox));

	label = GTK_WIDGET (g_object_get_data (G_OBJECT (hbox), "label"));
	g_return_if_fail (GTK_IS_WIDGET (label));

	gtk_label_set_text (GTK_LABEL (label), slot->title);

	if (slot->location != NULL) {
		/* Set the tooltip on the label's parent (the tab label hbox),
		 * so it covers all of the tab label.
		 */
		location_name = g_file_get_parse_name (slot->location);
		gtk_widget_set_tooltip_text (gtk_widget_get_parent (label), location_name);
		g_free (location_name);
	} else {
		gtk_widget_set_tooltip_text (gtk_widget_get_parent (label), NULL);
	}
}
Esempio n. 13
0
static char *
convert_file_list_to_string (CajaClipboardInfo *info,
                             gboolean format_for_text,
                             gsize *len)
{
    GString *uris;
    char *uri, *tmp;
    GFile *f;
    guint i;
    GList *l;

    if (format_for_text)
    {
        uris = g_string_new (NULL);
    }
    else
    {
        uris = g_string_new (info->cut ? "cut" : "copy");
    }

    for (i = 0, l = info->files; l != NULL; l = l->next, i++)
    {
        uri = caja_file_get_uri (l->data);

        if (format_for_text)
        {
            f = g_file_new_for_uri (uri);
            tmp = g_file_get_parse_name (f);
            g_object_unref (f);

            if (tmp != NULL)
            {
                g_string_append (uris, tmp);
                g_free (tmp);
            }
            else
            {
                g_string_append (uris, uri);
            }

            /* skip newline for last element */
            if (i + 1 < g_list_length (info->files))
            {
                g_string_append_c (uris, '\n');
            }
        }
        else
        {
            g_string_append_c (uris, '\n');
            g_string_append (uris, uri);
        }

        g_free (uri);
    }

    *len = uris->len;
    return g_string_free (uris, FALSE);
}
Esempio n. 14
0
GISourceSymbol *
gi_source_symbol_new (GISourceSymbolType type, GFile *file, int line)
{
  GISourceSymbol *s = g_slice_new0 (GISourceSymbol);
  s->ref_count = 1;
  s->source_filename = g_file_get_parse_name (file);
  s->type = type;
  s->line = line;
  return s;
}
Esempio n. 15
0
/**
 * Gets the filename of a  GFile
 * @param a_file : the GFile to get the filename from.
 * @returns the name of the GFile if any or "--" gchar * string that may be
 *          freed when no longer needed
 */
gchar *get_filename_from_gfile(GFile *a_file)
{
    gchar *filename = NULL;

    if (a_file != NULL)
        {
            filename = g_file_get_parse_name(a_file);
        }

    return filename;
}
Esempio n. 16
0
/**
 * gedit_utils_uri_for_display:
 * @uri: uri to be displayed.
 *
 * Filter, modify, unescape and change @uri to make it appropriate
 * for display to users.
 *
 * This function is a convenient wrapper for g_file_get_parse_name
 *
 * Return value: a string which represents @uri and can be displayed.
 */
gchar *
gedit_utils_uri_for_display(const gchar *uri) {
	GFile *gfile;
	gchar *parse_name;

	gfile = g_file_new_for_uri(uri);
	parse_name = g_file_get_parse_name(gfile);
	g_object_unref(gfile);

	return parse_name;
}
Esempio n. 17
0
/*
 *	this is clipboard nautilus convention
 * 	@format_for_text : TRUE: (<path_name> '\n')* <path_name>
 * 	                   FALSE: ["cut"|"copy"]('\n' <uri>)* <uri>
 */
static char *
__convert_file_list_to_string (FileOpsClipboardInfo *info,
			       gboolean format_for_text,
                               gsize *len)
{
    g_debug ("__convert_file_list_to_string: begin");
    GString *uris;
    if (format_for_text)
	uris = g_string_new (NULL);
    else
	uris = g_string_new (info->cut ? "cut" : "copy");

    char *uri, *tmp;
    GFile *f;
    guint i;
    for (i = 0; i < info->num; i++)
    {
	uri = g_file_get_uri (info->file_list[i]);

	if (format_for_text)
	{
	    f = g_file_new_for_uri (uri);
	    tmp = g_file_get_parse_name (f);
	    g_object_unref (f);

	    if (tmp != NULL)
	    {
		g_string_append (uris, tmp);
		g_free (tmp);
	    }
	    else
	    {
		g_string_append (uris, uri);
	    }
	    /* skip newline for last element */
	    if (i + 1 < info->num)
	    {
		g_string_append_c (uris, '\n');
	    }
	}
	else
	{
	    g_string_append_c (uris, '\n');
	    g_string_append (uris, uri);
	}

	g_free (uri);
    }

    *len = uris->len;

    g_debug ("__convert_file_list_to_string: begin");
    return g_string_free (uris, FALSE);
}
Esempio n. 18
0
char *
totem_uri_escape_for_display (const char *uri)
{
	GFile *file;
	char *disp;

	file = g_file_new_for_uri (uri);
	disp = g_file_get_parse_name (file);
	g_object_unref (file);

	return disp;
}
Esempio n. 19
0
/**
 * gedit_utils_location_get_dirname_for_display
 * @file: the location
 *
 * Returns a string suitable to be displayed in the UI indicating
 * the name of the directory where the file is located.
 * For remote files it may also contain the hostname etc.
 * For local files it tries to replace the home dir with ~.
 *
 * Returns: a string to display the dirname
 */
gchar *
gedit_utils_location_get_dirname_for_display (GFile *location)
{
	gchar *uri;
	gchar *res;
	GMount *mount;

	g_return_val_if_fail (location != NULL, NULL);

	/* we use the parse name, that is either the local path
	 * or an uri but which is utf8 safe */
	uri = g_file_get_parse_name (location);

	/* FIXME: this is sync... is it a problem? */
	mount = g_file_find_enclosing_mount (location, NULL, NULL);
	if (mount != NULL)
	{
		gchar *mount_name;
		gchar *path;

		mount_name = g_mount_get_name (mount);
		g_object_unref (mount);

		/* obtain the "path" patrt of the uri */
		if (gedit_utils_decode_uri (uri,
					    NULL, NULL,
					    NULL, NULL,
					    &path))
		{
			gchar *dirname;
			
			dirname = gedit_utils_uri_get_dirname (path);
			res = g_strdup_printf ("%s %s", mount_name, dirname);

			g_free (path);
			g_free (dirname);
			g_free (mount_name);
		}
		else
		{
			res = mount_name;
		}
	}
	else
	{
		/* fallback for local files or uris without mounts */
		res = gedit_utils_uri_get_dirname (uri);
	}

	g_free (uri);

	return res;
}
Esempio n. 20
0
static void
locale_parser_error (GMarkupParseContext *context,
                     GError              *error,
                     gpointer             user_data)
{
  LocaleParser *parser = (LocaleParser *) user_data;
  gchar        *name   = g_file_get_parse_name (parser->file);

  g_printerr ("help (parsing %s): %s", name, error->message);

  g_free (name);
}
Esempio n. 21
0
/* Setup the fileitem, depending uri's scheme
 * Return a string to search in.
 */
static gchar *
fileitem_setup (FileItem *item)
{
	gchar *scheme;
	gchar *filename;
	gchar *normalized_filename = NULL;
	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);

			normalized_filename = g_utf8_normalize (filename, -1, G_NORMALIZE_ALL);
			g_free (filename);
		}
	}
	else
	{
		GFile *file;
		gchar *parse_name;

		file = g_file_new_for_uri (item->uri);
		item->path = gedit_utils_location_get_dirname_for_display (file);
		item->name  = gedit_utils_basename_for_display (file);
		parse_name = g_file_get_parse_name (file);
		g_object_unref (file);

		normalized_filename = g_utf8_normalize (parse_name, -1, G_NORMALIZE_ALL);
		g_free (parse_name);
	}

        if (normalized_filename)
	{
		candidate = g_utf8_casefold (normalized_filename, -1);
		g_free (normalized_filename);
	}

	g_free (scheme);

	return candidate;
}
Esempio n. 22
0
/* FIXME: modify this dialog to be similar to the one provided by gtk+ for
 * already existing files - Paolo (Oct. 11, 2005) */
static gboolean
replace_read_only_file (GtkWindow *parent, GFile *file)
{
	GtkWidget *dialog;
	gint ret;
	gchar *parse_name;
	gchar *name_for_display;

	cedit_debug (DEBUG_COMMANDS);

	parse_name = g_file_get_parse_name (file);

	/* Truncate the name so it doesn't get insanely wide. Note that even
	 * though the dialog uses wrapped text, if the name doesn't contain
	 * white space then the text-wrapping code is too stupid to wrap it.
	 */
	name_for_display = cedit_utils_str_middle_truncate (parse_name, 50);
	g_free (parse_name);

	dialog = gtk_message_dialog_new (parent,
					 GTK_DIALOG_DESTROY_WITH_PARENT,
					 GTK_MESSAGE_QUESTION,
					 GTK_BUTTONS_NONE,
					 _("The file \"%s\" is read-only."),
				         name_for_display);
	g_free (name_for_display);

	gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
						  _("Do you want to try to replace it "
						    "with the one you are saving?"));

	gtk_dialog_add_button (GTK_DIALOG (dialog),
			       GTK_STOCK_CANCEL,
			       GTK_RESPONSE_CANCEL);

	cedit_dialog_add_button (GTK_DIALOG (dialog),
				 _("_Replace"),
			  	 GTK_STOCK_SAVE_AS,
			  	 GTK_RESPONSE_YES);

	gtk_dialog_set_default_response	(GTK_DIALOG (dialog),
					 GTK_RESPONSE_CANCEL);

	gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);

	ret = gtk_dialog_run (GTK_DIALOG (dialog));

	gtk_widget_destroy (dialog);

	return (ret == GTK_RESPONSE_YES);
}
Esempio n. 23
0
/**
 * gimp_file_get_utf8_name:
 * @file: a #GFile
 *
 * This function works like gimp_filename_to_utf8() and returns
 * a UTF-8 encoded string that does not need to be freed.
 *
 * It converts a #GFile's path or uri to UTF-8 temporarily.  The
 * return value is a pointer to a string that is guaranteed to be
 * valid only during the current iteration of the main loop or until
 * the next call to gimp_file_get_utf8_name().
 *
 * The only purpose of this function is to provide an easy way to pass
 * a #GFile's name to a function that expects an UTF-8 encoded string.
 *
 * See g_file_get_parse_name().
 *
 * Since: GIMP 2.10
 *
 * Return value: A temporarily valid UTF-8 representation of @file's name.
 *               This string must not be changed or freed.
 **/
const gchar *
gimp_file_get_utf8_name (GFile *file)
{
  gchar *name;

  g_return_val_if_fail (G_IS_FILE (file), NULL);

  name = g_file_get_parse_name (file);

  g_object_set_data_full (G_OBJECT (file), "gimp-parse-name", name,
                          (GDestroyNotify) g_free);

  return name;
}
Esempio n. 24
0
void hash_file_start(const char *uri)
{
	if (gui_get_view() != GUI_VIEW_FILE_LIST)
		gtkhash_hash_file_clear_digests(&hash_priv.file_data);

	GFile *file = g_file_new_for_uri(uri);
	char *pname = g_file_get_parse_name(file);
	gtk_progress_bar_set_text(gui.progressbar, pname);
	g_free(pname);
	g_object_unref(file);

	gtkhash_hash_file_set_uri(&hash_priv.file_data, uri);
	gtkhash_hash_file_set_stop(&hash_priv.file_data, false);
	gtkhash_hash_file_set_state(&hash_priv.file_data, HASH_FILE_STATE_START);
	gtkhash_hash_file_add_source(&hash_priv.file_data);
}
Esempio n. 25
0
gboolean
baobab_check_dir (GFile	*file)
{
	GFileInfo *info;
	GError *error = NULL;
	gboolean ret = TRUE;

	if (baobab_is_excluded_location (file)) {
		message("", _("Cannot check an excluded folder!"), GTK_MESSAGE_INFO, baobab.window);
		return FALSE;
		}

	info = g_file_query_info (file,
				  G_FILE_ATTRIBUTE_STANDARD_TYPE,
				  G_FILE_QUERY_INFO_NONE,
				  NULL,
				  &error);

	if (!info) {
		message("", error->message, GTK_MESSAGE_INFO, baobab.window);
		g_error_free (error);

		return FALSE;
	}	

	if ((g_file_info_get_file_type (info) != G_FILE_TYPE_DIRECTORY) ||
		is_virtual_filesystem(file)) {
		
		char *error_msg = NULL;
		gchar *name = NULL;

	    	name = g_file_get_parse_name (file);
		error_msg = g_strdup_printf (_("\"%s\" is not a valid folder"),
					     name);

		message (error_msg, _("Could not analyze disk usage."), 
		         GTK_MESSAGE_ERROR, baobab.window);

		g_free (error_msg);
		g_free (name);
		ret = FALSE;
	}

	g_object_unref(info);

	return ret;
}
Esempio n. 26
0
static void
locale_set_error (GError      **error,
                  const gchar  *format,
                  GFile        *file)
{
  if (error && *error)
    {
      gchar *name = g_file_get_parse_name (file);
      gchar *msg;

      msg = g_strdup_printf (format, name, (*error)->message);
      g_free (name);

      g_free ((*error)->message);
      (*error)->message = msg;
    }
}
Esempio n. 27
0
void list_append_row(const char * const uri, const char * const check)
{
	g_assert(uri);

	GFile *file = g_file_new_for_uri(uri);
	char *pname = g_file_get_parse_name(file);
	g_object_unref(file);

	gtk_list_store_insert_with_values(gui.liststore, NULL, list.rows + 1,
		COL_PNAME, pname,
		COL_CHECK, check ? check : "",
		-1);
	list.rows++;
	g_free(pname);

	if (check)
		list_priv.show_status = true;
}
Esempio n. 28
0
static void
on_selection_changed (GtkTreeSelection *treeselection,
                      gpointer user_data)
{
    CajaBookmark *selected;
    char *name = NULL, *entry_text = NULL;
    GFile *location;

    g_assert (GTK_IS_ENTRY (name_field));
    g_assert (GTK_IS_ENTRY (uri_field));

    selected = get_selected_bookmark ();

    if (selected)
    {
        name = caja_bookmark_get_name (selected);
        location = caja_bookmark_get_location (selected);
        entry_text = g_file_get_parse_name (location);

        g_object_unref (location);
    }

    /* Set the sensitivity of widgets that require a selection */
    gtk_widget_set_sensitive (remove_button, selected != NULL);
    gtk_widget_set_sensitive (jump_button, selected != NULL);
    gtk_widget_set_sensitive (name_field, selected != NULL);
    gtk_widget_set_sensitive (uri_field, selected != NULL);

    g_signal_handler_block (name_field, name_field_changed_signal_id);
    caja_entry_set_text (CAJA_ENTRY (name_field),
                         name ? name : "");
    g_signal_handler_unblock (name_field, name_field_changed_signal_id);

    g_signal_handler_block (uri_field, uri_field_changed_signal_id);
    caja_entry_set_text (CAJA_ENTRY (uri_field),
                         entry_text ? entry_text : "");
    g_signal_handler_unblock (uri_field, uri_field_changed_signal_id);

    text_changed = FALSE;
    name_text_changed = FALSE;

    g_free (name);
    g_free (entry_text);
}
Esempio n. 29
0
static void
update_system_bookmark_list_from_content (GthBrowser *browser,
        const char *content)
{
    BrowserData   *data;
    char        **lines;
    int           i;

    data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
    g_return_if_fail (data != NULL);

    lines = g_strsplit (content, "\n", -1);
    for (i = 0; lines[i] != NULL; i++) {
        char      **line;
        char       *uri;
        GFile      *file;
        char       *name;
        GMenuItem  *item;

        line = g_strsplit (lines[i], " ", 2);
        uri = line[0];
        if (uri == NULL) {
            g_strfreev (line);
            continue;
        }

        file = g_file_new_for_uri (uri);
        name = g_strdup (strchr (lines[i], ' '));
        if (name == NULL)
            name = _g_file_get_display_name (file);
        if (name == NULL)
            name = g_file_get_parse_name (file);
        item = _g_menu_item_new_for_file (file, name);
        g_menu_item_set_action_and_target (item, "win.go-to-location", "s", uri);
        g_menu_append_item (data->system_bookmarks_menu, item);

        g_object_unref (item);
        g_free (name);
        g_object_unref (file);
        g_strfreev (line);
    }

    g_strfreev (lines);
}
Esempio n. 30
0
static gboolean
drop_uri (PanelWidget         *panel,
	  PanelObjectPackType  pack_type,
	  int                  pack_index,
	  const char          *uri,
	  const char          *fallback_icon)
{
	char  *name;
	char  *comment;
	char  *buf;
	char  *icon;
	GFile *file;

	if (!panel_layout_is_writable ())
		return FALSE;

	name = panel_util_get_label_for_uri (uri);
	icon = panel_util_get_icon_for_uri (uri);
	if (!icon)
		icon = g_strdup (fallback_icon);

	/* FIXME: we might get icons like "folder-music" that might not exist in
	 * the icon theme. This would usually be okay if we could use fallback
	 * icons (and get "folder" this way). However, this is not possible for
	 * launchers: this could be an application that uses an icon named
	 * folder-magic-app, for which we don't want fallbacks. We just want to
	 * go to hicolor. */

	file = g_file_new_for_uri (uri);
	buf = g_file_get_parse_name (file);
	g_object_unref (file);
	/* Translators: %s is a URI */
	comment = g_strdup_printf (_("Open '%s'"), buf);
	g_free (buf);

	panel_launcher_create_from_info (panel->toplevel, pack_type, pack_index,
					 FALSE, uri, name, comment, icon);

	g_free (name);
	g_free (comment);
	g_free (icon);

	return TRUE;
}