Skip to content

Commit

Permalink
libdeng2|App: Changing the current working directory
Browse files Browse the repository at this point in the history
The current working path can be set and queried via de::App.

This does not reduce the usefulness of NativePath::workPath(), though,
as another way of accessing the same information.
  • Loading branch information
skyjake committed Nov 9, 2012
1 parent 886b560 commit 189a650
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 11 additions & 1 deletion doomsday/libdeng2/include/de/core/app.h
Expand Up @@ -106,10 +106,20 @@ namespace de
NativePath nativeHomePath();

/**
* Returns the process's current native working path.
* Returns the application's current native working directory.
*/
static NativePath currentWorkPath();

/**
* Changes the application's current native working directory.
*
* @param cwd New working directory for the application.
*
* @return @c true, if the current working directory was changed,
* otherwise @c false.
*/
static bool setCurrentWorkPath(const NativePath& cwd);

/**
* Returns the application's file system.
*/
Expand Down
9 changes: 8 additions & 1 deletion doomsday/libdeng2/src/core/app.cpp
Expand Up @@ -30,7 +30,7 @@
#include <QDesktopServices>
#include <QDir>

using namespace de;
namespace de {

App::App(int& argc, char** argv, GUIMode guiMode)
: QApplication(argc, argv, guiMode == GUIEnabled),
Expand Down Expand Up @@ -110,6 +110,11 @@ NativePath App::currentWorkPath()
return NativePath::workPath();
}

bool App::setCurrentWorkPath(const NativePath &cwd)
{
return QDir::setCurrent(cwd);
}

NativePath App::nativeBasePath()
{
int i;
Expand Down Expand Up @@ -359,3 +364,5 @@ void App::notifyDisplayModeChanged()
{
emit displayModeChanged();
}

} // namespace de
4 changes: 2 additions & 2 deletions doomsday/libdeng2/src/filesys/directoryfeed.cpp
Expand Up @@ -22,7 +22,7 @@
#include "de/NativeFile"
#include "de/FS"
#include "de/Date"
#include "de/Log"
#include "de/App"

#include <QDir>
#include <QFileInfo>
Expand Down Expand Up @@ -201,7 +201,7 @@ void DirectoryFeed::removeFile(const String& name)

void DirectoryFeed::changeWorkingDir(const NativePath& nativePath)
{
if(!QDir::setCurrent(nativePath))
if(!App::setCurrentWorkPath(nativePath))
{
/// @throw WorkingDirError Changing to @a nativePath failed.
throw WorkingDirError("DirectoryFeed::changeWorkingDir",
Expand Down

0 comments on commit 189a650

Please sign in to comment.