/*
 *   File name:	kdirsaver.cpp
 *   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
 */


#include <unistd.h>
#include <kdebug.h>
#include "kdirsaver.h"


KDirSaver::KDirSaver( const TQString & newPath )
{
    /*
     * No need to actually save the current working directory: This object
     * includes a TQDir whose default constructor constructs a directory object
     * that contains the current working directory. Just what is needed here.
     */

    cd( newPath );
}


KDirSaver::KDirSaver( const KURL & url )
{
    if ( url.isLocalFile() )
    {
	cd( url.path() );
    }
    else
    {
	kdError() << k_funcinfo << "Can't change dir to remote location " << url.url() << endl;
    }
}


KDirSaver::~KDirSaver()
{
    restore();
}


void
KDirSaver::cd( const TQString & newPath )
{
    if ( ! newPath.isEmpty() )
    {
	chdir( newPath.local8Bit() );
    }
}


TQString
KDirSaver::currentDirPath() const
{
    return TQDir::currentDirPath();
}


void
KDirSaver::restore()
{
    chdir( oldWorkingDir.path().local8Bit() );
}


// EOF
