[nautilus-actions] Fix the display of item's icon



commit 16b9a1be8d35be78f7b848e76184a4deedf06a32
Author: Pierre Wieser <pwieser trychlos org>
Date:   Mon Dec 21 21:31:08 2009 +0100

    Fix the display of item's icon

 ChangeLog                                          |   23 +++++++
 TODO                                               |    5 ++
 nautilus-actions/nact/Makefile.am                  |    1 +
 nautilus-actions/nact/nact-iaction-tab.c           |   62 +++++++++++-------
 nautilus-actions/nact/nact-iactions-list.c         |    4 +-
 nautilus-actions/nact/nact-main-window.c           |    3 +-
 .../nact/nautilus-actions-config-tool.ui           |   28 ++++----
 nautilus-actions/nact/transparent.png              |  Bin 0 -> 183 bytes
 nautilus-actions/private/na-object-item.c          |   69 +++++++++++---------
 9 files changed, 121 insertions(+), 74 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 819b6fc..9c12984 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,28 @@
 2009-12-21 Pierre Wieser <pwieser trychlos org>
 
+	Fix the display of item's icon.
+
+	* nautilus-actions/nact/transparent.png: New file.
+
+	* nautilus-actions/nact/Makefile.am: Updated accordingly.
+
+	* nautilus-actions/nact/nact-iaction-tab.c
+	(display_icon): Removed function.
+	(nact_iaction_tab_initial_load_toplevel):
+	Set the frame the same height that the row.
+	(on_icon_changed):
+	Displays a transparent image instead of hiding the widget.
+
+	* nautilus-actions/nact/nact-iactions-list.c
+	(nact_iactions_list_all_widgets_showed):
+	Only select the first item when all widgets have been showed.
+
+	* nautilus-actions/nact/nact-main-window.c
+	(on_base_all_widgets_showed): Initialize the tree after the tabs.
+
+	* nautilus-actions/private/na-object-item.c
+	(na_object_item_get_pixbuf): Use GThemedIcon.
+
 	* nautilus-actions/nact/nact-main-window.c
 	(on_iactions_list_selection_changed): Remove useless properties setup.
 	Provider writability status is also displayed for profiles.
diff --git a/TODO b/TODO
index 3de0b3c..548811b 100644
--- a/TODO
+++ b/TODO
@@ -110,3 +110,8 @@
   > remove in action class
 
 - the locked image is moved to the right (under the grip) at the first item
+  and height is not ok
+
+- desktop file is not deleted when the item is
+
+- crash on F5
diff --git a/nautilus-actions/nact/Makefile.am b/nautilus-actions/nact/Makefile.am
index 667ab12..02bda0a 100644
--- a/nautilus-actions/nact/Makefile.am
+++ b/nautilus-actions/nact/Makefile.am
@@ -143,6 +143,7 @@ pkgdata_DATA = \
 	nact-assistant-export.ui									\
 	nautilus-actions-config-tool.ui								\
 	locked.png													\
+	transparent.png												\
 	$(NULL)
 
 @INTLTOOL_DESKTOP_RULE@
diff --git a/nautilus-actions/nact/nact-iaction-tab.c b/nautilus-actions/nact/nact-iaction-tab.c
index 087975b..bb79275 100644
--- a/nautilus-actions/nact/nact-iaction-tab.c
+++ b/nautilus-actions/nact/nact-iaction-tab.c
@@ -95,7 +95,6 @@ static void          toolbar_label_set_sensitive( NactIActionTab *instance, NAOb
 static void          on_tooltip_changed( GtkEntry *entry, NactIActionTab *instance );
 
 static GtkTreeModel *create_stock_icon_model( void );
-static void          display_icon( NactIActionTab *instance, GtkWidget *image, gboolean display );
 static void          icon_combo_list_fill( GtkComboBoxEntry* combo );
 static void          on_icon_browse( GtkButton *button, NactIActionTab *instance );
 static void          on_icon_changed( GtkEntry *entry, NactIActionTab *instance );
@@ -177,18 +176,39 @@ interface_base_finalize( NactIActionTabInterface *klass )
 	}
 }
 
