static void slipInFilter(KProcess & proc, KTextEditor::View & view, QString command) { QString inputText; if (view.selection()) { inputText = view.selectionText(); } proc.clearProgram (); proc.setShellCommand(command); proc.start(); QByteArray encoded = inputText.toLocal8Bit(); proc.write(encoded); proc.closeWriteChannel(); // TODO: Put up a modal dialog to defend the text from further // keystrokes while the command is out. With a cancel button... }
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; }
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; }
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; }