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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* Nautilus
*
* Copyright (C) 2000, 2001 Eazel, Inc.
*
* Nautilus is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Nautilus 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors: Andy Hertzfeld <andy@eazel.com>
* Ramiro Estrugo <ramiro@eazel.com>
*/
/* nautilus-theme-selector.c - Nautilus theme selector widget. */
#include <config.h>
#include "nautilus-theme-selector.h"
#include <eel/eel-art-gtk-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-gtk-macros.h>
#include <eel/eel-image-chooser.h>
#include <eel/eel-stock-dialogs.h>
#include <eel/eel-string.h>
#include <gtk/gtkalignment.h>
#include <gtk/gtkbutton.h>
#include <gtk/gtkfilesel.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtkmain.h>
#include <gtk/gtkscrolledwindow.h>
#include <gtk/gtksignal.h>
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>
#include <libnautilus-private/nautilus-global-preferences.h>
#include <libnautilus-private/nautilus-theme.h>
#define NUM_VISIBLE_THEMES 3
#define DEFAULT_THEME_NAME "default"
#define THEME_SELECTOR_DATA_KEY "nautilus-theme-selector"
struct NautilusThemeSelectorDetails
{
GtkWidget *help_label;
GtkWidget *install_theme_button;
GtkWidget *remove_theme_button;
GtkWidget *cancel_remove_button;
EelImageChooser *theme_selector;
EelImageChooser *remove_theme_selector;
GtkWidget *scrolled_window;
GtkWidget *remove_scrolled_window;
guint theme_selector_changed_connection;
GtkWindow *parent_window;
};
/* Signals */
typedef enum
{
THEME_CHANGED,
LAST_SIGNAL
} ThemeSelectorSignals;
static guint theme_selector_signals[LAST_SIGNAL];
/* GtkObjectClass methods */
static void nautilus_theme_selector_class_init (NautilusThemeSelectorClass *theme_selector_class);
static void nautilus_theme_selector_init (NautilusThemeSelector *theme_selector);
static void theme_selector_finalize (GObject *object);
/* Private stuff */
static void theme_selector_populate_list (EelImageChooser *image_chooser,
GtkWidget *scrolled_window,
gboolean include_builtin);
static void theme_selector_changed_callback (EelImageChooser *image_chooser,
gpointer callback_data);
static void remove_theme_selector_changed_callback (EelImageChooser *image_chooser,
gpointer callback_data);
static void install_theme_button_clicked_callback (GtkWidget *button,
gpointer callback_data);
static void remove_theme_button_clicked_callback (GtkWidget *button,
gpointer callback_data);
static void cancel_remove_button_clicked_callback (GtkWidget *button,
gpointer callback_data);
static gboolean theme_selector_has_user_themes (const NautilusThemeSelector *theme_selector);
static void theme_selector_update_remove_theme_button (NautilusThemeSelector *theme_selector);
static void theme_selector_update_selected_theme_from_preferences (NautilusThemeSelector *theme_selector);
static void theme_selector_update_help_label (NautilusThemeSelector *theme_selector,
gboolean removing);
EEL_CLASS_BOILERPLATE (NautilusThemeSelector, nautilus_theme_selector, GTK_TYPE_VBOX)
/* NautilusThemeSelectorClass methods */
static void
nautilus_theme_selector_class_init (NautilusThemeSelectorClass *theme_selector_class)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (theme_selector_class);
/* GObjectClass */
object_class->finalize = theme_selector_finalize;
/* Signals */
theme_selector_signals[THEME_CHANGED] = g_signal_new
("theme_changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_STRING);
}
static void
make_widgets_same_size (GtkWidget *one, GtkWidget *two)
{
EelDimensions one_dimensions;
EelDimensions two_dimensions;
g_return_if_fail (GTK_IS_WIDGET (one));
g_return_if_fail (GTK_IS_WIDGET (two));
one_dimensions = eel_gtk_widget_get_preferred_dimensions (one);
two_dimensions = eel_gtk_widget_get_preferred_dimensions (two);
gtk_widget_set_usize (one,
MAX (one_dimensions.width, two_dimensions.width),
MAX (one_dimensions.height, two_dimensions.height));
gtk_widget_set_usize (two,
MAX (one_dimensions.width, two_dimensions.width),
MAX (one_dimensions.height, two_dimensions.height));
}
static void
nautilus_theme_selector_init (NautilusThemeSelector *theme_selector)
{
GtkWidget *button_box;
GtkWidget *alignment_box;
theme_selector->details = g_new0 (NautilusThemeSelectorDetails, 1);
theme_selector->details->help_label = gtk_label_new ("");
gtk_label_set_justify (GTK_LABEL (theme_selector->details->help_label),
GTK_JUSTIFY_LEFT);
gtk_misc_set_alignment (GTK_MISC (theme_selector->details->help_label), 0.0, 1.0);
theme_selector_update_help_label (theme_selector, FALSE);
theme_selector->details->scrolled_window =
eel_scrolled_image_chooser_new ((GtkWidget**) &theme_selector->details->theme_selector);
theme_selector->details->remove_scrolled_window =
eel_scrolled_image_chooser_new ((GtkWidget**) &theme_selector->details->remove_theme_selector);
alignment_box = gtk_hbox_new (FALSE, 4);
button_box = gtk_hbox_new (TRUE, 2);
gtk_box_pack_start (GTK_BOX (theme_selector), theme_selector->details->help_label, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (theme_selector), theme_selector->details->scrolled_window, TRUE, TRUE, 4);
gtk_box_pack_start (GTK_BOX (theme_selector), theme_selector->details->remove_scrolled_window, TRUE, TRUE, 2);
gtk_box_pack_start (GTK_BOX (theme_selector), alignment_box, FALSE, TRUE, 2);
gtk_box_pack_end (GTK_BOX (alignment_box), button_box, FALSE, FALSE, 2);
theme_selector->details->install_theme_button = gtk_button_new_with_label (_("Add New Theme..."));
g_signal_connect (theme_selector->details->install_theme_button,
"clicked",
G_CALLBACK (install_theme_button_clicked_callback),
theme_selector);
theme_selector->details->remove_theme_button = gtk_button_new_with_label (_("Remove Theme..."));
g_signal_connect (theme_selector->details->remove_theme_button,
"clicked",
G_CALLBACK (remove_theme_button_clicked_callback),
theme_selector);
theme_selector->details->cancel_remove_button = gtk_button_new_with_label (_("Cancel Remove"));
g_signal_connect (theme_selector->details->cancel_remove_button,
"clicked",
G_CALLBACK (cancel_remove_button_clicked_callback),
theme_selector);
gtk_box_pack_start (GTK_BOX (button_box), theme_selector->details->cancel_remove_button, TRUE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (button_box), theme_selector->details->install_theme_button, TRUE, FALSE, 4);
gtk_box_pack_start (GTK_BOX (button_box), theme_selector->details->remove_theme_button, TRUE, FALSE, 4);
make_widgets_same_size (theme_selector->details->install_theme_button,
theme_selector->details->remove_theme_button);
theme_selector_populate_list (theme_selector->details->theme_selector,
theme_selector->details->scrolled_window,
TRUE);
theme_selector_update_selected_theme_from_preferences (theme_selector);
theme_selector_populate_list (theme_selector->details->remove_theme_selector,
theme_selector->details->remove_scrolled_window,
FALSE);
gtk_widget_show (theme_selector->details->help_label);
gtk_widget_show_all (theme_selector->details->scrolled_window);
gtk_widget_show_all (theme_selector->details->remove_scrolled_window);
gtk_widget_show_all (alignment_box);
gtk_widget_hide (theme_selector->details->remove_scrolled_window);
gtk_widget_hide (theme_selector->details->cancel_remove_button);
theme_selector_update_remove_theme_button (theme_selector);
g_signal_connect (theme_selector->details->theme_selector,
"selection_changed",
G_CALLBACK (theme_selector_changed_callback),
theme_selector);
theme_selector->details->theme_selector_changed_connection =
g_signal_connect (theme_selector->details->remove_theme_selector,
"selection_changed",
G_CALLBACK (remove_theme_selector_changed_callback),
theme_selector);
}
static void
theme_selector_update_help_label (NautilusThemeSelector *theme_selector,
gboolean removing)
{
g_return_if_fail (NAUTILUS_IS_THEME_SELECTOR (theme_selector));
if (removing) {
gtk_label_set_text (GTK_LABEL (theme_selector->details->help_label),
_("Click on a theme to remove it."));
} else {
gtk_label_set_text (GTK_LABEL (theme_selector->details->help_label),
_("Click on a theme to change the appearance of Nautilus."));
}
}
static void
file_selection_ok_clicked_callback (GtkWidget *button,
gpointer callback_data)
{
NautilusThemeSelector *theme_selector;
const char *selected_path;
NautilusThemeInstallResult result;
char *message;
g_return_if_fail (GTK_IS_BUTTON (button));
g_return_if_fail (GTK_IS_FILE_SELECTION (callback_data));
g_return_if_fail (NAUTILUS_IS_THEME_SELECTOR (g_object_get_data (G_OBJECT (callback_data),
THEME_SELECTOR_DATA_KEY)));
theme_selector = NAUTILUS_THEME_SELECTOR (g_object_get_data (G_OBJECT (callback_data),
THEME_SELECTOR_DATA_KEY));
selected_path = gtk_file_selection_get_filename (GTK_FILE_SELECTION (callback_data));
result = nautilus_theme_install_user_theme (selected_path);
switch (result) {
case NAUTILUS_THEME_INSTALL_NOT_A_THEME_DIRECTORY:
message = g_strdup_printf (_("Sorry, but \"%s\" is not a valid theme folder."),
selected_path);
eel_show_error_dialog (message, _("Couldn't add theme"),
theme_selector->details->parent_window);
g_free (message);
break;
case NAUTILUS_THEME_INSTALL_FAILED_USER_THEMES_DIRECTORY_CREATION:
case NAUTILUS_THEME_INSTALL_FAILED:
message = g_strdup_printf (_("Sorry, but the \"%s\" theme couldn't be installed."),
selected_path);
eel_show_error_dialog (message, _("Couldn't install theme"),
theme_selector->details->parent_window);
g_free (message);
break;
case NAUTILUS_THEME_INSTALL_OK:
/* Re populate the theme lists to match the stored state */
theme_selector_populate_list (theme_selector->details->theme_selector,
theme_selector->details->scrolled_window,
TRUE);
theme_selector_update_selected_theme_from_preferences (theme_selector);
theme_selector_populate_list (theme_selector->details->remove_theme_selector,
theme_selector->details->remove_scrolled_window,
FALSE);
/* Update the showing state of the remove button */
theme_selector_update_remove_theme_button (theme_selector);
break;
}
gtk_widget_destroy (GTK_WIDGET (callback_data));
}
static void
file_selection_cancel_clicked_callback (GtkWidget *button,
gpointer callback_data)
{
g_return_if_fail (GTK_IS_BUTTON (button));
g_return_if_fail (GTK_IS_FILE_SELECTION (callback_data));
gtk_widget_destroy (GTK_WIDGET (callback_data));
}
static void
install_theme_button_clicked_callback (GtkWidget *button,
gpointer callback_data)
{
NautilusThemeSelector *theme_selector;
GtkWidget *file_selection_dialog;
g_return_if_fail (GTK_IS_BUTTON (button));
g_return_if_fail (NAUTILUS_IS_THEME_SELECTOR (callback_data));
theme_selector = NAUTILUS_THEME_SELECTOR (callback_data);
file_selection_dialog = gtk_file_selection_new (_("Select a theme folder to add as a new theme:"));
g_object_set_data (G_OBJECT (file_selection_dialog),
THEME_SELECTOR_DATA_KEY,
callback_data);
g_signal_connect (GTK_FILE_SELECTION (file_selection_dialog)->ok_button,
"clicked",
G_CALLBACK (file_selection_ok_clicked_callback),
file_selection_dialog);
g_signal_connect (GTK_FILE_SELECTION (file_selection_dialog)->cancel_button,
"clicked",
G_CALLBACK (file_selection_cancel_clicked_callback),
file_selection_dialog);
gtk_window_set_position (GTK_WINDOW (file_selection_dialog), GTK_WIN_POS_MOUSE);
if (theme_selector->details->parent_window != NULL) {
gtk_window_set_transient_for (GTK_WINDOW (file_selection_dialog),
theme_selector->details->parent_window);
}
gtk_window_set_wmclass (GTK_WINDOW (file_selection_dialog), "file_selector", "Nautilus");
gtk_widget_show (GTK_WIDGET (file_selection_dialog));
}
static void
remove_theme_button_clicked_callback (GtkWidget *button,
gpointer callback_data)
{
NautilusThemeSelector *theme_selector;
g_return_if_fail (GTK_IS_BUTTON (button));
g_return_if_fail (NAUTILUS_IS_THEME_SELECTOR (callback_data));
theme_selector = NAUTILUS_THEME_SELECTOR (callback_data);
theme_selector_update_help_label (theme_selector, TRUE);
gtk_widget_hide (theme_selector->details->scrolled_window);
gtk_widget_show (theme_selector->details->remove_scrolled_window);
gtk_widget_show (theme_selector->details->cancel_remove_button);
gtk_widget_hide (theme_selector->details->install_theme_button);
gtk_widget_hide (theme_selector->details->remove_theme_button);
}
static void
theme_selector_finish_remove (NautilusThemeSelector *theme_selector)
{
g_return_if_fail (NAUTILUS_IS_THEME_SELECTOR (theme_selector));
theme_selector_update_help_label (theme_selector, FALSE);
gtk_widget_show (theme_selector->details->scrolled_window);
gtk_widget_hide (theme_selector->details->remove_scrolled_window);
gtk_widget_hide (theme_selector->details->cancel_remove_button);
gtk_widget_show (theme_selector->details->install_theme_button);
theme_selector_update_remove_theme_button (theme_selector);
eel_image_chooser_set_selected_row (theme_selector->details->remove_theme_selector, -1);
}
static gboolean
theme_selector_has_user_themes (const NautilusThemeSelector *theme_selector)
{
g_return_val_if_fail (NAUTILUS_IS_THEME_SELECTOR (theme_selector), FALSE);
return eel_image_chooser_get_num_rows (theme_selector->details->remove_theme_selector) > 0;
}
static void
theme_selector_update_remove_theme_button (NautilusThemeSelector *theme_selector)
{
g_return_if_fail (NAUTILUS_IS_THEME_SELECTOR (theme_selector));
eel_gtk_widget_set_shown (theme_selector->details->remove_theme_button,
theme_selector_has_user_themes (theme_selector));
}
static void
cancel_remove_button_clicked_callback (GtkWidget *button,
gpointer callback_data)
{
g_return_if_fail (GTK_IS_BUTTON (button));
g_return_if_fail (NAUTILUS_IS_THEME_SELECTOR (callback_data));
theme_selector_finish_remove (NAUTILUS_THEME_SELECTOR (callback_data));
}
static char *
theme_selector_get_selected_theme (const NautilusThemeSelector *theme_selector)
{
int selected_row_position;
gpointer row_data;
g_return_val_if_fail (NAUTILUS_IS_THEME_SELECTOR (theme_selector), NULL);
selected_row_position = eel_image_chooser_get_selected_row (theme_selector->details->theme_selector);
g_return_val_if_fail (selected_row_position != -1, NULL);
row_data = eel_image_chooser_get_row_data (theme_selector->details->theme_selector,
selected_row_position);
g_return_val_if_fail (row_data != NULL, NULL);
return g_strdup (row_data);
}
static void
remove_theme_selector_changed_callback (EelImageChooser *image_chooser,
gpointer callback_data)
{
NautilusThemeSelector *theme_selector;
int theme_to_remove_position;
char *theme_to_remove;
char *selected_theme;
GnomeVFSResult remove_result;
g_return_if_fail (EEL_IS_IMAGE_CHOOSER (image_chooser));
g_return_if_fail (NAUTILUS_IS_THEME_SELECTOR (callback_data));
theme_selector = NAUTILUS_THEME_SELECTOR (callback_data);
theme_to_remove_position = eel_image_chooser_get_selected_row (image_chooser);
g_return_if_fail (theme_to_remove_position != -1);
theme_to_remove = g_strdup ((const char *)eel_image_chooser_get_row_data (image_chooser, theme_to_remove_position));
gtk_signal_handler_block (GTK_OBJECT (theme_selector->details->remove_theme_selector),
theme_selector->details->theme_selector_changed_connection);
theme_selector_finish_remove (theme_selector);
gtk_signal_handler_unblock (GTK_OBJECT (theme_selector->details->remove_theme_selector),
theme_selector->details->theme_selector_changed_connection);
selected_theme = theme_selector_get_selected_theme (theme_selector);
g_return_if_fail (selected_theme != NULL);
/* Don't allow the current theme to be deleted */
if (eel_str_is_equal (selected_theme, theme_to_remove)) {
eel_image_chooser_set_selected_row (theme_selector->details->remove_theme_selector, -1);
g_free (selected_theme);
g_free (theme_to_remove);
eel_show_error_dialog (_("Sorry, but you can't remove the current theme. "
"Please change to another theme before removing this one."),
_("Can't delete current theme"),
theme_selector->details->parent_window);
return;
}
remove_result = nautilus_theme_remove_user_theme (theme_to_remove);
if (remove_result != GNOME_VFS_OK) {
eel_show_error_dialog (_("Sorry, but that theme could not be removed!"),
_("Couldn't remove theme"), NULL);
}
/* Re populate the theme lists to match the stored state */
theme_selector_populate_list (theme_selector->details->theme_selector,
theme_selector->details->scrolled_window,
TRUE);
theme_selector_update_selected_theme_from_preferences (theme_selector);
theme_selector_populate_list (theme_selector->details->remove_theme_selector,
theme_selector->details->remove_scrolled_window,
FALSE);
/* Update the showing state of the remove button */
theme_selector_update_remove_theme_button (theme_selector);
g_free (selected_theme);
g_free (theme_to_remove);
}
static void
theme_selector_changed_callback (EelImageChooser *image_chooser,
gpointer callback_data)
{
int selected_row_position;
g_return_if_fail (EEL_IS_IMAGE_CHOOSER (image_chooser));
g_return_if_fail (NAUTILUS_IS_THEME_SELECTOR (callback_data));
image_chooser = EEL_IMAGE_CHOOSER (image_chooser);
selected_row_position = eel_image_chooser_get_selected_row (image_chooser);
g_signal_emit (callback_data,
theme_selector_signals[THEME_CHANGED], 0);
}
/* GtkObjectClass methods */
static void
theme_selector_finalize (GObject *object)
{
NautilusThemeSelector *theme_selector;
g_return_if_fail (NAUTILUS_IS_THEME_SELECTOR (object));
theme_selector = NAUTILUS_THEME_SELECTOR (object);
theme_selector->details->theme_selector_changed_connection = 0;
g_free (theme_selector->details);
/* Chain finalize */
EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
}
/* Private stuff */
typedef struct
{
EelImageChooser *image_chooser;
gboolean include_builtin;
} ForEachThemeData;
static void
for_each_theme_callback (const char *name,
const char *path,
const char *display_name,
const char *description,
GdkPixbuf *preview_pixbuf,
gboolean builtin,
gpointer callback_data)
{
ForEachThemeData *data;
g_return_if_fail (name != NULL);
g_return_if_fail (path != NULL);
g_return_if_fail (display_name != NULL);
g_return_if_fail (description != NULL);
g_return_if_fail (preview_pixbuf != NULL);
g_return_if_fail (callback_data != NULL);
data = callback_data;
g_return_if_fail (EEL_IS_IMAGE_CHOOSER (data->image_chooser));
if (!data->include_builtin && builtin) {
return;
}
eel_image_chooser_insert_row (data->image_chooser,
preview_pixbuf,
display_name,
description,
g_strdup (name),
g_free);
}
static void
theme_selector_populate_list (EelImageChooser *image_chooser,
GtkWidget *scrolled_window,
gboolean include_builtin)
{
ForEachThemeData data;
g_return_if_fail (EEL_IS_IMAGE_CHOOSER (image_chooser));
g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
eel_image_chooser_clear (image_chooser);
data.image_chooser = image_chooser;
data.include_builtin = include_builtin;
nautilus_theme_for_each_theme (for_each_theme_callback, &data);
eel_scrolled_image_chooser_set_num_visible_rows (image_chooser,
scrolled_window,
NUM_VISIBLE_THEMES);
eel_scrolled_image_chooser_show_selected_row (image_chooser, scrolled_window);
}
static void
theme_selector_update_selected_theme_from_preferences (NautilusThemeSelector *theme_selector)
{
char *theme_name;
g_return_if_fail (NAUTILUS_IS_THEME_SELECTOR (theme_selector));
theme_name = eel_preferences_get (NAUTILUS_PREFERENCES_THEME);
nautilus_theme_selector_set_selected_theme (theme_selector, theme_name);
g_free (theme_name);
eel_scrolled_image_chooser_show_selected_row (theme_selector->details->theme_selector,
theme_selector->details->scrolled_window);
}
/* NautilusThemeSelector public methods */
GtkWidget *
nautilus_theme_selector_new (void)
{
return gtk_widget_new (NAUTILUS_TYPE_THEME_SELECTOR, NULL);
}
char *
nautilus_theme_selector_get_selected_theme (const NautilusThemeSelector *theme_selector)
{
const char *theme_name;
int selected_row_position;
g_return_val_if_fail (NAUTILUS_IS_THEME_SELECTOR (theme_selector), NULL);
selected_row_position = eel_image_chooser_get_selected_row (theme_selector->details->theme_selector);
g_return_val_if_fail (selected_row_position != -1, g_strdup (DEFAULT_THEME_NAME));
theme_name = eel_image_chooser_get_row_data (theme_selector->details->theme_selector,
selected_row_position);
return g_strdup (theme_name);
}
void
nautilus_theme_selector_set_selected_theme (NautilusThemeSelector *theme_selector,
char *new_theme_name)
{
guint i;
const char *theme_name;
g_return_if_fail (NAUTILUS_IS_THEME_SELECTOR (theme_selector));
for (i = 0; i < eel_image_chooser_get_num_rows (theme_selector->details->theme_selector); i++) {
theme_name = eel_image_chooser_get_row_data (theme_selector->details->theme_selector, i);
if (eel_str_is_equal (theme_name, new_theme_name)) {
eel_image_chooser_set_selected_row (theme_selector->details->theme_selector, i);
eel_scrolled_image_chooser_show_selected_row (theme_selector->details->theme_selector,
theme_selector->details->scrolled_window);
return;
}
}
}
void
nautilus_theme_selector_set_parent_window (NautilusThemeSelector *theme_selector,
GtkWindow *parent_window)
{
g_return_if_fail (NAUTILUS_IS_THEME_SELECTOR (theme_selector));
g_return_if_fail (GTK_IS_WINDOW (parent_window));
theme_selector->details->parent_window = parent_window;
}
|