Skip to content

Commit

Permalink
Removed: unneeded object member "username" and helper functions
Browse files Browse the repository at this point in the history
Added: Replace spaces in username with underscores
  • Loading branch information
lukitree committed Aug 9, 2015
1 parent 0c7d387 commit 4dd5f42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
19 changes: 12 additions & 7 deletions Client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Client::Client(QWidget *parent)
tcpSocket = new QTcpSocket(this);
promptConnect = new ConnectDialog(this);

username = "NoName";
credentialsSent = false;

ui.actionDisconnect->setDisabled(true);
Expand All @@ -27,11 +26,6 @@ Client::~Client()

}

void Client::setUserName(QString name)
{
this->username = name;
}

void Client::on_sendButton_clicked()
{
QString message = ui.messageEdit->text();
Expand Down Expand Up @@ -66,7 +60,7 @@ void Client::on_actionConnect_triggered()
{
QString hostname = promptConnect->hostnameEdit->text();
quint16 port = promptConnect->portEdit->text().toInt();
setUserName(promptConnect->usernameEdit->text());
promptConnect->usernameEdit->setText(replaceWhiteSpace(promptConnect->usernameEdit->text()));

QString status = tr("-> Connecting to %1 on port %2.").arg(hostname).arg(port);
new QListWidgetItem(status, ui.messageList);
Expand Down Expand Up @@ -175,6 +169,7 @@ void Client::sendCredentials()
out.setVersion(QDataStream::Qt_4_0);

QString command = "_USR_";
QString username = promptConnect->usernameEdit->text();
out << command;
out << username;
tcpSocket->write(block);
Expand Down Expand Up @@ -217,3 +212,13 @@ void Client::whisperOnClick(QListWidgetItem* user)
ui.messageEdit->setText(insert);
ui.messageEdit->setFocus();
}

QString Client::replaceWhiteSpace(QString text)
{
text = text.simplified();
text.replace(" ", "_");
text.replace("\t", "_");
text.replace("\n", "_");

return text;
}
3 changes: 1 addition & 2 deletions Client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ private slots:
private:
Ui::ClientClass ui;

QString username;
ConnectDialog *promptConnect;
QTcpSocket *tcpSocket;
quint16 blockSize;

bool credentialsSent;

void setUserName(QString name);
void sendUserCommand(QString command);
QString replaceWhiteSpace(QString text);
};

#endif // CLIENT_H

0 comments on commit 4dd5f42

Please sign in to comment.