diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/CMakeLists.txt index 3babfdab1..426d3aa61 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/CMakeLists.txt @@ -6,10 +6,9 @@ ADD_SUBDIRECTORY(log) ADD_SUBDIRECTORY(disp_sheet_id) ADD_SUBDIRECTORY(object_viewer) ADD_SUBDIRECTORY(georges_editor) - +ADD_SUBDIRECTORY(translation_manager) # Note: Temporarily disabled until development continues. #ADD_SUBDIRECTORY(zone_painter) - # Ryzom Specific Plugins IF(WITH_RYZOM AND WITH_RYZOM_TOOLS) ADD_SUBDIRECTORY(mission_compiler) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_constants.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_constants.h index d1b4e902d..6eb7d41f4 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_constants.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_constants.h @@ -91,8 +91,8 @@ const char *const DATA_PATH_SECTION = "DataPath"; const char *const SEARCH_PATHS = "SearchPaths"; const char *const RECURSIVE_SEARCH_PATHS = "RecursiveSearchPathes"; const char *const LEVELDESIGN_PATH = "LevelDesignPath"; -const char *const ASSETS_PATH = "AssetsPath"; const char *const PRIMITIVES_PATH = "PrimitivesPath"; +const char * const ASSETS_PATH = "AssetsPath"; const char *const LIGOCONFIG_FILE = "LigoConfigFile"; const char *const REMAP_EXTENSIONS = "RemapExtensions"; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_main_window.cpp index 769c09e40..416a418f1 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_main_window.cpp @@ -26,6 +26,8 @@ #include #include +#include + using namespace MissionCompiler::Constants; MissionCompilerMainWindow::MissionCompilerMainWindow(QWidget *parent) : @@ -379,7 +381,7 @@ bool MissionCompilerMainWindow::parsePrimForMissions(NLLIGO::IPrimitive const *p { std::string value; // if the node is a mission parse it - if (prim->getPropertyByName("class",value) && !NLMISC::stricmp(value.c_str(),"mission") ) + if (prim->getPropertyByName("class",value) && !stricmp(value.c_str(),"mission") ) { std::string name; prim->getPropertyByName("name",name); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_manager.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_manager.h index 8348fae0c..7b06734f2 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_manager.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/object_viewer/scheme_manager.h @@ -25,7 +25,7 @@ namespace NL3D { -class CPSAttribMakerBase; + class CPSAttribMakerBase; } namespace NLQT @@ -50,11 +50,12 @@ public: void remove(NL3D::CPSAttribMakerBase *am); // rename a scheme, given a pointer on it void rename(NL3D::CPSAttribMakerBase *am, const std::string &newName); -protected: +protected: + // typedef std::pair TSchemeInfo; typedef std::multimap TSchemeMap; - TSchemeMap _SchemeMap; + TSchemeMap _SchemeMap; }; } /* namespace NLQT */ -#endif \ No newline at end of file +#endif 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 new file mode 100644 index 000000000..0f520c9d8 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt @@ -0,0 +1,53 @@ +INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${LIBXML2_INCLUDE_DIR} + ${QT_INCLUDES}) + +FILE(GLOB SRC *.cpp *.h) + +SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_manager.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h) + +SET(OVQT_PLUG_TRANSLATION_MANAGER_HDR translation_manager_plugin.h + translation_manager_main_window.h + translation_manager_settings_page.h + translation_manager_editor.h + source_selection.h + ftp_selection.h + editor_worksheet.h + editor_phrase.h + extract_new_sheet_names.h + extract_bot_names.h) + +SET(OVQT_PLUG_TRANSLATION_MANAGER_UIS translation_manager_settings_page.ui + translation_manager_main_window.ui + source_selection.ui + ftp_selection.ui) + +SET(OVQT_PLUG_TRANSLATION_MANAGER_RCS ftp_selection.qrc) + +SET(QT_USE_QTGUI TRUE) +SET(QT_USE_QTOPENGL TRUE) +SET(QT_USE_QTNETWORK TRUE) + +QT4_WRAP_CPP(OVQT_PLUG_TRANSLATION_MANAGER_MOC_SRC ${OVQT_PLUG_TRANSLATION_MANAGER_HDR}) +QT4_WRAP_UI(OVQT_PLUG_TRANSLATION_MANAGER_UI_HDRS ${OVQT_PLUG_TRANSLATION_MANAGER_UIS}) + +SOURCE_GROUP(QtResources FILES ${OVQT_PLUG_TRANSLATION_MANAGER_UIS}) +SOURCE_GROUP(QtGeneratedUiHdr FILES ${OVQT_PLUG_TRANSLATION_MANAGER_UI_HDRS}) +SOURCE_GROUP(QtGeneratedMocSrc FILES ${OVQT_PLUG_TRANSLATION_MANAGER_MOC_SRC}) +SOURCE_GROUP("Translation Manager Plugin" FILES ${SRC}) +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 nelligo nelgeorges ${QT_LIBRARIES} ${QT_QTOPENGL_LIBRARY} ${QT_QTNETWORK_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) +NL_ADD_LIB_SUFFIX(ovqt_plugin_translation_manager) + +ADD_DEFINITIONS(${LIBXML2_DEFINITIONS} -DQT_PLUGIN -DQT_SHARED ${QT_DEFINITIONS}) + +INSTALL(TARGETS ovqt_plugin_translation_manager LIBRARY DESTINATION lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib COMPONENT tools3d) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/README b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/README index c5c895519..b182bfdcf 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/README +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/README @@ -1,3 +1,5 @@ -OVQT Translation Manager plugin --------------------------------- +Translation Manager Plugin +-------------------------- +GSoC 2011 Project http://dev.ryzom.com/wiki/ryzom/OVQTTranslationPluginGSoc2011 + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp new file mode 100644 index 000000000..c1633c3be --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp @@ -0,0 +1,140 @@ +// Translation Manager Plugin - OVQT Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Emanuel Costea +// +// 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 . + +// Nel includes +#include "nel/misc/path.h" +#include "nel/misc/diff_tool.h" + +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Project includes +#include "editor_phrase.h" +#include "translation_manager_constants.h" + +using namespace std; + +namespace TranslationManager { + +void CEditorPhrase::open(QString filename) +{ + vector phrases; + if(readPhraseFile(filename.toStdString(), phrases, false)) + { + text_edit = new CTextEdit(this); + text_edit->setUndoStack(current_stack); + SyntaxHighlighter *highlighter = new SyntaxHighlighter(text_edit); + text_edit->setUndoRedoEnabled(true); + text_edit->document()->setUndoRedoEnabled(true); + setWidget(text_edit); + // read the file content + QFile file(filename); + file.open(QIODevice::ReadOnly | QIODevice::Text); + QTextStream in(&file); + // set the file content to the text edit + QString data = in.readAll(); + text_edit->append(data); + // window settings + setCurrentFile(filename); + setAttribute(Qt::WA_DeleteOnClose); + editor_type = Constants::ED_PHRASE; + current_file = filename; + connect(text_edit->document(), SIGNAL(contentsChanged()), this, SLOT(docContentsChanged())); + connect(text_edit->document(), SIGNAL(undoCommandAdded()), this, SLOT(newUndoCommandAdded())); + } else { + QErrorMessage error; + error.showMessage("This file is not a phrase file."); + error.exec(); + } +} + +void CEditorPhrase::newUndoCommandAdded() +{ + current_stack->push(new CUndoPhraseNewCommand(text_edit)); +} + +void CEditorPhrase::docContentsChanged() +{ + setWindowModified(true); +} + +void CEditorPhrase::activateWindow() +{ + showMaximized(); +} + +void CEditorPhrase::save() +{ + saveAs(current_file); +} + +void CEditorPhrase::saveAs(QString filename) +{ + QFile file(filename); + file.open(QIODevice::WriteOnly | QIODevice::Text); + QTextStream out(&file); + out.setCodec("UTF-8"); + out.setGenerateByteOrderMark(true); + out<toPlainText(); + current_file = filename; + setCurrentFile(current_file); +} + + + +void CEditorPhrase::closeEvent(QCloseEvent *event) +{ + if(isWindowModified()) + { + QMessageBox msgBox; + msgBox.setText("The document has been modified."); + msgBox.setInformativeText("Do you want to save your changes?"); + msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Save); + int ret = msgBox.exec(); + switch (ret) + { + case QMessageBox::Save: + save(); + event->accept(); + close(); + break; + case QMessageBox::Discard: + event->accept(); + close(); + break; + case QMessageBox::Cancel: + event->ignore(); + break; + default: + break; + } + } else { + event->accept(); + close(); + } +} + +} \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h new file mode 100644 index 000000000..f26dec73e --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h @@ -0,0 +1,189 @@ +// Translation Manager Plugin - OVQT Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Emanuel Costea +// +// 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 . + +#ifndef EDITOR_PHRASE_H +#define EDITOR_PHRASE_H + +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Project includes +#include "translation_manager_editor.h" + +namespace TranslationManager { + +class CTextEdit : public QTextEdit +{ + Q_OBJECT +private: + QUndoStack* m_undoStack; +public: + CTextEdit(QWidget* parent = 0) : QTextEdit(parent) + { + setUndoRedoEnabled(true); + } + //void keyPressEvent(QKeyEvent *event); + void setUndoStack(QUndoStack* undoStack) + { + m_undoStack = undoStack; + } +}; + +class CEditorPhrase : public CEditor +{ + Q_OBJECT +public: + CTextEdit *text_edit; +public: + CEditorPhrase(QMdiArea* parent) : CEditor(parent) {} + CEditorPhrase() : CEditor() {} + void open(QString filename); + void save(); + void saveAs(QString filename); + void activateWindow(); + void closeEvent(QCloseEvent *event); +public Q_SLOTS: + void docContentsChanged(); + void newUndoCommandAdded(); + +}; + +class CUndoPhraseNewCommand : public QUndoCommand +{ +public: + CUndoPhraseNewCommand(CTextEdit *textEdit, QUndoCommand *parent = 0) + : QUndoCommand("Inserting/Removing characters", parent), + m_textEdit(textEdit) + { } + + ~CUndoPhraseNewCommand() {} + + void undo() + { + m_textEdit->undo(); + } + + void redo() + { + m_textEdit->redo(); + } +private: + CTextEdit* m_textEdit; +}; + +class SyntaxHighlighter : public QSyntaxHighlighter +{ +public: + SyntaxHighlighter(QTextEdit *parent) : QSyntaxHighlighter(parent) + { + HighlightingRule rule; + + translateStringFormat.setFontWeight(QFont::Bold); + translateStringFormat.setForeground(Qt::darkMagenta); + rule.pattern = QRegExp("\\[.+\\]"); + rule.format = translateStringFormat; + highlightingRules.append(rule); + + + singleLineCommentFormat.setForeground(Qt::red); + rule.pattern = QRegExp("//[^\n]*"); + rule.format = singleLineCommentFormat; + highlightingRules.append(rule); + + multiLineCommentFormat.setForeground(Qt::red); + + quotationFormat.setForeground(Qt::darkGreen); + rule.pattern = QRegExp("\".*\""); + rule.format = quotationFormat; + highlightingRules.append(rule); + + functionFormat.setFontItalic(true); + functionFormat.setForeground(Qt::blue); + rule.pattern = QRegExp("\\(.+\\)"); + rule.format = functionFormat; + highlightingRules.append(rule); + + commentStartExpression = QRegExp("/\\*"); + commentEndExpression = QRegExp("\\*/"); + } + + void highlightBlock(const QString &text) + { + Q_FOREACH(const HighlightingRule &rule, highlightingRules) { + QRegExp expression(rule.pattern); + int index = expression.indexIn(text); + while (index >= 0) { + int length = expression.matchedLength(); + setFormat(index, length, rule.format); + index = expression.indexIn(text, index + length); + } + } + setCurrentBlockState(0); + + int startIndex = 0; + if (previousBlockState() != 1) + startIndex = commentStartExpression.indexIn(text); + + while (startIndex >= 0) { + int endIndex = commentEndExpression.indexIn(text, startIndex); + int commentLength; + if (endIndex == -1) { + setCurrentBlockState(1); + commentLength = text.length() - startIndex; + } else { + commentLength = endIndex - startIndex + + commentEndExpression.matchedLength(); + } + setFormat(startIndex, commentLength, multiLineCommentFormat); + startIndex = commentStartExpression.indexIn(text, startIndex + commentLength); + } + } + + private: + struct HighlightingRule + { + QRegExp pattern; + QTextCharFormat format; + }; + QVector highlightingRules; + + QRegExp commentStartExpression; + QRegExp commentEndExpression; + + QTextCharFormat keywordFormat; + QTextCharFormat classFormat; + QTextCharFormat singleLineCommentFormat; + QTextCharFormat multiLineCommentFormat; + QTextCharFormat quotationFormat; + QTextCharFormat functionFormat; + QTextCharFormat translateStringFormat; +}; + +} + +#endif /* EDITOR_PHRASE_H */ \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp new file mode 100644 index 000000000..c8a101e0f --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp @@ -0,0 +1,510 @@ +// Translation Manager Plugin - OVQT Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Emanuel Costea +// +// 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 . + +// Qt includes +#include +#include +#include +#include +#include +#include +#include + +// Project includes +#include "editor_worksheet.h" +#include "extract_bot_names.h" +#include "translation_manager_constants.h" +#include + +using namespace std; + +namespace TranslationManager { + +void CEditorWorksheet::open(QString filename) +{ + STRING_MANAGER::TWorksheet wk_file; + if(loadExcelSheet(filename.toStdString(), wk_file, true) == true) + { + bool hasHashValue = false; + table_editor = new QTableWidget(); + if(wk_file.getData(0, 0) == ucstring("*HASH_VALUE")) + { + table_editor->setColumnCount(wk_file.ColCount - 1); + hasHashValue = true; + } else { + table_editor->setColumnCount(wk_file.ColCount); + } + table_editor->setRowCount(wk_file.size() - 1); + + // read columns name + for(unsigned int i = 0; i < wk_file.ColCount; i++) + { + if(hasHashValue && i == 0) + { + // we don't show the column with hash value + } else { + QTableWidgetItem *col = new QTableWidgetItem(); + ucstring col_name = wk_file.getData(0, i); + col->setText(QString(col_name.toString().c_str())); + if(hasHashValue) + { + table_editor->setHorizontalHeaderItem(i - 1, col); + } else { + table_editor->setHorizontalHeaderItem(i, col); + } + } + } + + // read rows + for(unsigned int i = 1; i < wk_file.size(); i++) + { + for(unsigned int j = 0; j < wk_file.ColCount; j++) + { + if(hasHashValue && j == 0) + { + // we don't show the column with hash value + } else { + QTableWidgetItem *row = new QTableWidgetItem(); + ucstring row_value = wk_file.getData(i, j); + row->setText(QString::fromUtf8(row_value.toUtf8().c_str())); + if(hasHashValue) + { + table_editor->setItem(i - 1, j - 1, row); + } else { + table_editor->setItem(i - 1, j, row); + } + } + } + } + setCurrentFile(filename); + setAttribute(Qt::WA_DeleteOnClose); + setWidget(table_editor); + editor_type = Constants::ED_SHEET; + table_editor->resizeColumnsToContents(); + table_editor->resizeRowsToContents(); + // set editor signals + connect(table_editor, SIGNAL(itemChanged(QTableWidgetItem*) ), this, SLOT(worksheetEditorChanged(QTableWidgetItem*))); + connect(table_editor, SIGNAL(itemDoubleClicked(QTableWidgetItem*) ), this, SLOT(worksheetEditorCellEntered(QTableWidgetItem*))); + connect (table_editor,SIGNAL(customContextMenuRequested(const QPoint &)), this,SLOT(contextMenuEvent(QContextMenuEvent*))); + } else { + QErrorMessage error; + error.showMessage("This file is not a worksheet file."); + error.exec(); + } + +} + + +void CEditorWorksheet::contextMenuEvent(QContextMenuEvent *e) +{ + QAction *insertRowAct = new QAction("Insert new row", this); + connect(insertRowAct, SIGNAL(triggered()), this, SLOT(insertRow())); + QAction *deleteRowAct = new QAction("Delete row", this); + connect(deleteRowAct, SIGNAL(triggered()), this, SLOT(deleteRow())); + + QMenu *contextMenu = new QMenu(this); + contextMenu->addAction(insertRowAct); + contextMenu->addAction(deleteRowAct); + contextMenu->exec( e->globalPos() ); + delete contextMenu; + contextMenu = NULL; +} + + +void CEditorWorksheet::activateWindow() +{ + showMaximized(); +} + +void CEditorWorksheet::save() +{ + saveAs(current_file); +} + +void CEditorWorksheet::saveAs(QString filename) +{ + STRING_MANAGER::TWorksheet new_file, wk_file; + loadExcelSheet(current_file.toStdString(), wk_file, true); + // set columns + new_file.resize(new_file.size() + 1); + for(unsigned int i = 0; i < wk_file.ColCount; i++) + { + ucstring col_name = wk_file.getData(0, i); + new_file.insertColumn(new_file.ColCount); + new_file.setData(0, new_file.ColCount - 1, col_name); + } + // read all the rows from table + uint rowIdx; + uint colIdx = 0; + bool hasHashValue = false; + if(wk_file.getData(0, 0) == ucstring("*HASH_VALUE")) + { + hasHashValue = true; + colIdx = 1; + } + for(int i = 0; i < table_editor->rowCount(); i++) + { + rowIdx = new_file.size(); + new_file.resize(new_file.size() + 1); + ucstring tvalue; + for(int j = 0; j < table_editor->columnCount(); j++) + { + QTableWidgetItem* item = table_editor->item(i, j); + tvalue.fromUtf8(std::string(item->text().toUtf8())); + new_file.setData(rowIdx, j + colIdx, tvalue); + } + } + if(hasHashValue) + { + // rewrite the hash codes + makeHashCode(wk_file, true); + } + ucstring s = prepareExcelSheet(new_file); + NLMISC::CI18N::writeTextFile(filename.toStdString(), s, false); + current_file = filename; + setCurrentFile(filename); +} + +void CEditorWorksheet::insertRow() +{ + int last_row = table_editor->rowCount(); + current_stack->push(new CUndoWorksheetNewCommand(table_editor, last_row)); +} + +void CEditorWorksheet::deleteRow() +{ + int selected_row = table_editor->currentRow(); + QMessageBox msgBox; + msgBox.setText(tr("The row will be deleted.")); + msgBox.setInformativeText(tr("Do you want to delete the selected row ?")); + msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes); + msgBox.setDefaultButton(QMessageBox::No); + int ret = msgBox.exec(); + if(ret == QMessageBox::Yes) + { + current_stack->push(new CUndoWorksheetDeleteCommand(table_editor, selected_row)); + } + + table_editor->clearFocus(); + table_editor->clearSelection(); + return; +} + +void CEditorWorksheet::worksheetEditorCellEntered(QTableWidgetItem * item) +{ + temp_content = item->text(); + current_stack->push(new CUndoWorksheetCommand(table_editor, item, temp_content)); +} + +void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item) +{ + if(temp_content != item->text()) + { + //current_stack->push(new CUndoWorksheetCommand(table_editor, item, temp_content)); + } + + if(!isWindowModified()) + setWindowModified(true); +} + + +void CEditorWorksheet::extractBotNames(list filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig) +{ + bool modified = false; + QList new_items; + + ExtractBotNames ebn; + ebn.setRequiredSettings(filters, level_design_path); + ebn.extractBotNamesFromPrimitives(ligoConfig); + // get SimpleNames + { + map SimpleNames = ebn.getSimpleNames(); + map::iterator it(SimpleNames.begin()), last(SimpleNames.end()); + + for (; it != last; ++it) + { + QList search_results = table_editor->findItems(QString(it->first.c_str()), Qt::MatchExactly); + if(search_results.size() == 0) + { + QList records; + records.push_back(QString(it->first.c_str())); + records.push_back(QString(it->first.c_str())); + records.push_back(QString(it->second.SheetName.c_str())); + insertTableRecords(records, new_items); + if(!modified) modified = true; + } + } + ebn.cleanSimpleNames(); + } + // get GenericNames + { + set GenericNames = ebn.getGenericNames(); + set::iterator it(GenericNames.begin()), last(GenericNames.end()); + for (; it != last; ++it) + { + string gnName = "gn_" + ebn.cleanupName(*it); + QList search_results = table_editor->findItems(QString((*it).c_str()), Qt::MatchExactly); + if(search_results.size() == 0) + { + QList records; + records.push_back(QString((*it).c_str())); + records.push_back(QString(gnName.c_str())); + records.push_back(" "); + insertTableRecords(records, new_items); + if(!modified) modified = true; + } + } + ebn.cleanGenericNames(); + } + + current_stack->push(new CUndoWorksheetExtraction(new_items, table_editor)); + if(modified) + { + setWindowModified(true); + table_editor->scrollToBottom(); + } + +} + +void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordListBuilder& wordListBuilder) +{ + uint i; + + // **** Load the excel sheet + // load + TWorksheet workSheet; + if(!loadExcelSheet(filename.toStdString(), workSheet, true)) + { + nlwarning("Error reading '%s'. Aborted", filename.toStdString().c_str()); + return; + } + // get the key column index + uint keyColIndex = 0; + if(!workSheet.findCol(columnId.toStdString(), keyColIndex)) + { + nlwarning("Error: Don't find the column '%s'. '%s' Aborted", columnId.toStdString().c_str(), filename.toStdString().c_str()); + return; + } + // get the name column index + uint nameColIndex; + if(!workSheet.findCol(ucstring("name"), nameColIndex)) + { + nlwarning("Error: Don't find the column 'name'. '%s' Aborted", filename.toStdString().c_str()); + return; + } + + // **** List all words with the builder given + std::vector allWords; + if(!wordListBuilder.buildWordList(allWords, filename.toStdString())) + { + return; + } + bool modified = false; + QList new_items; + for(i = 0; i < allWords.size(); i++) + { + string keyName = allWords[i]; + QList search_results = table_editor->findItems(QString(keyName.c_str()), Qt::MatchExactly); + if(search_results.size() == 0) + { + int knPos = 0, nPos = 0; + if(workSheet.getData(0, 0) == ucstring("*HASH_VALUE")) + { + knPos = keyColIndex - 1; + nPos = nameColIndex - 1; + } else { + knPos = keyColIndex; + nPos = nameColIndex; + } + + QList records; + records.push_back(QString(keyName.c_str())); + records.push_back(QString("") + QString(keyName.c_str())); + insertTableRecords(records, new_items); + if(!modified) modified = true; + } + } + current_stack->push(new CUndoWorksheetExtraction(new_items, table_editor)); + if(modified) + { + setWindowModified(true); + table_editor->scrollToBottom(); + } +} + +void CEditorWorksheet::insertTableRecords(QList records, QList new_items) +{ + const int currentRow = table_editor->rowCount(); + table_editor->setRowCount(currentRow + 1); + int n = 0; + Q_FOREACH(QString record, records) + { + QTableWidgetItem *rec = new QTableWidgetItem(); + rec->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, n, rec); + CTableWidgetItemStore rec_s(rec, currentRow, n); + new_items.push_back(rec_s); + n++; + } + +} + +bool CEditorWorksheet::compareWorksheetFile(QString filename) +{ + STRING_MANAGER::TWorksheet wk_file; + int colIndex = 0; + if(loadExcelSheet(filename.toStdString(), wk_file, true) == true) + { + if(wk_file.getData(0, 0) == ucstring("*HASH_VALUE")) + { + colIndex = 1; + } + if(wk_file.ColCount - colIndex != table_editor->columnCount()) + { + return false; + } + for(int i = 0; i < table_editor->columnCount(); i++) + { + QString item = table_editor->horizontalHeaderItem(i)->text(); + ucstring itemC = wk_file.getData(0, i+ colIndex); + if(item.toStdString() != itemC.toString()) + { + nlwarning(item.toStdString().c_str()); + nlwarning(itemC.toString().c_str()); + return false; + } + } + } else { + return false; + } + + return true; +} + +void CEditorWorksheet::mergeWorksheetFile(QString filename) +{ + STRING_MANAGER::TWorksheet wk_file; + if(loadExcelSheet(filename.toStdString(), wk_file, true) == true) + { + bool hasHashValue = false; + int colIndex = 0; + if(wk_file.getData(0, 0) == ucstring("*HASH_VALUE")) + { + hasHashValue = true; + colIndex = 1; + } + // read rows + for(unsigned int i = 1; i < wk_file.size(); i++) + { + // search with the first column + ucstring rowId = wk_file.getData(i,colIndex); + QList search_results = table_editor->findItems(QString(rowId.toString().c_str()), Qt::MatchExactly); + if(search_results.size() == 0) + { + const int lastRow = table_editor->rowCount(); + table_editor->setRowCount(lastRow + 1); + for(unsigned int j = 0; j < table_editor->columnCount(); j++) + { + ucstring rowValue = wk_file.getData(i, j + colIndex); // get the value + QTableWidgetItem *row = new QTableWidgetItem(); + row->setText(QString(rowValue.toString().c_str())); // set the value in table item + table_editor->setItem(lastRow, j, row); + } + } + } + } else { + QErrorMessage error; + error.showMessage(tr("This file is not a worksheet file.")); + error.exec(); + } +} + +void CEditorWorksheet::closeEvent(QCloseEvent *event) +{ + if(isWindowModified()) + { + QMessageBox msgBox; + msgBox.setText(tr("The document has been modified.")); + msgBox.setInformativeText(tr("Do you want to save your changes?")); + msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Save); + int ret = msgBox.exec(); + switch (ret) + { + case QMessageBox::Save: + save(); + event->accept(); + close(); + break; + case QMessageBox::Discard: + event->accept(); + close(); + break; + case QMessageBox::Cancel: + event->ignore(); + break; + default: + break; + } + } else { + event->accept(); + close(); + } +} + + +bool CEditorWorksheet::isBotNamesTable() +{ + bool status = true; + if(table_editor->horizontalHeaderItem(0)->text() != "bot name" + || table_editor->horizontalHeaderItem(1)->text() != "translated name" + || table_editor->horizontalHeaderItem(2)->text() != "sheet_name") + { + status = false; + } + + return status; +} + +bool CEditorWorksheet::isSheetTable(QString type) +{ + QString column_name; + if(type.toAscii() == Constants::WK_ITEM) + { + column_name = "item ID"; + } else if(type.toAscii() == Constants::WK_CREATURE) { + column_name = "creature ID"; + } else if(type.toAscii() == Constants::WK_SBRICK) { + column_name = "sbrick ID"; + } else if(type.toAscii() == Constants::WK_SPHRASE) { + column_name = "sphrase ID"; + } else if(type.toAscii() == Constants::WK_PLACE) { + column_name = "placeId"; + } + bool status = true; + if(table_editor->horizontalHeaderItem(0)->text() != column_name + || table_editor->horizontalHeaderItem(1)->text() != "name") + { + status = false; + } + + return status; +} + +} + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h new file mode 100644 index 000000000..487a9eea8 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h @@ -0,0 +1,213 @@ +// Translation Manager Plugin - OVQT Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Emanuel Costea +// +// 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 . + +#ifndef EDITOR_WORKSHEET_H +#define EDITOR_WORKSHEET_H + +// Nel includes +#include "nel/misc/types_nl.h" +#include "nel/misc/sheet_id.h" +#include "nel/misc/path.h" +#include "nel/misc/diff_tool.h" +#include "nel/ligo/ligo_config.h" + +// Qt includes +#include +#include +#include +#include +#include +#include +#include + +// Project includes +#include "translation_manager_editor.h" +#include "extract_new_sheet_names.h" + +namespace TranslationManager { + +struct CTableWidgetItemStore +{ +public: + CTableWidgetItemStore(QTableWidgetItem *item, int row, int column) : + m_item(item), + m_row(row), + m_column(column) { } + QTableWidgetItem *m_item; + int m_row; + int m_column; +}; + +class CEditorWorksheet : public CEditor +{ + Q_OBJECT +private: + QString temp_content; +public: + CEditorWorksheet(QMdiArea* parent) : CEditor(parent) {} + CEditorWorksheet() : CEditor() {} + QTableWidget* table_editor; + void open(QString filename); + void save(); + void saveAs(QString filename); + void activateWindow(); + void mergeWorksheetFile(QString filename); + bool compareWorksheetFile(QString filename); + void extractBotNames(list filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig); + void extractWords(QString filename, QString columnId, IWordListBuilder &wordListBuilder); + void insertTableRecords(QList records, QList new_items); + bool isBotNamesTable(); + bool isSheetTable(QString type); + void closeEvent(QCloseEvent *event); +private Q_SLOTS: + void worksheetEditorCellEntered(QTableWidgetItem * item); + void worksheetEditorChanged(QTableWidgetItem * item); + void insertRow(); + void deleteRow(); + void contextMenuEvent(QContextMenuEvent *e); + +}; + +class CUndoWorksheetCommand : public QUndoCommand +{ +public: + CUndoWorksheetCommand(QTableWidget *table, QTableWidgetItem* item, const QString &ocontent, QUndoCommand *parent = 0) : QUndoCommand("Insert characters in cells", parent), m_table(table), m_item(item), m_ocontent(ocontent) + { + m_ccontent = m_ocontent; + } + + void redo() + { + if(m_item->text() == m_ocontent) + { + m_item->setText(m_ccontent); + } + } + void undo() + { + if(m_item->text() != m_ocontent) + { + m_ccontent = m_item->text(); + } + m_item->setText(m_ocontent); + } +private: + QTableWidget* m_table; + QTableWidgetItem* m_item; + QString m_ocontent; + QString m_ccontent; +}; + +class CUndoWorksheetNewCommand : public QUndoCommand +{ +public: + CUndoWorksheetNewCommand(QTableWidget *table, int rowID, QUndoCommand *parent = 0) : QUndoCommand("Insert a new row", parent), m_table(table), m_rowID(rowID) + { } + + void redo() + { + m_table->setRowCount(m_rowID + 1); + for(int j = 0; j < m_table->columnCount(); j++) + { + QTableWidgetItem* item = new QTableWidgetItem(); + m_table->setItem(m_rowID, j, item); + m_table->scrollToBottom(); + } + } + + void undo() + { + m_table->removeRow(m_rowID); + } +private: + QTableWidget* m_table; + int m_rowID; + +}; + +class CUndoWorksheetExtraction : public QUndoCommand +{ +public: + CUndoWorksheetExtraction(QList items, QTableWidget *table, QUndoCommand *parent = 0) : QUndoCommand("Word extraction", parent), + m_items(items), + m_table(table) + { } + + void redo() + { + Q_FOREACH(CTableWidgetItemStore is, m_items) + { + m_table->setItem(is.m_row, is.m_column, is.m_item); + } + + } + + void undo() + { + Q_FOREACH(CTableWidgetItemStore is, m_items) + { + m_table->setItem(is.m_row, is.m_column, is.m_item); + m_table->takeItem(is.m_row, is.m_column); + } + + } + +private: + QList m_items; + QTableWidget* m_table; +}; + +class CUndoWorksheetDeleteCommand : public QUndoCommand +{ +public: + CUndoWorksheetDeleteCommand(QTableWidget *table, int rowID, QUndoCommand *parent = 0) : QUndoCommand("Delete row", parent), m_table(table), m_rowID(rowID) + { } + + void redo() + { + for(int i = 0; i < m_table->columnCount(); i++) + { + QTableWidgetItem* item = new QTableWidgetItem(); + QTableWidgetItem* table_item = m_table->item(m_rowID, i); + item->setText(table_item->text()); + m_deletedItems.push_back(item); + } + m_table->removeRow(m_rowID); + } + + void undo() + { + int lastRow = m_table->rowCount(); + m_table->setRowCount(m_table->rowCount() + 1); + int i = 0; + Q_FOREACH(QTableWidgetItem* item, m_deletedItems) + { + m_table->setItem(lastRow, i, item); + i++; + } + m_deletedItems.clear(); + } + +private: + QList m_deletedItems; + QTableWidget* m_table; + int m_rowID; +}; + +} +#endif /* EDITOR_WORKSHEET_H */ + 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..e8ed68bbf --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_bot_names.cpp @@ -0,0 +1,379 @@ +// Translation Manager Plugin - OVQT Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Emanuel Costea +// +// 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 "extract_bot_names.h" + + +static bool RemoveOlds = false; + + + + +namespace TranslationManager +{ + +TCreatureInfo *ExtractBotNames::getCreature(const std::string &sheetName) +{ + CSheetId id(sheetName+".creature"); + + if (Creatures.find(id) != Creatures.end()) + return &(Creatures.find(id)->second); + else + return NULL; +} + +string ExtractBotNames::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; +} + + + + + +set ExtractBotNames::getGenericNames() +{ + return GenericNames; +} + +map ExtractBotNames::getSimpleNames() +{ + return SimpleNames; +} + +void ExtractBotNames::cleanSimpleNames() +{ + SimpleNames.clear(); +} + +void ExtractBotNames::cleanGenericNames() +{ + GenericNames.clear(); +} + +string ExtractBotNames::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 ExtractBotNames::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 ExtractBotNames::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)); + } +} + +void ExtractBotNames::setRequiredSettings(list filters, string level_design_path) +{ + for (std::list::iterator it = filters.begin(); it != 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()) + { + loadForm("creature", PACKED_SHEETS_NAME, Creatures, true); + } + +} + +void ExtractBotNames::extractBotNamesFromPrimitives(CLigoConfig 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 + { + addSimpleName(removeAndStoreFunction(name), sheetStr); + } + } + } + } +} + +} \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_bot_names.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_bot_names.h new file mode 100644 index 000000000..df1cb39ca --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_bot_names.h @@ -0,0 +1,111 @@ +// Translation Manager Plugin - OVQT Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Emanuel Costea +// +// 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 . + +#ifndef EXTRACT_BOT_NAMES_H +#define EXTRACT_BOT_NAMES_H + +#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; + +namespace TranslationManager +{ + +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() + { + } + +}; + +struct TEntryInfo +{ + string SheetName; +}; + +struct ExtractBotNames +{ +private: + vector Filters; + std::map Creatures; + set GenericNames; + map SimpleNames; + set Functions; +private: + TCreatureInfo *getCreature(const std::string &sheetName); + ucstring makeGroupName(const ucstring & translationName); + string removeAndStoreFunction(const std::string &fullName); + void addGenericName(const std::string &name, const std::string &sheetName); + void addSimpleName(const std::string &name, const std::string &sheetName); +public: + void extractBotNamesFromPrimitives(CLigoConfig ligoConfig); + void setRequiredSettings(list filters, string level_design_path); + set getGenericNames(); + map getSimpleNames(); + string cleanupName(const std::string &name); + ucstring cleanupUcName(const ucstring &name); + void cleanSimpleNames(); + void cleanGenericNames(); + +}; + +} + + +#endif /* EXTRACT_BOT_NAMES_H */ + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.cpp new file mode 100644 index 000000000..5d0b9b455 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.cpp @@ -0,0 +1,154 @@ +// 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 "extract_new_sheet_names.h" + +using namespace std; +using namespace NLMISC; +using namespace NLLIGO; +using namespace STRING_MANAGER; + +namespace TranslationManager +{ + + + +// *************************************************************************** +/* + * Specialisation of IWordListBuilder to list sheets in a directory + */ + + +bool CSheetWordListBuilder::buildWordList(std::vector &allWords, string workSheetFileName) + { + SheetExt= toLower(SheetExt); + // verify the directory is correct + if(!CFile::isDirectory(SheetPath)) + { + nlwarning("Error: Directory '%s' not found. '%s' Aborted", SheetPath.c_str(), workSheetFileName.c_str()); + return false; + } + + // list all files. + std::vector allFiles; + allFiles.reserve(100000); + CPath::getPathContent(SheetPath, true, false, true, allFiles, NULL); + + // Keep only the extension we want, and remove "_" (parent) + allWords.clear(); + allWords.reserve(allFiles.size()); + for(uint i=0;i &allWords, string workSheetFileName) + { + // verify the directory is correct + if(!CFile::isDirectory(PrimPath)) + { + nlwarning("Error: Directory '%s' not found. '%s' Aborted", PrimPath.c_str(), workSheetFileName.c_str()); + return false; + } + + // list all files. + std::vector allFiles; + allFiles.reserve(100000); + CPath::getPathContent(PrimPath, true, false, true, allFiles, NULL); + + // parse all primitive that match the filter + allWords.clear(); + allWords.reserve(100000); + // to avoid duplicate + set allWordSet; + for(uint i=0;i setPlace; + TPrimitiveSet placeRes; + setPlace.buildSet(PrimDoc.RootNode, predCont, placeRes); + // for all found + for (uint placeId= 0; placeId < placeRes.size(); ++placeId) + { + string primName; + if(placeRes[placeId]->getPropertyByName(listProp[cid], primName) && !primName.empty()) + { + primName= toLower(primName); + // avoid duplicate + if(allWordSet.insert(primName).second) + { + allWords.push_back(primName); + } + } + } + } + } + + return true; + } + +} \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.h new file mode 100644 index 000000000..ca7295f91 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.h @@ -0,0 +1,72 @@ +// 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 . + +#ifndef EXTRACT_NEW_SHEET_NAMES_H +#define EXTRACT_NEW_SHEET_NAMES_H + +#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/misc/algo.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; + +namespace TranslationManager +{ + + +// *************************************************************************** +/* + * Interface to build the whole list of words (key id) for a specific worksheet + */ +struct IWordListBuilder +{ + virtual bool buildWordList(std::vector &allWords, string workSheetFileName) =0; + +}; + +struct CSheetWordListBuilder : public IWordListBuilder +{ + string SheetExt; + string SheetPath; + + virtual bool buildWordList(std::vector &allWords, string workSheetFileName); +}; + +struct CRegionPrimWordListBuilder : public IWordListBuilder +{ + string PrimPath; + vector PrimFilter; + NLLIGO::CLigoConfig LigoConfig; + virtual bool buildWordList(std::vector &allWords, string workSheetFileName); +}; + +} + + +#endif /* EXTRACT_NEW_SHEET_NAMES_H */ + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.cpp new file mode 100644 index 000000000..41a8072e2 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.cpp @@ -0,0 +1,191 @@ + +#include "ftp_selection.h" + +#include +#include +namespace TranslationManager +{ + CFtpSelection::CFtpSelection(QWidget *parent): QDialog(parent) + { + _ui.setupUi(this); + connect(_ui.connectButton, SIGNAL(clicked()), this, SLOT(ConnectButtonClicked())); + connect(_ui.doneButton, SIGNAL(clicked()), this, SLOT(DoneButtonClicked())); + connect(_ui.cdToParrent, SIGNAL(clicked()), this, SLOT(cdToParent())); + connect(_ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject())); + + // file list + connect(_ui.fileList, SIGNAL(itemActivated(QTreeWidgetItem*,int)),this, SLOT(processItem(QTreeWidgetItem*,int))); + _ui.fileList->setEnabled(false); + _ui.fileList->setRootIsDecorated(false); + _ui.fileList->setHeaderLabels(QStringList() << tr("Name") << tr("Size") << tr("Owner") << tr("Group") << tr("Time")); + _ui.fileList->header()->setStretchLastSection(false); + + // buttons + _ui.cdToParrent->setEnabled(false); + _ui.doneButton->setEnabled(false); + + status = false; + } + + // Connection with the FTP Server. We retrieve the file list. + void CFtpSelection::ConnectButtonClicked() + { + conn = new QFtp(this); + connect(conn, SIGNAL(commandFinished(int,bool)), this, SLOT(FtpCommandFinished(int,bool))); + connect(conn, SIGNAL(listInfo(QUrlInfo)), this, SLOT(AddToList(QUrlInfo))); + #ifndef QT_NO_CURSOR + setCursor(Qt::WaitCursor); + #endif + QUrl url(_ui.url->text()); + if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) { + conn->connectToHost(_ui.url->text(), 21); + conn->login(); + } else { + conn->connectToHost(url.host(), url.port(21)); + + if (!url.userName().isEmpty()) + conn->login(QUrl::fromPercentEncoding(url.userName().toLatin1()), url.password()); + else + conn->login(); + if (!url.path().isEmpty()) + conn->cd(url.path()); + } + } + + // Get the user action. + void CFtpSelection::FtpCommandFinished(int, bool error) + { + #ifndef QT_NO_CURSOR + setCursor(Qt::ArrowCursor); + #endif + if (conn->currentCommand() == QFtp::ConnectToHost) + { + if (error) + { + QMessageBox::information(this, tr("FTP"), + tr("Unable to connect to the FTP server " + "at %1. Please check that the host " + "name is correct.") + .arg(_ui.url->text())); + return; + } + + return; + } + + if (conn->currentCommand() == QFtp::Login) + { + conn->list(); + } + + if (conn->currentCommand() == QFtp::Get) + { + if(error) + { + status = false; + file->close(); + file->remove(); + } else { + file->close(); + status = true; + } + _ui.cancelButton->setEnabled(true); + } + + if (conn->currentCommand() == QFtp::List) + { + if (isDirectory.isEmpty()) { + _ui.fileList->addTopLevelItem(new QTreeWidgetItem(QStringList() << tr(""))); + _ui.fileList->setEnabled(false); + } + } + } + // Make the file list with directories and files + void CFtpSelection::AddToList(const QUrlInfo &urlInfo) + { + QTreeWidgetItem *item = new QTreeWidgetItem; + item->setText(0, urlInfo.name()); + item->setText(1, QString::number(urlInfo.size())); + item->setText(2, urlInfo.owner()); + item->setText(3, urlInfo.group()); + item->setText(4, urlInfo.lastModified().toString("MMM dd yyyy")); + + QPixmap pixmap(urlInfo.isDir() ? ":/translationManager/images/dir.png" : ":/translationManager/images/file.png"); + item->setIcon(0, pixmap); + + isDirectory[urlInfo.name()] = urlInfo.isDir(); + _ui.fileList->addTopLevelItem(item); + if (!_ui.fileList->currentItem()) { + _ui.fileList->setCurrentItem(_ui.fileList->topLevelItem(0)); + _ui.fileList->setEnabled(true); + } + } + + void CFtpSelection::processItem(QTreeWidgetItem* item, int) + { + QString name = item->text(0); + if (isDirectory.value(name)) + { + _ui.fileList->clear(); + isDirectory.clear(); + currentPath += '/'; + currentPath += name; + conn->cd(name); + conn->list(); + #ifndef QT_NO_CURSOR + setCursor(Qt::WaitCursor); + #endif + return; + } + _ui.doneButton->setEnabled(true); + } + + // Exit from a directory + void CFtpSelection::cdToParent() + { + #ifndef QT_NO_CURSOR + setCursor(Qt::WaitCursor); + #endif + _ui.fileList->clear(); + isDirectory.clear(); + currentPath = currentPath.left(currentPath.lastIndexOf('/')); + if (currentPath.isEmpty()) { + _ui.cdToParrent->setEnabled(false); + conn->cd("/"); + } else { + conn->cd(currentPath); + } + conn->list(); + } + + // Done action + void CFtpSelection::DoneButtonClicked() + { + QString fileName = _ui.fileList->currentItem()->text(0); + + if (QFile::exists(fileName)) { + QMessageBox::information(this, tr("FTP"), + tr("There already exists a file called %1 in " + "the current directory.") + .arg(fileName)); + return; + } + + file = new QFile(fileName); + #ifndef QT_NO_CURSOR + setCursor(Qt::WaitCursor); + #endif + if (!file->open(QIODevice::WriteOnly)) { + QMessageBox::information(this, tr("FTP"), + tr("Unable to save the file %1: %2.") + .arg(fileName).arg(file->errorString())); + delete file; + return; + } + _ui.cancelButton->setEnabled(false); + conn->get(_ui.fileList->currentItem()->text(0), file); + + reject(); + } + +} diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.h new file mode 100644 index 000000000..47dcfdb57 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.h @@ -0,0 +1,49 @@ +/* + * File: ftp_selection.h + * Author: cemycc + * + * Created on July 8, 2011, 4:03 PM + */ + +#ifndef FTP_SELECTION_H +#define FTP_SELECTION_H + +#include +#include +#include +#include +#include +#include +#include + +#include "ui_ftp_selection.h" + +using namespace std; + +namespace TranslationManager { + + class CFtpSelection : public QDialog + { + Q_OBJECT + private: + Ui::FtpSelectionDialog _ui; + QFtp *conn; + QHash isDirectory; + QString currentPath; + private Q_SLOTS: + void cdToParent(); + void processItem(QTreeWidgetItem*,int); + void ConnectButtonClicked(); + void DoneButtonClicked(); + void FtpCommandFinished(int, bool error); + void AddToList(const QUrlInfo &urlInfo); + public: + bool status; + QFile *file; + CFtpSelection(QWidget* parent = 0); + ~CFtpSelection() {} + }; +} + +#endif /* FTP_SELECTION_H */ + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.qrc b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.qrc new file mode 100644 index 000000000..bd54366ed --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.qrc @@ -0,0 +1,7 @@ + + + images/cdtoparent.png + images/dir.png + images/file.png + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.ui new file mode 100644 index 000000000..7b3041c04 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.ui @@ -0,0 +1,120 @@ + + + FtpSelectionDialog + + + + 0 + 0 + 640 + 576 + + + + Dialog + + + + + + FTP Server informations + + + + + + + + Ftp server + + + + + + + + + + + + + + :/translationManager/images/cdtoparent.png:/translationManager/images/cdtoparent.png + + + + + + + Connect + + + + + + + + + Content + + + + + + Please select the file + + + + + + + + 1 + + + + + + + + Qt::Vertical + + + + 20 + 378 + + + + + + + + + + + + + Done + + + + + + + Cancel + + + + + + + + + + + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/images/cdtoparent.png b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/images/cdtoparent.png new file mode 100644 index 000000000..24b618082 Binary files /dev/null and b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/images/cdtoparent.png differ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/images/dir.png b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/images/dir.png new file mode 100644 index 000000000..0ce5ae75f Binary files /dev/null and b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/images/dir.png differ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/images/file.png b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/images/file.png new file mode 100644 index 000000000..be6c53089 Binary files /dev/null and b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/images/file.png differ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ovqt_plugin_translation_manager.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ovqt_plugin_translation_manager.xml new file mode 100644 index 000000000..93a7f19bf --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ovqt_plugin_translation_manager.xml @@ -0,0 +1,10 @@ + + ovqt_plugin_translation_manager + TranslationManager + 0.8 + Ryzom Core + Translation Manager plugin. + + + + \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.cpp new file mode 100644 index 000000000..3015b447d --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.cpp @@ -0,0 +1,45 @@ + +#include + +#include "source_selection.h" + +namespace TranslationManager +{ + + +CSourceDialog::CSourceDialog(QWidget *parent): QDialog(parent) +{ + _ui.setupUi(this); + // Set signal and slot for "OK Button" + connect(_ui.ok_button, SIGNAL(clicked()), this, SLOT(OkButtonClicked())); + // Set signal and slot for "Cancel Button" + connect(_ui.cancel_button, SIGNAL(clicked()), this, SLOT(reject())); + _ui.sourceSelectionListWidget->setSortingEnabled(false); + connect(_ui.sourceSelectionListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)), + this, SLOT(itemDoubleClicked(QListWidgetItem *))); +} + +// Insert options in the source dialog. Options like: from FTP Server, from Local directory etc. +void CSourceDialog::setSourceOptions(map options) +{ + map::iterator it; + + for(it = options.begin(); it != options.end(); ++it) + { + _ui.sourceSelectionListWidget->addItem((*it).first); + } +} + +void CSourceDialog::OkButtonClicked() +{ + selected_item = _ui.sourceSelectionListWidget->currentItem(); + accept(); +} + +void CSourceDialog::itemDoubleClicked(QListWidgetItem *item) +{ + selected_item = item; + accept(); +} + +} diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.h new file mode 100644 index 000000000..d32bfcb02 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.h @@ -0,0 +1,37 @@ + + +#ifndef SOURCE_SELECTION_H +#define SOURCE_SELECTION_H + +#include +#include +#include +#include +#include "ui_source_selection.h" +#include + +using namespace std; + +namespace TranslationManager +{ + +class CSourceDialog : public QDialog +{ + Q_OBJECT +private: + Ui::SourceSelectionDialog _ui; +private Q_SLOTS: + void OkButtonClicked(); + void itemDoubleClicked(QListWidgetItem *item); +public: + CSourceDialog(QWidget *parent = 0); + ~CSourceDialog(){} + void setSourceOptions(map options); + QListWidgetItem *selected_item; +}; + +} + + +#endif /* SOURCE_SELECTION_H */ + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.ui new file mode 100644 index 000000000..e64ba78c4 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.ui @@ -0,0 +1,60 @@ + + + SourceSelectionDialog + + + Qt::WindowModal + + + true + + + + 0 + 0 + 316 + 155 + + + + Dialog + + + true + + + + + + Select source for merge operation + + + + + + + + + + + OK + + + + + + + Cancel + + + + + + + + + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_constants.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_constants.h new file mode 100644 index 000000000..dcb91676b --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_constants.h @@ -0,0 +1,30 @@ +/* + * File: translation_manager_constants.h + * Author: cemycc + * + * Created on July 5, 2011, 9:15 PM + */ + +#ifndef TRANSLATION_MANAGER_CONSTANTS_H +#define TRANSLATION_MANAGER_CONSTANTS_H + +namespace TranslationManager +{ + namespace Constants + { + const int ED_SHEET = 1; + const int ED_PHRASE = 2; + + const char * const WK_BOTNAMES = "bot_names_wk.txt"; + const char * const WK_ITEM = "item_words_wk.txt"; + const char * const WK_CREATURE = "creature_words_wk.txt"; + const char * const WK_SBRICK = "sbrick_words_wk.txt"; + const char * const WK_SPHRASE = "sphrase_words_wk.txt"; + const char * const WK_PLACE = "place_words_wk.txt"; + const char * const WK_CONTINENT = "place_words_wk.txt"; + const char * const WK_STABLE = "place_words_wk.txt"; + } +} + +#endif /* TRANSLATION_MANAGER_CONSTANTS_H */ + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h new file mode 100644 index 000000000..bc46769c1 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h @@ -0,0 +1,71 @@ +// Translation Manager Plugin - OVQT Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Emanuel Costea +// +// 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 . + +#ifndef TRANSLATION_MANAGER_EDITOR_H +#define TRANSLATION_MANAGER_EDITOR_H + +#include +#include +#include +#include +#include +#include + +namespace TranslationManager { + +class CEditor : public QMdiSubWindow { +Q_OBJECT +protected: + QUndoStack* current_stack; + QString current_file; + int editor_type; +public: + CEditor(QMdiArea* parent) : QMdiSubWindow(parent) {} + CEditor() : QMdiSubWindow() {} + virtual void open(QString filename) =0; + virtual void save() =0; + virtual void saveAs(QString filename) =0; + virtual void activateWindow() =0; +public: + int eType() + { + return editor_type; + } + QString subWindowFilePath() + { + return current_file; + } + void setUndoStack(QUndoStack* stack) + { + current_stack = stack; + } + void setCurrentFile(QString filename) + { + QFileInfo *file = new QFileInfo(filename); + current_file = file->canonicalFilePath(); + setWindowModified(false); + setWindowTitle(file->fileName() + "[*]"); + setWindowFilePath(current_file); + } + +}; + +} + + +#endif /* TRANSLATION_MANAGER_EDITOR_H */ + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp new file mode 100644 index 000000000..23509bd20 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp @@ -0,0 +1,655 @@ + +// Translation Manager Plugin - OVQT Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Emanuel Costea +// +// 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 . + +// Project system includes +#include "../core/icore.h" +#include "../core/core_constants.h" +#include "../core/menu_manager.h" +#include "../../extension_system/iplugin_spec.h" + +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// Plugin includes +#include "translation_manager_main_window.h" +#include "translation_manager_constants.h" +#include "ftp_selection.h" + + +namespace TranslationManager +{ + +CMainWindow::CMainWindow(QWidget *parent) + : QMainWindow(parent) +{ + _ui.setupUi(this); + + _ui.mdiArea->closeAllSubWindows(); + windowMapper = new QSignalMapper(this); + connect(windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*))); + + initialize_settings["georges"] = false; + initialize_settings["ligo"] = false; + + connect(Core::ICore::instance(), SIGNAL(changeSettings()), this, SLOT(readSettings())); + readSettings(); + createToolbar(); + m_undoStack = new QUndoStack(this); + +} + +// Functions that will insert the plugin buttons +void CMainWindow::createToolbar() +{ + // File menu + openAct = new QAction(QIcon(Core::Constants::ICON_OPEN), "&Open file(s)...", this); + _ui.toolBar->addAction(openAct); + connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + saveAct = new QAction(QIcon(Core::Constants::ICON_SAVE), "&Save...", this); + _ui.toolBar->addAction(saveAct); + connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); + saveAsAct = new QAction(QIcon(Core::Constants::ICON_SAVE_AS), "&Save as...", this); + _ui.toolBar->addAction(saveAsAct); + connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); + + // Tools menu + QMenu *wordsExtractionMenu = new QMenu("&Words extraction..."); + wordsExtractionMenu->setIcon(QIcon(Core::Constants::ICON_SETTINGS)); + _ui.toolBar->addAction(wordsExtractionMenu->menuAction()); + // extract bot names + QAction *extractBotNamesAct = wordsExtractionMenu->addAction("&Extract bot names..."); + extractBotNamesAct->setStatusTip(tr("Extract bot names from primitives.")); + connect(extractBotNamesAct, SIGNAL(triggered()), this, SLOT(extractBotNames())); + // Words extraction + // ----------------------------- + // signal mapper for extraction words + QSignalMapper *wordsExtractionMapper = new QSignalMapper(this); + connect(wordsExtractionMapper, SIGNAL(mapped(QString)), this, SLOT(extractWords(QString))); + // extract item words + QAction *extractItemWordsAct = wordsExtractionMenu->addAction("&Extract item words..."); + extractItemWordsAct->setStatusTip(tr("Extract item words")); + connect(extractItemWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); + wordsExtractionMapper->setMapping(extractItemWordsAct, QString(Constants::WK_ITEM)); + // extract creature words + QAction *extractCreatureWordsAct = wordsExtractionMenu->addAction("&Extract creature words..."); + extractCreatureWordsAct->setStatusTip(tr("Extract creature words")); + connect(extractCreatureWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); + wordsExtractionMapper->setMapping(extractCreatureWordsAct, QString(Constants::WK_CREATURE)); + // extract sbrick words + QAction *extractSbrickWordsAct = wordsExtractionMenu->addAction("&Extract sbrick words..."); + extractSbrickWordsAct->setStatusTip(tr("Extract sbrick words")); + connect(extractSbrickWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); + wordsExtractionMapper->setMapping(extractSbrickWordsAct, QString(Constants::WK_SBRICK)); + // extract sphrase words + QAction *extractSphraseWordsAct = wordsExtractionMenu->addAction("&Extract sphrase words..."); + extractSphraseWordsAct->setStatusTip(tr("Extract sphrase words")); + connect(extractSphraseWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); + wordsExtractionMapper->setMapping(extractSphraseWordsAct, QString(Constants::WK_SPHRASE)); + // extract place and region names + QAction *extractPlaceNamesAct = wordsExtractionMenu->addAction("&Extract place names..."); + extractPlaceNamesAct->setStatusTip(tr("Extract place names from primitives")); + connect(extractPlaceNamesAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); + wordsExtractionMapper->setMapping(extractPlaceNamesAct, QString(Constants::WK_PLACE)); + // Merge options + // ----------------------------- + QAction *mergeSingleFileAct = wordsExtractionMenu->addAction("&Merge worksheet file..."); + mergeSingleFileAct->setStatusTip(tr("Merge worksheet file from local or remote directory")); + connect(mergeSingleFileAct, SIGNAL(triggered()), this, SLOT(mergeSingleFile())); + // Windows menu + Core::ICore *core = Core::ICore::instance(); + Core::MenuManager *menuManager = core->menuManager(); + windowMenu = menuManager->menuBar()->addMenu("Window"); + updateWindowsList(); + connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowsList())); + + // Undo, Redo actions + // ----------------------------- + QAction* undoAction = menuManager->action(Core::Constants::UNDO); + if (undoAction != 0) + _ui.toolBar->addAction(undoAction); + + QAction* redoAction = menuManager->action(Core::Constants::REDO); + if (redoAction != 0) + _ui.toolBar->addAction(redoAction); +} + +// Update the toolbar if the editor is worksheet +void CMainWindow::updateToolbar(QMdiSubWindow *window) +{ + if(_ui.mdiArea->subWindowList().size() > 0) + if(QString(window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + { + QAction *insertRowAct = new QAction(tr("Insert new row"), this); + connect(insertRowAct, SIGNAL(triggered()), window, SLOT(insertRow())); + windowMenu->addAction(insertRowAct); + QAction *deleteRowAct = new QAction(tr("Delete row"), this); + connect(deleteRowAct, SIGNAL(triggered()), window, SLOT(deleteRow())); + windowMenu->addAction(deleteRowAct); + + } +} + +// Set the active subwindow +void CMainWindow::setActiveSubWindow(QWidget* window) +{ + if (!window) + { + return; + } + QMdiSubWindow *cwindow = qobject_cast(window); + _ui.mdiArea->setActiveSubWindow(cwindow); +} + +// Functions for updating the windows list +void CMainWindow::updateWindowsList() +{ + if(_ui.mdiArea->activeSubWindow()) + { + windowMenu->clear(); + QMdiSubWindow *current_window = _ui.mdiArea->activeSubWindow(); + QList subWindows = _ui.mdiArea->subWindowList(); + + updateToolbar(current_window); + + for(int i = 0; i < subWindows.size(); ++i) + { + QString window_file = QFileInfo(subWindows.at(i)->windowFilePath()).fileName(); + QString action_text; + if (i < 9) { + action_text = QString("&%1 %2").arg(i + 1).arg(window_file); + } else { + action_text = QString("%1 %2").arg(i + 1).arg(window_file); + } + QAction *action = new QAction(action_text, this); + action->setCheckable(true); + action->setChecked(subWindows.at(i) == current_window); + connect(action, SIGNAL(triggered()), windowMapper, SLOT(map())); + windowMenu->addAction(action); + windowMapper->setMapping(action, subWindows.at(i)); + } + } else { + windowMenu->clear(); + } +} + +// Open signal +void CMainWindow::open() +{ + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup("translationmanager"); + QString lastOpenLocation = settings->value("lastOpenLocation").toString(); + QString file_name = QFileDialog::getOpenFileName(this, tr("Open translation file"), lastOpenLocation, tr("Translation files (*txt)")); + QFileInfo* file_info = new QFileInfo(file_name); + settings->setValue("lastOpenLocation", file_info->absolutePath()); + settings->endGroup(); + + if(!file_name.isEmpty()) + { + CEditor *editor = getEditorByWindowFilePath(file_name); + if(editor != NULL) + { + editor->activateWindow(); + return; + } + #ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); + #endif + // sheet editor + if(isWorksheetEditor(file_name)) + { + CEditorWorksheet *new_window = new CEditorWorksheet(_ui.mdiArea); + new_window->setUndoStack(m_undoStack); + new_window->open(file_name); + new_window->activateWindow(); + } + // phrase editor + if(isPhraseEditor(file_name)) + { + CEditorPhrase *new_window = new CEditorPhrase(_ui.mdiArea); + new_window->setUndoStack(m_undoStack); + new_window->open(file_name); + new_window->activateWindow(); + } + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif + } + +} + +// Open a work file. You can set the directory for work file in the settings dialog +void CMainWindow::openWorkFile(QString file) +{ + QFileInfo* file_path = new QFileInfo(QString("%1/%2").arg(work_path).arg(file)); + if(file_path->exists()) + { + if(isWorksheetEditor(file_path->filePath())) + { + CEditorWorksheet *new_window = new CEditorWorksheet(_ui.mdiArea); + new_window->open(file_path->filePath()); + new_window->activateWindow(); + } + } else { + QErrorMessage error; + error.showMessage(QString("The %1 file don't exists.").arg(file_path->fileName())); + error.exec(); + } + +} + +// Save signal +void CMainWindow::save() +{ + if(_ui.mdiArea->subWindowList().size() > 0) + { + CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + #ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); + #endif + current_window->save(); + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif + } +} + +// Save as signal +void CMainWindow::saveAs() +{ + QString file_name; + if (_ui.mdiArea->isActiveWindow()) + { + file_name = QFileDialog::getSaveFileName(this); + } + + if (!file_name.isEmpty()) + { + CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + #ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); + #endif + current_window->saveAs(file_name); + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif + } +} + +// This function is needed by extraction. +void CMainWindow::initializeSettings(bool georges = false) +{ + if(georges == true && initialize_settings["georges"] == false) + { + CPath::addSearchPath(level_design_path.toStdString() + "/DFN", true, false); + CPath::addSearchPath(level_design_path.toStdString() + "/Game_elem/Creature", true, false); + initialize_settings["georges"] = true; + } + + if(initialize_settings["ligo"] == false) + { + try + { + // Search path of file world_editor_classes.xml + std::string ligoPath = NLMISC::CPath::lookup("world_editor_classes.xml"); + // Init LIGO + ligoConfig.readPrimitiveClass(ligoPath.c_str(), true); + NLLIGO::Register(); + NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig = &ligoConfig; + initialize_settings["ligo"] = true; + } + catch (NLMISC::Exception &e) + { + nlerror("Can't found path to world_editor_classes.xml"); + } + } + +} + +// Extracting words +void CMainWindow::extractWords(QString typeq) +{ + if(verifySettings() == true) + { + CEditorWorksheet* editor_window = getEditorByWorksheetType(typeq); + if(editor_window != NULL) + { + editor_window->activateWindow(); + QString file_path = editor_window->windowFilePath(); + } else { + openWorkFile(typeq); + editor_window = getEditorByWorksheetType(typeq); + if(editor_window != NULL) + { + editor_window->activateWindow(); + QString file_path = editor_window->windowFilePath(); + } else return; + } + + QString column_name; + // Sheet extraction + CSheetWordListBuilder builderS; + // Primitives extraction + CRegionPrimWordListBuilder builderP; + bool isSheet = false; + if(typeq.toAscii() == Constants::WK_ITEM) { + column_name = "item ID"; + builderS.SheetExt = "sitem"; + builderS.SheetPath = level_design_path.append("/game_element/sitem").toStdString(); + isSheet = true; + } else if(typeq.toAscii() == Constants::WK_CREATURE) { + column_name = "creature ID"; + builderS.SheetExt = "creature"; + builderS.SheetPath = level_design_path.append("/Game_elem/Creature/fauna").toStdString(); + isSheet = true; + } else if(typeq.toAscii() == Constants::WK_SBRICK) { + column_name = "sbrick ID"; + builderS.SheetExt = "sbrick"; + builderS.SheetPath = level_design_path.append("/game_element/sbrick").toStdString(); + isSheet = true; + } else if(typeq.toAscii() == Constants::WK_SPHRASE) { + column_name = "sphrase ID"; + builderS.SheetExt = "sphrase"; + builderS.SheetPath = level_design_path.append("/game_element/sphrase").toStdString(); + isSheet = true; + } else if(typeq.toAscii() == Constants::WK_PLACE) { + column_name = "placeId"; + builderP.PrimPath = primitives_path.toStdString(); + builderP.PrimFilter.push_back("region_*.primitive"); + builderP.PrimFilter.push_back("indoors_*.primitive"); + isSheet = false; + } + #ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); + #endif + if(isSheet) + { + editor_window->extractWords(editor_window->windowFilePath(), column_name, builderS); + } else { + initializeSettings(false); + editor_window->extractWords(editor_window->windowFilePath(), column_name, builderP); + } + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif + } + +} + +// Extract bot names from primitives +void CMainWindow::extractBotNames() +{ + if(verifySettings() == true) + { + CEditorWorksheet* editor_window = getEditorByWorksheetType(NULL); + if(editor_window != NULL) + { + editor_window->activateWindow(); + QString file_path = editor_window->windowFilePath(); + } else { + openWorkFile(Constants::WK_BOTNAMES); + editor_window = getEditorByWorksheetType(NULL); + if(editor_window != NULL) + { + editor_window->activateWindow(); + QString file_path = editor_window->windowFilePath(); + } else return; + } + #ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); + #endif + initializeSettings(true); + editor_window->extractBotNames(convertQStringList(filters), level_design_path.toStdString(), ligoConfig); + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif + } +} + +// Merge the content for 2 worksheet files +void CMainWindow::mergeSingleFile() +{ + CEditor* editor_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + CSourceDialog *dialog = new CSourceDialog(this); + CFtpSelection* ftp_dialog; + map methods; + QString file_name; + + if (_ui.mdiArea->subWindowList().size() == 0) + { + QErrorMessage error; + error.showMessage(QString("Open a work file in editor for merge operation.")); + error.exec(); + return; + } + + if(editor_window->eType() != Constants::ED_SHEET) // Sheet Editor + { + QErrorMessage error; + error.showMessage(QString("Please open or activate the window with a sheet file.")); + error.exec(); + return; + } + + // create items + QListWidgetItem* local_item = new QListWidgetItem(); + local_item->setText("Local directory"); + methods[local_item] = 0; + QListWidgetItem* ftp_item = new QListWidgetItem(); + ftp_item->setText("From a FTP server"); + methods[ftp_item] = 1; + + dialog->setSourceOptions(methods); + dialog->show(); + dialog->exec(); + // get the file for merge + if(dialog->selected_item == local_item) // Local directory + { + file_name = QFileDialog::getOpenFileName(this); + } + else if(dialog->selected_item == ftp_item) // Ftp directory + { + CFtpSelection* ftp_dialog = new CFtpSelection(this); + ftp_dialog->show(); + + if(ftp_dialog->exec() && ftp_dialog->status == true) + file_name = ftp_dialog->file->fileName(); + + delete ftp_dialog; + } + else + return; + + // Make sure we retrieved a file name + if(file_name.isEmpty()) + return; + + editor_window->activateWindow(); + CEditorWorksheet* current_window = qobject_cast(editor_window); + if(current_window->windowFilePath() == file_name) + return; + if(current_window->compareWorksheetFile(file_name)) + { + current_window->mergeWorksheetFile(file_name); + } else { + QErrorMessage error; + error.showMessage(tr("The file: %1 has different columns from the current file in editor.").arg(file_name)); + error.exec(); + } + if(dialog->selected_item == ftp_item) + { + if(!ftp_dialog->file->remove()) + { + QErrorMessage error; + error.showMessage(tr("Please remove the file from ftp server manually. The file is located on the same directory with OVQT application.")); + error.exec(); + } + + } +} + +// Read the settings from QSettings +void CMainWindow::readSettings() +{ + QSettings *settings = Core::ICore::instance()->settings(); + // translation manager settings + settings->beginGroup("translationmanager"); + filters = settings->value("filters").toStringList(); + languages = settings->value("trlanguages").toStringList(); + translation_path = settings->value("translation").toString(); + work_path = settings->value("work").toString(); + settings->endGroup(); + // core settings + settings->beginGroup(Core::Constants::DATA_PATH_SECTION); + level_design_path = settings->value(Core::Constants::LEVELDESIGN_PATH).toString(); + primitives_path = QString(Core::Constants::PRIMITIVES_PATH); //TODO + settings->endGroup(); +} + +// Verify the settings +bool CMainWindow::verifySettings() +{ + bool count_errors = false; + + if(level_design_path.isNull() || primitives_path.isNull() || work_path.isNull()) + { + QErrorMessage error_settings; + error_settings.showMessage(tr("Please write all the paths on the settings dialog.")); + error_settings.exec(); + count_errors = true; + } + + return !count_errors; + +} + +bool CCoreListener::closeMainWindow() const +{ + bool okToClose = true; + Q_FOREACH(QMdiSubWindow *subWindow, m_MainWindow->_ui.mdiArea->subWindowList()) + { + CEditor *currentEditor = qobject_cast(subWindow); + if(subWindow->isWindowModified()) + { + QMessageBox msgBox; + msgBox.setText(tr("The document has been modified ( %1 ).").arg(currentEditor->windowFilePath())); + msgBox.setInformativeText("Do you want to save your changes?"); + msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Save); + int ret = msgBox.exec(); + if(ret == QMessageBox::Save) + { + currentEditor->save(); + } + else if(ret == QMessageBox::Cancel) + { + okToClose = false; + break; + } + } + } + return okToClose; +} + + +// Helper functions +CEditor *CMainWindow::getEditorByWindowFilePath(const QString &fileName) +{ + Q_FOREACH(QMdiSubWindow *subWindow, _ui.mdiArea->subWindowList()) + { + CEditor *currentEditor = qobject_cast(subWindow); + if(currentEditor->subWindowFilePath() == fileName) + return currentEditor; + } + return NULL; +} + +CEditorWorksheet *CMainWindow::getEditorByWorksheetType(const QString &type) +{ + Q_FOREACH(QMdiSubWindow *subWindow, _ui.mdiArea->subWindowList()) + { + CEditor *currentEditor = qobject_cast(subWindow); + if(currentEditor->eType() == Constants::ED_SHEET) + { + CEditorWorksheet *editor = qobject_cast(currentEditor); + if(type != NULL) { + if(editor->isSheetTable(type)) + { + return editor; + } + } else { + if(editor->isBotNamesTable()) + { + return editor; + } + } + } + } + return NULL; +} + + +list CMainWindow::convertQStringList(QStringList listq) +{ + std::list stdlist; + + Q_FOREACH(QString text, listq) + { + stdlist.push_back(text.toStdString()); + } + + return stdlist; +} + +bool CMainWindow::isWorksheetEditor(QString filename) +{ + STRING_MANAGER::TWorksheet wk_file; + if(loadExcelSheet(filename.toStdString(), wk_file, true) == true) + { + if(wk_file.ColCount > 1) + return true; + } + + return false; +} + +bool CMainWindow::isPhraseEditor(QString filename) +{ + vector phrases; + if(readPhraseFile(filename.toStdString(), phrases, false)) + { + return true; + } else { + return false; + } +} + +} /* namespace TranslationManager */ + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h new file mode 100644 index 000000000..19c3c1976 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h @@ -0,0 +1,133 @@ +// Translation Manager Plugin - OVQT Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Emanuel Costea +// +// 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 . + + +#ifndef MAIN_WINDOW_H +#define MAIN_WINDOW_H + +// Project system includes +#include "../core/icore_listener.h" + +// Nel includes +#include "nel/misc/types_nl.h" +#include "nel/misc/sheet_id.h" +#include "nel/misc/path.h" +#include "nel/misc/diff_tool.h" +#include "nel/ligo/ligo_config.h" + +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include + +// Plugin includes +#include "translation_manager_editor.h" +#include "source_selection.h" +#include "ui_translation_manager_main_window.h" +#include +#include "editor_worksheet.h" +#include "editor_phrase.h" + +class QWidget; + + +using namespace std; + +namespace TranslationManager +{ + +class CMainWindow : public QMainWindow +{ + Q_OBJECT +public: + CMainWindow(QWidget *parent = 0); + virtual ~CMainWindow() {} + QUndoStack *m_undoStack; +public: + Ui::CMainWindow _ui; +private: + // actions + QAction *openAct; + QAction *saveAct; + QAction *saveAsAct; + QMenu *windowMenu; + QSignalMapper *windowMapper; + // config + QMap initialize_settings; + QList filters; + QList languages; + QString level_design_path; + QString primitives_path; + QString translation_path; + QString work_path; + NLLIGO::CLigoConfig ligoConfig; +private Q_SLOTS: + void extractBotNames(); + void extractWords(QString typeq); + void open(); + void save(); + void saveAs(); + void setActiveSubWindow(QWidget *window); + void updateWindowsList(); + void mergeSingleFile(); +private: + void openWorkFile(QString file); + void updateToolbar(QMdiSubWindow *window); + bool verifySettings(); + void readSettings(); + void createMenus(); + void createToolbar(); + void initializeSettings(bool georges); + list convertQStringList(QStringList listq); + CEditor* getEditorByWindowFilePath(const QString &fileName); + // Worksheet specific functions + CEditorWorksheet* getEditorByWorksheetType(const QString &type); + bool isWorksheetEditor(QString filename); + bool isPhraseEditor(QString filename); + + + +}; + +class CCoreListener : public Core::ICoreListener +{ + Q_OBJECT +public: + CCoreListener(CMainWindow* mainWindow, QObject *parent = 0): ICoreListener(parent) + { + m_MainWindow = mainWindow; + } + + virtual ~CCoreListener() {} + virtual bool closeMainWindow() const; + +public: + CMainWindow *m_MainWindow; +}; + + + +} // namespace TranslationManager + + + +#endif // SIMPLE_VIEWER_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.ui new file mode 100644 index 000000000..6f2cd2815 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.ui @@ -0,0 +1,48 @@ + + + CMainWindow + + + + 0 + 0 + 883 + 576 + + + + MainWindow + + + + + + + + + QMdiArea::TabbedView + + + true + + + + + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + + 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 new file mode 100644 index 000000000..a43311506 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp @@ -0,0 +1,108 @@ +// Translation Manager Plugin - OVQT Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Emanuel Costea +// +// 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 . + +// Project includes +#include "translation_manager_plugin.h" +#include "translation_manager_settings_page.h" +#include "translation_manager_main_window.h" +// Project system includes +#include "../core/icore.h" +#include "../core/core_constants.h" +#include "../core/menu_manager.h" +#include "../../extension_system/iplugin_spec.h" + +// NeL includes +#include "nel/misc/debug.h" + +// Qt includes +#include +#include +#include +#include +#include +#include +#include + +namespace TranslationManager +{ +TranslationManagerPlugin::~TranslationManagerPlugin() +{ + Q_FOREACH(QObject *obj, _autoReleaseObjects) + { + _plugMan->removeObject(obj); + } + qDeleteAll(_autoReleaseObjects); + _autoReleaseObjects.clear(); +} + +bool TranslationManagerPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString) +{ + Q_UNUSED(errorString); + _plugMan = pluginManager; + // create the mainwindow + CMainWindow *mainWindow = new CMainWindow(); + + addAutoReleasedObject(new CTranslationManagerSettingsPage(this)); + addAutoReleasedObject(new CTranslationManagerContext(mainWindow, this)); + addAutoReleasedObject(new CCoreListener(mainWindow, this)); + + return true; +} + +void TranslationManagerPlugin::extensionsInitialized() +{ + +} + + + +void TranslationManagerPlugin::setNelContext(NLMISC::INelContext *nelContext) +{ +#ifdef NL_OS_WINDOWS + // Ensure that a context doesn't exist yet. + // This only applies to platforms without PIC, e.g. Windows. + nlassert(!NLMISC::INelContext::isContextInitialised()); +#endif // NL_OS_WINDOWS + _LibContext = new NLMISC::CLibraryContext(*nelContext); +} + +void TranslationManagerPlugin::addAutoReleasedObject(QObject *obj) +{ + _plugMan->addObject(obj); + _autoReleaseObjects.prepend(obj); +} + +QObject* TranslationManagerPlugin::objectByName(const QString &name) const +{ + Q_FOREACH (QObject *qobj, _plugMan->allObjects()) + if (qobj->objectName() == name) + return qobj; + return 0; +} + +ExtensionSystem::IPluginSpec *TranslationManagerPlugin::pluginByName(const QString &name) const +{ + Q_FOREACH (ExtensionSystem::IPluginSpec *spec, _plugMan->plugins()) + if (spec->name() == name) + return spec; + return 0; + +} + +} + +Q_EXPORT_PLUGIN(TranslationManager::TranslationManagerPlugin) 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 new file mode 100644 index 000000000..f9cb6798c --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h @@ -0,0 +1,117 @@ +// Translation Manager Plugin - OVQT Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Emanuel Costea +// +// 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 . + +#ifndef TRANSLATION_MANAGER_PLUGIN_H +#define TRANSLATION_MANAGER_PLUGIN_H + +// Project includes +#include "../../extension_system/iplugin.h" +#include "../core/icontext.h" +#include "translation_manager_main_window.h" + +// NeL includes +#include "nel/misc/app_context.h" + +// Qt includes +#include +#include + +using namespace std; + +namespace NLMISC +{ +class CLibraryContext; +} + +namespace ExtensionSystem +{ +class IPluginSpec; +} + +namespace TranslationManager +{ + + class CTranslationManagerContext; + +class TranslationManagerPlugin : public QObject, public ExtensionSystem::IPlugin +{ + Q_OBJECT + Q_INTERFACES(ExtensionSystem::IPlugin) +public: + virtual ~TranslationManagerPlugin(); + + bool initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString); + void extensionsInitialized(); + + void setNelContext(NLMISC::INelContext *nelContext); + + void addAutoReleasedObject(QObject *obj); + + QObject *objectByName(const QString &name) const; + ExtensionSystem::IPluginSpec *pluginByName(const QString &name) const; + +protected: + NLMISC::CLibraryContext *_LibContext; + +private: + ExtensionSystem::IPluginManager *_plugMan; + QList _autoReleaseObjects; +}; + +class CTranslationManagerContext: public Core::IContext +{ + Q_OBJECT +public: + CTranslationManagerContext(CMainWindow* mainWindow, QObject *parent = 0): IContext(parent) + { + m_MainWindow = mainWindow; + } + + virtual ~CTranslationManagerContext() {} + + virtual QString id() const + { + return QLatin1String("TranslationManagerContext"); + } + virtual QString trName() const + { + return tr("Translation Manager"); + } + virtual QIcon icon() const + { + return QIcon(); + } + virtual QWidget *widget() + { + return m_MainWindow; + } + virtual QUndoStack *undoStack() + { + return m_MainWindow->m_undoStack; + } + virtual void open() + { + + } + + CMainWindow *m_MainWindow; + +}; + +} // namespace Plugin + +#endif // TRANSLATION_MANAGER_PLUGIN_H 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 new file mode 100644 index 000000000..09588da7d --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp @@ -0,0 +1,207 @@ +// Translation Manager Plugin - OVQT Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Emanuel Costea +// +// 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 "translation_manager_settings_page.h" + +// Qt includes +#include +#include +#include +#include + +// NeL includes + +// Project includes +#include "../core/icore.h" + +namespace TranslationManager +{ + +QString lastDir = "."; + +CTranslationManagerSettingsPage::CTranslationManagerSettingsPage(QObject *parent) + : IOptionsPage(parent), + _currentPage(NULL) +{ +} + +QString CTranslationManagerSettingsPage::id() const +{ + return QLatin1String("TranslationManagerPage"); +} + +QString CTranslationManagerSettingsPage::trName() const +{ + return tr("Translation Manager"); +} + +QString CTranslationManagerSettingsPage::category() const +{ + return QLatin1String("Translation Manager"); +} + +QString CTranslationManagerSettingsPage::trCategory() const +{ + return tr("Translation Manager"); +} + +QIcon CTranslationManagerSettingsPage::categoryIcon() const +{ + return QIcon(); +} + +QWidget *CTranslationManagerSettingsPage::createPage(QWidget *parent) +{ + _currentPage = new QWidget(parent); + _ui.setupUi(_currentPage); + readSettings(); + 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::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 filters, languages; + QString ligo, translation, work; + + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup("translationmanager"); + + filters = settings->value("filters").toStringList(); /* filters */ + languages = settings->value("trlanguages").toStringList(); /* languages */ + ligo = settings->value("ligo").toString(); + translation = settings->value("translation").toString(); + work = settings->value("work").toString(); + + settings->endGroup(); + // 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); + } + // translation + _ui.translation_edit->setText(translation); + // work + _ui.work_edit->setText(work); + +} + +void CTranslationManagerSettingsPage::writeSettings() +{ + QStringList filters, languages; + QString ligo, translation, work; + // 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(); + // translations path + translation = _ui.translation_edit->text(); + // work path + work = _ui.work_edit->text(); + + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup("translationmanager"); + settings->setValue("filters", filters); + settings->setValue("trlanguages", languages); + settings->setValue("translation", translation); + settings->setValue("work", work); + settings->endGroup(); + settings->sync(); +} + + +} /* 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 new file mode 100644 index 000000000..34caea5e1 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h @@ -0,0 +1,66 @@ +// Translation Manager Plugin - OVQT Plugin +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Emanuel Costea +// +// 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 . + +#ifndef TRANSLATION_MANAGER_SETTINGS_PAGE_H +#define TRANSLATION_MANAGER_SETTINGS_PAGE_H + +#include + +#include "../core/ioptions_page.h" + +#include "ui_translation_manager_settings_page.h" + +class QWidget; + +namespace TranslationManager +{ +/** +@class CTranslationManagerSettingsPage +*/ +class CTranslationManagerSettingsPage : public Core::IOptionsPage +{ + Q_OBJECT +public: + CTranslationManagerSettingsPage(QObject *parent = 0); + virtual ~CTranslationManagerSettingsPage() {} + + virtual QString id() const; + virtual QString trName() const; + virtual QString category() const; + virtual QString trCategory() const; + virtual QIcon categoryIcon() const; + virtual QWidget *createPage(QWidget *parent); + + virtual void apply(); + virtual void finish() {} +private Q_SLOTS: + void filterAdd(); + void filterDel(); + void languageAdd(); + void languageDel(); + void translationAdd(); + void workAdd(); +private: + QWidget *_currentPage; + Ui::CTranslationManagerSettingsPage _ui; + void writeSettings(); + void readSettings(); +}; + +} // namespace Plugin + +#endif // TRANSLATION_MANAGER_SETTINGS_H 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 new file mode 100644 index 000000000..aaa4337f4 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui @@ -0,0 +1,186 @@ + + + CTranslationManagerSettingsPage + + + + 0 + 0 + 533 + 478 + + + + Form + + + + + 0 + 10 + 531 + 421 + + + + Translation Manager Plugin + + + + + 0 + 30 + 521 + 232 + + + + + + + Filters + + + + + + + + + + + + + + :/core/icons/ic_nel_add_item.png:/core/icons/ic_nel_add_item.png + + + true + + + + + + + + + + + :/core/icons/ic_nel_delete_item.png:/core/icons/ic_nel_delete_item.png + + + true + + + + + + + Languages + + + + + + + + + + + + + + :/core/icons/ic_nel_add_item.png:/core/icons/ic_nel_add_item.png + + + true + + + + + + + + + + + :/core/icons/ic_nel_delete_item.png:/core/icons/ic_nel_delete_item.png + + + true + + + + + + + + + + + + + + + 0 + 340 + 521 + 60 + + + + + + + Translation directory + + + + + + + + + + ... + + + + + + + + + 0 + 270 + 521 + 60 + + + + + + + Work directory + + + + + + + + + + ... + + + + + + + + + + + +