From 0dd90dab2dd644d8e55330ff4df4a58efe87a34d Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Wed, 29 Feb 2012 19:31:37 +0100 Subject: [PATCH] add current dir functions --- src/misc/misc.cpp | 23 +++++++++++++++++++++++ src/misc/misc.h | 8 +++++++- 2 files changed, 30 insertions(+), 1 deletions(-) diff --git a/src/misc/misc.cpp b/src/misc/misc.cpp index 663d788..a4bea14 100644 --- a/src/misc/misc.cpp +++ b/src/misc/misc.cpp @@ -20,6 +20,9 @@ #include #include +#include +#include +#include QString htmlize(QString str) { @@ -677,3 +680,23 @@ void MLocalFormat::setTimeZone(QString olsonname) m_timezone=olsonname; } +QString currentDir() +{ + return QSettings().value("lastUsedDirectory",".").toString(); +} + +void setCurrentDir(QString fn) +{ + if(fn.isEmpty())return; + QFileInfo fi(fn); + //it is already a directory + if(fi.isDir())QSettings().setValue("lastUsedDirectory",fn); + //it is probably a file + else { + //get parent directory name + fn=fi.dir().absolutePath(); + if(QFileInfo(fn).isDir()) + QSettings().setValue("lastUsedDirectory",fn); + //abort if not found by now, this was bogus + } +} diff --git a/src/misc/misc.h b/src/misc/misc.h index 4511d30..009e915 100644 --- a/src/misc/misc.h +++ b/src/misc/misc.h @@ -4,7 +4,7 @@ // Description: miscellaneous helper functions // // -// Author: Konrad Rosenbaum , (C) 2008-2011 +// Author: Konrad Rosenbaum , (C) 2008-2012 // // Copyright: See README/COPYING.GPL files that come with this distribution // @@ -47,6 +47,12 @@ QString unix2dateTime(qint64,bool localize=true); /**return a (localized) regular expression that validates prices*/ QRegExp priceRegExp(bool localize=true); +///returns the current directory (the one last used in a file dialog) +QString currentDir(); + +///sets a new current directory (transparently handles files and directories) +void setCurrentDir(QString); + /**localized formatter class for timestamps, numbers and money; per default it uses the local translation to format data, but can be overidden; -- 1.7.2.5