{
fprintf(stdout,
"Usage:\n"
- " %s [OPTION…] [FILE] — %s\n"
+ " %s [OPTION…] — %s\n"
"\n"
"Help Options:\n"
" -h, -?, --help Show help option\n"
"Application Options:\n"
" -V, --version Show release version\n"
" -l, --loglevel Set libsigrok/libsigrokdecode loglevel\n"
+ " -i, --input-file Load input from file\n"
+ " -I, --input-format Input format\n"
"\n", PV_BIN_NAME, PV_DESCRIPTION);
}
{
int ret = 0;
std::shared_ptr<sigrok::Context> context;
- const char *open_file = NULL;
+ std::string open_file, open_file_format;
Application a(argc, argv);
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"loglevel", required_argument, 0, 'l'},
+ {"input-file", required_argument, 0, 'i'},
+ {"input-format", required_argument, 0, 'I'},
{0, 0, 0, 0}
};
const int c = getopt_long(argc, argv,
- "l:Vh?", long_options, nullptr);
+ "l:Vh?i:I:", long_options, nullptr);
if (c == -1)
break;
break;
}
+
+ case 'i':
+ open_file = optarg;
+ break;
+
+ case 'I':
+ open_file_format = optarg;
+ break;
}
}
- if (argc - optind > 1) {
- fprintf(stderr, "Only one file can be openened.\n");
+ if (argc != optind) {
+ fprintf(stderr, "Unexpected argument: %s\n", argv[optind]);
return 1;
- } else if (argc - optind == 1)
- open_file = argv[argc - 1];
+ }
// Initialise libsigrok
context = sigrok::Context::create();
pv::DeviceManager device_manager(context);
// Initialise the main window
- pv::MainWindow w(device_manager, open_file);
+ pv::MainWindow w(device_manager,
+ open_file, open_file_format);
w.show();
#ifdef ENABLE_SIGNALS
#include <glib.h>
#include <libsigrokcxx/libsigrokcxx.hpp>
+using std::cerr;
+using std::endl;
using std::list;
using std::map;
+using std::pair;
using std::shared_ptr;
using std::string;
using std::vector;
const char *MainWindow::SettingSaveDirectory = "MainWindow/SaveDirectory";
MainWindow::MainWindow(DeviceManager &device_manager,
- const char *open_file_name,
+ string open_file_name, string open_file_format,
QWidget *parent) :
QMainWindow(parent),
device_manager_(device_manager),
{
setup_ui();
restore_ui_settings();
- if (open_file_name) {
- const QString s(QString::fromUtf8(open_file_name));
- QMetaObject::invokeMethod(this, "load_file",
- Qt::QueuedConnection,
- Q_ARG(QString, s));
- }
+ if (open_file_name.empty())
+ select_init_device();
+ else
+ load_init_file(open_file_name, open_file_format);
}
QAction* MainWindow::action_open() const
SLOT(device_selected()));
}
+void MainWindow::select_init_device() {
+ QSettings settings;
+ map<string, string> dev_info;
+ list<string> key_list;
+
+ // Re-select last used device if possible.
+ 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));
+ }
+
+ const shared_ptr<devices::HardwareDevice> device =
+ device_manager_.find_device_from_info(dev_info);
+ select_device(device);
+ update_device_list();
+
+ settings.endGroup();
+}
+
+void MainWindow::load_init_file(const std::string &file_name,
+ const std::string &format) {
+ shared_ptr<InputFormat> input_format;
+
+ 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);
+}
+
+
void MainWindow::save_ui_settings()
{
QSettings settings;
{
QSettings settings;
- map<string, string> dev_info;
- list<string> key_list;
-
settings.beginGroup("MainWindow");
if (settings.contains("geometry")) {
resize(1000, 720);
settings.endGroup();
-
- // Re-select last used device if possible.
- 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));
- }
-
- const shared_ptr<devices::HardwareDevice> device =
- device_manager_.find_device_from_info(dev_info);
- select_device(device);
- update_device_list();
-
- settings.endGroup();
}
void MainWindow::session_error(
main_bar_->update_device_list();
}
-void MainWindow::closeEvent(QCloseEvent *event)
-{
- save_ui_settings();
- event->accept();
-}
-
-void MainWindow::keyReleaseEvent(QKeyEvent *event)
-{
- if (event->key() == Qt::Key_Alt) {
- menuBar()->setHidden(!menuBar()->isHidden());
- menuBar()->setFocus();
- }
- QMainWindow::keyReleaseEvent(event);
-}
-
void MainWindow::load_file(QString file_name,
std::shared_ptr<sigrok::InputFormat> format,
const std::map<std::string, Glib::VariantBase> &options)
session_error(errorMessage, infoMessage); });
}
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+ save_ui_settings();
+ event->accept();
+}
+
+void MainWindow::keyReleaseEvent(QKeyEvent *event)
+{
+ if (event->key() == Qt::Key_Alt) {
+ menuBar()->setHidden(!menuBar()->isHidden());
+ menuBar()->setFocus();
+ }
+ QMainWindow::keyReleaseEvent(event);
+}
+
void MainWindow::show_session_error(
const QString text, const QString info_text)
{
public:
explicit MainWindow(DeviceManager &device_manager,
- const char *open_file_name = nullptr,
+ std::string open_file_name = std::string(),
+ std::string open_file_format = std::string(),
QWidget *parent = 0);
QAction* action_open() const;
private:
void setup_ui();
+ void select_init_device();
+
+ void load_init_file(const std::string &file_name,
+ const std::string &format);
+
void save_ui_settings();
void restore_ui_settings();
*/
void update_device_list();
+ void load_file(QString file_name,
+ std::shared_ptr<sigrok::InputFormat> format = nullptr,
+ const std::map<std::string, Glib::VariantBase> &options =
+ std::map<std::string, Glib::VariantBase>());
+
private:
void closeEvent(QCloseEvent *event);
void keyReleaseEvent(QKeyEvent *event);
private Q_SLOTS:
- void load_file(QString file_name,
- std::shared_ptr<sigrok::InputFormat> format = nullptr,
- const std::map<std::string, Glib::VariantBase> &options =
- std::map<std::string, Glib::VariantBase>());
-
void show_session_error(
const QString text, const QString info_text);