[gnome-control-center] printers: Handle no printers situation better



commit e2f6f36b8e29efaf44ec80928cdb063276262f65
Author: Marek Kasik <mkasik redhat com>
Date:   Fri Mar 18 14:45:57 2011 +0100

    printers: Handle no printers situation better
    
    Show "No printer available" in the device list.
    Show "Add New Printer" button on the right side.
    Show appropriate message if CUPS is not running.
    Fixes #641421.

 panels/printers/cc-printers-panel.c |   87 +++++++++++++++++++++++++++++++---
 panels/printers/printers.ui         |   59 ++++++++++++++++++++++--
 2 files changed, 134 insertions(+), 12 deletions(-)
---
diff --git a/panels/printers/cc-printers-panel.c b/panels/printers/cc-printers-panel.c
index e7b5813..39af8f5 100644
--- a/panels/printers/cc-printers-panel.c
+++ b/panels/printers/cc-printers-panel.c
@@ -178,6 +178,16 @@ cc_printers_panel_class_finalize (CcPrintersPanelClass *klass)
 
 enum
 {
+  NOTEBOOK_INFO_PAGE = 0,
+  NOTEBOOK_JOBS_PAGE,
+  NOTEBOOK_OPTIONS_PAGE,
+  NOTEBOOK_NO_PRINTERS_PAGE,
+  NOTEBOOK_NO_CUPS_PAGE,
+  NOTEBOOK_N_PAGES
+};
+
+enum
+{
   PRINTER_ID_COLUMN,
   PRINTER_NAME_COLUMN,
   PRINTER_PAUSED_COLUMN,
@@ -291,6 +301,11 @@ printer_selection_changed_cb (GtkTreeSelection *selection,
       priv->current_dest < priv->num_dests &&
       priv->dests != NULL)
     {
+      widget = (GtkWidget*)
+        gtk_builder_get_object (priv->builder, "notebook");
+      if (gtk_notebook_get_current_page (GTK_NOTEBOOK (widget)) >= NOTEBOOK_NO_PRINTERS_PAGE)
+        gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), NOTEBOOK_INFO_PAGE);
+
       for (i = 0; i < priv->dests[id].num_options; i++)
         {
           if (g_strcmp0 (priv->dests[id].options[i].name, "printer-location") == 0)
@@ -549,9 +564,27 @@ printer_selection_changed_cb (GtkTreeSelection *selection,
       widget = (GtkWidget*)
         gtk_builder_get_object (priv->builder, "printer-jobs-button");
       gtk_widget_set_sensitive (widget, TRUE);
+
+      widget = (GtkWidget*)
+        gtk_builder_get_object (priv->builder, "printer-icon");
+      gtk_widget_set_sensitive (widget, TRUE);
     }
   else
     {
+      http_t *http = NULL;
+
+      widget = (GtkWidget*)
+        gtk_builder_get_object (priv->builder, "notebook");
+
+      http = httpConnectEncrypt (cupsServer (), ippPort (), cupsEncryption ());
+      if (http)
+        {
+          httpClose (http);
+          gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), NOTEBOOK_NO_PRINTERS_PAGE);
+        }
+      else
+        gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), NOTEBOOK_NO_CUPS_PAGE);
+
       widget = (GtkWidget*)
         gtk_builder_get_object (priv->builder, "printer-name-label");
       gtk_label_set_text (GTK_LABEL (widget), "");
@@ -573,6 +606,10 @@ printer_selection_changed_cb (GtkTreeSelection *selection,
       gtk_label_set_text (GTK_LABEL (widget), "");
 
       widget = (GtkWidget*)
+        gtk_builder_get_object (priv->builder, "printer-jobs-label");
+      gtk_label_set_text (GTK_LABEL (widget), "");
+
+      widget = (GtkWidget*)
         gtk_builder_get_object (priv->builder, "print-test-page-button");
       gtk_widget_set_sensitive (widget, FALSE);
 
@@ -583,6 +620,10 @@ printer_selection_changed_cb (GtkTreeSelection *selection,
       widget = (GtkWidget*)
         gtk_builder_get_object (priv->builder, "printer-jobs-button");
       gtk_widget_set_sensitive (widget, FALSE);
+
+      widget = (GtkWidget*)
+        gtk_builder_get_object (priv->builder, "printer-icon");
+      gtk_widget_set_sensitive (widget, FALSE);
     }
 
   widget = (GtkWidget*)
@@ -649,6 +690,22 @@ actualize_printers_list (CcPrintersPanel *self)
                               G_TYPE_STRING,
                               G_TYPE_STRING);
 
+  if (priv->num_dests == 0)
+    {
+      gtk_list_store_append (store, &iter);
+      gtk_list_store_set (store, &iter,
+                          PRINTER_ID_COLUMN, 0,
+      /* Translators: There are no printers available (none is configured or CUPS is not running) */
+                          PRINTER_NAME_COLUMN, _("No printers available"),
+                          PRINTER_PAUSED_COLUMN, TRUE,
+                          PRINTER_DEFAULT_ICON_COLUMN, NULL,
+                          PRINTER_ICON_COLUMN, NULL,
+                          -1);
+      gtk_widget_set_sensitive (GTK_WIDGET (treeview), FALSE);
+    }
+  else
+    gtk_widget_set_sensitive (GTK_WIDGET (treeview), TRUE);
+
   for (i = 0; i < priv->num_dests; i++)
     {
       gchar *instance;
@@ -787,10 +844,25 @@ set_cell_sensitivity_func (GtkTreeViewColumn *tree_column,
                            GtkTreeIter       *iter,
                            gpointer           func_data)
 {
+  CcPrintersPanelPrivate *priv;
+  CcPrintersPanel        *self = (CcPrintersPanel*) func_data;
   gboolean                paused = FALSE;
 
+  priv = PRINTERS_PANEL_PRIVATE (self);
+
   gtk_tree_model_get (tree_model, iter, PRINTER_PAUSED_COLUMN, &paused, -1);
 
+  if (priv->num_dests == 0)
+    g_object_set (G_OBJECT (cell),
+                  "ellipsize", PANGO_ELLIPSIZE_NONE,
+                  "width-chars", -1,
+                  NULL);
+  else
+    g_object_set (G_OBJECT (cell),
+                  "ellipsize", PANGO_ELLIPSIZE_END,
+                  "width-chars", 18,
+                  NULL);
+
   if (paused)
     g_object_set (cell,
                   "sensitive", FALSE,
@@ -1897,6 +1969,9 @@ on_permission_changed (GPermission *permission,
   widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "printer-add-button");
   gtk_widget_set_sensitive (widget, is_authorized);
 
+  widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "printer-add-button2");
+  gtk_widget_set_sensitive (widget, is_authorized);
+
   widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "printer-remove-button");
   gtk_widget_set_sensitive (widget, is_authorized);
 
@@ -1913,14 +1988,6 @@ on_permission_changed (GPermission *permission,
   gtk_widget_set_sensitive (widget, is_authorized);
 }
 
-enum
-{
-  NOTEBOOK_INFO_PAGE = 0,
-  NOTEBOOK_JOBS_PAGE,
-  NOTEBOOK_OPTIONS_PAGE,
-  NOTEBOOK_N_PAGES
-};
-
 static void
 go_back_cb (GtkButton *button,
             gpointer   user_data)
@@ -2030,6 +2097,10 @@ cc_printers_panel_init (CcPrintersPanel *self)
   g_signal_connect (widget, "clicked", G_CALLBACK (printer_add_cb), self);
 
   widget = (GtkWidget*)
+    gtk_builder_get_object (priv->builder, "printer-add-button2");
+  g_signal_connect (widget, "clicked", G_CALLBACK (printer_add_cb), self);
+
+  widget = (GtkWidget*)
     gtk_builder_get_object (priv->builder, "printer-remove-button");
   g_signal_connect (widget, "clicked", G_CALLBACK (printer_remove_cb), self);
 
diff --git a/panels/printers/printers.ui b/panels/printers/printers.ui
index a546a56..07dba5a 100644
--- a/panels/printers/printers.ui
+++ b/panels/printers/printers.ui
@@ -271,7 +271,7 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkImage" id="image1">
+                      <object class="GtkImage" id="printer-icon">
                         <property name="visible">True</property>
                         <property name="xalign">1</property>
                         <property name="pixel_size">64</property>
@@ -437,7 +437,7 @@
             <child type="tab">
               <object class="GtkLabel" id="label2">
                 <property name="visible">True</property>
-                <property name="label" translatable="yes">Info</property>
+                <property name="label">Info</property>
               </object>
               <packing>
                 <property name="tab_fill">False</property>
@@ -580,7 +580,7 @@
             <child type="tab">
               <object class="GtkLabel" id="label4">
                 <property name="visible">True</property>
-                <property name="label" translatable="yes">Jobs</property>
+                <property name="label">Jobs</property>
               </object>
               <packing>
                 <property name="position">1</property>
@@ -741,13 +741,64 @@
             <child type="tab">
               <object class="GtkLabel" id="label5">
                 <property name="visible">True</property>
-                <property name="label" translatable="yes">Options</property>
+                <property name="label">Options</property>
               </object>
               <packing>
                 <property name="position">2</property>
                 <property name="tab_fill">False</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkHButtonBox" id="hbuttonbox2">
+                <property name="visible">True</property>
+                <child>
+                  <object class="GtkButton" id="printer-add-button2">
+                    <property name="label" translatable="yes" comments="Translators: This button adds new printer.">Add New Printer</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="position">3</property>
+              </packing>
+            </child>
+            <child type="tab">
+              <object class="GtkLabel" id="label21">
+                <property name="visible">True</property>
+                <property name="label">No printers</property>
+              </object>
+              <packing>
+                <property name="position">3</property>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="no-cups-label">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes" comments="Translators: The CUPS server is not running (we can not connect to it).">The printing service (CUPS) is not running,
+please check with your system administrator.</property>
+              </object>
+              <packing>
+                <property name="position">4</property>
+              </packing>
+            </child>
+            <child type="tab">
+              <object class="GtkLabel" id="label9">
+                <property name="visible">True</property>
+                <property name="label">No cups</property>
+              </object>
+              <packing>
+                <property name="position">4</property>
+                <property name="tab_fill">False</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="position">1</property>



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