+/*
+ * GTK_ICON_SIZE_MENU         : 16x16
+ * GTK_ICON_SIZE_SMALL_TOOLBAR: 18x18
+ * GTK_ICON_SIZE_LARGE_TOOLBAR: 24x24
+ * GTK_ICON_SIZE_BUTTON       : 20x20
+ * GTK_ICON_SIZE_DND          : 32x32
+ * GTK_ICON_SIZE_DIALOG       : 48x48
+ *
+ * icon is rendered for GTK_ICON_SIZE_MENU (na_object_item_get_pixbuf)
+ */
 void
 nact_iaction_tab_initial_load_toplevel( NactIActionTab *instance )
 {
 	static const gchar *thisfn = "nact_iaction_tab_initial_load_toplevel";
 	GtkWidget *icon_widget;
 	GtkTreeModel *model;
+	GtkButton *button;
+	GtkRequisition requisition;
+	GtkFrame *frame;
+	gint size;
 
 	g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
 	g_return_if_fail( NACT_IS_IACTION_TAB( instance ));
 
 	if( st_initialized && !st_finalized ){
 
+		button = GTK_BUTTON( base_window_get_widget( BASE_WINDOW( instance ), "ActionIconBrowseButton" ));
+		gtk_widget_size_request( GTK_WIDGET( button ), &requisition );
+		g_debug( "%s: button requisition width=%d, height=%d", thisfn, requisition.width, requisition.height );
+		frame = GTK_FRAME( base_window_get_widget( BASE_WINDOW( instance ), "ActionIconFrame" ));
+		size = requisition.height - 4;
+		gtk_widget_set_size_request( GTK_WIDGET( frame ), size, size );
+
 		icon_widget = base_window_get_widget( BASE_WINDOW( instance ), "ActionIconComboBoxEntry" );
 		model = create_stock_icon_model();
 		gtk_combo_box_set_model( GTK_COMBO_BOX( icon_widget ), model );
@@ -202,8 +222,8 @@ nact_iaction_tab_runtime_init_toplevel( NactIActionTab *instance )
 {
 	static const gchar *thisfn = "nact_iaction_tab_runtime_init_toplevel";
 	GtkWidget *label_widget, *tooltip_widget, *icon_widget;
-	GtkWidget *button;
 	GtkButton *enabled_button;
+	GtkWidget *button;
 
 	g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
 	g_return_if_fail( NACT_IS_IACTION_TAB( instance ));
@@ -875,21 +895,6 @@ create_stock_icon_model( void )
 }
 
 static void
-display_icon( NactIActionTab *instance, GtkWidget *image, gboolean show )
-{
-	GtkFrame *frame = GTK_FRAME( base_window_get_widget( BASE_WINDOW( instance ), "ActionIconFrame" ));
-
-	if( show ){
-		gtk_widget_show( image );
-		gtk_frame_set_shadow_type( frame, GTK_SHADOW_NONE );
-
-	} else {
-		gtk_widget_hide( image );
-		gtk_frame_set_shadow_type( frame, GTK_SHADOW_IN );
-	}
-}
-
-static void
 icon_combo_list_fill( GtkComboBoxEntry* combo )
 {
 	GtkCellRenderer *cell_renderer_pix;
@@ -943,15 +948,18 @@ on_icon_browse( GtkButton *button, NactIActionTab *instance )
 static void
 on_icon_changed( GtkEntry *icon_entry, NactIActionTab *instance )
 {
-	/*static const gchar *thisfn = "nact_iaction_tab_on_icon_changed";*/
+	static const gchar *thisfn = "nact_iaction_tab_on_icon_changed";
 	GtkWidget *image;
-	GdkPixbuf *icon;
+	GdkPixbuf *pixbuf;
 	NAObjectItem *edited;
 	const gchar *icon_name;
 
+	g_debug( "%s: entry=%p, instance=%p", thisfn, ( void * ) icon_entry, ( void * ) instance );
+
+	pixbuf = NULL;
+	icon_name = NULL;
 	image = base_window_get_widget( BASE_WINDOW( instance ), "ActionIconImage" );
 	g_assert( GTK_IS_WIDGET( image ));
-	display_icon( instance, image, FALSE );
 
 	g_object_get(
 			G_OBJECT( instance ),
@@ -963,11 +971,15 @@ on_icon_changed( GtkEntry *icon_entry, NactIActionTab *instance )
 		na_object_item_set_icon( edited, icon_name );
 		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, TRUE );
 
-		if( icon_name && strlen( icon_name ) > 0 ){
-			icon = na_object_item_get_pixbuf( edited, image );
-			gtk_image_set_from_pixbuf( GTK_IMAGE( image ), icon );
-			display_icon( instance, image, TRUE );
-		}
+		pixbuf = na_object_item_get_pixbuf( edited, image );
+	}
+
+	if( !pixbuf ){
+		pixbuf = gdk_pixbuf_new_from_file_at_size( PKGDATADIR "/transparent.png", GTK_ICON_SIZE_MENU, GTK_ICON_SIZE_MENU, NULL );
+	}
+
+	if( pixbuf ){
+		gtk_image_set_from_pixbuf( GTK_IMAGE( image ), pixbuf );
 	}
 }
 
diff --git a/nautilus-actions/nact/nact-iactions-list.c b/nautilus-actions/nact/nact-iactions-list.c
index 586cb4a..86f847e 100644
--- a/nautilus-actions/nact/nact-iactions-list.c
+++ b/nautilus-actions/nact/nact-iactions-list.c
@@ -516,6 +516,8 @@ nact_iactions_list_all_widgets_showed( NactIActionsList *instance )
 	g_return_if_fail( NACT_IS_IACTIONS_LIST( instance ));
 
 	if( st_iactions_list_initialized && !st_iactions_list_finalized ){
+
+		nact_iactions_list_bis_select_first_row( instance );
 	}
 }
 
@@ -687,8 +689,6 @@ nact_iactions_list_fill( NactIActionsList *instance, GList *items )
 			na_object_item_count_items( items, &ialid->menus, &ialid->actions, &ialid->profiles, TRUE );
 			nact_iactions_list_priv_send_list_count_updated_signal( instance, ialid );
 		}
