Skip to content
This repository has been archived by the owner on Sep 27, 2020. It is now read-only.

Porting gui to qml #83

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1690474
Added qml resources
tuminsky Aug 1, 2020
94c5e22
ported to QML
tuminsky Aug 1, 2020
8f3aabb
Removed old ui
tuminsky Aug 1, 2020
4e89744
Merge branch 'master' into porting_gui_to_qml
tuminsky Aug 1, 2020
0c18adc
Merge remote-tracking branch 'upstream/master'
tuminsky Aug 1, 2020
2ae6f47
Added qml to .travis.yml
tuminsky Aug 1, 2020
a607368
Renaming buttons registration and authorisation
tuminsky Aug 2, 2020
bcf71f9
Added field password repeat
tuminsky Aug 2, 2020
7f668a7
Removed message dialogs on success authorisation and registration
tuminsky Aug 2, 2020
b55ffeb
Fixed change room
tuminsky Aug 2, 2020
6876912
Removed mainwindow.ui
tuminsky Aug 2, 2020
99be463
Merge remote-tracking branch 'upstream/master'
tuminsky Aug 3, 2020
7f6c4d0
Added qml resources
tuminsky Aug 1, 2020
27ce319
ported to QML
tuminsky Aug 1, 2020
28e33bd
Removed old ui
tuminsky Aug 1, 2020
13316a6
Added qml to .travis.yml
tuminsky Aug 1, 2020
203f743
Renaming buttons registration and authorisation
tuminsky Aug 2, 2020
7845e43
Added field password repeat
tuminsky Aug 2, 2020
5e83dff
Removed message dialogs on success authorisation and registration
tuminsky Aug 2, 2020
9a7dcfb
Fixed change room
tuminsky Aug 2, 2020
6bb8bce
Fixed bug with chat view autoscroll
tuminsky Aug 3, 2020
f16e817
Added scroll bar fot input text and chat view
tuminsky Aug 3, 2020
9b515cb
Added text wraping in chat view
tuminsky Aug 3, 2020
e9c7f85
Merge branch 'porting_gui_to_qml' of https://github.com/tuminskiy/App…
tuminsky Aug 3, 2020
c0caf15
Fixed src/client/CMakeLists.txt
tuminsky Aug 3, 2020
7445574
Merge remote-tracking branch 'upstream/master'
tuminsky Aug 3, 2020
1ead0e1
Merge branch 'master' into porting_gui_to_qml
tuminsky Aug 3, 2020
f8fd9f0
- add ObjectPool for connections
k-morozov Aug 4, 2020
e94fa63
Fixed crash when closing the chat window
tuminsky Aug 4, 2020
e6f4fe7
Merge remote-tracking branch 'upstream/dev' into porting_gui_to_qml
tuminsky Aug 4, 2020
e64dcae
Changed server ip
tuminsky Aug 4, 2020
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ addons:
- sqlite3 libsqlite3-dev
- libboost-test-dev
- qt5-default
- qtdeclarative5-dev

before_script:
- if [ $TRAVIS_OS_NAME == linux ]; then sudo ./scripts/install_env.sh; fi
Expand Down
15 changes: 7 additions & 8 deletions src/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ set(GUI_dir gui)
#****************************************************************************************************
set(CLIENT_SOURCES
startup_client.cpp
${Client_dir}/client.h ${Client_dir}/client.cpp
${GUI_dir}/mainwindow.h ${GUI_dir}/mainwindow.cpp
${GUI_dir}/mainwindow.ui
${Control_dir}/control.h ${Control_dir}/control.cpp
${Client_dir}/client.h ${Client_dir}/client.cpp
${Control_dir}/control.h ${Control_dir}/control.cpp
${GUI_dir}/qml.qrc
)

#****************************************************************************************************
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt5 COMPONENTS Core Gui Qml Quick Widgets REQUIRED)
find_package (Threads)

add_executable(${CLIENT_BIN} ${CLIENT_SOURCES})
target_include_directories(${CLIENT_BIN} PUBLIC .)

#****************************************************************************************************
find_package(Boost COMPONENTS system date_time program_options regex REQUIRED)
find_package(Boost COMPONENTS system date_time REQUIRED)

