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