Commit c8fce9d8 authored by Jaison Lee's avatar Jaison Lee

KTempFile->KTemporaryFile


svn path=/trunk/KDE/kdeedu/kmplot/; revision=591220
parent ed5358a1
......@@ -33,7 +33,7 @@
#include <kio/netaccess.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <ktempfile.h>
#include <ktemporaryfile.h>
// ANSI-C includes
#include <stdlib.h>
......@@ -126,32 +126,27 @@ bool KmPlotIO::save( const KUrl &url )
{
QDomDocument doc = currentState();
QFile xmlfile;
if (!url.isLocalFile() )
{
KTempFile tmpfile;
xmlfile.setFileName( KUrl( tmpfile.name() ).path() );
if (!xmlfile.open( QIODevice::WriteOnly ) )
KTemporaryFile tmpfile;
if ( !tmpfile.open() )
{
tmpfile.unlink();
kWarning() << k_funcinfo << "Could not open " << KUrl( tmpfile.name() ).path() << " for writing.\n";
kWarning() << k_funcinfo << "Could not open " << KUrl( tmpfile.fileName() ).path() << " for writing.\n";
return false;
}
QTextStream ts( &xmlfile );
QTextStream ts( &tmpfile );
doc.save( ts, 4 );
xmlfile.close();
ts.flush();
if ( !KIO::NetAccess::upload(tmpfile.name(), url,0))
if ( !KIO::NetAccess::upload(tmpfile.fileName(), url,0))
{
tmpfile.unlink();
kWarning() << k_funcinfo << "Could not open " << url.prettyUrl() << " for writing ("<<KIO::NetAccess::lastErrorString()<<").\n";
return false;
}
tmpfile.unlink();
}
else
{
xmlfile.setFileName(url.path() );
QFile xmlfile (url.path());
if (!xmlfile.open( QIODevice::WriteOnly ) )
{
kWarning() << k_funcinfo << "Could not open " << url.path() << " for writing.\n";
......
......@@ -32,7 +32,7 @@
#include <klocale.h>
#include <kmessagebox.h>
#include <kpushbutton.h>
#include <ktempfile.h>
#include <ktemporaryfile.h>
#include <kurl.h>
#include <qfile.h>
#include <qtextstream.h>
......@@ -230,54 +230,50 @@ void KParameterEditor::cmdExport_clicked()
if( !KIO::NetAccess::exists( url,false,this ) || KMessageBox::warningContinueCancel( this, i18n( "A file named \"%1\" already exists. Are you sure you want to continue and overwrite this file?", url.url()), i18n( "Overwrite File?" ), KGuiItem( i18n( "&Overwrite" ) ) ) == KMessageBox::Continue )
{
QString tmpfile;
QFile file;
if ( !url.isLocalFile() )
{
KTempFile tmpfile;
file.setFileName(tmpfile.name() );
KTemporaryFile tmpfile;
if (file.open( QIODevice::WriteOnly ) )
{
QTextStream stream(&file);
for ( int i = 0; i < m_mainWidget->list->count(); i++ )
{
QListWidgetItem * it = m_mainWidget->list->item( i );
stream << it->text();
if ( i < m_mainWidget->list->count()-1 )
stream << endl; //only write a new line if there are more text
}
file.close();
}
else
KMessageBox::sorry(0,i18n("An error appeared when saving this file"));
if (tmpfile.open() )
{
QTextStream stream(&tmpfile);
for ( int i = 0; i < m_mainWidget->list->count(); i++ )
{
QListWidgetItem * it = m_mainWidget->list->item( i );
stream << it->text();
if ( i < m_mainWidget->list->count()-1 )
stream << endl; //only write a new line if there are more text
}
stream.flush();
}
else
KMessageBox::sorry(0,i18n("An error appeared when saving this file"));
if ( !KIO::NetAccess::upload(tmpfile.name(),url, this) )
if ( !KIO::NetAccess::upload(tmpfile.fileName(),url, this) )
{
KMessageBox::sorry(0,i18n("An error appeared when saving this file"));
tmpfile.unlink();
KMessageBox::sorry(0,i18n("An error appeared when saving this file"));
return;
}
tmpfile.unlink();
}
else
{
kDebug() << "url.path()="<<url.path()<<endl;
file.setFileName(url.path());
if (file.open( QIODevice::WriteOnly ) )
{
QTextStream stream(&file);
for ( int i = 0; i < m_mainWidget->list->count(); i++ )
{
QListWidgetItem * it = m_mainWidget->list->item( i );
stream << it->text();
if ( i < m_mainWidget->list->count()-1 )
stream << endl; //only write a new line if there are more text
}
file.close();
QFile file;
kDebug() << "url.path()="<<url.path()<<endl;
file.setFileName(url.path());
if (file.open( QIODevice::WriteOnly ) )
{
QTextStream stream(&file);
for ( int i = 0; i < m_mainWidget->list->count(); i++ )
{
QListWidgetItem * it = m_mainWidget->list->item( i );
stream << it->text();
if ( i < m_mainWidget->list->count()-1 )
stream << endl; //only write a new line if there are more text
}
file.close();
}
else
KMessageBox::sorry(0,i18n("An error appeared when saving this file"));
KMessageBox::sorry(0,i18n("An error appeared when saving this file"));
}
}
......
......@@ -46,7 +46,7 @@
#include <kmessagebox.h>
#include <kstandarddirs.h>
#include <kstdaction.h>
#include <ktempfile.h>
#include <ktemporaryfile.h>
#include <ktoolbar.h>
#include <ktoolinvocation.h>
#include <krecentfilesaction.h>
......@@ -547,10 +547,10 @@ void MainDlg::slotExport()
saveOk = img.save( url.path(), "SVG" );
else
{
KTempFile tmp;
img.save( tmp.name(), "SVG" );
saveOk = KIO::NetAccess::upload(tmp.name(), url, 0);
tmp.unlink();
KTemporaryFile tmp;
tmp.open();
img.save( tmp.fileName(), "SVG" );
saveOk = KIO::NetAccess::upload(tmp.fileName(), url, 0);
}
}
else
......@@ -566,10 +566,10 @@ void MainDlg::slotExport()
saveOk = img.save( url.path(), types.at(0).toLatin1() );
else
{
KTempFile tmp;
img.save( tmp.name(), types.at(0).toLatin1() );
saveOk = KIO::NetAccess::upload(tmp.name(), url, 0);
tmp.unlink();
KTemporaryFile tmp;
tmp.open();
img.save( tmp.fileName(), types.at(0).toLatin1() );
saveOk = KIO::NetAccess::upload(tmp.fileName(), url, 0);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment