diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-10 01:15:27 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-10 01:15:27 +0000 |
commit | b6e09a3a8ea5f1338d089a29eb6e08f00f03f1aa (patch) | |
tree | 7dee2cbb5c94d3371357f796d42e344e1305ce9c /kdirstat/kdirsaver.h | |
download | kdirstat-b6e09a3a8ea5f1338d089a29eb6e08f00f03f1aa.tar.gz kdirstat-b6e09a3a8ea5f1338d089a29eb6e08f00f03f1aa.zip |
Added abandoned KDE3 version of kdirstat
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kdirstat@1088039 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdirstat/kdirsaver.h')
-rw-r--r-- | kdirstat/kdirsaver.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/kdirstat/kdirsaver.h b/kdirstat/kdirsaver.h new file mode 100644 index 0000000..4fbe6e2 --- /dev/null +++ b/kdirstat/kdirsaver.h @@ -0,0 +1,75 @@ +/* + * File name: kdirsaver.h + * Summary: Utility object to save current working directory + * License: LGPL - See file COPYING.LIB for details. + * Author: Stefan Hundhammer <sh@suse.de> + * + * Updated: 2003-01-07 + */ + + +#ifndef KDirSaver_h +#define KDirSaver_h + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <kurl.h> +#include <qdir.h> + + +/** + * Helper class to change directories without losing the current context. + * Will change back to the old working directory when destroyed. + * + * @short Directory changer with automatic restore + **/ +class KDirSaver +{ +public: + /** + * Constructor. Will save the current working directory and change to the + * path supplied. The old working directory will be restored when this + * object is destroyed. + **/ + KDirSaver( const QString & newPath = "" ); + + /** + * Constructor from a KURL. Will issue error messages on stdout for + * non-local objects. + **/ + KDirSaver( const KURL & url ); + + /** + * Destructor. Restores the original working directory. + **/ + virtual ~KDirSaver(); + + /** + * Change directory. Unlike @ref QDir::cd(), this method really performs a + * system chdir() so subsequent system calls will have the directory + * specified as the new current working directory. + **/ + void cd( const QString & newPath ); + + /** + * Obtain the current working directory's absolute path. + * This is useful for resolving/simplifying relative paths. + **/ + QString currentDirPath() const; + + /** + * (Prematurely) restore the working directory. Unnecessary when this + * object will be destroyed anyway since the destructor does exactly that. + **/ + void restore(); + +protected: + QDir oldWorkingDir; +}; + +#endif // KDirSaver_h + + +// EOF |