+void MainBar::export_file(shared_ptr<OutputFormat> format,
+ bool selection_only)
+{
+ using pv::dialogs::StoreProgress;
+
+ // Stop any currently running capture session
+ session_.stop_capture();
+
+ QSettings settings;
+ const QString dir = settings.value(SettingSaveDirectory).toString();
+
+ std::pair<uint64_t, uint64_t> sample_range;
+
+ // Selection only? Verify that the cursors are active and fetch their values
+ if (selection_only) {
+ views::TraceView::View *trace_view =
+ qobject_cast<views::TraceView::View*>(session_.main_view().get());
+
+ if (!trace_view->cursors()->enabled()) {
+ show_session_error(tr("Missing Cursors"), tr("You need to set the " \
+ "cursors before you can save the data enclosed by them " \
+ "to a session file (e.g. using ALT-V - Show Cursors)."));
+ return;
+ }
+
+ const double samplerate = session_.get_samplerate();
+
+ const pv::util::Timestamp& start_time = trace_view->cursors()->first()->time();
+ const pv::util::Timestamp& end_time = trace_view->cursors()->second()->time();
+
+ const uint64_t start_sample = (uint64_t)std::max(
+ (double)0, start_time.convert_to<double>() * samplerate);
+ const uint64_t end_sample = (uint64_t)std::max(
+ (double)0, end_time.convert_to<double>() * samplerate);
+
+ sample_range = std::make_pair(start_sample, end_sample);
+ } else {
+ sample_range = std::make_pair(0, 0);
+ }
+
+ // 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, ", *.")),
+ tr("All Files"));
+
+ // Show the file dialog
+ const QString file_name = QFileDialog::getSaveFileName(
+ this, tr("Save File"), dir, filter);
+
+ if (file_name.isEmpty())