[nautilus-actions] Implement NactIFoldersTab interface



commit 5568fe42024a96027cb9a4485984e5e7687e0f5a
Author: Pierre Wieser <pwieser trychlos org>
Date:   Fri Jun 4 14:00:40 2010 +0200

    Implement NactIFoldersTab interface

 src/nact/nact-ibasenames-tab.c |   15 +-
 src/nact/nact-ifolders-tab.c   |  532 +++++-----------------------------------
 src/nact/nact-imimetypes-tab.c |   15 +-
 src/nact/nact-match-list.c     |  111 ++++++---
 src/nact/nact-match-list.h     |   21 ++-
 5 files changed, 169 insertions(+), 525 deletions(-)
---
diff --git a/src/nact/nact-ibasenames-tab.c b/src/nact/nact-ibasenames-tab.c
index 4c2b4b7..a686696 100644
--- a/src/nact/nact-ibasenames-tab.c
+++ b/src/nact/nact-ibasenames-tab.c
@@ -51,15 +51,15 @@ struct NactIBasenamesTabInterfacePrivate {
 static gboolean st_initialized = FALSE;
 static gboolean st_finalized = FALSE;
 
-static GType    register_type( void );
-static void     interface_base_init( NactIBasenamesTabInterface *klass );
-static void     interface_base_finalize( NactIBasenamesTabInterface *klass );
+static GType   register_type( void );
+static void    interface_base_init( NactIBasenamesTabInterface *klass );
+static void    interface_base_finalize( NactIBasenamesTabInterface *klass );
 
-static void     on_tab_updatable_selection_changed( BaseWindow *window, gint count_selected );
-static void     on_tab_updatable_enable_tab( BaseWindow *window, NAObjectItem *item );
+static void    on_tab_updatable_selection_changed( BaseWindow *window, gint count_selected );
+static void    on_tab_updatable_enable_tab( BaseWindow *window, NAObjectItem *item );
 
-static GSList  *get_basenames( void *context );
-static void     set_basenames( void *context, GSList *filters );
+static GSList *get_basenames( void *context );
+static void    set_basenames( void *context, GSList *filters );
 
 GType
 nact_ibasenames_tab_get_type( void )
@@ -159,6 +159,7 @@ nact_ibasenames_tab_initial_load_toplevel( NactIBasenamesTab *instance )
 				list, add, remove,
 				( pget_filters ) get_basenames,
 				( pset_filters ) set_basenames,
+				NULL,
 				_( "Basename filter" ));
 	}
 }
diff --git a/src/nact/nact-ifolders-tab.c b/src/nact/nact-ifolders-tab.c
index 5926184..6ccb68b 100644
--- a/src/nact/nact-ifolders-tab.c
+++ b/src/nact/nact-ifolders-tab.c
@@ -32,7 +32,6 @@
 #include <config.h>
 #endif
 
-#include <gdk/gdkkeysyms.h>
 #include <glib/gi18n.h>
 #include <string.h>
 
@@ -47,6 +46,7 @@
 #include "nact-iprefs.h"
 #include "nact-application.h"
 #include "nact-main-tab.h"
+#include "nact-match-list.h"
 #include "nact-ifolders-tab.h"
 
 /* private interface data
@@ -55,44 +55,24 @@ struct NactIFoldersTabInterfacePrivate {
 	void *empty;						/* so that gcc -pedantic is happy */
 };
 
-/* column ordering
- */
-enum {
-	FOLDERS_PATH_COLUMN = 0,
-	FOLDERS_N_COLUMN
-};
+#define ITAB_NAME						"folders"
 
-#define IPREFS_FOLDERS_DIALOG		"ifolders-chooser"
-#define IPREFS_FOLDERS_PATH			"ifolders-path"
+#define IPREFS_FOLDERS_DIALOG			"ifolders-chooser"
+#define IPREFS_FOLDERS_PATH				"ifolders-path"
 
 static gboolean st_initialized = FALSE;
 static gboolean st_finalized = FALSE;
