-QAction* MainBar::action_view_zoom_in() const
-{
- return action_view_zoom_in_;
-}
-
-QAction* MainBar::action_view_zoom_out() const
-{
- return action_view_zoom_out_;
-}
-
-QAction* MainBar::action_view_zoom_fit() const
-{
- return action_view_zoom_fit_;
-}
-
-QAction* MainBar::action_view_zoom_one_to_one() const
-{
- return action_view_zoom_one_to_one_;
-}
-
-QAction* MainBar::action_view_show_cursors() const
-{
- return action_view_show_cursors_;
-}
-
-void MainBar::run_stop()
-{
- switch (session_.get_capture_state()) {
- case Session::Stopped:
- session_.start_capture([&](QString message) {
- session_error("Capture failed", message); });
- break;
- case Session::AwaitingTrigger:
- case Session::Running:
- session_.stop_capture();
- break;
- }
-}
-
-void MainBar::select_device(shared_ptr<devices::Device> device)
-{
- try {
- if (device)
- session_.set_device(device);
- else
- session_.set_default_device();
- } catch (const QString &e) {
- QMessageBox msg(this);
- msg.setText(e);
- msg.setInformativeText(tr("Failed to Select Device"));
- msg.setStandardButtons(QMessageBox::Ok);
- msg.setIcon(QMessageBox::Warning);
- msg.exec();
- }
-}
-
-void MainBar::select_init_device()
-{
- QSettings settings;
- map<string, string> dev_info;
- list<string> key_list;
- shared_ptr<devices::HardwareDevice> device;
-
- DeviceManager& device_manager = session_.device_manager();
-
- // Re-select last used device if possible but only if it's not demo
- settings.beginGroup("Device");
- key_list.push_back("vendor");
- key_list.push_back("model");
- key_list.push_back("version");
- key_list.push_back("serial_num");
- key_list.push_back("connection_id");
-
- for (string key : key_list) {
- const QString k = QString::fromStdString(key);
- if (!settings.contains(k))
- continue;
-
- const string value = settings.value(k).toString().toStdString();
- if (!value.empty())
- dev_info.insert(std::make_pair(key, value));
- }
-
- if (dev_info.count("model") > 0)
- if (dev_info.at("model").find("Demo device") == std::string::npos)
- device = device_manager.find_device_from_info(dev_info);
-
- // When we can't find a device similar to the one we used last
- // time and there is at least one device aside from demo, use it
- if (!device) {
- for (shared_ptr<devices::HardwareDevice> dev : device_manager.devices()) {
- dev_info = device_manager.get_device_info(dev);
-
- if (dev_info.count("model") > 0)
- if (dev_info.at("model").find("Demo device") == std::string::npos) {
- device = dev;
- break;
- }
- }
- }
-
- select_device(device);
- update_device_list();
-
- settings.endGroup();
-}
-
-void MainBar::load_file(QString file_name,
- std::shared_ptr<sigrok::InputFormat> format,
- const std::map<std::string, Glib::VariantBase> &options)
-{
- DeviceManager& device_manager = session_.device_manager();
-
- const QString errorMessage(
- QString("Failed to load file %1").arg(file_name));
-
- try {
- if (format)
- session_.set_device(shared_ptr<devices::Device>(
- new devices::InputFile(
- device_manager.context(),
- file_name.toStdString(),
- format, options)));
- else
- session_.set_device(shared_ptr<devices::Device>(
- new devices::SessionFile(
- device_manager.context(),
- file_name.toStdString())));
- } catch (Error e) {
- show_session_error(tr("Failed to load ") + file_name, e.what());
- session_.set_default_device();
- update_device_list();
- return;
- }
-
- update_device_list();
-
- session_.start_capture([&, errorMessage](QString infoMessage) {
- session_error(errorMessage, infoMessage); });
-}
-
-void MainBar::load_init_file(const std::string &file_name,
- const std::string &format)
-{
- shared_ptr<InputFormat> input_format;
-
- DeviceManager& device_manager = session_.device_manager();
-
- if (!format.empty()) {
- const map<string, shared_ptr<InputFormat> > formats =
- device_manager.context()->input_formats();
- const auto iter = find_if(formats.begin(), formats.end(),
- [&](const pair<string, shared_ptr<InputFormat> > f) {
- return f.first == format; });
- if (iter == formats.end()) {
- cerr << "Unexpected input format: " << format << endl;
- return;
- }
-
- input_format = (*iter).second;
- }
-
- load_file(QString::fromStdString(file_name), input_format);
-}
-