diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2012-02-15 14:47:08 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2012-02-15 17:22:00 +0100 |
commit | 303a47c09592c33aa84e2264e69643ef2570fa76 (patch) | |
tree | c24139670ca4af1fda9355dc7239cce4a0dfa852 /src/qt | |
parent | 1df182ff886817cc8b85990aff9b0e1102c97be7 (diff) |
fix default suffixes in save dialog in GNOME, make it more clear that PNG is used (solves #833)
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/addressbookpage.cpp | 6 | ||||
-rw-r--r-- | src/qt/guiutil.cpp | 49 | ||||
-rw-r--r-- | src/qt/guiutil.h | 14 | ||||
-rw-r--r-- | src/qt/qrcodedialog.cpp | 6 | ||||
-rw-r--r-- | src/qt/transactionview.cpp | 6 |
5 files changed, 70 insertions, 11 deletions
diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index b5a798ca31..76aa87b134 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -9,7 +9,6 @@ #include <QSortFilterProxyModel> #include <QClipboard> -#include <QFileDialog> #include <QMessageBox> #include <QMenu> @@ -277,10 +276,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 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; +} + diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 3a81bd2f00..8c85668465 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -45,6 +45,20 @@ public: */ static void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole); + /** 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/qrcodedialog.cpp b/src/qt/qrcodedialog.cpp index 754e0bdcb2..82959831de 100644 --- a/src/qt/qrcodedialog.cpp +++ b/src/qt/qrcodedialog.cpp @@ -1,9 +1,9 @@ #include "qrcodedialog.h" #include "ui_qrcodedialog.h" +#include "guiutil.h" + #include <QPixmap> #include <QUrl> -#include <QFileDialog> -#include <QDesktopServices> #include <QDebug> #include <qrencode.h> @@ -98,7 +98,7 @@ void QRCodeDialog::on_lnMessage_textChanged(const QString &) void QRCodeDialog::on_btnSaveAs_clicked() { - QString fn = QFileDialog::getSaveFileName(this, "Save Image...", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation), "Images (*.png)"); + QString fn = GUIUtil::getSaveFileName(this, tr("Save Image..."), QString(), tr("PNG Images (*.png)")); if(!fn.isEmpty()) { myImage.scaled(EXPORT_IMAGE_SIZE, EXPORT_IMAGE_SIZE).save(fn); } diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 4c357d1379..eaed48bfdf 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -21,7 +21,6 @@ #include <QTableView> #include <QHeaderView> #include <QPushButton> -#include <QFileDialog> #include <QMessageBox> #include <QPoint> #include <QMenu> @@ -264,10 +263,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; |