예제 #1
0
void ReportGenerator::runTrml2Pdf( const QString& rmlFile, const QString& docID, const QString& archId )
{
    mErrors.clear();
    // findTrml2Pdf returns a list of command line parts for the converter, such as
    // /usr/bin/pyhton /usr/local/share/erml2pdf.py
    QStringList rmlbin = findTrml2Pdf();

    if ( ! rmlbin.size() ) {
        mErrors = i18n("The utility to create PDF from the rml file could not be found, "
                       "but is required to create documents.\n");
        mErrors += i18n("Please make sure the package is installed accordingly.");

        trml2pdfFinished(1, QProcess::NormalExit);
    }

    QApplication::setOverrideCursor( QCursor( Qt::BusyCursor ) );

    if ( mHavePdfMerge && mMergeIdent != "0" &&
         ( mWatermarkFile.isEmpty() || !QFile::exists( mWatermarkFile ) ) ) {
        QMessageBox msgBox;
        msgBox.setText(i18n("The Watermark file to merge with the document could not be found. "
                            "Merge is going to be disabled."));
        msgBox.setWindowTitle(i18n("Watermark Error"));
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.exec();
        mMergeIdent = "0";
    }

    const QString outputDir = ArchiveMan::self()->pdfBaseDir();
    const QString filename = ArchiveMan::self()->archiveFileName( docID, archId, "pdf" );
    mFile.setFileName( QString( "%1/%2").arg( outputDir).arg( filename ) );

    // qDebug () << "Writing output to " << mFile.fileName();

    // check if we have etrml2pdf
    bool haveErml = false;
    QStringList args;

    if( rmlbin.size() > 1 ) {
        QString ermlbin = rmlbin[1];
        if( ermlbin.endsWith( "erml2pdf.py") ) {
            haveErml = true;
        }
        args.append(rmlbin.at(1));
    }

    const QString prg = rmlbin.at(0);

    if( !haveErml ) {
        if ( mHavePdfMerge ) {
            args << mMergeIdent;
        }
        args << rmlFile;
        if ( mHavePdfMerge && mMergeIdent != "0" ) {
            args << mWatermarkFile;
        }
    } else {
        // qDebug () << "Erml2pdf available!";
        if ( mHavePdfMerge && mMergeIdent != "0" ) {
            args << "-m" << mMergeIdent;
            args << "-w" << mWatermarkFile;
        }
        args << rmlFile;
    }

    mOutputSize = 0;
    if ( mFile.open( QIODevice::WriteOnly ) ) {
        qDebug() << "Converting " << rmlFile << "using" << prg << args.join(QChar(' '));
        mProcess = new QProcess(this);
        connect(mProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReceivedStdout()));
        connect(mProcess, SIGNAL(readyReadStandardError()), this, SLOT(slotReceivedStderr()));
        connect(mProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this,
                SLOT(trml2pdfFinished(int,QProcess::ExitStatus)));

        mProcess->setProgram( prg );
        mProcess->setArguments(args);
        mTargetStream.setDevice( &mFile );

        mProcess->start( );
    } else {
예제 #2
0
void ReportGenerator::runTrml2Pdf( const QString& rmlFile, const QString& docID, const QString& archId )
{
  mProcess.clearProgram();

  QStringList prg;

  mErrors = QString();
  // findTrml2Pdf returns a list of command line parts for the converter, such as
  // /usr/bin/pyhton /usr/local/share/erml2pdf.py
  QStringList rmlbin = findTrml2Pdf();

  if ( ! rmlbin.size() ) {

    KMessageBox::error( 0, i18n("The utility to create PDF from the rml file could not be found, "
                                "but is required to create documents."
                                "Please make sure the package is installed accordingly." ),
                        i18n( "Document Generation Error" ) );
    return;
  }

  QApplication::setOverrideCursor( QCursor( Qt::BusyCursor ) );

  if ( mHavePdfMerge && mMergeIdent != "0" &&
       ( mWatermarkFile.isEmpty() || !QFile::exists( mWatermarkFile ) ) ) {
    KMessageBox::error( 0, i18n("The Watermark file to merge with the document could not be found. "
                                "Merge is going to be disabled." ),
                        i18n( "Watermark Error" ) );
    mMergeIdent = "0";
  }

  QString outputDir = ArchiveMan::self()->pdfBaseDir();
  QString filename = ArchiveMan::self()->archiveFileName( docID, archId, "pdf" );
  mFile.setFileName( QString( "%1/%2").arg( outputDir).arg( filename ) );

  kDebug() << "Writing output to " << mFile.fileName();

  // check if we have etrml2pdf
  bool haveErml = false;
  if( rmlbin.size() > 1 ) {
    QString ermlbin = rmlbin[1];
    if( ermlbin.endsWith( "erml2pdf.py") ) {
      haveErml = true;
    }
  }

  prg << rmlbin;

  if( !haveErml ) {
    if ( mHavePdfMerge ) {
        prg << mMergeIdent;
    }
    prg << rmlFile;
    if ( mHavePdfMerge && mMergeIdent != "0" ) {
      prg << mWatermarkFile;
    }
  } else {
    kDebug() << "Erml2pdf available!";
    if ( mHavePdfMerge && mMergeIdent != "0" ) {
      prg << "-m" << mMergeIdent;
      prg << "-w" << mWatermarkFile;
    }
    prg << rmlFile;
  }

  mFile.setFileName( mFile.fileName() );
  mOutputSize = 0;
  if ( mFile.open( QIODevice::WriteOnly ) ) {
    mProcess.setProgram( prg );
    mTargetStream.setDevice( &mFile );
    QStringList args = mProcess.program();
    kDebug() << "* rml2pdf Call-Arguments: " << args;

    mProcess.start( );
  }
}