You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.8 KiB
76 lines
1.8 KiB
/*
|
|
* 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 <tqdir.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 TQString & 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 TQDir::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 TQString & newPath );
|
|
|
|
/**
|
|
* Obtain the current working directory's absolute path.
|
|
* This is useful for resolving/simplifying relative paths.
|
|
**/
|
|
TQString currentDirPath() const;
|
|
|
|
/**
|
|
* (Prematurely) restore the working directory. Unnecessary when this
|
|
* object will be destroyed anyway since the destructor does exactly that.
|
|
**/
|
|
void restore();
|
|
|
|
protected:
|
|
TQDir oldWorkingDir;
|
|
};
|
|
|
|
#endif // KDirSaver_h
|
|
|
|
|
|
// EOF
|