Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
ServerModule/build/
build-ClientModule-Desktop_Qt_6_1_3_GCC_64bit-Debug/
*.sqlite
### C++ template
# Compiled Object files
*.slo
Expand Down Expand Up @@ -29,4 +32,4 @@
*.app

build-ClientModule-Desktop_Qt_5_13_1_MinGW_64_bit-Debug/
Lab3/
Lab3/
19 changes: 18 additions & 1 deletion ClientModule/ClientModule.pro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
QT += core gui sql printsupport
QT += core gui sql printsupport core5compat

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

Expand Down Expand Up @@ -96,3 +96,20 @@ win32 {
-lboost_thread-mgw73-mt-x64-1_66 \
-lws2_32
}

unix
{
INCLUDEPATH+= /usr/local/boost/include
#DEPENDPATH+= /usr/local/boost/lib
#LIBS+= -lboost_serialization\
#-lboost_filesystem\
#-lbboost_thread



}

unix:!macx: LIBS += -L$$PWD/../../../../../usr/local/boost/lib/ -lboost_thread -lboost_serialization -lboost_filesystem

INCLUDEPATH += $$PWD/../../../../../usr/local/boost/include
DEPENDPATH += $$PWD/../../../../../usr/local/boost/include
599 changes: 262 additions & 337 deletions ClientModule/ClientModule.pro.user

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ClientModule/MyQTextEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QClipboard>
#include <QRegularExpression>
#include <QPainter>
#include <QPainterPath>

