aboutsummaryrefslogtreecommitdiff
path: root/src/qt/guiutil.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2012-02-15 14:47:08 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2012-02-15 17:22:00 +0100
commit303a47c09592c33aa84e2264e69643ef2570fa76 (patch)
treec24139670ca4af1fda9355dc7239cce4a0dfa852 /src/qt/guiutil.cpp
parent1df182ff886817cc8b85990aff9b0e1102c97be7 (diff)
fix default suffixes in save dialog in GNOME, make it more clear that PNG is used (solves #833)
Diffstat (limited to 'src/qt/guiutil.cpp')
-rw-r--r--src/qt/guiutil.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index 29ef554ac3..b8e74203b9 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)
{
@@ -121,3 +123,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;
+}
+