-
-		nact_iactions_list_bis_select_first_row( instance );
 	}
 }
 
diff --git a/nautilus-actions/nact/nact-main-window.c b/nautilus-actions/nact/nact-main-window.c
index 8263f6f..0eed390 100644
--- a/nautilus-actions/nact/nact-main-window.c
+++ b/nautilus-actions/nact/nact-main-window.c
@@ -1100,12 +1100,13 @@ on_base_all_widgets_showed( NactMainWindow *window, gpointer user_data )
 
 	if( !window->private->dispose_has_run ){
 
-		nact_iactions_list_all_widgets_showed( NACT_IACTIONS_LIST( window ));
 		nact_iaction_tab_all_widgets_showed( NACT_IACTION_TAB( window ));
 		nact_icommand_tab_all_widgets_showed( NACT_ICOMMAND_TAB( window ));
 		nact_ibackground_tab_all_widgets_showed( NACT_IBACKGROUND_TAB( window ));
 		nact_iconditions_tab_all_widgets_showed( NACT_ICONDITIONS_TAB( window ));
 		nact_iadvanced_tab_all_widgets_showed( NACT_IADVANCED_TAB( window ));
+
+		nact_iactions_list_all_widgets_showed( NACT_IACTIONS_LIST( window ));
 	}
 }
 
diff --git a/nautilus-actions/nact/nautilus-actions-config-tool.ui b/nautilus-actions/nact/nautilus-actions-config-tool.ui
index 7f76d09..5101383 100644
--- a/nautilus-actions/nact/nautilus-actions-config-tool.ui
+++ b/nautilus-actions/nact/nautilus-actions-config-tool.ui
@@ -318,22 +318,22 @@
                                             <property name="spacing">6</property>
                                             <child>
                                               <object class="GtkAspectFrame" id="ActionIconFrame">
-                                                <property name="width_request">24</property>
-                                                <property name="height_request">24</property>
                                                 <property name="visible">True</property>
                                                 <property name="label_xalign">0</property>
                                                 <property name="shadow_type">in</property>
                                                 <property name="obey_child">False</property>
                                                 <child>
                                                   <object class="GtkImage" id="ActionIconImage">
-                                                    <property name="stock">gnome-stock-blank</property>
-                                                    <property name="icon-size">4</property>
+                                                    <property name="visible">True</property>
+                                                    <property name="xpad">2</property>
+                                                    <property name="ypad">2</property>
+                                                    <property name="stock">gtk-stock-blank</property>
+                                                    <property name="icon-size">1</property>
                                                   </object>
                                                 </child>
                                               </object>
                                               <packing>
                                                 <property name="expand">False</property>
-                                                <property name="fill">False</property>
                                                 <property name="position">0</property>
                                               </packing>
                                             </child>
@@ -1339,10 +1339,10 @@ Defining several profiles lets you have several commands, each applying with a d
         <child>
           <object class="GtkFileChooserWidget" id="ImportFileChooser">
             <property name="visible">True</property>
-            <property name="local_only">False</property>
+            <property name="use_preview_label">False</property>
             <property name="select_multiple">True</property>
             <property name="preview_widget_active">False</property>
-            <property name="use_preview_label">False</property>
+            <property name="local_only">False</property>
           </object>
           <packing>
             <property name="position">0</property>
@@ -2928,24 +2928,24 @@ Be warned: this mode may be dangerous. You will not be prompted another time.</p
   </object>
   <object class="GtkSizeGroup" id="CommandLabelSizeGroup">
     <widgets>
-      <widget name="ProfileLabelLabel"/>
-      <widget name="CommandPathLabel"/>
       <widget name="CommandParametersLabel"/>
