コード例 #1
0
ファイル: engine.cpp プロジェクト: drewbug/kandas
int Kandas::Daemon::Engine::addDevice(const QString &deviceName, const QList<QString> &readKey, const QString &writeKey)
{
    //only register new device if no device with this name exists
    if (m_devices.device(deviceName))
        return Kandas::DeviceExistsAlready;
    //validate input
    if (deviceName.contains('/') || deviceName.contains(' ')) //spaces in the device name are possible, but interfere with the parsing of /proc/ndas/devs
        return Kandas::InvalidDeviceName;
    if (readKey.count() != 4)
        return Kandas::InvalidDeviceKey;
    foreach (const QString &keyBlock, readKey)
        if (!validateKeyBlock(keyBlock))
            return Kandas::InvalidDeviceKey;
    if (!validateKeyBlock(writeKey, true))
        return Kandas::InvalidDeviceKey;
    //build key string
    QString keyString = QStringList(readKey).join(QChar('-'));
    if (!writeKey.isEmpty())
        keyString += '-' + writeKey;
    //call ndasadmin
    QStringList args; args << "register" << keyString << "-n" << deviceName << "-b";
    KProcess process;
    process.setProgram("ndasadmin", args);
    process.setOutputChannelMode(KProcess::OnlyStderrChannel);
    process.start();
    process.waitForFinished();
    const QString errorOutput = QString::fromUtf8(process.readAllStandardError()).simplified();
    if (errorOutput.isEmpty())
        return Kandas::DeviceAdded;
    else if (errorOutput.contains(QLatin1String("register: invalid NDAS ID.")))
        return Kandas::InvalidDeviceKey;
    else
        return Kandas::DeviceAdditionFailed;
    //
}
コード例 #2
0
ファイル: encoderassistant.cpp プロジェクト: KDE/audex
const QString EncoderAssistant::version(const EncoderAssistant::Encoder encoder) {

  KProcess process;
  process.setOutputChannelMode(KProcess::SeparateChannels);
  process.setReadChannel(KProcess::StandardError);
  switch (encoder) {
    case EncoderAssistant::LAME : process.setShellCommand(QString(ENCODER_LAME_BIN)+" "+QString(ENCODER_LAME_VERSION_PARA)); break;
    case EncoderAssistant::OGGENC : process.setShellCommand(QString(ENCODER_OGGENC_BIN)+" "+QString(ENCODER_OGGENC_VERSION_PARA)); break;
    case EncoderAssistant::FLAC : process.setShellCommand(QString(ENCODER_FLAC_BIN)+" "+QString(ENCODER_FLAC_VERSION_PARA)); break;
    case EncoderAssistant::FAAC : process.setShellCommand(QString(ENCODER_FAAC_BIN)+" "+QString(ENCODER_FAAC_VERSION_PARA)); break;
    case EncoderAssistant::WAVE : return "";
    case EncoderAssistant::CUSTOM : return "";
    default : return "";
  }
  process.start();
  if (!process.waitForFinished()) return "";
  QByteArray rawoutput = process.readAllStandardError();
  if (rawoutput.size() == 0) rawoutput = process.readAllStandardOutput();
  QString output(rawoutput);
  QStringList list = output.trimmed().split("\n");
  if (list.count()==0) return "";
  QStringList words = list[0].split(" ");
  if (words.count()==0) return "";

  switch (encoder) {

    case EncoderAssistant::LAME :
      if ((words.contains("version")) && (words.indexOf("version")+1<words.count())) return words[words.indexOf("version")+1];
      if (words.count()<2) return "";
      return words[words.count()-2];

    case EncoderAssistant::OGGENC :

    case EncoderAssistant::FLAC :
      return words.last();

    case EncoderAssistant::FAAC :
      if (list.count()<2) return "";
      words = list[1].split(" ");
      if (words.count()<2) return "";
      if ((words.contains("FAAC")) && (words.indexOf("FAAC")+1<words.count())) return words[words.indexOf("FAAC")+1];
      return words[1];

    case EncoderAssistant::WAVE :

    case EncoderAssistant::CUSTOM :

    default : ;

  }

  return "";

}
コード例 #3
0
ファイル: khc_indexbuilder.cpp プロジェクト: KDE/kde-runtime
void IndexBuilder::slotProcessExited( int exitCode, QProcess::ExitStatus exitStatus )
{
  KProcess *proc = static_cast<KProcess *>(sender());

  if ( exitStatus != QProcess::NormalExit ) {
    kError(1402) << "Process failed" << endl;
    kError(1402) << "stdout output:" << proc->readAllStandardOutput(); 
    kError(1402) << "stderr output:" << proc->readAllStandardError();  
  }
  else if (exitCode != 0 ) {
    kError(1402) << "running" << proc->program() << "failed with exitCode" << exitCode;
    kError(1402) << "stdout output:" << proc->readAllStandardOutput(); 
    kError(1402) << "stderr output:" << proc->readAllStandardError(); 
  }
  delete proc;

  sendProgressSignal();

  processCmdQueue();
}
コード例 #4
0
ファイル: planexecutor.cpp プロジェクト: kcroot/Kup
void PlanExecutor::unmountBupFuse() {
	KProcess lUnmount;
	lUnmount.setOutputChannelMode(KProcess::OnlyStderrChannel);
	lUnmount << QLatin1String("fusermount") << QLatin1String("-u") <<mTempDir;
	if(lUnmount.execute()) {
		KNotification::event(KNotification::Error, i18nc("@title", "Problem"),
		                     i18nc("notification", "Error when trying to unmount backup archive:\n%1",
		                           QString::fromLocal8Bit(lUnmount.readAllStandardError())));
		mShowFilesAction->setChecked(true);
	}
}
コード例 #5
0
ファイル: toc.cpp プロジェクト: KDE/kde-runtime
void TOC::meinprocExited( int exitCode, QProcess::ExitStatus exitStatus)
{
    KProcess *meinproc = static_cast<KProcess *>(sender());
    KXmlGuiWindow *mainWindow = dynamic_cast<KXmlGuiWindow *>( kapp->activeWindow() );

    if ( exitStatus == QProcess::CrashExit || exitCode != 0 ) {
        kError() << "running" << meinproc->program() << "failed with exitCode" << exitCode;
        kError() << "stderr output:" << meinproc->readAllStandardError(); 
        if (mainWindow && !m_alreadyWarned) {
            ; // add warning message box with don't display again option 
              // http://api.kde.org/4.0-api/kdelibs-apidocs/kdeui/html/classKDialog.html
            m_alreadyWarned = true;
        }
        delete meinproc;
        return;
    }

    delete meinproc;

    // add a timestamp to the meinproc4 created xml file
    QFile f( m_cacheFile );
    if ( !f.open( QIODevice::ReadWrite ) )
        return;

    QDomDocument doc;
    if ( !doc.setContent( &f ) )
        return;

    QDomComment timestamp = doc.createComment( QString::number( sourceFileCTime() ) );
    doc.documentElement().appendChild( timestamp );

    // write back updated xml content 
    f.seek( 0 );
    QTextStream stream( &f );
    stream.setCodec( "UTF-8" );
#ifdef Q_WS_WIN
    /*
      the problem that on german systems umlauts are displayed as '?' for unknown (Qt'r related ?) reasons
      is caused by wrong encoding type conversations and has been fixed in kdelibs/kdoctools
      To have propper encoding tags in the xml file, QXmlDocument::save() is used. 
    */
    doc.save(stream, 1, QDomNode::EncodingFromTextStream);

#else
    stream << doc.toString();
#endif
    f.close();
    fillTree();
}
コード例 #6
0
ファイル: kprocesstest.cpp プロジェクト: fluxer/kdelibs
static void recursor(char **argv)
{
    if (argv[1]) {
        KProcess p;
        p.setShellCommand("echo " EOUT "; echo " EERR " >&2");
        p.setOutputChannelMode((KProcess::OutputChannelMode)atoi(argv[1]));
        fputs(POUT, stdout);
        fflush(stdout);
        p.execute();
        fputs(ROUT, stdout);
        fputs(p.readAllStandardOutput(), stdout);
        fputs(RERR, stdout);
        fputs(p.readAllStandardError(), stdout);
        exit(0);
    }
    gargv = argv;
}
コード例 #7
0
bool ImageGrayScale::image2GrayScaleImageMagick(const QString& src, const QString& dest, QString& err)
{
    KProcess process;
    process.clearProgram();
    process << "convert";
    process << "-type" << "Grayscale";
    process << src + QString("[0]") << dest;

    kDebug( 51000 ) << "ImageMagick Command line: " << process.program() << endl;

    process.start();

    if (!process.waitForFinished())
        return false;

    if (process.exitStatus() != QProcess::NormalExit)
        return false;

    switch (process.exitCode())
    {
        case 0:  // Process finished successfully !
        {
            return true;
            break;
        }
        case 15: //  process aborted !
        {
            return false;
            break;
        }
    }

    // Processing error !
    m_stdErr = process.readAllStandardError();
    err      = i18n("Cannot convert to gray scale: %1", m_stdErr.replace('\n', ' '));
    return false;
}
コード例 #8
0
void CameraController::slotCheckRename(const QString& folder, const QString& file,
                                       const QString& destination, const QString& temp,
                                       const QString& script)
{
    // this is the direct continuation of executeCommand, case CameraCommand::cam_download
    bool skip      = false;
    bool cancel    = false;
    bool overwrite = d->overwriteAll;
    QString dest   = destination;

    // Check if dest file already exist, unless we overwrite anyway

    QFileInfo info(dest);

    if (!d->overwriteAll)
    {

        while (info.exists())
        {
            if (d->skipAll)
            {
                skip = true;
                break;
            }

            QPointer<KIO::RenameDialog> dlg = new KIO::RenameDialog(d->parent, i18nc("@title:window", "Rename File"),
                    QString(folder + QLatin1String("/") + file), dest,
                    KIO::RenameDialog_Mode(KIO::M_MULTI     |
                                           KIO::M_OVERWRITE |
                                           KIO::M_SKIP));

            int result = dlg->exec();
            dest       = dlg->newDestUrl().toLocalFile();
            info       = QFileInfo(dest);

            delete dlg;

            switch (result)
            {
            case KIO::R_CANCEL:
            {
                cancel = true;
                break;
            }

            case KIO::R_SKIP:
            {
                skip = true;
                break;
            }

            case KIO::R_AUTO_SKIP:
            {
                d->skipAll = true;
                skip       = true;
                break;
            }

            case KIO::R_OVERWRITE:
            {
                overwrite = true;
                break;
            }

            case KIO::R_OVERWRITE_ALL:
            {
                d->overwriteAll = true;
                overwrite       = true;
                break;
            }

            default:
                break;
            }

            if (cancel || skip || overwrite)
            {
                break;
            }
        }
    }

    if (cancel)
    {
        unlink(QFile::encodeName(temp));
        slotCancel();
        emit signalSkipped(folder, file);
        return;
    }
    else if (skip)
    {
        unlink(QFile::encodeName(temp));
        sendLogMsg(i18n("Skipped file <filename>%1</filename>", file), DHistoryView::WarningEntry, folder, file);
        emit signalSkipped(folder, file);
        return;
    }

    kDebug() << "Checking whether (" << temp << ") has a sidecar";

    // move the file to the destination file
    if (DMetadata::hasSidecar(temp))
    {
        kDebug() << "  Yes, renaming it to " << dest;
        if (KDE::rename(DMetadata::sidecarPath(temp), DMetadata::sidecarPath(dest)) != 0)
        {
            sendLogMsg(i18n("Failed to save sidecar file for <filename>%1</filename>", file), DHistoryView::ErrorEntry,  folder, file);
        }
    }

    if (KDE::rename(temp, dest) != 0)
    {
        kDebug() << "Renaming " << temp << " to " << dest << " failed";
        // rename failed. delete the temp file
        unlink(QFile::encodeName(temp));
        emit signalDownloaded(folder, file, CamItemInfo::DownloadFailed);
        sendLogMsg(i18n("Failed to download <filename>%1</filename>", file), DHistoryView::ErrorEntry,  folder, file);
    }
    else
    {
        kDebug() << "Rename done, emiting downloaded signals:" << file << " info.filename: " << info.fileName();
        // TODO why two signals??
        emit signalDownloaded(folder, file, CamItemInfo::DownloadedYes);
        emit signalDownloadComplete(folder, file, info.path(), info.fileName());

        // Run script
        if (!script.isEmpty())
        {
            kDebug() << "Got a script, processing: " << script;
            KProcess process;

            process.setOutputChannelMode(KProcess::SeparateChannels);
            QString s;

            if (script.indexOf('%') > -1)
            {
                QHash<QString, QString> map;
                map.insert("file", dest);
                map.insert("filename", info.fileName());
                map.insert("path", info.path());
                map.insert("orgfilename", file);
                map.insert("orgpath", folder);
                s = KMacroExpander::expandMacros(script, map);
            }
            else
            {
                s = script + " \"" + dest + "\"";
            }

            process.setShellCommand(s);
            kDebug() << "Running: " << s;
            int ret = process.execute();

            if (ret != 0)
            {
                sendLogMsg(i18n("Failed to run script for <filename>%1</filename>", file), DHistoryView::ErrorEntry,  folder, file);
            }

            kDebug() << "stdout" << process.readAllStandardOutput();
            kDebug() << "stderr" << process.readAllStandardError();
        }
    }
}
コード例 #9
0
bool ImageRotate::rotateImageMagick(const QString& src, const QString& dest, 
                                    RotateAction angle, QString& err)
{
    KProcess process;
    process.clearProgram();
    process << "convert";
    process << "-rotate";

    switch(angle)
    {
        case (Rot90):
        {
            process << "90";
            break;
        }
        case (Rot180):
        {
            process << "180";
            break;
        }
        case (Rot270):
        {
            process << "270";
            break;
        }
        case (Rot0):
        {
            break;
        }
        default:
        {
            kError() << "ImageRotate: Nonstandard rotation angle";
            err = i18n("Nonstandard rotation angle");
            return false;
        }
    }

    process << src + QString("[0]") << dest;

    kDebug() << "ImageMagick Command line: " << process.program();

    process.start();

    if (!process.waitForFinished())
        return false;

    if (process.exitStatus() != QProcess::NormalExit)
        return false;

    switch (process.exitCode())
    {
        case 0:  // Process finished successfully !
        {
            return true;
            break;
        }
        case 15: //  process aborted !
        {
            return false;
            break;
        }
    }

    // Processing error !
    m_stdErr = process.readAllStandardError();
    err      = i18n("Cannot rotate: %1", m_stdErr.replace('\n', ' '));
    return false;
}
コード例 #10
0
ファイル: utils.cpp プロジェクト: UIKit0/digikam
bool Utils::updateMetadataImageMagick(const QString& src, QString& err)
{
    QFileInfo finfo(src);
    if (src.isEmpty() || !finfo.isReadable())
    {
        err = i18n("unable to open source file");
        return false;
    }

    QImage img(src);
    QImage iptcPreview   = img.scaled(1280, 1024, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    QImage exifThumbnail = iptcPreview.scaled(160, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation);

    KExiv2Iface::KExiv2 meta;
    meta.load(src);
    meta.setImageOrientation(KExiv2Iface::KExiv2::ORIENTATION_NORMAL);
    meta.setImageProgramId(QString("Kipi-plugins"), QString(kipiplugins_version));
    meta.setImageDimensions(img.size());
    meta.setExifThumbnail(exifThumbnail);
    meta.setImagePreview(iptcPreview);

#if KEXIV2_VERSION >= 0x010000
    QByteArray exifData = meta.getExifEncoded(true);
#else
    QByteArray exifData = meta.getExif(true);
#endif

    QByteArray iptcData = meta.getIptc(true);
    QByteArray xmpData  = meta.getXmp();

    KTemporaryFile exifTemp;
    exifTemp.setSuffix(QString("kipipluginsexif.app1"));
    exifTemp.setAutoRemove(true);
    if ( !exifTemp.open() )
    {
        err = i18n("unable to open temp file");
        return false;
    }
    QString exifFile = exifTemp.fileName();
    QDataStream streamExif( &exifTemp );
    streamExif.writeRawData(exifData.data(), exifData.size());
    exifTemp.close();

    KTemporaryFile iptcTemp;
    iptcTemp.setSuffix(QString("kipipluginsiptc.8bim"));
    iptcTemp.setAutoRemove(true);
    iptcTemp.open();
    if ( !iptcTemp.open() )
    {
        err = i18n("Cannot rotate: unable to open temp file");
        return false;
    }
    QString iptcFile = iptcTemp.fileName();
    QDataStream streamIptc( &iptcTemp );
    streamIptc.writeRawData(iptcData.data(), iptcData.size());
    iptcTemp.close();

    KTemporaryFile xmpTemp;
    xmpTemp.setSuffix(QString("kipipluginsxmp.xmp"));
    xmpTemp.setAutoRemove(true);
    if ( !xmpTemp.open() )
    {
        err = i18n("unable to open temp file");
        return false;
    }
    QString xmpFile = xmpTemp.fileName();
    QDataStream streamXmp( &xmpTemp );
    streamXmp.writeRawData(xmpData.data(), xmpData.size());
    xmpTemp.close();

    KProcess process;
    process.clearProgram();
    process << "mogrify";

    process << "-profile";
    process << exifFile;

    process << "-profile";
    process << iptcFile;

    process << "-profile";
    process << xmpFile;

    process << src + QString("[0]");

    kDebug() << "ImageMagick Command line: " << process.program();

    process.start();

    if (!process.waitForFinished())
        return false;

    if (process.exitStatus() != QProcess::NormalExit)
        return false;

    switch (process.exitCode())
    {
        case 0:  // Process finished successfully !
        {
            return true;
            break;
        }
        case 15: //  process aborted !
        {
            return false;
            break;
        }
    }

    // Processing error !
    m_stdErr = process.readAllStandardError();
    err      = i18n("Cannot update metadata: %1", m_stdErr.replace('\n', ' '));
    return false;
}