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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* nautilus-prefs-dialog.c - Implementation for preferences dialog.
Copyright (C) 1999, 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Authors: Ramiro Estrugo <ramiro@eazel.com>
*/
#include <config.h>
#include <liboaf/liboaf.h>
#include "nautilus-global-preferences.h"
#include <nautilus-widgets/nautilus-preferences-group.h>
#include <nautilus-widgets/nautilus-preferences-item.h>
#include <nautilus-widgets/nautilus-preferences-dialog.h>
#include <libnautilus-extensions/nautilus-glib-extensions.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-view-identifier.h>
/* Constants */
#define GLOBAL_PREFERENCES_DIALOG_TITLE _("Nautilus Preferences")
/* User level */
#define NAUTILUS_PREFERENCES_USER_LEVEL "/nautilus/preferences/user_level"
enum
{
/* Start at something other than zero - which is reserved as the unspecified default value. */
NAUTILUS_USER_LEVEL_NOVICE = 100,
NAUTILUS_USER_LEVEL_INTERMEDIATE,
NAUTILUS_USER_LEVEL_HACKER
};
/* Private stuff */
static GtkWidget *global_preferences_create_dialog (void);
static GtkWidget *global_preferences_get_dialog (void);
static void global_preferences_register_for_ui (void);
static void user_level_changed_callback (gpointer user_data);
/*
* Private stuff
*/
static GtkWidget *
global_preferences_create_dialog (void)
{
GtkWidget *prefs_dialog;
NautilusPreferencesBox *preference_box;
GtkWidget *user_level_pane;
GtkWidget *directory_views_pane;
GtkWidget *meta_view_pane;
GtkWidget *appearance_pane;
/*
* In the soon to come star trek future, the following widgetry
* might be either fetched from a glade file or generated from
* an xml file.
*/
prefs_dialog = nautilus_preferences_dialog_new (GLOBAL_PREFERENCES_DIALOG_TITLE);
/* Create a preference box */
preference_box = NAUTILUS_PREFERENCES_BOX (nautilus_preferences_dialog_get_prefs_box
(NAUTILUS_PREFERENCES_DIALOG (prefs_dialog)));
/*
* User level pane
*/
user_level_pane = nautilus_preferences_box_add_pane (preference_box,
"User Level",
"User Level Something");
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (user_level_pane), "User Level");
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (user_level_pane),
0,
NAUTILUS_PREFERENCES_USER_LEVEL,
NAUTILUS_PREFERENCE_ITEM_ENUM);
/*
* Directory Views pane
*/
directory_views_pane = nautilus_preferences_box_add_pane (preference_box,
"Directory Views",
"Directory Views Something");
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane), "Window Behavior");
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane),
0,
NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW,
NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane), "Click Behavior");
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane),
1,
NAUTILUS_PREFERENCES_CLICK_POLICY,
NAUTILUS_PREFERENCE_ITEM_ENUM);
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane), "Remote Views");
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane),
2,
NAUTILUS_PREFERENCES_REMOTE_VIEWS,
NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
/*
* Meta view pane
*/
meta_view_pane = nautilus_preferences_box_add_pane (preference_box,
"Meta Views",
"Meta Views Something");
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (meta_view_pane), "Meta Views");
{
char *meta_view_pref;
GList *view_identifiers;
GList *p;
NautilusViewIdentifier *identifier;
view_identifiers = nautilus_global_preferences_get_sidebar_panel_view_identifiers ();
for (p = view_identifiers; p != NULL; p = p->next) {
identifier = (NautilusViewIdentifier *) (p->data);
meta_view_pref = g_strconcat ("/nautilus/metaviews/",
identifier->iid,
NULL);
nautilus_preferences_pane_add_item_to_nth_group
(NAUTILUS_PREFERENCES_PANE (meta_view_pane),
0,
meta_view_pref,
NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
g_free (meta_view_pref);
}
nautilus_view_identifier_free_list (view_identifiers);
}
/*
* Appearance
*/
appearance_pane = nautilus_preferences_box_add_pane (preference_box,
"Appearance",
"Appearance Options");
nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), "Appearance");
nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
0,
NAUTILUS_PREFERENCES_ANTI_ALIASED_CANVAS,
NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
return prefs_dialog;
}
/*
* Presummably, the following would be registered
* only if the component was present. Once we
* have smarter activation, that will be case.
*
* For now turn on all the ones we know about.
*/
GList *
nautilus_global_preferences_get_sidebar_panel_view_identifiers (void)
{
OAF_ServerInfoList *oaf_result;
const char *query;
CORBA_Environment ev;
int i;
GList *view_identifiers;
CORBA_exception_init (&ev);
view_identifiers = NULL;
oaf_result = NULL;
query = "repo_ids.has_all (['IDL:Nautilus/MetaView:1.0','IDL:Bonobo/Control:1.0'])";
oaf_result = oaf_query (query, NULL /* alphabetize by name in the future */, &ev);
if (ev._major == CORBA_NO_EXCEPTION && oaf_result != NULL && oaf_result->_length > 0) {
for (i = 0; i < oaf_result->_length; i++) {
view_identifiers = g_list_append (view_identifiers,
nautilus_view_identifier_new_from_sidebar_panel
(&oaf_result->_buffer[i]));
}
}
if (oaf_result != NULL) {
CORBA_free (oaf_result);
}
CORBA_exception_free (&ev);
return view_identifiers;
}
/*
* Presummably, the following would be registered
* only if the component was present. Once we
* have smarter activation, that will be case.
*
* For now turn on all the ones we know about.
*/
NautilusStringList *
nautilus_global_preferences_get_meta_view_iids (void)
{
NautilusStringList *meta_view_names;
GList *view_identifiers;
GList *p;
NautilusViewIdentifier *identifier;
view_identifiers = nautilus_global_preferences_get_sidebar_panel_view_identifiers ();
meta_view_names = nautilus_string_list_new ();
for (p = view_identifiers; p != NULL; p = p->next) {
identifier = (NautilusViewIdentifier *) (p->data);
nautilus_string_list_insert (meta_view_names,
identifier->iid);
}
nautilus_view_identifier_free_list (view_identifiers);
return meta_view_names;
}
static GtkWidget *
global_preferences_get_dialog (void)
{
static GtkWidget * global_prefs_dialog = NULL;
g_assert (nautilus_preferences_is_initialized ());
if (!global_prefs_dialog)
{
global_prefs_dialog = global_preferences_create_dialog ();
}
return global_prefs_dialog;
}
static void
nautilus_preferences_register_meta_view_preferences_for_ui (void)
{
GList *view_identifiers;
GList *p;
NautilusViewIdentifier *identifier;
char *preference_key;
view_identifiers = nautilus_global_preferences_get_sidebar_panel_view_identifiers ();
for (p = view_identifiers; p != NULL; p = p->next) {
identifier = (NautilusViewIdentifier *) (p->data);
preference_key = g_strconcat ("/nautilus/metaviews/", identifier->iid, NULL);
nautilus_preferences_set_info (preference_key,
identifier->name,
NAUTILUS_PREFERENCE_BOOLEAN,
(gconstpointer) TRUE);
g_free (preference_key);
}
nautilus_view_identifier_free_list (view_identifiers);
}
static void
global_preferences_register_for_ui ()
{
static gboolean preference_for_ui_registered = FALSE;
g_assert (nautilus_preferences_is_initialized ());
if (preference_for_ui_registered)
return;
preference_for_ui_registered = TRUE;
/*
* In the soon to come star trek future, the following information
* will be fetched using the latest xml techniques.
*/
/* Window create new */
nautilus_preferences_set_info (NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW,
"Open each item in a new window",
NAUTILUS_PREFERENCE_BOOLEAN,
(gconstpointer) FALSE);
/* Click activation type */
nautilus_preferences_set_info (NAUTILUS_PREFERENCES_CLICK_POLICY,
"Click policy",
NAUTILUS_PREFERENCE_ENUM,
(gconstpointer) NAUTILUS_CLICK_POLICY_SINGLE);
nautilus_preferences_enum_add_entry (NAUTILUS_PREFERENCES_CLICK_POLICY,
"single",
"Activate items with a single click",
NAUTILUS_CLICK_POLICY_SINGLE);
nautilus_preferences_enum_add_entry (NAUTILUS_PREFERENCES_CLICK_POLICY,
"double",
"Activate items with a double click",
NAUTILUS_CLICK_POLICY_DOUBLE);
/* remote views */
nautilus_preferences_set_info (NAUTILUS_PREFERENCES_REMOTE_VIEWS,
"Fully Decorate Remote Views",
NAUTILUS_PREFERENCE_BOOLEAN,
(gconstpointer) FALSE);
/* Anti-aliased canvas */
nautilus_preferences_set_info (NAUTILUS_PREFERENCES_ANTI_ALIASED_CANVAS,
"Use smoother (but slower) graphics",
NAUTILUS_PREFERENCE_BOOLEAN,
(gconstpointer) FALSE);
/* User level */
nautilus_preferences_set_info (NAUTILUS_PREFERENCES_USER_LEVEL,
"User Level",
NAUTILUS_PREFERENCE_ENUM,
(gconstpointer) NAUTILUS_USER_LEVEL_HACKER);
nautilus_preferences_enum_add_entry (NAUTILUS_PREFERENCES_USER_LEVEL,
"novice",
"Novice",
NAUTILUS_USER_LEVEL_NOVICE);
nautilus_preferences_enum_add_entry (NAUTILUS_PREFERENCES_USER_LEVEL,
"intermediate",
"Intermediate",
NAUTILUS_USER_LEVEL_INTERMEDIATE);
nautilus_preferences_enum_add_entry (NAUTILUS_PREFERENCES_USER_LEVEL,
"hacker",
"Hacker",
NAUTILUS_USER_LEVEL_HACKER);
/* Meta views */
nautilus_preferences_register_meta_view_preferences_for_ui ();
/* Appearance options */
nautilus_preferences_set_info (NAUTILUS_PREFERENCES_ANTI_ALIASED_CANVAS,
"Use smoother (but slower) graohics",
NAUTILUS_PREFERENCE_BOOLEAN,
(gconstpointer) FALSE);
/* miscellaneous */
nautilus_preferences_set_info (NAUTILUS_PREFERENCES_SHOW_REAL_FILE_NAME,
"Show entire file file",
NAUTILUS_PREFERENCE_BOOLEAN,
(gconstpointer) FALSE);
}
static void
user_level_changed_callback (gpointer user_data)
{
gint user_level;
char *home_uri_string;
gboolean show_hidden_files = FALSE;
gboolean use_real_home = TRUE;
gboolean show_real_file_name = FALSE;
gboolean can_add_content = TRUE;
const char *user_main_directory;
user_level = nautilus_preferences_get_enum (NAUTILUS_PREFERENCES_USER_LEVEL,
NAUTILUS_USER_LEVEL_HACKER);
/* Set some preferences according to the user level */
switch (user_level) {
case NAUTILUS_USER_LEVEL_NOVICE:
show_hidden_files = FALSE;
use_real_home = FALSE;
show_real_file_name = FALSE;
can_add_content = FALSE;
break;
case NAUTILUS_USER_LEVEL_INTERMEDIATE:
show_hidden_files = FALSE;
use_real_home = TRUE;
show_real_file_name = FALSE;
can_add_content = TRUE;
break;
case NAUTILUS_USER_LEVEL_HACKER:
default:
show_hidden_files = TRUE;
use_real_home = TRUE;
show_real_file_name = TRUE;
can_add_content = TRUE;
break;
}
nautilus_preferences_set_boolean (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
show_hidden_files);
nautilus_preferences_set_boolean (NAUTILUS_PREFERENCES_SHOW_REAL_FILE_NAME,
show_real_file_name);
nautilus_preferences_set_boolean (NAUTILUS_PREFERENCES_CAN_ADD_CONTENT,
can_add_content);
/* FIXME bugzilla.eazel.com 715: This call needs to be spanked to conform. Should return a strduped string */
user_main_directory = nautilus_user_main_directory ();
if (use_real_home)
home_uri_string = g_strdup_printf ("file://%s", g_get_home_dir());
else
home_uri_string = g_strdup_printf ("file://%s", user_main_directory);
g_assert (home_uri_string != NULL);
nautilus_preferences_set (NAUTILUS_PREFERENCES_HOME_URI,
home_uri_string);
g_free (home_uri_string);
}
/*
* Public functions
*/
void
nautilus_global_preferences_show_dialog (void)
{
GtkWidget * global_prefs_dialog = global_preferences_get_dialog ();
gtk_widget_show (global_prefs_dialog);
}
void
nautilus_global_preferences_shutdown (void)
{
/* Free the dialog first, cause it has refs to preferences */
GtkWidget * global_prefs_dialog = global_preferences_get_dialog ();
gtk_widget_destroy (global_prefs_dialog);
/* Now free the preferences tables and stuff */
nautilus_preferences_shutdown ();
}
void
nautilus_global_preferences_startup (void)
{
global_preferences_register_for_ui ();
/* Keep track of user level changes */
nautilus_preferences_add_enum_callback (NAUTILUS_PREFERENCES_USER_LEVEL,
user_level_changed_callback,
NULL);
/* Invoke the callback once to make sure stuff is properly setup */
user_level_changed_callback (NULL);
}
|