void _k_copyResultToTempFile(KJob* job) { KIO::FileCopyJob* cJob = qobject_cast<KIO::FileCopyJob *>(job); if (cJob && !cJob->error() ) { // Same as KRun::foundMimeType but with a different URL (void)KRun::runUrl(cJob->destUrl(), mimeType, window); } }
// ### when user cancels download, we crash :( void MrmlPart::slotDownloadResult( KIO::Job *job ) { assert( job->inherits( "KIO::FileCopyJob" ) ); KIO::FileCopyJob *copyJob = static_cast<KIO::FileCopyJob*>( job ); if ( !copyJob->error() ) m_queryList.append( copyJob->destURL() ); m_downloadJobs.removeRef( copyJob ); if ( m_downloadJobs.isEmpty() ) // finally, we can start the query! { if ( m_queryList.isEmpty() ) // rather unlikely, but could happen ;) { kdWarning() << "Couldn't download the reference files. Will start a random search now" << endl; } contactServer( m_url ); } }
bool ExportManager::remoteSave(const QUrl &url, const QString &mimetype) { QTemporaryFile tmpFile; if (tmpFile.open()) { if(!writeImage(&tmpFile, mimetype.toLatin1())) { emit errorMessage(i18n("Cannot save screenshot. Error while writing temporary local file.")); return false; } KIO::FileCopyJob *uploadJob = KIO::file_copy(QUrl::fromLocalFile(tmpFile.fileName()), url); uploadJob->exec(); if (uploadJob->error() != KJob::NoError) { emit errorMessage(i18n("Unable to save image. Could not upload file to remote location.")); return false; } return true; } return false; }
bool SambaFile::slotApply() { if (readonly) { kdDebug(FILESHARE_DEBUG) << "SambaFile::slotApply: readonly=true" << endl; return false; } // If we have write access to the smb.conf // we simply save the values to it // if not we have to save the results in // a temporary file and copy it afterwards // over the smb.conf file with kdesu. if (QFileInfo(path).isWritable()) { saveTo(path); changed = false; return true; } // Create a temporary smb.conf file delete _tempFile; _tempFile = new KTempFile(); _tempFile->setAutoDelete(true); if (!saveTo(_tempFile->name())) { kdDebug(5009) << "SambaFile::slotApply: Could not save to temporary file" << endl; delete _tempFile; _tempFile = 0; return false; } QFileInfo fi(path); KURL url(path); if (KURL(path).isLocalFile()) { KProcess proc; kdDebug(5009) << "SambaFile::slotApply: is local file!" << endl; QString suCommand=QString("cp %1 %2; rm %3") .arg(_tempFile->name()) .arg(path) .arg(_tempFile->name()); proc << "kdesu" << "-d" << suCommand; if (! proc.start(KProcess::Block)) { kdDebug(5009) << "SambaFile::slotApply: saving to " << path << " failed!" << endl; //KMessageBox::sorry(0,i18n("Saving the results to %1 failed.").arg(path)); delete _tempFile; _tempFile = 0; return false; } else { changed = false; delete _tempFile; _tempFile = 0; kdDebug(5009) << "SambaFile::slotApply: changes successfully saved!" << endl; return true; } } else { kdDebug(5009) << "SambaFile::slotApply: is remote file!" << endl; _tempFile->setAutoDelete(true); KURL srcURL; srcURL.setPath( _tempFile->name() ); KIO::FileCopyJob * job = KIO::file_copy( srcURL, url, -1, true ); connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotSaveJobFinished ( KIO::Job * ) ) ); return (job->error()==0); } return true; }