#include "devicemanager.hpp"
#include "util.hpp"
+#include "devices/hardwaredevice.hpp"
#include "dialogs/about.hpp"
#include "toolbars/mainbar.hpp"
#include "view/view.hpp"
#include <stdarg.h>
#include <libsigrokcxx/libsigrokcxx.hpp>
+using std::dynamic_pointer_cast;
using std::list;
using std::make_shared;
using std::map;
QWidget *parent) :
QMainWindow(parent),
device_manager_(device_manager),
- session_(device_manager),
- open_file_name_(open_file_name),
- open_file_format_(open_file_format),
action_view_sticky_scrolling_(new QAction(this)),
action_view_coloured_bg_(new QAction(this)),
action_about_(new QAction(this))
setup_ui();
restore_ui_settings();
+
+ if (!open_file_name.empty()) {
+ shared_ptr<Session> session = add_session();
+ session->main_bar()->load_init_file(open_file_name, open_file_format);
+ }
+
+ // Add empty default session if there aren't any sessions
+ if (sessions_.size() == 0) {
+ shared_ptr<Session> session = add_session();
+
+ map<string, string> dev_info;
+ shared_ptr<devices::HardwareDevice> other_device, demo_device;
+
+ // Use any available device that's not demo
+ for (shared_ptr<devices::HardwareDevice> dev : device_manager_.devices()) {
+ if (dev->hardware_device()->driver()->name() == "demo") {
+ demo_device = dev;
+ } else {
+ other_device = dev;
+ }
+ }
+
+ // ...and if there isn't any, just use demo then
+ session->main_bar()->select_device(other_device ?
+ other_device : demo_device);
+ }
}
MainWindow::~MainWindow()
dock->setWidget(0);
const std::shared_ptr<pv::view::View> view = entry.second;
- session_.deregister_view(view);
+
+ for (shared_ptr<Session> session : sessions_)
+ if (session->has_view(view))
+ session->deregister_view(view);
}
}
if (type == view::TraceView) {
connect(&session, SIGNAL(trigger_event(util::Timestamp)), v.get(),
SLOT(trigger_event(util::Timestamp)));
- connect(v.get(), SIGNAL(sticky_scrolling_changed(bool)), this,
- SLOT(sticky_scrolling_changed(bool)));
- connect(v.get(), SIGNAL(always_zoom_to_fit_changed(bool)), this,
- SLOT(always_zoom_to_fit_changed(bool)));
v->enable_sticky_scrolling(action_view_sticky_scrolling_->isChecked());
v->enable_coloured_bg(action_view_coloured_bg_->isChecked());
shared_ptr<MainBar> main_bar = session.main_bar();
if (!main_bar) {
- main_bar = make_shared<MainBar>(session_, *this,
- open_file_name_, open_file_format_);
+ main_bar = make_shared<MainBar>(session, *this);
dock_main->addToolBar(main_bar.get());
session.set_main_bar(main_bar);
- open_file_name_.clear();
- open_file_format_.clear();
+ connect(main_bar.get(), SIGNAL(new_session()),
+ this, SLOT(on_new_session()));
+ connect(main_bar.get(), SIGNAL(new_view(Session*)),
+ this, SLOT(on_new_view(Session*)));
}
main_bar->action_view_show_cursors()->setChecked(v->cursors_shown());
+
+ connect(v.get(), SIGNAL(always_zoom_to_fit_changed(bool)),
+ main_bar.get(), SLOT(on_always_zoom_to_fit_changed(bool)));
}
}
return v;
}
+shared_ptr<Session> MainWindow::add_session()
+{
+ int id = sessions_.size();
+ QString name = tr("Untitled-%1").arg(id + 1);
+
+ shared_ptr<Session> session = make_shared<Session>(device_manager_, name);
+
+ connect(session.get(), SIGNAL(add_view(const QString&, view::ViewType, Session*)),
+ this, SLOT(on_add_view(const QString&, view::ViewType, Session*)));
+
+ sessions_.push_back(session);
+
+ shared_ptr<view::View> main_view =
+ add_view(name, pv::view::TraceView, *session);
+
+ return session;
+}
+
void MainWindow::setup_ui()
{
setObjectName(QString::fromUtf8("MainWindow"));
action_about_->setObjectName(QString::fromUtf8("actionAbout"));
action_about_->setText(tr("&About..."));
- // Set up the initial view
- shared_ptr<view::View> main_view =
- add_view(tr("Untitled"), pv::view::TraceView, session_);
+ setDockNestingEnabled(true);
// Set the title
setWindowTitle(tr("PulseView"));
void MainWindow::save_ui_settings()
{
QSettings settings;
-
- map<string, string> dev_info;
- list<string> key_list;
+ int id = 0;
settings.beginGroup("MainWindow");
settings.setValue("state", saveState());
settings.setValue("geometry", saveGeometry());
settings.endGroup();
- if (session_.device()) {
- 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");
-
- dev_info = device_manager_.get_device_info(
- session_.device());
-
- for (string key : key_list) {
- if (dev_info.count(key))
- settings.setValue(QString::fromUtf8(key.c_str()),
- QString::fromUtf8(dev_info.at(key).c_str()));
- else
- settings.remove(QString::fromUtf8(key.c_str()));
+ for (shared_ptr<Session> session : sessions_) {
+ // Ignore sessions using the demo device
+ if (session->device()) {
+ shared_ptr<devices::HardwareDevice> device =
+ dynamic_pointer_cast< devices::HardwareDevice >
+ (session->device());
+
+ if (device &&
+ device->hardware_device()->driver()->name() == "demo")
+ continue;
}
+ settings.beginGroup("Session" + QString::number(id++));
+ settings.remove(""); // Remove all keys in this group
+ session->save_settings(settings);
settings.endGroup();
}
+
+ settings.setValue("sessions", id);
}
void MainWindow::restore_ui_settings()
{
QSettings settings;
+ int i, session_count;
settings.beginGroup("MainWindow");
resize(1000, 720);
settings.endGroup();
+
+ session_count = settings.value("sessions", 0).toInt();
+
+ for (i = 0; i < session_count; i++) {
+ settings.beginGroup("Session" + QString::number(i));
+ shared_ptr<Session> session = add_session();
+ session->restore_settings(settings);
+ settings.endGroup();
+ }
}
void MainWindow::closeEvent(QCloseEvent *event)
return false;
}
+void MainWindow::on_add_view(const QString &title, view::ViewType type,
+ Session *session)
+{
+ // We get a pointer and need a reference
+ for (std::shared_ptr<Session> s : sessions_)
+ if (s.get() == session)
+ add_view(title, type, *s);
+}
+
+void MainWindow::on_new_session()
+{
+ add_session();
+}
+
+void MainWindow::on_new_view(Session *session)
+{
+ // We get a pointer and need a reference
+ for (std::shared_ptr<Session> s : sessions_)
+ if (s.get() == session)
+ add_view(session->name(), pv::view::TraceView, *s);
+}
+
void MainWindow::on_actionViewStickyScrolling_triggered()
{
shared_ptr<pv::view::View> view = get_active_view();