/** Calls setServiceData on the specified service using the second argument as the basis for the argument to setServiceData. (The <ogsi:setByServiceDataNames> tags are added in this routine.) */ void Gridifier::setServiceData(const QString &nameSpace, const QString &gsh, const QString &sdeText){ QString arg("<ogsi:setByServiceDataNames>"); arg.append(sdeText); arg.append("</ogsi:setByServiceDataNames>"); QProcess *setServiceDataProcess = new QProcess(QString("./setServiceData.pl")); setServiceDataProcess->setWorkingDirectory(mScriptsDir); setServiceDataProcess->addArgument(nameSpace); setServiceDataProcess->addArgument(gsh); setServiceDataProcess->addArgument(arg); setServiceDataProcess->start(); while (setServiceDataProcess->isRunning()){ usleep(10000); mApplication->processEvents(); } if(setServiceDataProcess->canReadLineStdout()){ cout << "Stdout:" << endl << setServiceDataProcess->readStdout() << endl; } if (setServiceDataProcess->canReadLineStderr()){ cout << "Stderr:" << endl << setServiceDataProcess->readStderr() << endl; } }
//--------------------------------------------------------------- QString Gridifier::makeSGSFactory(const QString &container, const QString &topLevelRegistry, const QString &className){ QString result; QProcess *makeSGSFactoryProcess = new QProcess(QString("./make_" + className + "_factory.pl")); makeSGSFactoryProcess->setWorkingDirectory(mScriptsDir); makeSGSFactoryProcess->addArgument(container); makeSGSFactoryProcess->addArgument(topLevelRegistry); cout << makeSGSFactoryProcess->arguments().join(" ") << endl; makeSGSFactoryProcess->start(); while (makeSGSFactoryProcess->isRunning()){ usleep(10000); mApplication->processEvents(); } // this functionality is left in a seperate slot since it could be better // to allow the standard qt events to handle it, rather than sitting in the // above loop result = QString(makeSGSFactoryProcess->readStdout()).stripWhiteSpace(); return result; }
/** Method calls appropriate xxx_launch.sh script to * actually launch the visualization job on the target machine */ int Gridifier::launchVizScript(const QString &scriptConfigFileName, const LauncherConfig &config){ // Construct name of script from name of application QProcess *launchVizScriptProcess = new QProcess(QString("./"+config.mAppToLaunch->mAppName+"_launch.sh")); launchVizScriptProcess->setWorkingDirectory(mScriptsDir); launchVizScriptProcess->addArgument(scriptConfigFileName); launchVizScriptProcess->addArgument(QString::number(config.mTimeToRun)); launchVizScriptProcess->start(); while (launchVizScriptProcess->isRunning()){ usleep(10000); mApplication->processEvents(); } if (launchVizScriptProcess->canReadLineStdout()){ QString out(launchVizScriptProcess->readStdout()); cout << "Stdout:" << endl << out << endl; if(out.contains("ERROR")){ return REG_FAILURE; } } if (launchVizScriptProcess->canReadLineStderr()){ QString out(launchVizScriptProcess->readStderr()); cout << "Stderr:" << endl << out << endl; if(out.contains("ERROR")){ return REG_FAILURE; } } return REG_SUCCESS; }
/** Special case to launch a viz on Argonne's cluster * this will always render to multicast */ void Gridifier::launchArgonneViz(const LauncherConfig &config){ QProcess *launchArgonneVizProcess = new QProcess(QString("./argonneVis.sh")); launchArgonneVizProcess->setWorkingDirectory(mScriptsDir); launchArgonneVizProcess->addArgument(config.visualizationGSH.mEPR); launchArgonneVizProcess->addArgument(QString::number(config.mTimeToRun)); launchArgonneVizProcess->addArgument(config.multicastAddress); QString vizTypeStr = ""; if (config.vizType == isosurface){ vizTypeStr = "iso"; } else if (config.vizType == volumeRender){ vizTypeStr = "vol"; } if (config.vizType == hedgehog){ vizTypeStr = "hog"; } else if (config.vizType == cutPlane){ vizTypeStr = "cut"; } launchArgonneVizProcess->addArgument(vizTypeStr); cout << launchArgonneVizProcess->arguments().join(" ") << endl; launchArgonneVizProcess->start(); while (launchArgonneVizProcess->isRunning()){ usleep(10000); mApplication->processEvents(); } cout << "Stdout:" << endl << launchArgonneVizProcess->readStdout() << endl; if (launchArgonneVizProcess->canReadLineStderr()) cout << "Stderr:" << endl << launchArgonneVizProcess->readStderr() << endl; }
void ossimQtIgenController::runBatchIgen() { ossimFilename spec_file = theOutputFile; spec_file.setExtension("spec"); QString s = spec_file.c_str(); saveSpecFile(s); ossimFilename omd_file = theOutputFile; omd_file.setExtension("omd"); if(omd_file.exists()) { ossimFilename::remove(omd_file); } QProcess* proc = new QProcess( theDialog ); proc->addArgument("igen"); proc->addArgument(spec_file.c_str()); if (!proc->start()) { ossimString command = "igen "; command += spec_file; ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimQtIgenController::runIgen: " << "Can't execute command line = " << command << std::endl; } // Note: From QT's assistant, they never delete "proc"??? }
//////// NOT USED ////////// void Gridifier::copyCheckPointFiles(const QString &host){ QProcess *rgcpcProcess = new QProcess(QString("./rgcpc.pl")); rgcpcProcess->setWorkingDirectory(mScriptsDir); rgcpcProcess->addArgument("-t"); rgcpcProcess->addArgument(host); rgcpcProcess->addArgument("-f"); rgcpcProcess->addArgument("checkPointDataCache.xml"); rgcpcProcess->start(); // and then do something clever to give the users an update status on the file transfer progress }
/** Instructs the simulation associated with the specified SGS to take a checkpoint and then stop. This call blocks until job has stopped or a time-out occurs. */ QString Gridifier::checkPointAndStop(const QString &sgsGSH){ QProcess *checkPointAndStopProcess = new QProcess(QString("./checkpoint_and_stop.pl")); checkPointAndStopProcess->setWorkingDirectory(mScriptsDir); checkPointAndStopProcess->addArgument(sgsGSH); checkPointAndStopProcess->start(); while (checkPointAndStopProcess->isRunning()){ usleep(10000); mApplication->processEvents(); } QString result = checkPointAndStopProcess->readStdout(); return result; }
/** Create a MetaSGS */ QString Gridifier::makeMetaSGS(const QString &factory, const LauncherConfig &config, const QString &parentGSH){ QString result; QProcess *makeSimSGSProcess = new QProcess(QString("./make_msgs.pl")); makeSimSGSProcess->setWorkingDirectory(mScriptsDir); makeSimSGSProcess->addArgument(factory); // the tag is handled correctly if it contains spaces - thanks QT! makeSimSGSProcess->addArgument(config.mJobData->toXML(QString("MetaSGS"))); makeSimSGSProcess->addArgument(config.topLevelRegistryGSH); makeSimSGSProcess->addArgument(config.currentCheckpointGSH); makeSimSGSProcess->addArgument(config.mInputFileName); makeSimSGSProcess->addArgument(QString::number(config.mTimeToRun)); makeSimSGSProcess->addArgument(parentGSH); if (config.treeTag.length() > 0){ makeSimSGSProcess->addArgument(config.treeTag); makeSimSGSProcess->addArgument(config.checkPointTreeFactoryGSH); } makeSimSGSProcess->start(); while(makeSimSGSProcess->isRunning()){ usleep(10000); mApplication->processEvents(); } // Grab the sgs and return it // Do some error checking here - or in the calling class? result = QString(makeSimSGSProcess->readStdout()).stripWhiteSpace(); cout << "Stdout:" << endl << result << endl; if (makeSimSGSProcess->canReadLineStderr()) cout << "Stderr:" << endl << makeSimSGSProcess->readStderr() << endl; return result; }
void AboutForm::mousePressEvent(QMouseEvent*) { if (urlLabel->hasMouse()) { #ifdef _DEBUG qDebug("\t[AboutForm::mousePressEvent] Clicked on url."); #endif //launch a webbrowser to go to the url: QProcess *proc = new QProcess( this ); #ifdef Q_WS_X11 proc->addArgument( "konqueror"); #endif // proc->addArgument( qsProgramUrl ); if (!proc->start()) urlLabel->setText( "<font color=red>Can not start external webbrowser</font>" ); } }
/** * Method calls lb3d_client.pl script to call web service * to actually launch the job on the target machine */ void Gridifier::webServiceJobSubmit(const QString & scriptConfigFileName){ // Construct name of script from name of application QProcess *launchSimScriptProcess = new QProcess(QString("./lb3d_client.pl")); launchSimScriptProcess->setWorkingDirectory(mScriptsDir); launchSimScriptProcess->addArgument(scriptConfigFileName); launchSimScriptProcess->start(); while (launchSimScriptProcess->isRunning()){ usleep(10000); mApplication->processEvents(); } cout << "Stdout:" << endl << launchSimScriptProcess->readStdout() << endl; if (launchSimScriptProcess->canReadLineStderr()) cout << "Stderr:" << endl << launchSimScriptProcess->readStderr() << endl; }
/** The following static methods wrap around QProcess objects to * run the reg_perl_launcher scripts. Ultimately replace with * code that uses an API to perform the same function programatically. */ QString Gridifier::getSGSFactories(const QString &topLevelRegistry, const QString &desiredContainer, const QString &className){ QString result; QProcess *getSGSFactoriesProcess = new QProcess(QString("./get_" + className + "_factories.pl")); getSGSFactoriesProcess->setWorkingDirectory(mScriptsDir); getSGSFactoriesProcess->addArgument(topLevelRegistry); getSGSFactoriesProcess->start(); // At this point we need to wait for the process to complete. // Clearly this isn't ideal - hence the desire to replace this with API calls. // An alternative is to send the result back via a QT event.... // for the time being stick with this slightly naff approach while (getSGSFactoriesProcess->isRunning()){ // don't sit in an exhaustive loop - waste of electricity :) usleep(10000); // and keep the gui updated mApplication->processEvents(); } // this functionality is left in a seperate slot since it could be better // to allow the standard qt events to handle it, rather than sitting in the // above loop //result = getSGSFactoriesProcessEnded(desiredContainer); QString allFactories = getSGSFactoriesProcess->readStdout(); if (allFactories.length() == 0){ // then no SGS Factories exist - so create one - actually do this elsewhere result = ""; } else { QStringList factories = QStringList::split("\n", allFactories); int numFactories = factories.size(); // prune the list - remove any factories not on the desired container for (int i=0; i<numFactories; i++){ if (!factories[i].contains(desiredContainer)){ factories.erase(factories.at(i)); numFactories = factories.size(); // undo the increment since we've removed an element i--; } } // if there's no factories left - return the blank string if (numFactories <= 0) result = ""; // choose a factory at random int randomNum = rand(); randomNum = (int)((randomNum / (float)RAND_MAX) * numFactories); QString randomFactory = factories[randomNum]; result = randomFactory; } return result; }
//--------------------------------------------------------------- QString Gridifier::makeVizSGS(const QString &factory, const LauncherConfig &config){ QString result; #ifndef REG_WSRF QProcess *makeVizSGSProcess = new QProcess(QString("./make_vis_sgs.pl")); makeVizSGSProcess->setWorkingDirectory(mScriptsDir); makeVizSGSProcess->addArgument(factory); makeVizSGSProcess->addArgument(config.mJobData->toXML(QString("SGS"))); makeVizSGSProcess->addArgument(config.topLevelRegistryGSH); makeVizSGSProcess->addArgument(config.simulationGSH.mEPR); makeVizSGSProcess->addArgument(QString::number(config.mTimeToRun)); makeVizSGSProcess->start(); while (makeVizSGSProcess->isRunning()){ usleep(10000); mApplication->processEvents(); } if(makeVizSGSProcess->canReadLineStdout()){ result = QString(makeVizSGSProcess->readStdout()); cout << "stdout: " << result << endl; } else{ cout << "Full line of stdout unavailable" << endl; } if(makeVizSGSProcess->canReadLineStderr()){ cout << "stderr: " << QString(makeVizSGSProcess->readStderr()) << endl; } else{ cout << "Full line of stderr unavailable" << endl; } result = QString(makeVizSGSProcess->readStdout()).stripWhiteSpace(); #else // REG_WSRF is defined char purpose[1024]; char proxyAddress[1024]; int proxyPort; char iodef_label[256]; char *ioTypes; struct soap mySoap; char *EPR; struct msg_struct *msg; xmlDocPtr doc; xmlNsPtr ns; xmlNodePtr cur; struct io_struct *ioPtr; int i, count; struct reg_job_details job; /* Obtain the IOTypes from the data source */ soap_init(&mySoap); if( Get_resource_property (&mySoap, config.simulationGSH.mEPR.ascii(), config.simulationGSH.mSecurity.userDN, config.simulationGSH.mSecurity.passphrase, "ioTypeDefinitions", &ioTypes) != REG_SUCCESS ){ cout << "Call to get ioTypeDefinitions ResourceProperty on "<< config.simulationGSH.mEPR << " failed" << endl; return result; } cout << "Got ioTypeDefinitions >>" << ioTypes << "<<" << endl; if( !(doc = xmlParseMemory(ioTypes, strlen(ioTypes))) || !(cur = xmlDocGetRootElement(doc)) ){ fprintf(stderr, "Hit error parsing buffer\n"); xmlFreeDoc(doc); xmlCleanupParser(); return result; } ns = xmlSearchNsByHref(doc, cur, (const xmlChar *) "http://www.realitygrid.org/xml/steering"); if ( xmlStrcmp(cur->name, (const xmlChar *) "ioTypeDefinitions") ){ cout << "ioTypeDefinitions not the root element" << endl; return result; } /* Step down to ReG_steer_message and then to IOType_defs */ cur = cur->xmlChildrenNode->xmlChildrenNode; msg = New_msg_struct(); msg->msg_type = IO_DEFS; msg->io_def = New_io_def_struct(); parseIOTypeDef(doc, ns, cur, msg->io_def); Print_msg(msg); if(!(ioPtr = msg->io_def->first_io) ){ fprintf(stderr, "Got no IOType definitions from data source\n"); return result; } i = 0; printf("Available IOTypes:\n"); while(ioPtr){ if( !xmlStrcmp(ioPtr->direction, (const xmlChar *)"OUT") ){ printf(" %d: %s\n", i++, (char *)ioPtr->label); } ioPtr = ioPtr->next; } count = i-1; /* printf("Enter IOType to use as data source (0-%d): ", count); while(1){ if(scanf("%d", &i) == 1)break; } printf("\n"); */ // ARPDBG - temporary hardwire to select first output IOType //i = 0; count = 0; ioPtr = msg->io_def->first_io; while(ioPtr){ if( !xmlStrcmp(ioPtr->direction, (const xmlChar *)"OUT") ){ //if(count == i){ ARPDBG - temporary hardwire to select first output IOType strncpy(iodef_label, (char *)(ioPtr->label), 256); break; //}ARPDBG count++; } ioPtr = ioPtr->next; } Delete_msg_struct(&msg); // Initialize job_details struct snprintf(job.userName, REG_MAX_STRING_LENGTH, config.mJobData->mPersonLaunching.ascii()); snprintf(job.group, REG_MAX_STRING_LENGTH, "RSS"); snprintf(job.software, REG_MAX_STRING_LENGTH, config.mJobData->mSoftwareDescription.ascii()); snprintf(job.purpose, REG_MAX_STRING_LENGTH, config.mJobData->mPurposeOfJob.ascii()); snprintf(job.inputFilename, REG_MAX_STRING_LENGTH, config.mInputFileName.ascii()); job.lifetimeMinutes = config.mTimeToRun; snprintf(job.passphrase, REG_MAX_STRING_LENGTH, config.simulationGSH.mSecurity.passphrase); snprintf(job.checkpointAddress, REG_MAX_STRING_LENGTH, config.currentCheckpointGSH.ascii()); // Now create SWS for the vis if( !(EPR = Create_steering_service(&job, factory.ascii(), config.topLevelRegistryGSH.ascii(), &(config.registrySecurity)) ) ){ cout << "FAILED to create SWS for " << config.mJobData->mSoftwareDescription << " :-(" << endl; soap_end(&mySoap); soap_done(&mySoap); return result; } // Finally, set it up with information on the data source // Check to see whether or not an ioProxy is being used if( Get_resource_property (&mySoap, config.simulationGSH.mEPR.ascii(), config.simulationGSH.mSecurity.userDN, config.simulationGSH.mSecurity.passphrase, "dataSink", &ioTypes) != REG_SUCCESS ){ cout << "Call to get dataSink ResourceProperty on "<< config.simulationGSH.mEPR << " failed" << endl; return result; } // <sws:dataSink xmlns:sws="http://www.sve.man.ac.uk/SWS"> // <Proxy> // <address>methuselah.mvc.mcc.ac.uk</address> // <port>50010</port> // </Proxy> // </sws:dataSink> cout << "ARPDBG: Got dataSink >>" << ioTypes << "<<" << endl; char *ptr, *ptr0, *ptr1; proxyPort = 0; proxyAddress[0] = '\0'; if( ptr0 = strstr(ioTypes, "<Proxy>") ){ // An ioProxy IS being used by the simulation ptr1 = NULL; ptr = strstr(ptr0, "<address"); if(ptr)ptr = strstr(ptr, ">"); if(ptr)ptr++; if(ptr)ptr1 = strstr(ptr, "</address>"); if(ptr1)*ptr1 = '\0'; if(ptr1)strncpy(proxyAddress, ptr, 1024); if(ptr1)*ptr1 = '<'; ptr = strstr(ptr0, "<port"); if(ptr)ptr = strstr(ptr, ">"); if(ptr)ptr++; if(ptr)ptr1 = strstr(ptr, "</port>"); if(ptr1)*ptr1 = '\0'; if(ptr1)proxyPort = atoi(ptr); int idx = snprintf(purpose, 1024, "<dataSink><Proxy><address>%s</address>" "<port>%d</port></Proxy></dataSink>", proxyAddress, proxyPort); snprintf(&(purpose[idx]), 1024, "<dataSource><Proxy><address>%s" "</address><port>%d</port></Proxy><sourceLabel>%s" "</sourceLabel></dataSource>", proxyAddress, proxyPort, iodef_label); } else{ snprintf(purpose, 1024, "<dataSource><sourceEPR>%s</sourceEPR>" "<sourceLabel>%s</sourceLabel></dataSource>", config.simulationGSH.mEPR.ascii(), iodef_label); } printf("Calling Set_resource_property with >>%s<<\n", purpose); if(Set_resource_property(&mySoap, EPR, config.simulationGSH.mSecurity.userDN, config.simulationGSH.mSecurity.passphrase, purpose) != REG_SUCCESS){ cout << "Set_resource_property failed:" << endl; soap_end(&mySoap); soap_done(&mySoap); return result; } result = QString(EPR); soap_end(&mySoap); soap_done(&mySoap); #endif // ndef REG_WSRF return result; }
/* Create an SGS or SWS to associate with a simulation */ QString Gridifier::makeSteeringService(const QString &factory, const LauncherConfig &config){ QString result; #ifndef REG_WSRF QProcess *makeSimSGSProcess = new QProcess(QString("./make_sgs.pl")); makeSimSGSProcess->setWorkingDirectory(mScriptsDir); makeSimSGSProcess->addArgument(factory); // the tag is handled correctly if it contains spaces - thanks QT! makeSimSGSProcess->addArgument(config.mJobData->toXML(QString("SGS"))); makeSimSGSProcess->addArgument(config.topLevelRegistryGSH); makeSimSGSProcess->addArgument(config.currentCheckpointGSH); makeSimSGSProcess->addArgument(config.mInputFileName); makeSimSGSProcess->addArgument(QString::number(config.mTimeToRun)); if (config.treeTag.length() > 0){ makeSimSGSProcess->addArgument(config.treeTag); makeSimSGSProcess->addArgument(config.checkPointTreeFactoryGSH); } makeSimSGSProcess->start(); while(makeSimSGSProcess->isRunning()){ usleep(10000); mApplication->processEvents(); } // Grab the sgs and return it // Do some error checking here - or in the calling class? result = QString(makeSimSGSProcess->readStdout()).stripWhiteSpace(); #else // REG_WSRF is defined struct reg_job_details job; char *chkTree; // Initialize job_details struct snprintf(job.userName, REG_MAX_STRING_LENGTH, config.mJobData->mPersonLaunching.ascii()); snprintf(job.group, REG_MAX_STRING_LENGTH, "RSS"); snprintf(job.software, REG_MAX_STRING_LENGTH, config.mJobData->mSoftwareDescription.ascii()); snprintf(job.purpose, REG_MAX_STRING_LENGTH, config.mJobData->mPurposeOfJob.ascii()); snprintf(job.inputFilename, REG_MAX_STRING_LENGTH, config.mInputFileName.ascii()); job.lifetimeMinutes = config.mTimeToRun; snprintf(job.passphrase, REG_MAX_STRING_LENGTH, config.mServicePassword.ascii()); // Create a new checkpoint tree if requested if(config.treeTag.length()){ chkTree = Create_checkpoint_tree(config.checkPointTreeFactoryGSH.ascii(), config.treeTag.ascii()); if(!chkTree){ QMessageBox::critical( NULL, "Checkpoint tree error", "Failed to create new checkpoint tree.\n\n", QMessageBox::Ok, 0, 0 ); return result; } } else{ chkTree = (char *)(config.currentCheckpointGSH.ascii()); } snprintf(job.checkpointAddress, REG_MAX_STRING_LENGTH, chkTree); char *EPR = Create_steering_service(&job, factory.ascii(), config.topLevelRegistryGSH.ascii(), &(config.registrySecurity)); result = QString(EPR); struct soap mySoap; soap_init(&mySoap); // Put contents of input deck (if any) into the RP doc of the SWS if( EPR && !(config.mInputFileName.isEmpty()) ){ QFile *inputFile = new QFile(config.mInputFileName); inputFile->open( IO_ReadOnly ); QByteArray fileData = inputFile->readAll(); inputFile->close(); QString fileRP("<inputFileContent><![CDATA["); fileRP.append(fileData.data()); fileRP.append("]]></inputFileContent>"); if(Set_resource_property(&mySoap, EPR, job.userName, job.passphrase, (char *)(fileRP.ascii()) ) != REG_SUCCESS){ cout << "Gridifier::makeSteeringService: WARNING - failed to store " "job input file on SWS." << endl; } } if(EPR && config.mIOProxyPort){ QString resourceProp("<dataSink><Proxy><address>"); resourceProp.append(config.mIOProxyAddress); resourceProp.append("</address><port>"); resourceProp.append(QString::number(config.mIOProxyPort, 10)); resourceProp.append("</port></Proxy></dataSink>"); //cout << "Gridifier::makeSteeringService: Calling Set_resource_property " // "with >>" << resourceProp << "<<" << endl; if(Set_resource_property(&mySoap, EPR, job.userName, job.passphrase, (char *)(resourceProp.ascii())) != REG_SUCCESS){ cout << "Gridifier::makeSteeringService: WARNING - failed to set " "details of ioProxy on the SWS" << endl; } } soap_end(&mySoap); soap_done(&mySoap); if(EPR){ cout << "Address of SWS = " << EPR << endl; } else{ cout << "FAILED to create SWS :-(" << endl; } #endif // ndef REG_WSRF return result; }
void GofunURLComposer::fetchWithWebBrowser( ) { QProcess proc; proc.addArgument(GSC::get()->browser_cmd); proc.start(); }
/** Prints the rendered report to the selected printer - displays Qt print dialog */ bool MReportViewer::printReport() { // Check for a report if (report == 0) return false; report->setPrintToPos(printToPos_); if (report->printToPos()) return printPosReport(); #if defined(Q_OS_WIN32) bool gsOk = false; QProcess *procTemp = new QProcess(); procTemp->addArgument(aqApp->gsExecutable()); procTemp->addArgument("--version"); gsOk = procTemp->start(); delete procTemp; if (gsOk) { if (printGhostReport()) return true; } QMessageBox *m = new QMessageBox(tr("Sugerencia"), tr("Si instala Ghostscript (http://www.ghostscript.com) y añade\n" "el directorio de instalación a la ruta de búsqueda de programas\n" "del sistema (PATH), Eneboo podrá utilizarlo para optimizar\n" "sustancialmente la calidad de impresión y para poder generar códigos\nde barras.\n\n"), QMessageBox::Information, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton, this, 0, false); m->show(); #endif // Get the page count int cnt = report->pageCount(); // Check if there is a report or any pages to print if (cnt == 0) { QMessageBox::critical(this, "Kugar", tr("No hay páginas en el\ninforme para."), QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton); return false; } // Set the printer dialog printer = new QPrinter(QPrinter::HighResolution); printer->setPageSize((QPrinter::PageSize) report->pageSize()); if ((QPrinter::PageSize) report->pageSize() == QPrinter::Custom) printer->setCustomPaperSize(report->pageDimensions()); printer->setOrientation((QPrinter::Orientation) report->pageOrientation()); printer->setMinMax(1, cnt); printer->setFromTo(1, cnt); printer->setFullPage(true); printer->setColorMode((QPrinter::ColorMode) colorMode_); printer->setNumCopies(numCopies_); printer->setResolution(dpi_); if (!printerName_.isEmpty()) printer->setPrinterName(printerName_); QString printProg(aqApp->printProgram()); if (!printProg.isEmpty()) printer->setPrintProgram(aqApp->printProgram()); bool printNow = true; if (!printerName_.isNull()) printNow = true; else printNow = printer->setup(qApp->focusWidget()); if (printNow) { QPicture *page; QPainter painter; bool printRev = false; // Save the viewer's page index int viewIdx = report->getCurrentIndex(); // Check the order we are printing the pages if (printer->pageOrder() == QPrinter::LastPageFirst) printRev = true; // Get the count of pages and copies to print int printFrom = printer->fromPage() - 1; int printTo = printer->toPage(); int printCnt = (printTo - printFrom); int printCopies = printer->numCopies(); int totalSteps = printCnt * printCopies; int currentStep = 1; // Set copies to 1, QPrinter copies does not appear to work ... printer->setNumCopies(1); // Setup the progress dialog QProgressDialog progress(tr("Imprimiendo Informe..."), tr("Cancelar"), totalSteps, this, tr("progreso"), true); progress.setMinimumDuration(M_PROGRESS_DELAY); QObject::connect(&progress, SIGNAL(cancelled()), this, SLOT(slotCancelPrinting())); progress.setProgress(0); qApp->processEvents(); // Start the printer painter.begin(printer); QPaintDeviceMetrics pdm(printer); QSize dim(report->pageDimensions()); painter.setWindow(0, 0, dim.width(), dim.height()); painter.setViewport(0, 0, pdm.width(), pdm.height()); // Print each copy for (int j = 0; j < printCopies; j++) { // Print each page in the collection for (int i = printFrom; i < printTo; i++, currentStep++) { if (!printer->aborted()) { progress.setProgress(currentStep); qApp->processEvents(); if (printRev) report->setCurrentPage((printCnt == 1) ? i : (printCnt - 1) - i); else report->setCurrentPage(i); page = report->getCurrentPage(); page->play(&painter); if ((i - printFrom) < printCnt - 1) printer->newPage(); } else { j = printCopies; break; } } if (j < printCopies - 1) printer->newPage(); } // Cleanup printing painter.end(); report->setCurrentPage(viewIdx); delete printer; return true; } delete printer; return false; }
/** Imprime directamente sobre formato PDF */ bool MReportViewer::printReportToPDF(const QString &outPdfFile) { if (report == 0) return false; QString gs(aqApp->gsExecutable()); bool gsOk = false; QProcess *procTemp = new QProcess(); procTemp->addArgument(gs); procTemp->addArgument("--version"); gsOk = procTemp->start(); delete procTemp; if (!gsOk) { QMessageBox *m = new QMessageBox(tr("Falta Ghostscript"), tr("Para poder exportar a PDF debe instalar Ghostscript (http://www.ghostscript.com) y añadir\n" "el directorio de instalación a la ruta de búsqueda de programas\ndel sistema (PATH).\n\n"), QMessageBox::Critical, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton, this, 0, false); m->show(); return false; } QString outPsFile(AQ_DISKCACHE_DIRPATH + "/outprintpdf.ps"); //QString outPsPdfFile(AQ_DISKCACHE_DIRPATH + "/outprintps.pdf"); QFile::remove(outPsFile); //QFile::remove(outPsPdfFile); if (!printReportToPS(outPsFile)) return false; QProcess *proc = new QProcess(); proc->addArgument(gs); proc->addArgument("-q"); proc->addArgument("-dBATCH"); proc->addArgument("-dNOPAUSE"); proc->addArgument("-dSAFER"); proc->addArgument("-dCompatibilityLevel=1.4"); proc->addArgument("-dPDFSETTINGS=/printer"); proc->addArgument("-dAutoFilterColorImages=false"); proc->addArgument("-sColorImageFilter=FlateEncode"); proc->addArgument("-dAutoFilterGrayImages=false"); proc->addArgument("-sGrayImageFilter=FlateEncode"); proc->addArgument(QString("-r%1").arg(dpi_)); switch ((QPrinter::PageSize) report->pageSize()) { case QPrinter::A0: proc->addArgument("-sPAPERSIZE=a0"); break; case QPrinter::A1: proc->addArgument("-sPAPERSIZE=a1"); break; case QPrinter::A2: proc->addArgument("-sPAPERSIZE=a2"); break; case QPrinter::A3: proc->addArgument("-sPAPERSIZE=a3"); break; case QPrinter::A4: proc->addArgument("-sPAPERSIZE=a4"); break; case QPrinter::A5: proc->addArgument("-sPAPERSIZE=a5"); break; case QPrinter::B0: proc->addArgument("-sPAPERSIZE=b0"); break; case QPrinter::B1: proc->addArgument("-sPAPERSIZE=b1"); break; case QPrinter::B2: proc->addArgument("-sPAPERSIZE=b2"); break; case QPrinter::B3: proc->addArgument("-sPAPERSIZE=b3"); break; case QPrinter::B4: proc->addArgument("-sPAPERSIZE=b4"); break; case QPrinter::B5: proc->addArgument("-sPAPERSIZE=b5"); break; case QPrinter::Legal: proc->addArgument("-sPAPERSIZE=legal"); break; case QPrinter::Letter: proc->addArgument("-sPAPERSIZE=letter"); break; case QPrinter::Executive: proc->addArgument("-sPAPERSIZE=executive"); break; default: { QSize sz(report->pageDimensions()); proc->addArgument(QString("-dDEVICEWIDTHPOINTS=%1").arg(sz.width())); proc->addArgument(QString("-dDEVICEHEIGHTPOINTS=%1").arg(sz.height())); } } proc->addArgument("-dAutoRotatePages=/PageByPage"); proc->addArgument("-dUseCIEColor"); proc->addArgument("-sOutputFile=" + outPdfFile); proc->addArgument("-sDEVICE=pdfwrite"); proc->addArgument(outPsFile); if (!proc->start()) { delete proc; return false; } while (proc->isRunning()) qApp->processEvents(); delete proc; qApp->processEvents(); /** proc = new QProcess(); proc->addArgument(gs); proc->addArgument("-q"); proc->addArgument("-dBATCH"); proc->addArgument("-dNOPAUSE"); proc->addArgument("-dSAFER"); proc->addArgument("-dNODISPLAY"); proc->addArgument("-dDELAYSAFER"); proc->addArgument("--"); proc->addArgument("pdfopt.ps"); //Obsoleto desde gs 9.07 proc->addArgument(outPsPdfFile); proc->addArgument(outPdfFile); if (!proc->start()) { delete proc; return false; } while (proc->isRunning()) qApp->processEvents(); delete proc; qApp->processEvents(); **/ return true; }
bool MReportViewer::printGhostReport() { if (report == 0) return false; int cnt = report->pageCount(); if (cnt == 0) return false; QString outPsFile(AQ_DISKCACHE_DIRPATH + "/outprint.ps"); QFile::remove(outPsFile); int backupNumCopies = numCopies_; numCopies_ = 1; if (!printReportToPS(outPsFile)) { numCopies_ = backupNumCopies; return false; } numCopies_ = backupNumCopies; bool gsPrintOk = false; QProcess *procTemp = new QProcess(); procTemp->addArgument("gsprint"); procTemp->addArgument("-help"); gsPrintOk = procTemp->start(); delete procTemp; QProcess *proc = new QProcess(); if (gsPrintOk) { proc->addArgument("gsprint"); proc->addArgument("-color"); proc->addArgument("-query"); proc->addArgument("-from"); proc->addArgument("1"); proc->addArgument("-to"); proc->addArgument(QString("%1").arg(cnt)); proc->addArgument("-copies"); proc->addArgument(QString("%1").arg(numCopies_)); //proc->addArgument("-q"); //proc->addArgument("-dBATCH"); //proc->addArgument("-dNOPAUSE"); proc->addArgument(outPsFile); } else { QString setupPsFile(AQ_DISKCACHE_DIRPATH + "/setup.ps"); QFile::remove(setupPsFile); QFile fileSetup(setupPsFile); if (fileSetup.open(IO_WriteOnly)) { QTextStream stream(&fileSetup); stream << "mark" << "\n"; stream << " /NoCancel true" << "\n"; if (!printerName_.isEmpty()) { QString pName(" /OutputFile (%printer%"); pName += printerName_ + ")"; stream << pName << "\n"; } stream << " /BitsPerPixel 24" << "\n"; stream << " /UserSettings" << "\n"; stream << " <<" << "\n"; stream << " /DocumentName (AbanQ document)" << "\n"; stream << QString(" /DocumentRange [1 %1]").arg(cnt) << "\n"; stream << QString(" /SelectedRange [1 %1]").arg(cnt) << "\n"; stream << QString(" /MaxResolution %1").arg(dpi_) << "\n"; stream << QString(" /Copies %1").arg(numCopies_) << "\n"; stream << " >>" << "\n"; stream << " (mswinpr2) finddevice" << "\n"; stream << " putdeviceprops" << "\n"; stream << "setdevice" << "\n"; if ((QPrinter::PageSize) report->pageSize() == QPrinter::Custom) { QSize sz(report->pageDimensions()); stream << QString("<< /PageSize [%1 %2] /ImagingBBox null >> setpagedevice") .arg(sz.width()) .arg(sz.height()) << "\n"; } fileSetup.close(); } proc->addArgument(aqApp->gsExecutable()); proc->addArgument("-q"); proc->addArgument("-dBATCH"); proc->addArgument("-dNOPAUSE"); proc->addArgument("-dNODISPLAY"); proc->addArgument(QString("-r%1").arg(dpi_)); switch ((QPrinter::PageSize) report->pageSize()) { case QPrinter::A0: proc->addArgument("-sPAPERSIZE=a0"); break; case QPrinter::A1: proc->addArgument("-sPAPERSIZE=a1"); break; case QPrinter::A2: proc->addArgument("-sPAPERSIZE=a2"); break; case QPrinter::A3: proc->addArgument("-sPAPERSIZE=a3"); break; case QPrinter::A4: proc->addArgument("-sPAPERSIZE=a4"); break; case QPrinter::A5: proc->addArgument("-sPAPERSIZE=a5"); break; case QPrinter::B0: proc->addArgument("-sPAPERSIZE=b0"); break; case QPrinter::B1: proc->addArgument("-sPAPERSIZE=b1"); break; case QPrinter::B2: proc->addArgument("-sPAPERSIZE=b2"); break; case QPrinter::B3: proc->addArgument("-sPAPERSIZE=b3"); break; case QPrinter::B4: proc->addArgument("-sPAPERSIZE=b4"); break; case QPrinter::B5: proc->addArgument("-sPAPERSIZE=b5"); break; case QPrinter::Legal: proc->addArgument("-sPAPERSIZE=legal"); break; case QPrinter::Letter: proc->addArgument("-sPAPERSIZE=letter"); break; case QPrinter::Executive: proc->addArgument("-sPAPERSIZE=executive"); break; default: { QSize sz(report->pageDimensions()); proc->addArgument(QString("-dDEVICEWIDTHPOINTS=%1").arg(sz.width())); proc->addArgument(QString("-dDEVICEHEIGHTPOINTS=%1").arg(sz.height())); } } proc->addArgument(setupPsFile); proc->addArgument(outPsFile); } if (!proc->start()) { delete proc; return false; } //QProgressDialog *pd = new QProgressDialog(tr("Enviando a impresora..."), QString::null, 10000, this, tr("sendprintprogress"), true ); //int step = 0; //QApplication::setOverrideCursor(Qt::WaitCursor); while (proc->isRunning()) { //pd->setProgress(step++); qApp->processEvents(); //if (step == 9999) // step = 0; } //QApplication::restoreOverrideCursor(); delete proc; //delete pd; qApp->processEvents(); return true; }
void FLPosPrinter::flush() { if (!file) initFile(); QString fileName(AQ_DISKCACHE_DIRPATH + "/outposprinter.tmp"); for (int i = 0; i < idxBuffer; i++) { if (escBuffer && escBuffer->contains(i)) { const QString &esc = (*escBuffer)[i]; for (int j = 0; j < esc.length(); j++) file->putch(esc[j]); } if (strBuffer && strBuffer->contains(i)) file->putch((*strBuffer)[i]); } file->flush(); file->close(); if (printerName_.isNull()) printerName_ = "localhost:tpv"; int posdots = printerName_.find(":"); QString server = printerName_.left(posdots); QString name = printerName_.right(printerName_.length() - posdots - 1); #ifdef AQ_LPR_EXTERNAL QProcess *proc = new QProcess(); proc->addArgument("lpr.exe"); proc->addArgument("-S"); proc->addArgument(server); proc->addArgument("-P"); proc->addArgument(name); proc->addArgument("-o"); proc->addArgument("l"); proc->addArgument(fileName); if (!proc->start()) qWarning("FLPosPrinter::flush() : Error escribiendo en impresora " + printerName_); while (proc->isRunning()) qApp->processEvents(); qApp->processEvents(); if (proc) delete proc; #else int optc = 6; char *optv[optc]; optv[0] = (char *) "-H"; optv[1] = (char *) server.latin1(); optv[2] = (char *) "-P"; optv[3] = (char *) name.latin1(); optv[4] = (char *) "-l"; optv[5] = (char *) fileName.latin1(); if (lpr_main(optc, optv) != 0) qWarning("FLPosPrinter::flush() : Error escribiendo en impresora /usr/bin/lpr -P " + printerName_); #endif }
bool MReportViewer::printGhostReport() { if (report == 0) return false; int cnt = report->pageCount(); if (cnt == 0) return false; QString outPsFile(AQ_DISKCACHE_DIRPATH + "/outprint.ps"); QFile::remove(outPsFile); if (!printReportToPS(outPsFile)) return false; bool gsPrintOk = false; QProcess *procTemp = new QProcess(); procTemp->addArgument("gsprint"); procTemp->addArgument("-help"); gsPrintOk = procTemp->start(); delete procTemp; QProcess *proc = new QProcess(); if (gsPrintOk) { proc->addArgument("gsprint"); proc->addArgument("-color"); proc->addArgument("-query"); proc->addArgument(outPsFile); } else { QString setupPsFile(AQ_DISKCACHE_DIRPATH + "/setup.ps"); QFile::remove(setupPsFile); QFile fileSetup(setupPsFile); if (fileSetup.open(IO_WriteOnly)) { QTextStream stream(&fileSetup); stream << "mark" << "\n"; stream << " /NoCancel true" << "\n"; if (!printerName_.isEmpty()) { QString pName(" /OutputFile (%printer%"); pName += printerName_ + ")"; stream << pName << "\n"; } stream << " /BitsPerPixel 24" << "\n"; stream << " /UserSettings" << "\n"; stream << " <<" << "\n"; stream << " /DocumentName (AbanQ document)" << "\n"; stream << QString(" /DocumentRange [1 %1]").arg(cnt) << "\n"; stream << QString(" /SelectedRange [1 %1]").arg(cnt) << "\n"; stream << QString(" /MaxResolution %1").arg(dpi_) << "\n"; stream << " >>" << "\n"; stream << " (mswinpr2) finddevice" << "\n"; stream << " putdeviceprops" << "\n"; stream << "setdevice" << "\n"; fileSetup.close(); } proc->addArgument("gswin32c"); proc->addArgument("-q"); proc->addArgument("-dBATCH"); proc->addArgument("-dNOPAUSE"); proc->addArgument("-dNODISPLAY"); proc->addArgument(QString("-r%1").arg(dpi_)); proc->addArgument(setupPsFile); proc->addArgument(outPsFile); } if (!proc->start()) { delete proc; return false; } while (proc->isRunning()) qApp->processEvents(); delete proc; qApp->processEvents(); return true; }