-static gboolean st_on_selection_change = FALSE;
-
-static GType        register_type( void );
-static void         interface_base_init( NactIFoldersTabInterface *klass );
-static void         interface_base_finalize( NactIFoldersTabInterface *klass );
-
-static void         on_tab_updatable_selection_changed( NactIFoldersTab *instance, gint count_selected );
-static void         on_tab_updatable_enable_tab( NactIFoldersTab *instance, NAObjectItem *item );
-static gboolean     tab_set_sensitive( NactIFoldersTab *instance );
-
-static gboolean     on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, NactIFoldersTab *instance );
-static void         inline_edition( NactIFoldersTab *instance );
-static void         insert_new_row( NactIFoldersTab *instance );
-static void         delete_row( NactIFoldersTab *instance );
-
-static void         add_row( NactIFoldersTab *instance, GtkTreeView *listview, const gchar *path );
-static void         add_path_to_folders( NactIFoldersTab *instance, const gchar *path );
-static GtkTreeView *get_folders_treeview( NactIFoldersTab *instance );
-static void         on_folder_path_edited( GtkCellRendererText *renderer, const gchar *path, const gchar *text, NactIFoldersTab *instance );
-static void         on_folders_selection_changed( GtkTreeSelection *selection, NactIFoldersTab *instance );
-static void         on_add_folder_clicked( GtkButton *button, NactIFoldersTab *instance );
-static void         on_remove_folder_clicked( GtkButton *button, NactIFoldersTab *instance );
-static void         remove_path_from_folders( NactIFoldersTab *instance, const gchar *path );
-static void         reset_folders( NactIFoldersTab *instance );
-static void         setup_folders( NactIFoldersTab *instance );
-static void         treeview_cell_edited( NactIFoldersTab *instance, const gchar *path_string, const gchar *text, gint column, gchar **old_text );
+
+static GType   register_type( void );
+static void    interface_base_init( NactIFoldersTabInterface *klass );
+static void    interface_base_finalize( NactIFoldersTabInterface *klass );
+
+static void    on_add_folder_clicked( GtkButton *button, MatchListStr *data );
+static void    on_tab_updatable_selection_changed( NactIFoldersTab *instance, gint count_selected );
+static void    on_tab_updatable_enable_tab( NactIFoldersTab *instance, NAObjectItem *item );
+
+static GSList *get_folders( void *context );
+static void    set_folders( void *context, GSList *filters );
 
 GType
 nact_ifolders_tab_get_type( void )
@@ -167,35 +147,27 @@ void
 nact_ifolders_tab_initial_load_toplevel( NactIFoldersTab *instance )
 {
 	static const gchar *thisfn = "nact_ifolders_tab_initial_load_toplevel";
-	GtkTreeView *listview;
-	GtkListStore *model;
-	GtkTreeViewColumn *column;
-	GtkCellRenderer *text_cell;
-	GtkTreeSelection *selection;
+	GtkWidget *list, *add, *remove;
 
-	g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
 	g_return_if_fail( NACT_IS_IFOLDERS_TAB( instance ));
 
 	if( st_initialized && !st_finalized ){
 
-		model = gtk_list_store_new( FOLDERS_N_COLUMN, G_TYPE_STRING );
-		gtk_tree_sortable_set_sort_column_id( GTK_TREE_SORTABLE( model ), FOLDERS_PATH_COLUMN, GTK_SORT_ASCENDING );
-		listview = get_folders_treeview( instance );
-		gtk_tree_view_set_model( listview, GTK_TREE_MODEL( model ));
-		g_object_unref( model );
+		g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
 
-		text_cell = gtk_cell_renderer_text_new();
-		column = gtk_tree_view_column_new_with_attributes(
-				"folder-path",
-				text_cell,
-				"text", FOLDERS_PATH_COLUMN,
-				NULL );
-		gtk_tree_view_append_column( listview, column );
+		list = base_window_get_widget( BASE_WINDOW( instance ), "FoldersTreeView" );
+		add = base_window_get_widget( BASE_WINDOW( instance ), "AddFolderButton" );
+		remove = base_window_get_widget( BASE_WINDOW( instance ), "RemoveFolderButton" );
 
-		gtk_tree_view_set_headers_visible( listview, FALSE );
-
-		selection = gtk_tree_view_get_selection( listview );
-		gtk_tree_selection_set_mode( selection, GTK_SELECTION_BROWSE );
+		nact_match_list_create_model(
+				BASE_WINDOW( instance ),
+				ITAB_NAME,
+				TAB_FOLDERS,
+				list, add, remove,
+				( pget_filters ) get_folders,
+				( pset_filters ) set_folders,
+				( pon_add_callback ) on_add_folder_clicked,
+				_( "Folder filter" ));
 	}
 }
 