+      <widget name="CommandPathLabel"/>
+      <widget name="ProfileLabelLabel"/>
     </widgets>
   </object>
   <object class="GtkSizeGroup" id="CommandButtonSizeGroup">
     <widgets>
-      <widget name="CommandPathButton"/>
       <widget name="CommandLegendButton"/>
+      <widget name="CommandPathButton"/>
     </widgets>
   </object>
   <object class="GtkSizeGroup" id="ActionLabelSizeGroup">
     <widgets>
-      <widget name="ActionIconLabelLabel"/>
-      <widget name="ActionMenuLabelLabel"/>
-      <widget name="ActionIdLabel"/>
-      <widget name="ActionTooltipLabel"/>
       <widget name="ActionIconLabel"/>
+      <widget name="ActionTooltipLabel"/>
+      <widget name="ActionIdLabel"/>
+      <widget name="ActionMenuLabelLabel"/>
+      <widget name="ActionIconLabelLabel"/>
     </widgets>
   </object>
 </interface>
diff --git a/nautilus-actions/nact/transparent.png b/nautilus-actions/nact/transparent.png
new file mode 100644
index 0000000..70455d2
Binary files /dev/null and b/nautilus-actions/nact/transparent.png differ
diff --git a/nautilus-actions/private/na-object-item.c b/nautilus-actions/private/na-object-item.c
index 2462cfc..f55758e 100644
--- a/nautilus-actions/private/na-object-item.c
+++ b/nautilus-actions/private/na-object-item.c
@@ -415,43 +415,48 @@ na_object_item_get_icon( const NAObjectItem *item )
 GdkPixbuf *na_object_item_get_pixbuf( const NAObjectItem *item, GtkWidget *widget )
 {
 	static const gchar *thisfn = "na_object_item_get_pixbuf";
-	gchar *iconname;
-	GtkStockItem stock_item;
-	GdkPixbuf* icon = NULL;
-	gint width, height;
-	GError* error = NULL;
-
-	g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NULL );
-
-	if( !item->private->dispose_has_run ){
-
-		iconname = na_object_item_get_icon( item );
+	gint size;
+	gchar *icon_name;
+	GdkPixbuf* pixbuf;
+	GIcon *icon;
+	GtkIconTheme *theme;
+	GError *error;
+
+	error = NULL;
+	pixbuf = NULL;
+	size = GTK_ICON_SIZE_MENU;
+	icon_name = na_object_item_get_icon( item );
+
+	if( icon_name && strlen( icon_name )){
+		if( g_path_is_absolute( icon_name )){
+			pixbuf = gdk_pixbuf_new_from_file_at_size( icon_name, size, size, &error );
+			if( error ){
+				g_warning( "%s: gdk_pixbuf_new_from_file_at_size: icon_name=%s, error=%s", thisfn, icon_name, error->message );
+				g_error_free( error );
+				error = NULL;
+				pixbuf = NULL;
+			}
 
-		/* TODO: use the same algorythm than Nautilus to find and
-		 * display an icon
-		 */
-		if( iconname ){
-			if( gtk_stock_lookup( iconname, &stock_item )){
-				icon = gtk_widget_render_icon( widget, iconname, GTK_ICON_SIZE_MENU, NULL );
-
-			} else if( g_file_test( iconname, G_FILE_TEST_EXISTS )
-				   && g_file_test( iconname, G_FILE_TEST_IS_REGULAR )){
-
-				gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
-				icon = gdk_pixbuf_new_from_file_at_size( iconname, width, height, &error );
-				if( error ){
-					g_warning( "%s: iconname=%s, error=%s", thisfn, iconname, error->message );
-					g_error_free( error );
-					error = NULL;
-					icon = NULL;
-				}
+		} else {
+			icon = g_themed_icon_new( icon_name );
+			theme = gtk_icon_theme_get_default();
+			pixbuf = gtk_icon_theme_load_icon( theme, icon_name, size, GTK_ICON_LOOKUP_GENERIC_FALLBACK, &error );
+			if( error ){
+				g_warning( "%s: gtk_icon_theme_load_icon: icon_name=%s, error=%s", thisfn, icon_name, error->message );
+				g_error_free( error );
+				error = NULL;
+				pixbuf = NULL;
 			}
 		}
-
-		g_free( iconname );
 	}
 
-	return( icon );
+	g_free( icon_name );
+
+	/*if( gtk_stock_lookup( icon_name, &icon_stock )){
+		icon_pixbuf = gtk_widget_render_icon( widget, icon_name, stock_size, &error );
+	}*/
+
+	return( pixbuf );
 }
 
 /**



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