Example #1
0
void MainWindow::createCenter()
{
	userLoginButton = new QPushButton("userLogin",this);
	userLoginButton->setStatusTip(tr("login if your are the user"));
	registerButton = new QPushButton("Register",this);
	registerButton->setStatusTip(tr("register a new user!"));
	searchButton = new QPushButton(tr("search book"),this);
	searchButton->setStatusTip(tr("search books"));
	managerButton = new QPushButton(tr("manager"),this);
	managerButton->setStatusTip(tr("login as a manager"));
	exitButton = new QPushButton(tr("Exit"),this);
	exitButton->setStatusTip(tr("exit the applications"));
	MainWindowButton = new QPushButton("mainwindow",this);
	MainWindowButton->setVisible(false);
	MainWindowButton->setStatusTip(tr("return the welcome window"));

	QWidget *welcome = new QWidget(this);
	QLabel *img = new QLabel(welcome);
        img->setStyleSheet("border-image:url(:/imgs/1.jpg)");
	img->setStatusTip(tr("Welcome to the library"));
	toplayout = new QHBoxLayout;
	toplayout->addWidget(registerButton);
	toplayout->addWidget(userLoginButton);
	toplayout->addWidget(searchButton);
	toplayout->addWidget(managerButton);
	toplayout->addWidget(exitButton);
	welcomelayout = new QVBoxLayout(welcome);
	welcomelayout->addWidget(img);
	welcomelayout->addLayout(toplayout);
	welcome->setLayout(welcomelayout);

    	rig = new Register(this,mainmanager);
	manawidget = new ManagerWindow(this,mainmanager);
	user* tmpusr = NULL;
	searchwin = new SearchWindow(this,mainmanager,tmpusr,false,false);

	swidget = new QStackedWidget;
	swidget->addWidget(welcome);
	swidget->addWidget(rig);
	swidget->addWidget(manawidget);
	swidget->addWidget(searchwin);
	connect(registerButton,SIGNAL(clicked()),SLOT(regis()));
	connect(userLoginButton,SIGNAL(clicked()),SLOT(ulogin()));
	connect(MainWindowButton,SIGNAL(clicked()),SLOT(rmain()));
	connect(managerButton,SIGNAL(clicked()),SLOT(managerlog()));
	connect(searchButton,SIGNAL(clicked()),SLOT(search()));
	connect(rig,SIGNAL(isexit()),this,SLOT(rmain()));
	QWidget *mainwidget = new QWidget(this);
	buttomlayout = new QHBoxLayout;
	vlayout = new QVBoxLayout;
	buttomlayout->addStretch();
	buttomlayout->addWidget(MainWindowButton);
	vlayout->addWidget(swidget);
	vlayout->addLayout(buttomlayout);
	mainwidget->setLayout(vlayout);
	connect(exitButton,SIGNAL(clicked()),this,SLOT(whenexit()));
	setCentralWidget(mainwidget);
}
Example #2
0
void startClient(int sockFd)
{
	/**
		Start the client side operations.
	**/
	//printf("In startClient.\n");
	char sendMsg[MAXLINE], recvMsg[MAXLINE];
	int n, retVal;
	int logout = 0, retry = 0;
	
	while(1)
	{
		//printf("In startClient\n");
		bzero(&recvMsg, MAXLINE);
		bzero(&sendMsg, MAXLINE);

		// message from the server
		if((n = read(sockFd, recvMsg, MAXLINE)) < 0)
			printError('r');
		if(n == 0)
			printError('t');
		printf("\nServer : \n%s\n", recvMsg);
		
		//printf("sending response to server\n");
		printf("\nClient : \n");
		
		// sending response to server
		fgets(sendMsg, MAXLINE, stdin);
		if((n = write(sockFd, sendMsg, MAXLINE)) < 0)
			printError('w');
		if(n == 0)
			printError('t');
		
		// register
		if(strcmp("register", sendMsg) == EQUAL)
		{
			regis(sockFd);
			//printf("returned to start client\n");
			logout = logIn(sockFd);
			if(logout)
			{
				fputs("\nWrite ./client 127.0.0.1 9876 to reconnect.\n\n", stdout);
				return;
			}
		}
		else
			// log in
			if(strcmp("log in", sendMsg) == EQUAL || strcmp("login", sendMsg) == EQUAL)
			{
				logout = logIn(sockFd);
				if(logout == 1)
				{
					fputs("\nWrite ./client 127.0.0.1 9876 to reconnect.\n\n", stdout);
					return;
				}
			}
		
		if(logout == -1)
		{
			fputs("Something went wrong.\n", stdout);
		}
	}
}