Speeding up the startup time of the print dialog (3/2)



It turned out that we also need to modify libgnomeprintui to
make it pick up the default printer from the GPAConfig node even
if the default printer of the GPAConfig node changes during the
asynchronous loading of the printer list. Additionally, this patch
scrolls the printer list to the initially selected printer.

Matthias


? libgnomeprintui.patch
Index: libgnomeprintui/gpaui/gpa-printer-selector.c
===================================================================
RCS file: /cvs/gnome/libgnomeprintui/libgnomeprintui/gpaui/gpa-printer-selector.c,v
retrieving revision 1.28
diff -u -r1.28 gpa-printer-selector.c
--- libgnomeprintui/gpaui/gpa-printer-selector.c	13 Aug 2004 21:05:44 -0000	1.28
+++ libgnomeprintui/gpaui/gpa-printer-selector.c	31 Aug 2004 15:38:50 -0000
@@ -292,6 +292,9 @@
 	gtk_tree_model_get (selector->model, &iter, 0, &node, -1);
 
 	gpa_node_set_path_value (selector->config, "Printer", gpa_node_id (node));
+
+	if (!selector->changing_default)
+		selector->user_selected = TRUE;
 }
 
 /**
@@ -438,17 +441,53 @@
 	gtk_list_store_set (GTK_LIST_STORE (model), iter, 0, printer, -1);
 }
 
+static gboolean
+scroll_to_selected (GPAPrinterSelector *ps)
+{
+	GtkTreeIter iter;
+	GtkTreePath *path;	
+	GtkTreeSelection *selection;
+
+	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (ps->treeview));
+	if (gtk_tree_selection_get_selected (selection, NULL, &iter)) {
+		path = gtk_tree_model_get_path (ps->sortmodel, &iter);
+		gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (ps->treeview),
+					      path, NULL, FALSE, 0.0, 0.0);
+		gtk_tree_path_free (path);
+	}
+	
+	return FALSE;
+}
+
 static void
 gpa_printer_selector_printer_added_cb (GPANode *parent, GPANode *child,
 				       GPAPrinterSelector *ps)
 {
-	GtkTreeIter iter;
+	GtkTreeIter iter, sort_iter;
+	GtkTreeSelection *selection;
+	GPANode *default_printer = NULL;
 
 	g_return_if_fail (node_to_iter (ps->model, child, &iter) == FALSE);
 
 	gtk_list_store_append (GTK_LIST_STORE (ps->model), &iter);
+
 	gpa_printer_selector_sync_printer (GTK_LIST_STORE (ps->model), &iter,
 					   GPA_PRINTER (child));
+
+ 	if (!ps->user_selected && ps->config != NULL)
+ 		default_printer = GPA_REFERENCE_REFERENCE (GPA_CONFIG (ps->config)->printer);
+ 
+ 	if (default_printer != NULL &&
+ 	    node_to_iter (ps->model, default_printer, &iter)) {
+ 		gtk_tree_model_sort_convert_child_iter_to_iter (GTK_TREE_MODEL_SORT (ps->sortmodel), 
+								&sort_iter, &iter);
+ 		selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (ps->treeview));
+		ps->changing_default = TRUE;
+ 		gtk_tree_selection_select_iter (selection, &sort_iter);
+		ps->changing_default = FALSE;
+	}
+
+	scroll_to_selected (ps);
 }
 
 static void
@@ -467,10 +506,6 @@
 {
 	GPAPrinterSelector *ps;
 	GPANode *child;
-	GtkTreeIter iter;
-	GtkTreeIter sort_iter;
-	GPANode *default_printer = NULL;
-	GtkTreeSelection *selection;
 
 	ps = GPA_PRINTER_SELECTOR (gpa);
 	ps->config = GNOME_PRINT_CONFIG_NODE (gpa->config);
@@ -484,23 +519,8 @@
 
 	child = gpa_node_get_child (ps->node, NULL);
 	while (child) {
-		GtkTreeIter iter;
-		gtk_list_store_append (GTK_LIST_STORE (ps->model), &iter);
-		gpa_printer_selector_sync_printer (GTK_LIST_STORE (ps->model),
-						   &iter,
-						   GPA_PRINTER (child));
+		gpa_printer_selector_printer_added_cb (ps->node, child, ps);
 		child = gpa_node_get_child (ps->node, child);
-	}
-
-	if (ps->config != NULL)
-		default_printer = GPA_REFERENCE_REFERENCE (GPA_CONFIG (ps->config)->printer);
-
-	if (default_printer != NULL &&
-	    node_to_iter (ps->model, default_printer, &iter), FALSE) {
-		gtk_tree_model_sort_convert_child_iter_to_iter (
-			GTK_TREE_MODEL_SORT (ps->sortmodel), &sort_iter, &iter);
-		selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (ps->treeview));
-		gtk_tree_selection_select_iter (selection, &sort_iter);
 	}
 
 	return TRUE;
Index: libgnomeprintui/gpaui/gpa-printer-selector.h
===================================================================
RCS file: /cvs/gnome/libgnomeprintui/libgnomeprintui/gpaui/gpa-printer-selector.h,v
retrieving revision 1.13
diff -u -r1.13 gpa-printer-selector.h
--- libgnomeprintui/gpaui/gpa-printer-selector.h	21 Jul 2004 02:12:38 -0000	1.13
+++ libgnomeprintui/gpaui/gpa-printer-selector.h	31 Aug 2004 15:38:50 -0000
@@ -52,6 +52,9 @@
 	GPANode *config;       /* GPAConfig */
 
 	gulong handler_config; /* signal handler of ->config "modified" signal */
+
+	guint user_selected : 1;
+	guint changing_default : 1;
 };
 
 struct _GPAPrinterSelectorClass {


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