From b6e09a3a8ea5f1338d089a29eb6e08f00f03f1aa Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 10 Feb 2010 01:15:27 +0000 Subject: 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 --- kdirstat/kdirsaver.h | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 kdirstat/kdirsaver.h (limited to 'kdirstat/kdirsaver.h') 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 + * + * Updated: 2003-01-07 + */ + + +#ifndef KDirSaver_h +#define KDirSaver_h + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + + +/** + * 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 -- cgit v1.2.3