]> sigrok.org Git - pulseview.git/commitdiff
Initial manual connect dialog with a serial port selector
authorJoel Holdsworth <redacted>
Sat, 29 Dec 2012 14:57:10 +0000 (14:57 +0000)
committerUwe Hermann <redacted>
Sat, 9 Mar 2013 10:43:03 +0000 (11:43 +0100)
CMakeLists.txt
pv/dialogs/connect.cpp [new file with mode: 0644]
pv/dialogs/connect.h [new file with mode: 0644]
pv/mainwindow.cpp
pv/mainwindow.h

index 8d093be764d396efcdbd01847b80cacf0d2d6582..7db89f81effeee987aa915b75a1e5e6f0b792dff 100644 (file)
@@ -100,6 +100,7 @@ set(pulseview_SOURCES
        pv/data/signaldata.cpp
        pv/data/snapshot.cpp
        pv/dialogs/about.cpp
+       pv/dialogs/connect.cpp
        pv/dialogs/deviceoptions.cpp
        pv/prop/double.cpp
        pv/prop/enum.cpp
@@ -122,6 +123,7 @@ set(pulseview_HEADERS
        pv/samplingbar.h
        pv/sigsession.h
        pv/dialogs/about.h
+       pv/dialogs/connect.h
        pv/view/cursor.h
        pv/view/header.h
        pv/view/ruler.h
diff --git a/pv/dialogs/connect.cpp b/pv/dialogs/connect.cpp
new file mode 100644 (file)
index 0000000..03a03f2
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * 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
diff --git a/pv/dialogs/connect.h b/pv/dialogs/connect.h
new file mode 100644 (file)
index 0000000..443f6e0
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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
index 99e545681e71a3a71042dd30c56818606629e24d..82087ee080164f28cdfc9b3273ba2049d11dfe95 100644 (file)
@@ -33,6 +33,7 @@
 #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++). */
@@ -100,6 +101,15 @@ void MainWindow::setup_ui()
 
        _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));
@@ -195,6 +205,12 @@ void MainWindow::on_actionOpen_triggered()
        load_file(file_name);
 }
 
+void MainWindow::on_actionConnect_triggered()
+{
+       dialogs::Connect dlg(this);
+       dlg.exec();
+}
+
 void MainWindow::on_actionQuit_triggered()
 {
        close();
index 32b8f6f30da3af195bb1c6899ed3aa96f02a7272..993c608493a39a6b4a1b4a1f75486ee822985e57 100644 (file)
@@ -60,6 +60,7 @@ private:
        QMenuBar *_menu_bar;
        QMenu *_menu_file;
        QAction *_action_open;
+       QAction *_action_connect;
        QAction *_action_quit;
 
        QMenu *_menu_view;
@@ -82,6 +83,8 @@ private slots:
        void on_actionOpen_triggered();
        void on_actionQuit_triggered();
 
+       void on_actionConnect_triggered();
+
        void on_actionViewZoomIn_triggered();
 
        void on_actionViewZoomOut_triggered();