[gnome-control-center] printers: Select the last used printer when Printers panel starts
- From: Marek Kašík <mkasik src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] printers: Select the last used printer when Printers panel starts
- Date: Tue, 18 Jan 2011 12:03:23 +0000 (UTC)
commit 21c715edd3f60fb77cbf5965357b3ab79b419d30
Author: Marek Kasik <mkasik redhat com>
Date: Wed Jan 12 14:12:03 2011 +0100
printers: Select the last used printer when Printers panel starts
panels/printers/cc-printers-panel.c | 55 +++++++++++++++++++++++++++++-----
1 files changed, 47 insertions(+), 8 deletions(-)
---
diff --git a/panels/printers/cc-printers-panel.c b/panels/printers/cc-printers-panel.c
index c722d03..8fcc60d 100644
--- a/panels/printers/cc-printers-panel.c
+++ b/panels/printers/cc-printers-panel.c
@@ -378,6 +378,8 @@ actualize_printers_list (CcPrintersPanel *self)
current_printer_instance = g_strdup (priv->dests[priv->current_dest].instance);
}
+ if (priv->num_jobs > 0)
+ cupsFreeJobs (priv->num_jobs, priv->jobs);
priv->num_dests = cupsGetDests (&priv->dests);
priv->current_dest = -1;
@@ -444,11 +446,48 @@ actualize_printers_list (CcPrintersPanel *self)
}
else
{
- if (priv->num_dests > 0 &&
- gtk_tree_model_get_iter_first ((GtkTreeModel *) store,
- &selected_iter))
+ cups_job_t *jobs = NULL;
+ int num_jobs = 0;
+
+ num_jobs = cupsGetJobs (&jobs, NULL, 1, CUPS_WHICHJOBS_ALL);
+
+ /* Select last used printer */
+ if (num_jobs > 0)
+ {
+ for (i = 0; i < priv->num_dests; i++)
+ if (g_strcmp0 (priv->dests[i].name, jobs[num_jobs - 1].dest) == 0)
+ {
+ priv->current_dest = i;
+ break;
+ }
+ cupsFreeJobs (num_jobs, jobs);
+ }
+
+ /* Select default printer */
+ if (priv->current_dest < 0)
+ {
+ for (i = 0; i < priv->num_dests; i++)
+ if (priv->dests[i].is_default)
+ {
+ priv->current_dest = i;
+ break;
+ }
+ }
+
+ /* Select first printer */
+ if (priv->current_dest < 0 && priv->num_dests > 0)
{
priv->current_dest = 0;
+ }
+
+ if (priv->current_dest >= 0)
+ {
+ GtkTreePath *path = gtk_tree_path_new_from_indices (priv->current_dest, -1);
+
+ gtk_tree_model_get_iter ((GtkTreeModel *) store,
+ &selected_iter,
+ path);
+
gtk_tree_selection_select_iter (
gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
&selected_iter);
@@ -533,16 +572,16 @@ actualize_jobs_list (CcPrintersPanel *self)
treeview = (GtkTreeView*)
gtk_builder_get_object (priv->builder, "job-treeview");
+ if (priv->num_jobs > 0)
+ cupsFreeJobs (priv->num_jobs, priv->jobs);
+ priv->num_jobs = -1;
+ priv->jobs = NULL;
+
priv->current_job = -1;
if (priv->current_dest >= 0 &&
priv->current_dest < priv->num_dests &&
priv->dests != NULL)
priv->num_jobs = cupsGetJobs (&priv->jobs, priv->dests[priv->current_dest].name, 1, CUPS_WHICHJOBS_ACTIVE);
- else
- {
- priv->num_jobs = -1;
- priv->jobs = NULL;
- }
store = gtk_list_store_new (JOB_N_COLUMNS, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]