3 #include "SessionManager.h"
4 #include "SessionManager.moc"
5 #include "SessionEditor.h"
6 #include "ActiveSession.h"
12 SessionManager::SessionManager(QWidget
*parent
) {
15 int sessions
= settings
.beginReadArray("sessions");
16 for(int i
= 0; i
< sessions
; i
++) {
17 settings
.setArrayIndex(i
);
18 Session
*session
= new Session();
19 session
->set_session_name(settings
.value("session-name").toString());
20 session
->set_executable_path(settings
.value("executable-path").toString());
21 session
->set_arguments(settings
.value("arguments").toString());
22 session
->set_port(settings
.value("port").toInt());
23 session_list
.append(session
);
27 layout
= new QVBoxLayout();
29 session_list_view
= new SessionListWidget();
30 session_list_view
->update_list(session_list
);
31 layout
->addWidget(session_list_view
);
33 if(sessions
) session_list_view
->setCurrentRow(0);
35 session_button_layout
= new QHBoxLayout();
37 new_session_button
= new QPushButton("&New session");
38 connect(new_session_button
, SIGNAL(pressed()), this, SLOT(new_session()));
39 session_button_layout
->addWidget(new_session_button
);
41 /*edit_session_button = new QPushButton("&Edit session");
42 connect(edit_session_button, SIGNAL(pressed()), this, SLOT(edit_current_session()));
43 session_button_layout->addWidget(edit_session_button);*/
45 launch_session_button
= new QPushButton("&Launch session");
46 connect(launch_session_button
, SIGNAL(pressed()), this, SLOT(launch_current_session()));
47 session_button_layout
->addWidget(launch_session_button
);
49 layout
->addLayout(session_button_layout
);
50 this->setLayout(layout
);
52 connect(session_list_view
, SIGNAL(itemDoubleClicked(QListWidgetItem
*)), this, SLOT(edit_session(QListWidgetItem
*)));
53 connect(session_list_view
, SIGNAL(new_request()), this, SLOT(new_session()));
54 connect(session_list_view
, SIGNAL(edit_request(QListWidgetItem
*)), this, SLOT(edit_session(QListWidgetItem
*)));
55 connect(session_list_view
, SIGNAL(delete_request(QListWidgetItem
*)), this, SLOT(delete_session(QListWidgetItem
*)));
58 SessionManager::~SessionManager() {
62 void SessionManager::save_sessions() {
64 settings
.beginWriteArray("sessions");
65 for(int i
= 0; i
< session_list
.size(); i
++) {
66 settings
.setArrayIndex(i
);
67 settings
.setValue("session-name", session_list
[i
]->get_session_name());
68 settings
.setValue("executable-path", session_list
[i
]->get_executable_path());
69 settings
.setValue("arguments", session_list
[i
]->get_arguments());
70 settings
.setValue("port", session_list
[i
]->get_port());
75 Session
*SessionManager::get_session_by_name(const QString
&name
) const {
76 for(int i
= 0; i
< session_list
.size(); i
++) {
77 if(session_list
[i
]->get_session_name() == name
) return session_list
[i
];
82 void SessionManager::new_session() {
83 SessionEditor
*se
= new SessionEditor(this, NULL
);
84 if(se
->exec() == QDialog::Accepted
) {
85 session_list
.append(se
->get_session());
86 session_list_view
->update_list(session_list
);
90 void SessionManager::launch_session(QListWidgetItem
*session_item
) {
91 if(session_item
== NULL
) return;
92 QString session_name
= session_item
->data(Qt::DisplayRole
).toString();
93 Session
*session
= get_session_by_name(session_name
);
95 ActiveSession
*as
= new ActiveSession(session
);
96 emit
new_tab_request(as
, session_name
);
97 connect(as
, SIGNAL(close_session(ActiveSession
*)), this, SLOT(close_active_session(ActiveSession
*)));
101 void SessionManager::edit_session(QListWidgetItem
*session_item
) {
102 QString session_name
= session_item
->data(Qt::DisplayRole
).toString();
103 Session
*session
= get_session_by_name(session_name
);
104 SessionEditor
*se
= new SessionEditor(this, session
);
106 session_list_view
->update_list(session_list
);
109 void SessionManager::delete_session(QListWidgetItem
*session_item
) {
110 if(session_item
== NULL
) return;
111 QString session_name
= session_item
->data(Qt::DisplayRole
).toString();
112 Session
*session
= get_session_by_name(session_name
);
113 if(session_list
.removeOne(session
)) session_list_view
->update_list(session_list
);
116 void SessionManager::close_active_session(ActiveSession
*session
) {
117 emit
remove_tab_request(session
);
121 } // namespace Aesalon