\section{KTemp\-Dir Class Reference}
\label{classKTempDir}\index{KTempDir@{KTempDir}}
The KTemp\-Dir class creates a unique directory for temporary use.  


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

Collaboration diagram for KTemp\-Dir:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=60pt]{classKTempDir__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf KTemp\-Dir} ({\bf QString} directory\-Prefix=QString::null, int mode=0700)
\item 
{\bf $\sim$KTemp\-Dir} ()
\item 
void {\bf set\-Auto\-Delete} (bool auto\-Delete)
\item 
int {\bf status} () const 
\item 
{\bf QString} {\bf name} () const 
\item 
{\bf QDir} $\ast$ {\bf q\-Dir} ()
\item 
void {\bf unlink} ()
\item 
bool {\bf existing} () const 
\end{CompactItemize}
\subsection*{Protected Member Functions}
\begin{CompactItemize}
\item 
bool {\bf create} (const {\bf QString} \&directory\-Prefix, int mode)
\item 
void {\bf set\-Error} (int error)
\end{CompactItemize}


\subsection{Detailed Description}
The KTemp\-Dir class creates a unique directory for temporary use. 

This is especially useful if you need to create a directory in a world writable directory like /tmp without being vulnerable to so called symlink attacks.

{\bf KDE}{\rm (p.\,\pageref{namespaceKDE})} applications, however, shouldn't create files or directories in /tmp in the first place but use the \char`\"{}tmp\char`\"{} resource instead. The standard KTemp\-Dir constructor will do that by default.

To create a temporary directory that starts with a certain name in the \char`\"{}tmp\char`\"{} resource, one should use: KTemp\-Dir(locate\-Local(\char`\"{}tmp\char`\"{}, prefix));

{\bf KTemp\-File}{\rm (p.\,\pageref{classKTempFile})} does not create any missing directories, but locate\-Local() does.

See also {\bf KStandard\-Dirs}{\rm (p.\,\pageref{classKStandardDirs})}

\begin{Desc}
\item[Since:]3.2 \end{Desc}
\begin{Desc}
\item[Author:]Joseph Wenninger $<${\tt jowenn@kde.org}$>$ \end{Desc}




Definition at line 53 of file ktempdir.h.

\subsection{Constructor \& Destructor Documentation}
\index{KTempDir@{KTemp\-Dir}!KTempDir@{KTempDir}}
\index{KTempDir@{KTempDir}!KTempDir@{KTemp\-Dir}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KTemp\-Dir::KTemp\-Dir ({\bf QString} {\em directory\-Prefix} = {\tt QString::null}, int {\em mode} = {\tt 0700})}\label{classKTempDir_a0}


Creates a temporary directory with the name: {\tt $<$directory\-Prefix$>$$<$six} letters$>$. 

The default {\tt directory\-Prefix} is \char`\"{}\$KDEHOME/tmp-\$HOST/appname\char`\"{} \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em directory\-Prefix}]the prefix of the file name, or QString::null for the default value \item[{\em mode}]the file permissions, almost always in octal. The first digit selects permissions for the user who owns the file: read (4), write (2), and execute (1); the second selects permissions for other users in the file's group, with the same values; and the fourth for other users not in the file's group, with the same values. \end{description}
\end{Desc}


Definition at line 57 of file ktempdir.cpp.

References create(), and QString::is\-Empty().\index{KTempDir@{KTemp\-Dir}!~KTempDir@{$\sim$KTempDir}}
\index{~KTempDir@{$\sim$KTempDir}!KTempDir@{KTemp\-Dir}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KTemp\-Dir::$\sim${\bf KTemp\-Dir} ()}\label{classKTempDir_a1}


The destructor deletes the directory and it's contents if auto\-Delete is enabled. 



Definition at line 104 of file ktempdir.cpp.

References unlink().

