Changeset 220

Show
Ignore:
Timestamp:
06/11/06 09:47:12 (2 years ago)
Author:
jordi
Message:

The Print Dialog now selects a printer (default printer or the first, if there's no default.) Also, when there's no printers available the Print button is insensitived.

Location:
trunk/src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/IPrintView.h

    r219 r220  
    9393 
    9494            /// 
     95            /// @brief Selects a printer from the list. 
     96            /// 
     97            /// @param printerIndex The index of the printer to select. 
     98            /// 
     99            virtual void selectPrinter (unsigned int printerIndex) = 0; 
     100 
     101            /// 
    95102            /// @brief Changes the sensitivity of the "Collate" option. 
    96103            /// 
     
    114121            virtual void sensitivePageRange (gboolean sensitive) = 0; 
    115122 
     123            /// 
     124            /// @brief Changes the sensitivity of the "Print" button. 
     125            /// 
     126            /// The view must change the sensitivity (it's called enabled or 
     127            /// disabled on some toolkits) of the "Print" button. 
     128            /// 
     129            /// @param sensitive Set to TRUE if need to sensitive (enable) the 
     130            ///                  button or FALSE to insensitive (disable) it. 
     131            /// 
     132            virtual void sensitivePrintButton (gboolean sensitive) = 0; 
     133 
     134 
    116135        protected: 
    117136            /// The presenter that controls the view. 
  • trunk/src/PrintPter.cxx

    r219 r220  
    192192PrintPter::listPrinters (void) 
    193193{ 
     194    IPrintView &view = getView (); 
     195 
    194196    cups_dest_t *destinations; 
    195197    int numDestinations = cupsGetDests (&destinations); 
     198    // For now we don't have any printer selected. 
     199    int printerToSelect = -1; 
    196200 
    197201    for ( int currentDestination = 0 ; currentDestination < numDestinations ; 
     
    207211        printerAttributes *attributes = getPrinterAttributes (printerName); 
    208212        // Set all this data to the view. 
    209         getView ().addPrinter (printerName, numJobs, 
     213        view.addPrinter (printerName, numJobs, 
    210214                               attributes->state, attributes->location); 
    211215        g_free (attributes->location); 
    212216        g_free (attributes->state); 
    213217        delete attributes; 
    214     } 
    215  
     218 
     219        // If the printer is the default and we don't have any printer 
     220        // selected, then we should select it. 
     221        if ( -1 == printerToSelect && 
     222             destinations[currentDestination].is_default ) 
     223        { 
     224            printerToSelect = currentDestination; 
     225        } 
     226    } 
    216227    cupsFreeDests (numDestinations, destinations); 
    217 } 
     228 
     229    // If not printer is available, insensitive the print button. 
     230    if ( 0 == numDestinations ) 
     231    { 
     232        view.sensitivePrintButton (FALSE); 
     233    } 
     234    // Otherwise select a printer: the previously used, the default or  
     235    // the first. 
     236    else 
     237    { 
     238        if ( -1 == printerToSelect ) 
     239        { 
     240            view.selectPrinter (0); 
     241        } 
     242        else 
     243        { 
     244            view.selectPrinter (printerToSelect); 
     245        } 
     246    } 
     247} 
  • trunk/src/gtk/PrintView.cxx

    r219 r220  
    135135 
    136136void 
     137PrintView::selectPrinter (unsigned int printerIndex) 
     138{ 
     139    gchar *pathString = g_strdup_printf ("%d", printerIndex); 
     140    GtkTreeIter printerIter; 
     141    if ( gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (m_PrinterList), 
     142                                              &printerIter, pathString) ) 
     143    { 
     144        GtkTreeSelection *selection = 
     145            gtk_tree_view_get_selection (GTK_TREE_VIEW (m_PrinterListView)); 
     146        gtk_tree_selection_select_iter (selection, &printerIter); 
     147    } 
     148    g_free (pathString); 
     149} 
     150 
     151void 
    137152PrintView::sensitiveCollate (gboolean sensitive) 
    138153{ 
     
    144159{ 
    145160    gtk_widget_set_sensitive (m_PageRange, sensitive); 
     161} 
     162 
     163void 
     164PrintView::sensitivePrintButton (gboolean sensitive) 
     165{ 
     166    gtk_dialog_set_response_sensitive (GTK_DIALOG (m_PrintDialog), 
     167                                       GTK_RESPONSE_ACCEPT, sensitive); 
    146168} 
    147169 
  • trunk/src/gtk/PrintView.h

    r219 r220  
    3434            virtual unsigned int getNumberOfCopies (void); 
    3535            virtual gboolean isSelectedAllPagesRangeOption (void); 
     36            virtual void selectPrinter (unsigned int printerInde); 
    3637            virtual void sensitiveCollate (gboolean sensitive); 
    3738            virtual void sensitivePageRange (gboolean sensitive); 
     39            virtual void sensitivePrintButton (gboolean sensitive); 
    3840 
    3941        protected: