Ejemplo n.º 1
0
static gint
test_file (const gchar *filename)
{
  GBookmarkFile *bookmark_file;
  gboolean success;

  g_return_val_if_fail (filename != NULL, 1);

  g_print ("checking GBookmarkFile...\n");

  bookmark_file = g_bookmark_file_new ();
  g_assert (bookmark_file != NULL);

  success = test_load (bookmark_file, filename);
  
  if (success)
    {
      success = test_query (bookmark_file);
      success = test_modify (bookmark_file);
    }

  g_bookmark_file_free (bookmark_file);

  g_print ("ok\n");

  return (success == TRUE ? 0 : 1);
}
Ejemplo n.º 2
0
/* Work around crashes in the file open dialog in some Gtk+ versions if no
 * .recently-used.xbel is present. */
static void
ensure_gtk_recently_used(void)
{
    static gboolean ensured = FALSE;
    gchar *filename = NULL;

    if (ensured)
        return;

    /* Gtk+ 2.12 implies GBookmarkFile is also available. */
#if (GTK_CHECK_VERSION(2,12,0))
    filename = g_build_filename(g_get_user_data_dir(), ".recently-used.xbel",
                                NULL);
    if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
        GBookmarkFile *bookmarkfile = g_bookmark_file_new();
        GError *error = NULL;

        if (!g_bookmark_file_to_file(bookmarkfile, filename, &error)) {
            g_warning("Failed to create %s: %s", filename, error->message);
            g_clear_error(&error);
        }
        g_bookmark_file_free(bookmarkfile);
    }
#endif
    g_free(filename);
    ensured = TRUE;
}
Ejemplo n.º 3
0
static gboolean
go_to_server_cb (NautilusWindow *window,
		 GFile          *location,
		 GError         *error,
		 gpointer        user_data)
{
	gboolean retval;

	if (error == NULL) {
		GBookmarkFile *bookmarks;
		GError *error = NULL;
		char *datadir;
		char *filename;
		char *uri;
		char *title;
		NautilusFile *file;
		gboolean safe_to_save = TRUE;

		file = nautilus_file_get_existing (location);

		bookmarks = g_bookmark_file_new ();
		datadir = g_build_filename (g_get_user_config_dir (), "nautilus", NULL);
		filename = g_build_filename (datadir, "servers", NULL);
		g_mkdir_with_parents (datadir, 0700);
		g_free (datadir);
		g_bookmark_file_load_from_file (bookmarks,
						filename,
						&error);
		if (error != NULL) {
			if (! g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
				/* only warn if the file exists */
				g_warning ("Unable to open server bookmarks: %s", error->message);
				safe_to_save = FALSE;
			}
			g_error_free (error);
		}

		if (safe_to_save) {
			uri = nautilus_file_get_uri (file);
			title = nautilus_file_get_display_name (file);
			g_bookmark_file_set_title (bookmarks, uri, title);
			g_bookmark_file_set_visited (bookmarks, uri, -1);
			g_bookmark_file_add_application (bookmarks, uri, NULL, NULL);
			g_free (uri);
			g_free (title);

			g_bookmark_file_to_file (bookmarks, filename, NULL);
		}

		g_free (filename);
		g_bookmark_file_free (bookmarks);

		retval = TRUE;
	} else {
		retval = FALSE;
	}

	return retval;
}