Commit 5e5fc6a3 authored by Pierre Wieser's avatar Pierre Wieser

Rename base_window_get_widget_from_gtk() as nact_gtk_utils_get_widget_by_name()

+ src/nact/nact-icon-chooser.c: Updated accordingly.
parent b2581126
2011-01-22 Pierre Wieser <pwieser@trychlos.org>
* src/nact/base-builder.c:
* src/nact/base-builder.h (base_builder_get_toplevel_by_name):
Use a const BaseBuilder as argument;
* src/nact/base-window.c:
* src/nact/base-window.h (base_window_get_widget_from_gtk):
Removed function.
* src/nact/nact-gtk-utils.c:
* src/nact/nact-gtk-utils.h (nact_gtk_utils_get_widget_by_name):
New function.
* src/nact/nact-icon-chooser.c (on_destroy): Updated accordingly.
* src/nact/base-application.c (appli_initialize_unique_app):
Fix reverse test.
......
......@@ -230,6 +230,21 @@ base_builder_add_from_file( BaseBuilder *builder, const gchar *filename, GError
return( ret );
}
static gboolean
already_loaded( BaseBuilder *builder, const gchar *filename )
{
gboolean loaded = FALSE;
GSList *it;
for( it = builder->private->fnames ; it && !loaded ; it = it->next ){
if( !na_core_utils_str_collate(( const gchar * ) it->data, filename )){
loaded = TRUE;
}
}
return( loaded );
}
/**
* base_builder_get_toplevel_by_name:
* @builder: this #BaseBuilder object.
......@@ -243,7 +258,7 @@ base_builder_add_from_file( BaseBuilder *builder, const gchar *filename, GError
* g_free() nor g_object_unref() by the caller.
*/
GtkWindow *
base_builder_get_toplevel_by_name( BaseBuilder *builder, const gchar *name )
base_builder_get_toplevel_by_name( const BaseBuilder *builder, const gchar *name )
{
GtkWindow *toplevel = NULL;
......@@ -262,18 +277,3 @@ base_builder_get_toplevel_by_name( BaseBuilder *builder, const gchar *name )
return( toplevel );
}
static gboolean
already_loaded( BaseBuilder *builder, const gchar *filename )
{
gboolean loaded = FALSE;
GSList *it;
for( it = builder->private->fnames ; it && !loaded ; it = it->next ){
if( !na_core_utils_str_collate(( const gchar * ) it->data, filename )){
loaded = TRUE;
}
}
return( loaded );
}
......@@ -74,13 +74,11 @@ typedef struct {
GType base_builder_get_type( void );
BaseBuilder *base_builder_new ( void );
BaseBuilder *base_builder_new( void );
gboolean base_builder_add_from_file ( BaseBuilder *builder, const gchar *filename, GError **error );
gboolean base_builder_add_from_file( BaseBuilder *builder, const gchar *filename, GError **error );
GtkWindow *base_builder_get_toplevel_by_name( BaseBuilder *builder, const gchar *name );
/*GtkWidget *base_builder_get_gtk_widget_by_name ( BaseBuilder *builder, GtkWindow *toplevel, const gchar *name );*/
GtkWindow *base_builder_get_toplevel_by_name( const BaseBuilder *builder, const gchar *name );
G_END_DECLS
......
......@@ -40,6 +40,7 @@
#include "base-application.h"
#include "base-iprefs.h"
#include "base-window.h"
#include "nact-gtk-utils.h"
/* private class data
*/
......@@ -139,9 +140,6 @@ static gboolean window_do_delete_event( BaseWindow *window, GtkWindow *t
static gboolean window_do_is_willing_to_quit( const BaseWindow *window );
static gboolean is_main_window( BaseWindow *window );
static GtkWidget *search_for_widget( GtkWindow *toplevel, const gchar *name );
static GtkWidget *search_for_child_widget( GtkContainer *container, const gchar *name );
static GtkWindow *load_named_toplevel( const BaseWindow *window, const gchar *name );
static void record_connected_signal( BaseWindow *window, GObject *instance, gulong handler_id );
static gint display_dlg( const BaseWindow *parent, GtkMessageType type_message, GtkButtonsType type_buttons, const gchar *primary, const gchar *secondary );
......@@ -819,15 +817,16 @@ base_window_get_parent( const BaseWindow *window )
GtkWindow *
base_window_get_gtk_toplevel( const BaseWindow *window )
{
GtkWindow *toplevel = NULL;
GtkWindow *gtk_toplevel = NULL;
g_return_val_if_fail( BASE_IS_WINDOW( window ), NULL );
if( !window->private->dispose_has_run ){
toplevel = window->private->gtk_toplevel;
gtk_toplevel = window->private->gtk_toplevel;
}
return( toplevel );
return( gtk_toplevel );
}
/**
......@@ -846,15 +845,16 @@ base_window_get_gtk_toplevel( const BaseWindow *window )
GtkWindow *
base_window_get_gtk_toplevel_by_name( const BaseWindow *window, const gchar *name )
{
GtkWindow *toplevel = NULL;
GtkWindow *gtk_toplevel = NULL;
g_return_val_if_fail( BASE_IS_WINDOW( window ), NULL );
if( !window->private->dispose_has_run ){
toplevel = load_named_toplevel( window, name );
gtk_toplevel = base_builder_get_toplevel_by_name( window->private->builder, name );
}
return( toplevel );
return( gtk_toplevel );
}
/**
......@@ -872,43 +872,13 @@ base_window_get_gtk_toplevel_by_name( const BaseWindow *window, const gchar *nam
GtkWidget *
base_window_get_widget( const BaseWindow *window, const gchar *name )
{
static const gchar *thisfn = "base_window_get_widget";
GtkWindow *toplevel;
GtkWidget *widget = NULL;
g_return_val_if_fail( BASE_IS_WINDOW( window ), NULL );
if( !window->private->dispose_has_run ){
toplevel = window->private->gtk_toplevel;
widget = search_for_widget( toplevel, name );
if( !widget ){
g_warning( "%s: widget not found: %s", thisfn, name );
}
}
return( widget );
}
/**
* base_window_get_widget_from_gtk:
* @window: the #GtkWindow toplevel.
* @name: the name of the searched child.
*
* Returns: a pointer to the searched widget, or %NULL.
* This pointer is owned by GtkBuilder instance, and must not be
* released by the caller.
*/
GtkWidget *
base_window_get_widget_from_gtk( GtkWindow *window, const gchar *name )
{
static const gchar *thisfn = "base_window_get_widget_from_gtk";
GtkWidget *widget;
g_return_val_if_fail( GTK_IS_WINDOW( window ), NULL );
widget = search_for_widget( window, name );
if( !widget ){
g_warning( "%s: widget not found: %s", thisfn, name );
widget = nact_gtk_utils_get_widget_by_name( window->private->gtk_toplevel, name );
}
return( widget );
......@@ -1217,79 +1187,6 @@ is_main_window( BaseWindow *window )
return( is_main );
}
static GtkWindow *
load_named_toplevel( const BaseWindow *window, const gchar *name )
{
GtkWindow *toplevel = NULL;
BaseApplication *application;
BaseBuilder *builder;
gchar *msg;
if( window->private->builder ){
g_return_val_if_fail( BASE_IS_BUILDER( window->private->builder ), NULL );
toplevel = base_builder_get_toplevel_by_name( window->private->builder, name );
}
if( !toplevel ){
application = base_window_get_application( window );
builder = base_application_get_builder( application );
toplevel = base_builder_get_toplevel_by_name( builder, name );
}
if( !toplevel ){
msg = g_strdup_printf( _( "Unable to load %s XML definition." ), name );
base_window_display_error_dlg( window, msg, NULL );
g_free( msg );
}
return( toplevel );
}
static GtkWidget *
search_for_widget( GtkWindow *toplevel, const gchar *name )
{
GtkWidget *widget = NULL;
widget = search_for_child_widget( GTK_CONTAINER( toplevel ) , name );
g_return_val_if_fail( GTK_IS_WIDGET( widget ) || !widget, NULL );
return( widget );
}
static GtkWidget *
search_for_child_widget( GtkContainer *container, const gchar *name )
{
GList *children = gtk_container_get_children( container );
GList *ic;
GtkWidget *found = NULL;
GtkWidget *child;
const gchar *child_name;
for( ic = children ; ic ; ic = ic->next ){
if( GTK_IS_WIDGET( ic->data )){
child = GTK_WIDGET( ic->data );
child_name = gtk_buildable_get_name( GTK_BUILDABLE( child ));
if( child_name && strlen( child_name )){
/*g_debug( "%s: child=%s", thisfn, child_name );*/
if( !g_ascii_strcasecmp( name, child_name )){
found = child;
break;
} else if( GTK_IS_CONTAINER( child )){
found = search_for_child_widget( GTK_CONTAINER( child ), name );
if( found ){
break;
}
}
}
}
}
g_list_free( children );
return( found );
}
/**
* base_window_display_error_dlg:
* @parent: the #BaseWindow parent, may be %NULL.
......
......@@ -237,7 +237,6 @@ BaseWindow *base_window_get_parent ( const BaseWindow *window
GtkWindow *base_window_get_gtk_toplevel ( const BaseWindow *window );
GtkWindow *base_window_get_gtk_toplevel_by_name( const BaseWindow *window, const gchar *name );
GtkWidget *base_window_get_widget ( const BaseWindow *window, const gchar *name );
GtkWidget *base_window_get_widget_from_gtk ( GtkWindow *window, const gchar *name );
gboolean base_window_is_willing_to_quit ( const BaseWindow *window );
......
......@@ -49,6 +49,8 @@
#define DEFAULT_WIDTH 22
#define DEFAULT_HEIGHT 22
static GtkWidget *search_for_child_widget( GtkContainer *container, const gchar *name );
/**
* nact_gtk_utils_set_editable:
* @widget: the #GtkWdiget.
......@@ -572,3 +574,65 @@ nact_gtk_utils_select_dir( BaseWindow *window,
gtk_widget_destroy( dialog );
}
/**
* nact_gtk_utils_get_widget_by_name:
* @toplevel: the #GtkWindow toplevel.
* @name: the name of the searched child.
*
* Returns: a pointer to the named widget which is a child of @toplevel,
* or %NULL. the returned pointer is owned by #GtkBuilder instance, and
* should not be released by the caller.
*/
GtkWidget *
nact_gtk_utils_get_widget_by_name( GtkWindow *toplevel, const gchar *name )
{
static const gchar *thisfn = "nact_gtk_utils_get_widget_by_name";
GtkWidget *widget = NULL;
g_return_val_if_fail( GTK_IS_WINDOW( toplevel ), NULL );
widget = search_for_child_widget( GTK_CONTAINER( toplevel ), name );
if( !widget ){
g_warning( "%s: widget not found: %s", thisfn, name );
} else {
g_return_val_if_fail( GTK_IS_WIDGET( widget ), NULL );
}
return( widget );
}
static GtkWidget *
search_for_child_widget( GtkContainer *container, const gchar *name )
{
GList *children = gtk_container_get_children( container );
GList *ic;
GtkWidget *found = NULL;
GtkWidget *child;
const gchar *child_name;
for( ic = children ; ic ; ic = ic->next ){
if( GTK_IS_WIDGET( ic->data )){
child = GTK_WIDGET( ic->data );
child_name = gtk_buildable_get_name( GTK_BUILDABLE( child ));
if( child_name && strlen( child_name )){
/*g_debug( "%s: child=%s", thisfn, child_name );*/
if( !g_ascii_strcasecmp( name, child_name )){
found = child;
break;
} else if( GTK_IS_CONTAINER( child )){
found = search_for_child_widget( GTK_CONTAINER( child ), name );
if( found ){
break;
}
}
}
}
}
g_list_free( children );
return( found );
}
......@@ -32,13 +32,12 @@
#define __NACT_GTK_UTILS_H__
/**
* SECTION: nact_gtk_utils
* @short_description: Gtk helper functions.
* @include: nact/nact-gtk-utils.h
* SECTION: nact-gtk-utils
* @title: NactGtkUtils
* @short_description: Gtk helper functions
* @include: nact-gtk-utils.h
*/
#include <gtk/gtk.h>
#include "base-window.h"
G_BEGIN_DECLS
......@@ -79,6 +78,10 @@ void nact_gtk_utils_select_dir( BaseWindow *window,
const gchar *title, const gchar *dialog_name,
GtkWidget *entry, const gchar *entry_name );
/* GtkWidget
*/
GtkWidget *nact_gtk_utils_get_widget_by_name( GtkWindow *toplevel, const gchar *name );
G_END_DECLS
#endif /* __NACT_GTK_UTILS_H__ */
......@@ -656,7 +656,7 @@ on_destroy( GtkWidget *widget, GdkEvent *event, void *foo )
/* clear the various models
*/
context_view = GTK_TREE_VIEW( base_window_get_widget_from_gtk( GTK_WINDOW( widget ), "ThemedTreeView" ));
context_view = GTK_TREE_VIEW( nact_gtk_utils_get_widget_by_name( GTK_WINDOW( widget ), "ThemedTreeView" ));
context_store = GTK_LIST_STORE( gtk_tree_view_get_model( context_view ));
if( gtk_tree_model_get_iter_first( GTK_TREE_MODEL( context_store ), &context_iter )){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment