aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2012-02-15 14:47:08 +0100
committerLuke Dashjr <luke-jr+git@utopios.org>2012-03-16 16:36:27 -0400
commit458b6e64368b06f8951e2fe5849272c11923dca8 (patch)
tree5b4d924bc7275b677ad25a8c86794f6f2d6a9068
parentf322aa4d600f64eea8395811900dc98d562f1dac (diff)
downloadbitcoin-458b6e64368b06f8951e2fe5849272c11923dca8.tar.xz
fix default suffixes in save dialog in GNOME, make it more clear that PNG is used (solves #833)
-rw-r--r--src/qt/addressbookpage.cpp6
-rw-r--r--src/qt/guiutil.cpp49
-rw-r--r--src/qt/guiutil.h15
-rw-r--r--src/qt/transactionview.cpp6
4 files changed, 68 insertions, 8 deletions
diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp
index 0a147c9e10..76061233fc 100644
--- a/src/qt/addressbookpage.cpp
+++ b/src/qt/addressbookpage.cpp
@@ -7,7 +7,6 @@
#include <QSortFilterProxyModel>
#include <QClipboard>
-#include <QFileDialog>
#include <QMessageBox>
AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
@@ -206,10 +205,9 @@ void AddressBookPage::done(int retval)
void AddressBookPage::exportClicked()
{
// CSV is currently the only supported format
- QString filename = QFileDialog::getSaveFileName(
+ QString filename = GUIUtil::getSaveFileName(
this,
- tr("Export Address Book Data"),
- QDir::currentPath(),
+ tr("Export Address Book Data"), QString(),
tr("Comma separated file (*.csv)"));
if (filename.isNull()) return;
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index bc443ceeb6..d1490c8f70 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -11,6 +11,8 @@
#include <QFont>
#include <QLineEdit>
#include <QUrl>
+#include <QFileDialog>
+#include <QDesktopServices>
QString GUIUtil::dateTimeStr(qint64 nTime)
{
@@ -86,3 +88,50 @@ bool GUIUtil::parseBitcoinURL(QString url, SendCoinsRecipient *out)
QUrl urlInstance(url);
return parseBitcoinURL(&urlInstance, out);
}
+
+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;
+}
+
diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h
index 129ab73038..d7523aa15c 100644
--- a/src/qt/guiutil.h
+++ b/src/qt/guiutil.h
@@ -30,6 +30,21 @@ public:
// See Bitcoin URL definition discussion here: https://bitcointalk.org/index.php?topic=33490.0
static bool parseBitcoinURL(const QUrl *url, SendCoinsRecipient *out);
static bool parseBitcoinURL(QString url, SendCoinsRecipient *out);
+
+ /** Get save file name, mimics QFileDialog::getSaveFileName, except that it appends a default suffix
+ when no suffix is provided by the user.
+
+ @param[in] parent Parent window (or 0)
+ @param[in] caption Window caption (or empty, for default)
+ @param[in] dir Starting directory (or empty, to default to documents directory)
+ @param[in] filter Filter specification such as "Comma Separated Files (*.csv)"
+ @param[out] selectedSuffixOut Pointer to return the suffix (file type) that was selected (or 0).
+ Can be useful when choosing the save file format based on suffix.
+ */
+ static QString getSaveFileName(QWidget *parent=0, const QString &caption=QString(),
+ const QString &dir=QString(), const QString &filter=QString(),
+ QString *selectedSuffixOut=0);
+
};
#endif // GUIUTIL_H
diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp
index 3ef31854fb..0bfce351a4 100644
--- a/src/qt/transactionview.cpp
+++ b/src/qt/transactionview.cpp
@@ -20,7 +20,6 @@
#include <QTableView>
#include <QHeaderView>
#include <QPushButton>
-#include <QFileDialog>
#include <QMessageBox>
#include <QPoint>
#include <QMenu>
@@ -265,10 +264,9 @@ void TransactionView::changedAmount(const QString &amount)
void TransactionView::exportClicked()
{
// CSV is currently the only supported format
- QString filename = QFileDialog::getSaveFileName(
+ QString filename = GUIUtil::getSaveFileName(
this,
- tr("Export Transaction Data"),
- QDir::currentPath(),
+ tr("Export Transaction Data"), QString(),
tr("Comma separated file (*.csv)"));
if (filename.isNull()) return;