Skip to content

Commit

Permalink
Refs #95. Fixed translations and login sequence with WebLoginDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Sep 30, 2024
1 parent 244e683 commit 949f89d
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 31 deletions.
10 changes: 5 additions & 5 deletions client/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,6 @@ set(translation_files_srcs
# DEPENDS ${moc_uis}
# )

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

# #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})
Expand All @@ -395,6 +392,10 @@ set(translation_files_srcs
# ${translation_files_srcs}
# )
# endif()

# #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}
Expand All @@ -408,8 +409,7 @@ qt_add_lupdate(
)

qt_add_lrelease(
TS_FILES
${translation_files_srcs}
TS_FILES ${translation_files_srcs}
)

message(STATUS "qm_files : ${qm_files}")
Expand Down
62 changes: 41 additions & 21 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 @@ -63,9 +63,6 @@ ClientApp::~ClientApp()
m_comMan->deleteLater();
}

delete m_translator;
delete m_qt_translator;

}

ComManager *ClientApp::getComManager()
Expand Down Expand Up @@ -131,14 +128,12 @@ void ClientApp::showLogin()
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());

// Show servers list... or not!
m_loginDiag->showServers(m_config.showServers());
// Set server names
m_loginDiag->setServerNames(m_config.getServerNames());

// Show servers list... or not!
m_loginDiag->showServers(m_config.showServers());
}

// Delete main window, if present
if (m_mainWindow){
Expand Down Expand Up @@ -227,12 +222,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 @@ -246,15 +241,23 @@ 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(m_currentLocale, 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
// Install app specific translator
if (m_translator->load(m_currentLocale, QLatin1String("openteraplus"), QLatin1String("_"), QLatin1String(":/translations"))) {
this->installTranslator(m_translator);
//qDebug() << "Installed translator";
//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
Expand Down Expand Up @@ -319,10 +322,27 @@ void ClientApp::onLoginSuccess(const QString &token, const QString websocket_url
if (m_comMan){
m_comMan->deleteLater();
}
m_comMan = new ComManager(QUrl("https://127.0.0.1:40075"));

// 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();
//showMainWindow();
}

void ClientApp::loginQuitRequested()
Expand Down
2 changes: 1 addition & 1 deletion client/src/ClientApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ClientApp : public QApplication
ConfigManagerClient m_config;

#ifndef OPENTERA_WEBASSEMBLY
WebLoginDialog *m_loginDiag;
WebLoginDialog* m_loginDiag;
#else
LoginDialog* m_loginDiag;
#endif
Expand Down
3 changes: 2 additions & 1 deletion client/src/dialogs/WebLoginDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ void WebLoginDialog::onCertificateError(const QWebEngineCertificateError &certif
void WebLoginDialog::onServerSelected(int index)
{
QString currentServer = ui->cmbServers->itemText(index);

// Update last server
TeraSettings::setGlobalSetting("last_used_server", currentServer);

Expand Down Expand Up @@ -130,7 +131,7 @@ QString WebLoginDialog::currentServerName()
return QString();
}


///////////////////////////////////////////////////////////////////////////////////////////////////////
WebLoginRequestInterceptor::WebLoginRequestInterceptor(QObject *p) : QWebEngineUrlRequestInterceptor(p)
{
// Cache OS information
Expand Down
6 changes: 4 additions & 2 deletions client/src/dialogs/WebLoginDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class WebLoginSharedObject : public QObject {
}

Q_INVOKABLE void sendLoginSuccess(const QString &token, const QString &websocket_url, const QString &user_uuid) {
qDebug() << "[WebLoginSharedObject::sendLoginSuccess] " << token << websocket_url;
//qDebug() << "[WebLoginSharedObject::sendLoginSuccess] " << token << websocket_url;
emit loginSuccess(token, websocket_url, user_uuid);
}

Expand Down Expand Up @@ -60,7 +60,9 @@ class WebLoginDialog : public QDialog
public:
explicit WebLoginDialog(ConfigManagerClient *config, QWidget *parent = nullptr);
~WebLoginDialog();
void setStatusMessage(const QString &message, bool error=false) {qDebug() << "Unhandled message: " << message << "error: " << error;}
void setStatusMessage(const QString &message, bool error=false) {
/*qDebug() << "Unhandled message: " << message << "error: " << error;*/
}
void setServerNames(QStringList servers);
QString currentServerName();
void showServers(bool show);
Expand Down
1 change: 1 addition & 0 deletions client/src/main/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ void MainWindow::com_downloadCompleted(DownloadingFile *file)

void MainWindow::com_preferencesUpdated()
{
qDebug() << m_currentLanguage << m_comManager->getCurrentPreferences().getLanguage();
if (m_currentLanguage != m_comManager->getCurrentPreferences().getLanguage()){ // Filter initial language change
GlobalMessageBox msg;
if (msg.showYesNo(tr("Changement de langue"), tr("La langue a été modifiée.\nSouhaitez-vous vous déconnecter pour appliquer les changements?")) == QMessageBox::Yes){
Expand Down
2 changes: 1 addition & 1 deletion shared/src/data/TeraPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void TeraPreferences::load(const TeraData &pref_obj)
void TeraPreferences::clear()
{
// Reset default values
m_language = "fr";
m_language = "";
m_notifySounds = true;
m_isSet = false;

Expand Down

0 comments on commit 949f89d

Please sign in to comment.