[nautilus-actions] NactMatchList connects to base signals (and acts as a pseudo-interface)
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] NactMatchList connects to base signals (and acts as a pseudo-interface)
- Date: Tue, 17 Jan 2012 21:54:34 +0000 (UTC)
commit 36e295ac120dfab6728a1fcca0ce808bbed2894f
Author: Pierre Wieser <pwieser trychlos org>
Date: Tue Jan 17 21:56:24 2012 +0100
NactMatchList connects to base signals (and acts as a pseudo-interface)
ChangeLog | 16 ++
src/nact/nact-ibasenames-tab.c | 24 +--
src/nact/nact-icapabilities-tab.c | 25 ++--
src/nact/nact-ifolders-tab.c | 23 +--
src/nact/nact-imimetypes-tab.c | 21 +--
src/nact/nact-ischemes-tab.c | 21 +--
src/nact/nact-main-tab.h | 5 +-
src/nact/nact-match-list.c | 328 +++++++++++++++++++++++--------------
src/nact/nact-match-list.h | 70 ++++-----
9 files changed, 293 insertions(+), 240 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7a79792..0460b72 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2012-01-17 Pierre Wieser <pwieser trychlos org>
+ nact_match_list functions connect to base signals (and acts as a
+ pseudo-interface).
+
+ * src/nact/nact-match-list.c:
+ * src/nact/nact-match-list.h
+ (nact_match_list_create_model): Renamed as nact_match_list_init_with_args().
+ (nact_match_list_init_view, nact_match_list_on_selection_changed,
+ nact_match_list_dispose): Removed functions.
+
+ * src/nact/nact-ibasenames-tab.c:
+ * src/nact/nact-icapabilities-tab.c:
+ * src/nact/nact-ifolders-tab.c:
+ * src/nact/nact-imimetypes-tab.c:
+ * src/nact/nact-ischemes-tab.c:
+ * src/nact/nact-main-tab.h: Updated accordingly.
+
* src/core/na-pivot.c:
* src/core/na-settings.h:
* src/nact/nact-export-ask.c:
diff --git a/src/nact/nact-ibasenames-tab.c b/src/nact/nact-ibasenames-tab.c
index f5f8c00..65d1b1d 100644
--- a/src/nact/nact-ibasenames-tab.c
+++ b/src/nact/nact-ibasenames-tab.c
@@ -194,7 +194,6 @@ static void
on_base_initialize_gtk( NactIBasenamesTab *instance, GtkWindow *toplevel, void *user_data )
{
static const gchar *thisfn = "nact_ibasenames_tab_on_base_initialize_gtk";
- GtkWidget *list, *add, *remove;
g_return_if_fail( NACT_IS_IBASENAMES_TAB( instance ));
@@ -204,20 +203,20 @@ on_base_initialize_gtk( NactIBasenamesTab *instance, GtkWindow *toplevel, void *
( void * ) toplevel,
( void * ) user_data );
- list = base_window_get_widget( BASE_WINDOW( instance ), "BasenamesTreeView" );
- add = base_window_get_widget( BASE_WINDOW( instance ), "AddBasenameButton" );
- remove = base_window_get_widget( BASE_WINDOW( instance ), "RemoveBasenameButton" );
-
- nact_match_list_create_model(
+ nact_match_list_init_with_args(
BASE_WINDOW( instance ),
ITAB_NAME,
TAB_BASENAMES,
- list, add, remove,
+ base_window_get_widget( BASE_WINDOW( instance ), "BasenamesTreeView" ),
+ base_window_get_widget( BASE_WINDOW( instance ), "AddBasenameButton" ),
+ base_window_get_widget( BASE_WINDOW( instance ), "RemoveBasenameButton" ),
( pget_filters ) get_basenames,
( pset_filters ) set_basenames,
NULL,
+ NULL,
MATCH_LIST_MUST_MATCH_ONE_OF,
- _( "Basename filter" ), TRUE );
+ _( "Basename filter" ),
+ TRUE );
}
/*
@@ -252,22 +251,17 @@ on_base_initialize_window( NactIBasenamesTab *instance, void *user_data )
G_OBJECT( button ),
"toggled",
G_CALLBACK( on_matchcase_toggled ));
-
- nact_match_list_init_view( BASE_WINDOW( instance ), ITAB_NAME );
}
static void
on_main_selection_changed( BaseWindow *window, GList *selected_items, gpointer user_data )
{
- guint count_selected;
NAIContext *context;
gboolean editable;
GtkToggleButton *matchcase_button;
gboolean matchcase;
IBasenamesData *data;
- count_selected = g_list_length( selected_items );
-
g_object_get( G_OBJECT( window ),
MAIN_PROP_CONTEXT, &context, MAIN_PROP_EDITABLE, &editable,
NULL );
@@ -276,8 +270,6 @@ on_main_selection_changed( BaseWindow *window, GList *selected_items, gpointer u
data->on_selection_change = TRUE;
- nact_match_list_on_selection_changed( window, ITAB_NAME, count_selected );
-
matchcase_button = GTK_TOGGLE_BUTTON( base_window_get_widget( window, "BasenamesMatchcaseButton" ));
matchcase = context ? na_object_get_matchcase( context ) : FALSE;
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( matchcase_button ), matchcase );
@@ -354,7 +346,5 @@ on_instance_finalized( gpointer user_data, NactIBasenamesTab *instance )
data = get_ibasenames_data( instance );
- nact_match_list_dispose( BASE_WINDOW( instance ), ITAB_NAME );
-
g_free( data );
}
diff --git a/src/nact/nact-icapabilities-tab.c b/src/nact/nact-icapabilities-tab.c
index e2ca817..7c6a6c1 100644
--- a/src/nact/nact-icapabilities-tab.c
+++ b/src/nact/nact-icapabilities-tab.c
@@ -173,7 +173,6 @@ static void
on_base_initialize_gtk( NactICapabilitiesTab *instance, GtkWindow *toplevel, void *user_data )
{
static const gchar *thisfn = "nact_icapabilities_tab_on_base_initialize_gtk";
- GtkWidget *list, *add, *remove;
g_return_if_fail( NACT_IS_ICAPABILITIES_TAB( instance ));
@@ -183,18 +182,20 @@ on_base_initialize_gtk( NactICapabilitiesTab *instance, GtkWindow *toplevel, voi
( void * ) toplevel,
( void * ) user_data );
- list = base_window_get_widget( BASE_WINDOW( instance ), "CapabilitiesTreeView" );
- add = base_window_get_widget( BASE_WINDOW( instance ), "AddCapabilityButton" );
- remove = base_window_get_widget( BASE_WINDOW( instance ), "RemoveCapabilityButton" );
-
- nact_match_list_create_model( BASE_WINDOW( instance ),
- ITAB_NAME, TAB_CAPABILITIES,
- list, add, remove,
+ nact_match_list_init_with_args(
+ BASE_WINDOW( instance ),
+ ITAB_NAME,
+ TAB_CAPABILITIES,
+ base_window_get_widget( BASE_WINDOW( instance ), "CapabilitiesTreeView" ),
+ base_window_get_widget( BASE_WINDOW( instance ), "AddCapabilityButton" ),
+ base_window_get_widget( BASE_WINDOW( instance ), "RemoveCapabilityButton" ),
( pget_filters ) get_capabilities,
( pset_filters ) set_capabilities,
( pon_add_cb ) on_add_clicked,
+ NULL,
MATCH_LIST_MUST_MATCH_ALL_OF,
- _( "Capability filter" ), FALSE );
+ _( "Capability filter" ),
+ FALSE );
}
static void
@@ -209,8 +210,6 @@ on_base_initialize_window( NactICapabilitiesTab *instance, void *user_data )
( void * ) instance, G_OBJECT_TYPE_NAME( instance ),
( void * ) user_data );
- nact_match_list_init_view( BASE_WINDOW( instance ), ITAB_NAME );
-
base_window_signal_connect(
BASE_WINDOW( instance ),
G_OBJECT( instance ),
@@ -221,7 +220,7 @@ on_base_initialize_window( NactICapabilitiesTab *instance, void *user_data )
static void
on_main_selection_changed( NactICapabilitiesTab *instance, GList *selected_items, gpointer user_data )
{
- nact_match_list_on_selection_changed( BASE_WINDOW( instance ), ITAB_NAME, g_list_length( selected_items ));
+ /* nothing to do here */
}
static void
@@ -264,6 +263,4 @@ on_instance_finalized( gpointer user_data, NactICapabilitiesTab *instance )
static const gchar *thisfn = "nact_icapabilities_tab_on_instance_finalized";
g_debug( "%s: instance=%p, user_data=%p", thisfn, ( void * ) instance, ( void * ) user_data );
-
- nact_match_list_dispose( BASE_WINDOW( instance ), ITAB_NAME );
}
diff --git a/src/nact/nact-ifolders-tab.c b/src/nact/nact-ifolders-tab.c
index aa166c8..070f0cd 100644
--- a/src/nact/nact-ifolders-tab.c
+++ b/src/nact/nact-ifolders-tab.c
@@ -178,7 +178,6 @@ static void
on_base_initialize_gtk( NactIFoldersTab *instance, GtkWindow *toplevel, void *user_data )
{
static const gchar *thisfn = "nact_ifolders_tab_on_base_initialize_gtk";
- GtkWidget *list, *add, *remove;
g_return_if_fail( NACT_IS_IFOLDERS_TAB( instance ));
@@ -188,20 +187,20 @@ on_base_initialize_gtk( NactIFoldersTab *instance, GtkWindow *toplevel, void *us
( void * ) toplevel,
( void * ) user_data );
- 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" );
-
- nact_match_list_create_model(
+ nact_match_list_init_with_args(
BASE_WINDOW( instance ),
ITAB_NAME,
TAB_FOLDERS,
- list, add, remove,
+ base_window_get_widget( BASE_WINDOW( instance ), "FoldersTreeView" ),
+ base_window_get_widget( BASE_WINDOW( instance ), "AddFolderButton" ),
+ base_window_get_widget( BASE_WINDOW( instance ), "RemoveFolderButton" ),
( pget_filters ) get_folders,
( pset_filters ) set_folders,
NULL,
+ NULL,
MATCH_LIST_MUST_MATCH_ONE_OF,
- _( "Folder filter" ), TRUE );
+ _( "Folder filter" ),
+ TRUE );
}
static void
@@ -223,8 +222,6 @@ on_base_initialize_window( NactIFoldersTab *instance, void *user_data )
MAIN_SIGNAL_SELECTION_CHANGED,
G_CALLBACK( on_main_selection_changed ));
- nact_match_list_init_view( BASE_WINDOW( instance ), ITAB_NAME );
-
button = base_window_get_widget( BASE_WINDOW( instance ), "FolderBrowseButton" );
base_window_signal_connect(
BASE_WINDOW( instance ),
@@ -236,14 +233,10 @@ on_base_initialize_window( NactIFoldersTab *instance, void *user_data )
static void
on_main_selection_changed( NactIFoldersTab *instance, GList *selected_items, gpointer user_data )
{
- guint count_selected;
NAIContext *context;
gboolean editable;
GtkWidget *button;
- count_selected = g_list_length( selected_items );
- nact_match_list_on_selection_changed( BASE_WINDOW( instance ), ITAB_NAME, count_selected );
-
g_object_get( G_OBJECT( instance ),
MAIN_PROP_CONTEXT, &context, MAIN_PROP_EDITABLE, &editable,
NULL );
@@ -339,6 +332,4 @@ on_instance_finalized( gpointer user_data, NactIFoldersTab *instance )
static const gchar *thisfn = "nact_ifolders_tab_on_instance_finalized";
g_debug( "%s: instance=%p, user_data=%p", thisfn, ( void * ) instance, ( void * ) user_data );
-
- nact_match_list_dispose( BASE_WINDOW( instance ), ITAB_NAME );
}
diff --git a/src/nact/nact-imimetypes-tab.c b/src/nact/nact-imimetypes-tab.c
index 25cc3d6..5e56228 100644
--- a/src/nact/nact-imimetypes-tab.c
+++ b/src/nact/nact-imimetypes-tab.c
@@ -178,7 +178,6 @@ static void
on_base_initialize_gtk( NactIMimetypesTab *instance, GtkWindow *toplevel, void *user_data )
{
static const gchar *thisfn = "nact_imimetypes_tab_on_base_initialize_gtk";
- GtkWidget *list, *add, *remove;
g_return_if_fail( NACT_IS_IMIMETYPES_TAB( instance ));
@@ -188,20 +187,20 @@ on_base_initialize_gtk( NactIMimetypesTab *instance, GtkWindow *toplevel, void *
( void * ) toplevel,
( void * ) user_data );
- list = base_window_get_widget( BASE_WINDOW( instance ), "MimetypesTreeView" );
- add = base_window_get_widget( BASE_WINDOW( instance ), "AddMimetypeButton" );
- remove = base_window_get_widget( BASE_WINDOW( instance ), "RemoveMimetypeButton" );
-
- nact_match_list_create_model(
+ nact_match_list_init_with_args(
BASE_WINDOW( instance ),
ITAB_NAME,
TAB_MIMETYPES,
- list, add, remove,
+ base_window_get_widget( BASE_WINDOW( instance ), "MimetypesTreeView" ),
+ base_window_get_widget( BASE_WINDOW( instance ), "AddMimetypeButton" ),
+ base_window_get_widget( BASE_WINDOW( instance ), "RemoveMimetypeButton" ),
( pget_filters ) get_mimetypes,
( pset_filters ) set_mimetypes,
NULL,
+ NULL,
MATCH_LIST_MUST_MATCH_ONE_OF,
- _( "Mimetype filter" ), TRUE );
+ _( "Mimetype filter" ),
+ TRUE );
}
/*
@@ -228,14 +227,12 @@ on_base_initialize_window( NactIMimetypesTab *instance, void *user_data )
G_OBJECT( instance ),
MAIN_SIGNAL_SELECTION_CHANGED,
G_CALLBACK( on_main_selection_changed ));
-
- nact_match_list_init_view( BASE_WINDOW( instance ), ITAB_NAME );
}
static void
on_main_selection_changed( BaseWindow *window, GList *selected_items, gpointer user_data )
{
- nact_match_list_on_selection_changed( window, ITAB_NAME, g_list_length( selected_items ));
+ /* nothing to do here */
}
static GSList *
@@ -256,6 +253,4 @@ on_instance_finalized( gpointer user_data, NactIMimetypesTab *instance )
static const gchar *thisfn = "nact_imimetypes_tab_on_instance_finalized";
g_debug( "%s: instance=%p, user_data=%p", thisfn, ( void * ) instance, ( void * ) user_data );
-
- nact_match_list_dispose( BASE_WINDOW( instance ), ITAB_NAME );
}
diff --git a/src/nact/nact-ischemes-tab.c b/src/nact/nact-ischemes-tab.c
index d813a0c..91bb4bb 100644
--- a/src/nact/nact-ischemes-tab.c
+++ b/src/nact/nact-ischemes-tab.c
@@ -176,7 +176,6 @@ static void
on_base_initialize_gtk( NactISchemesTab *instance, GtkWindow *toplevel, void *user_data )
{
static const gchar *thisfn = "nact_ischemes_tab_on_base_initialize_gtk";
- GtkWidget *list, *add, *remove;
g_return_if_fail( NACT_IS_ISCHEMES_TAB( instance ));
@@ -186,20 +185,20 @@ on_base_initialize_gtk( NactISchemesTab *instance, GtkWindow *toplevel, void *us
( void * ) toplevel,
( void * ) user_data );
- list = base_window_get_widget( BASE_WINDOW( instance ), "SchemesTreeView" );
- add = base_window_get_widget( BASE_WINDOW( instance ), "AddSchemeButton" );
- remove = base_window_get_widget( BASE_WINDOW( instance ), "RemoveSchemeButton" );
-
- nact_match_list_create_model(
+ nact_match_list_init_with_args(
BASE_WINDOW( instance ),
ITAB_NAME,
TAB_SCHEMES,
- list, add, remove,
+ base_window_get_widget( BASE_WINDOW( instance ), "SchemesTreeView" ),
+ base_window_get_widget( BASE_WINDOW( instance ), "AddSchemeButton" ),
+ base_window_get_widget( BASE_WINDOW( instance ), "RemoveSchemeButton" ),
( pget_filters ) get_schemes,
( pset_filters ) set_schemes,
NULL,
+ NULL,
MATCH_LIST_MUST_MATCH_ONE_OF,
- _( "Scheme filter" ), TRUE );
+ _( "Scheme filter" ),
+ TRUE );
}
static void
@@ -221,8 +220,6 @@ on_base_initialize_window( NactISchemesTab *instance, void *user_data )
MAIN_SIGNAL_SELECTION_CHANGED,
G_CALLBACK( on_main_selection_changed ));
- nact_match_list_init_view( BASE_WINDOW( instance ), ITAB_NAME );
-
button = base_window_get_widget( BASE_WINDOW( instance ), "AddFromDefaultButton" );
base_window_signal_connect(
BASE_WINDOW( instance ),
@@ -238,8 +235,6 @@ on_main_selection_changed( BaseWindow *window, GList *selected_items, gpointer u
gboolean editable;
GtkWidget *button;
- nact_match_list_on_selection_changed( window, ITAB_NAME, g_list_length( selected_items ));
-
g_object_get( G_OBJECT( window ),
MAIN_PROP_CONTEXT, &context, MAIN_PROP_EDITABLE, &editable,
NULL );
@@ -286,6 +281,4 @@ on_instance_finalized( gpointer user_data, NactISchemesTab *instance )
static const gchar *thisfn = "nact_ischemes_tab_on_instance_finalized";
g_debug( "%s: instance=%p, user_data=%p", thisfn, ( void * ) instance, ( void * ) user_data );
-
- nact_match_list_dispose( BASE_WINDOW( instance ), ITAB_NAME );
}
diff --git a/src/nact/nact-main-tab.h b/src/nact/nact-main-tab.h
index af23387..69cf740 100644
--- a/src/nact/nact-main-tab.h
+++ b/src/nact/nact-main-tab.h
@@ -51,7 +51,6 @@
/* notebook tabs
*/
-
enum {
TAB_ACTION = 0,
TAB_COMMAND,
@@ -65,8 +64,8 @@ enum {
TAB_PROPERTIES
};
-void nact_main_tab_enable_page ( NactMainWindow *window, gint page, gboolean enabled );
-gboolean nact_main_tab_is_page_enabled( NactMainWindow *window, gint page );
+void nact_main_tab_enable_page ( NactMainWindow *window, gint page, gboolean enabled );
+gboolean nact_main_tab_is_page_enabled( NactMainWindow *window, gint page );
G_END_DECLS
diff --git a/src/nact/nact-match-list.c b/src/nact/nact-match-list.c
index 580a8a1..31d2dbf 100644
--- a/src/nact/nact-match-list.c
+++ b/src/nact/nact-match-list.c
@@ -58,6 +58,31 @@ typedef struct {
}
ColumnHeaderStruct;
+/* internal data set against the instance,
+ * addressed with the tab name
+ */
+typedef struct {
+ BaseWindow *window;
+ gchar *tab_name;
+ guint tab_id;
+ GtkTreeView *listview;
+ GtkWidget *addbutton;
+ GtkWidget *removebutton;
+ pget_filters pget;
+ pset_filters pset;
+ pon_add_cb pon_add;
+ pon_remove_cb pon_remove;
+ guint match_header;
+ gchar *item_header;
+ gboolean editable_filter;
+ /* dynamic data */
+ gboolean on_selection_change;
+ gboolean editable_item;
+ guint sort_column;
+ guint sort_order;
+}
+ MatchListData;
+
/* i18n: label of the header of the column which let the user select a positive filter
*/
static ColumnHeaderStruct st_match_headers[] = {
@@ -66,37 +91,42 @@ static ColumnHeaderStruct st_match_headers[] = {
{ 0 }
};
-static gboolean st_on_selection_change = FALSE;
-
-static void on_add_filter_clicked( GtkButton *button, MatchListStr *data );
-static void on_filter_clicked( GtkTreeViewColumn *treeviewcolumn, MatchListStr *data );
-static void on_filter_edited( GtkCellRendererText *renderer, const gchar *path, const gchar *text, MatchListStr *data );
-static gboolean on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, MatchListStr *data );
-static void on_must_match_clicked( GtkTreeViewColumn *treeviewcolumn, MatchListStr *data );
-static void on_must_match_toggled( GtkCellRendererToggle *cell_renderer, gchar *path, MatchListStr *data );
-static void on_must_not_match_clicked( GtkTreeViewColumn *treeviewcolumn, MatchListStr *data );
-static void on_must_not_match_toggled( GtkCellRendererToggle *cell_renderer, gchar *path, MatchListStr *data );
-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 guint count_filters( const gchar *filter, MatchListStr *data );
-static void delete_current_row( MatchListStr *data );
+static void initialize_pseudo_iface( MatchListData *data );
+static void create_tree_model( MatchListData *data );
+static void on_base_initialize_window( BaseWindow *window, MatchListData *data );
+static void on_main_selection_changed( BaseWindow *window, GList *selected_items, MatchListData *data );
+
+static void on_add_filter_clicked( GtkButton *button, MatchListData *data );
+static void on_filter_clicked( GtkTreeViewColumn *treeviewcolumn, MatchListData *data );
+static void on_filter_edited( GtkCellRendererText *renderer, const gchar *path, const gchar *text, MatchListData *data );
+static gboolean on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, MatchListData *data );
+static void on_must_match_clicked( GtkTreeViewColumn *treeviewcolumn, MatchListData *data );
+static void on_must_match_toggled( GtkCellRendererToggle *cell_renderer, gchar *path, MatchListData *data );
+static void on_must_not_match_clicked( GtkTreeViewColumn *treeviewcolumn, MatchListData *data );
+static void on_must_not_match_toggled( GtkCellRendererToggle *cell_renderer, gchar *path, MatchListData *data );
+static void on_remove_filter_clicked( GtkButton *button, MatchListData *data );
+static void on_selection_changed( GtkTreeSelection *selection, MatchListData *data );
+
+static void add_filter( MatchListData *data, const gchar *filter, const gchar *prefix );
+static guint count_filters( const gchar *filter, MatchListData *data );
+static void delete_current_row( MatchListData *data );
static void delete_row_at_path( GtkTreeView *treeview, GtkTreeModel *model, GtkTreePath *path );
-static void dump_current_rows( MatchListStr *data );
-static void edit_inline( MatchListStr *data );
-static gchar *get_filter_from_path( const gchar *path_str, MatchListStr *data );
+static void dump_current_rows( MatchListData *data );
+static void edit_inline( MatchListData *data );
+static gchar *get_filter_from_path( const gchar *path_str, MatchListData *data );
static const gchar *get_must_match_header( guint id );
static gboolean get_rows_iter( GtkTreeModel *model, GtkTreePath *path, GtkTreeIter* iter, GSList **filters );
-static void insert_new_row( MatchListStr *data );
-static void insert_new_row_data( MatchListStr *data, const gchar *filter, gboolean match, gboolean no_match );
+static void insert_new_row( MatchListData *data );
+static void insert_new_row_data( MatchListData *data, const gchar *filter, gboolean match, gboolean no_match );
static void iter_for_setup( gchar *filter, GtkTreeModel *model );
-static gchar *search_for_unique_label( const gchar *propal, MatchListStr *data );
-static void set_match_status( const gchar *path_str, gboolean must_match, gboolean must_not_match, MatchListStr *data );
-static void sort_on_column( GtkTreeViewColumn *treeviewcolumn, MatchListStr *data, guint colid );
+static gchar *search_for_unique_label( const gchar *propal, MatchListData *data );
+static void set_match_status( const gchar *path_str, gboolean must_match, gboolean must_not_match, MatchListData *data );
+static void sort_on_column( GtkTreeViewColumn *treeviewcolumn, MatchListData *data, guint colid );
+
+static void on_instance_finalized( MatchListData *data, BaseWindow *window );
/**
- * nact_match_list_create_model:
+ * nact_match_list_init_with_args:
* @window: the #BaseWindow window which contains the view.
* @tab_name: a string constant which identifies this page.
* @tab_id: our id for this page.
@@ -106,27 +136,42 @@ static void sort_on_column( GtkTreeViewColumn *treeviewcolumn, MatchList
* @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.
+ * @pon_remove: an optional pointer to a function which handles the Remove button.
* @item_header: the title of the item header.
*
- * Creates the tree model.
+ * Initialize this pseudo-interface, and creates the tree model.
+ *
+ * This function can only be called when (and so should be called immediately
+ * after) the Gtk toplevel has been first initialized. This is because we need
+ * here pointers to GtkTreeView and GtkButton widgets.
*/
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, pon_add_cb pon_add,
- guint match_header,
- const gchar *item_header,
- gboolean editable_filter )
-{
- MatchListStr *data;
- GtkListStore *model;
- GtkCellRenderer *text_cell, *radio_cell;
- GtkTreeViewColumn *column;
- GtkTreeSelection *selection;
+nact_match_list_init_with_args( BaseWindow *window, const gchar *tab_name,
+ guint tab_id,
+ GtkWidget *listview,
+ GtkWidget *addbutton,
+ GtkWidget *removebutton,
+ pget_filters pget,
+ pset_filters pset,
+ pon_add_cb pon_add,
+ pon_remove_cb pon_remove,
+ guint match_header,
+ const gchar *item_header,
+ gboolean editable_filter )
+{
+ static const gchar *thisfn = "nact_match_list_init_with_args";
+ MatchListData *data;
+
+ g_return_if_fail( BASE_IS_WINDOW( window ));
+
+ g_debug( "%s: window=%p, tab_name=%s", thisfn, ( void * ) window, tab_name );
+
+ data = g_new0( MatchListData, 1 );
- data = g_new0( MatchListStr, 1 );
+ /* parameters
+ */
data->window = window;
+ data->tab_name = g_strdup( tab_name );
data->tab_id = tab_id;
data->listview = GTK_TREE_VIEW( listview );
data->addbutton = addbutton;
@@ -134,14 +179,52 @@ nact_match_list_create_model( BaseWindow *window,
data->pget = pget;
data->pset = pset;
data->pon_add = pon_add;
+ data->pon_remove = pon_remove;
data->match_header = match_header;
data->item_header = g_strdup( item_header );
data->editable_filter = editable_filter;
+
+ /* dynamic data
+ */
+ data->on_selection_change = FALSE;
data->editable_item = FALSE;
data->sort_column = 0;
data->sort_order = 0;
+
g_object_set_data( G_OBJECT( window ), tab_name, data );
+ initialize_pseudo_iface( data );
+ create_tree_model( data );
+}
+
+static void
+initialize_pseudo_iface( MatchListData *data )
+{
+ base_window_signal_connect_with_data(
+ data->window,
+ G_OBJECT( data->window ),
+ BASE_SIGNAL_INITIALIZE_WINDOW,
+ G_CALLBACK( on_base_initialize_window ),
+ data );
+
+ base_window_signal_connect_with_data(
+ data->window,
+ G_OBJECT( data->window ),
+ MAIN_SIGNAL_SELECTION_CHANGED,
+ G_CALLBACK( on_main_selection_changed ),
+ data );
+
+ g_object_weak_ref( G_OBJECT( data->window ), ( GWeakNotify ) on_instance_finalized, data );
+}
+
+static void
+create_tree_model( MatchListData *data )
+{
+ GtkListStore *model;
+ GtkCellRenderer *text_cell, *radio_cell;
+ GtkTreeViewColumn *column;
+ GtkTreeSelection *selection;
+
model = gtk_list_store_new( N_COLUMN, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN );
gtk_tree_view_set_model( data->listview, GTK_TREE_MODEL( model ));
g_object_unref( model );
@@ -157,7 +240,7 @@ nact_match_list_create_model( BaseWindow *window,
radio_cell = gtk_cell_renderer_toggle_new();
gtk_cell_renderer_toggle_set_radio( GTK_CELL_RENDERER_TOGGLE( radio_cell ), TRUE );
column = gtk_tree_view_column_new_with_attributes(
- get_must_match_header( match_header ),
+ get_must_match_header( data->match_header ),
radio_cell,
"active", MUST_MATCH_COLUMN,
NULL );
@@ -185,23 +268,17 @@ nact_match_list_create_model( BaseWindow *window,
gtk_tree_selection_set_mode( selection, GTK_SELECTION_BROWSE );
}
-/**
- * nact_match_list_init_view:
- * @window: the #BaseWindow window which contains the view.
- * @tab_name: a string constant which identifies this page.
- *
- * Initializes the tab widget at each time the widget will be displayed.
+/*
+ * Initializes the tab widget at each time the widget will be displayed.
* Connect signals.
*/
-void
-nact_match_list_init_view( BaseWindow *window, const gchar *tab_name )
+static void
+on_base_initialize_window( BaseWindow *window, MatchListData *data )
{
- MatchListStr *data;
GtkTreeViewColumn *column;
GList *renderers;
GtkTreeModel *model;
- data = ( MatchListStr * ) g_object_get_data( G_OBJECT( window ), tab_name );
g_return_if_fail( data != NULL );
column = gtk_tree_view_get_column( data->listview, ITEM_COLUMN );
@@ -267,12 +344,20 @@ nact_match_list_init_view( BaseWindow *window, const gchar *tab_name )
data );
}
- base_window_signal_connect_with_data(
- window,
- G_OBJECT( data->removebutton ),
- "clicked",
- G_CALLBACK( on_remove_filter_clicked ),
- data );
+ if( data->pon_remove ){
+ base_window_signal_connect(
+ window,
+ G_OBJECT( data->removebutton ),
+ "clicked",
+ G_CALLBACK( data->pon_remove ));
+ } else {
+ base_window_signal_connect_with_data(
+ window,
+ G_OBJECT( data->removebutton ),
+ "clicked",
+ G_CALLBACK( on_remove_filter_clicked ),
+ data );
+ }
base_window_signal_connect_with_data(
window,
@@ -297,12 +382,7 @@ nact_match_list_init_view( BaseWindow *window, const gchar *tab_name )
sort_on_column( column, data, ITEM_COLUMN );
}
-/**
- * nact_match_list_on_selection_changed:
- * @window: the #BaseWindow window which contains the view.
- * @tab_name: a string constant which identifies this page.
- * @count_selected: count of selected items in the #NactIActionsList list view.
- *
+/*
* Called each time the selection changes in the Actions tree view.
*
* Basically we are using here a rather common scheme:
@@ -313,11 +393,10 @@ nact_match_list_init_view( BaseWindow *window, const gchar *tab_name )
* for the same basename filter
* - update the object with a summary of the listbox contents
*/
-void
-nact_match_list_on_selection_changed( BaseWindow *window, const gchar *tab_name, guint count_selected )
+static void
+on_main_selection_changed( BaseWindow *window, GList *selected_items, MatchListData *data )
{
- static const gchar *thisfn = "nact_match_list_on_selection_changed";
- MatchListStr *data;
+ static const gchar *thisfn = "nact_match_list_on_main_selection_changed";
NAIContext *context;
gboolean enable_tab;
GSList *filters;
@@ -326,9 +405,7 @@ nact_match_list_on_selection_changed( BaseWindow *window, const gchar *tab_name,
GtkTreeViewColumn *column;
GtkTreePath *path;
- g_debug( "%s: window=%p, tab=%s, count_selected=%d", thisfn, ( void * ) window, tab_name, count_selected );
-
- data = ( MatchListStr * ) g_object_get_data( G_OBJECT( window ), tab_name );
+ g_return_if_fail( BASE_IS_WINDOW( window ));
g_return_if_fail( data != NULL );
g_object_get( G_OBJECT( window ),
@@ -338,7 +415,7 @@ nact_match_list_on_selection_changed( BaseWindow *window, const gchar *tab_name,
enable_tab = ( context != NULL );
nact_main_tab_enable_page( NACT_MAIN_WINDOW( data->window ), data->tab_id, enable_tab );
- st_on_selection_change = TRUE;
+ data->on_selection_change = TRUE;
filters = context ? ( *data->pget )( context ) : NULL;
g_debug( "%s: filters=%p (count=%d)", thisfn, ( void * ) filters, filters ? g_slist_length( filters ) : -1 );
@@ -360,7 +437,7 @@ nact_match_list_on_selection_changed( BaseWindow *window, const gchar *tab_name,
base_gtk_utils_set_editable( G_OBJECT( data->removebutton ), data->editable_item );
gtk_widget_set_sensitive( data->removebutton, FALSE );
- st_on_selection_change = FALSE;
+ data->on_selection_change = FALSE;
path = gtk_tree_path_new_first();
if( path ){
@@ -383,9 +460,9 @@ nact_match_list_on_selection_changed( BaseWindow *window, const gchar *tab_name,
void
nact_match_list_insert_row( BaseWindow *window, const gchar *tab_name, const gchar *filter, gboolean match, gboolean not_match )
{
- MatchListStr *data;
+ MatchListData *data;
- data = ( MatchListStr * ) g_object_get_data( G_OBJECT( window ), tab_name );
+ data = ( MatchListData * ) g_object_get_data( G_OBJECT( window ), tab_name );
g_return_if_fail( data != NULL );
insert_new_row_data( data, filter, match, not_match );
@@ -403,10 +480,10 @@ GSList *
nact_match_list_get_rows( BaseWindow *window, const gchar *tab_name )
{
GSList *filters;
- MatchListStr *data;
+ MatchListData *data;
GtkTreeModel *model;
- data = ( MatchListStr * ) g_object_get_data( G_OBJECT( window ), tab_name );
+ data = ( MatchListData * ) g_object_get_data( G_OBJECT( window ), tab_name );
g_return_val_if_fail( data != NULL, NULL );
model = gtk_tree_view_get_model( data->listview );
@@ -416,48 +493,24 @@ nact_match_list_get_rows( BaseWindow *window, const gchar *tab_name )
return( filters );
}
-/**
- * nact_match_list_dispose:
- * @window: the #BaseWindow window which contains the view.
- * @tab_name: a string constant which identifies this page.
- *
- * Called at instance_dispose time.
+/* callback function called when the user clicks on "Add" button
+ * and no application callback has been provided by the caller
+ * at initialization time
*/
-void
-nact_match_list_dispose( BaseWindow *window, const gchar *tab_name )
-{
- MatchListStr *data;
- GtkTreeModel *model;
- GtkTreeSelection *selection;
-
- data = ( MatchListStr * ) g_object_get_data( G_OBJECT( window ), tab_name );
- g_return_if_fail( data != NULL );
-
- model = gtk_tree_view_get_model( data->listview );
- selection = gtk_tree_view_get_selection( data->listview );
- gtk_tree_selection_unselect_all( selection );
- gtk_list_store_clear( GTK_LIST_STORE( model ));
-
- g_free( data->item_header );
-
- g_free( data );
- g_object_set_data( G_OBJECT( window ), tab_name, NULL );
-}
-
static void
-on_add_filter_clicked( GtkButton *button, MatchListStr *data )
+on_add_filter_clicked( GtkButton *button, MatchListData *data )
{
insert_new_row( data );
}
static void
-on_filter_clicked( GtkTreeViewColumn *treeviewcolumn, MatchListStr *data )
+on_filter_clicked( GtkTreeViewColumn *treeviewcolumn, MatchListData *data )
{
sort_on_column( treeviewcolumn, data, ITEM_COLUMN );
}
static void
-on_filter_edited( GtkCellRendererText *renderer, const gchar *path_str, const gchar *text, MatchListStr *data )
+on_filter_edited( GtkCellRendererText *renderer, const gchar *path_str, const gchar *text, MatchListData *data )
{
static const gchar *thisfn = "nact_match_list_on_filter_edited";
GtkTreeModel *model;
@@ -534,7 +587,7 @@ on_filter_edited( GtkCellRendererText *renderer, const gchar *path_str, const gc
}
static gboolean
-on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, MatchListStr *data )
+on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, MatchListData *data )
{
gboolean stop;
@@ -565,7 +618,7 @@ on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, MatchListStr *data
}
static void
-on_must_match_clicked( GtkTreeViewColumn *treeviewcolumn, MatchListStr *data )
+on_must_match_clicked( GtkTreeViewColumn *treeviewcolumn, MatchListData *data )
{
sort_on_column( treeviewcolumn, data, MUST_MATCH_COLUMN );
}
@@ -579,7 +632,7 @@ on_must_match_clicked( GtkTreeViewColumn *treeviewcolumn, MatchListStr *data )
* filters list
*/
static void
-on_must_match_toggled( GtkCellRendererToggle *cell_renderer, gchar *path_str, MatchListStr *data )
+on_must_match_toggled( GtkCellRendererToggle *cell_renderer, gchar *path_str, MatchListData *data )
{
/*static const gchar *thisfn = "nact_match_list_on_must_match_toggled";*/
gchar *filter;
@@ -625,13 +678,13 @@ on_must_match_toggled( GtkCellRendererToggle *cell_renderer, gchar *path_str, Ma
}
static void
-on_must_not_match_clicked( GtkTreeViewColumn *treeviewcolumn, MatchListStr *data )
+on_must_not_match_clicked( GtkTreeViewColumn *treeviewcolumn, MatchListData *data )
{
sort_on_column( treeviewcolumn, data, MUST_NOT_MATCH_COLUMN );
}
static void
-on_must_not_match_toggled( GtkCellRendererToggle *cell_renderer, gchar *path_str, MatchListStr *data )
+on_must_not_match_toggled( GtkCellRendererToggle *cell_renderer, gchar *path_str, MatchListData *data )
{
/*static const gchar *thisfn = "nact_match_list_on_must_not_match_toggled";*/
gchar *filter;
@@ -676,20 +729,20 @@ on_must_not_match_toggled( GtkCellRendererToggle *cell_renderer, gchar *path_str
}
static void
-on_remove_filter_clicked( GtkButton *button, MatchListStr *data )
+on_remove_filter_clicked( GtkButton *button, MatchListData *data )
{
delete_current_row( data );
}
static void
-on_selection_changed( GtkTreeSelection *selection, MatchListStr *data )
+on_selection_changed( GtkTreeSelection *selection, MatchListData *data )
{
gtk_widget_set_sensitive( data->removebutton,
data->editable_item && gtk_tree_selection_count_selected_rows( selection ) > 0 );
}
static void
-add_filter( MatchListStr *data, const gchar *filter, const gchar *prefix )
+add_filter( MatchListData *data, const gchar *filter, const gchar *prefix )
{
NAIContext *context;
GSList *filters;
@@ -709,7 +762,7 @@ add_filter( MatchListStr *data, const gchar *filter, const gchar *prefix )
}
static guint
-count_filters( const gchar *filter, MatchListStr *data )
+count_filters( const gchar *filter, MatchListData *data )
{
guint count;
GtkTreeModel *model;
@@ -725,7 +778,7 @@ count_filters( const gchar *filter, MatchListStr *data )
}
static void
-delete_current_row( MatchListStr *data )
+delete_current_row( MatchListData *data )
{
GtkTreeSelection *selection;
GtkTreeModel *model;
@@ -787,7 +840,7 @@ delete_row_at_path( GtkTreeView *treeview, GtkTreeModel *model, GtkTreePath *pat
}
static void
-dump_current_rows( MatchListStr *data )
+dump_current_rows( MatchListData *data )
{
#ifdef NA_MAINTAINER_MODE
GtkTreeModel *model;
@@ -802,7 +855,7 @@ dump_current_rows( MatchListStr *data )
}
static void
-edit_inline( MatchListStr *data )
+edit_inline( MatchListData *data )
{
GtkTreeSelection *selection;
GList *rows;
@@ -823,7 +876,7 @@ edit_inline( MatchListStr *data )
}
static gchar *
-get_filter_from_path( const gchar *path_str, MatchListStr *data )
+get_filter_from_path( const gchar *path_str, MatchListData *data )
{
gchar *filter;
GtkTreeModel *model;
@@ -868,7 +921,7 @@ get_rows_iter( GtkTreeModel *model, GtkTreePath *path, GtkTreeIter* iter, GSList
}
static void
-insert_new_row( MatchListStr *data )
+insert_new_row( MatchListData *data )
{
/* i18n notes : new filter for a new row in a match/no match list */
static const gchar *filter_label = N_( "new-filter" );
@@ -880,7 +933,7 @@ insert_new_row( MatchListStr *data )
}
static void
-insert_new_row_data( MatchListStr *data, const gchar *filter, gboolean match, gboolean not_match )
+insert_new_row_data( MatchListData *data, const gchar *filter, gboolean match, gboolean not_match )
{
GtkTreeModel *model;
GtkTreeIter iter;
@@ -946,7 +999,7 @@ iter_for_setup( gchar *filter_orig, GtkTreeModel *model )
}
static gchar *
-search_for_unique_label( const gchar *propal, MatchListStr *data )
+search_for_unique_label( const gchar *propal, MatchListData *data )
{
gchar *label;
guint count;
@@ -963,7 +1016,7 @@ search_for_unique_label( const gchar *propal, MatchListStr *data )
}
static void
-set_match_status( const gchar *path_str, gboolean must_match, gboolean must_not_match, MatchListStr *data )
+set_match_status( const gchar *path_str, gboolean must_match, gboolean must_not_match, MatchListData *data )
{
GtkTreeModel *model;
GtkTreePath *path;
@@ -981,7 +1034,7 @@ set_match_status( const gchar *path_str, gboolean must_match, gboolean must_not_
}
static void
-sort_on_column( GtkTreeViewColumn *treeviewcolumn, MatchListStr *data, guint new_col_id )
+sort_on_column( GtkTreeViewColumn *treeviewcolumn, MatchListData *data, guint new_col_id )
{
guint prev_col_id;
guint prev_order, new_order;
@@ -1009,3 +1062,30 @@ sort_on_column( GtkTreeViewColumn *treeviewcolumn, MatchListStr *data, guint new
model = gtk_tree_view_get_model( data->listview );
gtk_tree_sortable_set_sort_column_id( GTK_TREE_SORTABLE( model ), new_col_id, new_order );
}
+
+static void
+on_instance_finalized( MatchListData *data, BaseWindow *window )
+{
+ static const gchar *thisfn = "nact_match_list_on_instance_finalized";
+ GtkTreeModel *model;
+ GtkTreeSelection *selection;
+
+ g_return_if_fail( data != NULL );
+
+ g_debug( "%s: window=%p, user_data=%p, tab_name=%s",
+ thisfn,
+ ( void * ) window,
+ ( void * ) data, data->tab_name );
+
+ g_object_set_data( G_OBJECT( window ), data->tab_name, NULL );
+
+ model = gtk_tree_view_get_model( data->listview );
+ selection = gtk_tree_view_get_selection( data->listview );
+ gtk_tree_selection_unselect_all( selection );
+ gtk_list_store_clear( GTK_LIST_STORE( model ));
+
+ g_free( data->tab_name );
+ g_free( data->item_header );
+
+ g_free( data );
+}
diff --git a/src/nact/nact-match-list.h b/src/nact/nact-match-list.h
index 6622837..7762fec 100644
--- a/src/nact/nact-match-list.h
+++ b/src/nact/nact-match-list.h
@@ -35,59 +35,51 @@
* SECTION: nact_match_list
* @short_description: Implementation of a list match/does not match.
* @include: nact/nact-match-list.h
+ *
+ * In an ideal world, this would be a base interface for NactISchemesTab,
+ * etc. interfaces.
+ * In GObject world however, one cannot derived an interface, nor an interface
+ * can implement another interface. The GObject solution would be for NactISchemesTab
+ * to requires NactIMatchList, and for NactMainWindow to implement this same
+ * NactIMatchList interface. This is not very practical as NactMainWindow is
+ * already some big bunch of code...
+ *
+ * So we stay with just a piece of helper functions...
*/
#include "base-window.h"
G_BEGIN_DECLS
-typedef GSList * ( *pget_filters )( void * );
-typedef void ( *pset_filters )( void *, GSList * );
-typedef void ( *pon_add_cb ) ( void *, BaseWindow * );
+typedef GSList * ( *pget_filters ) ( void * );
+typedef void ( *pset_filters ) ( void *, GSList * );
+typedef void ( *pon_add_cb ) ( void *, BaseWindow * );
+typedef void ( *pon_remove_cb )( void *, BaseWindow * );
enum {
MATCH_LIST_MUST_MATCH_ONE_OF = 1,
MATCH_LIST_MUST_MATCH_ALL_OF,
};
-typedef struct {
- BaseWindow *window;
- guint tab_id;
- GtkTreeView *listview;
- GtkWidget *addbutton;
- GtkWidget *removebutton;
- pget_filters pget;
- pset_filters pset;
- pon_add_cb pon_add;
- guint match_header;
- gchar *item_header;
- gboolean editable_filter;
- /* dynamic data */
- gboolean editable_item;
- 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, pon_add_cb pon_add,
- guint match_header,
- const gchar *item_header,
- gboolean editable_filter );
-
-void nact_match_list_init_view ( BaseWindow *window, const gchar *tab_name );
-
-void nact_match_list_on_selection_changed( BaseWindow *window, const gchar *tab_name,
- guint count );
-
-void nact_match_list_insert_row ( BaseWindow *window, const gchar *tab_name,
- const gchar *filter, gboolean match, gboolean not_match );
+void nact_match_list_init_with_args( BaseWindow *window, const gchar *tab_name,
+ guint tab_id,
+ GtkWidget *listview,
+ GtkWidget *addbutton,
+ GtkWidget *removebutton,
+ pget_filters pget,
+ pset_filters pset,
+ pon_add_cb pon_add,
+ pon_remove_cb pon_remove,
+ guint match_header,
+ const gchar *item_header,
+ gboolean editable_filter );
-GSList *nact_match_list_get_rows ( BaseWindow *window, const gchar *tab_name );
+void nact_match_list_insert_row ( BaseWindow *window, const gchar *tab_name,
+ const gchar *filter,
+ gboolean match,
+ gboolean not_match );
-void nact_match_list_dispose ( BaseWindow *window, const gchar *tab_name );
+GSList *nact_match_list_get_rows ( BaseWindow *window, const gchar *tab_name );
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]