本文整理汇总了C++中KTempFile类的典型用法代码示例。如果您正苦于以下问题:C++ KTempFile类的具体用法?C++ KTempFile怎么用?C++ KTempFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KTempFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slotSave
void KMoneyThingMainWidget::slotSave()
{
KTempFile temp;
QString fileName = mCurrentFile->kurl().path();
if (fileName == "")
{
slotSaveAs();
return;
}
if (!mCurrentFile->kurl().isLocalFile())
{
fileName = temp.name();
}
emit(setStatus(i18n("Saving file...")));
QByteArray dump = qCompress(mCurrentFile->dump());
QFile file(fileName);
file.open(IO_WriteOnly);
QDataStream stream(&file);
stream << (QString) "KMoneyThingFile" << dump;
file.close();
if (!mCurrentFile->kurl().isLocalFile())
{
emit(setStatus(i18n("Uploading file...")));
if (!KIO::NetAccess::upload(fileName, mCurrentFile->kurl(), this))
KMessageBox::error(this, i18n("Failed to upload file."));
}
temp.unlink();
emit(setStatus(i18n("Ready.")));
}
示例2: pattern
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()));
}
}
示例3: move
// The finaly step: write _data to tempfile and move it to neW_url
static KIO::CopyJob *pasteDataAsyncTo(const KURL &new_url, const QByteArray &_data)
{
KTempFile tempFile;
tempFile.dataStream()->writeRawBytes(_data.data(), _data.size());
tempFile.close();
KURL orig_url;
orig_url.setPath(tempFile.name());
return KIO::move(orig_url, new_url);
}
示例4: interface
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: QRegExp
void SVNHandler::processDiff( QString output )
{
output.remove( QRegExp( "\\[ .* \\]$" ));
output.remove( QRegExp( "^" + i18n("[ Starting command ]" ).replace("[","\\[").replace("]","\\]")));
KTempFile tmpFile;
*(tmpFile.textStream()) << output;
tmpFile.close();
QString error;
if ( KApplication::startServiceByName( "Kompare", tmpFile.name(), &error ) )
KMessageBox::error( 0, error );
}
示例6: 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() );
}
示例7: getNewFileName
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);
}
示例8: Arch
TarArch::TarArch( ArkWidget *_gui,
const QString & _filename, const QString & _openAsMimeType)
: Arch( _gui, _filename), m_tmpDir( 0 ), createTmpInProgress(false),
updateInProgress(false), deleteInProgress(false), fd(0),
m_pTmpProc( 0 ), m_pTmpProc2( 0 ), failed( false ),
m_dotslash( false ), m_listingThread( 0 )
{
m_filesToAdd = m_filesToRemove = QStringList();
m_archiver_program = m_unarchiver_program = ArkSettings::tarExe();
verifyCompressUtilityIsAvailable( m_archiver_program );
verifyUncompressUtilityIsAvailable( m_unarchiver_program );
m_fileMimeType = _openAsMimeType;
if ( m_fileMimeType.isNull() )
m_fileMimeType = KMimeType::findByPath( _filename )->name();
kdDebug(1601) << "TarArch::TarArch: mimetype is " << m_fileMimeType << endl;
if ( m_fileMimeType == "application/x-tbz2" )
{
// ark treats .tar.bz2 as x-tbz, instead of duplicating the mimetype
// let's just alias it to the one we already handle.
m_fileMimeType = "application/x-tbz";
}
if ( m_fileMimeType == "application/x-tar" )
{
compressed = false;
}
else
{
compressed = true;
m_tmpDir = new KTempDir( _gui->tmpDir()
+ QString::fromLatin1( "temp_tar" ) );
m_tmpDir->setAutoDelete( true );
m_tmpDir->qDir()->cd( m_tmpDir->name() );
// build the temp file name
KTempFile *pTempFile = new KTempFile( m_tmpDir->name(),
QString::fromLatin1(".tar") );
tmpfile = pTempFile->name();
delete pTempFile;
kdDebug(1601) << "Tmpfile will be " << tmpfile << "\n" << endl;
}
}
示例9: createMainPage
void KPrWebPresentation::createMainPage( KProgress *progressBar )
{
QTextCodec *codec = KGlobal::charsets()->codecForName( m_encoding );
KTempFile tmp;
QString dest = QString( "%1/index.html" ).arg( path );
QFile file( tmp.name() );
file.open( IO_WriteOnly );
QTextStream streamOut( &file );
streamOut.setCodec( codec );
writeStartOfHeader( streamOut, codec, i18n("Table of Contents"), QString() );
streamOut << "</head>\n";
streamOut << "<body bgcolor=\"" << backColor.name() << "\" text=\"" << textColor.name() << "\">\n";
streamOut << "<h1 align=\"center\"><font color=\"" << titleColor.name()
<< "\">" << title << "</font></h1>";
streamOut << "<p align=\"center\"><a href=\"html/slide_1.html\">";
streamOut << i18n("Click here to start the Slideshow");
streamOut << "</a></p>\n";
streamOut << "<p><b>" << i18n("Table of Contents") << "</b></p>\n";
// create list of slides (with proper link)
streamOut << "<ol>\n";
for ( unsigned int i = 0; i < slideInfos.count(); i++ )
streamOut << " <li><a href=\"html/slide_" << i+1 << ".html\">" << slideInfos[ i ].slideTitle << "</a></li>\n";
streamOut << "</ol>\n";
// footer: author name, e-mail
QString htmlAuthor = email.isEmpty() ? escapeHtmlText( codec, author ) :
QString("<a href=\"mailto:%1\">%2</a>").arg( escapeHtmlText( codec, email )).arg( escapeHtmlText( codec, author ));
streamOut << EscapeEncodingOnly ( codec, i18n( "Created on %1 by <i>%2</i> with <a href=\"http://www.koffice.org/kpresenter\">KPresenter</a>" )
.arg( KGlobal::locale()->formatDate ( QDate::currentDate() ) ).arg( htmlAuthor ) );
streamOut << "</body>\n</html>\n";
file.close();
KIO::NetAccess::file_move( tmp.name(), dest, -1, true /*overwrite*/);
progressBar->setProgress( progressBar->totalSteps() );
kapp->processEvents();
}
示例10: 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;
}
示例11: kdDebug
bool SambaFile::load()
{
if (path.isNull() || path.isEmpty())
return false;
kdDebug(FILESHARE_DEBUG) << "SambaFile::load: path=" << path << endl;
KURL url(path);
if (!url.isLocalFile()) {
KTempFile tempFile;
localPath = tempFile.name();
KURL destURL;
destURL.setPath( localPath );
KIO::FileCopyJob * job = KIO::file_copy( url, destURL, 0600, true, false, true );
// emit started( d->m_job );
connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotJobFinished ( KIO::Job * ) ) );
return true;
} else {
示例12: i18n
bool KMiniEdit::saveFile(KURL newurl)
{
if (newurl.isEmpty())
newurl = KFileDialog::getSaveURL();
if (newurl.isEmpty())
return false;
if (newurl.isMalformed())
{
QString text = i18n("<b>THe URL %1 is not correct!</b>");
KMessageBox::sorry(this, text.arg(newurl.prettyURL()));
return false;
}
if (newurl.isLocalFile())
{
QFile file(newurl.path());
file.open(IO_WriteOnly);
saveToLocalFile(&file);
}
else
{
KTempFile tempfile;
saveToLocalFile(tempfile.file());
if (!KIO::NetAccess::upload(tempfile.name(), newurl))
{
QString text = i18n("<b>Error uploading %1!</b>");
KMessageBox::sorry(this, text.arg(newurl.prettyURL()));
tempfile.unlink();
return false;
}
tempfile.unlink();
}
url = newurl;
addURLtoRecent();
resetEdited();
return true;
}
示例13: url
void ImageLabel::setValue(QString fn)
{
// use the first line
QStringList sList = QStringList::split( "\n", fn );
QString fileName = *sList.begin();
KURL url(fileName);
QRegExp rx("^[a-zA-Z]{1,5}:/",false);
bool protocol = (rx.search(fileName)!=-1)?true:false;
QPixmap pm;
if(protocol && url.isLocalFile() == false)
{
KTempFile tmpFile;
KIO::FileCopyJob* copy = KIO::file_copy(fileName, tmpFile.name(), 0600,
true, false, false);
connect(copy, SIGNAL(result(KIO::Job*)),
this, SLOT(slotCopyResult(KIO::Job*)));
return;
}
示例14: createThumbnail
void PreviewJob::getOrCreateThumbnail()
{
// We still need to load the orig file ! (This is getting tedious) :)
const KFileItem* item = d->currentItem.item;
const TQString localPath = item->localPath();
if ( !localPath.isEmpty() )
createThumbnail( localPath );
else
{
d->state = PreviewJobPrivate::STATE_GETORIG;
KTempFile localFile;
KURL localURL;
localURL.setPath( d->tempName = localFile.name() );
const KURL currentURL = item->url();
TDEIO::Job * job = TDEIO::file_copy( currentURL, localURL, -1, true,
false, false /* No GUI */ );
job->addMetaData("thumbnail","1");
addSubjob(job);
}
}
示例15: exportContacts
bool GMXXXPort::exportContacts( const KABC::AddresseeList &list, const QString& )
{
KURL url = KFileDialog::getSaveURL( ":xxport_gmx", GMX_FILESELECTION_STRING );
if ( url.isEmpty() )
return true;
if ( !url.isLocalFile() ) {
KTempFile tmpFile;
if ( tmpFile.status() != 0 ) {
QString txt = i18n( "<qt>Unable to open file <b>%1</b>.%2.</qt>" );
KMessageBox::error( parentWidget(), txt.arg( url.url() )
.arg( strerror( tmpFile.status() ) ) );
return false;
}
doExport( tmpFile.file(), list );
tmpFile.close();
return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
} else {
QString filename = url.path();
QFile file( filename );
if ( !file.open( IO_WriteOnly ) ) {
QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
KMessageBox::error( parentWidget(), txt.arg( filename ) );
return false;
}
doExport( &file, list );
file.close();
return true;
}
}