\section{KSave\-File Class Reference}
\label{classKSaveFile}\index{KSaveFile@{KSaveFile}}
The KSave\-File class has been made to write out changes to an existing file atomically.  


{\tt \#include $<$ksavefile.h$>$}

Collaboration diagram for KSave\-File:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=204pt]{classKSaveFile__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf KSave\-File} (const {\bf QString} \&filename, int mode=0666)
\item 
{\bf $\sim$KSave\-File} ()
\item 
int {\bf status} () const 
\item 
{\bf QString} {\bf name} () const 
\item 
int {\bf handle} () const 
\item 
FILE $\ast$ {\bf fstream} ()
\item 
{\bf QFile} $\ast$ {\bf file} ()
\item 
{\bf QText\-Stream} $\ast$ {\bf text\-Stream} ()
\item 
{\bf QData\-Stream} $\ast$ {\bf data\-Stream} ()
\item 
void {\bf abort} ()
\item 
bool {\bf close} ()
\end{CompactItemize}
\subsection*{Static Public Member Functions}
\begin{CompactItemize}
\item 
static bool {\bf backup\-File} (const {\bf QString} \&filename, const {\bf QString} \&backup\-Dir=QString::null, const {\bf QString} \&backup\-Extension={\bf QString::from\-Latin1}(\char`\"{}$\sim$\char`\"{}))
\end{CompactItemize}


\subsection{Detailed Description}
The KSave\-File 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.

b) Some error occurred, no changes have been written whatsoever and the old file is still in place. 



Definition at line 41 of file ksavefile.h.

\subsection{Constructor \& Destructor Documentation}
\index{KSaveFile@{KSave\-File}!KSaveFile@{KSaveFile}}
\index{KSaveFile@{KSaveFile}!KSaveFile@{KSave\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KSave\-File::KSave\-File (const {\bf QString} \& {\em filename}, int {\em mode} = {\tt 0666})}\label{classKSaveFile_a0}


Creates a new KSave\-File with the given file name. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em filename}]the path of the file \item[{\em mode}]the mode of the file (see chmod(1)) \end{description}
\end{Desc}


Definition at line 43 of file ksavefile.cpp.

