Changeset 219
- Timestamp:
- 06/11/06 07:51:00 (2 years ago)
- Location:
- trunk
- Files:
-
- 6 modified
-
po/POTFILES.in (modified) (1 diff)
-
src/IPrintView.h (modified) (1 diff)
-
src/PrintPter.cxx (modified) (3 diffs)
-
src/PrintPter.h (modified) (2 diffs)
-
src/gtk/PrintView.cxx (modified) (2 diffs)
-
src/gtk/PrintView.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/po/POTFILES.in
r214 r219 6 6 src/MainPter.cxx 7 7 src/PagePter.cxx 8 src/PrintPter.cxx 8 9 src/PDFDocument.cxx 9 10 # GTK+ Shell -
trunk/src/IPrintView.h
r218 r219 62 62 63 63 /// 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 /// 64 79 /// @brief Gets the number of copies to do. 65 80 /// -
trunk/src/PrintPter.cxx
r218 r219 17 17 18 18 #include <config.h> 19 #include <cups/cups.h> 20 #include <cups/ipp.h> 21 #include <locale.h> 19 22 #include "epdfview.h" 20 23 21 24 using namespace ePDFView; 25 26 // Structures 27 struct _printerAttributes 28 { 29 gchar *location; 30 gchar *state; 31 }; 22 32 23 33 PrintPter::PrintPter () … … 48 58 view->sensitivePageRange (FALSE); 49 59 60 // Retrieve and set the list of printer. 61 listPrinters (); 62 50 63 getView ().setPresenter (this); 51 64 } … … 91 104 cancelActivated (); 92 105 } 106 107 printerAttributes * 108 PrintPter::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 191 void 192 PrintPter::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 19 19 #define __PRINT_PTER_H__ 20 20 21 // Forward declarations. 22 typedef struct _printerAttributes printerAttributes; 23 21 24 namespace ePDFView 22 25 { 26 23 27 /// 24 28 /// @class PrintPter … … 41 45 protected: 42 46 IPrintView *m_View; 47 48 printerAttributes *getPrinterAttributes (const gchar *printerName); 49 void listPrinters (void); 43 50 }; 44 51 } -
trunk/src/gtk/PrintView.cxx
r218 r219 106 106 pter->cancelActivated (); 107 107 } 108 } 109 110 void 111 PrintView::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); 108 122 } 109 123 … … 324 338 gtk_container_set_border_width (GTK_CONTAINER (mainBox), 3); 325 339 326 m_PrinterList = gtk_ tree_store_new (printerListNumColumn,340 m_PrinterList = gtk_list_store_new (printerListNumColumn, 327 341 G_TYPE_STRING, 328 342 G_TYPE_STRING, -
trunk/src/gtk/PrintView.h
r218 r219 29 29 virtual void setPresenter (PrintPter *pter); 30 30 31 virtual void addPrinter (const gchar *name, int jobs, 32 const gchar *state, 33 const gchar *location); 31 34 virtual unsigned int getNumberOfCopies (void); 32 35 virtual gboolean isSelectedAllPagesRangeOption (void); … … 41 44 GtkWidget *m_PageRange; 42 45 GtkWidget *m_PrintDialog; 43 Gtk TreeStore *m_PrinterList;46 GtkListStore *m_PrinterList; 44 47 GtkWidget *m_PrinterListView; 45 48
