Changeset 219

Show
Ignore:
Timestamp:
06/11/06 07:51:00 (2 years ago)
Author:
jordi
Message:

The PrintPter? class now retrieves the list of printers from cups and sends them to the view. I also added the PrintPter?.cxx function in the POTFILES file.

Location:
trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/po/POTFILES.in

    r214 r219  
    66src/MainPter.cxx 
    77src/PagePter.cxx 
     8src/PrintPter.cxx 
    89src/PDFDocument.cxx 
    910# GTK+ Shell 
  • trunk/src/IPrintView.h

    r218 r219  
    6262 
    6363            /// 
     64            /// @brief Adds a new printer to the list of printer. 
     65            /// 
     66            /// The presenter will get the list of printers from the 
     67            /// system and call this function for each one it finds. 
     68            /// 
     69            /// @param name The name of the printer. 
     70            /// @param job The number of jobs the printer currently has active. 
     71            /// @param state The current printer's state. 
     72            /// @param location The printer's location. 
     73            /// 
     74            virtual void addPrinter (const gchar *name, int jobs, 
     75                                     const gchar *state, 
     76                                     const gchar *location) = 0; 
     77 
     78            /// 
    6479            /// @brief Gets the number of copies to do. 
    6580            /// 
  • trunk/src/PrintPter.cxx

    r218 r219  
    1717 
    1818#include <config.h> 
     19#include <cups/cups.h> 
     20#include <cups/ipp.h> 
     21#include <locale.h> 
    1922#include "epdfview.h" 
    2023 
    2124using namespace ePDFView; 
     25 
     26// Structures 
     27struct _printerAttributes 
     28{ 
     29    gchar *location; 
     30    gchar *state; 
     31}; 
    2232 
    2333PrintPter::PrintPter () 
     
    4858    view->sensitivePageRange (FALSE); 
    4959 
     60    // Retrieve and set the list of printer. 
     61    listPrinters (); 
     62 
    5063    getView ().setPresenter (this); 
    5164} 
     
    91104    cancelActivated (); 
    92105} 
     106 
     107printerAttributes * 
     108PrintPter::getPrinterAttributes (const gchar *printerName) 
     109{ 
     110    // Create and empty attributes structure. 
     111    printerAttributes *attributes = new printerAttributes (); 
     112    attributes->state = NULL; 
     113    attributes->location = NULL; 
     114 
     115    // The attributes to request from the server. 
     116    const gchar *attributesToRequest[] = 
     117    { 
     118        "printer-state", 
     119        "printer-location" 
     120    }; 
     121 
     122    http_t *http = httpConnect (cupsServer (), ippPort ()); 
     123    if ( NULL == http ) 
     124    { 
     125        printf ("No http!\n"); 
     126        return attributes; 
     127    } 
     128 
     129    ipp_t *request = ippNew (); 
     130 
     131    request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES; 
     132    request->request.op.request_id = 1; 
     133 
     134    ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 
     135                  "attributes-charset", NULL, "utf-8"); 
     136    ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, 
     137                  "attributes-natural-language", NULL, 
     138                  setlocale (LC_MESSAGES, NULL)); 
     139    ippAddStrings (request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, 
     140                   "requested-attributes", G_N_ELEMENTS (attributesToRequest), 
     141                   NULL, attributesToRequest); 
     142    gchar *uri = g_strdup_printf ("ipp://localhost/printers/%s", printerName); 
     143    ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI, 
     144                  "printer-uri", NULL, uri); 
     145 
     146    ipp_t *answer = cupsDoRequest (http, request, "/"); 
     147    if ( NULL != answer ) 
     148    { 
     149        // Get the state. 
     150        ipp_attribute_t *state = 
     151            ippFindAttribute (answer, "printer-state", IPP_TAG_ZERO); 
     152        if ( NULL != state ) 
     153        { 
     154            switch (state->values[0].integer) 
     155            { 
     156                case IPP_PRINTER_IDLE: 
     157                    attributes->state = g_strdup (_("Idle")); 
     158                    break; 
     159                case IPP_PRINTER_STOPPED: 
     160                    attributes->state = g_strdup (_("Stopped")); 
     161                    break; 
     162                case IPP_PRINTER_PROCESSING: 
     163                    attributes->state = g_strdup (_("Processing")); 
     164                    break; 
     165                default: 
     166                    attributes->state = g_strdup (_("Unknown")); 
     167                    break; 
     168            } 
     169        } 
     170 
     171        // Get the location. 
     172        ipp_attribute_t *location = 
     173            ippFindAttribute (answer, "printer-location", IPP_TAG_ZERO); 
     174        if ( NULL != location ) 
     175        { 
     176            attributes->location = g_strdup (location->values[0].string.text); 
     177        } 
     178 
     179        ippDelete (answer); 
     180    } 
     181    else 
     182    { 
     183        printf ("No answer!\n"); 
     184    } 
     185 
     186    httpClose (http); 
     187    g_free (uri); 
     188    return attributes; 
     189} 
     190 
     191void 
     192PrintPter::listPrinters (void) 
     193{ 
     194    cups_dest_t *destinations; 
     195    int numDestinations = cupsGetDests (&destinations); 
     196 
     197    for ( int currentDestination = 0 ; currentDestination < numDestinations ; 
     198          ++currentDestination ) 
     199    { 
     200        // Get the printer name. 
     201        gchar *printerName = destinations[currentDestination].name; 
     202        // Get the number of jobs the printer currently has. 
     203        cups_job_t *destinationJobs; 
     204        int numJobs = cupsGetJobs (&destinationJobs, printerName, 1, 0); 
     205        cupsFreeJobs (numJobs, destinationJobs); 
     206        // Get the state and location. 
     207        printerAttributes *attributes = getPrinterAttributes (printerName); 
     208        // Set all this data to the view. 
     209        getView ().addPrinter (printerName, numJobs, 
     210                               attributes->state, attributes->location); 
     211        g_free (attributes->location); 
     212        g_free (attributes->state); 
     213        delete attributes; 
     214    } 
     215 
     216    cupsFreeDests (numDestinations, destinations); 
     217} 
  • trunk/src/PrintPter.h

    r218 r219  
    1919#define __PRINT_PTER_H__ 
    2020 
     21// Forward declarations. 
     22typedef struct _printerAttributes printerAttributes; 
     23 
    2124namespace ePDFView 
    2225{ 
     26 
    2327    /// 
    2428    /// @class PrintPter 
     
    4145        protected: 
    4246            IPrintView *m_View; 
     47 
     48            printerAttributes *getPrinterAttributes (const gchar *printerName); 
     49            void listPrinters (void); 
    4350    }; 
    4451} 
  • trunk/src/gtk/PrintView.cxx

    r218 r219  
    106106        pter->cancelActivated (); 
    107107    } 
     108} 
     109 
     110void 
     111PrintView::addPrinter (const gchar *name, int jobs, const gchar *state, 
     112                       const gchar *location) 
     113{ 
     114    GtkTreeIter printerIter; 
     115    gtk_list_store_append (GTK_LIST_STORE (m_PrinterList), &printerIter); 
     116    gtk_list_store_set (GTK_LIST_STORE (m_PrinterList), &printerIter, 
     117                        printerListNameColumn, name, 
     118                        printerListJobsColumn, jobs, 
     119                        printerListStateColumn, state, 
     120                        printerListLocationColumn, location, 
     121                        -1); 
    108122} 
    109123 
     
    324338    gtk_container_set_border_width (GTK_CONTAINER (mainBox), 3); 
    325339 
    326     m_PrinterList = gtk_tree_store_new (printerListNumColumn, 
     340    m_PrinterList = gtk_list_store_new (printerListNumColumn, 
    327341                                        G_TYPE_STRING, 
    328342                                        G_TYPE_STRING, 
  • trunk/src/gtk/PrintView.h

    r218 r219  
    2929            virtual void setPresenter (PrintPter *pter); 
    3030 
     31            virtual void addPrinter (const gchar *name, int jobs, 
     32                                     const gchar *state, 
     33                                     const gchar *location); 
    3134            virtual unsigned int getNumberOfCopies (void); 
    3235            virtual gboolean isSelectedAllPagesRangeOption (void); 
     
    4144            GtkWidget *m_PageRange; 
    4245            GtkWidget *m_PrintDialog; 
    43             GtkTreeStore *m_PrinterList; 
     46            GtkListStore *m_PrinterList; 
    4447            GtkWidget *m_PrinterListView; 
    4548