@@ -203,16 +175,13 @@ void
 nact_ifolders_tab_runtime_init_toplevel( NactIFoldersTab *instance )
 {
 	static const gchar *thisfn = "nact_ifolders_tab_runtime_init_toplevel";
-	GtkTreeView *listview;
-	GtkTreeViewColumn *column;
-	GList *renderers;
-	GtkWidget *add_button, *remove_button;
 
-	g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
 	g_return_if_fail( NACT_IS_IFOLDERS_TAB( instance ));
 
 	if( st_initialized && !st_finalized ){
 
+		g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
+
 		base_window_signal_connect(
 				BASE_WINDOW( instance ),
 				G_OBJECT( instance ),
@@ -225,40 +194,7 @@ nact_ifolders_tab_runtime_init_toplevel( NactIFoldersTab *instance )
 				TAB_UPDATABLE_SIGNAL_ENABLE_TAB,
 				G_CALLBACK( on_tab_updatable_enable_tab ));
 
-		listview = get_folders_treeview( instance );
-		column = gtk_tree_view_get_column( listview, FOLDERS_PATH_COLUMN );
-		renderers = gtk_cell_layout_get_cells( GTK_CELL_LAYOUT( column ));
-		base_window_signal_connect(
-				BASE_WINDOW( instance ),
-				G_OBJECT( renderers->data ),
-				"edited",
-				G_CALLBACK( on_folder_path_edited ));
-
-		add_button = base_window_get_widget( BASE_WINDOW( instance ), "AddFolderButton");
-		base_window_signal_connect(
-				BASE_WINDOW( instance ),
-				G_OBJECT( add_button ),
-				"clicked",
-				G_CALLBACK( on_add_folder_clicked ));
-
-		remove_button = base_window_get_widget( BASE_WINDOW( instance ), "RemoveFolderButton");
-		base_window_signal_connect(
-				BASE_WINDOW( instance ),
-				G_OBJECT( remove_button ),
-				"clicked",
-				G_CALLBACK( on_remove_folder_clicked ));
-
-		base_window_signal_connect(
-				BASE_WINDOW( instance ),
-				G_OBJECT( gtk_tree_view_get_selection( listview )),
-				"changed",
-				G_CALLBACK( on_folders_selection_changed ));
-
-		base_window_signal_connect(
-				BASE_WINDOW( instance ),
-				G_OBJECT( listview ),
-				"key-press-event",
-				G_CALLBACK( on_key_pressed_event ));
+		nact_match_list_init_view( BASE_WINDOW( instance ), ITAB_NAME );
 	}
 }
 
@@ -267,10 +203,11 @@ nact_ifolders_tab_all_widgets_showed( NactIFoldersTab *instance )
 {
 	static const gchar *thisfn = "nact_ifolders_tab_all_widgets_showed";
 
-	g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
 	g_return_if_fail( NACT_IS_IFOLDERS_TAB( instance ));
 
 	if( st_initialized && !st_finalized ){
+
+		g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
 	}
 }
 
@@ -279,273 +216,18 @@ nact_ifolders_tab_dispose( NactIFoldersTab *instance )
 {
 	static const gchar *thisfn = "nact_ifolders_tab_dispose";
 
-	g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
 	g_return_if_fail( NACT_IS_IFOLDERS_TAB( instance ));
 
 	if( st_initialized && !st_finalized ){
 
-		reset_folders( instance );
-	}
-}
-
-static void
-on_tab_updatable_selection_changed( NactIFoldersTab *instance, gint count_selected )
-{
-	static const gchar *thisfn = "nact_ifolders_tab_on_tab_updatable_selection_changed";
-	NAObjectItem *item;
-	NAObjectProfile *profile;
-	gboolean editable;
-	GtkTreeView *treeview;
-	GtkTreeViewColumn *column;
-	GtkWidget *widget;
-
-	g_debug( "%s: instance=%p, count_selected=%d", thisfn, ( void * ) instance, count_selected );
-	g_return_if_fail( NACT_IS_IFOLDERS_TAB( instance ));
-
-	if( st_initialized && !st_finalized ){
-
-		st_on_selection_change = TRUE;
-
-		reset_folders( instance );
-
-		g_object_get(
-				G_OBJECT( instance ),
-				TAB_UPDATABLE_PROP_EDITED_ACTION, &item,
-				TAB_UPDATABLE_PROP_EDITED_PROFILE, &profile,
-				TAB_UPDATABLE_PROP_EDITABLE, &editable,
-				NULL );
-
-		g_return_if_fail( !item || NA_IS_OBJECT_ITEM( item ));
-
-		tab_set_sensitive( instance );
+		g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
 
-		if( item && NA_IS_OBJECT_ACTION( item )){
-			setup_folders( instance );
-		}
-
-		treeview = GTK_TREE_VIEW( base_window_get_widget( BASE_WINDOW( instance ), "FoldersTreeView" ));
-		gtk_widget_set_sensitive( GTK_WIDGET( treeview ), profile != NULL );
-		column = gtk_tree_view_get_column( treeview, FOLDERS_PATH_COLUMN );
-		nact_gtk_utils_set_editable( GTK_OBJECT( column ), editable );
-
-		widget = base_window_get_widget( BASE_WINDOW( instance ), "AddFolderButton" );
-		gtk_widget_set_sensitive( widget, profile != NULL );
-		nact_gtk_utils_set_editable( GTK_OBJECT( widget ), editable );
-
-		widget = base_window_get_widget( BASE_WINDOW( instance ), "RemoveFolderButton" );
-		gtk_widget_set_sensitive( widget, profile != NULL );
-		nact_gtk_utils_set_editable( GTK_OBJECT( widget ), editable );
-
-		st_on_selection_change = FALSE;
+		nact_match_list_dispose( BASE_WINDOW( instance ), ITAB_NAME );
 	}
 }
 
 static void
-on_tab_updatable_enable_tab( NactIFoldersTab *instance, NAObjectItem *item )
-{
-	static const gchar *thisfn = "nact_ifolders_tab_on_tab_updatable_enable_tab";
-
-	if( st_initialized && !st_finalized ){
-
-		g_debug( "%s: instance=%p, item=%p", thisfn, ( void * ) instance, ( void * ) item );
-		g_return_if_fail( NACT_IS_IFOLDERS_TAB( instance ));
-
-		tab_set_sensitive( instance );
-	}
-}
-
-static gboolean
-tab_set_sensitive( NactIFoldersTab *instance )
-{
-	NAObjectAction *action;
-	NAObjectProfile *profile;
-	gboolean enable_tab;
-
-	g_object_get(
-			G_OBJECT( instance ),
-			TAB_UPDATABLE_PROP_EDITED_ACTION, &action,
-			TAB_UPDATABLE_PROP_EDITED_PROFILE, &profile,
-			NULL );
-
-	enable_tab = ( profile != NULL );
-	nact_main_tab_enable_page( NACT_MAIN_WINDOW( instance ), TAB_FOLDERS, enable_tab );
-
-	return( enable_tab );
-}
-
-static gboolean
-on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, NactIFoldersTab *instance )
-{
-	gboolean stop;
-	gboolean editable;
-
-	stop = FALSE;
-
-	g_object_get(
-			G_OBJECT( instance ),
-			TAB_UPDATABLE_PROP_EDITABLE, &editable,
-			NULL );
-
-	if( editable ){
-
-		if( event->keyval == GDK_F2 ){
-			inline_edition( instance );
-			stop = TRUE;
-		}
-
-		if( event->keyval == GDK_Insert || event->keyval == GDK_KP_Insert ){
-			insert_new_row( instance );
-			stop = TRUE;
-		}
-
-		if( event->keyval == GDK_Delete || event->keyval == GDK_KP_Delete ){
-			delete_row( instance );
-			stop = TRUE;
-		}
-	}
-
-	return( stop );
-}
-
-static void
-inline_edition( NactIFoldersTab *instance )
-{
-	GtkTreeView *listview;
-	GtkTreeSelection *selection;
-	GList *listrows;
-	GtkTreePath *path;
-	GtkTreeViewColumn *column;
-
-	listview = get_folders_treeview( instance );
-	selection = gtk_tree_view_get_selection( listview );
-	listrows = gtk_tree_selection_get_selected_rows( selection, NULL );
-
-	if( g_list_length( listrows ) == 1 ){
-		path = ( GtkTreePath * ) listrows->data;
-		column = gtk_tree_view_get_column( listview, FOLDERS_PATH_COLUMN );
-		gtk_tree_view_set_cursor( listview, path, column, TRUE );
-	}
-
-	g_list_foreach( listrows, ( GFunc ) gtk_tree_path_free, NULL );
-	g_list_free( listrows );
-}
-
-/*
- * the list is sorted on path: it is no worth to try to insert a row
- * before currently selected item...
- */
-static void
-insert_new_row( NactIFoldersTab *instance )
-{
-	GtkTreeView *listview;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	const gchar *folder_path = "/";
-	GtkTreePath *path;
-	GtkTreeViewColumn *column;
-
-	listview = get_folders_treeview( instance );
-	model = gtk_tree_view_get_model( listview );
-
-	gtk_list_store_append( GTK_LIST_STORE( model ), &iter );
-	gtk_list_store_set( GTK_LIST_STORE( model ), &iter, FOLDERS_PATH_COLUMN, folder_path, -1 );
-	add_path_to_folders( instance, folder_path );
-
-	path = gtk_tree_model_get_path( model, &iter );
-	column = gtk_tree_view_get_column( listview, FOLDERS_PATH_COLUMN );
-	gtk_tree_view_set_cursor( listview, path, column, TRUE );
-	gtk_tree_path_free( path );
-}
-
-static void
-delete_row( NactIFoldersTab *instance )
-{
-	GtkTreeView *listview;
-	GtkTreeModel *model;
-	GtkTreeSelection *selection;
-	GList *rows;
-	GtkTreePath *path;
-	GtkTreeIter iter;
-	gchar *folder_path;
-
-	listview = get_folders_treeview( instance );
-	model = gtk_tree_view_get_model( listview );
-	selection = gtk_tree_view_get_selection( listview );
-	rows = gtk_tree_selection_get_selected_rows( selection, NULL );
-
-	if( g_list_length( rows ) == 1 ){
-		path = ( GtkTreePath * ) rows->data;
-		gtk_tree_model_get_iter( model, &iter, path );
-		gtk_tree_model_get( model, &iter, FOLDERS_PATH_COLUMN, &folder_path, -1 );
-
-		gtk_list_store_remove( GTK_LIST_STORE( model ), &iter );
-		remove_path_from_folders( instance, folder_path );
-		g_free( folder_path );
-
-		if( gtk_tree_model_get_iter( model, &iter, path ) ||
-			gtk_tree_path_prev( path )){
-
-			gtk_tree_view_set_cursor( listview, path, NULL, FALSE );
-		}
-	}
-
-	g_list_foreach( rows, ( GFunc ) gtk_tree_path_free, NULL );
-	g_list_free( rows );
-}
-
-static void
-add_row( NactIFoldersTab *instance, GtkTreeView *listview, const gchar *path )
-{
-	GtkTreeModel *model;
-	GtkTreeIter row;
-
-	model = gtk_tree_view_get_model( listview );
-
-	gtk_list_store_append(
-			GTK_LIST_STORE( model ),
-			&row );
-
-	gtk_list_store_set(
-			GTK_LIST_STORE( model ),
-			&row,
-			FOLDERS_PATH_COLUMN, path,
-			-1 );
-}
-
-static void
-add_path_to_folders( NactIFoldersTab *instance, const gchar *path )
-{
-	NAObjectAction *action;
-	NAObjectProfile *edited;
-	GSList *folders;
-
-	g_object_get(
-			G_OBJECT( instance ),
-			TAB_UPDATABLE_PROP_EDITED_ACTION, &action,
-			TAB_UPDATABLE_PROP_EDITED_PROFILE, &edited,
-			NULL );
-
-	folders = na_object_get_folders( edited );
-	folders = g_slist_prepend( folders, ( gpointer ) g_strdup( path ));
-	na_object_set_folders( edited, folders );
-	na_core_utils_slist_free( folders );
-
-	g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
-}
-
-static GtkTreeView *
-get_folders_treeview( NactIFoldersTab *instance )
-{
-	GtkWidget *treeview;
-
-	treeview = base_window_get_widget( BASE_WINDOW( instance ), "FoldersTreeview" );
-	g_assert( GTK_IS_TREE_VIEW( treeview ));
-
-	return( GTK_TREE_VIEW( treeview ));
-}
-
-static void
-on_add_folder_clicked( GtkButton *button, NactIFoldersTab *instance )
+on_add_folder_clicked( GtkButton *button, MatchListStr *data )
 {
 #if 0
 	/* this is the code I sent to gtk-app-devel list
@@ -571,16 +253,15 @@ on_add_folder_clicked( GtkButton *button, NactIFoldersTab *instance )
 
 	gtk_widget_destroy( dialog );
 #endif
-	GtkWidget *dialog;
+
+	gchar *path;
 	GtkWindow *toplevel;
+	GtkWidget *dialog;
 	NactApplication *application;
 	NAUpdater *updater;
-	gchar *path;
-	GtkTreeView *listview;
 
 	path = NULL;
-	listview = get_folders_treeview( instance );
-	toplevel = base_window_get_toplevel( BASE_WINDOW( instance ));
+	toplevel = base_window_get_toplevel( data->window );
 
 	/* i18n: title of the FileChoose dialog when selecting an URI which
 	 * will be compare to Nautilus 'current_folder'
@@ -592,10 +273,10 @@ on_add_folder_clicked( GtkButton *button, NactIFoldersTab *instance )
 			GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
 			NULL );
 
-	application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( instance )));
+	application = NACT_APPLICATION( base_window_get_application( data->window ));
 	updater = nact_application_get_updater( application );
 
-	base_iprefs_position_named_window( BASE_WINDOW( instance ), GTK_WINDOW( dialog ), IPREFS_FOLDERS_DIALOG );
+	base_iprefs_position_named_window( data->window, GTK_WINDOW( dialog ), IPREFS_FOLDERS_DIALOG );
 
 	path = na_iprefs_read_string( NA_IPREFS( updater ), IPREFS_FOLDERS_PATH, "/" );
 	if( path && g_utf8_strlen( path, -1 )){
@@ -605,137 +286,38 @@ on_add_folder_clicked( GtkButton *button, NactIFoldersTab *instance )
 
 	if( gtk_dialog_run( GTK_DIALOG( dialog )) == GTK_RESPONSE_ACCEPT ){
 		path = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( dialog ));
-		nact_iprefs_write_string( BASE_WINDOW( instance ), IPREFS_FOLDERS_PATH, path );
-		add_row( instance, listview, path );
-		add_path_to_folders( instance, path );
+		nact_iprefs_write_string( data->window, IPREFS_FOLDERS_PATH, path );
+
+		nact_match_list_insert_row( data, path, FALSE, FALSE );
+
 		g_free( path );
 	}
 
-	base_iprefs_save_named_window_position( BASE_WINDOW( instance ), GTK_WINDOW( dialog ), IPREFS_FOLDERS_DIALOG );
+	base_iprefs_save_named_window_position( data->window, GTK_WINDOW( dialog ), IPREFS_FOLDERS_DIALOG );
 
 	gtk_widget_destroy( dialog );
 }
 
 static void
-on_folder_path_edited( GtkCellRendererText *renderer, const gchar *path, const gchar *text, NactIFoldersTab *instance )
-{
-	treeview_cell_edited( instance, path, text, FOLDERS_PATH_COLUMN, NULL );
-}
-
-static void
-on_folders_selection_changed( GtkTreeSelection *selection, NactIFoldersTab *instance )
-{
-	gboolean editable;
-	GtkWidget *button;
-
-	g_object_get(
-			G_OBJECT( instance ),
-			TAB_UPDATABLE_PROP_EDITABLE, &editable,
-			NULL );
-
-	if( editable ){
-		button = base_window_get_widget( BASE_WINDOW( instance ), "RemoveFolderButton");
-		gtk_widget_set_sensitive( button, gtk_tree_selection_count_selected_rows( selection ) > 0 );
-	}
-}
-
-static void
-on_remove_folder_clicked( GtkButton *button, NactIFoldersTab *instance )
+on_tab_updatable_selection_changed( NactIFoldersTab *instance, gint count_selected )
 {
-	delete_row( instance );
+	nact_match_list_on_selection_changed( BASE_WINDOW( instance ), ITAB_NAME, count_selected );
 }
 
 static void
-remove_path_from_folders( NactIFoldersTab *instance, const gchar *path )
-{
-	NAObjectProfile *edited;
-	GSList *folders;
-
-	g_object_get(
-			G_OBJECT( instance ),
-			TAB_UPDATABLE_PROP_EDITED_PROFILE, &edited,
-			NULL );
-
-	folders = na_object_get_folders( edited );
-	folders = na_core_utils_slist_remove_utf8( folders, path );
-	na_object_set_folders( edited, folders );
-
-	na_core_utils_slist_free( folders );
-
-	g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
-}
-
-static void
-reset_folders( NactIFoldersTab *instance )
+on_tab_updatable_enable_tab( NactIFoldersTab *instance, NAObjectItem *item )
 {
-	GtkTreeView *listview;
-	GtkTreeModel *model;
-
-	listview = get_folders_treeview( instance );
-	model = gtk_tree_view_get_model( listview );
-	gtk_list_store_clear( GTK_LIST_STORE( model ));
+	nact_match_list_on_enable_tab( BASE_WINDOW( instance ), ITAB_NAME, item );
 }
 
-static void
-setup_folders( NactIFoldersTab *instance )
+static GSList *
+get_folders( void *context )
 {
-	NAObjectProfile *edited;
-	GSList *folders, *is;
-	GtkTreeView *listview;
-
-	listview = get_folders_treeview( instance );
-
-	g_object_get(
-			G_OBJECT( instance ),
-			TAB_UPDATABLE_PROP_EDITED_PROFILE, &edited,
-			NULL );
-
-	if( edited ){
-		folders = na_object_get_folders( edited );
-		for( is = folders ; is ; is = is->next ){
-			add_row( instance, listview, ( const gchar * ) is->data );
-		}
-		na_core_utils_slist_free( folders );
-	}
+	return( na_object_get_folders( context ));
 }
 
 static void
-treeview_cell_edited( NactIFoldersTab *instance, const gchar *path_string, const gchar *text, gint column, gchar **old_text )
+set_folders( void *context, GSList *filters )
 {
-	static const gchar *thisfn = "nact_ifolders_tab_treeview_cell_edited";
-	GtkTreeView *listview;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	GtkTreePath *path;
-	NAObjectAction *action;
-	NAObjectProfile *edited;
-	gchar *previous_text;
-
-	g_debug( "%s: instance=%p, path_string=%s, text=%s, column=%d",
-			thisfn, ( void * ) instance, path_string, text, column );
-
-	listview = get_folders_treeview( instance );
-	model = gtk_tree_view_get_model( listview );
-	path = gtk_tree_path_new_from_string( path_string );
-	gtk_tree_model_get_iter( model, &iter, path );
-	gtk_tree_path_free( path );
-
-	gtk_tree_model_get( model, &iter, FOLDERS_PATH_COLUMN, &previous_text, -1 );
-
-	gtk_list_store_set( GTK_LIST_STORE( model ), &iter, column, text, -1 );
-
-	g_object_get(
-			G_OBJECT( instance ),
-			TAB_UPDATABLE_PROP_EDITED_ACTION, &action,
-			TAB_UPDATABLE_PROP_EDITED_PROFILE, &edited,
-			NULL );
-
-	na_object_replace_folder( edited, previous_text, text );
-
-	if( old_text ){
-		*old_text = g_strdup( previous_text );
-	}
-	g_free( previous_text );
-
-	g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
+	na_object_set_folders( context, filters );
 }
diff --git a/src/nact/nact-imimetypes-tab.c b/src/nact/nact-imimetypes-tab.c
index 337d491..92c14bb 100644
--- a/src/nact/nact-imimetypes-tab.c
+++ b/src/nact/nact-imimetypes-tab.c
@@ -51,15 +51,15 @@ struct NactIMimetypesTabInterfacePrivate {
 static gboolean st_initialized = FALSE;
 static gboolean st_finalized = FALSE;
 
-static GType    register_type( void );
-static void     interface_base_init( NactIMimetypesTabInterface *klass );
-static void     interface_base_finalize( NactIMimetypesTabInterface *klass );
+static GType   register_type( void );
+static void    interface_base_init( NactIMimetypesTabInterface *klass );
+static void    interface_base_finalize( NactIMimetypesTabInterface *klass );
 
-static void     on_tab_updatable_selection_changed( BaseWindow *window, gint count_selected );
-static void     on_tab_updatable_enable_tab( BaseWindow *window, NAObjectItem *item );
+static void    on_tab_updatable_selection_changed( BaseWindow *window, gint count_selected );
+static void    on_tab_updatable_enable_tab( BaseWindow *window, NAObjectItem *item );
 
-static GSList  *get_mimetypes( void *context );
-static void     set_mimetypes( void *context, GSList *filters );
+static GSList *get_mimetypes( void *context );
+static void    set_mimetypes( void *context, GSList *filters );
 
 GType
 nact_imimetypes_tab_get_type( void )
@@ -159,6 +159,7 @@ nact_imimetypes_tab_initial_load_toplevel( NactIMimetypesTab *instance )
 				list, add, remove,
 				( pget_filters ) get_mimetypes,
 				( pset_filters ) set_mimetypes,
+				NULL,
 				_( "Mimetype filter" ));
 	}
 }
diff --git a/src/nact/nact-match-list.c b/src/nact/nact-match-list.c
index b2072be..c652649 100644
--- a/src/nact/nact-match-list.c
+++ b/src/nact/nact-match-list.c
@@ -42,21 +42,6 @@
 #include "nact-main-tab.h"
 #include "nact-match-list.h"
 
-typedef struct {
-	BaseWindow  *window;
-	guint        tab_id;
-	GtkTreeView *listview;
-	GtkWidget   *addbutton;
-	GtkWidget   *removebutton;
-	pget_filters pget;
-	pset_filters pset;
-	gchar       *item_header;
-	gboolean     editable;
-	guint        sort_column;
-	guint        sort_order;
-}
-	MatchListStr;
-
 /* column ordering
  */
 enum {
@@ -79,6 +64,7 @@ static void     on_must_not_match_toggled( GtkCellRendererToggle *cell_renderer,
 static void     on_remove_filter_clicked( GtkButton *button, MatchListStr *data );
 static void     on_selection_changed( GtkTreeSelection *selection, MatchListStr *data );
 
+static void     add_filter( MatchListStr *data, const gchar *filter, const gchar *prefix );
 static void     delete_current_row( MatchListStr *data );
 static void     edit_inline( MatchListStr *data );
 static void     insert_new_row( MatchListStr *data );
@@ -96,6 +82,7 @@ static gboolean tab_set_sensitive( MatchListStr *data );
  * @removebutton: the #GtkButton widget.
  * @pget: a pointer to the function to get the list of filters.
  * @pset: a pointer to the function to set the list of filters.
+ * @pon_add: an optional pointer to a function which handles the Add button.
  * @item_header: the title of the item header.
  *
  * Creates the tree model.
@@ -104,7 +91,7 @@ void
 nact_match_list_create_model( BaseWindow *window,
 		const gchar *tab_name, guint tab_id,
 		GtkWidget *listview, GtkWidget *addbutton, GtkWidget *removebutton,
-		pget_filters pget, pset_filters pset,
+		pget_filters pget, pset_filters pset, pon_add_callback pon_add,
 		const gchar *item_header )
 {
 	MatchListStr *data;
@@ -121,6 +108,7 @@ nact_match_list_create_model( BaseWindow *window,
 	data->removebutton = removebutton;
 	data->pget = pget;
 	data->pset = pset;
+	data->pon_add = pon_add;
 	data->item_header = g_strdup( item_header );
 	data->editable = FALSE;
 	data->sort_column = 0;
@@ -244,7 +232,7 @@ nact_match_list_init_view( BaseWindow *window, const gchar *tab_name )
 			window,
 			G_OBJECT( data->addbutton ),
 			"clicked",
-			G_CALLBACK( on_add_filter_clicked ),
+			data->pon_add ? G_CALLBACK( data->pon_add ) : G_CALLBACK( on_add_filter_clicked ),
 			data );
 
 	base_window_signal_connect_with_data(
@@ -371,6 +359,48 @@ nact_match_list_on_enable_tab( BaseWindow *window, const gchar *tab_name, NAObje
 }
 
 /**
+ * nact_match_list_insert_row:
+ * @data: the #MatchListStr structure.
+ * @filter: the item to add.
+ * @match: whether the 'must match' column is checked.
+ * @not_match: whether the 'must not match' column is checked.
+ *
+ * Add a new row to the list view.
+ */
+void
+nact_match_list_insert_row( MatchListStr *data, const gchar *filter, gboolean match, gboolean not_match )
+{
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	GtkTreePath *path;
+	GtkTreeViewColumn *column;
+
+	g_return_if_fail( !( match && not_match ));
+
+	model = gtk_tree_view_get_model( data->listview );
+
+	gtk_list_store_insert_with_values( GTK_LIST_STORE( model ), &iter, 0,
+			/* i18n notes : new filter for a new row in a match/no matchlist */
+			ITEM_COLUMN, filter,
+			MUST_MATCH_COLUMN, match,
+			MUST_NOT_MATCH_COLUMN, not_match,
+			-1 );
+
+	path = gtk_tree_model_get_path( model, &iter );
+	column = gtk_tree_view_get_column( data->listview, ITEM_COLUMN );
+	gtk_tree_view_set_cursor( data->listview, path, column, TRUE );
+	gtk_tree_path_free( path );
+
+	if( match ){
+		add_filter( data, filter, "" );
+	}
+
+	if( not_match ){
+		add_filter( data, filter, "!" );
+	}
+}
+
+/**
  * nact_match_list_dispose:
  * @window: the #BaseWindow window which contains the view.
  * @tab_name: a string constant which identifies this page.
@@ -636,6 +666,34 @@ on_selection_changed( GtkTreeSelection *selection, MatchListStr *data )
 }
 
 static void
+add_filter( MatchListStr *data, const gchar *filter, const gchar *prefix )
+{
+	NAObjectItem *item;
+	NAObjectProfile *profile;
+	NAIContext *context;
+	GSList *filters;
+	gchar *to_add;
+
+	g_object_get(
+			G_OBJECT( data->window ),
+			TAB_UPDATABLE_PROP_EDITED_ACTION, &item,
+			TAB_UPDATABLE_PROP_EDITED_PROFILE, &profile,
+			NULL );
+
+	context = ( profile ? NA_ICONTEXT( profile ) : ( NAIContext * ) item );
+
+	if( context ){
+		filters = ( *data->pget )( context );
+		to_add = g_strdup_printf( "%s%s", prefix, filter );
+		filters = g_slist_prepend( filters, to_add );
+		( *data->pset )( context, filters );
+		na_core_utils_slist_free( filters );
+
+		g_signal_emit_by_name( G_OBJECT( data->window ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, context, FALSE );
+	}
+}
+
+static void
 delete_current_row( MatchListStr *data )
 {
 	GtkTreeSelection *selection;
@@ -719,24 +777,7 @@ edit_inline( MatchListStr *data )
 static void
 insert_new_row( MatchListStr *data )
 {
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	GtkTreePath *path;
-	GtkTreeViewColumn *column;
-
-	model = gtk_tree_view_get_model( data->listview );
-
-	gtk_list_store_insert_with_values( GTK_LIST_STORE( model ), &iter, 0,
-			/* i18n notes : new filter for a new row in a match/no matchlist */
-			ITEM_COLUMN, _( "new-filter" ),
-			MUST_MATCH_COLUMN, FALSE,
-			MUST_NOT_MATCH_COLUMN, FALSE,
-			-1 );
-
-	path = gtk_tree_model_get_path( model, &iter );
-	column = gtk_tree_view_get_column( data->listview, ITEM_COLUMN );
-	gtk_tree_view_set_cursor( data->listview, path, column, TRUE );
-	gtk_tree_path_free( path );
+	nact_match_list_insert_row( data, _( "new-filter" ), FALSE, FALSE );
 }
 
 static void
diff --git a/src/nact/nact-match-list.h b/src/nact/nact-match-list.h
index ef7e007..b1d18f4 100644
--- a/src/nact/nact-match-list.h
+++ b/src/nact/nact-match-list.h
@@ -43,11 +43,28 @@ G_BEGIN_DECLS
 
 typedef GSList * ( *pget_filters )( void * );
 typedef void     ( *pset_filters )( void *, GSList * );
+typedef void     ( *pon_add_callback )( GtkButton *button, void *user_data );
+
+typedef struct {
+	BaseWindow      *window;
+	guint            tab_id;
+	GtkTreeView     *listview;
+	GtkWidget       *addbutton;
+	GtkWidget       *removebutton;
+	pget_filters     pget;
+	pset_filters     pset;
+	pon_add_callback pon_add;
+	gchar           *item_header;
+	gboolean         editable;
+	guint            sort_column;
+	guint            sort_order;
+}
+	MatchListStr;
 
 void  nact_match_list_create_model        ( BaseWindow *window, const gchar *tab_name,
 		guint tab_id,
 		GtkWidget *listview, GtkWidget *addbutton, GtkWidget *removebutton,
-		pget_filters pget, pset_filters pset,
+		pget_filters pget, pset_filters pset, pon_add_callback pon_add,
 		const gchar *item_header );
 
 void  nact_match_list_init_view           ( BaseWindow *window, const gchar *tab_name );
@@ -58,6 +75,8 @@ void  nact_match_list_on_selection_changed( BaseWindow *window, const gchar *tab
 void  nact_match_list_on_enable_tab       ( BaseWindow *window, const gchar *tab_name,
 		NAObjectItem *item );
 
+void  nact_match_list_insert_row( MatchListStr *data, const gchar *filter, gboolean match, gboolean not_match );
+
 void  nact_match_list_dispose             ( BaseWindow *window, const gchar *tab_name );
 
 G_END_DECLS



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]