# HG changeset patch # User John Tsiombikas # Date 1387771765 -7200 # Node ID 2e57c80653afb3dedb55354dfe52009e9c6f89c4 # Parent ad12da657c0021af1a79fd7739ed1806aedd579a more stuff diff -r ad12da657c00 -r 2e57c80653af src/main.cc --- a/src/main.cc Sun Dec 22 04:09:23 2013 +0200 +++ b/src/main.cc Mon Dec 23 06:09:25 2013 +0200 @@ -18,17 +18,19 @@ QTcpSocket *socket; static std::string srv_passwd; -static MainWindow win_main; +static MainWindow *win_main; int main(int argc, char *argv[]) { srand(time(0)); QApplication app(argc, argv); - win_main.show(); + + win_main = new MainWindow; + win_main->show(); set_log_file(stdout); - set_log_callback(status_log, win_main.statusBar()); + set_log_callback(status_log, win_main->statusBar()); return app.exec(); } @@ -59,7 +61,7 @@ log_message("received connection request from: %s\n", client_addr.toString().toUtf8().data()); } -void connect(const char *host, int port, const char *passwd) +void start_client(const char *host, int port, const char *passwd) { log_message("connecting to host: %s port: %d\n", host, port); } diff -r ad12da657c00 -r 2e57c80653af src/mainwin.cc --- a/src/mainwin.cc Sun Dec 22 04:09:23 2013 +0200 +++ b/src/mainwin.cc Mon Dec 23 06:09:25 2013 +0200 @@ -1,8 +1,10 @@ +#include #include "mainwin.h" #include "ui_mainwin.h" #include "ui_server.h" #include "rollwidget.h" #include "main.h" +#include "logger.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -17,8 +19,10 @@ connect(ui->bn_clear, SIGNAL(clicked()), this, SLOT(clear_dice())); connect(ui->bn_roll_all, SIGNAL(clicked()), this, SLOT(roll_all())); - //connect(ui->action_connect, SIGNAL(triggered()), this, SLOT(start_client())); - //connect(ui->action_start_server, SIGNAL(triggered()), this, SLOT(start_server())); + connect(ui->action_connect, SIGNAL(triggered()), this, SLOT(start_client())); + connect(ui->action_start_server, SIGNAL(triggered()), this, SLOT(start_server())); + + connect(ui->action_quit, SIGNAL(triggered()), this, SLOT(close())); } MainWindow::~MainWindow() @@ -64,10 +68,29 @@ void MainWindow::start_client() { - Ui::ServerDialog *dlg = new Ui::ServerDialog; - dlg->setupUi(0); } void MainWindow::start_server() { + QDialog *dlg_server = new QDialog(0, 0); + Ui_ServerDialog ui; + ui.setupUi(dlg_server); + + if(dlg_server->exec()) { + bool valid; + int port = ui.tx_port->text().toInt(&valid); + + if(!valid) { + log_message("invalid port: %s\n", ui.tx_port->text().toUtf8().data()); + return; + } + + std::string passwd = ui.tx_passwd->text().toUtf8().data(); + if(passwd.empty()) { + log_message("failed to start server: empty password field\n"); + return; + } + + ::start_server(port, passwd.c_str()); + } }