本文整理汇总了C++中KTempFile::setAutoDelete方法的典型用法代码示例。如果您正苦于以下问题:C++ KTempFile::setAutoDelete方法的具体用法?C++ KTempFile::setAutoDelete怎么用?C++ KTempFile::setAutoDelete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KTempFile
的用法示例。
在下文中一共展示了KTempFile::setAutoDelete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: copyfile
QString copyfile(const QString &filename)
{
kdDebug(500) << "Copying file " << filename << endl;
QString result;
QFile f(filename);
if(f.open(IO_ReadOnly))
{
KTempFile temp;
temp.setAutoDelete(false);
QFile *tf = temp.file();
if(tf)
{
char buffer[0xFFFF];
int b = 0;
while((b = f.readBlock(buffer, 0xFFFF)) > 0)
{
if(tf->writeBlock(buffer, b) != b)
break;
}
tf->close();
if(b > 0)
temp.setAutoDelete(true);
else
{
kdDebug(500) << "File copied to " << temp.name() << endl;
result = temp.name();
}
}
else
temp.setAutoDelete(true);
f.close();
}
return result;
}
示例2: slotCreateFile
void BaseTreeView::slotCreateFile()
{
bool ok;
QString fileName = KInputDialog::getText(i18n("Create New File"), i18n("File name:"), "", &ok, this);
if (ok)
{
KURL url = currentURL();
if (currentKFileTreeViewItem()->isDir())
url.setPath(url.path() + "/" + fileName);
else
url.setPath(url.directory() + "/" + fileName);
if (QExtFileInfo::exists(url, false, this))
{
KMessageBox::error(this, i18n("<qt>Cannot create file, because a file named <b>%1</b> already exists.</qt>").arg(fileName), i18n("Error Creating File"));
return;
}
KTempFile *tempFile = new KTempFile(tmpDir);
tempFile->setAutoDelete(true);
tempFile->close();
if (QuantaNetAccess::copy(KURL::fromPathOrURL(tempFile->name()), url, this))
{
emit openFile(url);
}
delete tempFile;
}
}
示例3: saveGame
void KJumpingCube::saveGame(bool saveAs)
{
if(saveAs || gameURL.isEmpty())
{
int result=0;
KURL url;
do
{
url = KFileDialog::getSaveURL(gameURL.url(),"*.kjc",this,0);
if(url.isEmpty())
return;
// check filename
QRegExp pattern("*.kjc",true,true);
if(!pattern.exactMatch(url.filename()))
{
url.setFileName( url.filename()+".kjc" );
}
if(KIO::NetAccess::exists(url,false,this))
{
QString mes=i18n("The file %1 exists.\n"
"Do you want to overwrite it?").arg(url.url());
result = KMessageBox::warningContinueCancel(this, mes, QString::null, i18n("Overwrite"));
if(result==KMessageBox::Cancel)
return;
}
}
while(result==KMessageBox::No);
gameURL=url;
}
KTempFile tempFile;
tempFile.setAutoDelete(true);
KSimpleConfig config(tempFile.name());
config.setGroup("KJumpingCube");
config.writeEntry("Version",KJC_VERSION);
config.setGroup("Game");
view->saveGame(&config);
config.sync();
if(KIO::NetAccess::upload( tempFile.name(),gameURL,this ))
{
QString s=i18n("game saved as %1");
s=s.arg(gameURL.url());
statusBar()->message(s,MESSAGE_TIME);
}
else
{
KMessageBox::sorry(this,i18n("There was an error in saving file\n%1").arg(gameURL.url()));
}
}
示例4: processDropEvent
void KOrganizerPlugin::processDropEvent( QDropEvent *event )
{
QString text;
KABC::VCardConverter converter;
if ( KVCardDrag::canDecode( event ) && KVCardDrag::decode( event, text ) ) {
KABC::Addressee::List contacts = converter.parseVCards( text );
KABC::Addressee::List::Iterator it;
QStringList attendees;
for ( it = contacts.begin(); it != contacts.end(); ++it ) {
QString email = (*it).fullEmail();
if ( email.isEmpty() )
attendees.append( (*it).realName() + "<>" );
else
attendees.append( email );
}
interface()->openEventEditor( i18n( "Meeting" ), QString::null, QString::null,
attendees );
return;
}
if ( QTextDrag::decode( event, text ) ) {
kdDebug(5602) << "DROP:" << text << endl;
interface()->openEventEditor( text );
return;
}
KPIM::MailList mails;
if ( KPIM::MailListDrag::decode( event, mails ) ) {
if ( mails.count() != 1 ) {
KMessageBox::sorry( core(),
i18n("Drops of multiple mails are not supported." ) );
} else {
KPIM::MailSummary mail = mails.first();
QString txt = i18n("From: %1\nTo: %2\nSubject: %3").arg( mail.from() )
.arg( mail.to() ).arg( mail.subject() );
KTempFile tf;
tf.setAutoDelete( true );
QString uri = QString::fromLatin1("kmail:") + QString::number( mail.serialNumber() );
tf.file()->writeBlock( event->encodedData( "message/rfc822" ) );
tf.close();
interface()->openEventEditor( i18n("Mail: %1").arg( mail.subject() ), txt,
uri, tf.name(), QStringList(), "message/rfc822" );
}
return;
}
KMessageBox::sorry( core(), i18n("Cannot handle drop events of type '%1'.")
.arg( event->format() ) );
}
示例5: doExport
bool VCardXXPort::doExport( const KURL &url, const QString &data )
{
KTempFile tmpFile;
tmpFile.setAutoDelete( true );
QTextStream stream( tmpFile.file() );
stream.setEncoding( QTextStream::UnicodeUTF8 );
stream << data;
tmpFile.close();
return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
}
示例6: pasteData
KIO_EXPORT void KIO::pasteData(const KURL &u, const QByteArray &_data)
{
KURL new_url = getNewFileName(u, QString::null);
// We could use KIO::put here, but that would require a class
// for the slotData call. With NetAccess, we can do a synchronous call.
if(new_url.isEmpty())
return;
KTempFile tempFile;
tempFile.setAutoDelete(true);
tempFile.dataStream()->writeRawBytes(_data.data(), _data.size());
tempFile.close();
(void)KIO::NetAccess::upload(tempFile.name(), new_url, 0);
}
示例7: save
bool KSnapshot::save( const KURL& url )
{
if ( KIO::NetAccess::exists( url, false, this ) ) {
const QString title = i18n( "File Exists" );
const QString text = i18n( "<qt>Do you really want to overwrite <b>%1</b>?</qt>" ).arg(url.prettyURL());
if (KMessageBox::Continue != KMessageBox::warningContinueCancel( this, text, title, i18n("Overwrite") ) )
{
return false;
}
}
QString type( KImageIO::type(url.path()) );
if ( type.isNull() )
type = "PNG";
bool ok = false;
if ( url.isLocalFile() ) {
KSaveFile saveFile( url.path() );
if ( saveFile.status() == 0 ) {
if ( snapshot.save( saveFile.file(), type.latin1() ) )
ok = saveFile.close();
}
}
else {
KTempFile tmpFile;
tmpFile.setAutoDelete( true );
if ( tmpFile.status() == 0 ) {
if ( snapshot.save( tmpFile.file(), type.latin1() ) ) {
if ( tmpFile.close() )
ok = KIO::NetAccess::upload( tmpFile.name(), url, this );
}
}
}
QApplication::restoreOverrideCursor();
if ( !ok ) {
kdWarning() << "KSnapshot was unable to save the snapshot" << endl;
QString caption = i18n("Unable to save image");
QString text = i18n("KSnapshot was unable to save the image to\n%1.")
.arg(url.prettyURL());
KMessageBox::error(this, text, caption);
}
return ok;
}
示例8: save
bool KSnapshot::save( const KURL& url )
{
QString type( KImageIO::type(url.path()) );
if ( type.isNull() )
type = "PNG";
bool ok = false;
if ( url.isLocalFile() ) {
KSaveFile saveFile( url.path() );
if ( saveFile.status() == 0 ) {
if ( snapshot.save( saveFile.file(), type.latin1() ) )
ok = saveFile.close();
}
}
else {
KTempFile tmpFile;
tmpFile.setAutoDelete( true );
if ( tmpFile.status() == 0 ) {
if ( snapshot.save( tmpFile.file(), type.latin1() ) ) {
if ( tmpFile.close() )
ok = KIO::NetAccess::upload( tmpFile.name(), url, this );
}
}
}
QApplication::restoreOverrideCursor();
if ( !ok ) {
kdWarning() << "KSnapshot was unable to save the snapshot" << endl;
QString caption = i18n("Unable to Save Image");
QString text = i18n("KSnapshot was unable to save the image to\n%1.")
.arg(url.prettyURL());
KMessageBox::error(this, text, caption);
}
return ok;
}
示例9: type
bool Q3DGraph::save(const KURL& url)
{
if ( KIO::NetAccess::exists( url, false, this ) ) //The file already exist
return false;
QString type(KImageIO::type(url.path()));
if (type.isNull())
type = "PNG";
bool ok = false;
if(url.isLocalFile()) {
KSaveFile saveFile(url.path());
if ( saveFile.status() == 0 ) {
if (toPixmap().save( saveFile.file(), type.latin1() ) )
ok = saveFile.close();
}
} else {
KTempFile tmpFile;
tmpFile.setAutoDelete(true);
if(tmpFile.status()==0) {
if(toPixmap().save( tmpFile.file(), type.latin1())) {
if(tmpFile.close())
ok = KIO::NetAccess::upload( tmpFile.name(), url, this );
}
}
}
// QApplication::restoreOverrideCursor();
if (!ok) {
qDebug("Was unable to save it");
}
return ok;
}
示例10: archiveIncidences
void EventArchiver::archiveIncidences( Calendar* calendar, const QDate& /*limitDate*/, QWidget* widget, const Incidence::List& incidences, bool /*withGUI*/)
{
FileStorage storage( calendar );
// Save current calendar to disk
KTempFile tmpFile;
tmpFile.setAutoDelete(true);
storage.setFileName( tmpFile.name() );
if ( !storage.save() ) {
kdDebug(5850) << "EventArchiver::archiveEvents(): Can't save calendar to temp file" << endl;
return;
}
// Duplicate current calendar by loading in new calendar object
CalendarLocal archiveCalendar( KOPrefs::instance()->mTimeZoneId );
FileStorage archiveStore( &archiveCalendar );
archiveStore.setFileName( tmpFile.name() );
if (!archiveStore.load()) {
kdDebug(5850) << "EventArchiver::archiveEvents(): Can't load calendar from temp file" << endl;
return;
}
// Strip active events from calendar so that only events to be archived
// remain. This is not really efficient, but there is no other easy way.
QStringList uids;
Incidence::List allIncidences = archiveCalendar.rawIncidences();
Incidence::List::ConstIterator it;
for( it = incidences.begin(); it != incidences.end(); ++it ) {
uids << (*it)->uid();
}
for( it = allIncidences.begin(); it != allIncidences.end(); ++it ) {
if ( !uids.contains( (*it)->uid() ) ) {
archiveCalendar.deleteIncidence( *it );
}
}
// Get or create the archive file
KURL archiveURL( KOPrefs::instance()->mArchiveFile );
QString archiveFile;
if ( KIO::NetAccess::exists( archiveURL, true, widget ) ) {
if( !KIO::NetAccess::download( archiveURL, archiveFile, widget ) ) {
kdDebug(5850) << "EventArchiver::archiveEvents(): Can't download archive file" << endl;
return;
}
// Merge with events to be archived.
archiveStore.setFileName( archiveFile );
if ( !archiveStore.load() ) {
kdDebug(5850) << "EventArchiver::archiveEvents(): Can't merge with archive file" << endl;
return;
}
} else {
archiveFile = tmpFile.name();
}
// Save archive calendar
if ( !archiveStore.save() ) {
KMessageBox::error(widget,i18n("Cannot write archive file %1.").arg( archiveStore.fileName() ));
return;
}
// Upload if necessary
KURL srcUrl;
srcUrl.setPath(archiveFile);
if (srcUrl != archiveURL) {
if ( !KIO::NetAccess::upload( archiveFile, archiveURL, widget ) ) {
KMessageBox::error(widget,i18n("Cannot write archive to final destination."));
return;
}
}
KIO::NetAccess::removeTempFile(archiveFile);
// Delete archived events from calendar
for( it = incidences.begin(); it != incidences.end(); ++it ) {
calendar->deleteIncidence( *it );
}
emit eventsDeleted();
}
示例11: startOCRAD
void KSANEOCR::startOCRAD( )
{
ocradDialog *ocrDia = static_cast<ocradDialog*>(m_ocrProcessDia);
m_ocrResultImage = ocrDia->orfUrl();
const QString cmd = ocrDia->getOCRCmd();
// if( m_ocrResultImage.isEmpty() )
{
/* The url is empty. Start the program to fill up a temp file */
m_ocrResultImage = ImgSaver::tempSaveImage( m_img, "BMP", 8 ); // m_tmpFile->name();
kdDebug(28000) << "The new image name is <" << m_ocrResultImage << ">" << endl;
}
m_ocrImagePBM = ImgSaver::tempSaveImage( m_img, "PBM", 1 );
/* temporar file for orf result */
KTempFile *tmpOrf = new KTempFile( QString(), ".orf" );
tmpOrf->setAutoDelete( false );
tmpOrf->close();
m_tmpOrfName = QFile::encodeName(tmpOrf->name());
if( daemon )
{
delete( daemon );
daemon = 0;
}
daemon = new KProcess;
Q_CHECK_PTR(daemon);
*daemon << cmd;
*daemon << QString("-x");
*daemon << m_tmpOrfName; // the orf result file
*daemon << QFile::encodeName( m_ocrImagePBM ); // The name of the image
*daemon << QString("-l");
*daemon << QString::number( ocrDia->layoutDetectionMode());
KConfig *konf = KGlobal::config ();
KConfigGroupSaver( konf, CFG_GROUP_OCRAD );
QString format = konf->readEntry( CFG_OCRAD_FORMAT, "utf8");
*daemon << QString("-F");
*daemon << format;
QString charset = konf->readEntry( CFG_OCRAD_CHARSET, "iso-8859-15");
*daemon << QString("-c");
*daemon << charset;
QString addArgs = konf->readEntry( CFG_OCRAD_EXTRA_ARGUMENTS, QString() );
if( !addArgs.isEmpty() )
{
kdDebug(28000) << "Setting additional args from config for ocrad: " << addArgs << endl;
*daemon << addArgs;
}
m_ocrResultText = "";
connect(daemon, SIGNAL(processExited(KProcess *)),
this, SLOT( ocradExited(KProcess*)));
connect(daemon, SIGNAL(receivedStdout(KProcess *, char*, int)),
this, SLOT( ocradStdIn(KProcess*, char*, int)));
connect(daemon, SIGNAL(receivedStderr(KProcess *, char*, int)),
this, SLOT( ocradStdErr(KProcess*, char*, int)));
if (!daemon->start(KProcess::NotifyOnExit, KProcess::All))
{
kdDebug(28000) << "Error starting ocrad-daemon!" << endl;
}
else
{
kdDebug(28000) << "Start OK" << endl;
}
delete tmpOrf;
}
示例12: kimgio_eps_read
KDE_EXPORT void kimgio_eps_read(QImageIO *image)
{
kdDebug(399) << "kimgio EPS: starting..." << endl;
FILE *ghostfd;
int x1, y1, x2, y2;
// QTime dt;
// dt.start();
QString cmdBuf;
QString tmp;
QIODevice *io = image->ioDevice();
Q_UINT32 ps_offset, ps_size;
// find start of PostScript code
if(!seekToCodeStart(io, ps_offset, ps_size))
return;
// find bounding box
if(!bbox(io, &x1, &y1, &x2, &y2))
{
kdError(399) << "kimgio EPS: no bounding box found!" << endl;
return;
}
KTempFile tmpFile;
tmpFile.setAutoDelete(true);
if(tmpFile.status() != 0)
{
kdError(399) << "kimgio EPS: no temp file!" << endl;
return;
}
tmpFile.close(); // Close the file, we just want the filename
// x1, y1 -> translation
// x2, y2 -> new size
x2 -= x1;
y2 -= y1;
// kdDebug(399) << "origin point: " << x1 << "," << y1 << " size:" << x2 << "," << y2 << endl;
double xScale = 1.0;
double yScale = 1.0;
bool needsScaling = false;
int wantedWidth = x2;
int wantedHeight = y2;
if(image->parameters())
{
// Size forced by the caller
QStringList params = QStringList::split(':', image->parameters());
if(params.count() >= 2 && x2 != 0.0 && y2 != 0.0)
{
wantedWidth = params[0].toInt();
xScale = (double)wantedWidth / (double)x2;
wantedHeight = params[1].toInt();
yScale = (double)wantedHeight / (double)y2;
// kdDebug(399) << "wanted size:" << wantedWidth << "x" << wantedHeight << endl;
// kdDebug(399) << "scaling:" << xScale << "," << yScale << endl;
needsScaling = true;
}
}
// create GS command line
cmdBuf = "gs -sOutputFile=";
cmdBuf += tmpFile.name();
cmdBuf += " -q -g";
tmp.setNum(wantedWidth);
cmdBuf += tmp;
tmp.setNum(wantedHeight);
cmdBuf += "x";
cmdBuf += tmp;
cmdBuf +=
" -dSAFER -dPARANOIDSAFER -dNOPAUSE -sDEVICE=ppm -c "
"0 0 moveto "
"1000 0 lineto "
"1000 1000 lineto "
"0 1000 lineto "
"1 1 254 255 div setrgbcolor fill "
"0 0 0 setrgbcolor - -c showpage quit";
// run ghostview
ghostfd = popen(QFile::encodeName(cmdBuf), "w");
if(ghostfd == 0)
{
kdError(399) << "kimgio EPS: no GhostScript?" << endl;
return;
}
fprintf(ghostfd, "\n%d %d translate\n", -qRound(x1 * xScale), -qRound(y1 * yScale));
if(needsScaling)
fprintf(ghostfd, "%g %g scale\n", xScale, yScale);
// write image to gs
io->reset(); // Go back to start of file to give all the file to GhostScript
//.........这里部分代码省略.........
示例13: if
void
Crash::crashHandler( int /*signal*/ )
{
// we need to fork to be able to get a
// semi-decent bt - I dunno why
const pid_t pid = ::fork();
if( pid < 0 )
{
std::cout << "forking crash reporter failed\n";
// continuing now can't do no good
_exit( 1 );
}
else if ( pid == 0 )
{
// we are the child process (the result of the fork)
std::cout << "Pana is crashing...sorry this will be a minute...\n";
QString subject = APP_VERSION " ";
QString body = i18n(
"Pana has crashed.\n\n"
"Please help us fix it by clicking send on the crash report, "
"If you have time please add a brief description of what was happening just before the crash.\n\n"
"Thank you very much.\n\n" );
body += i18n( "\n\n\n\n\n\n"
"The information below is to help identify the problem.\n\n\n ");
body += "=== Debug information ===\n"
"Version: " APP_VERSION "\n"
"Engine: %1\n"
"Build date: " __DATE__ "\n"
"CC version: " __VERSION__ "\n"
"KDElibs: " KDE_VERSION_STRING "\n"
"Qt: %2\n"
"TagLib: %3.%4.%5\n"
"CPU count: %6\n";
QString cpucount = "unknown";
#ifdef __linux__
QString line;
uint cpuCount = 0;
QFile cpuinfo( "/proc/cpuinfo" );
if ( cpuinfo.open( IO_ReadOnly ) ) {
while ( cpuinfo.readLine( line, 20000 ) != -1 ) {
if ( line.startsWith( "processor" ) ) {
++cpuCount;
}
}
}
cpucount = QString::number( cpuCount );
#endif
body = body.arg( PanaConfig::soundSystem() )
.arg( qVersion() )
.arg( TAGLIB_MAJOR_VERSION )
.arg( TAGLIB_MINOR_VERSION )
.arg( TAGLIB_PATCH_VERSION )
.arg( cpucount );
#ifdef NDEBUG
body += "NDEBUG: true";
#endif
body += '\n';
/// obtain the backtrace with gdb
KTempFile temp;
temp.setAutoDelete( true );
const int handle = temp.handle();
// QCString gdb_command_string =
// "file panaapp\n"
// "attach " + QCString().setNum( ::getppid() ) + "\n"
// "bt\n" "echo \\n\n"
// "thread apply all bt\n";
const QCString gdb_batch =
"bt\n"
"echo \\n\\n\n"
"bt full\n"
"echo \\n\\n\n"
"echo ==== (gdb) thread apply all bt ====\\n\n"
"thread apply all bt\n";
::write( handle, gdb_batch, gdb_batch.length() );
::fsync( handle );
// so we can read stderr too
::dup2( fileno( stdout ), fileno( stderr ) );
QCString gdb;
gdb = "gdb --nw -n --batch -x ";
gdb += temp.name().latin1();
gdb += " panaapp ";
gdb += QCString().setNum( ::getppid() );
//.........这里部分代码省略.........
示例14: slotCreateSiteTemplate
void BaseTreeView::slotCreateSiteTemplate()
{
QString startDir;
if (Project::ref()->hasProject())
{
startDir = Project::ref()->templateURL().url();
} else
{
startDir = locateLocal("data", resourceDir + "templates/");
}
KURL targetURL;
bool valid;
do {
valid = false;
targetURL = KFileDialog::getSaveURL(startDir, "*.tgz", this, i18n("Create Site Template File"));
if (targetURL.isEmpty())
return;
if (targetURL.url().startsWith(KURL::fromPathOrURL(locateLocal("data", resourceDir + "templates/")).url()))
valid = true;
if (Project::ref()->hasProject() && targetURL.url().startsWith(Project::ref()->templateURL().url()))
valid = true;
if (!valid)
KMessageBox::error(this, i18n("Templates should be saved to the local or project template folder."));
}while (!valid);
KURL url = currentURL();
//TODO: Implement creation from remote folders as well. Requires downloading of the files to a
//temporary directory
if (url.protocol() != "file")
{
KMessageBox::sorry(this, i18n("Currently you can create site templates only from local folders."), i18n("Unsupported Feature"));
return;
}
KTempFile *tempFile = new KTempFile(tmpDir);
tempFile->setAutoDelete(true);
tempFile->close();
KTar tar(tempFile->name(), "application/x-gzip");
bool error = false;
if (tar.open(IO_WriteOnly))
{
KURL::List fileList = QExtFileInfo::allFiles(url, "*", this);
for (KURL::List::Iterator it = fileList.begin(); it != fileList.end(); ++it)
{
if (!(*it).path().endsWith("/"))
{
QFile f((*it).path());
if (f.open(IO_ReadOnly))
{
QByteArray buffer(f.readAll());
if (!tar.writeFile((*it).path().remove(url.path()), "user", "group", buffer.size(), buffer.data()))
{
error = true;
}
f.close();
} else
error = true;
}
}
tar.close();
} else
error = true;
if (!QuantaNetAccess::copy(KURL::fromPathOrURL(tempFile->name()), targetURL, m_parent, false))
error = true;
if (error)
KMessageBox::error(this, i18n("<qt>There was an error while creating the site template tarball.<br>Check that you can read the files from <i>%1</i>, you have write access to <i>%2</i> and that you have enough free space in your temporary folder.</qt>").arg(url.prettyURL(0, KURL::StripFileProtocol)).arg(targetURL.prettyURL(0, KURL::StripFileProtocol)), i18n("Template Creation Error"));
delete tempFile;
}
示例15: tryScaleWithGhostScript
// Helper method for scaleWithGhostScript. Returns 1 on success, 0 on error, -1 if nothing generated
// (in which case another 'output device' can be tried)
int KoPictureEps::tryScaleWithGhostScript(QImage &image, const QSize& size, const int resolutionx, const int resolutiony, const char* device )
// Based on the code of the file kdelibs/kimgio/eps.cpp
{
kdDebug(30003) << "Sampling with GhostScript, using device \"" << device << "\" (in KoPictureEps::tryScaleWithGhostScript)" << endl;
KTempFile tmpFile;
tmpFile.setAutoDelete(true);
if ( tmpFile.status() )
{
kdError(30003) << "No KTempFile! (in KoPictureEps::tryScaleWithGhostScript)" << endl;
return 0; // error
}
const int wantedWidth = size.width();
const int wantedHeight = size.height();
const double xScale = double(size.width()) / double(m_boundingBox.width());
const double yScale = double(size.height()) / double(m_boundingBox.height());
// create GS command line
QString cmdBuf ( "gs -sOutputFile=" );
cmdBuf += KProcess::quote(tmpFile.name());
cmdBuf += " -q -g";
cmdBuf += QString::number( wantedWidth );
cmdBuf += "x";
cmdBuf += QString::number( wantedHeight );
if ( ( resolutionx > 0) && ( resolutiony > 0) )
{
#if 0
// Do not play with resolution for now.
// It brings more problems at print than solutions
cmdBuf += " -r";
cmdBuf += QString::number( resolutionx );
cmdBuf += "x";
cmdBuf += QString::number( resolutiony );
#endif
}
cmdBuf += " -dSAFER -dPARANOIDSAFER -dNOPAUSE -sDEVICE=";
cmdBuf += device;
//cmdBuf += " -c 255 255 255 setrgbcolor fill 0 0 0 setrgbcolor";
cmdBuf += " -";
cmdBuf += " -c showpage quit";
// run ghostview
FILE* ghostfd = popen (QFile::encodeName(cmdBuf), "w");
if ( ghostfd == 0 )
{
kdError(30003) << "No connection to GhostScript (in KoPictureEps::tryScaleWithGhostScript)" << endl;
return 0; // error
}
// The translation is needed as GhostScript (7.07) cannot handle negative values in the bounding box otherwise.
fprintf (ghostfd, "\n%d %d translate\n", -qRound(m_boundingBox.left()*xScale), -qRound(m_boundingBox.top()*yScale));
fprintf (ghostfd, "%g %g scale\n", xScale, yScale);
// write image to gs
fwrite( m_rawData.data() + m_psStreamStart, sizeof(char), m_psStreamLength, ghostfd);
pclose ( ghostfd );
// load image
if( !image.load (tmpFile.name()) )
{
// It failed - maybe the device isn't supported by gs
return -1;
}
if ( image.size() != size ) // this can happen due to rounding problems
{
//kdDebug(30003) << "fixing size to " << size.width() << "x" << size.height()
// << " (was " << image.width() << "x" << image.height() << ")" << endl;
image = image.scale( size ); // hmm, smoothScale instead?
}
kdDebug(30003) << "Image parameters: " << image.width() << "x" << image.height() << "x" << image.depth() << endl;
return 1; // success
}