Skip to content

Commit

Permalink
Merge pull request #96 from introlab/2fa-dev
Browse files Browse the repository at this point in the history
Merge 2fa-dev branch into dev
  • Loading branch information
doumdi authored Oct 10, 2024
2 parents a6eb186 + 76e1fed commit d3565f5
Show file tree
Hide file tree
Showing 41 changed files with 3,671 additions and 2,001 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_on_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install Qt
uses: jurplel/install-qt-action@v3.3.0
with:
version: '6.5.3'
version: '6.7.3'
host: 'windows'
target: 'desktop'
arch: 'win64_msvc2019_64'
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/client/resources/translations/*.qm
deploy
/build-*
/build
*.user

html
Expand Down
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Look for minimum cmake version
cmake_minimum_required(VERSION 3.21)

if (APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "Minimum OS X deployment version")
endif(APPLE)
Expand All @@ -8,16 +11,14 @@ project(OpenTeraPlus)
#enable_testing()
#include(CheckFunctionExists)

#Look for minimum cmake version
cmake_minimum_required(VERSION 3.21)

#DEFINITIONS POLICY, NEW SINCE 3.0.2
cmake_policy(SET CMP0043 NEW)
cmake_policy(SET CMP0007 NEW)

# Software version
SET(CPACK_PACKAGE_VERSION_MAJOR "1")
SET(CPACK_PACKAGE_VERSION_MINOR "2")
SET(CPACK_PACKAGE_VERSION_PATCH "1")
SET(CPACK_PACKAGE_VERSION_MINOR "3")
SET(CPACK_PACKAGE_VERSION_PATCH "0")
SET(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
add_definitions(-DOPENTERAPLUS_VERSION="${CPACK_PACKAGE_VERSION}" )
add_definitions(-DOPENTERAPLUS_VERSION_MAJOR="${CPACK_PACKAGE_VERSION_MAJOR}" )
Expand Down
7 changes: 7 additions & 0 deletions client/resources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
set(TERACLIENT_RES_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "doc string")

set(translations
translations/openteraplus_en.ts
translations/openteraplus_fr.ts
)

add_custom_target(translation_files SOURCES ${translations})
5 changes: 3 additions & 2 deletions client/resources/stylesheet.qss
Original file line number Diff line number Diff line change
Expand Up @@ -660,11 +660,12 @@ QLabel#lblWarning, QLabel#lblWarning2, QLabel#lblDeviceRegisterKeyValue{
}


/* Customizations for LoginDialog */
/* Customizations for LoginDialog / WebLoginDialog */
QFrame#frameLogos{background-color:rgba(200,200,200,100%);}
QLabel#lblMessage{color:white;}
QFrame#frameMessage{background-color: transparent;}
QFrame#frameButtons{background-color:rgba(29,29,29,50%);}
QFrame#frameButtons,QFrame#frameLoginMessages{background-color:rgba(29,29,29,50%);}
QLabel#lblError{color: orange;}

