Continued ripping up the source.
[aesalon.git] / gui / src / ActiveSession.cpp
blob5e0b785fdbadd1bf53007da2c0fe6eb2a200346c
1 #include <sys/types.h>
2 #include <unistd.h>
4 #include <QSettings>
5 #include <QShortcut>
7 #include "ActiveSession.h"
8 #include "ActiveSession.moc"
10 namespace Aesalon {
11 namespace GUI {
13 ActiveSession::ActiveSession(Session *session, QWidget *parent) : QTabWidget(parent), session(session), status(INITIALIZING) {
14 this->setTabPosition(West);
15 overview = new ActiveSessionOverview(session);
16 this->addTab(overview, tr("&Overview"));
18 status = WAITING_FOR_CONNECTION;
19 connect(this, SIGNAL(status_changed(QString)), overview, SLOT(update_status(QString)));
20 emit status_changed(get_status_as_string());
22 QShortcut *close_tab = new QShortcut(Qt::Key_W + Qt::CTRL, this);
23 connect(close_tab, SIGNAL(activated()), this, SLOT(terminate_session()));
26 ActiveSession::~ActiveSession() {
29 void ActiveSession::execute() {
30 QSettings settings;
31 /* NOTE: reimplement this function */\
32 #if 0
33 al.add_argument(settings.value("xterm-path").toString().toStdString());
34 al.add_argument("-e");
35 al.add_argument(settings.value("aesalon-path").toString().toStdString());
36 al.add_argument("--wait");
37 al.add_argument("--use-port");
38 al.add_argument(QString().setNum(session->get_port()).toStdString());
39 al.add_argument(session->get_executable_path().toStdString());
40 /* TODO: handle arguments in here . . . */
41 pid_t pid = fork();
42 if(pid == -1) return;
43 else if(pid == 0) {
44 execv(al.get_argument(0).c_str(), al.get_as_argv());
45 exit(1);
47 #endif
48 connect_to("localhost", session->get_port());
51 void ActiveSession::connect_to(QString host, int port) {
52 socket = new ActiveSessionSocket(host, port);
53 connect(socket, SIGNAL(connected()), this, SLOT(socket_connection()));
54 connect(socket, SIGNAL(disconnected()), this, SLOT(socket_disconnection()));
57 void ActiveSession::socket_connection() {
58 set_status(CONNECTED);
61 void ActiveSession::socket_disconnection() {
62 set_status(CONNECTION_CLOSED);
65 QString ActiveSession::get_status_as_string() const {
66 switch(get_status()) {
67 case INITIALIZING:
68 return tr("Initializing . . .");
69 case WAITING_FOR_CONNECTION:
70 return tr("Connecting . . .");
71 case CONNECTED:
72 return tr("Running . . .");
73 case CONNECTION_CLOSED:
74 return tr("Execution completed.");
76 qDebug("Invalid ActiveSession status!");
77 return tr("Invalid ActiveSession status!");
80 } // namespace GUI
81 } // namespace Aesalon