[gnome-control-center] printers: Don't sort printers by usage
- From: Marek Kašík <mkasik src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] printers: Don't sort printers by usage
- Date: Fri, 18 Mar 2011 11:57:08 +0000 (UTC)
commit bedb8e12183f421a4f433d0e6e4bcfda57dd78db
Author: Marek Kasik <mkasik redhat com>
Date: Fri Mar 18 12:55:18 2011 +0100
printers: Don't sort printers by usage
It is very inefficient to get all jobs when there are
thousands of them. Sort it alphabetically.
panels/printers/cc-printers-panel.c | 86 +----------------------------------
1 files changed, 1 insertions(+), 85 deletions(-)
---
diff --git a/panels/printers/cc-printers-panel.c b/panels/printers/cc-printers-panel.c
index aa2d9f0..e7b5813 100644
--- a/panels/printers/cc-printers-panel.c
+++ b/panels/printers/cc-printers-panel.c
@@ -183,7 +183,6 @@ enum
PRINTER_PAUSED_COLUMN,
PRINTER_DEFAULT_ICON_COLUMN,
PRINTER_ICON_COLUMN,
- PRINTER_IS_SEPARATOR_COLUMN,
PRINTER_N_COLUMNS
};
@@ -599,26 +598,6 @@ printer_selection_changed_cb (GtkTreeSelection *selection,
gtk_widget_set_sensitive (widget, FALSE);
}
-typedef struct {
- gint printer_id;
- gint usage;
-} PrinterUsage;
-
-static gint
-printer_usage_cmp (gconstpointer a,
- gconstpointer b)
-{
- PrinterUsage *x = (PrinterUsage*) a;
- PrinterUsage *y = (PrinterUsage*) b;
-
- if (x->usage < y->usage)
- return 1;
- else if (x->usage == y->usage)
- return 0;
- else
- return -1;
-}
-
static void
actualize_printers_list (CcPrintersPanel *self)
{
@@ -628,16 +607,12 @@ actualize_printers_list (CcPrintersPanel *self)
GtkTreeView *treeview;
GtkTreeIter iter;
cups_job_t *jobs = NULL;
- gboolean has_used_printer = FALSE;
- gboolean has_separator = FALSE;
gboolean paused = FALSE;
gboolean valid = FALSE;
gchar *current_printer_instance = NULL;
gchar *current_printer_name = NULL;
gchar *printer_icon_name = NULL;
gchar *default_icon_name = NULL;
- GList *tmp_list = NULL;
- GList *usages = NULL;
int current_dest = -1;
int i, j;
int num_jobs = 0;
@@ -672,47 +647,12 @@ actualize_printers_list (CcPrintersPanel *self)
G_TYPE_STRING,
G_TYPE_BOOLEAN,
G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_BOOLEAN);
+ G_TYPE_STRING);
for (i = 0; i < priv->num_dests; i++)
{
- PrinterUsage *usage = g_new (PrinterUsage, 1);
- num_jobs = cupsGetJobs (&jobs, priv->dests[i].name, 1, CUPS_WHICHJOBS_ALL);
- usage->printer_id = i;
- usage->usage = num_jobs;
- usages = g_list_append (usages, usage);
- cupsFreeJobs (num_jobs, jobs);
- }
- num_jobs = 0;
- jobs = NULL;
-
- usages = g_list_sort (usages, printer_usage_cmp);
-
- for (tmp_list = usages; tmp_list; tmp_list = tmp_list->next)
- {
gchar *instance;
- i = ((PrinterUsage*) tmp_list->data)->printer_id;
- if (((PrinterUsage*) tmp_list->data)->usage == 0)
- {
- if (!has_separator && has_used_printer)
- {
- has_separator = TRUE;
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- PRINTER_ID_COLUMN, -1,
- PRINTER_NAME_COLUMN, NULL,
- PRINTER_PAUSED_COLUMN, FALSE,
- PRINTER_DEFAULT_ICON_COLUMN, FALSE,
- PRINTER_ICON_COLUMN, NULL,
- PRINTER_IS_SEPARATOR_COLUMN, TRUE,
- -1);
- }
- }
- else
- has_used_printer = TRUE;
-
gtk_list_store_append (store, &iter);
if (priv->dests[i].instance)
@@ -758,14 +698,12 @@ actualize_printers_list (CcPrintersPanel *self)
PRINTER_PAUSED_COLUMN, paused,
PRINTER_DEFAULT_ICON_COLUMN, default_icon_name,
PRINTER_ICON_COLUMN, printer_icon_name,
- PRINTER_IS_SEPARATOR_COLUMN, FALSE,
-1);
g_free (instance);
g_free (printer_icon_name);
g_free (default_icon_name);
}
- g_list_free_full (usages, g_free);
gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (store));
@@ -863,23 +801,6 @@ set_cell_sensitivity_func (GtkTreeViewColumn *tree_column,
NULL);
}
-static gboolean
-printers_row_separator_func (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- gboolean separator;
-
- gtk_tree_model_get (model,
- iter,
- PRINTER_IS_SEPARATOR_COLUMN,
- &separator,
- -1);
-
- return separator;
-}
-
-
static void
populate_printers_list (CcPrintersPanel *self)
{
@@ -925,11 +846,6 @@ populate_printers_list (CcPrintersPanel *self)
"icon-name", PRINTER_DEFAULT_ICON_COLUMN, NULL);
gtk_tree_view_column_set_expand (column, FALSE);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
-
- gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (treeview),
- printers_row_separator_func,
- NULL,
- NULL);
}
enum
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]