Example #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);
}
/* 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;
}
Example #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;
}
static GBookmarkFile *
ide_recent_projects_get_bookmarks (IdeRecentProjects  *self,
                                   GError            **error)
{
  GBookmarkFile *bookmarks;

  g_assert (IDE_IS_RECENT_PROJECTS (self));
  g_assert (error != NULL);

  bookmarks = g_bookmark_file_new ();

  if (!g_bookmark_file_load_from_file (bookmarks, self->file_uri, error))
    {
      if (!g_error_matches (*error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
        {
          g_object_unref (bookmarks);
          return NULL;
        }
    }

  return bookmarks;
}
static GBookmarkFile *
ide_recent_projects_get_bookmarks (IdeRecentProjects  *self,
                                   GError            **error)
{
  g_autoptr(GBookmarkFile) bookmarks = NULL;
  g_autoptr(GError) local_error = NULL;

  g_assert (IDE_IS_RECENT_PROJECTS (self));

  bookmarks = g_bookmark_file_new ();

  if (!g_bookmark_file_load_from_file (bookmarks, self->file_uri, &local_error))
    {
      if (!g_error_matches (local_error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
        {
          g_propagate_error (error, g_steal_pointer (&local_error));
          return NULL;
        }
    }

  return g_steal_pointer (&bookmarks);
}
static VALUE
bf_initialize(VALUE self)
{
    G_INITIALIZE(self, g_bookmark_file_new());
    return Qnil;
}
Example #7
0
static void
test_g_bookmark_file (void)
{
  g_autoptr(GBookmarkFile) val = g_bookmark_file_new ();
  g_assert (val != NULL);
}