Set Nautilus-Actions as being the actual official product name
[nautilus-actions.git] / src / nact / nact-ienvironment-tab.c
blob8a620ac238bcc1375b672978f6d3fb584a0e3491
1 /*
2 * Nautilus-Actions
3 * A Nautilus extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
9 * This Program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This Program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this Library; see the file COPYING. If not,
21 * write to the Free Software Foundation, Inc., 59 Temple Place,
22 * Suite 330, Boston, MA 02111-1307, USA.
24 * Authors:
25 * Frederic Ruaudel <grumz@grumz.net>
26 * Rodrigo Moya <rodrigo@gnome-db.org>
27 * Pierre Wieser <pwieser@trychlos.org>
28 * ... and many others (see AUTHORS)
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
35 #include <glib/gi18n.h>
36 #include <stdlib.h>
37 #include <string.h>
39 #include <api/na-core-utils.h>
40 #include <api/na-object-api.h>
42 #include "nact-gtk-utils.h"
43 #include "nact-main-tab.h"
44 #include "nact-ienvironment-tab.h"
46 /* private interface data
48 struct NactIEnvironmentTabInterfacePrivate {
49 void *empty; /* so that gcc -pedantic is happy */
52 /* columns in the selection count combobox
54 enum {
55 COUNT_SIGN_COLUMN = 0,
56 COUNT_LABEL_COLUMN,
57 COUNT_N_COLUMN
60 typedef struct {
61 gchar *sign;
62 gchar *label;
64 SelectionCountStruct;
66 /* i18n notes: selection count symbol, respectively 'less than', 'equal to' and 'greater than' */
67 static SelectionCountStruct st_counts[] = {
68 { "<", N_( "(strictly lesser than)" ) },
69 { "=", N_( "(equal to)" ) },
70 { ">", N_( "(strictly greater than)" ) },
71 { NULL }
74 /* column ordering in the OnlyShowIn/NotShowIn listview
76 enum {
77 ENV_BOOL_COLUMN = 0,
78 ENV_LABEL_COLUMN,
79 ENV_KEYWORD_COLUMN,
80 N_COLUMN
83 typedef struct {
84 gchar *keyword;
85 gchar *label;
87 EnvStruct;
89 static EnvStruct st_envs[] = {
90 { "GNOME", N_( "GNOME desktop" ) },
91 { "KDE", N_( "KDE desktop" ) },
92 { "ROX", N_( "ROX desktop" ) },
93 { "XFCE", N_( "XFCE desktop" ) },
94 { "Old", N_( "Legacy systems" ) },
95 { NULL }
98 static gboolean st_initialized = FALSE;
99 static gboolean st_finalized = FALSE;
100 static gboolean st_on_selection_change = FALSE;
102 static GType register_type( void );
103 static void interface_base_init( NactIEnvironmentTabInterface *klass );
104 static void interface_base_finalize( NactIEnvironmentTabInterface *klass );
106 static void on_tab_updatable_selection_changed( NactIEnvironmentTab *instance, gint count_selected );
108 static void on_selcount_ope_changed( GtkComboBox *combo, NactIEnvironmentTab *instance );
109 static void on_selcount_int_changed( GtkEntry *entry, NactIEnvironmentTab *instance );
110 static void on_selection_count_changed( NactIEnvironmentTab *instance );
111 static void on_show_always_toggled( GtkToggleButton *togglebutton, NactIEnvironmentTab *instance );
112 static void on_only_show_toggled( GtkToggleButton *togglebutton, NactIEnvironmentTab *instance );
113 static void on_do_not_show_toggled( GtkToggleButton *togglebutton, NactIEnvironmentTab *instance );
114 static void on_desktop_toggled( GtkCellRendererToggle *renderer, gchar *path, BaseWindow *window );
115 static void on_try_exec_changed( GtkEntry *entry, NactIEnvironmentTab *instance );
116 static void on_try_exec_browse( GtkButton *button, NactIEnvironmentTab *instance );
117 static void on_show_if_registered_changed( GtkEntry *entry, NactIEnvironmentTab *instance );
118 static void on_show_if_true_changed( GtkEntry *entry, NactIEnvironmentTab *instance );
119 static void on_show_if_running_changed( GtkEntry *entry, NactIEnvironmentTab *instance );
120 static void on_show_if_running_browse( GtkButton *button, NactIEnvironmentTab *instance );
122 static void init_selection_count_combobox( NactIEnvironmentTab *instance );
123 static gchar *get_selection_count_selection( NactIEnvironmentTab *instance );
124 static void set_selection_count_selection( NactIEnvironmentTab *instance, const gchar *ope, const gchar *uint );
125 static void dispose_selection_count_combobox( NactIEnvironmentTab *instance );
127 static void init_desktop_listview( NactIEnvironmentTab *instance );
128 static void raz_desktop_listview( NactIEnvironmentTab *instance );
129 static void setup_desktop_listview( NactIEnvironmentTab *instance, GSList *show );
130 static void dispose_desktop_listview( NactIEnvironmentTab *instance );
132 GType
133 nact_ienvironment_tab_get_type( void )
135 static GType iface_type = 0;
137 if( !iface_type ){
138 iface_type = register_type();
141 return( iface_type );
144 static GType
145 register_type( void )
147 static const gchar *thisfn = "nact_ienvironment_tab_register_type";
148 GType type;
150 static const GTypeInfo info = {
151 sizeof( NactIEnvironmentTabInterface ),
152 ( GBaseInitFunc ) interface_base_init,
153 ( GBaseFinalizeFunc ) interface_base_finalize,
154 NULL,
155 NULL,
156 NULL,
159 NULL
162 g_debug( "%s", thisfn );
164 type = g_type_register_static( G_TYPE_INTERFACE, "NactIEnvironmentTab", &info, 0 );
166 g_type_interface_add_prerequisite( type, BASE_WINDOW_TYPE );
168 return( type );
171 static void
172 interface_base_init( NactIEnvironmentTabInterface *klass )
174 static const gchar *thisfn = "nact_ienvironment_tab_interface_base_init";
176 if( !st_initialized ){
178 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
180 klass->private = g_new0( NactIEnvironmentTabInterfacePrivate, 1 );
182 st_initialized = TRUE;
186 static void
187 interface_base_finalize( NactIEnvironmentTabInterface *klass )
189 static const gchar *thisfn = "nact_ienvironment_tab_interface_base_finalize";
191 if( st_initialized && !st_finalized ){
193 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
195 st_finalized = TRUE;
197 g_free( klass->private );
202 * nact_ienvironment_tab_initial_load:
203 * @window: this #NactIEnvironmentTab instance.
205 * Initializes the tab widget at initial load.
207 void
208 nact_ienvironment_tab_initial_load_toplevel( NactIEnvironmentTab *instance )
210 static const gchar *thisfn = "nact_ienvironment_tab_initial_load_toplevel";
212 g_return_if_fail( NACT_IS_IENVIRONMENT_TAB( instance ));
214 if( st_initialized && !st_finalized ){
216 g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
218 init_selection_count_combobox( instance );
219 init_desktop_listview( instance );
224 * nact_ienvironment_tab_runtime_init:
225 * @window: this #NactIEnvironmentTab instance.
227 * Initializes the tab widget at each time the widget will be displayed.
228 * Connect signals and setup runtime values.
230 void
231 nact_ienvironment_tab_runtime_init_toplevel( NactIEnvironmentTab *instance )
233 static const gchar *thisfn = "nact_ienvironment_tab_runtime_init_toplevel";
234 GtkWidget *selcount_ope, *selcount_int;
235 GtkWidget *button, *entry;
236 GtkTreeView *listview;
237 GtkTreeModel *model;
238 GtkTreeIter iter;
239 GtkTreeViewColumn *column;
240 GList *renderers;
241 guint i;
243 g_return_if_fail( NACT_IS_IENVIRONMENT_TAB( instance ));
245 if( st_initialized && !st_finalized ){
247 g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
249 base_window_signal_connect(
250 BASE_WINDOW( instance ),
251 G_OBJECT( instance ),
252 MAIN_WINDOW_SIGNAL_SELECTION_CHANGED,
253 G_CALLBACK( on_tab_updatable_selection_changed ));
255 selcount_ope = base_window_get_widget( BASE_WINDOW( instance ), "SelectionCountSigneCombobox" );
256 base_window_signal_connect(
257 BASE_WINDOW( instance ),
258 G_OBJECT( selcount_ope ),
259 "changed",
260 G_CALLBACK( on_selcount_ope_changed ));
262 selcount_int = base_window_get_widget( BASE_WINDOW( instance ), "SelectionCountNumberEntry" );
263 base_window_signal_connect(
264 BASE_WINDOW( instance ),
265 G_OBJECT( selcount_int ),
266 "changed",
267 G_CALLBACK( on_selcount_int_changed ));
269 button = base_window_get_widget( BASE_WINDOW( instance ), "ShowAlwaysButton" );
270 base_window_signal_connect(
271 BASE_WINDOW( instance ),
272 G_OBJECT( button ),
273 "toggled",
274 G_CALLBACK( on_show_always_toggled ));
276 button = base_window_get_widget( BASE_WINDOW( instance ), "OnlyShowButton" );
277 base_window_signal_connect(
278 BASE_WINDOW( instance ),
279 G_OBJECT( button ),
280 "toggled",
281 G_CALLBACK( on_only_show_toggled ));
283 button = base_window_get_widget( BASE_WINDOW( instance ), "DoNotShowButton" );
284 base_window_signal_connect(
285 BASE_WINDOW( instance ),
286 G_OBJECT( button ),
287 "toggled",
288 G_CALLBACK( on_do_not_show_toggled ));
290 listview = GTK_TREE_VIEW( base_window_get_widget( BASE_WINDOW( instance ), "EnvironmentsDesktopTreeView" ));
291 model = gtk_tree_view_get_model( listview );
293 for( i = 0 ; st_envs[i].keyword ; ++i ){
294 gtk_list_store_append( GTK_LIST_STORE( model ), &iter );
295 gtk_list_store_set(
296 GTK_LIST_STORE( model ),
297 &iter,
298 ENV_BOOL_COLUMN, FALSE,
299 ENV_LABEL_COLUMN, st_envs[i].label,
300 ENV_KEYWORD_COLUMN, st_envs[i].keyword,
301 -1 );
304 column = gtk_tree_view_get_column( listview, ENV_BOOL_COLUMN );
305 renderers = gtk_cell_layout_get_cells( GTK_CELL_LAYOUT( column ));
306 base_window_signal_connect(
307 BASE_WINDOW( instance ),
308 G_OBJECT( renderers->data ),
309 "toggled",
310 G_CALLBACK( on_desktop_toggled ));
313 entry = base_window_get_widget( BASE_WINDOW( instance ), "TryExecEntry" );
314 base_window_signal_connect(
315 BASE_WINDOW( instance ),
316 G_OBJECT( entry ),
317 "changed",
318 G_CALLBACK( on_try_exec_changed ));
320 button = base_window_get_widget( BASE_WINDOW( instance ), "TryExecButton" );
321 base_window_signal_connect(
322 BASE_WINDOW( instance ),
323 G_OBJECT( button ),
324 "clicked",
325 G_CALLBACK( on_try_exec_browse ));
327 entry = base_window_get_widget( BASE_WINDOW( instance ), "ShowIfRegisteredEntry" );
328 base_window_signal_connect(
329 BASE_WINDOW( instance ),
330 G_OBJECT( entry ),
331 "changed",
332 G_CALLBACK( on_show_if_registered_changed ));
334 entry = base_window_get_widget( BASE_WINDOW( instance ), "ShowIfTrueEntry" );
335 base_window_signal_connect(
336 BASE_WINDOW( instance ),
337 G_OBJECT( entry ),
338 "changed",
339 G_CALLBACK( on_show_if_true_changed ));
341 entry = base_window_get_widget( BASE_WINDOW( instance ), "ShowIfRunningEntry" );
342 base_window_signal_connect(
343 BASE_WINDOW( instance ),
344 G_OBJECT( entry ),
345 "changed",
346 G_CALLBACK( on_show_if_running_changed ));
348 button = base_window_get_widget( BASE_WINDOW( instance ), "ShowIfRunningButton" );
349 base_window_signal_connect(
350 BASE_WINDOW( instance ),
351 G_OBJECT( button ),
352 "clicked",
353 G_CALLBACK( on_show_if_running_browse ));
357 void
358 nact_ienvironment_tab_all_widgets_showed( NactIEnvironmentTab *instance )
360 static const gchar *thisfn = "nact_ienvironment_tab_all_widgets_showed";
362 g_return_if_fail( NACT_IS_IENVIRONMENT_TAB( instance ));
364 if( st_initialized && !st_finalized ){
366 g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
371 * nact_ienvironment_tab_dispose:
372 * @window: this #NactIEnvironmentTab instance.
374 * Called at instance_dispose time.
376 void
377 nact_ienvironment_tab_dispose( NactIEnvironmentTab *instance )
379 static const gchar *thisfn = "nact_ienvironment_tab_dispose";
381 g_return_if_fail( NACT_IS_IENVIRONMENT_TAB( instance ));
383 if( st_initialized && !st_finalized ){
385 g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
387 st_on_selection_change = TRUE;
389 dispose_selection_count_combobox( instance );
390 dispose_desktop_listview( instance );
394 static void
395 on_tab_updatable_selection_changed( NactIEnvironmentTab *instance, gint count_selected )
397 static const gchar *thisfn = "nact_ienvironment_tab_on_tab_updatable_selection_changed";
398 NAIContext *context;
399 gboolean editable;
400 gboolean enable_tab;
401 gchar *sel_count, *selcount_ope, *selcount_int;
402 GtkWidget *combo, *entry;
403 GtkTreeView *listview;
404 GtkTreePath *path;
405 GtkTreeSelection *selection;
406 GtkWidget *always_button, *show_button, *notshow_button;
407 GtkWidget *browse_button;
408 GSList *desktops;
409 gchar *text;
411 g_return_if_fail( NACT_IS_IENVIRONMENT_TAB( instance ));
413 if( st_initialized && !st_finalized ){
415 g_debug( "%s: instance=%p, count_selected=%d", thisfn, ( void * ) instance, count_selected );
417 context = nact_main_tab_get_context( NACT_MAIN_WINDOW( instance ), &editable );
419 enable_tab = ( context != NULL );
420 nact_main_tab_enable_page( NACT_MAIN_WINDOW( instance ), TAB_ENVIRONMENT, enable_tab );
422 st_on_selection_change = TRUE;
424 /* selection count
426 sel_count = context ? na_object_get_selection_count( context ) : g_strdup( "" );
427 na_core_utils_selcount_get_ope_int( sel_count, &selcount_ope, &selcount_int );
428 set_selection_count_selection( instance, selcount_ope, selcount_int );
429 g_free( selcount_int );
430 g_free( selcount_ope );
431 g_free( sel_count );
433 combo = base_window_get_widget( BASE_WINDOW( instance ), "SelectionCountSigneCombobox" );
434 nact_gtk_utils_set_editable( G_OBJECT( combo ), editable );
436 entry = base_window_get_widget( BASE_WINDOW( instance ), "SelectionCountNumberEntry" );
437 nact_gtk_utils_set_editable( G_OBJECT( entry ), editable );
439 /* desktop environment
441 raz_desktop_listview( instance );
443 always_button = base_window_get_widget( BASE_WINDOW( instance ), "ShowAlwaysButton" );
444 nact_gtk_utils_set_editable( G_OBJECT( always_button ), editable );
446 show_button = base_window_get_widget( BASE_WINDOW( instance ), "OnlyShowButton" );
447 nact_gtk_utils_set_editable( G_OBJECT( show_button ), editable );
449 notshow_button = base_window_get_widget( BASE_WINDOW( instance ), "DoNotShowButton" );
450 nact_gtk_utils_set_editable( G_OBJECT( notshow_button ), editable );
452 desktops = context ? na_object_get_only_show_in( context ) : NULL;
453 listview = GTK_TREE_VIEW( base_window_get_widget( BASE_WINDOW( instance ), "EnvironmentsDesktopTreeView" ));
454 gtk_toggle_button_set_inconsistent( GTK_TOGGLE_BUTTON( always_button ), context == NULL );
456 if( desktops && g_slist_length( desktops )){
457 nact_gtk_utils_set_initial_state( GTK_TOGGLE_BUTTON( show_button ), G_CALLBACK( on_only_show_toggled ));
458 gtk_widget_set_sensitive( GTK_WIDGET( listview ), TRUE );
460 } else {
461 desktops = context ? na_object_get_not_show_in( context ) : NULL;
463 if( desktops && g_slist_length( desktops )){
464 nact_gtk_utils_set_initial_state( GTK_TOGGLE_BUTTON( notshow_button ), G_CALLBACK( on_do_not_show_toggled ));
465 gtk_widget_set_sensitive( GTK_WIDGET( listview ), TRUE );
467 } else {
468 nact_gtk_utils_set_initial_state( GTK_TOGGLE_BUTTON( always_button ), G_CALLBACK( on_show_always_toggled ));
469 gtk_widget_set_sensitive( GTK_WIDGET( listview ), FALSE );
470 desktops = NULL;
474 setup_desktop_listview( instance, desktops );
476 /* execution environment
478 entry = base_window_get_widget( BASE_WINDOW( instance ), "TryExecEntry" );
479 text = context ? na_object_get_try_exec( context ) : g_strdup( "" );
480 text = text && strlen( text ) ? text : g_strdup( "" );
481 gtk_entry_set_text( GTK_ENTRY( entry ), text );
482 g_free( text );
483 nact_gtk_utils_set_editable( G_OBJECT( entry ), editable );
485 browse_button = base_window_get_widget( BASE_WINDOW( instance ), "TryExecButton" );
486 nact_gtk_utils_set_editable( G_OBJECT( browse_button ), editable );
488 entry = base_window_get_widget( BASE_WINDOW( instance ), "ShowIfRegisteredEntry" );
489 text = context ? na_object_get_show_if_registered( context ) : g_strdup( "" );
490 text = text && strlen( text ) ? text : g_strdup( "" );
491 gtk_entry_set_text( GTK_ENTRY( entry ), text );
492 g_free( text );
493 nact_gtk_utils_set_editable( G_OBJECT( entry ), editable );
495 entry = base_window_get_widget( BASE_WINDOW( instance ), "ShowIfTrueEntry" );
496 text = context ? na_object_get_show_if_true( context ) : g_strdup( "" );
497 text = text && strlen( text ) ? text : g_strdup( "" );
498 gtk_entry_set_text( GTK_ENTRY( entry ), text );
499 g_free( text );
500 nact_gtk_utils_set_editable( G_OBJECT( entry ), editable );
502 entry = base_window_get_widget( BASE_WINDOW( instance ), "ShowIfRunningEntry" );
503 text = context ? na_object_get_show_if_running( context ) : g_strdup( "" );
504 text = text && strlen( text ) ? text : g_strdup( "" );
505 gtk_entry_set_text( GTK_ENTRY( entry ), text );
506 g_free( text );
507 nact_gtk_utils_set_editable( G_OBJECT( entry ), editable );
509 browse_button = base_window_get_widget( BASE_WINDOW( instance ), "ShowIfRunningButton" );
510 nact_gtk_utils_set_editable( G_OBJECT( browse_button ), editable );
512 st_on_selection_change = FALSE;
514 path = gtk_tree_path_new_first();
515 if( path ){
516 selection = gtk_tree_view_get_selection( listview );
517 gtk_tree_selection_select_path( selection, path );
518 gtk_tree_path_free( path );
523 static void
524 on_selcount_ope_changed( GtkComboBox *combo, NactIEnvironmentTab *instance )
526 on_selection_count_changed( instance );
529 static void
530 on_selcount_int_changed( GtkEntry *entry, NactIEnvironmentTab *instance )
532 on_selection_count_changed( instance );
535 static void
536 on_selection_count_changed( NactIEnvironmentTab *instance )
538 NAIContext *context;
539 gchar *selcount;
541 if( !st_on_selection_change ){
542 context = nact_main_tab_get_context( NACT_MAIN_WINDOW( instance ), NULL );
544 if( context ){
545 selcount = get_selection_count_selection( instance );
546 na_object_set_selection_count( context, selcount );
547 g_free( selcount );
549 g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, context, FALSE );
555 * the behavior coded here as one main drawback:
556 * - user will usually try to go through the radio buttons (always show,
557 * only show in, not show in) just to see what are their effects
558 * - but each time we toggle one of these buttons, the list of desktop is raz :(
560 * this behavior is inherent because we have to save each modification in the
561 * context as soon as this modification is made in the UI, so that user do not
562 * have to save each modification before going to another tab/context/item
564 * as far as I know, this case is the only which has this drawback...
566 static void
567 on_show_always_toggled( GtkToggleButton *toggle_button, NactIEnvironmentTab *instance )
569 static const gchar *thisfn = "nact_ienvironment_tab_on_show_always_toggled";
570 NAIContext *context;
571 gboolean editable;
572 gboolean active;
573 GtkTreeView *listview;
575 g_debug( "%s: toggle_button=%p (active=%s), instance=%p",
576 thisfn,
577 ( void * ) toggle_button, gtk_toggle_button_get_active( toggle_button ) ? "True":"False",
578 ( void * ) instance );
580 context = nact_main_tab_get_context( NACT_MAIN_WINDOW( instance ), &editable );
582 if( context ){
583 active = gtk_toggle_button_get_active( toggle_button );
585 if( editable ){
586 listview = GTK_TREE_VIEW( base_window_get_widget( BASE_WINDOW( instance ), "EnvironmentsDesktopTreeView" ));
587 gtk_widget_set_sensitive( GTK_WIDGET( listview ), !active );
589 if( active ){
590 raz_desktop_listview( instance );
591 na_object_set_only_show_in( context, NULL );
592 na_object_set_not_show_in( context, NULL );
593 g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, context, FALSE );
596 } else {
597 nact_gtk_utils_reset_initial_state( toggle_button, G_CALLBACK( on_show_always_toggled ), instance, active );
602 static void
603 on_only_show_toggled( GtkToggleButton *toggle_button, NactIEnvironmentTab *instance )
605 static const gchar *thisfn = "nact_ienvironment_tab_on_only_show_toggled";
606 NAIContext *context;
607 gboolean editable;
608 gboolean active;
609 GSList *show;
611 g_debug( "%s: toggle_button=%p (active=%s), instance=%p",
612 thisfn,
613 ( void * ) toggle_button, gtk_toggle_button_get_active( toggle_button ) ? "True":"False",
614 ( void * ) instance );
616 context = nact_main_tab_get_context( NACT_MAIN_WINDOW( instance ), &editable );
618 if( context ){
619 active = gtk_toggle_button_get_active( toggle_button );
621 if( editable ){
622 if( active ){
623 raz_desktop_listview( instance );
624 show = na_object_get_only_show_in( context );
625 if( show && g_slist_length( show )){
626 setup_desktop_listview( instance, show );
629 } else {
630 na_object_set_only_show_in( context, NULL );
631 g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, context, FALSE );
634 } else {
635 nact_gtk_utils_reset_initial_state( toggle_button, G_CALLBACK( on_only_show_toggled ), instance, active );
640 static void
641 on_do_not_show_toggled( GtkToggleButton *toggle_button, NactIEnvironmentTab *instance )
643 static const gchar *thisfn = "nact_ienvironment_tab_on_do_not_show_toggled";
644 NAIContext *context;
645 gboolean editable;
646 gboolean active;
647 GSList *show;
649 g_debug( "%s: toggle_button=%p (active=%s), instance=%p",
650 thisfn,
651 ( void * ) toggle_button, gtk_toggle_button_get_active( toggle_button ) ? "True":"False",
652 ( void * ) instance );
654 context = nact_main_tab_get_context( NACT_MAIN_WINDOW( instance ), &editable );
656 if( context ){
657 active = gtk_toggle_button_get_active( toggle_button );
659 if( editable ){
660 if( active ){
661 raz_desktop_listview( instance );
662 show = na_object_get_not_show_in( context );
663 if( show && g_slist_length( show )){
664 setup_desktop_listview( instance, show );
667 } else {
668 na_object_set_not_show_in( context, NULL );
669 g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, context, FALSE );
672 } else {
673 nact_gtk_utils_reset_initial_state( toggle_button, G_CALLBACK( on_do_not_show_toggled ), instance, active );
678 static void
679 on_desktop_toggled( GtkCellRendererToggle *renderer, gchar *path, BaseWindow *window )
681 static const gchar *thisfn = "nact_ienvironment_tab_on_desktop_toggled";
682 NAIContext *context;
683 gboolean editable;
684 GtkTreeView *listview;
685 GtkTreeModel *model;
686 GtkTreeIter iter;
687 GtkTreePath *tree_path;
688 gboolean state;
689 gchar *desktop;
690 GtkWidget *show_button;
692 g_debug( "%s: renderer=%p, path=%s, window=%p", thisfn, ( void * ) renderer, path, ( void * ) window );
694 if( !st_on_selection_change ){
695 context = nact_main_tab_get_context( NACT_MAIN_WINDOW( window ), &editable );
697 if( context ){
698 if( editable ){
699 listview = GTK_TREE_VIEW( base_window_get_widget( window, "EnvironmentsDesktopTreeView" ));
700 model = gtk_tree_view_get_model( listview );
701 tree_path = gtk_tree_path_new_from_string( path );
702 gtk_tree_model_get_iter( model, &iter, tree_path );
703 gtk_tree_path_free( tree_path );
704 gtk_tree_model_get( model, &iter, ENV_BOOL_COLUMN, &state, ENV_KEYWORD_COLUMN, &desktop, -1 );
705 gtk_list_store_set( GTK_LIST_STORE( model ), &iter, ENV_BOOL_COLUMN, !state, -1 );
707 show_button = base_window_get_widget( BASE_WINDOW( window ), "OnlyShowButton" );
708 if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( show_button ))){
709 na_object_set_only_desktop( context, desktop, !state );
710 } else {
711 na_object_set_not_desktop( context, desktop, !state );
714 g_signal_emit_by_name( G_OBJECT( window ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, context, FALSE );
716 g_free( desktop );
718 } else {
719 g_signal_handlers_block_by_func(( gpointer ) renderer, on_desktop_toggled, window );
720 gtk_cell_renderer_toggle_set_active( renderer, state );
721 g_signal_handlers_unblock_by_func(( gpointer ) renderer, on_desktop_toggled, window );
727 static void
728 on_try_exec_changed( GtkEntry *entry, NactIEnvironmentTab *instance )
730 NAIContext *context;
731 const gchar *text;
733 context = nact_main_tab_get_context( NACT_MAIN_WINDOW( instance ), NULL );
735 if( context ){
736 text = gtk_entry_get_text( entry );
737 na_object_set_try_exec( context, text );
738 g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, context, FALSE );
742 static void
743 on_try_exec_browse( GtkButton *button, NactIEnvironmentTab *instance )
745 GtkWidget *entry;
747 entry = base_window_get_widget( BASE_WINDOW( instance ), "TryExecEntry" );
749 nact_gtk_utils_select_file(
750 BASE_WINDOW( instance ),
751 _( "Choosing an executable" ), "ienvironment-try-exec-dialog",
752 entry, "ienvironment-try-exec-uri", "file:///bin" );
755 static void
756 on_show_if_registered_changed( GtkEntry *entry, NactIEnvironmentTab *instance )
758 NAIContext *context;
759 const gchar *text;
761 context = nact_main_tab_get_context( NACT_MAIN_WINDOW( instance ), NULL );
763 if( context ){
764 text = gtk_entry_get_text( entry );
765 na_object_set_show_if_registered( context, text );
766 g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, context, FALSE );
770 static void
771 on_show_if_true_changed( GtkEntry *entry, NactIEnvironmentTab *instance )
773 NAIContext *context;
774 const gchar *text;
776 context = nact_main_tab_get_context( NACT_MAIN_WINDOW( instance ), NULL );
778 if( context ){
779 text = gtk_entry_get_text( entry );
780 na_object_set_show_if_true( context, text );
781 g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, context, FALSE );
785 static void
786 on_show_if_running_changed( GtkEntry *entry, NactIEnvironmentTab *instance )
788 NAIContext *context;
789 const gchar *text;
791 context = nact_main_tab_get_context( NACT_MAIN_WINDOW( instance ), NULL );
793 if( context ){
794 text = gtk_entry_get_text( entry );
795 na_object_set_show_if_running( context, text );
796 g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, context, FALSE );
800 static void
801 on_show_if_running_browse( GtkButton *button, NactIEnvironmentTab *instance )
803 GtkWidget *entry;
805 entry = base_window_get_widget( BASE_WINDOW( instance ), "ShowIfRunningEntry" );
807 nact_gtk_utils_select_file(
808 BASE_WINDOW( instance ),
809 _( "Choosing an executable" ), "ienvironment-show-if-running-dialog",
810 entry, "ienvironment-show-if-running-uri", "file:///bin" );
813 static void
814 init_selection_count_combobox( NactIEnvironmentTab *instance )
816 GtkTreeModel *model;
817 guint i;
818 GtkTreeIter row;
819 GtkComboBox *combo;
820 GtkCellRenderer *cell_renderer_text;
822 model = GTK_TREE_MODEL( gtk_list_store_new( COUNT_N_COLUMN, G_TYPE_STRING, G_TYPE_STRING ));
823 i = 0;
824 while( st_counts[i].sign ){
825 gtk_list_store_append( GTK_LIST_STORE( model ), &row );
826 gtk_list_store_set( GTK_LIST_STORE( model ), &row, COUNT_SIGN_COLUMN, st_counts[i].sign, -1 );
827 gtk_list_store_set( GTK_LIST_STORE( model ), &row, COUNT_LABEL_COLUMN, st_counts[i].label, -1 );
828 i += 1;
831 combo = GTK_COMBO_BOX( base_window_get_widget( BASE_WINDOW( instance ), "SelectionCountSigneCombobox" ));
832 gtk_combo_box_set_model( combo, model );
833 g_object_unref( model );
835 gtk_cell_layout_clear( GTK_CELL_LAYOUT( combo ));
837 cell_renderer_text = gtk_cell_renderer_text_new();
838 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( combo ), cell_renderer_text, FALSE );
839 gtk_cell_layout_add_attribute( GTK_CELL_LAYOUT( combo ), cell_renderer_text, "text", COUNT_SIGN_COLUMN );
841 cell_renderer_text = gtk_cell_renderer_text_new();
842 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( combo ), cell_renderer_text, TRUE );
843 g_object_set( G_OBJECT( cell_renderer_text ), "xalign", ( gdouble ) 0.0, "style", PANGO_STYLE_ITALIC, "style-set", TRUE, NULL );
844 gtk_cell_layout_add_attribute( GTK_CELL_LAYOUT( combo ), cell_renderer_text, "text", COUNT_LABEL_COLUMN );
846 gtk_combo_box_set_active( GTK_COMBO_BOX( combo ), 0 );
849 static gchar *
850 get_selection_count_selection( NactIEnvironmentTab *instance )
852 GtkComboBox *combo;
853 GtkEntry *entry;
854 gint index;
855 gchar *uints, *selcount;
856 guint uinti;
858 combo = GTK_COMBO_BOX( base_window_get_widget( BASE_WINDOW( instance ), "SelectionCountSigneCombobox" ));
859 index = gtk_combo_box_get_active( combo );
860 if( index == -1 ){
861 return( NULL );
864 entry = GTK_ENTRY( base_window_get_widget( BASE_WINDOW( instance ), "SelectionCountNumberEntry" ));
865 uinti = abs( atoi( gtk_entry_get_text( entry )));
866 uints = g_strdup_printf( "%d", uinti );
867 gtk_entry_set_text( entry, uints );
868 g_free( uints );
870 selcount = g_strdup_printf( "%s%d", st_counts[index].sign, uinti );
872 return( selcount );
875 static void
876 set_selection_count_selection( NactIEnvironmentTab *instance, const gchar *ope, const gchar *uint )
878 GtkComboBox *combo;
879 GtkEntry *entry;
880 gint i, index;
882 combo = GTK_COMBO_BOX( base_window_get_widget( BASE_WINDOW( instance ), "SelectionCountSigneCombobox" ));
884 index = -1;
885 for( i=0 ; st_counts[i].sign && index==-1 ; ++i ){
886 if( !strcmp( st_counts[i].sign, ope )){
887 index = i;
890 gtk_combo_box_set_active( combo, index );
892 entry = GTK_ENTRY( base_window_get_widget( BASE_WINDOW( instance ), "SelectionCountNumberEntry" ));
893 gtk_entry_set_text( entry, uint );
896 static void
897 dispose_selection_count_combobox( NactIEnvironmentTab *instance )
899 GtkComboBox *combo;
900 GtkTreeModel *model;
902 combo = GTK_COMBO_BOX( base_window_get_widget( BASE_WINDOW( instance ), "SelectionCountSigneCombobox" ));
903 model = gtk_combo_box_get_model( combo );
904 gtk_list_store_clear( GTK_LIST_STORE( model ));
907 static void
908 init_desktop_listview( NactIEnvironmentTab *instance )
910 GtkTreeView *listview;
911 GtkListStore *model;
912 GtkCellRenderer *check_cell, *text_cell;
913 GtkTreeViewColumn *column;
914 GtkTreeSelection *selection;
916 listview = GTK_TREE_VIEW( base_window_get_widget( BASE_WINDOW( instance ), "EnvironmentsDesktopTreeView" ));
917 model = gtk_list_store_new( N_COLUMN, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING );
918 gtk_tree_view_set_model( listview, GTK_TREE_MODEL( model ));
919 g_object_unref( model );
921 check_cell = gtk_cell_renderer_toggle_new();
922 column = gtk_tree_view_column_new_with_attributes(
923 "boolean",
924 check_cell,
925 "active", ENV_BOOL_COLUMN,
926 NULL );
927 gtk_tree_view_append_column( listview, column );
929 text_cell = gtk_cell_renderer_text_new();
930 column = gtk_tree_view_column_new_with_attributes(
931 "label",
932 text_cell,
933 "text", ENV_LABEL_COLUMN,
934 NULL );
935 gtk_tree_view_append_column( listview, column );
937 gtk_tree_view_set_headers_visible( listview, FALSE );
939 selection = gtk_tree_view_get_selection( listview );
940 gtk_tree_selection_set_mode( selection, GTK_SELECTION_BROWSE );
943 static void
944 raz_desktop_listview( NactIEnvironmentTab *instance )
946 GtkTreeView *listview;
947 GtkTreeModel *model;
948 GtkTreeIter iter;
949 gboolean next_ok;
951 listview = GTK_TREE_VIEW( base_window_get_widget( BASE_WINDOW( instance ), "EnvironmentsDesktopTreeView" ));
952 model = gtk_tree_view_get_model( listview );
954 if( gtk_tree_model_get_iter_first( model, &iter )){
955 next_ok = TRUE;
956 while( next_ok ){
957 gtk_list_store_set( GTK_LIST_STORE( model ), &iter, ENV_BOOL_COLUMN, FALSE, -1 );
958 next_ok = gtk_tree_model_iter_next( model, &iter );
963 static void
964 setup_desktop_listview( NactIEnvironmentTab *instance, GSList *show )
966 static const gchar *thisfn = "nact_ienvironment_tab_setup_desktop_listview";
967 GtkTreeView *listview;
968 GtkTreeModel *model;
969 GtkTreeIter iter;
970 gboolean next_ok, found;
971 GSList *ic;
972 gchar *keyword;
974 listview = GTK_TREE_VIEW( base_window_get_widget( BASE_WINDOW( instance ), "EnvironmentsDesktopTreeView" ));
975 model = gtk_tree_view_get_model( listview );
977 for( ic = show ; ic ; ic = ic->next ){
978 if( strlen( ic->data )){
979 found = FALSE;
980 if( gtk_tree_model_get_iter_first( model, &iter )){
981 next_ok = TRUE;
982 while( next_ok && !found ){
983 gtk_tree_model_get( model, &iter, ENV_KEYWORD_COLUMN, &keyword, -1 );
984 if( !strcmp( keyword, ic->data )){
985 gtk_list_store_set( GTK_LIST_STORE( model ), &iter, ENV_BOOL_COLUMN, TRUE, -1 );
986 found = TRUE;
988 g_free( keyword );
989 if( !found ){
990 next_ok = gtk_tree_model_iter_next( model, &iter );
994 if( !found ){
995 g_warning( "%s: unable to set %s environment", thisfn, ( const gchar * ) ic->data );
1001 static void
1002 dispose_desktop_listview( NactIEnvironmentTab *instance )
1004 GtkTreeView *listview;
1005 GtkTreeModel *model;
1006 GtkTreeSelection *selection;
1008 listview = GTK_TREE_VIEW( base_window_get_widget( BASE_WINDOW( instance ), "EnvironmentsDesktopTreeView" ));
1009 model = gtk_tree_view_get_model( listview );
1010 selection = gtk_tree_view_get_selection( listview );
1011 gtk_tree_selection_unselect_all( selection );
1012 gtk_list_store_clear( GTK_LIST_STORE( model ));