[nautilus-actions] NactAssistantImport: refactoring



commit 8afaed307914d5757283a03eabd14c0e17bcc159
Author: Pierre Wieser <pwieser trychlos org>
Date:   Tue Dec 20 19:43:19 2011 +0100

    NactAssistantImport: refactoring
    
    - Review the border around the pages for Gtk2
    - Force immediate redraw of dynamic labels (Gtk2)
    - Display URI in blue or red depending of the import status
    - Massively use GtkAlignment in user interface XML definition file.

 ChangeLog                         |   10 ++
 src/nact/nact-assistant-import.c  |   66 +++++++----
 src/nact/nact-assistant-import.ui |  239 ++++++++++++++++++-------------------
 3 files changed, 172 insertions(+), 143 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 70fe9a6..5e23aa9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-12-20 Pierre Wieser <pwieser trychlos org>
+
+	* src/nact/nact-assistant-import.c
+	(prepare_confirm, prepare_importdone):
+	Force immediate redraw with Gtk2.
+	(prepare_importdone): Color the URI depending of the status.
+
+	* src/nact/nact-assistant-import.ui:
+	Display the import mode in only one GtkLabel.
+
 2011-12-19 Pierre Wieser <pwieser trychlos org>
 
 	Review import assistant.
diff --git a/src/nact/nact-assistant-import.c b/src/nact/nact-assistant-import.c
index e0539be..556545f 100644
--- a/src/nact/nact-assistant-import.c
+++ b/src/nact/nact-assistant-import.c
@@ -344,24 +344,24 @@ on_base_initialize_gtk( NactAssistantImport *dialog )
 		g_debug( "%s: dialog=%p", thisfn, ( void * ) dialog );
 
 #if !GTK_CHECK_VERSION( 3,0,0 )
-		guint width = 10;
+		guint padder = 8;
 		GtkAssistant *assistant = GTK_ASSISTANT( base_window_get_gtk_toplevel( BASE_WINDOW( dialog )));
 		/* selecting files */
 		GtkWidget *page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_FILES_SELECTION );
-		GtkWidget *container = find_widget_from_page( page, "ImportFileChooser" );
-		g_object_set( G_OBJECT( container ), "border-width", width, NULL );
+		GtkWidget *container = find_widget_from_page( page, "p1-l2-alignment1" );
+		g_object_set( G_OBJECT( container ), "top_padding", padder, NULL );
 		/* managing duplicates */
 		page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_DUPLICATES );
-		container = find_widget_from_page( page, "p2-l2-vbox1" );
-		g_object_set( G_OBJECT( container ), "border-width", width, NULL );
+		container = find_widget_from_page( page, "p2-l2-alignment1" );
+		g_object_set( G_OBJECT( container ), "border_width", padder, NULL );
 		/* summary */
 		page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_CONFIRM );
-		container = find_widget_from_page( page, "p3-l4-vbox1" );
-		g_object_set( G_OBJECT( container ), "border-width", width, NULL );
+		container = find_widget_from_page( page, "p3-l2-alignment1" );
+		g_object_set( G_OBJECT( container ), "border_width", padder, NULL );
 		/* import is done */
 		page = gtk_assistant_get_nth_page( assistant, ASSIST_PAGE_DONE );
-		container = find_widget_from_page( page, "p4-l4-vbox1" );
-		g_object_set( G_OBJECT( container ), "border-width", width, NULL );
+		container = find_widget_from_page( page, "p4-l2-alignment1" );
+		g_object_set( G_OBJECT( container ), "border_width", padder, NULL );
 #endif
 
 		create_duplicates_treeview_model( dialog );
