4
* Created by: Axel von Bertoldi
5
* Last Modified: January 2008
6
* Last Modified by: Axel von Bertoldi
7
* (C) 2005-2008 Axel von Bertoldi
9
* This program is free software; you can redistribute it and/or modify it
10
* under the terms of the GNU General Public License as published by the Free
11
* Software Foundation; either version 2 of the License, or (at your option)
14
* This program is distributed in the hope that it will be useful, but WITHOUT
15
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19
* You should have received a copy of the GNU General Public License along with
20
* this program; if not, write to:
21
* The Free Software Foundation, Inc.,
22
* 51 Franklin Street, Fifth Floor
23
* Boston, MA 02110-1301, USA.
26
#include "preferences.h"
29
#include <glade/glade-xml.h>
30
#include <glib/gprintf.h>
35
/******************************************************************************/
36
struct _AppletPreferencesPrivate {
41
/******************************************************************************/
42
#define APPLET_PREFERENCES_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_APPLET_PREFERENCES, AppletPreferencesPrivate))
43
#define DEFAULT_ICON_PATH "/usr/share/pixmaps/"
44
/******************************************************************************/
46
APPLET_PREFERENCES_DUMMY_PROPERTY
61
/******************************************************************************/
62
static guint applet_preferences_signals[LAST_SIGNAL] = { 0 };
63
/* this is bad, but I need to get at the button from all over the file to
64
* update it's state. The other option is make it private member. */
65
/*static GtkWidget *revert_button = NULL;*/
66
/******************************************************************************/
67
static gpointer applet_preferences_parent_class = NULL;
68
static void applet_preferences_dispose (GObject *obj);
69
/******************************************************************************/
71
applet_preferences_on_show_icon_pressed (GtkWidget *widget, gpointer data) {
72
AppletPreferences *self = (AppletPreferences *)data;
74
/* get the new state from the widget and update the prefs structure */
75
self->menu_bar_prefs->show_icon = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
77
PrefsChangedSignalData *signal_data = g_new0 (PrefsChangedSignalData, 1);
78
signal_data->signal_id = PREFS_SIGNAL_SHOW_ICON;
79
signal_data->instance = -1;
80
signal_data->label = NULL;
81
signal_data->path = NULL;
83
/* emit the signal so the panel menu bar updates itself */
84
g_signal_emit (G_OBJECT (data),
85
applet_preferences_signals [PREFS_CHANGED],
89
/* update the state of the revert button. A pref has changed so the button
90
* should now be sensitive */
91
/*gtk_widget_set_sensitive (revert_button, TRUE);*/
94
/******************************************************************************/
96
applet_preferences_on_show_hidden_pressed (GtkWidget *widget, gpointer data) {
97
AppletPreferences *self = (AppletPreferences *)data;
98
/* get the new state from the widget and update the prefs structure. No
99
* need to let the menu bar or browser object know */
100
self->menu_bar_prefs->browser_prefs->show_hidden = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
102
/* update the state of the revert button. A pref has changed so the button
103
* should now be sensitive */
104
/*gtk_widget_set_sensitive (revert_button, TRUE);*/
107
/******************************************************************************/
109
applet_preferences_on_terminal_changed (GtkWidget *widget, gpointer data) {
111
AppletPreferences *self = (AppletPreferences *)data;
113
/* get the new state from the widget and update the prefs structure. No
114
* need to let the menu bar or browser object know */
115
tmp = self->menu_bar_prefs->browser_prefs->terminal;
117
self->menu_bar_prefs->browser_prefs->terminal = g_strdup (gtk_entry_get_text (GTK_ENTRY (widget)));
119
/* update the state of the revert button. A pref has changed so the button
120
* should now be sensitive */
121
/*gtk_widget_set_sensitive (revert_button, TRUE);*/
123
/******************************************************************************/
125
applet_preferences_on_editor_changed (GtkWidget *widget, gpointer data) {
127
AppletPreferences *self = (AppletPreferences *)data;
129
/* get the new state from the widget and update the prefs structure. No
130
* need to let the menu bar or browser object know */
131
tmp = self->menu_bar_prefs->browser_prefs->editor;
133
self->menu_bar_prefs->browser_prefs->editor = g_strdup (gtk_entry_get_text (GTK_ENTRY (widget)));
135
/* update the state of the revert button. A pref has changed so the button
136
* should now be sensitive */
137
/*gtk_widget_set_sensitive (revert_button, TRUE);*/
139
/******************************************************************************/
141
applet_preferences_on_icon_select (GtkWidget *button, gpointer data) {
142
GtkWidget *file_chooser_dialog;
143
gchar *icon_path = DEFAULT_ICON_PATH;
144
AppletPreferences *self = (AppletPreferences *)data;
145
/* set up a file chooser dialog so we can choose the new icon. An icon
146
* chooser would be better, but that widget is deprecated in the Gnome UI
147
* lib and GTK equivalent doesn't exist yet */
148
file_chooser_dialog = gtk_file_chooser_dialog_new ("Select Icon",
150
GTK_FILE_CHOOSER_ACTION_OPEN,
156
/* Set the starting path */
157
if (vfs_file_exists (self->menu_bar_prefs->icon)) {
158
icon_path = self->menu_bar_prefs->icon;
160
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (file_chooser_dialog),
162
/* check the reply */
163
if (gtk_dialog_run (GTK_DIALOG (file_chooser_dialog)) == GTK_RESPONSE_ACCEPT) {
165
new_icon = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_chooser_dialog));
166
/* make sure the new icon is not the same as the old one */
167
if (g_ascii_strcasecmp (new_icon, self->menu_bar_prefs->icon)) {
168
/* update the prefs structure */
169
g_free (self->menu_bar_prefs->icon);
170
self->menu_bar_prefs->icon = new_icon;
172
/* update the button's icon */
173
GtkWidget *icon = gtk_button_get_image (GTK_BUTTON (button));
174
gtk_widget_destroy (icon);
175
icon = utils_get_scaled_image_from_file (self->menu_bar_prefs->icon,
178
icon = gtk_image_new_from_icon_name ("user-home", GTK_ICON_SIZE_BUTTON);
180
gtk_button_set_image (GTK_BUTTON (button), icon);
182
PrefsChangedSignalData *signal_data = g_new0 (PrefsChangedSignalData, 1);
183
signal_data->signal_id = PREFS_SIGNAL_ICON_CHANGED;
184
signal_data->instance = -1;
185
signal_data->label = NULL;
186
signal_data->path = NULL;
188
/* emit the signal so the panel menu bar updates itself */
189
g_signal_emit (G_OBJECT (data),
190
applet_preferences_signals [PREFS_CHANGED],
193
/*gtk_widget_set_sensitive (revert_button, TRUE);*/
196
/* they chose the same icon again! */
201
/* clean up and update the state of the revert button. A pref has changed
202
* so the button should now be sensitive */
203
gtk_widget_destroy (file_chooser_dialog);
205
/******************************************************************************/
207
applet_preferences_save_to_gconf (AppletPreferences *self) {
208
PanelApplet *applet = self->priv->applet;
209
GError *error = NULL;
210
/* save the data in the prefs structure to the gconf schema (or whatever)*/
211
/* show hidden files? */
212
panel_applet_gconf_set_bool (applet,
214
self->menu_bar_prefs->browser_prefs->show_hidden,
216
utils_check_gerror (&error);
218
panel_applet_gconf_set_string (applet,
220
self->menu_bar_prefs->browser_prefs->terminal,
222
utils_check_gerror (&error);
224
panel_applet_gconf_set_string (applet,
226
self->menu_bar_prefs->browser_prefs->editor,
228
utils_check_gerror (&error);
230
panel_applet_gconf_set_string (applet,
232
self->menu_bar_prefs->icon,
234
utils_check_gerror (&error);
236
panel_applet_gconf_set_bool (applet,
238
self->menu_bar_prefs->show_icon,
240
utils_check_gerror (&error);
242
panel_applet_gconf_set_list (applet,
245
self->menu_bar_prefs->dirs,
247
utils_check_gerror (&error);
249
panel_applet_gconf_set_list (applet,
252
self->menu_bar_prefs->labels,
254
utils_check_gerror (&error);
257
/******************************************************************************/
259
applet_preferences_dialog_response (GtkWidget *window, gint response, gpointer data) {
260
AppletPreferences *self = (AppletPreferences *)data;
261
/* figure out what button closed the dialog and take the appropriate action */
263
case RESPONSE_REVERT:
264
/* revert to the saved config */
265
/*gtk_widget_set_sensitive (revert_button, FALSE);*/
268
case GTK_RESPONSE_CLOSE:
269
/* save the current configuration */
270
applet_preferences_save_to_gconf (self);
271
/*gtk_widget_set_sensitive (revert_button, FALSE);*/
272
gtk_widget_hide (window);
275
case GTK_RESPONSE_DELETE_EVENT:
276
/* neither save nor revert */
277
gtk_widget_hide (window);
282
/******************************************************************************/
284
applet_preferences_label_cell_edited (GtkCellRenderer *cell,
289
AppletPreferences *self = (AppletPreferences *)data;
290
GtkWidget *tree_view = self->priv->tree_view;
295
/* get the model where the actual data is stored */
296
model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
298
/* get an iterator to the model for the currently selected cell */
299
gtk_tree_model_get_iter_from_string (model,
302
/* update the model */
303
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
304
LABEL_COLUMN, new_string,
307
/* the path associated with the selection */
308
gtk_tree_model_get (model,
313
/* create the data structure with the event info to pass to panel_menu_bar */
314
PrefsChangedSignalData *signal_data = g_new0 (PrefsChangedSignalData, 1);
315
signal_data->signal_id = PREFS_SIGNAL_DIR_CHANGED;
316
signal_data->instance = atoi (path_string);
317
signal_data->label = g_strdup (new_string);
318
signal_data->path = path;
320
/* update this item from the list holding the label prefs */
322
tmp = g_slist_nth (self->menu_bar_prefs->labels, signal_data->instance);
324
tmp->data = (gpointer)g_strdup (new_string);
326
/* emit the signal so the panel menu bar updates itself */
327
g_signal_emit (G_OBJECT (data),
328
applet_preferences_signals [PREFS_CHANGED],
332
/* update the revert button*/
333
/*gtk_widget_set_sensitive (revert_button, TRUE);*/
336
/******************************************************************************/
338
applet_preferences_path_cell_activated (GtkTreeView *tree_view,
340
GtkTreeViewColumn *col,
342
AppletPreferences *self = (AppletPreferences *)data;
345
GtkWidget *file_chooser_dialog;
346
gchar *old_path = NULL;
348
model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
350
/* get an iterator to the model for the currently selected cell */
351
gtk_tree_model_get_iter (model,
354
/* the "Path" value for the active cell */
355
gtk_tree_model_get (model,
357
PATH_COLUMN, &old_path,
360
/* make a file chooser object to select the new path */
361
file_chooser_dialog = gtk_file_chooser_dialog_new ("Select New Folder To Browse",
363
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
369
/* Set the starting path as the old path */
370
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (file_chooser_dialog),
374
if (gtk_dialog_run (GTK_DIALOG (file_chooser_dialog)) == GTK_RESPONSE_ACCEPT) {
375
/* get the new path*/
376
gchar *new_path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_chooser_dialog));
377
/* only update data if it's not the same as the old one */
378
if (g_ascii_strcasecmp (old_path, new_path)) {
379
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
380
PATH_COLUMN, new_path,
384
/* the label associated with the selection */
386
gtk_tree_model_get (model,
388
LABEL_COLUMN, &label,
391
/* get the instance from the iterator */
392
gchar *instance = gtk_tree_model_get_string_from_iter (model, &iter);
394
/* create the data structure with the event info to pass to panel_menu_bar */
395
PrefsChangedSignalData *signal_data = g_new0 (PrefsChangedSignalData, 1);
396
signal_data->signal_id = PREFS_SIGNAL_DIR_CHANGED;
397
signal_data->instance = atoi (instance);
398
signal_data->label = label;
399
signal_data->path = new_path;
402
/* update this item from the list holding the path prefs */
404
tmp = g_slist_nth (self->menu_bar_prefs->dirs, signal_data->instance);
406
tmp->data = (gpointer)g_strdup (new_path);
408
/* emit the signal so the panel menu bar updates itself */
409
g_signal_emit (G_OBJECT (data),
410
applet_preferences_signals [PREFS_CHANGED],
414
/* update the revert button*/
415
/*gtk_widget_set_sensitive (revert_button, TRUE);*/
418
gtk_widget_destroy (file_chooser_dialog);
422
/******************************************************************************/
424
applet_preferences_on_add_dir_clicked (GtkWidget *widget, gpointer data) {
427
GtkWidget *file_chooser_dialog;
428
AppletPreferences *self = (AppletPreferences *)data;
429
GtkWidget *tree_view = self->priv->tree_view;
431
file_chooser_dialog = gtk_file_chooser_dialog_new ("Select Folder To Add",
433
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
439
/* Set the starting path */
440
gchar *start_path = g_strdup_printf ("%s/*", g_get_home_dir ());
441
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (file_chooser_dialog),
445
/* check the reply */
446
if (gtk_dialog_run (GTK_DIALOG (file_chooser_dialog)) == GTK_RESPONSE_ACCEPT) {
447
/* get the new path, and make the label from it */
448
gchar *dir = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_chooser_dialog));
449
gchar *label = g_path_get_basename (dir);
450
/* get the view's model, add a row and set the values */
451
model = gtk_tree_view_get_model (GTK_TREE_VIEW(tree_view));
452
gtk_list_store_append (GTK_LIST_STORE(model), &iter);
453
gtk_list_store_set (GTK_LIST_STORE(model), &iter,
458
/* create the data structure with the event info to pass to panel_menu_bar */
459
PrefsChangedSignalData *signal_data = g_new0 (PrefsChangedSignalData, 1);
460
signal_data->signal_id = PREFS_SIGNAL_DIR_ADD;
461
signal_data->instance = -1;
462
signal_data->label = label;
463
signal_data->path = dir;
465
/* add this item from the list holding the path/label prefs */
466
self->menu_bar_prefs->dirs = g_slist_append (self->menu_bar_prefs->dirs, g_strdup (dir));
467
self->menu_bar_prefs->labels = g_slist_append (self->menu_bar_prefs->labels, g_strdup(label));
469
/* emit the signal so the panel menu bar updates itself */
470
g_signal_emit (G_OBJECT (data),
471
applet_preferences_signals [PREFS_CHANGED],
475
/* update the revert button*/
476
/*gtk_widget_set_sensitive (revert_button, TRUE);*/
478
gtk_widget_destroy (file_chooser_dialog);
481
/******************************************************************************/
483
applet_preferences_on_rem_dir_clicked (GtkWidget *widget, gpointer data) {
484
GtkTreeSelection *selection;
487
AppletPreferences *self = (AppletPreferences *)data;
488
GtkWidget *tree_view = self->priv->tree_view;
490
/* get the current selection */
491
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree_view));
493
/* get the iterator for the current selection and remove the corresponding
494
* row form the model */
495
if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
497
/* get the instance from the iterator */
498
gchar *instance = gtk_tree_model_get_string_from_iter (model, &iter);
500
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
502
/* create the data structure with the event info to pass to panel_menu_bar */
503
PrefsChangedSignalData *signal_data = g_new0 (PrefsChangedSignalData, 1);
504
signal_data->signal_id = PREFS_SIGNAL_DIR_DEL;
505
signal_data->instance = atoi (instance);
506
signal_data->label = NULL;
507
signal_data->path = NULL;
510
/* remove this item from the list holding the path/label prefs */
512
tmp = g_slist_nth (self->menu_bar_prefs->dirs, signal_data->instance);
514
self->menu_bar_prefs->dirs = g_slist_delete_link (self->menu_bar_prefs->dirs, tmp);
515
tmp = g_slist_nth (self->menu_bar_prefs->labels, signal_data->instance);
517
self->menu_bar_prefs->labels = g_slist_delete_link (self->menu_bar_prefs->labels, tmp);
519
/* emit the signal so the panel menu bar updates itself */
520
g_signal_emit (G_OBJECT (data),
521
applet_preferences_signals [PREFS_CHANGED],
525
/* update the revert button*/
526
/*gtk_widget_set_sensitive (revert_button, TRUE);*/
531
/******************************************************************************/
533
applet_preferences_on_down_dir_clicked (GtkWidget *widget, gpointer data) {
534
GtkTreeSelection *selection = NULL;
535
GtkTreeModel *model = NULL;
536
GtkTreeIter iter, iter_next;
537
AppletPreferences *self = (AppletPreferences *)data;
538
GtkWidget *tree_view = self->priv->tree_view;
540
/* get the current selection */
541
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
543
/* get the iterator for the current selection */
544
if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
545
/* is this dangerous? Time will tell... */
547
/* get the next iterator and it it's valid, swap them */
548
if (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter_next)){
550
/* get the instance from the iterator */
551
gchar *instance = gtk_tree_model_get_string_from_iter (model, &iter);
553
gtk_list_store_swap (GTK_LIST_STORE (model),
557
/* create the data structure with the event info to pass to panel_menu_bar */
558
PrefsChangedSignalData *signal_data = g_new0 (PrefsChangedSignalData, 1);
559
signal_data->signal_id = PREFS_SIGNAL_DIR_MOVE_DOWN;
560
signal_data->instance = atoi (instance);
561
signal_data->label = NULL;
562
signal_data->path = NULL;
565
/* swap the entries in the list holding the path/label prefs */
566
g_slist_swap_data (self->menu_bar_prefs->dirs, signal_data->instance);
567
g_slist_swap_data (self->menu_bar_prefs->labels, signal_data->instance);
569
/* emit the signal so the panel menu bar updates itself */
570
g_signal_emit (G_OBJECT (data),
571
applet_preferences_signals [PREFS_CHANGED],
575
/* update the revert button*/
576
/*gtk_widget_set_sensitive (revert_button, TRUE);*/
581
/******************************************************************************/
583
applet_preferences_on_up_dir_clicked (GtkWidget *widget, gpointer data) {
584
GtkTreeSelection *selection = NULL;
585
GtkTreeModel *model = NULL;
586
GtkTreeIter iter, iter_prev;
588
AppletPreferences *self = (AppletPreferences *)data;
589
GtkWidget *tree_view = self->priv->tree_view;
591
/* get the current selection */
592
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
594
/* get the iterator for the current selection */
595
if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
596
/* Sigh! gtk_tree_model_iter_prev does not exist, so have to get the
597
* path for that iter and do a prev on it, then get the iter for the
599
path = gtk_tree_model_get_path (model, &iter);
600
/* if the previous path is valid */
601
if (gtk_tree_path_prev (path)) {
602
/* get the corresponding iter, and swap the store elements*/
603
gtk_tree_model_get_iter (model, &iter_prev, path);
605
/* get the instance from the iterator */
606
gchar *instance = gtk_tree_model_get_string_from_iter (model, &iter);
608
gtk_list_store_swap (GTK_LIST_STORE (model),
612
/* create the data structure with the event info to pass to panel_menu_bar */
613
PrefsChangedSignalData *signal_data = g_new0 (PrefsChangedSignalData, 1);
614
signal_data->signal_id = PREFS_SIGNAL_DIR_MOVE_UP;
615
signal_data->instance = atoi (instance);
616
signal_data->label = NULL;
617
signal_data->path = NULL;
620
/* swap the entries in the list holding the path/label prefs */
621
g_slist_swap_data (self->menu_bar_prefs->dirs, signal_data->instance - 1);
622
g_slist_swap_data (self->menu_bar_prefs->labels, signal_data->instance - 1);
624
/* emit the signal so the panel menu bar updates itself */
625
g_signal_emit (G_OBJECT (data),
626
applet_preferences_signals [PREFS_CHANGED],
630
/* update the revert button*/
631
/*gtk_widget_set_sensitive (revert_button, TRUE);*/
633
gtk_tree_path_free (path);
637
/******************************************************************************/
639
applet_preferences_create_list_view (AppletPreferences *self) {
642
GtkTreeViewColumn *column;
643
GtkCellRenderer *renderer;
644
GtkTreeSelection *selection;
646
/* Create a model. We are using the store model for now, though we
647
* could use any other GtkTreeModel */
648
store = gtk_list_store_new (N_COLUMNS,
652
/* fill the model with data */
653
GSList *tmp_dir = self->menu_bar_prefs->dirs;
654
GSList *tmp_label = self->menu_bar_prefs->labels;
655
while (tmp_label && tmp_dir) {
656
gtk_list_store_append (store, &iter);
657
gtk_list_store_set (store, &iter,
658
LABEL_COLUMN, (gchar *)tmp_label->data,
659
PATH_COLUMN, (gchar *)tmp_dir->data,
661
tmp_dir = tmp_dir->next;
662
tmp_label = tmp_label->next;
666
gtk_tree_view_set_model (GTK_TREE_VIEW (self->priv->tree_view), GTK_TREE_MODEL (store));
667
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (self->priv->tree_view), TRUE);
669
/* The view now holds a reference. We can get rid of our own
671
g_object_unref (G_OBJECT (store));
673
/* Create a cell render for the label, make it editable as set the callback */
674
renderer = gtk_cell_renderer_text_new ();
675
g_object_set (G_OBJECT (renderer), "editable", TRUE, NULL);
676
g_signal_connect (G_OBJECT (renderer),
678
G_CALLBACK (applet_preferences_label_cell_edited),
681
/* Create a column, associating the "text" attribute of the
682
* cell_renderer to the first column of the model */
683
column = gtk_tree_view_column_new_with_attributes ("Label", renderer,
684
"text", LABEL_COLUMN,
686
/* Add the column to the view. */
687
gtk_tree_view_append_column (GTK_TREE_VIEW (self->priv->tree_view), column);
689
/* Create a cell render for the path */
690
renderer = gtk_cell_renderer_text_new ();
691
g_signal_connect (G_OBJECT (self->priv->tree_view),
693
G_CALLBACK (applet_preferences_path_cell_activated),
695
column = gtk_tree_view_column_new_with_attributes ("Path", renderer,
698
gtk_tree_view_append_column (GTK_TREE_VIEW (self->priv->tree_view), column);
700
/*put the selection in SINGLE mode */
701
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(self->priv->tree_view));
702
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
706
/******************************************************************************/
708
applet_preferences_make_dialog (AppletPreferences *self) {
709
g_return_if_fail (self == NULL || IS_APPLET_PREFERENCES (self));
712
GtkWidget *show_icon;
713
GtkWidget *icon_button;
714
GtkWidget *show_hidden;
717
MenuBarPrefs *mb_prefs = self->menu_bar_prefs;
719
if (self->priv->window == NULL) {
720
GladeXML *xml = glade_xml_new (GLADEUI_PATH, NULL, NULL);
721
g_return_if_fail (xml != NULL);
722
window = glade_xml_get_widget (xml, "preferences_dialog");
724
g_signal_connect (G_OBJECT (GTK_DIALOG (window)),
726
G_CALLBACK (applet_preferences_dialog_response),
729
g_signal_connect (G_OBJECT (window),
731
G_CALLBACK (gtk_widget_hide),
734
/***** terminal *****/
735
terminal = glade_xml_get_widget (xml, "terminal_entry");
736
gtk_entry_set_width_chars (GTK_ENTRY (terminal), 10);
737
gtk_entry_set_text (GTK_ENTRY (terminal),
738
mb_prefs->browser_prefs->terminal);
739
g_signal_connect (G_OBJECT (terminal),
741
G_CALLBACK (applet_preferences_on_terminal_changed),
745
editor = glade_xml_get_widget (xml, "editor_entry");
746
gtk_entry_set_width_chars (GTK_ENTRY (editor), 10);
747
gtk_entry_set_text (GTK_ENTRY (editor),
748
mb_prefs->browser_prefs->editor);
749
g_signal_connect (G_OBJECT (editor),
751
G_CALLBACK (applet_preferences_on_editor_changed),
754
/***** show hidden *****/
755
show_hidden = glade_xml_get_widget (xml, "show_hidden_check");
756
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (show_hidden),
757
mb_prefs->browser_prefs->show_hidden);
758
g_signal_connect (G_OBJECT (show_hidden),
760
G_CALLBACK (applet_preferences_on_show_hidden_pressed),
764
show_icon = glade_xml_get_widget (xml, "show_icon_check");
765
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (show_icon),
766
mb_prefs->show_icon);
767
g_signal_connect (G_OBJECT (show_icon),
769
G_CALLBACK (applet_preferences_on_show_icon_pressed),
772
icon_button = glade_xml_get_widget (xml, "icon_button");
773
GtkWidget *icon = utils_get_scaled_image_from_file (mb_prefs->icon, ICON_BUTTON_SIZE);
775
icon = gtk_image_new_from_icon_name ("user-home", GTK_ICON_SIZE_BUTTON);
777
gtk_button_set_image (GTK_BUTTON (icon_button), icon);
778
g_signal_connect (G_OBJECT (icon_button),
780
G_CALLBACK (applet_preferences_on_icon_select),
783
/***** dirs/labels **/
784
self->priv->tree_view = glade_xml_get_widget (xml, "directories_tree");
785
applet_preferences_create_list_view (self);
787
/***** more buttons ******/
788
GtkWidget *add_button = glade_xml_get_widget (xml, "directory_add_button");
789
GtkWidget *rem_button = glade_xml_get_widget (xml, "directory_remove_button");
790
GtkWidget *up_button = glade_xml_get_widget (xml, "move_up_button");
791
GtkWidget *down_button = glade_xml_get_widget (xml, "move_down_button");
794
g_signal_connect (G_OBJECT (add_button),
796
G_CALLBACK (applet_preferences_on_add_dir_clicked),
798
g_signal_connect (G_OBJECT (rem_button),
800
G_CALLBACK (applet_preferences_on_rem_dir_clicked),
802
g_signal_connect (G_OBJECT (up_button),
804
G_CALLBACK (applet_preferences_on_up_dir_clicked),
806
g_signal_connect (G_OBJECT (down_button),
808
G_CALLBACK (applet_preferences_on_down_dir_clicked),
811
/***** the end ******/
812
self->priv->window = window;
815
gtk_widget_show_all (self->priv->window);
816
gtk_window_present (GTK_WINDOW (self->priv->window));
820
/******************************************************************************/
821
static MenuBarPrefs *
822
applet_preferences_load_from_gconf (PanelApplet *applet) {
823
GError *error = NULL;
825
MenuBarPrefs *mb_prefs = g_new0 (MenuBarPrefs, 1);
826
mb_prefs->browser_prefs = g_new0 (BrowserPrefs, 1);
828
/* this loads the default key's/values into the gconf entry for this applet
829
* instance. It also check to make sure the values were retrieved properly
830
* AND that they are valid */
831
panel_applet_add_preferences (applet, "/schemas/apps/file-browser-applet/prefs", &error);
832
if (utils_check_gerror (&error)) return NULL;
834
/* show hidden files? */
835
mb_prefs->browser_prefs->show_hidden = panel_applet_gconf_get_bool (applet,
838
if (utils_check_gerror (&error)) {
839
mb_prefs->browser_prefs->show_hidden = DEFAULT_SHOW_HIDDEN;
840
panel_applet_gconf_set_bool (applet,
842
mb_prefs->browser_prefs->show_hidden,
846
mb_prefs->browser_prefs->terminal = panel_applet_gconf_get_string (applet,
849
if (utils_check_gerror (&error) || mb_prefs->browser_prefs->terminal == NULL) {
850
mb_prefs->browser_prefs->terminal = g_strdup (DEFAULT_TERMINAL);
851
panel_applet_gconf_set_string (applet,
853
mb_prefs->browser_prefs->terminal,
857
mb_prefs->browser_prefs->editor = panel_applet_gconf_get_string (applet,
860
if (utils_check_gerror (&error) || mb_prefs->browser_prefs->editor == NULL) {
861
mb_prefs->browser_prefs->editor = g_strdup (DEFAULT_EDITOR);
862
panel_applet_gconf_set_string (applet,
864
mb_prefs->browser_prefs->editor,
869
mb_prefs->icon = panel_applet_gconf_get_string (applet,
872
if (utils_check_gerror (&error) || mb_prefs->icon == NULL) {
873
mb_prefs->icon = g_strdup (DEFAULT_ICON);
874
panel_applet_gconf_set_string (applet,
881
mb_prefs->show_icon = panel_applet_gconf_get_bool (applet,
884
if (utils_check_gerror (&error)) {
885
mb_prefs->show_icon = DEFAULT_SHOW_ICON;
886
panel_applet_gconf_set_bool (applet,
892
GSList *dirs = panel_applet_gconf_get_list (applet,
896
if (utils_check_gerror (&error) || dirs == NULL) {
897
dirs = g_slist_alloc ();
898
dirs->data = g_strdup (DEFAULT_PATH);
900
panel_applet_gconf_set_list (applet,
907
GSList *labels = panel_applet_gconf_get_list (applet,
911
if (utils_check_gerror (&error) || labels == NULL) {
912
labels = g_slist_alloc ();
913
labels->data = g_strdup (DEFAULT_LABEL);
915
panel_applet_gconf_set_list (applet,
921
mb_prefs->dirs = dirs;
922
mb_prefs->labels = labels;
926
/******************************************************************************/
928
applet_preferences_new (PanelApplet* applet) {
929
AppletPreferences *self;
930
g_return_val_if_fail (applet == NULL || PANEL_IS_APPLET (applet), NULL);
931
self = g_object_newv (TYPE_APPLET_PREFERENCES, 0, NULL);
933
self->menu_bar_prefs = applet_preferences_load_from_gconf (applet);
934
self->priv->window = NULL;
935
self->priv->applet = applet;
940
/******************************************************************************/
942
applet_preferences_class_init (AppletPreferencesClass * klass) {
943
applet_preferences_parent_class = g_type_class_peek_parent (klass);
944
g_type_class_add_private (klass, sizeof (AppletPreferencesPrivate));
945
G_OBJECT_CLASS (klass)->dispose = applet_preferences_dispose;
947
applet_preferences_signals [PREFS_CHANGED] =
948
g_signal_new ("prefs_changed",
949
G_TYPE_FROM_CLASS (klass),
951
/*G_STRUCT_OFFSET (AppletPreferencesClass, prefs_changed),*/
955
g_cclosure_marshal_VOID__INT,
959
/* NOTE!!! a dynamically allocated PrefsChangedSignalData structure is passed
960
* to the callback function including 2 gchar pointers. The callback function
961
* is responsible for freeing this memory. HOWEVER!!! make sure that the gchar*
962
* can be freed!!! Be careful!!!*/
964
/******************************************************************************/
966
applet_preferences_init (AppletPreferences * self) {
967
self->priv = APPLET_PREFERENCES_GET_PRIVATE (self);
969
/******************************************************************************/
971
applet_preferences_dispose (GObject * obj) {
972
AppletPreferences * self;
973
self = APPLET_PREFERENCES (obj);
974
(self->priv->window == NULL ? NULL : (self->priv->window = (g_object_unref (self->priv->window), NULL)));
975
G_OBJECT_CLASS (applet_preferences_parent_class)->dispose (obj);
977
/******************************************************************************/
979
applet_preferences_get_type (void) {
980
static GType applet_preferences_type_id = 0;
981
if (G_UNLIKELY (applet_preferences_type_id == 0)) {
982
static const GTypeInfo g_define_type_info = { sizeof (AppletPreferencesClass),
983
(GBaseInitFunc) NULL,
984
(GBaseFinalizeFunc) NULL,
985
(GClassInitFunc) applet_preferences_class_init,
986
(GClassFinalizeFunc) NULL,
988
sizeof (AppletPreferences),
990
(GInstanceInitFunc) applet_preferences_init };
992
applet_preferences_type_id = g_type_register_static (G_TYPE_OBJECT,
994
&g_define_type_info, 0);
996
return applet_preferences_type_id;
998
/******************************************************************************/