2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <sigrokdecode.h>
24 #include <QApplication>
25 #include <QButtonGroup>
26 #include <QFileDialog>
30 #include <QVBoxLayout>
33 #include "mainwindow.h"
34 #include "samplingbar.h"
35 #include "dialogs/about.h"
36 #include "dialogs/connect.h"
37 #include "view/view.h"
39 /* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */
40 #define __STDC_FORMAT_MACROS
45 #include <libsigrok/libsigrok.h>
50 MainWindow::MainWindow(const char *open_file_name,
56 const QString s(QString::fromUtf8(open_file_name));
57 QMetaObject::invokeMethod(this, "load_file",
63 void MainWindow::setup_ui()
65 setObjectName(QString::fromUtf8("MainWindow"));
69 // Set the window icon
71 icon.addFile(QString::fromUtf8(":/icons/sigrok-logo-notext.png"),
72 QSize(), QIcon::Normal, QIcon::Off);
75 // Setup the central widget
76 _central_widget = new QWidget(this);
77 _vertical_layout = new QVBoxLayout(_central_widget);
78 _vertical_layout->setSpacing(6);
79 _vertical_layout->setContentsMargins(0, 0, 0, 0);
80 setCentralWidget(_central_widget);
82 _view = new pv::view::View(_session, this);
83 _vertical_layout->addWidget(_view);
86 _menu_bar = new QMenuBar(this);
87 _menu_bar->setGeometry(QRect(0, 0, 400, 25));
90 _menu_file = new QMenu(_menu_bar);
91 _menu_file->setTitle(QApplication::translate(
92 "MainWindow", "&File", 0, QApplication::UnicodeUTF8));
94 _action_open = new QAction(this);
95 _action_open->setText(QApplication::translate(
96 "MainWindow", "&Open...", 0, QApplication::UnicodeUTF8));
97 _action_open->setIcon(QIcon::fromTheme("document-open",
98 QIcon(":/icons/document-open.png")));
99 _action_open->setObjectName(QString::fromUtf8("actionOpen"));
100 _menu_file->addAction(_action_open);
102 _menu_file->addSeparator();
104 _action_connect = new QAction(this);
105 _action_connect->setText(QApplication::translate(
106 "MainWindow", "&Connect to Device...", 0,
107 QApplication::UnicodeUTF8));
108 _action_connect->setObjectName(QString::fromUtf8("actionConnect"));
109 _menu_file->addAction(_action_connect);
111 _menu_file->addSeparator();
113 _action_quit = new QAction(this);
114 _action_quit->setText(QApplication::translate(
115 "MainWindow", "&Quit", 0, QApplication::UnicodeUTF8));
116 _action_quit->setIcon(QIcon::fromTheme("application-exit",
117 QIcon(":/icons/application-exit.png")));
118 _action_quit->setObjectName(QString::fromUtf8("actionQuit"));
119 _menu_file->addAction(_action_quit);
122 _menu_view = new QMenu(_menu_bar);
123 _menu_view->setTitle(QApplication::translate(
124 "MainWindow", "&View", 0, QApplication::UnicodeUTF8));
126 _action_view_zoom_in = new QAction(this);
127 _action_view_zoom_in->setText(QApplication::translate(
128 "MainWindow", "Zoom &In", 0, QApplication::UnicodeUTF8));
129 _action_view_zoom_in->setIcon(QIcon::fromTheme("zoom-in",
130 QIcon(":/icons/zoom-in.png")));
131 _action_view_zoom_in->setObjectName(
132 QString::fromUtf8("actionViewZoomIn"));
133 _menu_view->addAction(_action_view_zoom_in);
135 _action_view_zoom_out = new QAction(this);
136 _action_view_zoom_out->setText(QApplication::translate(
137 "MainWindow", "Zoom &Out", 0, QApplication::UnicodeUTF8));
138 _action_view_zoom_out->setIcon(QIcon::fromTheme("zoom-out",
139 QIcon(":/icons/zoom-out.png")));
140 _action_view_zoom_out->setObjectName(
141 QString::fromUtf8("actionViewZoomOut"));
142 _menu_view->addAction(_action_view_zoom_out);
144 _menu_view->addSeparator();
146 _action_view_show_cursors = new QAction(this);
147 _action_view_show_cursors->setCheckable(true);
148 _action_view_show_cursors->setChecked(_view->cursors_shown());
149 _action_view_show_cursors->setObjectName(
150 QString::fromUtf8("actionViewShowCursors"));
151 _action_view_show_cursors->setText(QApplication::translate(
152 "MainWindow", "Show &Cursors", 0, QApplication::UnicodeUTF8));
153 _menu_view->addAction(_action_view_show_cursors);
156 _menu_help = new QMenu(_menu_bar);
157 _menu_help->setTitle(QApplication::translate(
158 "MainWindow", "&Help", 0, QApplication::UnicodeUTF8));
160 _action_about = new QAction(this);
161 _action_about->setObjectName(QString::fromUtf8("actionAbout"));
162 _action_about->setText(QApplication::translate(
163 "MainWindow", "&About...", 0, QApplication::UnicodeUTF8));
164 _menu_help->addAction(_action_about);
166 _menu_bar->addAction(_menu_file->menuAction());
167 _menu_bar->addAction(_menu_view->menuAction());
168 _menu_bar->addAction(_menu_help->menuAction());
170 setMenuBar(_menu_bar);
171 QMetaObject::connectSlotsByName(this);
173 // Setup the toolbars
174 _toolbar = new QToolBar(this);
175 _toolbar->addAction(_action_open);
176 _toolbar->addSeparator();
177 _toolbar->addAction(_action_view_zoom_in);
178 _toolbar->addAction(_action_view_zoom_out);
179 addToolBar(_toolbar);
181 _sampling_bar = new SamplingBar(this);
183 connect(_sampling_bar, SIGNAL(run_stop()), this,
185 addToolBar(_sampling_bar);
187 setWindowTitle(QApplication::translate("MainWindow", "PulseView", 0,
188 QApplication::UnicodeUTF8));
190 // Setup _session events
191 connect(&_session, SIGNAL(capture_state_changed(int)), this,
192 SLOT(capture_state_changed(int)));
196 void MainWindow::scan_devices()
200 /* Scan all drivers for all devices. */
201 struct sr_dev_driver **const drivers = sr_driver_list();
202 for (struct sr_dev_driver **driver = drivers; *driver; driver++) {
203 GSList *const devices = sr_driver_scan(*driver, NULL);
204 for (GSList *l = devices; l; l = l->next)
205 _devices.push_back((sr_dev_inst*)l->data);
206 g_slist_free(devices);
209 assert(_sampling_bar);
210 _sampling_bar->set_device_list(_devices);
213 void MainWindow::load_file(QString file_name)
215 _session.load_file(file_name.toStdString());
218 void MainWindow::on_actionOpen_triggered()
220 const QString file_name = QFileDialog::getOpenFileName(
221 this, tr("Open File"), "",
222 tr("Sigrok Sessions (*.sr)"));
223 load_file(file_name);
226 void MainWindow::on_actionConnect_triggered()
228 dialogs::Connect dlg(this);
232 struct sr_dev_inst *const sdi = dlg.get_selected_device();
234 assert(_sampling_bar);
236 _devices.push_back(sdi);
237 _sampling_bar->set_device_list(_devices);
238 _sampling_bar->set_selected_device(sdi);
242 void MainWindow::on_actionQuit_triggered()
247 void MainWindow::on_actionViewZoomIn_triggered()
252 void MainWindow::on_actionViewZoomOut_triggered()
257 void MainWindow::on_actionViewShowCursors_triggered()
260 _view->show_cursors(_action_view_show_cursors->isChecked());
263 void MainWindow::on_actionAbout_triggered()
265 dialogs::About dlg(this);
269 void MainWindow::run_stop()
271 switch(_session.get_capture_state()) {
272 case SigSession::Stopped:
273 _session.start_capture(
274 _sampling_bar->get_selected_device(),
275 _sampling_bar->get_record_length());
278 case SigSession::Running:
279 _session.stop_capture();
284 void MainWindow::capture_state_changed(int state)
286 _sampling_bar->set_sampling(state != SigSession::Stopped);