/* Customizations for MainWindow */
QMainWindow{background-image: url(://TeRA_Background.png); background-color: #2c3338;}
Expand Down
2,218 changes: 1,287 additions & 931 deletions client/resources/translations/openteraplus_en.ts

Large diffs are not rendered by default.

2,184 changes: 1,251 additions & 933 deletions client/resources/translations/openteraplus_fr.ts

Large diffs are not rendered by default.

94 changes: 70 additions & 24 deletions client/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ endif (MSVC)

find_package(Qt6 REQUIRED COMPONENTS LinguistTools Multimedia WebSockets Network)

qt_standard_project_setup(
I18N_SOURCE_LANGUAGE fr
I18N_TRANSLATED_LANGUAGES en fr
)

# Drivers first
add_subdirectory(drivers)

Expand Down Expand Up @@ -119,6 +124,7 @@ if(NOT DEFINED OPENTERA_WEBASSEMBLY)
dialogs/JoinSessionDialog.h
dialogs/AboutDialog.h
dialogs/AboutDialogPage.h
dialogs/WebLoginDialog.h
# Widgets
widgets/InSessionWidget.h
# Services
Expand Down Expand Up @@ -238,6 +244,7 @@ if(NOT DEFINED OPENTERA_WEBASSEMBLY)
dialogs/JoinSessionDialog.cpp
dialogs/AboutDialog.cpp
dialogs/AboutDialogPage.cpp
dialogs/WebLoginDialog.cpp
# Widgets
widgets/InSessionWidget.cpp
# Services
Expand Down Expand Up @@ -280,6 +287,7 @@ SET(uis
dialogs/CleanUpDialog.ui
dialogs/FileUploaderDialog.ui
dialogs/QRCodeDialog.ui
dialogs/WebLoginDialog.ui
# Editors
editors/DataListWidget.ui
editors/DeviceSubTypeWidget.ui
Expand Down Expand Up @@ -337,43 +345,80 @@ QT6_WRAP_UI(moc_uis ${uis})
#This will generate moc_* for Qt
QT6_WRAP_CPP(moc_srcs ${headers})

# generate rules for building source files from the resources
QT6_ADD_RESOURCES(client_qrc ${qrcs})



set(translation_files_srcs
${TERACLIENT_RES_INCLUDES}/translations/openteraplus_fr.ts
${TERACLIENT_RES_INCLUDES}/translations/openteraplus_en.ts
)

# #set qm files output directory
set_source_files_properties(${translation_files_srcs} PROPERTIES OUTPUT_LOCATION ${TERACLIENT_RES_INCLUDES}/translations/)

qt_add_lupdate(
TS_FILES
${translation_files_srcs}

SOURCES
${srcs}
${headers}
${moc_uis}

#Translation files, this is done manually to avoid removing the file when doing make clean
# Add -noobsolete parameter to remove obsoleted translations
add_custom_target(openteraplus_en_ts
COMMAND ${Qt6_LUPDATE_EXECUTABLE} -target-language en ${srcs} ${OPENTERA_SHARED_INCLUDES} ${headers} ${moc_uis} -ts ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_en.ts
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${moc_uis}
SOURCE_TARGETS opentera_shared
)

add_custom_target(openteraplus_fr_ts
COMMAND ${Qt6_LUPDATE_EXECUTABLE} -target-language fr ${srcs} ${OPENTERA_SHARED_INCLUDES} ${headers} ${moc_uis} -ts ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_fr.ts
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${moc_uis}
qt_add_lrelease(
TS_FILES ${translation_files_srcs} QM_FILES_OUTPUT_VARIABLE qm_files
)

#set qm files output directory
set_source_files_properties(${translation_files_srcs} PROPERTIES OUTPUT_LOCATION ${TERACLIENT_RES_INCLUDES}/translations/)
message(STATUS "qm_files : ${qm_files}")


#Build this target to update translations
add_custom_target(translations DEPENDS openteraplus_en_ts openteraplus_fr_ts)
add_custom_target(translation_files SOURCES ${translation_files_srcs})
# generate rules for building source files from the resources
QT6_ADD_RESOURCES(client_qrc ${qrcs})

#Generate qm files from .ts files
qt6_add_translation(qm_files ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_en.ts ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_fr.ts)


message(STATUS "qm_files : ${qm_files}")
# Make client_qrc target depends on qm_files



# #Translation files, this is done manually to avoid removing the file when doing make clean
# # Add -noobsolete parameter to remove obsoleted translations
# add_custom_target(openteraplus_en_ts
# COMMAND ${Qt6_LUPDATE_EXECUTABLE} -target-language en ${srcs} ${OPENTERA_SHARED_INCLUDES} ${headers} ${moc_uis} -ts ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_en.ts
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# DEPENDS ${moc_uis}
# )

# add_custom_target(openteraplus_fr_ts
# COMMAND ${Qt6_LUPDATE_EXECUTABLE} -target-language fr ${srcs} ${OPENTERA_SHARED_INCLUDES} ${headers} ${moc_uis} -ts ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_fr.ts
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# DEPENDS ${moc_uis}
# )

# #Build this target to update translations
# add_custom_target(translations DEPENDS openteraplus_en_ts openteraplus_fr_ts)
# add_custom_target(translation_files SOURCES ${translation_files_srcs})

# #Generate qm files from .ts files
# qt6_add_translation(qm_files
# ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_en.ts
# ${TERACLIENT_RES_INCLUDES}/translations/openteraplus_fr.ts)

# Translations
# if (Qt6_VERSION VERSION_GREATER_EQUAL 6.7)
# qt_add_translations(TARGETS OpenTeraPlus
# SOURCE_TARGETS ${srcs} ${OPENTERA_SHARED_INCLUDES} ${headers} ${moc_uis}
# TS_FILES ${translation_files_srcs}

# )
# else()
# qt_add_translations(OpenTeraPlus
# TS_FILES
# ${translation_files_srcs}
# )
# endif()



include_directories(
${TERACLIENT_RES_INCLUDES}
Expand Down Expand Up @@ -417,7 +462,8 @@ set(ICON_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${MACOSX_BUNDLE_ICON_FILE}")
# create an executable file named "OpenTeraPlus" from the source files
# Put qrc files after qm files
if(NOT DEFINED OPENTERA_WEBASSEMBLY)
add_executable(OpenTeraPlus MACOSX_BUNDLE WIN32 ${icon} ${srcs} ${headers} ${moc_srcs} ${moc_uis} ${ICON_PATH} ${qm_files} ${client_qrc})
add_executable(OpenTeraPlus MACOSX_BUNDLE WIN32 ${icon} ${srcs} ${headers} ${moc_srcs} ${moc_uis} ${ICON_PATH} ${qm_files} ${client_qrc}
dialogs/WebLoginDialog.ui)
else()
qt_add_executable(OpenTeraPlus ${icon} ${srcs} ${headers} ${moc_srcs} ${moc_uis} ${ICON_PATH} ${qm_files} ${client_qrc})
endif()
Expand Down
83 changes: 66 additions & 17 deletions client/src/ClientApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ ClientApp::ClientApp(int &argc, char **argv)
m_mainKitWindow = nullptr;
#endif

m_translator = new QTranslator();
m_qt_translator = new QTranslator();
m_translator = new QTranslator(this);
m_qt_translator = new QTranslator(this);

// Translations
QString last_lang = TeraSettings::getGlobalSetting(SETTINGS_LASTLANGUAGE).toString();
Expand Down Expand Up @@ -59,12 +59,17 @@ ClientApp::~ClientApp()
delete m_loginDiag;

if (m_comMan){
m_comMan->disconnectFromServer();
m_comMan->deleteLater();
//m_comMan->disconnect();
//m_comMan->disconnectFromServer();
//m_comMan->deleteLater();
delete m_comMan;
}

delete m_translator;
delete m_qt_translator;
if (m_mainWindow){
delete m_mainWindow;
}
if (m_mainKitWindow)
delete m_mainKitWindow;

}

Expand Down Expand Up @@ -122,10 +127,16 @@ void ClientApp::showLogin()
m_comMan = nullptr;
}
if (m_loginDiag == nullptr){

#ifndef OPENTERA_WEBASSEMBLY
m_loginDiag = new WebLoginDialog(&m_config);
connect(m_loginDiag, &WebLoginDialog::loginSuccess, this, &ClientApp::onLoginSuccess, Qt::QueuedConnection);
connect(m_loginDiag, &WebLoginDialog::finished, this, &ClientApp::loginQuitRequested);
#else
m_loginDiag = new LoginDialog();
connect(m_loginDiag, &LoginDialog::loginRequest, this, &ClientApp::loginRequested);
connect(m_loginDiag, &LoginDialog::quitRequest, this, &ClientApp::loginQuitRequested);

#endif
// Set server names
m_loginDiag->setServerNames(m_config.getServerNames());

Expand Down Expand Up @@ -220,12 +231,12 @@ void ClientApp::setTranslation(QString language)
m_currentLocale = QLocale(); // Use system locale by default
lang_changed = true;
}
if (language.toLower() == "en" && m_currentLocale != QLocale::English){
if (language.toLower() == "en" && m_currentLocale.language() != QLocale::English){
m_currentLocale = QLocale(QLocale::English);
lang_changed = true;
}

if (language.toLower() == "fr" && m_currentLocale != QLocale::French){
if (language.toLower() == "fr" && m_currentLocale.language() != QLocale::French){
m_currentLocale = QLocale(QLocale::French);
lang_changed = true;
}
Expand All @@ -239,19 +250,27 @@ void ClientApp::setTranslation(QString language)
QLocale::setDefault(m_currentLocale);

// Install Qt translator for default widgets
if (m_qt_translator->load("qt_" + m_currentLocale.name(), QLibraryInfo::path(QLibraryInfo::TranslationsPath)))
if (m_qt_translator->load(QLocale(m_currentLocale.language()), QLatin1String("qt"), QLatin1String("_"), QLibraryInfo::path(QLibraryInfo::TranslationsPath)))
{
this->installTranslator(m_qt_translator);
if(!this->installTranslator(m_qt_translator)){
qWarning() << "Unable to install Qt translator...";
}else{
qDebug() << "Installed Qt translator";
}
}

// Install app specific translator
if (m_translator->load(m_currentLocale, QLatin1String("openteraplus"), QLatin1String("_"), QLatin1String(":/translations"))) {
this->installTranslator(m_translator);
//qDebug() << "Installed translator";
// Install app specific translator
if (m_translator->load(QLocale(m_currentLocale.language()), QLatin1String("openteraplus"), QLatin1String("_"), QLatin1String(":/translations"))) {
qDebug() << m_translator->filePath() << m_translator->language() << m_translator->isEmpty();
if (!this->installTranslator(m_translator)){
qWarning() << "Unable to install translator...";
}else{
qDebug() << "Installed translator";
}
}

// Save last used language
TeraSettings::setGlobalSetting(SETTINGS_LASTLANGUAGE, language.toLower());
TeraSettings::setGlobalSetting(SETTINGS_LASTLANGUAGE, QLocale(m_currentLocale.language()).bcp47Name());
}

}
Expand Down Expand Up @@ -286,7 +305,7 @@ void ClientApp::loginRequested(QString username, QString password, QString serve
void ClientApp::logoutRequested()
{
m_comMan->disconnectFromServer();
showLogin();
//showLogin();
}

void ClientApp::on_loginResult(bool logged, QString log_msg)
Expand All @@ -306,6 +325,35 @@ void ClientApp::on_loginResult(bool logged, QString log_msg)
}
}

void ClientApp::onLoginSuccess(const QString &token, const QString websocket_url, const QString &user_uuid)
{
// Create ComManager for that server
if (m_comMan){
m_comMan->deleteLater();
}

// Find server url for that server
QUrl server;
if (m_loginDiag)
server = m_config.getServerUrl(m_loginDiag->currentServerName());

m_comMan = new ComManager(server);

connect(m_comMan, &ComManager::socketError, this, &ClientApp::on_serverError);
connect(m_comMan, &ComManager::serverDisconnected, this, &ClientApp::on_serverDisconnected);
connect(m_comMan, &ComManager::loginResult, this, &ClientApp::on_loginResult);
connect(m_comMan, &ComManager::networkError, this, &ClientApp::on_networkError);
connect(m_comMan, &ComManager::preferencesUpdated, this, &ClientApp::preferencesUpdated);
connect(m_comMan, &ComManager::newVersionAvailable, this, &ClientApp::on_newVersionAvailable);
connect(m_comMan, &ComManager::currentUserUpdated, this, &ClientApp::on_currentUserUpdated);

connect(m_comMan->getWebSocketManager(), &WebSocketManager::genericEventReceived, this, &ClientApp::ws_genericEventReceived);

m_comMan->connectToServer(token, websocket_url, user_uuid);

//showMainWindow();
}

void ClientApp::loginQuitRequested()
{
QApplication::quit();
Expand All @@ -315,6 +363,7 @@ void ClientApp::on_serverDisconnected()
{
LOG_DEBUG("Disconnected from server.", "ClientApp::on_serverDisconnected");
showLogin();

}

void ClientApp::on_serverError(QAbstractSocket::SocketError error, QString error_str)
Expand Down
Loading

0 comments on commit d3565f5

Please sign in to comment.