* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifdef ENABLE_DECODE
#include <libsigrokdecode/libsigrokdecode.h>
+#endif
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
+#include <algorithm>
+#include <iterator>
+
#include <QAction>
#include <QApplication>
#include <QButtonGroup>
#include "mainwindow.h"
#include "devicemanager.h"
+#include "device/device.h"
#include "dialogs/about.h"
#include "dialogs/connect.h"
+#include "dialogs/storeprogress.h"
#include "toolbars/samplingbar.h"
#include "view/logicsignal.h"
#include "view/view.h"
+#ifdef ENABLE_DECODE
#include "widgets/decodermenu.h"
+#endif
/* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */
#define __STDC_FORMAT_MACROS
#include <glib.h>
#include <libsigrok/libsigrok.h>
-using namespace boost;
-using namespace std;
+using boost::shared_ptr;
+using std::list;
namespace pv {
action_open->setObjectName(QString::fromUtf8("actionOpen"));
menu_file->addAction(action_open);
+ QAction *const action_save_as = new QAction(this);
+ action_save_as->setText(QApplication::translate(
+ "MainWindow", "&Save As...", 0, QApplication::UnicodeUTF8));
+ action_save_as->setIcon(QIcon::fromTheme("document-save-as",
+ QIcon(":/icons/document-save-as.png")));
+ action_save_as->setObjectName(QString::fromUtf8("actionSaveAs"));
+ menu_file->addAction(action_save_as);
+
menu_file->addSeparator();
QAction *const action_connect = new QAction(this);
"MainWindow", "Zoom &In", 0, QApplication::UnicodeUTF8));
action_view_zoom_in->setIcon(QIcon::fromTheme("zoom-in",
QIcon(":/icons/zoom-in.png")));
+ // simply using Qt::Key_Plus shows no + in the menu
+ action_view_zoom_in->setShortcut(QKeySequence::ZoomIn);
action_view_zoom_in->setObjectName(
QString::fromUtf8("actionViewZoomIn"));
menu_view->addAction(action_view_zoom_in);
"MainWindow", "Zoom &Out", 0, QApplication::UnicodeUTF8));
action_view_zoom_out->setIcon(QIcon::fromTheme("zoom-out",
QIcon(":/icons/zoom-out.png")));
+ action_view_zoom_out->setShortcut(QKeySequence::ZoomOut);
action_view_zoom_out->setObjectName(
QString::fromUtf8("actionViewZoomOut"));
menu_view->addAction(action_view_zoom_out);
menu_view->addAction(action_view_show_cursors);
// Decoders Menu
+#ifdef ENABLE_DECODE
QMenu *const menu_decoders = new QMenu;
menu_decoders->setTitle(QApplication::translate(
"MainWindow", "&Decoders", 0, QApplication::UnicodeUTF8));
this, SLOT(add_decoder(srd_decoder*)));
menu_decoders->addMenu(menu_decoders_add);
+#endif
// Help Menu
QMenu *const menu_help = new QMenu;
menu_bar->addAction(menu_file->menuAction());
menu_bar->addAction(menu_view->menuAction());
+#ifdef ENABLE_DECODE
menu_bar->addAction(menu_decoders->menuAction());
+#endif
menu_bar->addAction(menu_help->menuAction());
setMenuBar(menu_bar);
Q_ARG(QString, info_text));
}
-void MainWindow::update_device_list(struct sr_dev_inst *selected_device)
+void MainWindow::update_device_list()
{
assert(_sampling_bar);
- const list<sr_dev_inst*> &devices = _device_manager.devices();
- _sampling_bar->set_device_list(devices);
+ shared_ptr<pv::device::DevInst> selected_device = _session.get_device();
+ list< shared_ptr<device::DevInst> > devices;
+ std::copy(_device_manager.devices().begin(),
+ _device_manager.devices().end(), std::back_inserter(devices));
- if (!selected_device && !devices.empty()) {
- // Fall back to the first device in the list.
- selected_device = devices.front();
+ if (std::find(devices.begin(), devices.end(), selected_device) ==
+ devices.end())
+ devices.push_back(selected_device);
- // Try and find the demo device and select that by default
- BOOST_FOREACH (struct sr_dev_inst *sdi, devices)
- if (strcmp(sdi->driver->name, "demo") == 0) {
- selected_device = sdi;
- }
- }
+ _sampling_bar->set_device_list(devices);
- if (selected_device) {
+ if (selected_device)
_sampling_bar->set_selected_device(selected_device);
- _session.set_device(selected_device);
- }
}
void MainWindow::load_file(QString file_name)
const QString errorMessage(
QString("Failed to load file %1").arg(file_name));
const QString infoMessage;
- _session.load_file(file_name.toStdString(),
- boost::bind(&MainWindow::session_error, this,
- errorMessage, infoMessage));
+
+ try {
+ _session.set_file(file_name.toStdString());
+ } catch(QString e) {
+ show_session_error(tr("Failed to load ") + file_name, e);
+ }
+
+ update_device_list();
+
+ _session.start_capture(boost::bind(&MainWindow::session_error, this,
+ errorMessage, infoMessage));
}
void MainWindow::show_session_error(
void MainWindow::on_actionOpen_triggered()
{
- // Enumerate the file formats
- QString filters(tr("Sigrok Sessions (*.sr)"));
- filters.append(tr(";;All Files (*.*)"));
-
// Show the dialog
const QString file_name = QFileDialog::getOpenFileName(
- this, tr("Open File"), "", filters);
+ this, tr("Open File"), "", tr(
+ "Sigrok Sessions (*.sr);;"
+ "All Files (*.*)"));
if (!file_name.isEmpty())
load_file(file_name);
}
+void MainWindow::on_actionSaveAs_triggered()
+{
+ using pv::dialogs::StoreProgress;
+
+ // Stop any currently running capture session
+ _session.stop_capture();
+
+ // Show the dialog
+ const QString file_name = QFileDialog::getSaveFileName(
+ this, tr("Save File"), "", tr("Sigrok Sessions (*.sr)"));
+
+ if (file_name.isEmpty())
+ return;
+
+ StoreProgress *dlg = new StoreProgress(file_name, _session, this);
+ dlg->run();
+}
+
void MainWindow::on_actionConnect_triggered()
{
// Stop any currently running capture session
// If the user selected a device, select it in the device list. Select the
// current device otherwise.
- struct sr_dev_inst *const sdi = dlg.exec() ?
- dlg.get_selected_device() : _session.get_device();
+ if (dlg.exec())
+ _session.set_device(dlg.get_selected_device());
- update_device_list(sdi);
+ update_device_list();
}
void MainWindow::on_actionQuit_triggered()
void MainWindow::add_decoder(srd_decoder *decoder)
{
+#ifdef ENABLE_DECODE
assert(decoder);
_session.add_decoder(decoder);
+#else
+ (void)decoder;
+#endif
}
void MainWindow::run_stop()
{
switch(_session.get_capture_state()) {
case SigSession::Stopped:
- _session.start_capture(_sampling_bar->get_record_length(),
- boost::bind(&MainWindow::session_error, this,
+ _session.start_capture(
+ boost::bind(&MainWindow::session_error, this,
QString("Capture failed"), _1));
break;