qnetdice

changeset 3:2e57c80653af

more stuff
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 23 Dec 2013 06:09:25 +0200
parents ad12da657c00
children 7d28bef3fbca
files src/main.cc src/mainwin.cc
diffstat 2 files changed, 33 insertions(+), 8 deletions(-) [+]
line diff
     1.1 --- a/src/main.cc	Sun Dec 22 04:09:23 2013 +0200
     1.2 +++ b/src/main.cc	Mon Dec 23 06:09:25 2013 +0200
     1.3 @@ -18,17 +18,19 @@
     1.4  QTcpSocket *socket;
     1.5  
     1.6  static std::string srv_passwd;
     1.7 -static MainWindow win_main;
     1.8 +static MainWindow *win_main;
     1.9  
    1.10  int main(int argc, char *argv[])
    1.11  {
    1.12  	srand(time(0));
    1.13  
    1.14  	QApplication app(argc, argv);
    1.15 -	win_main.show();
    1.16 +
    1.17 +	win_main = new MainWindow;
    1.18 +	win_main->show();
    1.19  
    1.20  	set_log_file(stdout);
    1.21 -	set_log_callback(status_log, win_main.statusBar());
    1.22 +	set_log_callback(status_log, win_main->statusBar());
    1.23  
    1.24  	return app.exec();
    1.25  }
    1.26 @@ -59,7 +61,7 @@
    1.27  	log_message("received connection request from: %s\n", client_addr.toString().toUtf8().data());
    1.28  }
    1.29  
    1.30 -void connect(const char *host, int port, const char *passwd)
    1.31 +void start_client(const char *host, int port, const char *passwd)
    1.32  {
    1.33  	log_message("connecting to host: %s port: %d\n", host, port);
    1.34  }
     2.1 --- a/src/mainwin.cc	Sun Dec 22 04:09:23 2013 +0200
     2.2 +++ b/src/mainwin.cc	Mon Dec 23 06:09:25 2013 +0200
     2.3 @@ -1,8 +1,10 @@
     2.4 +#include <QDialog>
     2.5  #include "mainwin.h"
     2.6  #include "ui_mainwin.h"
     2.7  #include "ui_server.h"
     2.8  #include "rollwidget.h"
     2.9  #include "main.h"
    2.10 +#include "logger.h"
    2.11  
    2.12  MainWindow::MainWindow(QWidget *parent)
    2.13  	: QMainWindow(parent),
    2.14 @@ -17,8 +19,10 @@
    2.15  	connect(ui->bn_clear, SIGNAL(clicked()), this, SLOT(clear_dice()));
    2.16  	connect(ui->bn_roll_all, SIGNAL(clicked()), this, SLOT(roll_all()));
    2.17  
    2.18 -	//connect(ui->action_connect, SIGNAL(triggered()), this, SLOT(start_client()));
    2.19 -	//connect(ui->action_start_server, SIGNAL(triggered()), this, SLOT(start_server()));
    2.20 +	connect(ui->action_connect, SIGNAL(triggered()), this, SLOT(start_client()));
    2.21 +	connect(ui->action_start_server, SIGNAL(triggered()), this, SLOT(start_server()));
    2.22 +
    2.23 +	connect(ui->action_quit, SIGNAL(triggered()), this, SLOT(close()));
    2.24  }
    2.25  
    2.26  MainWindow::~MainWindow()
    2.27 @@ -64,10 +68,29 @@
    2.28  
    2.29  void MainWindow::start_client()
    2.30  {
    2.31 -	Ui::ServerDialog *dlg = new Ui::ServerDialog;
    2.32 -	dlg->setupUi(0);
    2.33  }
    2.34  
    2.35  void MainWindow::start_server()
    2.36  {
    2.37 +	QDialog *dlg_server = new QDialog(0, 0);
    2.38 +	Ui_ServerDialog ui;
    2.39 +	ui.setupUi(dlg_server);
    2.40 +
    2.41 +	if(dlg_server->exec()) {
    2.42 +		bool valid;
    2.43 +		int port = ui.tx_port->text().toInt(&valid);
    2.44 +
    2.45 +		if(!valid) {
    2.46 +			log_message("invalid port: %s\n", ui.tx_port->text().toUtf8().data());
    2.47 +			return;
    2.48 +		}
    2.49 +
    2.50 +		std::string passwd = ui.tx_passwd->text().toUtf8().data();
    2.51 +		if(passwd.empty()) {
    2.52 +			log_message("failed to start server: empty password field\n");
    2.53 +			return;
    2.54 +		}
    2.55 +
    2.56 +		::start_server(port, passwd.c_str());
    2.57 +	}
    2.58  }