Skip to content

Commit

Permalink
v0037
Browse files Browse the repository at this point in the history
-now it is possible to pass IP address and port number of server-side
app to client app as command line arguments when launching (this will
make binaries usable, even if server-side application will eventually be
shut down)
-following options are supported:
{--help | -h} - lists all available options and default values
{--address | -a} SERVER_ADDRESS - specifies SERVER_ADDRESS as IP address
of machine where the server-side application is listening
{--port | -p} SERVER_PORT - specifies SERVER_PORT as number of port on
which the server-side application is listening
  • Loading branch information
zeko868 committed Mar 22, 2018
1 parent db367e7 commit c8dfd62
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
4 changes: 3 additions & 1 deletion LoginWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include <QMessageBox>


LoginWindow::LoginWindow(bool adminMode, QWidget *parent) :
LoginWindow::LoginWindow(bool adminMode, const char* const serverAddress, const short serverPort, QWidget *parent) :
QMainWindow(parent),
socket(new QTcpSocket()),
adminMode(adminMode), //value of adminMode as a parameter (that was sent from main() function) is set to adminMode attribute of LoginWindow (that's required because it will be forwarded next to instance of MainWindow class)
serverAddress(serverAddress),
serverPort(serverPort),
ui(new Ui::LoginWindow)
{
this->ui->setupUi(this);
Expand Down
6 changes: 3 additions & 3 deletions LoginWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LoginWindow : public QMainWindow
Q_OBJECT

public:
explicit LoginWindow(bool adminMode, QWidget *parent = 0);
explicit LoginWindow(bool adminMode, const char* const serverAddress, const short serverPort, QWidget *parent = 0);
~LoginWindow();

private slots:
Expand All @@ -30,8 +30,8 @@ private slots:
Ui::LoginWindow *ui;
QTcpSocket* socket;
bool adminMode;
const char* const serverAddress = "165.227.174.7";
const ushort serverPort = 1337;
const char* const serverAddress;
const ushort serverPort;
};

#endif // LOGINWINDOW_H
Binary file removed logo.ico
Binary file not shown.
33 changes: 32 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "LoginWindow.h"
#include <QApplication>
#include <QProcess>
#include <iostream>
#include <fstream>
#define LOCKFILE "lock.dat"

Expand Down Expand Up @@ -55,6 +56,36 @@ int main(int argc, char *argv[])
{
QApplication::addLibraryPath(".");
bool adminMode = isRunningAsAdministrator();
const char* serverAddress = "165.227.174.7";
short serverPort = 1337;
if (argc % 2 == 1) {
for (int i=1; i<argc; i+=2) {
const char* const key = argv[i];
const char* const value = argv[i+1];
if (strcmp(key, "-a")==0 || strcmp(key, "--address")==0) {
serverAddress = value;
}
else if (strcmp(key, "-p")==0 || strcmp(key, "--port")==0) {
serverPort = QString(value).toShort();
}
else {
std::cout << "Invalid option has been passed: " << key << std::endl;
return 0;
}
}
}
else {
const char* const key = argv[1];
if (argc == 2 && (strcmp(key, "-h")==0 || strcmp(key, "--help")==0)) {
std::cout << "Available options:" << std::endl
<< "\t{-a | --address} SERVER_ADDRESS - IP address of machine where the server-side application is listening (default: " << serverAddress << ")" << std::endl
<< "\t{-p | --port} SERVER_PORT - number of port on which the server-side application is listening (default: " << serverPort << ")" << std::endl;
}
else {
std::cout << "Arguments have been passed in invalid format! Launch program with -h or --help argument to list all available options" << std::endl;
}
return 0;
}

if (adminMode) {
std::fstream file;
Expand Down Expand Up @@ -101,7 +132,7 @@ int main(int argc, char *argv[])
short exitStatus;
do {
QApplication a(argc, argv);
LoginWindow w(adminMode); //we are sending information about having administrative privileges to constructor of first form which will be opened
LoginWindow w(adminMode, serverAddress, serverPort); //we are sending information about having administrative privileges to constructor of first form which will be opened
//w.setAttribute(Qt::WA_DeleteOnClose); //this will call destructors of all classes which were closed manually or which were closed by parent class (child class needs to have pointer to parent class forwarded in its constructor in that case)
w.show();
exitStatus = a.exec();
Expand Down

0 comments on commit c8dfd62

Please sign in to comment.