diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2012-02-22 10:41:11 -0500 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2012-02-22 10:41:11 -0500 |
commit | f246fc648a26115587ae51090bde48b92c3a6a3b (patch) | |
tree | 110b138fb94196b34e7e89e2a117b7eaff184e52 /src/qt/guiutil.cpp | |
parent | 0d56f11ada27d8fa60c8f5179917a7c9de4a8c4b (diff) | |
parent | 303a47c09592c33aa84e2264e69643ef2570fa76 (diff) |
Merge branch '201202_guiaddsuffix' of https://github.com/laanwj/bitcoin
Diffstat (limited to 'src/qt/guiutil.cpp')
-rw-r--r-- | src/qt/guiutil.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 02fc3b6700..ac69bd07e9 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -15,6 +15,8 @@ #include <QAbstractItemView> #include <QApplication> #include <QClipboard> +#include <QFileDialog> +#include <QDesktopServices> QString GUIUtil::dateTimeStr(qint64 nTime) { @@ -135,3 +137,50 @@ void GUIUtil::copyEntryData(QAbstractItemView *view, int column, int role) QApplication::clipboard()->setText(selection.at(0).data(role).toString()); } } + +QString GUIUtil::getSaveFileName(QWidget *parent, const QString &caption, + const QString &dir, + const QString &filter, + QString *selectedSuffixOut) +{ + QString selectedFilter; + QString myDir; + if(dir.isEmpty()) // Default to user documents location + { + myDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); + } + else + { + myDir = dir; + } + QString result = QFileDialog::getSaveFileName(parent, caption, myDir, filter, &selectedFilter); + + /* Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...) */ + QRegExp filter_re(".* \\(\\*\\.(.*)[ \\)]"); + QString selectedSuffix; + if(filter_re.exactMatch(selectedFilter)) + { + selectedSuffix = filter_re.cap(1); + } + + /* Add suffix if needed */ + QFileInfo info(result); + if(!result.isEmpty()) + { + if(info.suffix().isEmpty() && !selectedSuffix.isEmpty()) + { + /* No suffix specified, add selected suffix */ + if(!result.endsWith(".")) + result.append("."); + result.append(selectedSuffix); + } + } + + /* Return selected suffix if asked to */ + if(selectedSuffixOut) + { + *selectedSuffixOut = selectedSuffix; + } + return result; +} + |