Skip to content

Instantly share code, notes, and snippets.

View .cpp
void Server::on_client_fileSend(QString uname,QString filename,QByteArray dataOfFile){
ClientThread* client = (ClientThread*)sender();
QString currentTime = QTime::currentTime().toString("H:mm A/");
QString command = "/fileAll:"+currentTime + uname + " : " + filename + "\n";
QString filePath;
//Si no esta la carpeta creada, la crea.
if(!QDir("Documentos_Servidor").exists()){
qDebug() << "No esta creada la carpeta";
View .cpp
void Server::sendDataFileToAll(QString text,QByteArray dataOfFile,ClientThread* except){
QByteArray block;
QDataStream out(&block,QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_8);
out << (quint32)0 << text;
block.append(dataOfFile);
out.device()->seek(0);
out << (quint32)(block.size() - sizeof(quint32));
View .cpp
void Dialog::on_pushButton_ChooseFile_clicked()
{
//configurar el directorio de inicio a la ruta de inicio del usuario
QString homePath = QDir::homePath();
//Abre el dialogo y escoge el archivo. Obtenemos el path del archivo.
QString filePath = QFileDialog::getOpenFileName(this,tr("Open a file"),
homePath,tr("All files (*.*)"),NULL,QFileDialog::DontResolveSymlinks);
//Se obtiene el nombre del archivo
QString filename = filePath.section("/",-1);
View .cpp
//match con la expresión de chat privado
match = regex_private.match(data);
if(match.hasMatch()){
QString senderName = match.captured(2);
QString time = match.captured(1);
QString text = match.captured(3);
//Si la ventana ya esta abierta solo agrega
if(!privateChatList.contains(senderName)){
privateChatList[senderName] = new PrivateDialog(this->username,senderName,this);
connect(privateChatList[senderName],SIGNAL(finished(int)),this,SLOT(privateFinished(int)));
View .cpp
match = regex_text.match(data);
if(match.hasMatch()){
//update chat display
ui->textEdit_ChatDisplay->append(tr("<b>%1 <font color = \"LightGrey\">[%2]</font>: </b> %3")
.arg(match.captured(2),match.captured(1),match.captured(3)));
}
View .cpp
void Server::sendTextToOne(QString text,ClientThread* target){
QByteArray block;
QDataStream out(&block,QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_8);
out << (quint32)0 << text;
out.device()->seek(0);
out << (quint32)(block.size() - sizeof(quint32));
qDebug() << "block.size() = " << block.size();
View .cpp
void Server::on_client_privateTextSend(QString uname,QString receiverName,QString text){
QString currentTime = QTime::currentTime().toString("H:mm A/");
QString messagePm = "/pm:"+currentTime+uname+" : "+text+"\n";
foreach(ClientThread* client,clientThreadList){
if(client->getUsername() == receiverName){
sendTextToOne(messagePm,client);
return;
}
}
}
View .cpp
void Server::on_client_textSend(QString uname,QString text){
//client that send the signal to this slot
ClientThread* sender_client = (ClientThread*)sender();
QString currentTime = QTime::currentTime().toString("H:m A/");
QString message = "/text:"+currentTime + uname + " : " + text + "\n";
sendTextToAll(message,sender_client);
}
View .cpp
void Server::sendTextToAll(QString text,ClientThread* except){
QByteArray block;
QDataStream out(&block,QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_8);
out << (quint32)0 << text;
out.device()->seek(0);
out << (quint32)(block.size() - sizeof(quint32));
qDebug() << "block.size() = " << block.size();
View .cpp
void Server::sendTextToOne(QString text,ClientThread* target){
QByteArray block;
QDataStream out(&block,QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_8);
out << (quint32)0 << text;
out.device()->seek(0);
out << (quint32)(block.size() - sizeof(quint32));
qDebug() << "block.size() = " << block.size();
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.