void MyQTextEdit::insertFromMimeData(const QMimeData* source) {
if (source->hasText() && !source->hasImage() && !source->hasUrls() && !source->html().contains("<a href")) {
Expand Down
118 changes: 63 additions & 55 deletions ClientModule/editorwindow.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ClientModule/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <boost/asio.hpp>
#include "startwindow.h"
#include <QTextCodec>
#include <QApplication>

int main(int argc, char *argv[]){
Expand Down
58 changes: 29 additions & 29 deletions ClientModule/myClient.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "myClient.h"
#include <qtextcodec.h>

#include <QMessageBox>
#include <QtWidgets/QApplication>

Expand All @@ -13,7 +13,7 @@ myClient::myClient()
mail_(""),
color_("#00ffffff"),
fullBody(""),
crdt(),
_crdt(),
fileVector_(std::vector<File>())
{
worker_= std::thread([&](){io_context_.run();}); //boost thread loop start
Expand Down Expand Up @@ -52,7 +52,7 @@ void myClient::do_read_header() {
do_read_body();
}
else {
qDebug() << ec.message().c_str() << endl;
qDebug() << ec.message().c_str() << Qt::endl;
closeConnection();
}
});
Expand Down Expand Up @@ -80,7 +80,7 @@ void myClient::do_read_body() {
jsonUtility::from_json_resp(jdata_in, db_responseJSON);

if(db_responseJSON == "LOGIN_OK") {
qDebug() << "Login success" << endl;
qDebug() << "Login success" << Qt::endl;
std::string db_usernameLoginJSON;
std::string db_colorJSON;
std::string db_mailJSON;
Expand All @@ -94,11 +94,11 @@ void myClient::do_read_body() {
this->setUsername(name_qstring);
this->setColor(color_qstring);
this->setMail(mail_qstring);
this->crdt.setSiteId(idJSON);
this->_crdt.setSiteId(idJSON);

emit formResultSuccess("LOGIN_SUCCESS");
} else {
qDebug() << "Wrong user or password" << endl;
qDebug() << "Wrong user or password" << Qt::endl;
emit formResultFailure("LOGIN_FAILURE");
}
} else if(opJSON == "SIGNUP_RESPONSE") {
Expand Down Expand Up @@ -136,7 +136,7 @@ void myClient::do_read_body() {
emit removeRemoteCursor(db_usernameJSON);
emit getUserOffline(db_mapJSON);
} else {
qDebug() << "Something went wrong with db" << endl;
qDebug() << "Something went wrong with db" << Qt::endl;
}
} else if(opJSON == "GET_USER_ONLINE_RESPONSE") {
std::string db_responseJSON;
Expand All @@ -148,7 +148,7 @@ void myClient::do_read_body() {
jsonUtility::from_json_user_offline(jdata_in, db_usernameJSON, db_mapJSON);
emit getUserOnline(db_mapJSON);
} else {
qDebug() << "Something went wrong with db" << endl;
qDebug() << "Something went wrong with db" << Qt::endl;
}
} else if(opJSON == "LOGOUTURI_RESPONSE") {
std::string db_responseJSON;
Expand All @@ -170,7 +170,7 @@ void myClient::do_read_body() {

//Update client data
this->setFileURI(uriQString);
this->crdt.setSymbols(std::vector<symbol>());
this->_crdt.setSymbols(std::vector<symbol>());
emit opResultSuccess("NEWFILE_SUCCESS");
} else
emit opResultFailure("NEWFILE_FAILURE");
Expand All @@ -184,12 +184,12 @@ void myClient::do_read_body() {
jsonUtility::from_json_symbols(jdata_in, symbolsJSON);

//Update client data
this->crdt.setSymbols(symbolsJSON);
this->_crdt.setSymbols(symbolsJSON);

emit opResultSuccess("OPENFILE_SUCCESS");
} else if(db_responseJSON == "OPENFILE_FILE_EMPTY") {
//Update client data
this->crdt.setSymbols(std::vector<symbol>());
this->_crdt.setSymbols(std::vector<symbol>());
emit opResultSuccess("OPENFILE_SUCCESS");
} else
emit opResultFailure("OPENFILE_FAILURE");
Expand All @@ -213,20 +213,20 @@ void myClient::do_read_body() {

//Update client data
this->setFilename(QString::fromStdString(filenameJSON));
this->crdt.setSymbols(symbolsJSON);
this->_crdt.setSymbols(symbolsJSON);

qDebug() << "OPENWITHURI success" << endl;
qDebug() << "OPENWITHURI success" << Qt::endl;
emit opResultSuccess("OPENWITHURI_SUCCESS");
} else if(db_responseJSON == "OPENFILE_FILE_EMPTY") {
std::string filenameJSON;
jsonUtility::from_json_filename(jdata_in, filenameJSON);

//Update client data
this->setFilename(QString::fromStdString(filenameJSON));
this->crdt.setSymbols(std::vector<symbol>());
this->_crdt.setSymbols(std::vector<symbol>());
emit opResultSuccess("OPENFILE_SUCCESS");
} else {
qDebug() << "Something went wrong" << endl;
qDebug() << "Something went wrong" << Qt::endl;
emit opResultFailure("OPENWITHURI_FAILURE");
}
} else if(opJSON == "LISTFILE_RESPONSE") {
Expand All @@ -250,13 +250,13 @@ void myClient::do_read_body() {
}
emit listFileResult(files);

qDebug() << "Listfile success" << endl;
qDebug() << "Listfile success" << Qt::endl;
emit opResultSuccess("LISTFILE_SUCCESS");
} else if (db_responseJSON == "LIST_DOESNT_EXIST"){
qDebug() << "Non ha nessuna lista di file" << endl;
qDebug() << "Non ha nessuna lista di file" << Qt::endl;
emit opResultFailure("LISTFILE_FAILURE_LISTNOTEXIST");
} else {
qDebug() << "Something went wrong" << endl;
qDebug() << "Something went wrong" << Qt::endl;
emit opResultFailure("LISTFILE_FAILURE");
}
} else if(opJSON == "INVITE_URI_RESPONSE") {
Expand All @@ -281,7 +281,7 @@ void myClient::do_read_body() {
jsonUtility::from_json_insertion(jdata_in, symbolJSON, indexEditorJSON);

//process received symbol and retrieve new calculated index
int newIndex = this->crdt.process(0, indexEditorJSON, symbolJSON);
int newIndex = this->_crdt.process(0, indexEditorJSON, symbolJSON);

std::pair<int, wchar_t> tuple = std::make_pair(newIndex, symbolJSON.getLetter());
emit insertSymbol(tuple, symbolJSON.getStyle());
Expand All @@ -303,7 +303,7 @@ void myClient::do_read_body() {
symbols.push_back(*s);

//process received symbol and retrieve new calculated index
newIndex = this->crdt.process(0, newIndex, *s);
newIndex = this->_crdt.process(0, newIndex, *s);

std::pair<int, wchar_t> tuple = std::make_pair(newIndex, s->getLetter());
emit insertSymbol(tuple, s->getStyle());
Expand Down Expand Up @@ -332,7 +332,7 @@ void myClient::do_read_body() {
int newIndex;
for(const sId& id : symbolsId) {
//process received symbol and retrieve new calculated index
newIndex = this->crdt.processErase(id);
newIndex = this->_crdt.processErase(id);
if(newIndex != -1) {
emit eraseSymbols(newIndex, newIndex+1);
}
Expand All @@ -344,7 +344,7 @@ void myClient::do_read_body() {
int newIndex;
for(const sId& id : symbolsId) {
//process received symbol and retrieve new calculated index
newIndex = this->crdt.processFormat(id, formatJSON);
newIndex = this->_crdt.processFormat(id, formatJSON);
if(newIndex != -1) {
emit formatSymbols(newIndex, newIndex+1, formatJSON);
}
Expand All @@ -356,7 +356,7 @@ void myClient::do_read_body() {
int newIndex;
for(const sId& id : symbolsId) {
//process received symbol and retrieve new calculated index
newIndex = this->crdt.processFontSize(id, fontSizeJSON);
newIndex = this->_crdt.processFontSize(id, fontSizeJSON);
if(newIndex != -1) {
emit changeFontSize(newIndex, newIndex+1, fontSizeJSON);
}
Expand All @@ -368,7 +368,7 @@ void myClient::do_read_body() {
int newIndex;
for(const sId& id : symbolsId) {
//process received symbol and retrieve new calculated index
newIndex = this->crdt.processFontFamily(id, fontFamilyJSON);
newIndex = this->_crdt.processFontFamily(id, fontFamilyJSON);
if(newIndex != -1) {
emit changeFontFamily(newIndex, newIndex+1, fontFamilyJSON);
}
Expand All @@ -384,15 +384,15 @@ void myClient::do_read_body() {
else {
for(const sId& id : symbolsId) {
//process received symbol and retrieve new calculated index
newIndex = this->crdt.processAlignment(id, alignmentJSON);
newIndex = this->_crdt.processAlignment(id, alignmentJSON);
if(newIndex != -1) {
emit changeAlignment(newIndex, newIndex+1, alignmentJSON);
}
}
}
}
else {
qDebug() << "Something went wrong" << endl;
qDebug() << "Something went wrong" << Qt::endl;
emit opResultFailure("RESPONSE_FAILURE");
}
fullBody = "";
Expand All @@ -405,7 +405,7 @@ void myClient::do_read_body() {
}
}
else {
qDebug() << ec.message().c_str() << endl;
qDebug() << ec.message().c_str() << Qt::endl;
closeConnection();
}
});
Expand All @@ -421,14 +421,14 @@ void myClient::do_write() {
boost::asio::buffer(write_msgs_.front().data(), write_msgs_.front().length()+1),
[this](boost::system::error_code ec, std::size_t /*length*/) {
if (!ec) {
qDebug() << "Sent:" << write_msgs_.front().data() << "END" << endl;
qDebug() << "Sent:" << write_msgs_.front().data() << "END" << Qt::endl;
write_msgs_.pop_front();
if (!write_msgs_.empty()) {
do_write();
}
}
else {
qDebug() << ec.message().c_str() << endl;
qDebug() << ec.message().c_str() << Qt::endl;
closeConnection();
}
});
Expand Down
2 changes: 1 addition & 1 deletion ClientModule/myClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class myClient : public QObject
public:
myClient();
virtual ~myClient();
crdt crdt;
crdt _crdt;
void do_connect();
bool getStatus();
QString getUsername();
Expand Down
7 changes: 4 additions & 3 deletions ClientModule/startwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "jsonUtility.h"
#include "editorwindow.h"
#include "message.h"
#include <QDesktopWidget>
//#include <QDesktopWidget>

using json = nlohmann::json;
using boost::asio::ip::tcp;
Expand All @@ -19,7 +19,8 @@ typedef std::deque<message> message_queue;
StartWindow::StartWindow(QWidget *parent): QMainWindow(parent, Qt::FramelessWindowHint | Qt::WindowSystemMenuHint),
ui(new Ui::StartWindow), _client(new myClient)
{
QRect screenGeometry = QApplication::desktop()->screenGeometry();
//QRect screenGeometry = QApplication::desktop()->screenGeometry();
QRect screenGeometry = QGuiApplication::primaryScreen()->availableGeometry();
double width = screenGeometry.width();
int minWidth = 1920;
double scale = width / minWidth;
Expand Down Expand Up @@ -61,7 +62,7 @@ void StartWindow::mouseMoveEvent(QMouseEvent *evt){
void StartWindow::on_LoginButton_clicked(){
if(_client->getStatus()==false){
_client ->do_connect();
Sleep(1000);
sleep(1000);
qDebug () << "IL SERVER é connesso?--> " <<_client->getStatus();
if(_client->getStatus()==false){
//secondo controllo se non sono riuscito a ricollegarmi al server
Expand Down
48 changes: 28 additions & 20 deletions ClientModule/userprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ui_userprofile.h"
#include <QMessageBox>
#include <QDebug>
#include <QTextCodec>

UserProfile::UserProfile(myClient* client, QString nome, QString mail,int files, int myFiles, QWidget *parent):
QWidget(parent, Qt::FramelessWindowHint | Qt::WindowSystemMenuHint), ui(new Ui::UserProfile), _client(client) {
Expand Down Expand Up @@ -73,27 +74,34 @@ void UserProfile::mouseMoveEvent(QMouseEvent *evt) {

QChar UserProfile::SimplifySingleCharForSorting(QChar c, bool changeToLowerCase){

if ( ( c >= 0xC0 && c <= 0xC5 ) || ( c >= 0xE1 && c <= 0xE5 ) || c == 0xAA )
return ( ( c >= 0xC0 && c <= 0xC5 ) && !changeToLowerCase ) ? 'A' : 'a';
if ( ( c >= 0xC8 && c <= 0xCB ) || ( c >= 0xE8 && c <= 0xEB ) )
return ( c > 0xCB || changeToLowerCase ) ? 'e' : 'E';
if ( ( c >= 0xCC && c <= 0xCF ) || ( c >= 0xEC && c <= 0xEF ) )
return ( c > 0xCF || changeToLowerCase ) ? 'i' : 'I';
if ( ( c >= 0xD2 && c <= 0xD6 ) || ( c >= 0xF2 && c <= 0xF6 ) || c == 0xBA )
return ( ( c >= 0xD2 && c <= 0xD6 ) && !changeToLowerCase ) ? 'O' : 'o';
if ( ( c >= 0xD9 && c <= 0xDC ) || ( c >= 0xF9 && c <= 0xFC ) )
return ( c > 0xDC || changeToLowerCase ) ? 'u' : 'U';
if ( c == 0xA9 || c == 0xC7 || c == 0xE7 )
return ( c == 0xC7 && !changeToLowerCase ) ? 'C' : 'c';
if ( c == 0xD1 || c == 0xF1 )
return ( c == 0xD1 && !changeToLowerCase ) ? 'N' : 'n';
if ( c == 0xAE )
if ( ( c >= QChar(0xC0) && c <= QChar(0xC5) ) || ( c >= QChar(0xE1) && c <= QChar(0xE5) ) || c == QChar(0xAA) )
return ( ( c >= QChar(0xC0) && c <= QChar(0xC5) ) && !changeToLowerCase ) ? 'A' : 'a';

if ( ( c >= QChar(0xC8) && c <= QChar(0xCB) ) || ( c >=QChar( 0xE8) && c <= QChar(0xEB) ) )
return ( c > QChar(0xCB) || changeToLowerCase ) ? 'e' : 'E';

if ( ( c >= QChar(0xCC) && c <= QChar(0xCF) ) || ( c >= QChar(0xEC) && c <= QChar(0xEF) ) )
return ( c > QChar(0xCF) || changeToLowerCase ) ? 'i' : 'I';

if ( ( c >=QChar(0xD2) && c <= QChar(0xD6) ) || ( c >= QChar(0xF2) && c <= QChar(0xF6) ) || c == QChar(0xBA) )
return ( ( c >= QChar(0xD2) && c <= QChar(0xD6) ) && !changeToLowerCase ) ? 'O' : 'o';

if ( ( c >= QChar(0xD9) && c <= QChar(0xDC) ) || ( c >= QChar(0xF9) && c <= QChar(0xFC) ) )
return ( c > QChar(0xDC) || changeToLowerCase ) ? 'u' : 'U';

if ( c == QChar(0xA9) || c == QChar(0xC7) || c == QChar(0xE7) )
return ( c == QChar(0xC7) && !changeToLowerCase ) ? 'C' : 'c';

if ( c ==QChar(0xD1) || c == QChar(0xF1) )
return ( c == QChar(0xD1) && !changeToLowerCase ) ? 'N' : 'n';

if ( c == QChar(0xAE) )
return 'r';
if ( c == 0xDF )
if ( c == QChar(0xDF) )
return 's';
if ( c == 0x8E || c == 0x9E )
return ( c == 0x8E && !changeToLowerCase ) ? 'Z' : 'z';
if ( c == 0x9F || c == 0xDD || c == 0xFD || c == 0xFF )
return ( ( c == 0x9F || c == 0xDD ) && !changeToLowerCase ) ? 'Y' : 'y';
if ( c == QChar(0x8E) || c == QChar(0x9E) )
return ( c == QChar(0x8E) && !changeToLowerCase ) ? 'Z' : 'z';
if ( c == QChar(0x9F) || c == QChar(0xDD) || c == QChar(0xFD) || c == QChar(0xFF) )
return ( ( c == QChar(0x9F) || c == QChar(0xDD) ) && !changeToLowerCase ) ? 'Y' : 'y';
return c;
}
Binary file modified ServerModule/Db/texteditor_users.sqlite
Binary file not shown.