/* * call-seq: * Cups.options_for(name) -> Hash or nil * * Get all options from CUPS server with name. Returns a hash with key/value pairs * based on server options, or nil if no server with name. */ static VALUE cups_get_options(VALUE self, VALUE printer) { // Don't have to lift a finger unless the printer exists. if (!printer_exists(printer)){ rb_raise(rb_eRuntimeError, "The printer or destination doesn't exist!"); } VALUE options_list; int i; char *printer_arg = RSTRING_PTR(printer); options_list = rb_hash_new(); cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = cupsGetDest(printer_arg, NULL, num_dests, dests); if (dest == NULL) { cupsFreeDests(num_dests, dests); return Qnil; } else { for(i =0; i< dest->num_options; i++) { rb_hash_aset(options_list, rb_str_new2(dest->options[i].name), rb_str_new2(dest->options[i].value)); } cupsFreeDests(num_dests, dests); return options_list; } }
/* * call-seq: * Cups.options_for(name) -> Hash or nil * * Get all options from CUPS server with name. Returns a hash with key/value pairs * based on server options, or nil if no server with name. */ static VALUE cups_get_options(VALUE self, VALUE printer) { VALUE options_list; int i; char *printer_arg = RSTRING_PTR(printer); options_list = rb_hash_new(); cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = cupsGetDest(printer_arg, NULL, num_dests, dests); if (dest == NULL) { cupsFreeDests(num_dests, dests); return Qnil; } else { for(i =0; i< dest->num_options; i++) { rb_hash_aset(options_list, rb_str_new2(dest->options[i].name), rb_str_new2(dest->options[i].value)); } cupsFreeDests(num_dests, dests); return options_list; } }
void pp_options_dialog_free (PpOptionsDialog *dialog) { gtk_widget_destroy (GTK_WIDGET (dialog->dialog)); dialog->dialog = NULL; g_object_unref (dialog->builder); dialog->builder = NULL; g_free (dialog->printer_name); dialog->printer_name = NULL; if (dialog->ppd_filename) { g_unlink (dialog->ppd_filename); g_free (dialog->ppd_filename); dialog->ppd_filename = NULL; } if (dialog->destination) { cupsFreeDests (1, dialog->destination); dialog->destination = NULL; } if (dialog->ipp_attributes) { g_hash_table_unref (dialog->ipp_attributes); dialog->ipp_attributes = NULL; } g_free (dialog); }
int GetDevices ( http_t * http, char *** list, oyAlloc_f allocateFunc ) { cups_dest_t *dests, *dest; int num_dests; int i, p; int len; char ** texts; /* Open access to printer(s) installed on system. */ num_dests = cupsGetDests2(http, &dests); len = sizeof(char*) * num_dests; texts = allocateFunc( len ); memset( texts, 0, len ); /* Use CUPS to obtain printer name(s) on the default server. */ for (p = 0, i = num_dests, dest = dests; i > 0; i--, dest++, p++) { texts[p] = allocateFunc(strlen(dest->name)+1); sprintf( texts[p], "%s", dest->name ); } /* Free memory that is used by CUPS. */ cupsFreeDests (num_dests, dests); /* Return printer name(s) and the number of printers installed on system. */ *list = texts; return num_dests; }
static int _detect_printers_callback(dt_job_t *job) { dt_prtctl_t *pctl = dt_control_job_get_params(job); int res; #if ((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 6)) || CUPS_VERSION_MAJOR > 1 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 if (cupsEnumDests != NULL) #endif res = cupsEnumDests(CUPS_MEDIA_FLAGS_DEFAULT, 30000, &_cancel, 0, 0, _dest_cb, pctl); #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 else #endif #endif #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 || !(((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 6)) || CUPS_VERSION_MAJOR > 1) { cups_dest_t *dests; const int num_dests = cupsGetDests(&dests); for (int k=0; k<num_dests; k++) { _dest_cb((void *)pctl, 0, &dests[k]); } cupsFreeDests(num_dests, dests); res=1; } #endif return !res; }
gboolean is_printer_available(void) { cups_dest_t *dests; const int num_dests = cupsGetDests(&dests); cupsFreeDests(num_dests, dests); return (gboolean) num_dests > 0; }
QPpdPrintDevice::~QPpdPrintDevice() { if (m_ppd) ppdClose(m_ppd); if (m_cupsDest) cupsFreeDests(1, m_cupsDest); m_cupsDest = 0; m_ppd = 0; }
int cngplpInitOptions(cngplpData *data) { cups_dest_t *all_dests; cups_dest_t *curr_dest; int num; num = cupsGetDests(&all_dests); if(data->curr_printer == NULL) return -1; curr_dest = cupsGetDest(data->curr_printer, NULL, num, all_dests); if(curr_dest == NULL) return -1; data->cups_opt = (CupsOptions *)malloc(sizeof(CupsOptions)); if(data->cups_opt == NULL) return -1; if(CreateCupsOptions(data) < 0){ MemFree(data->cups_opt); return -1; } SetCupsStoreOption(data, curr_dest); data->ppd_opt = (PPDOptions *)malloc(sizeof(PPDOptions)); if(data->ppd_opt == NULL){ DeleteCupsOptions(data->cups_opt); return -1; } if(CreatePPDOptions(data) < 0){ DeleteCupsOptions(data->cups_opt); DeletePPDOptions(data); return -1; } if(data->ppdfile){ SetPPDStoreOption(data, curr_dest); } if(data->ppd_opt->uivalue != NULL){ SetPPDStoreUIValue(data, curr_dest); } if(CreateSaveOptions(data) < 0){ DeleteCupsOptions(data->cups_opt); DeletePPDOptions(data); return -1; } cupsFreeDests(num, all_dests); return 0; }
QStringList PrinterUtil::getPrinterNames() { QString printerName; QStringList printerNames; #if defined (HAVE_CUPS) cups_dest_t *dests; int num_dests = cupsGetDests(&dests); for (int pr = 0; pr < num_dests; ++pr) { printerName = QString(dests[pr].name); printerNames.append(printerName); } cupsFreeDests(num_dests, dests); #elif defined(_WIN32) DWORD size; DWORD numPrinters; PRINTER_INFO_2W* printerInfos = NULL; EnumPrintersW ( PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS , NULL, 2, NULL, 0, &size, &numPrinters ); printerInfos = (PRINTER_INFO_2W*) malloc(size); if ( EnumPrintersW ( PRINTER_ENUM_LOCAL|PRINTER_ENUM_CONNECTIONS, NULL, 2, (LPBYTE) printerInfos, size, &size, &numPrinters ) ) { for ( uint i = 0; i < numPrinters; i++) { printerName = QString::fromUtf16( (const ushort*) printerInfos[i].pPrinterName ); printerNames.append(printerName); } printerNames.sort(); } if ( printerInfos) free(printerInfos); #else QString tmp; QString Pcap; QStringList wt; if (loadText("/etc/printcap", &Pcap)) { QDataStream ts(&Pcap, QIODevice::ReadOnly); while(!ts.atEnd()) { tmp = readLinefromDataStream(ts); if (tmp.isEmpty()) continue; if ((tmp[0] != '#') && (tmp[0] != ' ') && (tmp[0] != '\n') && (tmp[0] != '\t')) { tmp = tmp.trimmed(); tmp = tmp.left(tmp.length() - (tmp.right(2) == ":\\" ? 2 : 1)); wt = tmp.split("|", QString::SkipEmptyParts); printerName = wt[0]; printerNames.append(printerName); } } } #endif return printerNames; }
void ofxCUPS::addOption(string optionKey, string optionValue) { cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = cupsGetDest(printerName.c_str(), NULL, num_dests, dests); int num_options = 0; cups_option_t *options = (cups_option_t *)0; num_options = cupsAddOption(optionKey.c_str(), optionValue.c_str(), num_options, &options); cupsFreeDests(num_dests, dests); }
/* * call-seq: * Cups.show_destinations -> Array * * Show all destinations on the default server */ static VALUE cups_show_dests(VALUE self) { VALUE dest_list; int i; int num_dests = cupsGetDests(&dests); // Size of dest_list array dest_list = rb_ary_new2(num_dests); for (i = num_dests, dest = dests; i > 0; i --, dest ++) { VALUE destination = rb_str_new2(dest->name); rb_ary_push(dest_list, destination); // Add this testination name to dest_list string } cupsFreeDests(num_dests, dests); return dest_list; }
void ofxCUPS::updatePrinterInfo() { cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = cupsGetDest(printerName.c_str(), NULL, num_dests, dests); const char *value; value = cupsGetOption("printer-state", dest->num_options, dest->options); // printf("%s printer-state: %s\n", dest->name, value ? value : "no description"); setPrinterState(ofToInt(value)); value = cupsGetOption("printer-state-reasons", dest->num_options, dest->options); // printf("%s printer-state-reasons: %s\n", dest->name, value ? value : "(no description)"); setPrinterInfo(ofToString(value)); cupsFreeDests(num_dests, dests); }
static void get_named_dest_cb (cups_dest_t *dest, gpointer user_data) { PpOptionsDialog *dialog = (PpOptionsDialog *) user_data; if (dialog->destination) cupsFreeDests (1, dialog->destination); dialog->destination = dest; dialog->destination_set = TRUE; if (dialog->ppd_filename_set && dialog->ipp_attributes_set) { populate_options_real (dialog); } }
int GetAllPrinters() { cups_dest_t *all_dests = NULL; cups_dest_t *curr_dest = NULL; PrintersInfo *printers = NULL; int num = 0, i = 0; PrinterInfo *info = NULL; num = cupsGetDests(&all_dests); if(0 == num){ return -1; } printers = (PrintersInfo*)malloc(sizeof(PrintersInfo)); if(NULL == printers){ return -1; } memset(printers, 0, sizeof(PrintersInfo)); g_printers = printers; curr_dest = all_dests; for(i = 0; i < num; i++){ if(curr_dest->name != NULL){ info = GetPrinterInfo((char*)curr_dest->name); if(info != NULL){ printers->printer_list = g_list_append(printers->printer_list, info); if(TRUE == curr_dest->is_default){ printers->curr_printer = info; } } } curr_dest++; } if(0 == g_list_length(printers->printer_list)) { return -1; } if(NULL == printers->curr_printer){ printers->curr_printer = g_list_nth_data(printers->printer_list, 0); } cupsFreeDests(num, all_dests); return 0; }
int printer_hw_register_auto(PDEVMAN pDevman, PDEVMAN_ENTRY_POINTS pEntryPoints, SERVICE * srv, int * port) { cups_dest_t *dests; cups_dest_t *dest; int num_dests; int i; num_dests = cupsGetDests(&dests); for (i = 0, dest = dests; i < num_dests; i++, dest++) { if (dest->instance == NULL) { printer_register(pDevman, pEntryPoints, srv, dest->name, NULL, dest->is_default, port); } } cupsFreeDests(num_dests, dests); return 0; }
static void printer_add_real_async_cb (cups_dest_t *destination, gpointer user_data) { PpNewPrinter *printer = (PpNewPrinter *) user_data; gboolean success = FALSE; if (destination) { success = TRUE; cupsFreeDests (1, destination); } if (success) { printer_configure_async (printer); } else { _pp_new_printer_add_async_cb (FALSE, printer); } }
void ofxCUPS::updatePrinterInfo() { cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = NULL; dest = cupsGetDest(printerName.c_str(), NULL, num_dests, dests); if ( dest == NULL) { ofLogError() << "NO PRINTER - PRINTER NAME >> [" << printerName << "]" <<endl; return; } const char *value; value = cupsGetOption("printer-state", dest->num_options, dest->options); // printf("%s printer-state: %s\n", dest->name, value ? value : "no description"); setPrinterState(ofToInt(value)); value = cupsGetOption("printer-state-reasons", dest->num_options, dest->options); // printf("%s printer-state-reasons: %s\n", dest->name, value ? value : "(no description)"); setPrinterInfo(ofToString(value)); cupsFreeDests(num_dests, dests); }
int main(int argc, char *agrv[]) { // int fd = open("/home/cww/tt", O_CREAT | O_RDWR); // write(fd, "123", 4); // close(fd); cups_dest_t *dests; int num_dests = cupsGetDests(&dests); int i; for (i = 0;i < num_dests;i++) { cups_dest_t *t = dests + i; if (t != NULL) { printf("#%d:name = %s, instance=%s\n", i, t->name, t->instance); } } printf("num_dests = %d\n", num_dests); cups_dest_t *dest = cupsGetDest(NULL, NULL, num_dests, dests); if (dest != NULL) { printf("name = %s, instance = %s\n", dest->name, dest->instance); } cupsFreeDests(num_dests, dests); /* int job_id; //if ((job_id = cupsPrintFile("Brother_HL-1208_Printer:4", "/home/cww/pcms-0.01/test/main.c", "title_test" ,0, NULL)) == 0) { if ((job_id = cupsPrintFile("CUPS-PDF", "/home/cww/Desktop/copy2.ps", "copy2_test" ,0, NULL)) == 0) { //perror("cupsPrintFile() error"); puts(cupsLastErrorString()); exit(1); } printf("job_id = %d\n", job_id); */ return 0; }
int GetPrinterInfo(cngplpData *data) { cups_dest_t *all_dests; cups_dest_t *curr_dest; int num, i; num = cupsGetDests(&all_dests); if(num == 0) return -1; data->printer_num = num; data->printer_names = (char **)malloc(sizeof(char *) * num); if(data->printer_names == NULL) return -1; curr_dest = all_dests; for(i = 0; i < num; i++){ if(curr_dest->name != NULL) data->printer_names[i] = strdup(curr_dest->name); else data->printer_names[i] = NULL; curr_dest++; } data->curr_printer = data->printer_names[0]; curr_dest = all_dests; for(i = 0; i < num; i++){ if(curr_dest->is_default){ data->curr_printer = data->printer_names[i]; break; } curr_dest++; } cupsFreeDests(num, all_dests); return 0; }
/////////////////////////////////////////////////////////////////////////////////////////// // // CS : PUBLIC gint getDefaultPrinterName(gchar *pDestName, gint bufSize) // IN : gint bufSize : Size of buffer for default printer name. // OUT : gchar *pDestName : Default printer name of CUPS. // RETURN : ID_ERR_NO_ERROR : No error. // ID_ERR_CUPS_API_FAILED : Error occured in CUPS API. // ID_ERR_NO_PRINTER_ADDED : No printer registered into CUPS. // PUBLIC gint getDefaultPrinterName(gchar *pDestName, gint bufSize) { /*** Parameters start ***/ cups_dest_t *pDests; // Destinations. gint numDests; // Number of destinations. gint i; // Counter. gint retVal = ID_ERR_NO_PRINTER_ADDED; // Return value. /*** Parameters end ***/ // Get all dests. numDests = cupsGetDests(&pDests); for (i = 0; i < numDests; i++) { if ((pDests[i].is_default != 0) && printerIsSupported(pDests[i].options, pDests[i].num_options)) { // Default printer found. strncpy(pDestName, pDests[i].name, bufSize); retVal = ID_ERR_NO_ERROR; break; } } if (retVal != ID_ERR_NO_ERROR) { // iterate over all printers and check if it is supported for (i = 0; i < numDests; i++) { if (printerIsSupported(pDests[i].options, pDests[i].num_options)) { strncpy(pDestName, pDests[i].name, bufSize); retVal = ID_ERR_NO_ERROR; break; } } } cupsFreeDests(numDests, pDests); return(retVal); }// End getDefaultPrinterName
dt_printer_info_t *dt_get_printer_info(const char *printer_name) { cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = cupsGetDest(printer_name, NULL, num_dests, dests); dt_printer_info_t *result = NULL; if (dest) { const char *PPDFile = cupsGetPPD (printer_name); result = (dt_printer_info_t *)malloc(sizeof(dt_printer_info_t)); g_strlcpy(result->name, dest->name, MAX_NAME); ppd_file_t *ppd = ppdOpenFile(PPDFile); if (ppd) { ppdMarkDefaults(ppd); cupsMarkOptions(ppd, dest->num_options, dest->options); // hardware margins ppd_attr_t *attr = ppdFindAttr(ppd, "HWMargins", NULL); if (attr) { sscanf(attr->value, "%lf %lf %lf %lf", &result->hw_margin_left, &result->hw_margin_bottom, &result->hw_margin_right, &result->hw_margin_top); result->hw_margin_left = dt_pdf_point_to_mm (result->hw_margin_left); result->hw_margin_bottom = dt_pdf_point_to_mm (result->hw_margin_bottom); result->hw_margin_right = dt_pdf_point_to_mm (result->hw_margin_right); result->hw_margin_top = dt_pdf_point_to_mm (result->hw_margin_top); } // default resolution attr = ppdFindAttr(ppd, "DefaultResolution", NULL); if (attr) { char *x = strstr(attr->value, "x"); if (x) sscanf (x+1, "%ddpi", &result->resolution); else sscanf (attr->value, "%ddpi", &result->resolution); } else result->resolution = 300; while(result->resolution>360) result->resolution /= 2.0; ppdClose(ppd); unlink(PPDFile); } } cupsFreeDests(num_dests, dests); return result; }
void dt_get_printer_info(const char *printer_name, dt_printer_info_t *pinfo) { cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = cupsGetDest(printer_name, NULL, num_dests, dests); if (dest) { const char *PPDFile = cupsGetPPD (printer_name); g_strlcpy(pinfo->name, dest->name, MAX_NAME); ppd_file_t *ppd = ppdOpenFile(PPDFile); if (ppd) { ppdMarkDefaults(ppd); cupsMarkOptions(ppd, dest->num_options, dest->options); // first check if this is turboprint drived printer, two solutions: // 1. ModelName constains TurboPrint // 2. zedoPrinterDriver exists ppd_attr_t *attr = ppdFindAttr(ppd, "ModelName", NULL); if (attr) { pinfo->is_turboprint = strstr(attr->value, "TurboPrint") != NULL; } // hardware margins attr = ppdFindAttr(ppd, "HWMargins", NULL); if (attr) { sscanf(attr->value, "%lf %lf %lf %lf", &pinfo->hw_margin_left, &pinfo->hw_margin_bottom, &pinfo->hw_margin_right, &pinfo->hw_margin_top); pinfo->hw_margin_left = dt_pdf_point_to_mm (pinfo->hw_margin_left); pinfo->hw_margin_bottom = dt_pdf_point_to_mm (pinfo->hw_margin_bottom); pinfo->hw_margin_right = dt_pdf_point_to_mm (pinfo->hw_margin_right); pinfo->hw_margin_top = dt_pdf_point_to_mm (pinfo->hw_margin_top); } // default resolution attr = ppdFindAttr(ppd, "DefaultResolution", NULL); if (attr) { char *x = strstr(attr->value, "x"); if (x) sscanf (x+1, "%ddpi", &pinfo->resolution); else sscanf (attr->value, "%ddpi", &pinfo->resolution); } else pinfo->resolution = 300; while(pinfo->resolution>360) pinfo->resolution /= 2.0; ppdClose(ppd); g_unlink(PPDFile); } } cupsFreeDests(num_dests, dests); }
void dt_print_file(const int32_t imgid, const char *filename, const char *job_title, const dt_print_info_t *pinfo) { // first for safety check that filename exists and is readable if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { dt_control_log(_("file `%s' to print not found for image %d on `%s'"), filename, imgid, pinfo->printer.name); return; } cups_option_t *options = NULL; int num_options = 0; // for turboprint drived printer, use the turboprint dialog if (pinfo->printer.is_turboprint) { const char *tp_intent_name[] = { "perception_0", "colorimetric-relative_1", "saturation_1", "colorimetric-absolute_1" }; char tmpfile[PATH_MAX] = { 0 }; dt_loc_get_tmp_dir(tmpfile, sizeof(tmpfile)); g_strlcat(tmpfile, "/dt_cups_opts_XXXXXX", sizeof(tmpfile)); gint fd = g_mkstemp(tmpfile); if(fd == -1) { dt_control_log(_("failed to create temporary file for printing options")); fprintf(stderr, "failed to create temporary pdf for printing options\n"); return; } close(fd); // ensure that intent is in the range, may happen if at some point we add new intent in the list const int intent = (pinfo->printer.intent < 4) ? pinfo->printer.intent : 0; // spawn turboprint command gchar * argv[15] = { 0 }; argv[0] = "turboprint"; argv[1] = g_strdup_printf("--printer=%s", pinfo->printer.name); argv[2] = "--options"; argv[3] = g_strdup_printf("--output=%s", tmpfile); argv[4] = "-o"; argv[5] = "copies=1"; argv[6] = "-o"; argv[7] = g_strdup_printf("PageSize=%s", pinfo->paper.common_name); argv[8] = "-o"; argv[9] = "InputSlot=AutoSelect"; argv[10] = "-o"; argv[11] = g_strdup_printf("zedoIntent=%s", tp_intent_name[intent]); argv[12] = "-o"; argv[13] = g_strdup_printf("MediaType=%s", pinfo->medium.name); argv[14] = NULL; gint exit_status = 0; g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, NULL, NULL, &exit_status, NULL); g_free(argv[1]); g_free(argv[3]); g_free(argv[7]); g_free(argv[11]); g_free(argv[13]); if (exit_status==0) { FILE *stream = g_fopen(tmpfile, "rb"); while(1) { char optname[100]; char optvalue[100]; const int ropt = fscanf(stream, "%*s %[^= ]=%s", optname, optvalue); // if we parsed an option name=value if (ropt==2) { char *v = optvalue; // remove possible single quote around value if (*v == '\'') v++; if (v[strlen(v)-1] == '\'') v[strlen(v)-1] = '\0'; num_options = cupsAddOption(optname, v, num_options, &options); } else if (ropt == EOF) break; } fclose(stream); g_unlink(tmpfile); } else { dt_print(DT_DEBUG_PRINT, "[print] command fails with %d, cancel printing\n", exit_status); return; } } else { cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = cupsGetDest(pinfo->printer.name, NULL, num_dests, dests); for (int j = 0; j < dest->num_options; j ++) if (cupsGetOption(dest->options[j].name, num_options, options) == NULL) num_options = cupsAddOption(dest->options[j].name, dest->options[j].value, num_options, &options); cupsFreeDests(num_dests, dests); // if we have a profile, disable cm on CUPS, this is important as dt does the cm num_options = cupsAddOption("cm-calibration", *pinfo->printer.profile ? "true" : "false", num_options, &options); // media to print on num_options = cupsAddOption("media", pinfo->paper.name, num_options, &options); // the media type to print on num_options = cupsAddOption("MediaType", pinfo->medium.name, num_options, &options); // never print two-side num_options = cupsAddOption("sides", "one-sided", num_options, &options); // and a single image per page num_options = cupsAddOption("number-up", "1", num_options, &options); // if the printer has no hardward margins activate the borderless mode if (pinfo->printer.hw_margin_top == 0 || pinfo->printer.hw_margin_bottom == 0 || pinfo->printer.hw_margin_left == 0 || pinfo->printer.hw_margin_right == 0) { // there is many variant for this parameter num_options = cupsAddOption("StpFullBleed", "true", num_options, &options); num_options = cupsAddOption("STP_FullBleed", "true", num_options, &options); num_options = cupsAddOption("Borderless", "true", num_options, &options); } num_options = cupsAddOption("landscape", pinfo->page.landscape ? "true" : "false", num_options, &options); } // print lp options dt_print(DT_DEBUG_PRINT, "[print] printer options (%d)\n", num_options); for (int k=0; k<num_options; k++) dt_print(DT_DEBUG_PRINT, "[print] %2d %s=%s\n", k+1, options[k].name, options[k].value); const int job_id = cupsPrintFile(pinfo->printer.name, filename, job_title, num_options, options); if (job_id == 0) dt_control_log(_("error while printing `%s' on `%s'"), job_title, pinfo->printer.name); else dt_control_log(_("printing `%s' on `%s'"), job_title, pinfo->printer.name); cupsFreeOptions (num_options, options); }
GList *dt_get_papers(const dt_printer_info_t *printer) { const char *printer_name = printer->name; GList *result = NULL; #if ((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 7)) || CUPS_VERSION_MAJOR > 1 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 if (cupsConnectDest != NULL && cupsCopyDestInfo != NULL && cupsGetDestMediaCount != NULL && cupsGetDestMediaByIndex != NULL && cupsFreeDestInfo != NULL) #endif { cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = cupsGetDest(printer_name, NULL, num_dests, dests); int cancel = 0; // important char resource[1024]; if (dest) { http_t *hcon = cupsConnectDest(dest, 0, 2000, &cancel, resource, sizeof(resource), NULL, (void *)NULL); if (hcon) { cups_size_t size; cups_dinfo_t *info = cupsCopyDestInfo (hcon, dest); const int count = cupsGetDestMediaCount(hcon, dest, info, CUPS_MEDIA_FLAGS_DEFAULT); for (int k=0; k<count; k++) { if (cupsGetDestMediaByIndex(hcon, dest, info, k, CUPS_MEDIA_FLAGS_DEFAULT, &size)) { if (size.width!=0 && size.length!=0 && !paper_exists(result, size.media)) { pwg_media_t *med = pwgMediaForPWG (size.media); char common_name[MAX_NAME] = { 0 }; if (med->ppd) g_strlcpy(common_name, med->ppd, sizeof(common_name)); else g_strlcpy(common_name, size.media, sizeof(common_name)); dt_paper_info_t *paper = (dt_paper_info_t*)malloc(sizeof(dt_paper_info_t)); g_strlcpy(paper->name, size.media, sizeof(paper->name)); g_strlcpy(paper->common_name, common_name, sizeof(paper->common_name)); paper->width = (double)size.width / 100.0; paper->height = (double)size.length / 100.0; result = g_list_append (result, paper); dt_print(DT_DEBUG_PRINT, "[print] new media paper %4d %6.2f x %6.2f (%s) (%s)\n", k, paper->width, paper->height, paper->name, paper->common_name); } } } cupsFreeDestInfo(info); httpClose(hcon); } else dt_print(DT_DEBUG_PRINT, "[print] cannot connect to printer %s (cancel=%d)\n", printer_name, cancel); } cupsFreeDests(num_dests, dests); } #endif // check now PPD page sizes const char *PPDFile = cupsGetPPD(printer_name); ppd_file_t *ppd = ppdOpenFile(PPDFile); if (ppd) { ppd_size_t *size = ppd->sizes; for (int k=0; k<ppd->num_sizes; k++) { if (size->width!=0 && size->length!=0 && !paper_exists(result, size->name)) { dt_paper_info_t *paper = (dt_paper_info_t*)malloc(sizeof(dt_paper_info_t)); g_strlcpy(paper->name, size->name, MAX_NAME); g_strlcpy(paper->common_name, size->name, MAX_NAME); paper->width = (double)dt_pdf_point_to_mm(size->width); paper->height = (double)dt_pdf_point_to_mm(size->length); result = g_list_append (result, paper); dt_print(DT_DEBUG_PRINT, "[print] new ppd paper %4d %6.2f x %6.2f (%s) (%s)\n", k, paper->width, paper->height, paper->name, paper->common_name); } size++; } ppdClose(ppd); g_unlink(PPDFile); } result = g_list_sort_with_data (result, (GCompareDataFunc)sort_papers, NULL); return result; }
int main(int argc, /* I - Number of command-line arguments */ char *argv[]) /* I - Command-line arguments */ { int i; /* Looping var */ http_t *http; /* Connection to server */ const char *dest, /* Desired printer */ *user, /* Desired user */ *val; /* Environment variable name */ char *instance; /* Printer instance */ int id, /* Desired job ID */ all, /* All printers */ interval, /* Reporting interval */ longstatus; /* Show file details */ cups_dest_t *named_dest; /* Named destination */ _cupsSetLocale(argv); /* * Check for command-line options... */ http = NULL; dest = NULL; user = NULL; id = 0; interval = 0; longstatus = 0; all = 0; for (i = 1; i < argc; i ++) if (argv[i][0] == '+') interval = atoi(argv[i] + 1); else if (argv[i][0] == '-') { switch (argv[i][1]) { case 'E' : /* Encrypt */ #ifdef HAVE_SSL cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); if (http) httpEncryption(http, HTTP_ENCRYPT_REQUIRED); #else _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."), argv[0]); #endif /* HAVE_SSL */ break; case 'U' : /* Username */ if (argv[i][2] != '\0') cupsSetUser(argv[i] + 2); else { i ++; if (i >= argc) { _cupsLangPrintf(stderr, _("%s: Error - expected username after " "\"-U\" option."), argv[0]); return (1); } cupsSetUser(argv[i]); } break; case 'P' : /* Printer */ if (argv[i][2]) dest = argv[i] + 2; else { i ++; if (i >= argc) { httpClose(http); usage(); } dest = argv[i]; } if ((instance = strchr(dest, '/')) != NULL) *instance++ = '\0'; http = connect_server(argv[0], http); if ((named_dest = cupsGetNamedDest(http, dest, instance)) == NULL) { if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server " "name."), argv[0]); else if (instance) _cupsLangPrintf(stderr, _("%s: Error - unknown destination \"%s/%s\"."), argv[0], dest, instance); else _cupsLangPrintf(stderr, _("%s: Unknown destination \"%s\"."), argv[0], dest); return (1); } cupsFreeDests(1, named_dest); break; case 'a' : /* All printers */ all = 1; break; case 'h' : /* Connect to host */ if (http) { httpClose(http); http = NULL; } if (argv[i][2] != '\0') cupsSetServer(argv[i] + 2); else { i ++; if (i >= argc) { _cupsLangPrintf(stderr, _("%s: Error - expected hostname after " "\"-h\" option."), argv[0]); return (1); } else cupsSetServer(argv[i]); } break; case 'l' : /* Long status */ longstatus = 1; break; default : httpClose(http); usage(); break; } } else if (isdigit(argv[i][0] & 255)) id = atoi(argv[i]); else user = argv[i]; http = connect_server(argv[0], http); if (dest == NULL && !all) { if ((named_dest = cupsGetNamedDest(http, NULL, NULL)) == NULL) { if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) { _cupsLangPrintf(stderr, _("%s: Error - add '/version=1.1' to server name."), argv[0]); return (1); } val = NULL; if ((dest = getenv("LPDEST")) == NULL) { if ((dest = getenv("PRINTER")) != NULL) { if (!strcmp(dest, "lp")) dest = NULL; else val = "PRINTER"; } } else val = "LPDEST"; if (dest && val) _cupsLangPrintf(stderr, _("%s: Error - %s environment variable names " "non-existent destination \"%s\"."), argv[0], val, dest); else _cupsLangPrintf(stderr, _("%s: Error - no default destination available."), argv[0]); httpClose(http); return (1); } dest = named_dest->name; } /* * Show the status in a loop... */ for (;;) { if (dest) show_printer(argv[0], http, dest); i = show_jobs(argv[0], http, dest, user, id, longstatus); if (i && interval) { fflush(stdout); sleep(interval); } else break; } /* * Close the connection to the server and return... */ httpClose(http); return (0); }
int /* O - Exit status */ main(int argc, /* I - Number of command-line arguments */ char *argv[]) /* I - Command-line arguments */ { int status = 0, /* Exit status */ i, /* Looping var */ num_dests; /* Number of destinations */ cups_dest_t *dests, /* Destinations */ *dest, /* Current destination */ *named_dest; /* Current named destination */ const char *ppdfile; /* PPD file */ ppd_file_t *ppd; /* PPD file data */ int num_jobs; /* Number of jobs for queue */ cups_job_t *jobs; /* Jobs for queue */ if (argc > 1) { if (!strcmp(argv[1], "enum")) { cups_ptype_t mask = CUPS_PRINTER_LOCAL, /* Printer type mask */ type = CUPS_PRINTER_LOCAL; /* Printer type */ int msec = 0; /* Timeout in milliseconds */ for (i = 2; i < argc; i ++) if (isdigit(argv[i][0] & 255) || argv[i][0] == '.') msec = (int)(atof(argv[i]) * 1000); else if (!_cups_strcasecmp(argv[i], "bw")) { mask |= CUPS_PRINTER_BW; type |= CUPS_PRINTER_BW; } else if (!_cups_strcasecmp(argv[i], "color")) { mask |= CUPS_PRINTER_COLOR; type |= CUPS_PRINTER_COLOR; } else if (!_cups_strcasecmp(argv[i], "mono")) { mask |= CUPS_PRINTER_COLOR; } else if (!_cups_strcasecmp(argv[i], "duplex")) { mask |= CUPS_PRINTER_DUPLEX; type |= CUPS_PRINTER_DUPLEX; } else if (!_cups_strcasecmp(argv[i], "simplex")) { mask |= CUPS_PRINTER_DUPLEX; } else if (!_cups_strcasecmp(argv[i], "staple")) { mask |= CUPS_PRINTER_STAPLE; type |= CUPS_PRINTER_STAPLE; } else if (!_cups_strcasecmp(argv[i], "copies")) { mask |= CUPS_PRINTER_COPIES; type |= CUPS_PRINTER_COPIES; } else if (!_cups_strcasecmp(argv[i], "collate")) { mask |= CUPS_PRINTER_COLLATE; type |= CUPS_PRINTER_COLLATE; } else if (!_cups_strcasecmp(argv[i], "punch")) { mask |= CUPS_PRINTER_PUNCH; type |= CUPS_PRINTER_PUNCH; } else if (!_cups_strcasecmp(argv[i], "cover")) { mask |= CUPS_PRINTER_COVER; type |= CUPS_PRINTER_COVER; } else if (!_cups_strcasecmp(argv[i], "bind")) { mask |= CUPS_PRINTER_BIND; type |= CUPS_PRINTER_BIND; } else if (!_cups_strcasecmp(argv[i], "sort")) { mask |= CUPS_PRINTER_SORT; type |= CUPS_PRINTER_SORT; } else if (!_cups_strcasecmp(argv[i], "mfp")) { mask |= CUPS_PRINTER_MFP; type |= CUPS_PRINTER_MFP; } else if (!_cups_strcasecmp(argv[i], "printer")) { mask |= CUPS_PRINTER_MFP; } else if (!_cups_strcasecmp(argv[i], "large")) { mask |= CUPS_PRINTER_LARGE; type |= CUPS_PRINTER_LARGE; } else if (!_cups_strcasecmp(argv[i], "medium")) { mask |= CUPS_PRINTER_MEDIUM; type |= CUPS_PRINTER_MEDIUM; } else if (!_cups_strcasecmp(argv[i], "small")) { mask |= CUPS_PRINTER_SMALL; type |= CUPS_PRINTER_SMALL; } else fprintf(stderr, "Unknown argument \"%s\" ignored...\n", argv[i]); cupsEnumDests(CUPS_DEST_FLAGS_NONE, msec, NULL, type, mask, enum_cb, NULL); } else if (!strcmp(argv[1], "password")) { const char *pass = cupsGetPassword("Password:"******"Password entered: %s\n", pass); else puts("No password entered."); } else if (!strcmp(argv[1], "ppd") && argc == 3) { /* * ./testcups ppd printer */ http_status_t http_status; /* Status */ char buffer[1024]; /* PPD filename */ time_t modtime = 0; /* Last modified */ if ((http_status = cupsGetPPD3(CUPS_HTTP_DEFAULT, argv[2], &modtime, buffer, sizeof(buffer))) != HTTP_STATUS_OK) printf("Unable to get PPD: %d (%s)\n", (int)http_status, cupsLastErrorString()); else puts(buffer); } else if (!strcmp(argv[1], "print") && argc == 5) { /* * ./testcups print printer file interval */ int interval, /* Interval between writes */ job_id; /* Job ID */ cups_file_t *fp; /* Print file */ char buffer[16384]; /* Read/write buffer */ ssize_t bytes; /* Bytes read/written */ if ((fp = cupsFileOpen(argv[3], "r")) == NULL) { printf("Unable to open \"%s\": %s\n", argv[2], strerror(errno)); return (1); } if ((job_id = cupsCreateJob(CUPS_HTTP_DEFAULT, argv[2], "testcups", 0, NULL)) <= 0) { printf("Unable to create print job on %s: %s\n", argv[1], cupsLastErrorString()); return (1); } interval = atoi(argv[4]); if (cupsStartDocument(CUPS_HTTP_DEFAULT, argv[1], job_id, argv[2], CUPS_FORMAT_AUTO, 1) != HTTP_STATUS_CONTINUE) { puts("Unable to start document!"); return (1); } while ((bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0) { printf("Writing %d bytes...\n", (int)bytes); if (cupsWriteRequestData(CUPS_HTTP_DEFAULT, buffer, bytes) != HTTP_STATUS_CONTINUE) { puts("Unable to write bytes!"); return (1); } if (interval > 0) sleep(interval); } cupsFileClose(fp); if (cupsFinishDocument(CUPS_HTTP_DEFAULT, argv[1]) > IPP_STATUS_OK_IGNORED_OR_SUBSTITUTED) { puts("Unable to finish document!"); return (1); } } else { puts("Usage:"); puts(""); puts("Run basic unit tests:"); puts(""); puts(" ./testcups"); puts(""); puts("Enumerate printers (for N seconds, -1 for indefinitely):"); puts(""); puts(" ./testcups enum [seconds]"); puts(""); puts("Ask for a password:"******""); puts(" ./testcups password"); puts(""); puts("Get the PPD file:"); puts(""); puts(" ./testcups ppd printer"); puts(""); puts("Print a file (interval controls delay between buffers in seconds):"); puts(""); puts(" ./testcups print printer file interval"); return (1); } return (0); } /* * cupsGetDests() */ fputs("cupsGetDests: ", stdout); fflush(stdout); num_dests = cupsGetDests(&dests); if (num_dests == 0) { puts("FAIL"); return (1); } else { printf("PASS (%d dests)\n", num_dests); for (i = num_dests, dest = dests; i > 0; i --, dest ++) { printf(" %s", dest->name); if (dest->instance) printf(" /%s", dest->instance); if (dest->is_default) puts(" ***DEFAULT***"); else putchar('\n'); } } /* * cupsGetDest(NULL) */ fputs("cupsGetDest(NULL): ", stdout); fflush(stdout); if ((dest = cupsGetDest(NULL, NULL, num_dests, dests)) == NULL) { for (i = num_dests, dest = dests; i > 0; i --, dest ++) if (dest->is_default) break; if (i) { status = 1; puts("FAIL"); } else puts("PASS (no default)"); dest = NULL; } else printf("PASS (%s)\n", dest->name); /* * cupsGetNamedDest(NULL, NULL, NULL) */ fputs("cupsGetNamedDest(NULL, NULL, NULL): ", stdout); fflush(stdout); if ((named_dest = cupsGetNamedDest(NULL, NULL, NULL)) == NULL || !dests_equal(dest, named_dest)) { if (!dest) puts("PASS (no default)"); else if (named_dest) { puts("FAIL (different values)"); show_diffs(dest, named_dest); status = 1; } else { puts("FAIL (no default)"); status = 1; } } else printf("PASS (%s)\n", named_dest->name); if (named_dest) cupsFreeDests(1, named_dest); /* * cupsGetDest(printer) */ printf("cupsGetDest(\"%s\"): ", dests[num_dests / 2].name); fflush(stdout); if ((dest = cupsGetDest(dests[num_dests / 2].name, NULL, num_dests, dests)) == NULL) { puts("FAIL"); return (1); } else puts("PASS"); /* * cupsGetNamedDest(NULL, printer, instance) */ printf("cupsGetNamedDest(NULL, \"%s\", \"%s\"): ", dest->name, dest->instance ? dest->instance : "(null)"); fflush(stdout); if ((named_dest = cupsGetNamedDest(NULL, dest->name, dest->instance)) == NULL || !dests_equal(dest, named_dest)) { if (named_dest) { puts("FAIL (different values)"); show_diffs(dest, named_dest); } else puts("FAIL (no destination)"); status = 1; } else puts("PASS"); if (named_dest) cupsFreeDests(1, named_dest); /* * cupsPrintFile() */ fputs("cupsPrintFile: ", stdout); fflush(stdout); if (cupsPrintFile(dest->name, "../data/testprint", "Test Page", dest->num_options, dest->options) <= 0) { printf("FAIL (%s)\n", cupsLastErrorString()); return (1); } else puts("PASS"); /* * cupsGetPPD(printer) */ fputs("cupsGetPPD(): ", stdout); fflush(stdout); if ((ppdfile = cupsGetPPD(dest->name)) == NULL) { puts("FAIL"); } else { puts("PASS"); /* * ppdOpenFile() */ fputs("ppdOpenFile(): ", stdout); fflush(stdout); if ((ppd = ppdOpenFile(ppdfile)) == NULL) { puts("FAIL"); return (1); } else puts("PASS"); ppdClose(ppd); unlink(ppdfile); } /* * cupsGetJobs() */ fputs("cupsGetJobs: ", stdout); fflush(stdout); num_jobs = cupsGetJobs(&jobs, NULL, 0, -1); if (num_jobs == 0) { puts("FAIL"); return (1); } else puts("PASS"); cupsFreeJobs(num_jobs, jobs); cupsFreeDests(num_dests, dests); return (status); }
CupsOptions::CupsOptions(QWidget* parent, QString Geraet) : QDialog( parent ) { FlagsOpt.clear(); setModal(true); setWindowTitle( tr( "Printer Options" ) ); setWindowIcon(QIcon(loadIcon ( "AppIcon.png" ))); prefs = PrefsManager::instance()->prefsFile->getContext("cups_options"); setSizeGripEnabled(true); CupsOptionsLayout = new QVBoxLayout( this ); CupsOptionsLayout->setSpacing( 5 ); CupsOptionsLayout->setMargin( 10 ); Table = new QTableWidget(0, 2, this); Table->setSortingEnabled(false); Table->setSelectionMode(QAbstractItemView::NoSelection); Table->verticalHeader()->hide(); Table->setHorizontalHeaderItem(0, new QTableWidgetItem( tr("Option"))); Table->setHorizontalHeaderItem(1, new QTableWidgetItem( tr("Value"))); QHeaderView* headerH = Table->horizontalHeader(); headerH->setStretchLastSection(true); headerH->setMovable(false); headerH->setClickable(false); headerH->setResizeMode(QHeaderView::Fixed); Table->setMinimumSize(300, 100); #ifdef HAVE_CUPS int i; cups_dest_t *dests; cups_dest_t *dest; int num_dests; const char *filename; /* PPD filename */ ppd_file_t *ppd; /* PPD data */ ppd_group_t *group; /* Current group */ num_dests = cupsGetDests(&dests); dest = cupsGetDest(Geraet.toLocal8Bit().constData(), NULL, num_dests, dests); if (!(dest == NULL || (filename = cupsGetPPD(dest->name)) == NULL || (ppd = ppdOpenFile(filename)) == NULL)) { ppdMarkDefaults(ppd); cupsMarkOptions(ppd, dest->num_options, dest->options); QStringList opts; QString Marked = ""; KeyToText.clear(); KeyToDefault.clear(); for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, ++group) { int ix; ppd_option_t *option; /* Current option */ ppd_choice_t *choice; /* Current choice */ for (ix = group->num_options, option = group->options; ix > 0; ix --, ++option) { int j; Marked = ""; struct OpData Daten; opts.clear(); for (j = option->num_choices, choice = option->choices; j > 0; j --, ++choice) { opts.append(QString(choice->choice)); if (choice->marked) Marked = QString(choice->choice); } if (!Marked.isEmpty()) { Table->setRowCount(Table->rowCount()+1); Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString(option->text))); QComboBox *item = new QComboBox( this ); item->setEditable(false); FlagsOpt.append(item); Daten.Cnum = static_cast<int>(FlagsOpt.count()-1); Daten.KeyW = QString(option->keyword); KeyToText[QString(option->text)] = Daten; item->addItems(opts); int lastSelected = prefs->getInt(QString(option->text), 0); if (lastSelected >= static_cast<int>(opts.count())) lastSelected = 0; item->setCurrentIndex(lastSelected); KeyToDefault[QString(option->text)] = Marked; Table->setCellWidget(Table->rowCount()-1, 1, item); } } } ppdClose(ppd); cupsFreeDests(num_dests, dests); } struct OpData Daten; Table->setRowCount(Table->rowCount()+1); Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString( tr("Page Set")))); QComboBox *item4 = new QComboBox( this ); item4->setEditable(false); FlagsOpt.append(item4); Daten.Cnum = static_cast<int>(FlagsOpt.count()-1); Daten.KeyW = "page-set"; KeyToText["Page Set"] = Daten; item4->addItem( tr("All Pages")); item4->addItem( tr("Even Pages only")); item4->addItem( tr("Odd Pages only")); int lastSelected = prefs->getInt( tr("Page Set"), 0); if (lastSelected >= 3) lastSelected = 0; item4->setCurrentIndex(lastSelected); KeyToDefault["Page Set"] = tr("All Pages"); Table->setCellWidget(Table->rowCount()-1, 1, item4); Table->setRowCount(Table->rowCount()+1); Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString( tr("Mirror")))); QComboBox *item2 = new QComboBox( this ); item2->setEditable(false); FlagsOpt.append(item2); Daten.Cnum = static_cast<int>(FlagsOpt.count()-1); Daten.KeyW = "mirror"; KeyToText["Mirror"] = Daten; item2->addItem(CommonStrings::trNo); item2->addItem(CommonStrings::trYes); item2->setCurrentIndex(0); lastSelected = prefs->getInt( tr("Mirror"), 0); if (lastSelected >= 2) lastSelected = 0; item2->setCurrentIndex(lastSelected); KeyToDefault["Mirror"] = CommonStrings::trNo; Table->setCellWidget(Table->rowCount()-1, 1, item2); Table->setRowCount(Table->rowCount()+1); Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString( tr("Orientation")))); QComboBox *item5 = new QComboBox( this ); item5->setEditable(false); FlagsOpt.append(item5); Daten.Cnum = static_cast<int>(FlagsOpt.count()-1); Daten.KeyW = "orientation"; KeyToText["Orientation"] = Daten; item5->addItem( tr("Portrait")); item5->addItem( tr("Landscape")); item5->setCurrentIndex(0); lastSelected = prefs->getInt( tr("Orientation"), 0); if (lastSelected >= 2) lastSelected = 0; item5->setCurrentIndex(lastSelected); KeyToDefault["Orientation"] = tr("Portrait"); Table->setCellWidget(Table->rowCount()-1, 1, item5); Table->setRowCount(Table->rowCount()+1); Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString( tr("N-Up Printing")))); QComboBox *item3 = new QComboBox( this ); item3->setEditable(false); FlagsOpt.append(item3); Daten.Cnum = static_cast<int>(FlagsOpt.count()-1); Daten.KeyW = "number-up"; KeyToText["N-Up Printing"] = Daten; item3->addItem("1 "+ tr("Page per Sheet")); item3->addItem("2 "+ tr("Pages per Sheet")); item3->addItem("4 "+ tr("Pages per Sheet")); item3->addItem("6 "+ tr("Pages per Sheet")); item3->addItem("9 "+ tr("Pages per Sheet")); item3->addItem("16 "+ tr("Pages per Sheet")); lastSelected = prefs->getInt( tr("N-Up Printing"), 0); if (lastSelected >= 6) lastSelected = 0; item3->setCurrentIndex(lastSelected); KeyToDefault["N-Up Printing"] = "1 "+ tr("Page per Sheet"); Table->setCellWidget(Table->rowCount()-1, 1, item3); #endif Table->resizeColumnsToContents(); CupsOptionsLayout->addWidget( Table ); Layout2 = new QHBoxLayout; Layout2->setSpacing( 5 ); Layout2->setMargin( 0 ); QSpacerItem* spacer = new QSpacerItem( 2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum ); Layout2->addItem( spacer ); PushButton1 = new QPushButton( CommonStrings::tr_OK, this ); PushButton1->setDefault( true ); Layout2->addWidget( PushButton1 ); PushButton2 = new QPushButton( CommonStrings::tr_Cancel, this ); PushButton2->setDefault( false ); PushButton1->setFocus(); Layout2->addWidget( PushButton2 ); CupsOptionsLayout->addLayout( Layout2 ); setMinimumSize( sizeHint() ); resize(minimumSizeHint().expandedTo(QSize(300, 100))); //tooltips Table->setToolTip( "<qt>" + tr( "This panel displays various CUPS options when printing. The exact parameters available will depend on your printer driver. You can confirm CUPS support by selecting Help > About. Look for the listings: C-C-T These equate to C=CUPS C=littlecms T=TIFF support. Missing library support is indicated by a *" ) + "</qt>" ); // signals and slots connections connect( PushButton2, SIGNAL( clicked() ), this, SLOT( reject() ) ); connect( PushButton1, SIGNAL( clicked() ), this, SLOT( accept() ) ); }
static void populate_options_real (PpOptionsDialog *dialog) { GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeView *treeview; GtkTreeIter iter; ppd_file_t *ppd_file; GtkWidget *notebook; GtkWidget *grid; GtkWidget *general_tab_grid = tab_grid_new (); GtkWidget *page_setup_tab_grid = tab_grid_new (); GtkWidget *installable_options_tab_grid = tab_grid_new (); GtkWidget *job_tab_grid = tab_grid_new (); GtkWidget *image_quality_tab_grid = tab_grid_new (); GtkWidget *color_tab_grid = tab_grid_new (); GtkWidget *finishing_tab_grid = tab_grid_new (); GtkWidget *advanced_tab_grid = tab_grid_new (); GtkWidget *widget; gint i, j; widget = (GtkWidget*) gtk_builder_get_object (dialog->builder, "options-spinner"); gtk_widget_hide (widget); gtk_spinner_stop (GTK_SPINNER (widget)); widget = (GtkWidget*) gtk_builder_get_object (dialog->builder, "progress-label"); gtk_widget_hide (widget); treeview = (GtkTreeView *) gtk_builder_get_object (dialog->builder, "options-categories-treeview"); notebook = (GtkWidget *) gtk_builder_get_object (dialog->builder, "options-notebook"); if (dialog->ipp_attributes) { /* Add number-up option to Page Setup tab */ ipp_option_add (g_hash_table_lookup (dialog->ipp_attributes, "number-up-supported"), g_hash_table_lookup (dialog->ipp_attributes, "number-up-default"), "number-up", /* Translators: This option sets number of pages printed on one sheet */ _("Pages per side"), dialog->printer_name, page_setup_tab_grid, dialog->sensitive); /* Add sides option to Page Setup tab */ ipp_option_add (g_hash_table_lookup (dialog->ipp_attributes, "sides-supported"), g_hash_table_lookup (dialog->ipp_attributes, "sides-default"), "sides", /* Translators: This option sets whether to print on both sides of paper */ _("Two-sided"), dialog->printer_name, page_setup_tab_grid, dialog->sensitive); /* Add orientation-requested option to Page Setup tab */ ipp_option_add (g_hash_table_lookup (dialog->ipp_attributes, "orientation-requested-supported"), g_hash_table_lookup (dialog->ipp_attributes, "orientation-requested-default"), "orientation-requested", /* Translators: This option sets orientation of print (portrait, landscape...) */ _("Orientation"), dialog->printer_name, page_setup_tab_grid, dialog->sensitive); } if (dialog->destination && dialog->ppd_filename) { ppd_file = ppdOpenFile (dialog->ppd_filename); ppdLocalize (ppd_file); if (ppd_file) { ppdMarkDefaults (ppd_file); cupsMarkOptions (ppd_file, dialog->destination->num_options, dialog->destination->options); for (i = 0; i < ppd_file->num_groups; i++) { for (j = 0; j < ppd_file->groups[i].num_options; j++) { grid = NULL; if (STRING_IN_TABLE (ppd_file->groups[i].name, color_group_whitelist)) grid = color_tab_grid; else if (STRING_IN_TABLE (ppd_file->groups[i].name, image_quality_group_whitelist)) grid = image_quality_tab_grid; else if (STRING_IN_TABLE (ppd_file->groups[i].name, job_group_whitelist)) grid = job_tab_grid; else if (STRING_IN_TABLE (ppd_file->groups[i].name, finishing_group_whitelist)) grid = finishing_tab_grid; else if (STRING_IN_TABLE (ppd_file->groups[i].name, installable_options_group_whitelist)) grid = installable_options_tab_grid; else if (STRING_IN_TABLE (ppd_file->groups[i].name, page_setup_group_whitelist)) grid = page_setup_tab_grid; if (!STRING_IN_TABLE (ppd_file->groups[i].options[j].keyword, ppd_option_blacklist)) { if (!grid && STRING_IN_TABLE (ppd_file->groups[i].options[j].keyword, color_option_whitelist)) grid = color_tab_grid; else if (!grid && STRING_IN_TABLE (ppd_file->groups[i].options[j].keyword, image_quality_option_whitelist)) grid = image_quality_tab_grid; else if (!grid && STRING_IN_TABLE (ppd_file->groups[i].options[j].keyword, finishing_option_whitelist)) grid = finishing_tab_grid; else if (!grid && STRING_IN_TABLE (ppd_file->groups[i].options[j].keyword, page_setup_option_whitelist)) grid = page_setup_tab_grid; if (!grid) grid = advanced_tab_grid; ppd_option_add (ppd_file->groups[i].options[j], dialog->printer_name, grid, dialog->sensitive); } } } ppdClose (ppd_file); } } dialog->ppd_filename_set = FALSE; if (dialog->ppd_filename) { g_unlink (dialog->ppd_filename); g_free (dialog->ppd_filename); dialog->ppd_filename = NULL; } dialog->destination_set = FALSE; if (dialog->destination) { cupsFreeDests (1, dialog->destination); dialog->destination = NULL; } dialog->ipp_attributes_set = FALSE; if (dialog->ipp_attributes) { g_hash_table_unref (dialog->ipp_attributes); dialog->ipp_attributes = NULL; } /* Translators: "General" tab contains general printer options */ tab_add (C_("Printer Option Group", "General"), notebook, treeview, general_tab_grid); /* Translators: "Page Setup" tab contains settings related to pages (page size, paper source, etc.) */ tab_add (C_("Printer Option Group", "Page Setup"), notebook, treeview, page_setup_tab_grid); /* Translators: "Installable Options" tab contains settings of presence of installed options (amount of RAM, duplex unit, etc.) */ tab_add (C_("Printer Option Group", "Installable Options"), notebook, treeview, installable_options_tab_grid); /* Translators: "Job" tab contains settings for jobs */ tab_add (C_("Printer Option Group", "Job"), notebook, treeview, job_tab_grid); /* Translators: "Image Quality" tab contains settings for quality of output print (e.g. resolution) */ tab_add (C_("Printer Option Group", "Image Quality"), notebook, treeview, image_quality_tab_grid); /* Translators: "Color" tab contains color settings (e.g. color printing) */ tab_add (C_("Printer Option Group", "Color"), notebook, treeview, color_tab_grid); /* Translators: "Finishing" tab contains finishing settings (e.g. booklet printing) */ tab_add (C_("Printer Option Group", "Finishing"), notebook, treeview, finishing_tab_grid); /* Translators: "Advanced" tab contains all others settings */ tab_add (C_("Printer Option Group", "Advanced"), notebook, treeview, advanced_tab_grid); gtk_widget_show_all (GTK_WIDGET (notebook)); /* Select the first option group */ if ((selection = gtk_tree_view_get_selection (treeview)) != NULL) { g_signal_connect (selection, "changed", G_CALLBACK (category_selection_changed_cb), dialog); if ((model = gtk_tree_view_get_model (treeview)) != NULL && gtk_tree_model_get_iter_first (model, &iter)) gtk_tree_selection_select_iter (selection, &iter); } dialog->populating_dialog = FALSE; if (dialog->response != GTK_RESPONSE_NONE) { dialog->user_callback (GTK_DIALOG (dialog->dialog), dialog->response, dialog->user_data); } }
void dt_print_file(const int32_t imgid, const char *filename, const dt_print_info_t *pinfo) { // first for safety check that filename exists and is readable if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { dt_control_log(_("file `%s' to print not found for image %d on `%s'"), filename, imgid, pinfo->printer.name); return; } cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = cupsGetDest(pinfo->printer.name, NULL, num_dests, dests); cups_option_t *options = NULL; int num_options = 0; for (int j = 0; j < dest->num_options; j ++) if (cupsGetOption(dest->options[j].name, num_options, options) == NULL) num_options = cupsAddOption(dest->options[j].name, dest->options[j].value, num_options, &options); cupsFreeDests(num_dests, dests); // disable cm on CUPS, this is important as dt does the cm if (*pinfo->printer.profile) num_options = cupsAddOption("cm-calibration", "true", num_options, &options); // media to print on num_options = cupsAddOption("media", pinfo->paper.name, num_options, &options); // never print two-side num_options = cupsAddOption("sides", "one-sided", num_options, &options); // and a single image per page num_options = cupsAddOption("number-up", "1", num_options, &options); // if the printer has no hardward margins activate the borderless mode if (pinfo->printer.hw_margin_top == 0 || pinfo->printer.hw_margin_bottom == 0 || pinfo->printer.hw_margin_left == 0 || pinfo->printer.hw_margin_right == 0) { // there is many variant for this parameter num_options = cupsAddOption("StpFullBleed", "true", num_options, &options); num_options = cupsAddOption("STP_FullBleed", "true", num_options, &options); num_options = cupsAddOption("Borderless", "true", num_options, &options); } if (pinfo->page.landscape) num_options = cupsAddOption("landscape", "true", num_options, &options); else num_options = cupsAddOption("landscape", "false", num_options, &options); // print lp options dt_print(DT_DEBUG_PRINT, "[print] printer options (%d)\n", num_options); for (int k=0; k<num_options; k++) dt_print(DT_DEBUG_PRINT, "[print] %s=%s\n", options[k].name, options[k].value); const int job_id = cupsPrintFile(pinfo->printer.name, filename, "darktable", num_options, options); if (job_id == 0) dt_control_log(_("error while printing image %d on `%s'"), imgid, pinfo->printer.name); else dt_control_log(_("printing image %d on `%s'"), imgid, pinfo->printer.name); cupsFreeOptions (num_options, options); }
GList *dt_get_printers(void) { cups_dest_t *dests; int num_dests = cupsGetDests(&dests); int k; GList *result = NULL; for (k=0; k<num_dests; k++) { const cups_dest_t *dest = &dests[k]; const char *psvalue = cupsGetOption("printer-state", dest->num_options, dest->options); // check that the printer is ready if (strtol(psvalue, NULL, 10) < IPP_PRINTER_STOPPED) { dt_printer_info_t *pr = dt_get_printer_info(dest->name); result = g_list_append(result,pr); } else dt_print(DT_DEBUG_PRINT, "[print] skip printer %s as stopped\n", dest->name); } cupsFreeDests(num_dests, dests); return result; }