.TH "KSaveFile" kde3 "11 Jun 2005" "Version Version 3.4.1" "kdecore Library" \" -*- nroff -*-
.ad l
.nh
.SH NAME
KSaveFile \- The KSaveFile class has been made to write out changes to an existing file atomically.  

.PP
.SH SYNOPSIS
.br
.PP
\fC#include <ksavefile.h>\fP
.PP
.SS "Public Member Functions"

.in +1c
.ti -1c
.RI "\fBKSaveFile\fP (const \fBQString\fP &filename, int mode=0666)"
.br
.ti -1c
.RI "\fB~KSaveFile\fP ()"
.br
.ti -1c
.RI "int \fBstatus\fP () const "
.br
.ti -1c
.RI "\fBQString\fP \fBname\fP () const "
.br
.ti -1c
.RI "int \fBhandle\fP () const "
.br
.ti -1c
.RI "FILE * \fBfstream\fP ()"
.br
.ti -1c
.RI "\fBQFile\fP * \fBfile\fP ()"
.br
.ti -1c
.RI "\fBQTextStream\fP * \fBtextStream\fP ()"
.br
.ti -1c
.RI "\fBQDataStream\fP * \fBdataStream\fP ()"
.br
.ti -1c
.RI "void \fBabort\fP ()"
.br
.ti -1c
.RI "bool \fBclose\fP ()"
.br
.in -1c
.SS "Static Public Member Functions"

.in +1c
.ti -1c
.RI "static bool \fBbackupFile\fP (const \fBQString\fP &filename, const \fBQString\fP &backupDir=QString::null, const \fBQString\fP &backupExtension=\fBQString::fromLatin1\fP('~'))"
.br
.in -1c
.SH "Detailed Description"
.PP 
The KSaveFile class has been made to write out changes to an existing file atomically. 

This means that EITHER: a) All changes have been written successfully to the file.
.PP
b) Some error occurred, no changes have been written whatsoever and the old file is still in place. 
.PP
Definition at line 41 of file ksavefile.h.
.SH "Constructor & Destructor Documentation"
.PP 
.SS "KSaveFile::KSaveFile (const \fBQString\fP & filename, int mode = \fC0666\fP)"
.PP
Creates a new KSaveFile with the given file name. 
.PP
\fBParameters:\fP
.RS 4
\fIfilename\fP the path of the file 
.br
\fImode\fP the mode of the file (see chmod(1)) 
.RE
.PP

.PP
Definition at line 43 of file ksavefile.cpp.
.PP
References KTempFile::create(), KTempFile::handle(), KStandardDirs::realFilePath(), and KTempFile::setError().
.SS "KSaveFile::~\fBKSaveFile\fP ()"
.PP
The destructor closes the file. 
.PP
You might want to call \fBclose()\fP explicitely though, to test whether it worked. 
.PP
Definition at line 87 of file ksavefile.cpp.
.PP
References KTempFile::bOpen, and close().
.SH "Member Function Documentation"
.PP 
.SS "int KSaveFile::status () const\fC [inline]\fP"
.PP
Returns the status of the file based on errno. 
.PP
(see errno.h) 0 means OK.
.PP
You should check the status after object creation to check whether a file could be created in the first place.
.PP
You may check the status after closing the file to verify that the file has indeed been written correctly. 
.PP
\fBReturns:\fP
.RS 4
the errno status, 0 means ok 
.RE
.PP

.PP
Definition at line 68 of file ksavefile.h.
.PP
Referenced by KPalette::save(), and KConfigINIBackEnd::writeConfigFile().
.SS "\fBQString\fP KSaveFile::name () const"
.PP
The name of the file as passed to the constructor. 
.PP
\fBReturns:\fP
.RS 4
The name of the file, or QString::null if opening the file has failed 
.RE
.PP

.PP
Definition at line 94 of file ksavefile.cpp.
.SS "int KSaveFile::handle () const\fC [inline]\fP"
.PP
An integer file descriptor open for writing to the file. 
.PP
\fBReturns:\fP
.RS 4
The file descriptor, or a negative number if opening the temporary file failed 
.RE
.PP

