Began removal of platform/. The Monitor:: namespace is completely converted.
[aesalon.git] / src / gui / SessionEditor.cpp
blob7b1ccf5f2ccf4228b4247710064e1f562fad56cd
1 #include <stdlib.h>
2 #include "SessionEditor.h"
3 #include "SessionEditor.moc"
5 namespace Aesalon {
6 namespace GUI {
8 QString SessionEditor::last_directory = getenv("HOME");
10 SessionEditor::SessionEditor(QWidget *parent, Session *session) : QDialog(parent), session(session) {
11 if(this->session == NULL) {
12 this->session = new Session();
14 create_widgets();
15 this->setModal(true);
16 QSizePolicy expanding;
17 expanding.setHorizontalPolicy(QSizePolicy::Expanding);
18 expanding.setVerticalPolicy(QSizePolicy::Expanding);
19 this->setSizePolicy(expanding);
20 this->setMinimumSize(600, 100);
21 this->setWindowTitle(tr("Editing session"));
24 void SessionEditor::create_widgets() {
25 layout = new QVBoxLayout();
27 form_layout = new QFormLayout();
29 session_name = new QLineEdit(session->get_session_name());
30 form_layout->addRow(tr("Session name:"), session_name);
32 session_type_layout = new QHBoxLayout();
33 session_type_group = new QButtonGroup();
34 session_type_group->setExclusive(true);
35 launch_session_type = new QRadioButton(tr("&Launch local program"));
36 connect_session_type = new QRadioButton(tr("&Connect to remote monitor"));
38 if(session->get_session_type() == Session::LAUNCH_SESSION) launch_session_type->setChecked(true);
39 else connect_session_type->setChecked(true);
41 session_type_group->addButton(launch_session_type);
42 session_type_group->addButton(connect_session_type);
43 connect(session_type_group, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(session_type_changed(QAbstractButton*)));
45 session_type_layout->addWidget(launch_session_type);
46 session_type_layout->addWidget(connect_session_type);
47 form_layout->addRow(tr("Session type:"), session_type_layout);
49 executable_path_layout = new QHBoxLayout();
50 executable_path = new QLineEdit(session->get_executable_path());
51 executable_path_layout->addWidget(executable_path);
52 file_select_dialog = new QPushButton(tr(". . ."));
53 connect(file_select_dialog, SIGNAL(pressed()), this, SLOT(show_file_select_dialog()));
54 executable_path_layout->addWidget(file_select_dialog);
55 executable_path_label = new QLabel(tr("Executable path:"));
56 form_layout->addRow(executable_path_label, executable_path_layout);
58 arguments = new QLineEdit(session->get_arguments());
59 arguments_label = new QLabel(tr("Arguments:"));
60 form_layout->addRow(arguments_label, arguments);
62 port = new QSpinBox();
63 port->setMinimum(1025);
64 port->setMaximum(65535);
65 if(session->get_port()) port->setValue(session->get_port());
66 else port->setValue(DEFAULT_PORT);
67 form_layout->addRow(tr("Port:"), port);
69 layout->addLayout(form_layout);
71 button_box = new QDialogButtonBox();
72 button_box->addButton(QDialogButtonBox::Save);
73 button_box->addButton(QDialogButtonBox::Cancel);
75 connect(button_box, SIGNAL(accepted()), this, SLOT(accept()));
76 connect(button_box, SIGNAL(rejected()), this, SLOT(reject()));
78 button_box->setCenterButtons(false);
80 layout->addWidget(button_box);
82 file_dialog = new QFileDialog();
83 file_dialog->setDirectory(last_directory);
84 connect(file_dialog, SIGNAL(fileSelected(QString)), this, SLOT(change_selected_file(QString)));
86 this->setLayout(layout);
88 this->change_session_type(session->get_session_type());
91 void SessionEditor::accept() {
92 if(session_name->text().length() == 0) return;
93 session->set_session_name(session_name->text());
94 session->set_executable_path(executable_path->text());
95 session->set_arguments(arguments->text());
96 session->set_port(port->value());
97 if(launch_session_type->isChecked()) session->set_session_type(Session::LAUNCH_SESSION);
98 else session->set_session_type(Session::CONNECT_SESSION);
99 QDialog::accept();
102 void SessionEditor::show_file_select_dialog() {
103 file_dialog->exec();
106 void SessionEditor::change_selected_file(QString new_filename) {
107 executable_path->setText(new_filename);
108 last_directory = new_filename.left(new_filename.lastIndexOf('/'));
109 file_dialog->setDirectory(last_directory);
112 void SessionEditor::change_session_type(Session::session_type_e new_type) {
113 if(new_type == Session::LAUNCH_SESSION) {
114 executable_path_label->setText(tr("Executable path:"));
115 file_select_dialog->show();
116 arguments->show();
117 arguments_label->show();
119 else {
120 executable_path_label->setText(tr("Host:"));
121 file_select_dialog->hide();
122 arguments->hide();
123 arguments_label->hide();
127 } // namespace GUI
128 } // namespace Aesalon