Example #1
0
void MyProcess::SLOT_Stderr( Opie::Core::OProcess * , char * Buf, int len ) {
      if( EchoMode ) {
        write( 2, Buf, len );
        return;
      }

      char * LB = (char *)alloca( len + 1 );
      memcpy( LB, Buf, len );
      LB[len] = '\0';

      // now input is zero terminated
      StderrBuffer += LB;

      odebug << "Received " << len << " bytes on stderr" << oendl;
      // see if we have some lines (allow empty lines)
      QStringList SL = QStringList::split( "\n", StderrBuffer, TRUE );

      for( unsigned int i = 0; i < SL.count()-1; i ++ ) {
        Log(( "Stderr : \"%s\"\n", SL[i].latin1() ) );
        emit stderrLine( SL[i] );
      }

      // last line is rest
      StderrBuffer = SL[ SL.count()-1 ];
}
Example #2
0
void K3b::IsoImager::start()
{
    jobStarted();

    cleanup();

    d->mkisofsBin = initMkisofs();
    if( !d->mkisofsBin ) {
        jobFinished( false );
        return;
    }

    initVariables();

    delete m_process;
    m_process = new K3b::Process( this );
    m_process->setFlags( K3bQProcess::RawStdout );

    *m_process << d->mkisofsBin;

    // prepare the filenames as written to the image
    m_doc->prepareFilenames();

    if( !prepareMkisofsFiles() ||
        !addMkisofsParameters() ) {
        cleanup();
        jobFinished( false );
        return;
    }

    connect( m_process, SIGNAL(finished(int,QProcess::ExitStatus)),
             this, SLOT(slotProcessExited(int,QProcess::ExitStatus)) );
    connect( m_process, SIGNAL(stderrLine(QString)),
             this, SLOT(slotReceivedStderr(QString)) );

    qDebug() << "***** mkisofs parameters:\n";
    QString s = m_process->joinedArgs();
    qDebug() << s << endl << flush;
    emit debuggingOutput("mkisofs command:", s);

    if( !m_process->start( KProcess::SeparateChannels ) ) {
        // something went wrong when starting the program
        // it "should" be the executable
        qDebug() << "(K3b::IsoImager) could not start mkisofs";
        emit infoMessage( i18n("Could not start %1.", QLatin1String("mkisofs")), K3b::Job::MessageError );
        jobFinished( false );
        cleanup();
    }
}
Example #3
0
void K3b::DvdFormattingJob::startFormatting( const Device::DiskInfo& diskInfo )
{
    //
    // Now check the media type:
    // if DVD-RW: use d->mode
    //            emit warning if formatting is full and stuff
    //
    // in overwrite mode: emit info that progress might stop before 100% since formatting will continue
    //                    in the background once the media gets rewritten (only DVD+RW/BD-RE?)
    //


    // emit info about what kind of media has been found
    if( diskInfo.mediaType() & (Device::MEDIA_REWRITABLE_DVD | Device::MEDIA_BD_RE) ) {
        emit infoMessage( i18n("Found %1 medium.", Device::mediaTypeString(diskInfo.mediaType())),
                        MessageInfo );
    }
    else {
        emit infoMessage( i18n("No rewritable DVD or BD medium found. Unable to format."), MessageError );
        d->running = false;
        jobFinished(false);
        return;
    }

    bool format = true;  // do we need to format
    bool blank = false;  // blank is for DVD-RW sequential incremental
    // DVD-RW restricted overwrite and DVD+RW uses the force option (or no option at all)

    //
    // DVD+RW/BD-RE is quite easy to handle. There is only one possible mode and it is always recommended to not
    // format it more than once but to overwrite it once it is formatted
    // Once the initial formatting has been done it's always "appendable" (or "complete"???)
    //

    if( diskInfo.mediaType() & (Device::MEDIA_DVD_PLUS_ALL | Device::MEDIA_BD_RE) ) {

        if( diskInfo.empty() ) {
            //
            // The DVD+RW/BD is blank and needs to be initially formatted
            //
            blank = false;
        }
        else {
            emit infoMessage( i18n("No need to format %1 media more than once.",
                                   Device::mediaTypeString(diskInfo.mediaType())), MessageInfo );
            emit infoMessage( i18n("It may simply be overwritten."), MessageInfo );

            if( d->force ) {
                emit infoMessage( i18n("Forcing formatting anyway."), MessageInfo );
                emit infoMessage( i18n("It is not recommended to force formatting of %1 media.",
                                       Device::mediaTypeString(diskInfo.mediaType())), MessageInfo );
                emit infoMessage( i18n("After 10-20 reformats the media might become unusable."), MessageInfo );
                blank = false;
            }
            else {
                format = false;
            }
        }

        if( format )
            emit newSubTask( i18n("Formatting %1 medium", Device::mediaTypeString(diskInfo.mediaType())) );
    }

    //
    // DVD-RW has two modes: incremental sequential (the default which is also needed for DAO writing)
    // and restricted overwrite which compares to the DVD+RW mode.
    //

    else {  // MEDIA_DVD_RW

        if( diskInfo.currentProfile() != Device::MEDIA_UNKNOWN ) {
            emit infoMessage( i18n("Formatted in %1 mode.",Device::mediaTypeString(diskInfo.currentProfile())), MessageInfo );


            //
            // Is it possible to have an empty DVD-RW in restricted overwrite mode???? I don't think so.
            //

            if( diskInfo.empty() &&
                (d->mode == WritingModeAuto ||
                 (d->mode == WritingModeIncrementalSequential &&
                  diskInfo.currentProfile() == Device::MEDIA_DVD_RW_SEQ) ||
                 (d->mode == WritingModeRestrictedOverwrite &&
                  diskInfo.currentProfile() == Device::MEDIA_DVD_RW_OVWR) )
                ) {
                emit infoMessage( i18n("Media is already empty."), MessageInfo );
                if( d->force )
                    emit infoMessage( i18n("Forcing formatting anyway."), MessageInfo );
                else
                    format = false;
            }
            else if( diskInfo.currentProfile() == Device::MEDIA_DVD_RW_OVWR &&
                     d->mode != WritingModeIncrementalSequential ) {
                emit infoMessage( i18n("No need to format %1 media more than once.",
                                  Device::mediaTypeString(diskInfo.currentProfile())), MessageInfo );
                emit infoMessage( i18n("It may simply be overwritten."), MessageInfo );

                if( d->force )
                    emit infoMessage( i18n("Forcing formatting anyway."), MessageInfo );
                else
                    format = false;
            }

            if( format ) {
                if( d->mode == WritingModeAuto ) {
                    // just format in the same mode as the media is currently formatted
                    blank = (diskInfo.currentProfile() == Device::MEDIA_DVD_RW_SEQ);
                }
                else {
                    blank = (d->mode == WritingModeIncrementalSequential);
                }

                emit newSubTask( i18n("Formatting"
                                      " DVD-RW in %1 mode.",Device::mediaTypeString( blank ?
                                                                                     Device::MEDIA_DVD_RW_SEQ :
                                                                                     Device::MEDIA_DVD_RW_OVWR )) );
            }
        }
        else {
            emit infoMessage( i18n("Unable to determine the current formatting state of the DVD-RW medium."), MessageError );
            d->running = false;
            jobFinished(false);
            return;
        }
    }


    if( format ) {
        delete d->process;
        d->process = new Process();
        connect( d->process, SIGNAL(stderrLine(QString)), this, SLOT(slotStderrLine(QString)) );
        connect( d->process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotProcessFinished(int,QProcess::ExitStatus)) );

        d->dvdFormatBin = k3bcore->externalBinManager()->binObject( "dvd+rw-format" );
        if( !d->dvdFormatBin ) {
            emit infoMessage( i18n("Could not find %1 executable.",QString("dvd+rw-format")), MessageError );
            d->running = false;
            jobFinished(false);
            return;
        }

        if( !d->dvdFormatBin->copyright().isEmpty() )
            emit infoMessage( i18n("Using %1 %2 – Copyright © %3",d->dvdFormatBin->name(),d->dvdFormatBin->version(),d->dvdFormatBin->copyright()), MessageInfo );


        *d->process << d->dvdFormatBin;

        if( d->dvdFormatBin->version() >= Version( 4, 6 ) )
            *d->process << "-gui";

        QString p;
        if( blank )
            p = "-blank";
        else
            p = "-force";
        if( d->formattingMode == FormattingComplete )
            p += "=full";

        *d->process << p;

        *d->process << d->device->blockDeviceName();

        // additional user parameters from config
        const QStringList& params = d->dvdFormatBin->userParameters();
        for( QStringList::const_iterator it = params.begin(); it != params.end(); ++it )
            *d->process << *it;

        qDebug() << "***** dvd+rw-format parameters:\n";
        QString s = d->process->joinedArgs();
        qDebug() << s << endl << flush;
        emit debuggingOutput( "dvd+rw-format command:", s );

        if( !d->process->start( KProcess::OnlyStderrChannel ) ) {
            // something went wrong when starting the program
            // it "should" be the executable
            qDebug() << "(K3b::DvdFormattingJob) could not start " << d->dvdFormatBin->path();
            emit infoMessage( i18n("Could not start %1.",d->dvdFormatBin->name()), Job::MessageError );
            d->running = false;
            jobFinished(false);
        }
        else {
            emit newTask( i18n("Formatting") );
        }
    }
    else {
Example #4
0
void K3b::IsoImager::startSizeCalculation()
{
    d->mkisofsBin = initMkisofs();
    if( !d->mkisofsBin ) {
        jobFinished( false );
        return;
    }

    initVariables();

    delete m_process;
    m_process = new K3b::Process( this );
    m_process->setSplitStdout(true);

    emit debuggingOutput( QLatin1String( "Used versions" ), QString::fromLatin1( "mkisofs: %1").arg(d->mkisofsBin->version()) );

    *m_process << d->mkisofsBin;

    if( !prepareMkisofsFiles() ||
        !addMkisofsParameters(true) ) {
        cleanup();
        jobFinished( false );
        return;
    }

    // add empty dummy dir since one path-spec is needed
    // ??? Seems it is not needed after all. At least mkisofs 1.14 and above don't need it. ???
    //  *m_process << dummyDir();

    qDebug() << "***** mkisofs calculate size parameters:";
    QString s = m_process->joinedArgs();
    qDebug() << s << endl << flush;
    emit debuggingOutput("mkisofs calculate size command:", s);

    // since output changed during mkisofs version changes we grab both
    // stdout and stderr

    // mkisofs version >= 1.15 (don't know about 1.14!)
    // the extends on stdout (as lonely number)
    // and error and warning messages on stderr

    // mkisofs >= 1.13
    // everything is written to stderr
    // last line is: "Total extents scheduled to be written = XXXXX"

    connect( m_process, SIGNAL(stdoutLine(QString)),
             this, SLOT(slotCollectMkisofsPrintSizeStdout(QString)) );
    connect( m_process, SIGNAL(stderrLine(QString)),
             this, SLOT(slotCollectMkisofsPrintSizeStderr(QString)) );
    connect( m_process, SIGNAL(finished(int,QProcess::ExitStatus)),
             this, SLOT(slotMkisofsPrintSizeFinished()) );

    // we also want error messages
    connect( m_process, SIGNAL(stderrLine(QString)),
             this, SLOT(slotReceivedStderr(QString)) );

    m_collectedMkisofsPrintSizeStdout = QString();
    m_collectedMkisofsPrintSizeStderr = QString();
    m_mkisofsPrintSizeResult = 0;

    if( !m_process->start( KProcess::SeparateChannels ) ) {
        emit infoMessage( i18n("Could not start %1.",QString("mkisofs")), K3b::Job::MessageError );
        cleanup();

        jobFinished( false );
        return;
    }
}