@@ -739,6 +739,16 @@ prepare_confirm( NactAssistantImport *window, GtkAssistant *assistant, GtkWidget
 	g_debug( "%s: window=%p, assistant=%p, page=%p",
 			thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page );
 
+#if !GTK_CHECK_VERSION( 3,0,0 )
+	/* Note that, at least, in Gtk 2.20 (Ubuntu 10) and 2.22 (Fedora 14), GtkLabel
+	 * queues its resize (when the text is being set), but the actual resize does
+	 * not happen immediately - We have to wait until Gtk 3.0, most probably due
+	 * to the new width-for-height and height-for-width features...
+	 */
+	GtkWidget *vbox = find_widget_from_page( page, "p3-ConfirmVBox" );
+	gtk_container_set_resize_mode( GTK_CONTAINER( vbox ), GTK_RESIZE_IMMEDIATE );
+#endif
+
 	/* adding list of uris to import
 	 */
 	text = NULL;
@@ -764,13 +774,11 @@ prepare_confirm( NactAssistantImport *window, GtkAssistant *assistant, GtkWidget
 	 */
 	label = find_widget_from_page( page, "p3-ConfirmImportMode" );
 	g_return_if_fail( GTK_IS_LABEL( label ));
-	gtk_label_set_text( GTK_LABEL( label ), gettext( st_import_modes[window->private->index_mode].label ));
-
-	/* adding import mode tooltip
-	 */
-	label = find_widget_from_page( page, "p3-ConfirmImportTooltip" );
-	g_return_if_fail( GTK_IS_LABEL( label ));
-	gtk_label_set_text( GTK_LABEL( label ), gettext( st_import_modes[window->private->index_mode].tooltip ));
+	text = g_markup_printf_escaped( "%s\n\n<span style=\"italic\">%s</span>",
+			gettext( st_import_modes[window->private->index_mode].label ),
+			gettext( st_import_modes[window->private->index_mode].tooltip ));
+	gtk_label_set_markup( GTK_LABEL( label ), text );
+	g_free( text );
 
 	gtk_assistant_set_page_complete( assistant, page, TRUE );
 }
@@ -859,6 +867,8 @@ check_for_existence( const NAObjectItem *item, NactMainWindow *window )
 /*
  * summary page is a vbox inside of a scrolled window
  * each line in this vbox is a GtkLabel
+ * Starting with 3.1.6, uri is displayed in red if an error has occured, or
+ * in blue.
  */
 static void
 prepare_importdone( NactAssistantImport *window, GtkAssistant *assistant, GtkWidget *page )
@@ -871,6 +881,7 @@ prepare_importdone( NactAssistantImport *window, GtkAssistant *assistant, GtkWid
 	GSList *im;
 	NAImporterResult *result;
 	gchar *text, *id, *item_label, *text2, *tmp;
+	const gchar *color;
 
 	g_debug( "%s: window=%p, assistant=%p, page=%p",
 			thisfn, ( void * ) window, ( void * ) assistant, ( void * ) page );
@@ -879,6 +890,15 @@ prepare_importdone( NactAssistantImport *window, GtkAssistant *assistant, GtkWid
 	vbox = find_widget_from_page( page, "p4-SummaryVBox" );
 	g_return_if_fail( GTK_IS_BOX( vbox ));
 
+#if !GTK_CHECK_VERSION( 3,0,0 )
+	/* Note that, at least, in Gtk 2.20 (Ubuntu 10) and 2.22 (Fedora 14), GtkLabel
+	 * queues its resize (when the text is being set), but the actual resize does
+	 * not happen immediately - We have to wait until Gtk 3.0, most probably due
+	 * to the new width-for-height and height-for-width features...
+	 */
+	gtk_container_set_resize_mode( GTK_CONTAINER( vbox ), GTK_RESIZE_IMMEDIATE );
+#endif
+
 	/* for each uri
 	 * 	- display the uri
 	 *  - display a brief import log
@@ -890,13 +910,17 @@ prepare_importdone( NactAssistantImport *window, GtkAssistant *assistant, GtkWid
 		/* display the uri
 		 */
 #if GTK_CHECK_VERSION( 3,0,0 )
-		file_vbox = gtk_box_new( GTK_ORIENTATION_VERTICAL, 5 );
+		file_vbox = gtk_box_new( GTK_ORIENTATION_VERTICAL, 4 );
 #else
-		file_vbox = gtk_vbox_new( FALSE, 5 );
+		file_vbox = gtk_vbox_new( FALSE, 4 );
 #endif
 		gtk_box_pack_start( GTK_BOX( vbox ), file_vbox, FALSE, FALSE, 0 );
 
-		file_uri = gtk_label_new( result->uri );
+		color = result->imported ? "blue" : "red";
+		text = g_markup_printf_escaped( "<span foreground=\"%s\">%s</span>", color, result->uri );
+		file_uri = gtk_label_new( NULL );
+		gtk_label_set_markup( GTK_LABEL( file_uri ), text );
+		g_free( text );
 		g_object_set( G_OBJECT( file_uri ), "xalign", 0, NULL );
 		g_object_set( G_OBJECT( file_uri ), "xpad", width, NULL );
 		gtk_box_pack_start( GTK_BOX( file_vbox ), file_uri, FALSE, FALSE, 0 );
@@ -941,8 +965,6 @@ prepare_importdone( NactAssistantImport *window, GtkAssistant *assistant, GtkWid
 	g_object_set( G_OBJECT( window ), BASE_PROP_WARN_ON_ESCAPE, FALSE, NULL );
 	na_iprefs_set_import_mode( NA_IPREFS_IMPORT_PREFERRED_MODE, window->private->mode );
 	gtk_assistant_set_page_complete( assistant, page, TRUE );
-	/* gtk_widget_show_all( page ) is ok with Gtk 3, but not with Gtk 2 */
-	/* gtk_widget_show_all( vbox ) is not better with Gtk 2 */
 	gtk_widget_show_all( page );
 }
 
@@ -989,7 +1011,7 @@ get_duplicates_treeview_from_page( GtkWidget *page )
 {
 	GtkWidget *listview;
 
-	listview = find_widget_from_page( page, "AskTreeView" );
+	listview = find_widget_from_page( page, "p2-AskTreeView" );
 
 	g_return_val_if_fail( GTK_IS_TREE_VIEW( listview ), NULL );
 
diff --git a/src/nact/nact-assistant-import.ui b/src/nact/nact-assistant-import.ui
index 04ccce1..46fa275 100644
--- a/src/nact/nact-assistant-import.ui
+++ b/src/nact/nact-assistant-import.ui
@@ -3,7 +3,6 @@
   <requires lib="gtk+" version="2.20"/>
   <!-- interface-naming-policy toplevel-contextual -->
   <object class="GtkAssistant" id="ImportAssistant">
-    <property name="border_width">10</property>
     <property name="title" translatable="yes">Importing actions</property>
     <property name="modal">True</property>
     <property name="type_hint">dialog</property>
@@ -21,12 +20,17 @@
       <object class="GtkVBox" id="p1-l1-vbox1">
         <property name="visible">True</property>
         <child>
-          <object class="GtkFileChooserWidget" id="ImportFileChooser">
+          <object class="GtkAlignment" id="p1-l2-alignment1">
             <property name="visible">True</property>
-            <property name="use_preview_label">False</property>
-            <property name="preview_widget_active">False</property>
-            <property name="local_only">False</property>
-            <property name="select_multiple">True</property>
+            <child>
+              <object class="GtkFileChooserWidget" id="ImportFileChooser">
+                <property name="visible">True</property>
+                <property name="use_preview_label">False</property>
+                <property name="preview_widget_active">False</property>
+                <property name="local_only">False</property>
+                <property name="select_multiple">True</property>
+              </object>
+            </child>
           </object>
           <packing>
             <property name="position">0</property>
@@ -42,43 +46,47 @@
       <object class="GtkVBox" id="p2-l1-vbox1">
         <property name="visible">True</property>
         <child>
-          <object class="GtkVBox" id="p2-l2-vbox1">
+          <object class="GtkAlignment" id="p2-l2-alignment1">
             <property name="visible">True</property>
-            <property name="spacing">10</property>
-            <child>
-              <object class="GtkLabel" id="p2-l3-label1">
-                <property name="visible">True</property>
-                <property name="xalign">0</property>
-                <property name="label" translatable="yes">What should I do when importing an item whose ID already exists ?</property>
-                <property name="use_markup">True</property>
-                <property name="wrap">True</property>
-                <attributes>
-                  <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
-                </attributes>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
             <child>
-              <object class="GtkTreeView" id="AskTreeView">
+              <object class="GtkVBox" id="p2-l3-vbox1">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="headers_visible">False</property>
-                <property name="rules_hint">True</property>
-                <property name="show_expanders">False</property>
+                <property name="spacing">10</property>
+                <child>
+                  <object class="GtkLabel" id="p2-l4-label1">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">What should I do when importing an item whose ID already exists ?</property>
+                    <property name="use_markup">True</property>
+                    <property name="wrap">True</property>
+                    <attributes>
+                      <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkTreeView" id="p2-AskTreeView">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                        <property name="headers_visible">False</property>
+                    <property name="rules_hint">True</property>
+                    <property name="show_expanders">False</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
             </child>
           </object>
-            <packing>
-              <property name="position">0</property>
-            </packing>
+          <packing>
+            <property name="position">0</property>
+          </packing>
         </child>
       </object>
       <packing>
@@ -90,99 +98,91 @@
       <object class="GtkVBox" id="p3-l1-vbox1">
         <property name="visible">True</property>
         <child>
-          <object class="GtkScrolledWindow" id="p3-l2-scrolledwindow1">
+          <object class="GtkAlignment" id="p3-l2-alignment1">
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="hscrollbar_policy">automatic</property>
-            <property name="vscrollbar_policy">automatic</property>
             <child>
-              <object class="GtkViewport" id="p3-l3-viewport1">
+              <object class="GtkScrolledWindow" id="p3-l3-scrolledwindow1">
                 <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hscrollbar_policy">automatic</property>
+                <property name="vscrollbar_policy">automatic</property>
                 <child>
-                  <object class="GtkVBox" id="p3-l4-vbox1">
+                  <object class="GtkViewport" id="p3-l4-viewport1">
                     <property name="visible">True</property>
-                    <property name="spacing">10</property>
+                    <property name="shadow_type">GTK_SHADOW_NONE</property>
                     <child>
-                      <object class="GtkVBox" id="p3-l5-vbox1">
+                      <object class="GtkVBox" id="p3-ConfirmVBox">
                         <property name="visible">True</property>
-                        <property name="spacing">10</property>
+                        <property name="spacing">15</property>
                         <child>
-                          <object class="GtkLabel" id="p3-l6-label1">
+                          <object class="GtkVBox" id="p3-l6-vbox1">
                             <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="yes">About to import selected files:</property>
-                            <attributes>
-                              <attribute name="weight" value="bold"/>
-                            </attributes>
+                            <property name="spacing">8</property>
+                            <child>
+                              <object class="GtkLabel" id="p3-l7-label1">
+                                <property name="visible">True</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">About to import selected files:</property>
+                                <attributes>
+                                  <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
+                                </attributes>
+                              </object>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="p3-ConfirmFilesList">
+                                <property name="visible">True</property>
+                                <property name="xalign">0</property>
+                                <property name="xpad">15</property>
+                              </object>
+                              <packing>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
                           </object>
                           <packing>
+                            <property name="expand">False</property>
                             <property name="position">0</property>
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkLabel" id="p3-ConfirmFilesList">
+                          <object class="GtkVBox" id="p3-l6-vbox2">
                             <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="xpad">15</property>
-                            <property name="label" translatable="yes"></property>
+                            <property name="spacing">8</property>
+                            <child>
+                              <object class="GtkLabel" id="p3-l7-label2">
+                                <property name="visible">True</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">When importing an item whose ID already exists:</property>
+                                <property name="wrap">True</property>
+                                <attributes>
+                                  <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
+                                </attributes>
+                              </object>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="p3-ConfirmImportMode">
+                                <property name="visible">True</property>
+                                <property name="xalign">0</property>
+                                <property name="xpad">15</property>
+                                <property name="wrap">True</property>
+                              </object>
+                              <packing>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
                           </object>
                           <packing>
+                            <property name="expand">False</property>
                             <property name="position">1</property>
                           </packing>
                         </child>
                       </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkVBox" id="p3-l5-vbox2">
-                        <property name="visible">True</property>
-                        <property name="spacing">10</property>
-                        <child>
-                          <object class="GtkLabel" id="p3-l6-label2">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="yes">When importing an item whose ID already exists:</property>
-                            <property name="wrap">True</property>
-                            <attributes>
-                              <attribute name="weight" value="bold"/>
-                            </attributes>
-                          </object>
-                          <packing>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="p3-ConfirmImportMode">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="xpad">15</property>
-                            <property name="label" translatable="yes"></property>
-                            <property name="wrap">True</property>
-                          </object>
-                          <packing>
-                            <property name="position">1</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="p3-ConfirmImportTooltip">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="xpad">30</property>
-                            <property name="label" translatable="yes"></property>
-                            <property name="wrap">True</property>
-                          </object>
-                          <packing>
-                            <property name="position">2</property>
-                          </packing>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="position">1</property>
-                      </packing>
                     </child>
                   </object>
                 </child>
@@ -203,41 +203,38 @@
       <object class="GtkVBox" id="p4-l1-vbox1">
         <property name="visible">True</property>
         <child>
-          <object class="GtkScrolledWindow" id="p4-l2-scrolledwindow1">
+          <object class="GtkAlignment" id="p4-l2-alignment1">
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="hscrollbar_policy">automatic</property>
-            <property name="vscrollbar_policy">automatic</property>
             <child>
-              <object class="GtkViewport" id="p4-l3-viewport1">
+              <object class="GtkScrolledWindow" id="p4-l3-scrolledwindow1">
                 <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="hscrollbar_policy">automatic</property>
+                <property name="vscrollbar_policy">automatic</property>
                 <child>
-                  <object class="GtkVBox" id="p4-l4-vbox1">
+                  <object class="GtkViewport" id="p4-l4-viewport1">
                     <property name="visible">True</property>
-                    <property name="orientation">vertical</property>
+                    <property name="shadow_type">GTK_SHADOW_NONE</property>
                     <child>
                       <object class="GtkVBox" id="p4-SummaryVBox">
                         <property name="visible">True</property>
                         <property name="orientation">vertical</property>
-                        <property name="spacing">10</property>
+                        <property name="spacing">8</property>
                         <child>
                           <object class="GtkLabel" id="p4-l6-label1">
                             <property name="visible">True</property>
                             <property name="xalign">0</property>
                             <property name="label" translatable="yes">Selected files have been proceeded:</property>
                             <attributes>
-                              <attribute name="weight" value="bold"/>
+                              <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
                             </attributes>
                           </object>
                           <packing>
+                            <property name="expand">False</property>
                             <property name="position">0</property>
                           </packing>
                         </child>
                       </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="position">0</property>
-                      </packing>
                     </child>
                   </object>
                 </child>



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