\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=237pt]{classKSaveFile__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf KSave\-File} (const  {\bf QString} \&filename, int mode=0666)
\begin{CompactList}\small\item\em Creates a new KSave\-File with the given file name. \item\end{CompactList}\item 
{\bf $\sim$KSave\-File} ()
\begin{CompactList}\small\item\em The destructor closes the file. \item\end{CompactList}\item 
int {\bf status} () const 
\begin{CompactList}\small\item\em Returns the status of the file based on errno. \item\end{CompactList}\item 
{\bf QString} {\bf name} () const 
\begin{CompactList}\small\item\em The name of the file as passed to the constructor. \item\end{CompactList}\item 
int {\bf handle} () const 
\begin{CompactList}\small\item\em An integer file descriptor open for writing to the file. \item\end{CompactList}\item 
FILE $\ast$ {\bf fstream} ()
\begin{CompactList}\small\item\em A FILE$\ast$ stream open for writing to the file. \item\end{CompactList}\item 
{\bf QFile} $\ast$ {\bf file} ()
\begin{CompactList}\small\item\em A QFile$\ast$ open for writing to the file. \item\end{CompactList}\item 
{\bf QText\-Stream} $\ast$ {\bf text\-Stream} ()
\begin{CompactList}\small\item\em A QText\-Stream$\ast$ open for writing to the file. \item\end{CompactList}\item 
{\bf QData\-Stream} $\ast$ {\bf data\-Stream} ()
\begin{CompactList}\small\item\em A QData\-Stream$\ast$ open for writing to the file. \item\end{CompactList}\item 
void {\bf abort} ()
\begin{CompactList}\small\item\em Aborts the write operation and removes any intermediate files This implies a close. \item\end{CompactList}\item 
bool {\bf close} ()
\begin{CompactList}\small\item\em Closes the file and makes the changes definitive. \item\end{CompactList}\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 occured, 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} = 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 41 of file ksavefile.cpp.

References KTemp\-File::create(), QString::from\-Latin1(), 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. 



Definition at line 60 of file ksavefile.cpp.

References 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 67 of file ksavefile.h.

References KTemp\-File::status().

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 66 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 82 of file ksavefile.h.

References KTemp\-File::handle().

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 90 of file ksavefile.h.

References KTemp\-File::fstream().

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 98 of file ksavefile.h.

References KTemp\-File::file().\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 106 of file ksavefile.h.

References KTemp\-File::text\-Stream().

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 114 of file ksavefile.h.

References KTemp\-File::data\-Stream().\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 72 of file ksavefile.cpp.

References KTemp\-File::close(), and KTemp\-File::unlink().\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 occured. 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 occured. \end{Desc}


Definition at line 79 of file ksavefile.cpp.

References KTemp\-File::close(), QString::is\-Empty(), KTemp\-File::name(), QDir::rename(), KTemp\-File::set\-Error(), and KTemp\-File::unlink().

Referenced by KPalette::save(), KConfig\-INIBack\-End::write\-Config\-File(), and $\sim$KSave\-File().

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