]>
Commit | Line | Data |
---|---|---|
d7bed479 | 1 | /* |
b3f22de0 | 2 | * This file is part of the PulseView project. |
d7bed479 JH |
3 | * |
4 | * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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 | |
19 | */ | |
20 | ||
943edd76 MC |
21 | #include <cassert> |
22 | ||
269528f5 | 23 | #ifdef ENABLE_DECODE |
aaabd61b | 24 | #include <libsigrokdecode/libsigrokdecode.h> |
269528f5 | 25 | #endif |
30236a54 | 26 | |
85843b14 JH |
27 | #include <algorithm> |
28 | #include <iterator> | |
29 | ||
7d5425ef JH |
30 | #include <QAction> |
31 | #include <QApplication> | |
32 | #include <QButtonGroup> | |
93f683ad | 33 | #include <QCloseEvent> |
2953961c | 34 | #include <QFileDialog> |
f2edb557 | 35 | #include <QMessageBox> |
7d5425ef JH |
36 | #include <QMenu> |
37 | #include <QMenuBar> | |
643f65f9 | 38 | #include <QSettings> |
7d5425ef JH |
39 | #include <QStatusBar> |
40 | #include <QVBoxLayout> | |
41 | #include <QWidget> | |
2953961c | 42 | |
2acdb232 | 43 | #include "mainwindow.hpp" |
107ca6d3 | 44 | |
2acdb232 JH |
45 | #include "devicemanager.hpp" |
46 | #include "dialogs/about.hpp" | |
47 | #include "dialogs/connect.hpp" | |
48 | #include "dialogs/storeprogress.hpp" | |
7c657094 | 49 | #include "toolbars/mainbar.hpp" |
2acdb232 JH |
50 | #include "view/logicsignal.hpp" |
51 | #include "view/view.hpp" | |
269528f5 | 52 | #ifdef ENABLE_DECODE |
2acdb232 | 53 | #include "widgets/decodermenu.hpp" |
269528f5 | 54 | #endif |
d7bed479 | 55 | |
30236a54 JH |
56 | #include <inttypes.h> |
57 | #include <stdint.h> | |
58 | #include <stdarg.h> | |
59 | #include <glib.h> | |
e8d00928 | 60 | #include <libsigrok/libsigrok.hpp> |
e82fd481 | 61 | |
819f4c25 | 62 | using std::list; |
6842b5fc | 63 | using std::map; |
f9abf97e | 64 | using std::shared_ptr; |
6842b5fc | 65 | using std::string; |
30236a54 | 66 | |
e8d00928 ML |
67 | using sigrok::Device; |
68 | using sigrok::Error; | |
69 | using sigrok::HardwareDevice; | |
70 | ||
51e77110 JH |
71 | namespace pv { |
72 | ||
b1264f56 | 73 | namespace view { |
26e3af6b | 74 | class ViewItem; |
b1264f56 JH |
75 | } |
76 | ||
643f65f9 JS |
77 | const char *MainWindow::SettingOpenDirectory = "MainWindow/OpenDirectory"; |
78 | const char *MainWindow::SettingSaveDirectory = "MainWindow/SaveDirectory"; | |
79 | ||
107ca6d3 JH |
80 | MainWindow::MainWindow(DeviceManager &device_manager, |
81 | const char *open_file_name, | |
1d478458 | 82 | QWidget *parent) : |
107ca6d3 | 83 | QMainWindow(parent), |
8dbbc7f0 | 84 | device_manager_(device_manager), |
69654681 JH |
85 | session_(device_manager), |
86 | action_open_(new QAction(this)), | |
87 | action_save_as_(new QAction(this)), | |
88 | action_connect_(new QAction(this)), | |
89 | action_quit_(new QAction(this)), | |
90 | action_view_zoom_in_(new QAction(this)), | |
91 | action_view_zoom_out_(new QAction(this)), | |
92 | action_view_zoom_fit_(new QAction(this)), | |
93 | action_view_zoom_one_to_one_(new QAction(this)), | |
94 | action_view_show_cursors_(new QAction(this)), | |
95 | action_about_(new QAction(this)) | |
d7bed479 | 96 | { |
7d5425ef | 97 | setup_ui(); |
93f683ad | 98 | restore_ui_settings(); |
1d478458 JH |
99 | if (open_file_name) { |
100 | const QString s(QString::fromUtf8(open_file_name)); | |
101 | QMetaObject::invokeMethod(this, "load_file", | |
102 | Qt::QueuedConnection, | |
103 | Q_ARG(QString, s)); | |
104 | } | |
7d5425ef JH |
105 | } |
106 | ||
69654681 JH |
107 | QAction* MainWindow::action_open() const |
108 | { | |
109 | return action_open_; | |
110 | } | |
111 | ||
112 | QAction* MainWindow::action_save_as() const | |
113 | { | |
114 | return action_save_as_; | |
115 | } | |
116 | ||
117 | QAction* MainWindow::action_connect() const | |
118 | { | |
119 | return action_connect_; | |
120 | } | |
121 | ||
122 | QAction* MainWindow::action_quit() const | |
123 | { | |
124 | return action_quit_; | |
125 | } | |
126 | ||
127 | QAction* MainWindow::action_view_zoom_in() const | |
128 | { | |
129 | return action_view_zoom_in_; | |
130 | } | |
131 | ||
132 | QAction* MainWindow::action_view_zoom_out() const | |
133 | { | |
134 | return action_view_zoom_out_; | |
135 | } | |
136 | ||
137 | QAction* MainWindow::action_view_zoom_fit() const | |
138 | { | |
139 | return action_view_zoom_fit_; | |
140 | } | |
141 | ||
142 | QAction* MainWindow::action_view_zoom_one_to_one() const | |
143 | { | |
144 | return action_view_zoom_one_to_one_; | |
145 | } | |
146 | ||
147 | QAction* MainWindow::action_view_show_cursors() const | |
148 | { | |
149 | return action_view_show_cursors_; | |
150 | } | |
151 | ||
152 | QAction* MainWindow::action_about() const | |
153 | { | |
154 | return action_about_; | |
155 | } | |
156 | ||
4e7f5ba8 JH |
157 | void MainWindow::run_stop() |
158 | { | |
159 | switch(session_.get_capture_state()) { | |
2b81ae46 | 160 | case Session::Stopped: |
4e7f5ba8 JH |
161 | session_.start_capture([&](QString message) { |
162 | session_error("Capture failed", message); }); | |
163 | break; | |
164 | ||
2b81ae46 JH |
165 | case Session::AwaitingTrigger: |
166 | case Session::Running: | |
4e7f5ba8 JH |
167 | session_.stop_capture(); |
168 | break; | |
169 | } | |
170 | } | |
171 | ||
51cf49fe JH |
172 | void MainWindow::select_device(shared_ptr<Device> device) |
173 | { | |
174 | try { | |
175 | session_.set_device(device); | |
176 | } catch(const QString &e) { | |
177 | QMessageBox msg(this); | |
178 | msg.setText(e); | |
179 | msg.setInformativeText(tr("Failed to Select Device")); | |
180 | msg.setStandardButtons(QMessageBox::Ok); | |
181 | msg.setIcon(QMessageBox::Warning); | |
182 | msg.exec(); | |
183 | } | |
184 | } | |
185 | ||
7d5425ef JH |
186 | void MainWindow::setup_ui() |
187 | { | |
188 | setObjectName(QString::fromUtf8("MainWindow")); | |
189 | ||
7d5425ef JH |
190 | // Set the window icon |
191 | QIcon icon; | |
192 | icon.addFile(QString::fromUtf8(":/icons/sigrok-logo-notext.png"), | |
193 | QSize(), QIcon::Normal, QIcon::Off); | |
194 | setWindowIcon(icon); | |
195 | ||
e072efc8 | 196 | // Setup the central widget |
8dbbc7f0 JH |
197 | central_widget_ = new QWidget(this); |
198 | vertical_layout_ = new QVBoxLayout(central_widget_); | |
199 | vertical_layout_->setSpacing(6); | |
200 | vertical_layout_->setContentsMargins(0, 0, 0, 0); | |
201 | setCentralWidget(central_widget_); | |
e072efc8 | 202 | |
8dbbc7f0 | 203 | view_ = new pv::view::View(session_, this); |
b1264f56 | 204 | |
8dbbc7f0 | 205 | vertical_layout_->addWidget(view_); |
e072efc8 | 206 | |
ab1d13ee | 207 | // Setup the menu bar |
ced1cc13 JH |
208 | QMenuBar *const menu_bar = new QMenuBar(this); |
209 | menu_bar->setGeometry(QRect(0, 0, 400, 25)); | |
a429590b | 210 | |
ab1d13ee | 211 | // File Menu |
ced1cc13 | 212 | QMenu *const menu_file = new QMenu; |
0a9fdca5 | 213 | menu_file->setTitle(tr("&File")); |
e072efc8 | 214 | |
69654681 JH |
215 | action_open_->setText(tr("&Open...")); |
216 | action_open_->setIcon(QIcon::fromTheme("document-open", | |
362eea96 | 217 | QIcon(":/icons/document-open.png"))); |
69654681 JH |
218 | action_open_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O)); |
219 | action_open_->setObjectName(QString::fromUtf8("actionOpen")); | |
220 | menu_file->addAction(action_open_); | |
009e1503 | 221 | |
69654681 JH |
222 | action_save_as_->setText(tr("&Save As...")); |
223 | action_save_as_->setIcon(QIcon::fromTheme("document-save-as", | |
0fbda3c2 | 224 | QIcon(":/icons/document-save-as.png"))); |
69654681 JH |
225 | action_save_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); |
226 | action_save_as_->setObjectName(QString::fromUtf8("actionSaveAs")); | |
227 | menu_file->addAction(action_save_as_); | |
0fbda3c2 | 228 | |
ced1cc13 | 229 | menu_file->addSeparator(); |
2a032dcb | 230 | |
69654681 JH |
231 | action_connect_->setText(tr("&Connect to Device...")); |
232 | action_connect_->setObjectName(QString::fromUtf8("actionConnect")); | |
233 | menu_file->addAction(action_connect_); | |
9663c82b | 234 | |
ced1cc13 | 235 | menu_file->addSeparator(); |
9663c82b | 236 | |
69654681 JH |
237 | action_quit_->setText(tr("&Quit")); |
238 | action_quit_->setIcon(QIcon::fromTheme("application-exit", | |
2a032dcb | 239 | QIcon(":/icons/application-exit.png"))); |
69654681 JH |
240 | action_quit_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q)); |
241 | action_quit_->setObjectName(QString::fromUtf8("actionQuit")); | |
242 | menu_file->addAction(action_quit_); | |
2a032dcb | 243 | |
ab1d13ee | 244 | // View Menu |
ced1cc13 | 245 | QMenu *menu_view = new QMenu; |
0a9fdca5 | 246 | menu_view->setTitle(tr("&View")); |
ab1d13ee | 247 | |
69654681 JH |
248 | action_view_zoom_in_->setText(tr("Zoom &In")); |
249 | action_view_zoom_in_->setIcon(QIcon::fromTheme("zoom-in", | |
ab1d13ee | 250 | QIcon(":/icons/zoom-in.png"))); |
d2899ad5 | 251 | // simply using Qt::Key_Plus shows no + in the menu |
69654681 JH |
252 | action_view_zoom_in_->setShortcut(QKeySequence::ZoomIn); |
253 | action_view_zoom_in_->setObjectName( | |
ab1d13ee | 254 | QString::fromUtf8("actionViewZoomIn")); |
69654681 | 255 | menu_view->addAction(action_view_zoom_in_); |
ab1d13ee | 256 | |
69654681 JH |
257 | action_view_zoom_out_->setText(tr("Zoom &Out")); |
258 | action_view_zoom_out_->setIcon(QIcon::fromTheme("zoom-out", | |
ab1d13ee | 259 | QIcon(":/icons/zoom-out.png"))); |
69654681 JH |
260 | action_view_zoom_out_->setShortcut(QKeySequence::ZoomOut); |
261 | action_view_zoom_out_->setObjectName( | |
ab1d13ee | 262 | QString::fromUtf8("actionViewZoomOut")); |
69654681 | 263 | menu_view->addAction(action_view_zoom_out_); |
ab1d13ee | 264 | |
69654681 JH |
265 | action_view_zoom_fit_->setText(tr("Zoom to &Fit")); |
266 | action_view_zoom_fit_->setIcon(QIcon::fromTheme("zoom-fit", | |
ca46b534 | 267 | QIcon(":/icons/zoom-fit.png"))); |
69654681 JH |
268 | action_view_zoom_fit_->setShortcut(QKeySequence(Qt::Key_F)); |
269 | action_view_zoom_fit_->setObjectName( | |
ca46b534 | 270 | QString::fromUtf8("actionViewZoomFit")); |
69654681 | 271 | menu_view->addAction(action_view_zoom_fit_); |
ca46b534 | 272 | |
69654681 JH |
273 | action_view_zoom_one_to_one_->setText(tr("Zoom to &One-to-One")); |
274 | action_view_zoom_one_to_one_->setIcon(QIcon::fromTheme("zoom-original", | |
d1e7d82c | 275 | QIcon(":/icons/zoom-original.png"))); |
69654681 JH |
276 | action_view_zoom_one_to_one_->setShortcut(QKeySequence(Qt::Key_O)); |
277 | action_view_zoom_one_to_one_->setObjectName( | |
d1e7d82c | 278 | QString::fromUtf8("actionViewZoomOneToOne")); |
69654681 | 279 | menu_view->addAction(action_view_zoom_one_to_one_); |
d1e7d82c | 280 | |
ced1cc13 | 281 | menu_view->addSeparator(); |
ab1d13ee | 282 | |
69654681 JH |
283 | action_view_show_cursors_->setCheckable(true); |
284 | action_view_show_cursors_->setChecked(view_->cursors_shown()); | |
285 | action_view_show_cursors_->setShortcut(QKeySequence(Qt::Key_C)); | |
286 | action_view_show_cursors_->setObjectName( | |
ab1d13ee | 287 | QString::fromUtf8("actionViewShowCursors")); |
69654681 JH |
288 | action_view_show_cursors_->setText(tr("Show &Cursors")); |
289 | menu_view->addAction(action_view_show_cursors_); | |
a429590b | 290 | |
7dd093df | 291 | // Decoders Menu |
269528f5 | 292 | #ifdef ENABLE_DECODE |
ced1cc13 | 293 | QMenu *const menu_decoders = new QMenu; |
0a9fdca5 | 294 | menu_decoders->setTitle(tr("&Decoders")); |
7dd093df | 295 | |
ced1cc13 | 296 | pv::widgets::DecoderMenu *const menu_decoders_add = |
f69ec72d | 297 | new pv::widgets::DecoderMenu(menu_decoders, true); |
0a9fdca5 | 298 | menu_decoders_add->setTitle(tr("&Add")); |
ced1cc13 | 299 | connect(menu_decoders_add, SIGNAL(decoder_selected(srd_decoder*)), |
f0d37dab | 300 | this, SLOT(add_decoder(srd_decoder*))); |
7dd093df | 301 | |
ced1cc13 | 302 | menu_decoders->addMenu(menu_decoders_add); |
269528f5 | 303 | #endif |
7dd093df | 304 | |
ab1d13ee | 305 | // Help Menu |
ced1cc13 | 306 | QMenu *const menu_help = new QMenu; |
0a9fdca5 | 307 | menu_help->setTitle(tr("&Help")); |
ab1d13ee | 308 | |
69654681 JH |
309 | action_about_->setObjectName(QString::fromUtf8("actionAbout")); |
310 | action_about_->setText(tr("&About...")); | |
311 | menu_help->addAction(action_about_); | |
7d5425ef | 312 | |
ced1cc13 JH |
313 | menu_bar->addAction(menu_file->menuAction()); |
314 | menu_bar->addAction(menu_view->menuAction()); | |
269528f5 | 315 | #ifdef ENABLE_DECODE |
ced1cc13 | 316 | menu_bar->addAction(menu_decoders->menuAction()); |
269528f5 | 317 | #endif |
ced1cc13 | 318 | menu_bar->addAction(menu_help->menuAction()); |
7d5425ef | 319 | |
ced1cc13 | 320 | setMenuBar(menu_bar); |
7d5425ef JH |
321 | QMetaObject::connectSlotsByName(this); |
322 | ||
5ac961e3 | 323 | // Setup the toolbar |
ced1cc13 | 324 | QToolBar *const toolbar = new QToolBar(tr("Main Toolbar"), this); |
0c7cdea2 | 325 | toolbar->setObjectName(QString::fromUtf8("MainToolbar")); |
69654681 JH |
326 | toolbar->addAction(action_open_); |
327 | toolbar->addAction(action_save_as_); | |
ced1cc13 | 328 | toolbar->addSeparator(); |
69654681 JH |
329 | toolbar->addAction(action_view_zoom_in_); |
330 | toolbar->addAction(action_view_zoom_out_); | |
331 | toolbar->addAction(action_view_zoom_fit_); | |
332 | toolbar->addAction(action_view_zoom_one_to_one_); | |
ced1cc13 | 333 | addToolBar(toolbar); |
0a4db787 | 334 | |
5ac961e3 | 335 | // Setup the sampling bar |
7c657094 | 336 | main_bar_ = new toolbars::MainBar(session_, *this); |
5ac961e3 JH |
337 | |
338 | // Populate the device list and select the initially selected device | |
107ca6d3 | 339 | update_device_list(); |
5ac961e3 | 340 | |
7c657094 | 341 | addToolBar(main_bar_); |
d4984fe7 | 342 | |
5ac961e3 | 343 | // Set the title |
0a9fdca5 | 344 | setWindowTitle(tr("PulseView")); |
a8d3fb2d | 345 | |
8dbbc7f0 JH |
346 | // Setup session_ events |
347 | connect(&session_, SIGNAL(capture_state_changed(int)), this, | |
6ac96c2e | 348 | SLOT(capture_state_changed(int))); |
20f81a58 JH |
349 | connect(&session_, SIGNAL(device_selected()), this, |
350 | SLOT(device_selected())); | |
d7bed479 | 351 | } |
30236a54 | 352 | |
93f683ad SA |
353 | void MainWindow::save_ui_settings() |
354 | { | |
39eb0d45 | 355 | QSettings settings; |
93f683ad | 356 | |
6842b5fc SA |
357 | map<string, string> dev_info; |
358 | list<string> key_list; | |
359 | ||
93f683ad SA |
360 | settings.beginGroup("MainWindow"); |
361 | settings.setValue("state", saveState()); | |
362 | settings.setValue("geometry", saveGeometry()); | |
363 | settings.endGroup(); | |
6842b5fc | 364 | |
8dbbc7f0 | 365 | if (session_.device()) { |
6842b5fc SA |
366 | settings.beginGroup("Device"); |
367 | key_list.push_back("vendor"); | |
368 | key_list.push_back("model"); | |
369 | key_list.push_back("version"); | |
370 | key_list.push_back("serial_num"); | |
371 | key_list.push_back("connection_id"); | |
372 | ||
8dbbc7f0 JH |
373 | dev_info = device_manager_.get_device_info( |
374 | session_.device()); | |
6842b5fc SA |
375 | |
376 | for (string key : key_list) { | |
377 | ||
378 | if (dev_info.count(key)) | |
379 | settings.setValue(QString::fromUtf8(key.c_str()), | |
380 | QString::fromUtf8(dev_info.at(key).c_str())); | |
381 | else | |
382 | settings.remove(QString::fromUtf8(key.c_str())); | |
383 | } | |
384 | ||
385 | settings.endGroup(); | |
386 | } | |
93f683ad SA |
387 | } |
388 | ||
389 | void MainWindow::restore_ui_settings() | |
390 | { | |
39eb0d45 | 391 | QSettings settings; |
93f683ad | 392 | |
e8d00928 | 393 | shared_ptr<HardwareDevice> device; |
6842b5fc SA |
394 | |
395 | map<string, string> dev_info; | |
396 | list<string> key_list; | |
397 | string value; | |
398 | ||
93f683ad SA |
399 | settings.beginGroup("MainWindow"); |
400 | ||
401 | if (settings.contains("geometry")) { | |
402 | restoreGeometry(settings.value("geometry").toByteArray()); | |
403 | restoreState(settings.value("state").toByteArray()); | |
404 | } else | |
405 | resize(1000, 720); | |
406 | ||
407 | settings.endGroup(); | |
6842b5fc SA |
408 | |
409 | // Re-select last used device if possible. | |
410 | settings.beginGroup("Device"); | |
411 | key_list.push_back("vendor"); | |
412 | key_list.push_back("model"); | |
413 | key_list.push_back("version"); | |
414 | key_list.push_back("serial_num"); | |
415 | key_list.push_back("connection_id"); | |
416 | ||
417 | for (string key : key_list) { | |
418 | if (!settings.contains(QString::fromUtf8(key.c_str()))) | |
419 | continue; | |
420 | ||
421 | value = settings.value(QString::fromUtf8(key.c_str())).toString().toStdString(); | |
422 | ||
423 | if (value.size() > 0) | |
424 | dev_info.insert(std::make_pair(key, value)); | |
425 | } | |
426 | ||
8dbbc7f0 | 427 | device = device_manager_.find_device_from_info(dev_info); |
6842b5fc SA |
428 | |
429 | if (device) { | |
51cf49fe | 430 | select_device(device); |
6842b5fc SA |
431 | update_device_list(); |
432 | } | |
433 | ||
434 | settings.endGroup(); | |
93f683ad SA |
435 | } |
436 | ||
f2edb557 JH |
437 | void MainWindow::session_error( |
438 | const QString text, const QString info_text) | |
439 | { | |
440 | QMetaObject::invokeMethod(this, "show_session_error", | |
441 | Qt::QueuedConnection, Q_ARG(QString, text), | |
442 | Q_ARG(QString, info_text)); | |
443 | } | |
444 | ||
d873f4d6 | 445 | void MainWindow::update_device_list() |
107ca6d3 | 446 | { |
7c657094 | 447 | assert(main_bar_); |
107ca6d3 | 448 | |
8dbbc7f0 | 449 | shared_ptr<Device> selected_device = session_.device(); |
e8d00928 | 450 | list< shared_ptr<Device> > devices; |
52a80eb3 | 451 | |
8dbbc7f0 | 452 | if (device_manager_.devices().size() == 0) |
52a80eb3 SA |
453 | return; |
454 | ||
8dbbc7f0 JH |
455 | std::copy(device_manager_.devices().begin(), |
456 | device_manager_.devices().end(), std::back_inserter(devices)); | |
85843b14 | 457 | |
a5ea63c2 JH |
458 | if (std::find(devices.begin(), devices.end(), selected_device) == |
459 | devices.end()) | |
460 | devices.push_back(selected_device); | |
e95e8563 | 461 | assert(selected_device); |
a5ea63c2 | 462 | |
7c657094 | 463 | main_bar_->set_device_list(devices, selected_device); |
107ca6d3 JH |
464 | } |
465 | ||
93f683ad SA |
466 | void MainWindow::closeEvent(QCloseEvent *event) |
467 | { | |
468 | save_ui_settings(); | |
469 | event->accept(); | |
470 | } | |
471 | ||
1d478458 JH |
472 | void MainWindow::load_file(QString file_name) |
473 | { | |
f2edb557 JH |
474 | const QString errorMessage( |
475 | QString("Failed to load file %1").arg(file_name)); | |
476 | const QString infoMessage; | |
ae2d1bc5 JH |
477 | |
478 | try { | |
8dbbc7f0 | 479 | session_.set_file(file_name.toStdString()); |
e8d00928 ML |
480 | } catch(Error e) { |
481 | show_session_error(tr("Failed to load ") + file_name, e.what()); | |
8dbbc7f0 | 482 | session_.set_default_device(); |
6fd0b639 JH |
483 | update_device_list(); |
484 | return; | |
ae2d1bc5 JH |
485 | } |
486 | ||
a5ea63c2 JH |
487 | update_device_list(); |
488 | ||
8dbbc7f0 | 489 | session_.start_capture([&, errorMessage, infoMessage](QString) { |
6db73158 | 490 | session_error(errorMessage, infoMessage); }); |
f2edb557 JH |
491 | } |
492 | ||
493 | void MainWindow::show_session_error( | |
494 | const QString text, const QString info_text) | |
495 | { | |
496 | QMessageBox msg(this); | |
497 | msg.setText(text); | |
498 | msg.setInformativeText(info_text); | |
499 | msg.setStandardButtons(QMessageBox::Ok); | |
500 | msg.setIcon(QMessageBox::Warning); | |
501 | msg.exec(); | |
1d478458 JH |
502 | } |
503 | ||
2953961c JH |
504 | void MainWindow::on_actionOpen_triggered() |
505 | { | |
643f65f9 JS |
506 | QSettings settings; |
507 | const QString dir = settings.value(SettingOpenDirectory).toString(); | |
508 | ||
1d43d767 | 509 | // Show the dialog |
1d478458 | 510 | const QString file_name = QFileDialog::getOpenFileName( |
643f65f9 | 511 | this, tr("Open File"), dir, tr( |
6866d5de JH |
512 | "Sigrok Sessions (*.sr);;" |
513 | "All Files (*.*)")); | |
643f65f9 JS |
514 | |
515 | if (!file_name.isEmpty()) { | |
92b139d0 | 516 | load_file(file_name); |
643f65f9 JS |
517 | |
518 | const QString abs_path = QFileInfo(file_name).absolutePath(); | |
519 | settings.setValue(SettingOpenDirectory, abs_path); | |
520 | } | |
2953961c JH |
521 | } |
522 | ||
0fbda3c2 JH |
523 | void MainWindow::on_actionSaveAs_triggered() |
524 | { | |
525 | using pv::dialogs::StoreProgress; | |
526 | ||
527 | // Stop any currently running capture session | |
8dbbc7f0 | 528 | session_.stop_capture(); |
0fbda3c2 | 529 | |
643f65f9 JS |
530 | QSettings settings; |
531 | const QString dir = settings.value(SettingSaveDirectory).toString(); | |
532 | ||
0fbda3c2 JH |
533 | // Show the dialog |
534 | const QString file_name = QFileDialog::getSaveFileName( | |
643f65f9 | 535 | this, tr("Save File"), dir, tr("Sigrok Sessions (*.sr)")); |
0fbda3c2 JH |
536 | |
537 | if (file_name.isEmpty()) | |
538 | return; | |
539 | ||
643f65f9 JS |
540 | const QString abs_path = QFileInfo(file_name).absolutePath(); |
541 | settings.setValue(SettingSaveDirectory, abs_path); | |
542 | ||
8dbbc7f0 | 543 | StoreProgress *dlg = new StoreProgress(file_name, session_, this); |
0fbda3c2 JH |
544 | dlg->run(); |
545 | } | |
546 | ||
9663c82b JH |
547 | void MainWindow::on_actionConnect_triggered() |
548 | { | |
b99cfc42 | 549 | // Stop any currently running capture session |
8dbbc7f0 | 550 | session_.stop_capture(); |
b99cfc42 | 551 | |
8dbbc7f0 | 552 | dialogs::Connect dlg(this, device_manager_); |
5eb0fa13 | 553 | |
dc0867ff JH |
554 | // If the user selected a device, select it in the device list. Select the |
555 | // current device otherwise. | |
d873f4d6 | 556 | if (dlg.exec()) |
51cf49fe | 557 | select_device(dlg.get_selected_device()); |
dc0867ff | 558 | |
d873f4d6 | 559 | update_device_list(); |
9663c82b JH |
560 | } |
561 | ||
2a032dcb JH |
562 | void MainWindow::on_actionQuit_triggered() |
563 | { | |
564 | close(); | |
565 | } | |
566 | ||
a429590b JH |
567 | void MainWindow::on_actionViewZoomIn_triggered() |
568 | { | |
8dbbc7f0 | 569 | view_->zoom(1); |
a429590b JH |
570 | } |
571 | ||
572 | void MainWindow::on_actionViewZoomOut_triggered() | |
573 | { | |
8dbbc7f0 | 574 | view_->zoom(-1); |
a429590b JH |
575 | } |
576 | ||
ca46b534 JH |
577 | void MainWindow::on_actionViewZoomFit_triggered() |
578 | { | |
8dbbc7f0 | 579 | view_->zoom_fit(); |
ca46b534 JH |
580 | } |
581 | ||
d1e7d82c JH |
582 | void MainWindow::on_actionViewZoomOneToOne_triggered() |
583 | { | |
8dbbc7f0 | 584 | view_->zoom_one_to_one(); |
d1e7d82c JH |
585 | } |
586 | ||
e072efc8 JH |
587 | void MainWindow::on_actionViewShowCursors_triggered() |
588 | { | |
8dbbc7f0 | 589 | assert(view_); |
b4d91e56 | 590 | |
8dbbc7f0 | 591 | const bool show = !view_->cursors_shown(); |
b4d91e56 | 592 | if(show) |
8dbbc7f0 | 593 | view_->centre_cursors(); |
b4d91e56 | 594 | |
8dbbc7f0 | 595 | view_->show_cursors(show); |
e072efc8 JH |
596 | } |
597 | ||
30236a54 JH |
598 | void MainWindow::on_actionAbout_triggered() |
599 | { | |
8dbbc7f0 | 600 | dialogs::About dlg(device_manager_.context(), this); |
40eb2ff4 | 601 | dlg.exec(); |
30236a54 | 602 | } |
274d4f13 | 603 | |
f0d37dab | 604 | void MainWindow::add_decoder(srd_decoder *decoder) |
7dd093df | 605 | { |
269528f5 | 606 | #ifdef ENABLE_DECODE |
f0d37dab | 607 | assert(decoder); |
8dbbc7f0 | 608 | session_.add_decoder(decoder); |
269528f5 JH |
609 | #else |
610 | (void)decoder; | |
611 | #endif | |
7dd093df JH |
612 | } |
613 | ||
6ac96c2e JH |
614 | void MainWindow::capture_state_changed(int state) |
615 | { | |
7c657094 | 616 | main_bar_->set_capture_state((pv::Session::capture_state)state); |
6ac96c2e JH |
617 | } |
618 | ||
20f81a58 JH |
619 | void MainWindow::device_selected() |
620 | { | |
621 | // Set the title to include the device/file name | |
622 | const shared_ptr<sigrok::Device> device = session_.device(); | |
623 | if (!device) | |
624 | return; | |
625 | ||
626 | const string display_name = device_manager_.get_display_name(device); | |
627 | setWindowTitle(tr("%1 - PulseView").arg(display_name.c_str())); | |
628 | } | |
629 | ||
51e77110 | 630 | } // namespace pv |