--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2012-2013 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "connect.h"
+
+extern "C" {
+/* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */
+#define __STDC_FORMAT_MACROS
+#include <glib.h>
+#include <libsigrok/libsigrok.h>
+}
+
+namespace pv {
+namespace dialogs {
+
+Connect::Connect(QWidget *parent) :
+ QDialog(parent),
+ _layout(this),
+ _form(this),
+ _form_layout(&_form),
+ _drivers(&_form),
+ _serial_device(&_form),
+ _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+ Qt::Horizontal, this)
+{
+ setWindowTitle(tr("Connect to Device"));
+
+ connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
+
+ populate_drivers();
+ connect(&_drivers, SIGNAL(activated(int)),
+ this, SLOT(device_selected(int)));
+
+ _form.setLayout(&_form_layout);
+ _form_layout.addRow(tr("Driver"), &_drivers);
+
+ _form_layout.addRow(tr("Serial Port"), &_serial_device);
+
+ unset_connection();
+
+ setLayout(&_layout);
+ _layout.addWidget(&_form);
+ _layout.addWidget(&_button_box);
+}
+
+void Connect::populate_drivers()
+{
+ struct sr_dev_driver **drivers = sr_driver_list();
+ for (int i = 0; drivers[i]; ++i)
+ _drivers.addItem(QString("%1 (%2)").arg(
+ drivers[i]->longname).arg(drivers[i]->name),
+ qVariantFromValue((void*)drivers[i]));
+}
+
+void Connect::device_selected(int index)
+{
+ const int *hwopts;
+ const struct sr_hwcap_option *hwo;
+ sr_dev_driver *const driver = (sr_dev_driver*)_drivers.itemData(
+ index).value<void*>();
+
+ unset_connection();
+
+ if ((sr_config_list(driver, SR_CONF_SCAN_OPTIONS,
+ (const void **)&hwopts, NULL) == SR_OK) && hwopts) {
+
+ for (int i = 0; hwopts[i]; i++) {
+ switch(hwopts[i]) {
+ case SR_CONF_SERIALCOMM:
+ set_serial_connection();
+ break;
+
+ default:
+ continue;
+ }
+
+ break;
+ }
+ }
+}
+
+void Connect::unset_connection()
+{
+ _serial_device.hide();
+ _form_layout.labelForField(&_serial_device)->hide();
+}
+
+void Connect::set_serial_connection()
+{
+ _serial_device.show();
+ _form_layout.labelForField(&_serial_device)->show();
+}
+
+
+} // namespace dialogs
+} // namespace pv
--- /dev/null
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2012-2013 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef PULSEVIEW_PV_CONNECT_H
+#define PULSEVIEW_PV_CONNECT_H
+
+#include <QComboBox>
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QFormLayout>
+#include <QLineEdit>
+#include <QVBoxLayout>
+
+namespace pv {
+namespace dialogs {
+
+class Connect : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Connect(QWidget *parent);
+
+private:
+ void populate_drivers();
+
+private slots:
+ void device_selected(int index);
+
+ void unset_connection();
+
+ void set_serial_connection();
+
+private:
+ QVBoxLayout _layout;
+
+ QWidget _form;
+ QFormLayout _form_layout;
+
+ QComboBox _drivers;
+
+ QLineEdit _serial_device;
+
+ QDialogButtonBox _button_box;
+};
+
+} // namespace dialogs
+} // namespace pv
+
+#endif // PULSEVIEW_PV_CONNECT_H
#include "mainwindow.h"
#include "samplingbar.h"
#include "dialogs/about.h"
+#include "dialogs/connect.h"
#include "view/view.h"
/* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */
_menu_file->addSeparator();
+ _action_connect = new QAction(this);
+ _action_connect->setText(QApplication::translate(
+ "MainWindow", "&Connect to Device...", 0,
+ QApplication::UnicodeUTF8));
+ _action_connect->setObjectName(QString::fromUtf8("actionConnect"));
+ _menu_file->addAction(_action_connect);
+
+ _menu_file->addSeparator();
+
_action_quit = new QAction(this);
_action_quit->setText(QApplication::translate(
"MainWindow", "&Quit", 0, QApplication::UnicodeUTF8));
load_file(file_name);
}
+void MainWindow::on_actionConnect_triggered()
+{
+ dialogs::Connect dlg(this);
+ dlg.exec();
+}
+
void MainWindow::on_actionQuit_triggered()
{
close();