References KTemp\-File::create(), KTemp\-File::handle(), KStandard\-Dirs::real\-File\-Path(), and KTemp\-File::set\-Error().\index{KSaveFile@{KSave\-File}!~KSaveFile@{$\sim$KSaveFile}}
\index{~KSaveFile@{$\sim$KSaveFile}!KSaveFile@{KSave\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KSave\-File::$\sim${\bf KSave\-File} ()}\label{classKSaveFile_a1}


The destructor closes the file. 

You might want to call {\bf close()}{\rm (p.\,\pageref{classKSaveFile_a10})} explicitely though, to test whether it worked. 

Definition at line 87 of file ksavefile.cpp.

References KTemp\-File::b\-Open, and close().

\subsection{Member Function Documentation}
\index{KSaveFile@{KSave\-File}!status@{status}}
\index{status@{status}!KSaveFile@{KSave\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int KSave\-File::status () const\hspace{0.3cm}{\tt  [inline]}}\label{classKSaveFile_a2}


Returns the status of the file based on errno. 

(see errno.h) 0 means OK.

You should check the status after object creation to check whether a file could be created in the first place.

You may check the status after closing the file to verify that the file has indeed been written correctly. \begin{Desc}
\item[Returns:]the errno status, 0 means ok \end{Desc}


Definition at line 68 of file ksavefile.h.

Referenced by KPalette::save(), and KConfig\-INIBack\-End::write\-Config\-File().\index{KSaveFile@{KSave\-File}!name@{name}}
\index{name@{name}!KSaveFile@{KSave\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QString} KSave\-File::name () const}\label{classKSaveFile_a3}


The name of the file as passed to the constructor. 

\begin{Desc}
\item[Returns:]The name of the file, or QString::null if opening the file has failed \end{Desc}


Definition at line 94 of file ksavefile.cpp.\index{KSaveFile@{KSave\-File}!handle@{handle}}
\index{handle@{handle}!KSaveFile@{KSave\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int KSave\-File::handle () const\hspace{0.3cm}{\tt  [inline]}}\label{classKSaveFile_a4}


An integer file descriptor open for writing to the file. 

\begin{Desc}
\item[Returns:]The file descriptor, or a negative number if opening the temporary file failed \end{Desc}


Definition at line 83 of file ksavefile.h.

Referenced by KConfig\-INIBack\-End::write\-Config\-File().\index{KSaveFile@{KSave\-File}!fstream@{fstream}}
\index{fstream@{fstream}!KSaveFile@{KSave\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}FILE$\ast$ KSave\-File::fstream ()\hspace{0.3cm}{\tt  [inline]}}\label{classKSaveFile_a5}


A FILE$\ast$ stream open for writing to the file. 

\begin{Desc}
\item[Returns:]FILE$\ast$ stream open for writing to the file, or 0 if opening the temporary file failed \end{Desc}


Definition at line 91 of file ksavefile.h.

Referenced by KConfig\-INIBack\-End::write\-Config\-File().\index{KSaveFile@{KSave\-File}!file@{file}}
\index{file@{file}!KSaveFile@{KSave\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QFile}$\ast$ KSave\-File::file ()\hspace{0.3cm}{\tt  [inline]}}\label{classKSaveFile_a6}


A QFile$\ast$ open for writing to the file. 

\begin{Desc}
\item[Returns:]A {\bf QFile} open for writing to the file, or 0 if opening the temporary file failed. \end{Desc}


Definition at line 99 of file ksavefile.h.\index{KSaveFile@{KSave\-File}!textStream@{textStream}}
\index{textStream@{textStream}!KSaveFile@{KSave\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QText\-Stream}$\ast$ KSave\-File::text\-Stream ()\hspace{0.3cm}{\tt  [inline]}}\label{classKSaveFile_a7}


A QText\-Stream$\ast$ open for writing to the file. 

\begin{Desc}
\item[Returns:]A {\bf QText\-Stream} that is open for writing to the file, or 0 if opening the temporary file failed \end{Desc}


Definition at line 107 of file ksavefile.h.

Referenced by KPalette::save().\index{KSaveFile@{KSave\-File}!dataStream@{dataStream}}
\index{dataStream@{dataStream}!KSaveFile@{KSave\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QData\-Stream}$\ast$ KSave\-File::data\-Stream ()\hspace{0.3cm}{\tt  [inline]}}\label{classKSaveFile_a8}


A QData\-Stream$\ast$ open for writing to the file. 

\begin{Desc}
\item[Returns:]A {\bf QData\-Stream} that is open for writing to the file, or 0 if opening the file failed \end{Desc}


Definition at line 115 of file ksavefile.h.\index{KSaveFile@{KSave\-File}!abort@{abort}}
\index{abort@{abort}!KSaveFile@{KSave\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KSave\-File::abort ()}\label{classKSaveFile_a9}


Aborts the write operation and removes any intermediate files This implies a close. 



Definition at line 100 of file ksavefile.cpp.

References KTemp\-File::close(), and KTemp\-File::unlink().

Referenced by close(), and KConfig\-INIBack\-End::write\-Config\-File().\index{KSaveFile@{KSave\-File}!close@{close}}
\index{close@{close}!KSaveFile@{KSave\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KSave\-File::close ()}\label{classKSaveFile_a10}


Closes the file and makes the changes definitive. 

Returns 'true' is successful, or 'false' if an error has occurred. See {\bf status()}{\rm (p.\,\pageref{classKSaveFile_a2})} for details about errors. \begin{Desc}
\item[Returns:]true if successful, or false if an error has occurred. \end{Desc}


Definition at line 107 of file ksavefile.cpp.

References abort(), KTemp\-File::close(), QFile::encode\-Name(), KTemp\-File::handle(), QString::is\-Empty(), KTemp\-File::name(), KTemp\-File::set\-Error(), KTemp\-File::sync(), and KTemp\-File::unlink().

Referenced by KPalette::save(), KConfig\-INIBack\-End::write\-Config\-File(), and $\sim$KSave\-File().\index{KSaveFile@{KSave\-File}!backupFile@{backupFile}}
\index{backupFile@{backupFile}!KSaveFile@{KSave\-File}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KSave\-File::backup\-File (const {\bf QString} \& {\em filename}, const {\bf QString} \& {\em backup\-Dir} = {\tt QString::null}, const {\bf QString} \& {\em backup\-Extension} = {\tt {\bf QString::from\-Latin1}(\char`\"{}$\sim$\char`\"{})})\hspace{0.3cm}{\tt  [static]}}\label{classKSaveFile_e0}


Static method to create a backup file before saving. 

You can use this method even if you don't use KSave\-File. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em filename}]the file to backup \item[{\em backup\-Dir}]optional directory where to save the backup file in. If empty (the default), the backup will be in the same directory as {\tt filename}. \item[{\em backup\-Extension}]the extension to append to {\tt filename}, \char`\"{}$\sim$\char`\"{} by default. \end{description}
\end{Desc}
\begin{Desc}
\item[Since:]3.2 \end{Desc}


Definition at line 145 of file ksavefile.cpp.

References QFile::encode\-Name(), QCString::find\-Rev(), and QCString::mid().

The documentation for this class was generated from the following files:\begin{CompactItemize}
\item 
ksavefile.h\item 
ksavefile.cpp\end{CompactItemize}