\subsection{Member Function Documentation}
\index{KTempDir@{KTemp\-Dir}!setAutoDelete@{setAutoDelete}}
\index{setAutoDelete@{setAutoDelete}!KTempDir@{KTemp\-Dir}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KTemp\-Dir::set\-Auto\-Delete (bool {\em auto\-Delete})\hspace{0.3cm}{\tt  [inline]}}\label{classKTempDir_a2}


Turn automatic deletion on or off. 

Automatic deletion is off by default. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em auto\-Delete}]true to turn automatic deletion on \end{description}
\end{Desc}


Definition at line 85 of file ktempdir.h.\index{KTempDir@{KTemp\-Dir}!status@{status}}
\index{status@{status}!KTempDir@{KTemp\-Dir}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int KTemp\-Dir::status () const}\label{classKTempDir_a3}


Returns the status of the directory creation based on errno. 

(see errno.h) 0 means OK.

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

\begin{Desc}
\item[Returns:]the errno status, 0 means ok \end{Desc}


Definition at line 111 of file ktempdir.cpp.\index{KTempDir@{KTemp\-Dir}!name@{name}}
\index{name@{name}!KTempDir@{KTemp\-Dir}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QString} KTemp\-Dir::name () const}\label{classKTempDir_a4}


Returns the full path and name of the directory, including a trailing '/'. 

\begin{Desc}
\item[Returns:]The name of the directory, or QString::null if creating the directory has failed or the directory has been unlinked \end{Desc}


Definition at line 117 of file ktempdir.cpp.\index{KTempDir@{KTemp\-Dir}!qDir@{qDir}}
\index{qDir@{qDir}!KTempDir@{KTemp\-Dir}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QDir} $\ast$ KTemp\-Dir::q\-Dir ()}\label{classKTempDir_a5}


Returns the QDir$\ast$ of the temporary directory. 

\begin{Desc}
\item[Returns:]{\bf QDir} directory information of the directory or 0 if their is no managed directory The caller has to free the pointer open for writing to the \end{Desc}


Definition at line 129 of file ktempdir.cpp.\index{KTempDir@{KTemp\-Dir}!unlink@{unlink}}
\index{unlink@{unlink}!KTempDir@{KTemp\-Dir}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KTemp\-Dir::unlink ()}\label{classKTempDir_a6}


Deletes the directory recursively. 



Definition at line 136 of file ktempdir.cpp.

References QFile::encode\-Name(), and KProcess::quote().

Referenced by $\sim$KTemp\-Dir().\index{KTempDir@{KTemp\-Dir}!existing@{existing}}
\index{existing@{existing}!KTempDir@{KTemp\-Dir}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KTemp\-Dir::existing () const}\label{classKTempDir_a7}


\begin{Desc}
\item[Returns:]true if a temporary directory has successfully been created and not been unlinked yet \end{Desc}


Definition at line 123 of file ktempdir.cpp.\index{KTempDir@{KTemp\-Dir}!create@{create}}
\index{create@{create}!KTempDir@{KTemp\-Dir}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KTemp\-Dir::create (const {\bf QString} \& {\em directory\-Prefix}, int {\em mode})\hspace{0.3cm}{\tt  [protected]}}\label{classKTempDir_b0}


Creates a \char`\"{}random\char`\"{} directory with specified mode. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em directory\-Prefix}]to use when creating temp directory (the rest is generated randomly) \item[{\em mode}]directory permissions \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]bool true upon sucess \end{Desc}


Definition at line 70 of file ktempdir.cpp.

References QFile::decode\-Name(), QFile::encode\-Name(), endl(), and KApplication::random().

Referenced by KTemp\-Dir().\index{KTempDir@{KTemp\-Dir}!setError@{setError}}
\index{setError@{setError}!KTempDir@{KTemp\-Dir}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KTemp\-Dir::set\-Error (int {\em error})\hspace{0.3cm}{\tt  [inline, protected]}}\label{classKTempDir_b1}


Sets the errno value. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em error}]the value to set the status to. \end{description}
\end{Desc}


Definition at line 138 of file ktempdir.h.

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