]> sigrok.org Git - pulseview.git/commitdiff
MainWindow: Use extension to populate filter
authorJoel Holdsworth <redacted>
Wed, 21 Jan 2015 06:53:29 +0000 (01:53 -0500)
committerUwe Hermann <redacted>
Tue, 27 Jan 2015 15:28:32 +0000 (16:28 +0100)
pv/mainwindow.cpp

index 81112aba805ffa688fbef84bc91708c38ab569b6..7dcf8958e4dd29fc3778f7b19e3c94d664993c0b 100644 (file)
@@ -27,6 +27,8 @@
 #include <algorithm>
 #include <iterator>
 
+#include <boost/algorithm/string/join.hpp>
+
 #include <QAction>
 #include <QApplication>
 #include <QButtonGroup>
@@ -66,6 +68,9 @@ using std::list;
 using std::map;
 using std::shared_ptr;
 using std::string;
+using std::vector;
+
+using boost::algorithm::join;
 
 using sigrok::Device;
 using sigrok::Error;
@@ -203,10 +208,21 @@ void MainWindow::export_file(shared_ptr<OutputFormat> format)
        QSettings settings;
        const QString dir = settings.value(SettingSaveDirectory).toString();
 
+       // Construct the filter
+       const vector<string> exts = format->extensions();
+       QString filter = tr("%1 files ").arg(
+               QString::fromStdString(format->description()));
+
+       if (exts.empty())
+               filter += "(*.*)";
+       else
+               filter += QString("(*.%1);;%2 (*.*)").arg(
+                       QString::fromStdString(join(exts, ", *."))).arg(
+                       tr("All Files"));
+
        // Show the file dialog
        const QString file_name = QFileDialog::getSaveFileName(
-               this, tr("Save File"), dir, tr("%1 files (*.*)").arg(
-                       QString::fromStdString(format->description())));
+               this, tr("Save File"), dir, filter);
 
        if (file_name.isEmpty())
                return;