+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_focus_changed()
+{
+ shared_ptr<view::View> view;
+ bool title_set = false;
+
+ view = get_active_view();
+
+ for (shared_ptr<Session> session : sessions_) {
+ if (!session->has_view(view))
+ continue;
+
+ setWindowTitle(session->name() + " - " + WindowTitle);
+ title_set = true;
+ }
+
+ if (!title_set)
+ setWindowTitle(WindowTitle);
+}
+
+void MainWindow::on_new_session()
+{
+ add_session();
+}
+
+void MainWindow::on_session_name_changed()
+{
+ // Update the corresponding dock widget's name(s)
+ Session *session = qobject_cast<Session*>(QObject::sender());
+ assert(session);
+
+ for (shared_ptr<view::View> view : session->views()) {
+ // Get the dock that contains the view
+ for (auto entry : view_docks_)
+ if (entry.second == view) {
+ entry.first->setObjectName(session->name());
+ entry.first->setWindowTitle(session->name());
+ }
+ }
+
+ // Refresh window title if the affected session has focus
+ on_focus_changed();
+}
+
+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_view_close_clicked()
+{
+ // Find the dock widget that contains the close button that was clicked
+ QObject *w = QObject::sender();
+ QDockWidget *dock = 0;
+
+ while (w) {
+ dock = qobject_cast<QDockWidget*>(w);
+ if (dock)
+ break;
+ w = w->parent();
+ }
+
+ // Get the view contained in the dock widget
+ shared_ptr<view::View> view;
+
+ for (auto entry : view_docks_)
+ if (entry.first.get() == dock)
+ view = entry.second;
+
+ // Deregister the view
+ for (shared_ptr<Session> session : sessions_) {
+ if (!session->has_view(view))
+ continue;
+
+ // Also destroy the entire session if its main view is closing
+ if (view == session->main_view()) {
+ remove_session(session);
+ break;
+ } else
+ session->deregister_view(view);
+ }
+}
+