set_target_properties(${CLIENT_BIN} PROPERTIES
CXX_STANDARD 17
Expand All @@ -46,8 +45,8 @@ set_target_properties(${CLIENT_BIN} PROPERTIES
COMPILE_OPTIONS "-std=c++17;-O2;-Wall;-Wextra;-Wpedantic"
)

#add_dependencies(${CLIENT_BIN} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} Qt5::Widgets ${PROTOCOL_LIB_NAME})
target_link_libraries (${CLIENT_BIN} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} Qt5::Widgets ${PROTOCOL_LIB_NAME})
target_link_libraries (${CLIENT_BIN} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${PROTOCOL_LIB_NAME}
Qt5::Core Qt5::Gui Qt5::Qml Qt5::Quick Qt5::Widgets)

# install to bin folder our binaries
install(TARGETS ${CLIENT_BIN} RUNTIME DESTINATION bin)
Expand Down
14 changes: 2 additions & 12 deletions src/client/client/client.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <client/client.h>
//#include <charconv>

void Client::write(const std::string& message) {
text_request_ptr text_request = std::make_shared<TextRequest>(login, room_id, message);
Expand Down Expand Up @@ -89,19 +88,16 @@ void Client::send_login_packet(packet_ptr packet) {
}
else
{
// good_client_is_registred();
emit send_input_code(InputCode::RegistrOK);
}
else {
if (response->get_loginid()==-1) {
// emit bad_client_is_autorisation();
emit send_input_code(InputCode::IncorrectAutor);
this->close();
return;
}
else
{
// good_client_is_autorisation();
emit send_input_code(InputCode::AutorOK);
}
}
Expand Down Expand Up @@ -154,7 +150,7 @@ void Client::read_response_header() {
}
}
else {
sock.close();
std::cout << ec.message() << "\n";
}
});
}
Expand All @@ -165,8 +161,6 @@ void Client::read_response_data(registr_response_ptr packet) {
boost::asio::async_read(sock, boost::asio::buffer(packet->get_data(), packet->get_length_data()),
[this, packet](boost::system::error_code error, std::size_t) {
if (!error) {
// std::cout << "read_response_data" << std::endl;

read_response_header();
}
else {
Expand All @@ -181,7 +175,6 @@ void Client::read_response_data(autor_response_ptr packet) {
boost::asio::async_read(sock, boost::asio::buffer(packet->get_data(), packet->get_length_data()),
[this, packet](boost::system::error_code error, std::size_t) {
if (!error) {
// std::cout << "read_response_data" << std::endl;
read_response_header();
}
else {
Expand All @@ -199,7 +192,7 @@ void Client::read_response_data(text_response_ptr packet) {
auto local_time = DateTime::from_universal_to_local(packet->get_datetime());

std::cout << packet->get_login() << ": " << packet->get_message() << std::endl;
send_text(packet->get_login(), packet->get_message(), local_time);
emit send_text(packet->get_login(), packet->get_message(), local_time);

read_response_header();
}
Expand All @@ -209,9 +202,6 @@ void Client::read_response_data(text_response_ptr packet) {
});
}

//void Client::read_response_join_room(join_room_request_ptr) {

//}
void Client::send_request_header() {
boost::asio::async_write(sock, boost::asio::buffer(packets_to_server.front()->get_header(), Block::Header),
[this](boost::system::error_code ec, std::size_t) {
Expand Down
33 changes: 15 additions & 18 deletions src/client/control/control.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
#include <control/control.h>
#include "control.h"

Control::Control() {
w.show();

qRegisterMetaType<std::string>("std::string");
qRegisterMetaType<QTextCursor>("QTextCursor");
qRegisterMetaType<InputCode>("InputCode");
qRegisterMetaType<DateTime>("DateTime");

QObject::connect(&w, &MainWindow::send_autorisation_info, this, &Control::autorisation);
QObject::connect(&w, &MainWindow::send_registration_info, this, &Control::registration);

QObject::connect(&w, &MainWindow::send_change_room, this, &Control::change_room);

QObject::connect(this, &Control::send_text_to_gui, &w, &MainWindow::print_text);

QObject::connect(&w, &MainWindow::send_text_data, this, &Control::get_text_from_gui);
}

void Control::connect_to_server(const std::string& login, const std::string& password, TypeCommand command) {
Expand All @@ -32,12 +20,21 @@ void Control::connect_to_server(const std::string& login, const std::string& pas
client = std::make_unique<Client>(io_service, endpoints, request);

QObject::connect(client.get(), &Client::send_text, this, &Control::text_from_client);
QObject::connect(client.get(), &Client::send_input_code, this, &Control::send_input_code);

QObject::connect(client.get(), SIGNAL(send_input_code(InputCode)), &w, SLOT(handler_input_code(InputCode)));

std::thread th([&io_service]() {
io_service.run();
std::thread th([&io_service] {
io_service.run();
});

th.join();
client->close();
}

void Control::send_input_code(InputCode code)
{
switch (code) {
case InputCode::RegistrOK: emit registrationOk(); break;
case InputCode::BusyRegistr: emit registrationBusy(); break;
case InputCode::AutorOK: emit authorisationOk(); break;
case InputCode::IncorrectAutor: emit authorisationIncorrect(); break;
}
}
42 changes: 24 additions & 18 deletions src/client/control/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#define CONTROL_H

#include <QWidget>
#include <client/client.h>
#include <gui/mainwindow.h>
#include <QString>
#include <QDateTime>

#include "client/client.h"

/**
* @brief Controller
Expand All @@ -28,11 +30,7 @@ class Control: public QObject
/**
* @brief Close client socket when destroy UI controller.
*/
~Control() {
if (client) {
client->close();
}
}
~Control() { }

signals:
/**
Expand All @@ -42,7 +40,12 @@ class Control: public QObject
* @param text message content
* @param dt date and time of sending the text
*/
void send_text_to_gui(const std::string& login, const std::string& text, DateTime dt);
void send_text_to_gui(const QString& login, const QString& text, const QDateTime dt);

void registrationOk();
void registrationBusy();
void authorisationOk();
void authorisationIncorrect();

public slots:
/**
Expand All @@ -51,12 +54,11 @@ public slots:
* @param login user's login
*
* @param password user's password
*
* @todo fix typo autorisation -> authorization
*/
void autorisation(const std::string& login, const std::string& password) {
void authorisation(const QString& login, const QString& password) {
std::thread th([this, login, password]() {
connect_to_server(login, password, TypeCommand::AuthorisationRequest);
connect_to_server(login.toStdString(), password.toStdString(),
TypeCommand::AuthorisationRequest);
});
th.detach();
}
Expand All @@ -67,9 +69,10 @@ public slots:
* @param login user's login
* @param password user's password
*/
void registration(const std::string& login, const std::string& password) {
void registration(const QString& login, const QString& password) {
std::thread th([this, login, password]() {
connect_to_server(login, password, TypeCommand::RegistrationRequest);
connect_to_server(login.toStdString(), password.toStdString(),
TypeCommand::RegistrationRequest);
});
th.detach();
}
Expand All @@ -81,8 +84,8 @@ public slots:
* @param text message content
* @param room_id sender's room
*/
void get_text_from_gui(const std::string& login, const std::string& text, int room_id) {
client->write(std::make_shared<TextRequest>(login, room_id, text));
void get_text_from_gui(const QString& login, const QString& text, int room_id) {
client->write(std::make_shared<TextRequest>(login.toStdString(), room_id, text.toStdString()));
}

/**
Expand All @@ -93,7 +96,9 @@ public slots:
* @param dt date and time of sending the text
*/
void text_from_client(const std::string& from, const std::string& text, DateTime dt) {
send_text_to_gui(from, text, dt);
const QDateTime qdt(QDate(dt.year, dt.month, dt.day),
QTime(dt.hours, dt.minutes, dt.seconds));
emit send_text_to_gui(QString(from.c_str()), QString(text.c_str()), qdt);
}

/**
Expand All @@ -105,9 +110,10 @@ public slots:
client->write(std::make_shared<JoinRoomRequest>(new_room_id));
}

void send_input_code(InputCode code);

private:
std::unique_ptr<Client> client;
MainWindow w;
};

#endif // CONTROL_H
4 changes: 4 additions & 0 deletions src/client/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ void MainWindow::on_push_autorisation_clicked()
password = ui->password->text();
if (logon.isEmpty() || password.isEmpty()) return;
send_autorisation_info(logon.toStdString(), password.toStdString());
ui->logon->clear();
ui->password->clear();
}

void MainWindow::on_push_send_clicked()
Expand Down Expand Up @@ -68,6 +70,8 @@ void MainWindow::on_push_registration_clicked()
password = ui->password->text();
if (logon.isEmpty() || password.isEmpty()) return;
send_registration_info(logon.toStdString(), password.toStdString());
ui->logon->clear();
ui->password->clear();
}

void MainWindow::on_push_change_room_id_clicked()
Expand Down
Loading