本文整理汇总了C++中KTempFile::name方法的典型用法代码示例。如果您正苦于以下问题:C++ KTempFile::name方法的具体用法?C++ KTempFile::name怎么用?C++ KTempFile::name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KTempFile
的用法示例。
在下文中一共展示了KTempFile::name方法的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: 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()));
}
}
示例3: file
void RulesDialog::slotUser2()
{
KURL kurl = KFileDialog::getSaveURL(0, i18n("*.sh|Shell Scripts (*.sh)"), this);
if (kurl.path() == "")
return;
KTempFile temp;
QString fileName = kurl.path();
if (fileName == "")
return;
if (!kurl.isLocalFile())
{
fileName = temp.name();
}
QFile file(fileName);
file.open(IO_WriteOnly);
QTextStream stream(&file);
stream << mRules->text();
file.close();
if (!kurl.isLocalFile())
{
if (!KIO::NetAccess::upload(fileName, kurl, this))
KMessageBox::error(this, i18n("Failed to upload file."));
}
temp.unlink();
}
示例4: 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;
}
}
示例5: 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;
}
}
示例6: infoMessage
void K3bIsoImager::writePathSpecForFile( K3bFileItem* item, QTextStream& stream )
{
stream << escapeGraftPoint( item->writtenPath() )
<< "=";
if( m_doc->bootImages().containsRef( dynamic_cast<K3bBootItem*>(item) ) ) { // boot-image-backup-hack
// create temp file
KTempFile temp;
QString tempPath = temp.name();
temp.unlink();
if( !KIO::NetAccess::copy( KURL(item->localPath()), KURL::fromPathOrURL(tempPath) ) ) {
emit infoMessage( i18n("Failed to backup boot image file %1").arg(item->localPath()), ERROR );
return;
}
static_cast<K3bBootItem*>(item)->setTempPath( tempPath );
m_tempFiles.append(tempPath);
stream << escapeGraftPoint( tempPath ) << "\n";
}
else if( item->isSymLink() && d->usedLinkHandling == Private::FOLLOW )
stream << escapeGraftPoint( K3b::resolveLink( item->localPath() ) ) << "\n";
else
stream << escapeGraftPoint( item->localPath() ) << "\n";
}
示例7: loadFile
/******************************************************************************
* Load the calendar file.
*/
bool ADCalendar::loadFile(bool reset)
{
if(reset)
clearEventsHandled();
if(!mTempFileName.isNull())
{
// Don't try to load the file if already downloading it
kdError(5900) << "ADCalendar::loadFile(): already downloading another file\n";
return false;
}
mLoaded = false;
KURL url(mUrlString);
if(url.isLocalFile())
{
// It's a local file
loadLocalFile(url.path());
emit loaded(this, mLoaded);
}
else
{
// It's a remote file. Download to a temporary file before loading it
KTempFile tempFile;
mTempFileName = tempFile.name();
KURL dest;
dest.setPath(mTempFileName);
KIO::FileCopyJob *job = KIO::file_copy(url, dest, -1, true);
connect(job, SIGNAL(result(KIO::Job *)), SLOT(slotDownloadJobResult(KIO::Job *)));
}
return true;
}
示例8: 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.")));
}
示例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: slotFileSave
void KgpgApp::slotFileSave()
{
TQString filn=Docname.path();
if (filn.isEmpty()) {
slotFileSaveAs();
return;
}
TQTextCodec*cod=TQTextCodec::codecForName (textEncoding.ascii());
// slotStatusMsg(i18n("Saving file..."));
if (!checkEncoding(cod)) {
KMessageBox::sorry(this,i18n("The document could not been saved, as the selected encoding cannot encode every unicode character in it."));
return;
}
KTempFile tmpfile;
if (Docname.isLocalFile()) {
TQFile f(filn);
if ( !f.open( IO_WriteOnly ) ) {
KMessageBox::sorry(this,i18n("The document could not be saved, please check your permissions and disk space."));
return;
}
TQTextStream t( &f );
t.setCodec(cod);
//t.setEncoding( TQTextStream::Latin1 );
t << view->editor->text();//.utf8();
f.close();
}
else {
/*FIXME use following code:
TQFile f( fName );
00983 if ( !f.open( IO_ReadOnly ) )
00984 return;
00985 TQFileInfo info ( f );
00986 smModificationTime = new TQTime( info.lastModified().time() );
00987 TQTextStream t(&f);
00988 t.setEncoding( TQTextStream::Latin1 );
00989 TQString s = t.readLine();
00990 f.close();
*/
TQTextStream *stream = tmpfile.textStream();
stream->setCodec(cod);
*stream << view->editor->text();//.utf8();
tmpfile.close();
if(!TDEIO::NetAccess::upload(tmpfile.name(), Docname,this)) {
KMessageBox::sorry(this,i18n("The document could not be saved, please check your permissions and disk space."));
tmpfile.unlink();
return;
}
tmpfile.unlink();
}
fileSave->setEnabled(false);
setCaption(Docname.fileName(),false);
}
示例11: 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);
}
示例12: 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() ) );
}
示例13: processDiff
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 );
}
示例14: 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() );
}
示例15: createSlidesPictures
void KPrWebPresentation::createSlidesPictures( KProgress *progressBar )
{
if ( slideInfos.isEmpty() )
return;
QPixmap pix( 10, 10 );
QString filename;
int p;
for ( unsigned int i = 0; i < slideInfos.count(); i++ ) {
int pgNum = slideInfos[i].pageNumber;
view->getCanvas()->drawPageInPix( pix, pgNum, zoom, true /*force real variable value*/ );
filename = QString( "%1/pics/slide_%2.png" ).arg( path ).arg( i + 1 );
KTempFile tmp;
pix.save( tmp.name(), "PNG" );
KIO::NetAccess::file_move( tmp.name(), filename, -1, true /*overwrite*/);
p = progressBar->progress();
progressBar->setProgress( ++p );
kapp->processEvents();
}
}