summaryrefslogtreecommitdiff
path: root/libnautilus-extensions/test-nautilus-preferences.c
blob: ba09358c2858414e3affc865325c0ec2a01396f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

#include <config.h>
#include "nautilus-radio-button-group.h"
#include "nautilus-caption-table.h"
#include "nautilus-password-dialog.h"
#include "nautilus-preferences-group.h"
#include "nautilus-preferences-item.h"
#include "nautilus-preferences.h"

#include <gtk/gtk.h>

static void test_preferences_group               (void);
static void test_preferences_item                (void);
static void register_global_preferences          (void);
GtkWidget * create_enum_item                     (const char *preference_name);
GtkWidget * create_bool_item                     (const char *preference_name);

enum
{
	FRUIT_APPLE,
	FRUIT_ORANGE,
	FRUIT_BANNANA
};

static const char FRUIT_PREFERENCE[] = "/a/very/fruity/path";

int
main (int argc, char * argv[])
{
	gnome_init ("foo", "bar", argc, argv);

	register_global_preferences ();

	test_preferences_group ();
	test_preferences_item ();
		
	gtk_main ();

	return 0;
}

static void
test_preferences_item (void)
{
	GtkWidget * window;
	GtkWidget * item;

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

	item = create_enum_item (FRUIT_PREFERENCE);

	gtk_container_add (GTK_CONTAINER (window), item);

	gtk_widget_show (item);

	gtk_widget_show (window);
}

static void
test_preferences_group (void)
{
	GtkWidget * window;
	GtkWidget * group;

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	
	group = nautilus_preferences_group_new ("A group");
	
	nautilus_preferences_group_add_item (NAUTILUS_PREFERENCES_GROUP (group),
					     FRUIT_PREFERENCE,
					     NAUTILUS_PREFERENCE_ITEM_ENUM);
	
	gtk_container_add (GTK_CONTAINER (window), group);

	gtk_widget_show (group);

	gtk_widget_show (window);
}

GtkWidget *
create_enum_item (const char *preference_name)
{
 	return nautilus_preferences_item_new (preference_name, NAUTILUS_PREFERENCE_ITEM_ENUM);
}

// GtkWidget *
// create_bool_item (const char *preference_name)
// {
// 	return nautilus_preferences_item_new (global_preferences,
// 					      preference_name,
// 					      NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
// }

static void
register_global_preferences (void)
{
	gconstpointer default_values[3] = { (gconstpointer)FRUIT_ORANGE, (gconstpointer)FRUIT_ORANGE, (gconstpointer)FRUIT_ORANGE };

	nautilus_preference_set_info_by_name (FRUIT_PREFERENCE,
					      "Fruits",
					      NAUTILUS_PREFERENCE_ENUM,
					      default_values,
					      3);
	
	nautilus_preference_enum_add_entry_by_name (FRUIT_PREFERENCE,
						    "apple",
						    "Apple",
						    FRUIT_APPLE);

	nautilus_preference_enum_add_entry_by_name (FRUIT_PREFERENCE,
					     "orange",
					     "Orange",
					     FRUIT_ORANGE);

	nautilus_preference_enum_add_entry_by_name (FRUIT_PREFERENCE,
					     "bannana",
					     "Bannana",
					     FRUIT_BANNANA);

	nautilus_preferences_set_enum (FRUIT_PREFERENCE,
				       FRUIT_BANNANA);
}