.PP
Definition at line 83 of file ksavefile.h.
.PP
Referenced by KConfigINIBackEnd::writeConfigFile().
.SS "FILE* KSaveFile::fstream ()\fC [inline]\fP"
.PP
A FILE* stream open for writing to the file. 
.PP
\fBReturns:\fP
.RS 4
FILE* stream open for writing to the file, or 0 if opening the temporary file failed 
.RE
.PP

.PP
Definition at line 91 of file ksavefile.h.
.PP
Referenced by KConfigINIBackEnd::writeConfigFile().
.SS "\fBQFile\fP* KSaveFile::file ()\fC [inline]\fP"
.PP
A QFile* open for writing to the file. 
.PP
\fBReturns:\fP
.RS 4
A \fBQFile\fP open for writing to the file, or 0 if opening the temporary file failed. 
.RE
.PP

.PP
Definition at line 99 of file ksavefile.h.
.SS "\fBQTextStream\fP* KSaveFile::textStream ()\fC [inline]\fP"
.PP
A QTextStream* open for writing to the file. 
.PP
\fBReturns:\fP
.RS 4
A \fBQTextStream\fP that is open for writing to the file, or 0 if opening the temporary file failed 
.RE
.PP

.PP
Definition at line 107 of file ksavefile.h.
.PP
Referenced by KPalette::save().
.SS "\fBQDataStream\fP* KSaveFile::dataStream ()\fC [inline]\fP"
.PP
A QDataStream* open for writing to the file. 
.PP
\fBReturns:\fP
.RS 4
A \fBQDataStream\fP that is open for writing to the file, or 0 if opening the file failed 
.RE
.PP

.PP
Definition at line 115 of file ksavefile.h.
.SS "void KSaveFile::abort ()"
.PP
Aborts the write operation and removes any intermediate files This implies a close. 
.PP
Definition at line 100 of file ksavefile.cpp.
.PP
References KTempFile::close(), and KTempFile::unlink().
.PP
Referenced by close(), and KConfigINIBackEnd::writeConfigFile().
.SS "bool KSaveFile::close ()"
.PP
Closes the file and makes the changes definitive. 
.PP
Returns 'true' is successful, or 'false' if an error has occurred. See \fBstatus()\fP for details about errors. 
.PP
\fBReturns:\fP
.RS 4
true if successful, or false if an error has occurred. 
.RE
.PP

.PP
Definition at line 107 of file ksavefile.cpp.
.PP
References abort(), KTempFile::close(), QFile::encodeName(), KTempFile::handle(), QString::isEmpty(), KTempFile::name(), KTempFile::setError(), KTempFile::sync(), and KTempFile::unlink().
.PP
Referenced by KPalette::save(), KConfigINIBackEnd::writeConfigFile(), and ~KSaveFile().
.SS "bool KSaveFile::backupFile (const \fBQString\fP & filename, const \fBQString\fP & backupDir = \fCQString::null\fP, const \fBQString\fP & backupExtension = \fC\fBQString::fromLatin1\fP('~')\fP)\fC [static]\fP"
.PP
Static method to create a backup file before saving. 
.PP
You can use this method even if you don't use KSaveFile. 
.PP
\fBParameters:\fP
.RS 4
\fIfilename\fP the file to backup 
.br
\fIbackupDir\fP optional directory where to save the backup file in. If empty (the default), the backup will be in the same directory as \fCfilename\fP. 
.br
\fIbackupExtension\fP the extension to append to \fCfilename\fP, '~' by default. 
.RE
.PP
\fBSince:\fP
.RS 4
3.2 
.RE
.PP

.PP
Definition at line 145 of file ksavefile.cpp.
.PP
References QFile::encodeName(), QCString::findRev(), and QCString::mid().

.SH "Author"
.PP 
Generated automatically by Doxygen for kdecore Library from the source code.
