Exemplo n.º 1
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;
}
Exemplo n.º 2
0
static VALUE
bf_add_application(VALUE self, VALUE uri, VALUE name, VALUE exec)
{
    g_bookmark_file_add_application(_SELF(self),
                                    (const gchar *)RVAL2CSTR(uri),
                                    (const gchar *)RVAL2CSTR(name),
                                    (const gchar *)RVAL2CSTR(exec));
    return self;
}
Exemplo n.º 3
0
static gboolean
test_modify (GBookmarkFile *bookmark)
{
  gchar *text;
  guint count;
  time_t stamp;
  GError *error = NULL;
  
  g_print ("\t=> check global title/description...");
  g_bookmark_file_set_title (bookmark, NULL, "a file");
  g_bookmark_file_set_description (bookmark, NULL, "a bookmark file");
  
  text = g_bookmark_file_get_title (bookmark, NULL, &error);
  test_assert_empty_error (&error);
  test_assert_str_equal (text, "a file");
  g_free (text);

  text = g_bookmark_file_get_description (bookmark, NULL, &error);
  test_assert_empty_error (&error);
  test_assert_str_equal (text, "a bookmark file");
  g_free (text);
  g_print ("ok\n");

  g_print ("\t=> check bookmark title/description...");
  g_bookmark_file_set_title (bookmark, TEST_URI_0, "a title");
  g_bookmark_file_set_description (bookmark, TEST_URI_0, "a description");

  text = g_bookmark_file_get_title (bookmark, TEST_URI_0, &error);
  test_assert_empty_error (&error);
  test_assert_str_equal (text, "a title");
  g_free (text);
  g_print ("ok\n");

  g_print ("\t=> check non existing bookmark...");
  g_bookmark_file_get_description (bookmark, TEST_URI_1, &error);
  test_assert_not_empty_error (&error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
  g_print ("ok\n");
  
  g_print ("\t=> check application...");
  g_bookmark_file_set_mime_type (bookmark, TEST_URI_0, TEST_MIME);
  g_bookmark_file_add_application (bookmark, TEST_URI_0,
				   TEST_APP_NAME,
				   TEST_APP_EXEC);
  g_assert (g_bookmark_file_has_application (bookmark, TEST_URI_0, TEST_APP_NAME, NULL) == TRUE);
  g_bookmark_file_get_app_info (bookmark, TEST_URI_0, TEST_APP_NAME,
		  		&text,
				&count,
				&stamp,
				&error);
  test_assert_empty_error (&error);
  g_assert (count == 1);
  g_assert (stamp == g_bookmark_file_get_modified (bookmark, TEST_URI_0, NULL));
  g_free (text);
  
  g_bookmark_file_get_app_info (bookmark, TEST_URI_0, "fail",
		  		&text,
				&count,
				&stamp,
				&error);
  test_assert_not_empty_error (&error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED);
  g_print ("ok\n"); 

  g_print ("\t=> check groups...");
  g_bookmark_file_add_group (bookmark, TEST_URI_1, "Test");
  g_assert (g_bookmark_file_has_group (bookmark, TEST_URI_1, "Test", NULL) == TRUE);
  g_assert (g_bookmark_file_has_group (bookmark, TEST_URI_1, "Fail", NULL) == FALSE);
  g_print ("ok\n");

  g_print ("\t=> check remove...");
  g_assert (g_bookmark_file_remove_item (bookmark, TEST_URI_1, &error) == TRUE);
  test_assert_empty_error (&error);
  g_assert (g_bookmark_file_remove_item (bookmark, TEST_URI_1, &error) == FALSE);
  test_assert_not_empty_error (&error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
  g_print ("ok\n");
  
  return TRUE;
}