From 1b3a0278eb0b652a0a1b795388ddc55aaca7e463 Mon Sep 17 00:00:00 2001 From: cemycc Date: Mon, 30 May 2011 20:56:22 +0300 Subject: [PATCH] Changed: #1307 Added extract bot names and UI dialog for plugin settings. --- .../translation_manager/CMakeLists.txt | 2 +- .../translation_manager/extract_bot_names.cpp | 756 ++++++++++++++++++ .../translation_manager_plugin.cpp | 47 +- .../translation_manager_plugin.h | 8 + .../translation_manager_settings_page.cpp | 243 ++++++ .../translation_manager_settings_page.h | 16 +- .../translation_manager_settings_page.ui | 485 ++++++++--- 7 files changed, 1462 insertions(+), 95 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_bot_names.cpp diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt index ce85c682e..827db7487 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt @@ -30,7 +30,7 @@ SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC}) ADD_LIBRARY(ovqt_plugin_translation_manager MODULE ${SRC} ${OVQT_PLUG_TRANSLATION_MANAGER_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_PLUG_TRANSLATION_MANAGER_UI_HDRS}) -TARGET_LINK_LIBRARIES(ovqt_plugin_translation_manager ovqt_plugin_core nelmisc nel3d ${QT_LIBRARIES} ${QT_QTOPENGL_LIBRARY}) +TARGET_LINK_LIBRARIES(ovqt_plugin_translation_manager ovqt_plugin_core nelmisc nel3d nelligo nelgeorges ${QT_LIBRARIES} ${QT_QTOPENGL_LIBRARY}) NL_DEFAULT_PROPS(ovqt_plugin_translation_manager "NeL, Tools, 3D: Object Viewer Qt Plugin: Translation Manager") NL_ADD_RUNTIME_FLAGS(ovqt_plugin_translation_manager) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_bot_names.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_bot_names.cpp new file mode 100644 index 000000000..75a97d3bb --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_bot_names.cpp @@ -0,0 +1,756 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "nel/misc/types_nl.h" +#include "nel/misc/config_file.h" +#include "nel/misc/sheet_id.h" +#include "nel/misc/path.h" +#include "nel/misc/diff_tool.h" +#include "nel/georges/u_form.h" +#include "nel/georges/u_form_elm.h" +#include "nel/georges/load_form.h" +#include "nel/ligo/ligo_config.h" +#include "nel/ligo/primitive.h" +#include "nel/ligo/primitive_utils.h" + +using namespace std; +using namespace NLMISC; +using namespace NLLIGO; +using namespace STRING_MANAGER; + +vector Filters; + +static CLigoConfig LigoConfig; +static bool RemoveOlds = false; + +struct TCreatureInfo +{ + CSheetId SheetId; + bool ForceSheetName; + bool DisplayName; + + + void readGeorges (const NLMISC::CSmartPtr &form, const NLMISC::CSheetId &sheetId) + { + const NLGEORGES::UFormElm &item=form->getRootNode(); + + SheetId=sheetId; + item.getValueByName(ForceSheetName, "3d data.ForceDisplayCreatureName"); + item.getValueByName(DisplayName, "3d data.DisplayName"); + } + + void serial(NLMISC::IStream &f) + { + f.serial(SheetId); + f.serial(ForceSheetName); + f.serial(DisplayName); + } + + + static uint getVersion () + { + return 1; + } + + void removed() + { + } + +}; + +std::map Creatures; + +TCreatureInfo *getCreature(const std::string &sheetName) +{ + CSheetId id(sheetName+".creature"); + + if (Creatures.find(id) != Creatures.end()) + return &(Creatures.find(id)->second); + else + return NULL; +} + +string cleanupName(const std::string &name) +{ + string ret; + + for (uint i=0; i= 2) + { + if ( *ret.begin() == ucchar('$')) + { + ret=ret.substr(1); + } + if ( *ret.rbegin() == ucchar('$')) + { + ret = ret.substr(0, ret.size()-1); + } + } + ret = cleanupUcName(ret); + return ret; +} + +struct TEntryInfo +{ + string SheetName; +}; + +set GenericNames; +map SimpleNames; +set Functions; + + +string removeAndStoreFunction(const std::string &fullName) +{ + string::size_type pos = fullName.find("$"); + if (pos == string::npos) + return fullName; + else + { + // extract and store the function name + string ret; + + ret = fullName.substr(0, pos); + string::size_type pos2 = fullName.find("$", pos+1); + + string fct = fullName.substr(pos+1, pos2-(pos+1)); + + ret += fullName.substr(pos2+1); + + if (Functions.find(fct) == Functions.end()) + { + nldebug("Adding function '%s'", fct.c_str()); + Functions.insert(fct); + } + + return ret; + } +} + + +void addGenericName(const std::string &name, const std::string &sheetName) +{ + TCreatureInfo *c = getCreature(sheetName); + if (!c || c->ForceSheetName || !c->DisplayName) + return; + + if (SimpleNames.find(name) != SimpleNames.end()) + { + nldebug("Name '%s' is now a generic name", name.c_str()); + GenericNames.insert(name); + SimpleNames.erase(name); + + } + else if (GenericNames.find(name) == GenericNames.end()) + { + nldebug("Adding generic name '%s'", name.c_str()); + GenericNames.insert(name); + } +} + +void addSimpleName(const std::string &name, const std::string &sheetName) +{ + TCreatureInfo *c = getCreature(sheetName); + if (!c || c->ForceSheetName || !c->DisplayName) + return; + + if (SimpleNames.find(name) != SimpleNames.end()) + { + addGenericName(name, sheetName); + } + else if (GenericNames.find(name) != GenericNames.end()) + { + return; + } + else + { + nldebug("Adding simple name '%s'", name.c_str()); + + TEntryInfo ei; + ei.SheetName = sheetName; + + SimpleNames.insert(make_pair(name, ei)); + } +} + +int extractBotNamesAll(map > config_paths, string ligo_class_file, string trans_path, string work_path) +{ + //------------------------------------------------------------------- + // read the parameters + /*for (int i=2; i::iterator it = config_paths["paths"].begin(); it != config_paths["paths"].end(); ++it) + { + CPath::addSearchPath(*it, true, false); + } + for (std::list::iterator it = config_paths["pathsR"].begin(); it != config_paths["pathsR"].end(); ++it) + { + CPath::addSearchPath(*it, false, false); + } + + for (std::list::iterator it = config_paths["filters"].begin(); it != config_paths["filters"].end(); ++it) + { + Filters.push_back(*it); + } + + + //------------------------------------------------------------------- + // init the sheets + CSheetId::init(false); + const string PACKED_SHEETS_NAME = "bin/translation_tools_creature.packed_sheets"; + loadForm("creature", PACKED_SHEETS_NAME, Creatures, false, false); + + if (Creatures.empty()) + { + for (std::list::iterator it = config_paths["georges"].begin(); it != config_paths["georges"].end(); ++it) + CPath::addSearchPath((*it).c_str(), true, false); + + loadForm("creature", PACKED_SHEETS_NAME, Creatures, true); + } + + + //------------------------------------------------------------------- + // init ligo config + string ligoPath = CPath::lookup(ligo_class_file, true, true); + LigoConfig.readPrimitiveClass(ligoPath.c_str(), false); + NLLIGO::Register(); + + CPrimitiveContext::instance().CurrentLigoConfig = &LigoConfig; + + //------------------------------------------------------------------- + // ok, ready for the real work, + // first, read the primitives files and parse the primitives + vector files; + CPath::getFileList("primitive", files); + + for (uint i=0; i ps; + ps.buildSet(primDoc.RootNode, pred, result); + + for (uint i=0; igetPropertyByName("name", name); + result[i]->getPropertyByName("count", countStr); + result[i]->getPropertyByName("bot_sheet_look", sheetStr); + + uint32 count; + NLMISC::fromString(countStr, count); + + if (count != 0) + { + if (sheetStr.empty()) + { + nlwarning("In '%s', empty sheet !", buildPrimPath(result[i]).c_str()); + } + else + { + addGenericName(removeAndStoreFunction(name), sheetStr); + } + } + } + } + // look for bot template + { + TPrimitiveClassPredicate pred("bot_template_npc"); + TPrimitiveSet result; + + CPrimitiveSet ps; + ps.buildSet(primDoc.RootNode, pred, result); + + for (uint i=0; igetPropertyByName("name", name); + result[i]->getPropertyByName("sheet_look", sheetStr); + + if (sheetStr.empty()) + { + // take the sheet in the parent + result[i]->getParent()->getPropertyByName("bot_sheet_look", sheetStr); + } + + if (sheetStr.empty()) + { + nlwarning("In '%s', empty sheet !", buildPrimPath(result[i]).c_str()); + } + else + { + addGenericName(removeAndStoreFunction(name), sheetStr); + } + } + } + // look for npc_group + { + TPrimitiveClassPredicate pred("npc_group"); + TPrimitiveSet result; + + CPrimitiveSet ps; + ps.buildSet(primDoc.RootNode, pred, result); + + for (uint i=0; igetPropertyByName("name", name); + result[i]->getPropertyByName("count", countStr); + result[i]->getPropertyByName("bot_sheet_client", sheetStr); + + uint32 count; + NLMISC::fromString(countStr, count); + + if (count > 0 && sheetStr.empty()) + { + nlwarning("In '%s', empty sheet !", buildPrimPath(result[i]).c_str()); + } + else + { + if (count == 1) + { + addSimpleName(removeAndStoreFunction(name), sheetStr); + } + else if (count > 1) + { + addGenericName(removeAndStoreFunction(name), sheetStr); + } + } + } + } + // look for bot + { + TPrimitiveClassPredicate pred("npc_bot"); + TPrimitiveSet result; + + CPrimitiveSet ps; + ps.buildSet(primDoc.RootNode, pred, result); + + for (uint i=0; igetPropertyByName("name", name); + result[i]->getPropertyByName("sheet_client", sheetStr); + + if (sheetStr.empty()) + { + // take the sheet in the parent + result[i]->getParent()->getPropertyByName("bot_sheet_client", sheetStr); + } + + if (sheetStr.empty()) + { + nlwarning("In '%s', empty sheet !", buildPrimPath(result[i]).c_str()); + } + else + { + TEntryInfo ei; + addSimpleName(removeAndStoreFunction(name), sheetStr); + } + } + } + } + + //------------------------------------------------------------------- + // step 2 : load the reference file + + nlinfo("Looking for missing translation:"); + + TWorksheet botNames; + loadExcelSheet(work_path, botNames, true); + TWorksheet transBotNames; + loadExcelSheet(trans_path, transBotNames, true); + + TWorksheet fcts; + loadExcelSheet(work_path, fcts, true); + + + // add missing element + + uint nbAddSimpleName = 0; + uint nbAddFunction = 0; + uint nbAddGenericName = 0; + + uint botIdCol; + nlverify(botNames.findId(botIdCol)); + uint transIdCol; + nlverify(transBotNames.findId(transIdCol)); + uint fctsIdCol; + nlverify(fcts.findId(fctsIdCol)); + + // special treatment to add the sheet_name col + { + uint sheetCol; + if (!botNames.findCol(ucstring("sheet_name"), sheetCol)) + { + botNames.insertColumn(botNames.ColCount); + botNames.setData(0, botNames.ColCount-1, ucstring("sheet_name")); + } + + if (!transBotNames.findCol(ucstring("sheet_name"), sheetCol)) + { + transBotNames.insertColumn(transBotNames.ColCount); + transBotNames.setData(0, transBotNames.ColCount-1, ucstring("sheet_name")); + } + } + // 1 - simple names + { + nlinfo(" Simple names..."); + + + map::iterator first(SimpleNames.begin()), last(SimpleNames.end()); + for (; first != last; ++first) + { + uint rowIdx; + if (!botNames.findRow(botIdCol, first->first, rowIdx)) + { + // we need to add the entry + rowIdx = botNames.size(); + botNames.resize(botNames.size()+1); + + botNames.setData(rowIdx, ucstring("bot name"), first->first); + botNames.setData(rowIdx, ucstring("translated name"), first->first); + botNames.setData(rowIdx, ucstring("sheet_name"), first->second.SheetName); + + nbAddSimpleName++; + } + else + { + // set/update the sheet name info + // try to restore the existing translation + uint transRowIdx; + if (transBotNames.findRow(transIdCol, first->first, transRowIdx)) + { + ucstring wkBotName = botNames.getData(rowIdx, ucstring("bot name")); + ucstring wkSheetName = botNames.getData(rowIdx, ucstring("sheet_name")); + ucstring wkTranslationName = botNames.getData(rowIdx, ucstring("translated name")); + ucstring ucWkHash; + uint64 hash = CI18N::makeHash(wkBotName + wkTranslationName +wkSheetName); + CI18N::hashToUCString(hash, ucWkHash); + ucstring trUcHash = transBotNames[transRowIdx][0]; + bool isWkTranslationNameAGroupName = wkTranslationName.find(ucstring("$")) != ucstring::npos; + bool hashIsValide = std::equal(ucWkHash.begin(), ucWkHash.end(), trUcHash.begin()+1); + // Hash is equal get the translation + if (hashIsValide && !isWkTranslationNameAGroupName) + { + wkTranslationName = transBotNames.getData(transRowIdx, ucstring("translated name")); + wkSheetName = transBotNames.getData(transRowIdx, ucstring("sheet_name")); + botNames.setData(rowIdx, ucstring("translated name"), wkTranslationName); + botNames.setData(rowIdx, ucstring("sheet_name"), wkSheetName); + hash = CI18N::makeHash(wkBotName + wkTranslationName + wkSheetName); + // update the hash code + CI18N::hashToUCString(hash, transBotNames[transRowIdx][0]); + } + // bots_name.txt has been manually changed. We trust what the Level Designer has done. We don't destroy is work. + // or it is a simple + else + { + //use the "translated name" of the manually changed work/bot_name.txt + botNames.setData(rowIdx, ucstring("translated name"), wkTranslationName); + botNames.setData(rowIdx, ucstring("sheet_name"), wkSheetName); + } + } + } + } + } + + // 2 - generic names + + { + nlinfo(" Generic names..."); + + set::iterator first(GenericNames.begin()), last(GenericNames.end()); + for (; first != last; ++first) + { + string gnName = "gn_" + cleanupName(*first); + + ucstring fctsTitleId; + ucstring fctsName; + // add or modify the bot names + uint rowIdx; + if (!botNames.findRow(botIdCol, *first, rowIdx)) + { + // we need to add the entry + rowIdx = botNames.size(); + botNames.resize(botNames.size()+1); + + botNames.setData(rowIdx, ucstring("bot name"), *first); + botNames.setData(rowIdx, ucstring("translated name"), ucstring("$") + gnName + "$"); + botNames.setData(rowIdx, ucstring("sheet_name"), ucstring()); + fctsTitleId = gnName; + fctsName = *first; + + nbAddSimpleName++; + } + else + { + // look in the translated table to remember the translated name to write it in the string file + ucstring wkBotName = botNames.getData(rowIdx, ucstring("bot name")); + ucstring wkTranslationName = botNames.getData(rowIdx, ucstring("translated name")); + ucstring wkSheetName = botNames.getData(rowIdx, ucstring("sheet_name")); + + + nlinfo("Bot name:%s\n",wkBotName.toString().c_str()); + bool isWkTranslationNameAGroupName = wkTranslationName.find(ucstring("$")) != ucstring::npos; + + if ( isWkTranslationNameAGroupName ) //work name looks like "$gn_***$: do not modify + { + + //Do not change work/bot_name.txt + // update work/world_title.txt + + ucstring transName; + fctsTitleId = makeGroupName(wkTranslationName); + uint transRowIdx; + if (transBotNames.findRow(transIdCol, *first, transRowIdx)) + { + transName = transBotNames.getData(transRowIdx, ucstring("translated name")); + + if (transName.find(ucstring("$")) != ucstring::npos) + { + transName = fctsTitleId; + } + } + else + { + transName = fctsTitleId; + } + //Do not touch anything + botNames.setData(rowIdx, ucstring("translated name"), wkTranslationName); + botNames.setData(rowIdx, ucstring("sheet_name"), wkSheetName); + // fctsTitleId = makeGroupName(wkTranslationName); + fctsName = transName; + + } + else // WkTranslationName != "$gn*$" + { + uint transRowIdx; + ucstring transName; + ucstring wkSheetName; + // Get the translation as a simple name. + if (transBotNames.findRow(transIdCol, *first, transRowIdx)) + { + + transName = transBotNames.getData(transRowIdx, ucstring("translated name")); + ucstring trSheetName = transBotNames.getData(transRowIdx, ucstring("sheet_name")); + + //tr."translation name" is + if (transName.find(ucstring("$")) != ucstring::npos) + { + //get Translation, update hash + botNames[rowIdx][1] = transName; + botNames[rowIdx][2] = trSheetName; + fctsTitleId = makeGroupName(transName); + fctsName = makeGroupName(transName); + ucstring trNewUcHash; + uint64 hash = CI18N::makeHash(wkBotName + transName +trSheetName); + CI18N::hashToUCString(hash, trNewUcHash); + transBotNames[transRowIdx][0] = ucstring("_") + trNewUcHash; + } + else //botNames."translated name" != $gn_$ && tansName."translated name" != $gn_$ + { + + // get the translation back + //update work/bot_name.txt + wkTranslationName = ucstring("$")+gnName+"$"; + botNames[rowIdx][0] = wkBotName; + botNames[rowIdx][1] = wkTranslationName; + botNames[rowIdx][2] = wkSheetName; + + //update translated/bot_name.txt + + fctsName = transName; //transName + fctsTitleId = gnName; + ucstring trNewUcHash; + uint64 hash = CI18N::makeHash(botNames[rowIdx][0] + botNames[rowIdx][1] +botNames[rowIdx][2]); + CI18N::hashToUCString(hash, trNewUcHash); + transBotNames[transRowIdx][0] = ucstring("_") + trNewUcHash; + } + + } + else //There is no translation yet + { + fctsName = wkTranslationName; + wkTranslationName = ucstring("$")+gnName+"$"; + botNames[rowIdx][0] = wkBotName; + botNames[rowIdx][1] = wkTranslationName; + botNames[rowIdx][2] = wkSheetName; + fctsTitleId = gnName; + + + } + } + + } + + + // look for a corresponding entry + uint gnNameRow; + + + if (!fcts.findRow(fctsIdCol, fctsTitleId, gnNameRow)) + { + + // not found, add it + gnNameRow = fcts.size(); + fcts.resize(fcts.size()+1); + fcts.setData(gnNameRow, ucstring("title_id"), fctsTitleId); + fcts.setData(gnNameRow, ucstring("name"), fctsName); + nbAddGenericName++; + + } + else //Update + { + + } + } + } + + + // 3 - functions + { + nlinfo(" Functions..."); + + set::iterator first(Functions.begin()), last(Functions.end()); + for (; first != last; ++first) + { + string fctName = *first; + // look for a corresponding entry + uint functionRow; + if (!fcts.findRow(fctsIdCol, fctName, functionRow)) + { + // not found, add it + functionRow = fcts.size(); + fcts.resize(fcts.size()+1); + + fcts.setData(functionRow, ucstring("title_id"), fctName); + fcts.setData(functionRow, ucstring("name"), *first); + + nbAddFunction++; + } + } + } + + // display resum\E9 + nlinfo("Adding %u new simple name", nbAddSimpleName); + nlinfo("Adding %u new generic name", nbAddGenericName); + nlinfo("Adding %u new function name", nbAddFunction); + + // saving the modified files + + ucstring s = prepareExcelSheet(botNames); + CI18N::writeTextFile(work_path, s, false); + s = prepareExcelSheet(transBotNames); + CI18N::writeTextFile(trans_path, s, false); + s = prepareExcelSheet(fcts); + CI18N::writeTextFile(work_path, s, false); + + return 0; +} + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp index 6140a3985..233780ca5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp @@ -19,6 +19,8 @@ #include #include +int extractBotNamesAll(map > config_paths, string ligo_class_file, string trans_path, string work_path); + namespace Plugin { TranslationManagerPlugin::~TranslationManagerPlugin() @@ -54,7 +56,39 @@ void TranslationManagerPlugin::extensionsInitialized() QAction *aboutQtAction = menuManager->action(Core::Constants::ABOUT_QT); helpMenu->addSeparator(); helpMenu->insertAction(aboutQtAction, aboutTManPlugin); - menuManager->menuBar()->addMenu("Translation Manager"); + QMenu *transMenu = menuManager->menuBar()->addMenu("Translation Manager"); + /* Words extraction*/ + QAction *botnamesAct = new QAction("Extract bot_names", this); + connect(botnamesAct, SIGNAL(triggered()), this, SLOT(extractBotNames())); + transMenu->addAction(botnamesAct); +} + +void TranslationManagerPlugin::extractBotNames() +{ + // prepare the config paths + list paths,pathsR, georges, filters, languages; + string ligo, translation, work; + map > config_paths; + + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup("translationmanager"); + + paths = ConvertQStringList(settings->value("paths").toStringList()); /* paths */ + config_paths["paths"] = paths; + pathsR = ConvertQStringList(settings->value("pathsR").toStringList()); /* pathsR */ + config_paths["pathsR"] = pathsR; + georges = ConvertQStringList(settings->value("georges").toStringList()); /* georges */ + config_paths["georges"] = georges; + filters = ConvertQStringList(settings->value("filters").toStringList()); /* filters */ + config_paths["filters"] = filters; + languages = ConvertQStringList(settings->value("languages").toStringList()); /* languages */ + ligo = settings->value("ligo").toString().toStdString(); + translation = settings->value("translation").toString().toStdString(); + work = settings->value("work").toString().toStdString(); + settings->endGroup(); + + extractBotNamesAll(config_paths, ligo, translation, work); + } void TranslationManagerPlugin::setNelContext(NLMISC::INelContext *nelContext) @@ -67,6 +101,17 @@ void TranslationManagerPlugin::setNelContext(NLMISC::INelContext *nelContext) _LibContext = new NLMISC::CLibraryContext(*nelContext); } +list TranslationManagerPlugin::ConvertQStringList(QStringList listq) +{ + std::list stdlist; + Q_FOREACH(QString text, listq) + { + stdlist.push_back(text.toStdString()); + } + + return stdlist; +} + QString TranslationManagerPlugin::name() const { return "Translation Manager"; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h index c1bfc2548..07bf0d434 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h @@ -13,6 +13,8 @@ #include #include +using namespace std; + namespace NLMISC { class CLibraryContext; @@ -56,6 +58,11 @@ protected: private: ExtensionSystem::IPluginManager *_plugMan; QList _autoReleaseObjects; + list ConvertQStringList(QStringList list); + + +private Q_SLOTS: + void extractBotNames(); }; class CTranslationManagerContext: public Core::IContext @@ -87,6 +94,7 @@ public: } CSimpleViewer *m_simpleViewer; + }; } // namespace Plugin diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp index c3e4883d4..b3a731ae5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp @@ -18,15 +18,21 @@ #include "translation_manager_settings_page.h" // Qt includes +#include #include +#include +#include // NeL includes // Project includes +#include "../core/icore.h" namespace Plugin { +QString lastDir = "."; + CTranslationManagerSettingsPage::CTranslationManagerSettingsPage(QObject *parent) : IOptionsPage(parent), _currentPage(NULL) @@ -57,11 +63,248 @@ QWidget *CTranslationManagerSettingsPage::createPage(QWidget *parent) { _currentPage = new QWidget(parent); _ui.setupUi(_currentPage); + readSettings(); + connect(_ui.paths_add, SIGNAL(clicked()), this, SLOT(pathAdd())); + connect(_ui.paths_del, SIGNAL(clicked()), this, SLOT(pathDel())); + connect(_ui.pathsR_add, SIGNAL(clicked()), this, SLOT(pathRAdd())); + connect(_ui.pathsR_del, SIGNAL(clicked()), this, SLOT(pathRDel())); + connect(_ui.georges_add, SIGNAL(clicked()), this, SLOT(georgeAdd())); + connect(_ui.georges_del, SIGNAL(clicked()), this, SLOT(georgeDel())); + connect(_ui.filter_add, SIGNAL(clicked()), this, SLOT(filterAdd())); + connect(_ui.filter_del, SIGNAL(clicked()), this, SLOT(filterDel())); + connect(_ui.lang_add, SIGNAL(clicked()), this, SLOT(languageAdd())); + connect(_ui.lang_del, SIGNAL(clicked()), this, SLOT(languageDel())); + connect(_ui.translation_add, SIGNAL(clicked()), this, SLOT(translationAdd())); + connect(_ui.work_add, SIGNAL(clicked()), this, SLOT(workAdd())); + return _currentPage; } +void CTranslationManagerSettingsPage::pathAdd() +{ + QString newPath = QFileDialog::getExistingDirectory(_currentPage, "", lastDir); + if (!newPath.isEmpty()) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(newPath); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.paths_list->addItem(newItem); + lastDir = newPath; + } +} + +void CTranslationManagerSettingsPage::pathDel() +{ + QListWidgetItem *removeItem = _ui.paths_list->takeItem(_ui.paths_list->currentRow()); + if (!removeItem) + delete removeItem; +} + +void CTranslationManagerSettingsPage::pathRAdd() +{ + QString newPath = QFileDialog::getExistingDirectory(_currentPage, "", lastDir); + if (!newPath.isEmpty()) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(newPath); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.pathsR_list->addItem(newItem); + lastDir = newPath; + } +} + +void CTranslationManagerSettingsPage::pathRDel() +{ + QListWidgetItem *removeItem = _ui.pathsR_list->takeItem(_ui.pathsR_list->currentRow()); + if (!removeItem) + delete removeItem; +} + +void CTranslationManagerSettingsPage::georgeAdd() +{ + QString newPath = QFileDialog::getExistingDirectory(_currentPage, "", lastDir); + if (!newPath.isEmpty()) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(newPath); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.georges_list->addItem(newItem); + lastDir = newPath; + } +} + +void CTranslationManagerSettingsPage::georgeDel() +{ + QListWidgetItem *removeItem = _ui.georges_list->takeItem(_ui.georges_list->currentRow()); + if (!removeItem) + delete removeItem; +} + +void CTranslationManagerSettingsPage::filterAdd() +{ + QString newValue = _ui.filter_edit->text(); + if (!newValue.isEmpty()) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(newValue); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.filter_list->addItem(newItem); + } +} + +void CTranslationManagerSettingsPage::filterDel() +{ + QListWidgetItem *removeItem = _ui.filter_list->takeItem(_ui.filter_list->currentRow()); + if (!removeItem) + delete removeItem; +} + +void CTranslationManagerSettingsPage::languageAdd() +{ + QString newValue = _ui.lang_edit->text(); + if (!newValue.isEmpty()) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(newValue); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.lang_list->addItem(newItem); + } +} + +void CTranslationManagerSettingsPage::languageDel() +{ + QListWidgetItem *removeItem = _ui.lang_list->takeItem(_ui.lang_list->currentRow()); + if (!removeItem) + delete removeItem; +} + +void CTranslationManagerSettingsPage::translationAdd() +{ + QString newPath = QFileDialog::getExistingDirectory(_currentPage, ""); + if (!newPath.isEmpty()) + { + _ui.translation_edit->setText(newPath); + } +} + +void CTranslationManagerSettingsPage::workAdd() +{ + QString newPath = QFileDialog::getExistingDirectory(_currentPage, ""); + if (!newPath.isEmpty()) + { + _ui.work_edit->setText(newPath); + } +} + void CTranslationManagerSettingsPage::apply() { + writeSettings(); } +void CTranslationManagerSettingsPage::readSettings() +{ + QStringList paths, pathsR, georges, filters, languages; + QString ligo, translation, work; + + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup("translationmanager"); + + paths = settings->value("paths").toStringList(); /* paths */ + pathsR = settings->value("pathsR").toStringList(); /* pathsR */ + georges = settings->value("georges").toStringList(); /* georges */ + filters = settings->value("filters").toStringList(); /* filters */ + languages = settings->value("languages").toStringList(); /* languages */ + ligo = settings->value("ligo").toString(); + translation = settings->value("translation").toString(); + work = settings->value("work").toString(); + + settings->endGroup(); + /* paths */ + Q_FOREACH(QString path, paths) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(path); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.paths_list->addItem(newItem); + } + /* pathsR */ + Q_FOREACH(QString pathR, pathsR) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(pathR); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.pathsR_list->addItem(newItem); + } + /* georges */ + Q_FOREACH(QString george, georges) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(george); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.georges_list->addItem(newItem); + } + /* filter */ + Q_FOREACH(QString filter, filters) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(filter); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.filter_list->addItem(newItem); + } + /* languages */ + Q_FOREACH(QString lang, languages) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(lang); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.lang_list->addItem(newItem); + } + /* ligo */ + _ui.ligo_edit->setText(ligo); + /* translation */ + _ui.translation_edit->setText(translation); + /* work */ + _ui.work_edit->setText(work); + +} + +void CTranslationManagerSettingsPage::writeSettings() +{ + QStringList paths, pathsR, georges, filters, languages; + QString ligo, translation, work; + /* paths */ + for (int i = 0; i < _ui.paths_list->count(); ++i) + paths << _ui.paths_list->item(i)->text(); + /* pathsR */ + for (int i = 0; i < _ui.pathsR_list->count(); ++i) + pathsR << _ui.pathsR_list->item(i)->text(); + /* georges */ + for (int i = 0; i < _ui.georges_list->count(); ++i) + georges << _ui.georges_list->item(i)->text(); + /* filters */ + for (int i = 0; i < _ui.filter_list->count(); ++i) + filters << _ui.filter_list->item(i)->text(); + /* languages */ + for (int i = 0; i < _ui.lang_list->count(); ++i) + languages << _ui.lang_list->item(i)->text(); + /* ligo path */ + ligo = _ui.ligo_edit->text(); + /* translations path*/ + translation = _ui.translation_edit->text(); + work = _ui.work_edit->text(); + + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup("translationmanager"); + settings->setValue("paths", paths); + settings->setValue("pathsR", pathsR); + settings->setValue("georges", georges); + settings->setValue("filters", filters); + settings->setValue("languages", languages); + settings->setValue("ligo", ligo); + settings->setValue("translation", translation); + settings->setValue("work", work); + settings->endGroup(); +} + + } /* namespace Plugin */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h index 53f9068e1..4fec51fb6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h @@ -47,10 +47,24 @@ public: virtual void apply(); virtual void finish() {} - +private Q_SLOTS: + void pathAdd(); + void pathDel(); + void pathRAdd(); + void pathRDel(); + void georgeAdd(); + void georgeDel(); + void filterAdd(); + void filterDel(); + void languageAdd(); + void languageDel(); + void translationAdd(); + void workAdd(); private: QWidget *_currentPage; Ui::CTranslationManagerSettingsPage _ui; + void writeSettings(); + void readSettings(); }; } // namespace Plugin diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui index 951be0615..c58533185 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui @@ -1,92 +1,393 @@ - - - CTranslationManagerSettingsPage - - - - 0 - 0 - 458 - 479 - - - - Form - - - - 0 - - - - - GroupBox - - - - - - PushButton - - - - - - - - - - PushButton - - - - - - - RadioButton - - - - - - - RadioButton - - - - - - - CheckBox - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - - - - - + + + CTranslationManagerSettingsPage + + + + 0 + 0 + 490 + 495 + + + + Form + + + + + + 1 + + + + Core paths + + + + + + + + + + Paths + + + + + + + Qt::Horizontal + + + + 318 + 20 + + + + + + + + dwadwadwa + + + + :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png + + + Qt::ToolButtonIconOnly + + + true + + + + + + + ... + + + + :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png + + + true + + + + + + + + + + + + + + + + + + Paths non recursives + + + + + + + Qt::Horizontal + + + + 218 + 20 + + + + + + + + + + + + :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png + + + true + + + + + + + ... + + + + :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png + + + true + + + + + + + + + + + + + + + + + + Georges Paths + + + + + + + Qt::Horizontal + + + + 258 + 20 + + + + + + + + + + + + :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png + + + true + + + + + + + + + + + :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png + + + true + + + + + + + + + + + + + + + Translation files paths + + + + + 9 + 230 + 450 + 201 + + + + + + + Ligo class file - This is the name of the world_editor_classes.xml file. + + + + + + + + + + Work directory + + + + + + + + + + + + ... + + + + + + + + + Translation directory + + + + + + + + + + + + ... + + + + + + + + + + + 9 + 10 + 211 + 221 + + + + + + + Filters + + + + + + + + + + + + + + :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png + + + true + + + + + + + + + + + :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png + + + true + + + + + + + + + + + + 240 + 10 + 221 + 221 + + + + + + + Languages + + + + + + + + + + + + + + :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png + + + true + + + + + + + + + + + :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png + + + true + + + + + + + + + + + + + + + + + + +