From cddb66027e39adae589585e444ff6485fcd597f6 Mon Sep 17 00:00:00 2001 From: cemycc Date: Fri, 29 Apr 2011 22:58:59 +0300 Subject: [PATCH 02/34] Create directory for the Translation Manager plugin --HG-- branch : gsoc2011-translationovqt --- .../object_viewer_qt/src/plugins/translation_manager/README | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/README 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 new file mode 100644 index 000000000..b182bfdcf --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/README @@ -0,0 +1,5 @@ +Translation Manager Plugin +-------------------------- +GSoC 2011 Project +http://dev.ryzom.com/wiki/ryzom/OVQTTranslationPluginGSoc2011 + From f47f5a3799b315b06cdaab759c421b265cb58ef5 Mon Sep 17 00:00:00 2001 From: cemycc Date: Wed, 25 May 2011 00:06:07 +0300 Subject: [PATCH 03/34] first stage for my plugin --HG-- branch : gsoc2011-translationovqt --- .../tools/3d/object_viewer_qt/src/plugins/CMakeLists.txt | 3 ++- .../src/plugins/object_viewer/scheme_manager.h | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) 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 d5a792acd..125c0c8c4 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 @@ -4,4 +4,5 @@ ADD_SUBDIRECTORY(ovqt_sheet_builder) ADD_SUBDIRECTORY(log) ADD_SUBDIRECTORY(disp_sheet_id) ADD_SUBDIRECTORY(object_viewer) -ADD_SUBDIRECTORY(zone_painter) \ No newline at end of file +ADD_SUBDIRECTORY(zone_painter) +ADD_SUBDIRECTORY(translation_manager) 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 01a2abb35..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 @@ -27,8 +27,8 @@ namespace NL3D { class CPSAttribMakerBase; } - -namespace NLQT + +namespace NLQT { class CSchemeManager @@ -51,11 +51,11 @@ public: // rename a scheme, given a pointer on it void rename(NL3D::CPSAttribMakerBase *am, const std::string &newName); protected: - typedef std::pair TSchemeInfo; + // typedef std::pair TSchemeInfo; typedef std::multimap TSchemeMap; TSchemeMap _SchemeMap; }; } /* namespace NLQT */ -#endif \ No newline at end of file +#endif From 9dab149983def5b077e99fa0924c310fb24a1915 Mon Sep 17 00:00:00 2001 From: cemycc Date: Wed, 25 May 2011 00:07:32 +0300 Subject: [PATCH 04/34] first stage for my plugin --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/CMakeLists.txt | 41 ++++ .../translation_manager/qnel_widget.cpp | 197 ++++++++++++++++++ .../plugins/translation_manager/qnel_widget.h | 130 ++++++++++++ .../translation_manager/simple_viewer.cpp | 54 +++++ .../translation_manager/simple_viewer.h | 54 +++++ .../translation_manager_plugin.cpp | 122 +++++++++++ .../translation_manager_plugin.h | 94 +++++++++ .../translation_manager_settings_page.cpp | 67 ++++++ .../translation_manager_settings_page.h | 58 ++++++ .../translation_manager_settings_page.ui | 92 ++++++++ 10 files changed, 909 insertions(+) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui 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..ce85c682e --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt @@ -0,0 +1,41 @@ +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 + qnel_widget.h + simple_viewer.h + translation_manager_settings_page.h) + +SET(OVQT_PLUG_TRANSLATION_MANAGER_UIS translation_manager_settings_page.ui) + +SET(QT_USE_QTGUI TRUE) +SET(QT_USE_QTOPENGL 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 ${QT_LIBRARIES} ${QT_QTOPENGL_LIBRARY}) + +NL_DEFAULT_PROPS(ovqt_plugin_translation_manager "NeL, Tools, 3D: Object Viewer Qt Plugin: Translation Manager") +NL_ADD_RUNTIME_FLAGS(ovqt_plugin_translation_manager) +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/qnel_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.cpp new file mode 100644 index 000000000..9a67abb80 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.cpp @@ -0,0 +1,197 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// 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 "qnel_widget.h" + +// STL includes + +// Qt includes +#include +#include + +// NeL includes +#include +#include +#include +#include + +namespace NLQT +{ + +QNLWidget::QNLWidget(QWidget *parent) + : QNeLWidget(parent), + m_driver(NULL), + m_initialized(false), + m_interval(25) +{ + setMouseTracking(true); + setFocusPolicy(Qt::StrongFocus); + + init(); +#ifdef Q_OS_LINUX + makeCurrent(); +#endif + m_mainTimer = new QTimer(this); + connect(m_mainTimer, SIGNAL(timeout()), this, SLOT(updateRender())); +} + +QNLWidget::~QNLWidget() +{ + release(); +} + +void QNLWidget::init() +{ + // create the driver + m_driver = NL3D::UDriver::createDriver(NULL, false, NULL); + nlassert(m_driver); + + // initialize the nel 3d viewport + m_driver->setDisplay((nlWindow)winId(), NL3D::UDriver::CMode(width(), height(), 32)); + + // set the cache size for the font manager(in bytes) + m_driver->setFontManagerMaxMemory(2097152); + + m_initialized = true; +} + +void QNLWidget::release() +{ + m_mainTimer->stop(); + delete m_mainTimer; + if (m_initialized) + { + m_driver->release(); + delete m_driver; + m_driver = NULL; + } +} + +void QNLWidget::setInterval(int msec) +{ + m_interval = msec; + m_mainTimer->setInterval(msec); +} + +void QNLWidget::setBackgroundColor(NLMISC::CRGBA backgroundColor) +{ + m_backgroundColor = backgroundColor; +} + +void QNLWidget::updateRender() +{ + if (isVisible()) + { + if (m_initialized) + m_driver->EventServer.pump(); + Q_EMIT updateData(); + + // Calc FPS + static sint64 lastTime = NLMISC::CTime::getPerformanceTime (); + sint64 newTime = NLMISC::CTime::getPerformanceTime (); + m_fps = float(1.0 / NLMISC::CTime::ticksToSecond (newTime-lastTime)); + lastTime = newTime; + + if (m_initialized && !m_driver->isLost()) + { + //_driver->activate(); + m_driver->clearBuffers(m_backgroundColor); + Q_EMIT updatePreRender(); + + Q_EMIT updatePostRender(); + // swap 3d buffers + m_driver->swapBuffers(); + } + } +} + +void QNLWidget::showEvent(QShowEvent *showEvent) +{ + QWidget::showEvent(showEvent); + m_driver->activate(); + m_mainTimer->start(m_interval); +} + +void QNLWidget::hideEvent(QHideEvent *hideEvent) +{ + m_mainTimer->stop(); + QWidget::hideEvent(hideEvent); +} + +#if defined(NL_OS_WINDOWS) + +typedef bool (*winProc)(NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + +bool QNLWidget::winEvent(MSG *message, long *result) +{ + if (m_driver && m_driver->isActive()) + { + NL3D::IDriver *driver = dynamic_cast(m_driver)->getDriver(); + if (driver) + { + winProc proc = (winProc)driver->getWindowProc(); + return proc(driver, message->hwnd, message->message, message->wParam, message->lParam); + } + } + + return false; +} + +#elif defined(NL_OS_MAC) + +typedef bool (*cocoaProc)(NL3D::IDriver *, const void *e); + +bool QNLWidget::macEvent(EventHandlerCallRef caller, EventRef event) +{ + if(caller) + nlerror("You are using QtCarbon! Only QtCocoa supported, please upgrade Qt"); + + if (m_driver && m_driver->isActive()) + { + NL3D::IDriver *driver = dynamic_cast(m_driver)->getDriver(); + if (driver) + { + cocoaProc proc = (cocoaProc)driver->getWindowProc(); + return proc(driver, event); + } + } + + return false; +} + +#elif defined(NL_OS_UNIX) + +typedef bool (*x11Proc)(NL3D::IDriver *drv, XEvent *e); + +bool QNLWidget::x11Event(XEvent *event) +{ + if (m_driver && m_driver->isActive()) + { + NL3D::IDriver *driver = dynamic_cast(m_driver)->getDriver(); + if (driver) + { + x11Proc proc = (x11Proc)driver->getWindowProc(); + return proc(driver, event); + } + } + + return false; +} +#endif + +} /* namespace NLQT */ + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.h new file mode 100644 index 000000000..a54e6bb8a --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.h @@ -0,0 +1,130 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// 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 QNEL_WIDGET_H +#define QNEL_WIDGET_H + +// NeL includes +#include +#include +#include + +// Qt includes +#include +#include + +class QAction; + +/* TODO every platform should use QWidget */ +#if defined(NL_OS_WINDOWS) +typedef QWidget QNeLWidget; +#elif defined(NL_OS_MAC) +typedef QWidget QNeLWidget; +#elif defined(NL_OS_UNIX) +typedef QGLWidget QNeLWidget; +#endif // NL_OS_UNIX + +namespace NL3D +{ +class UDriver; +class UScene; +} + +namespace NLQT +{ + +/** +@class QNLWidget +@brief Responsible for interaction between Qt and NeL. +@details Automatically begins to update the render if the widget is visible +or suspends the updating of render if the widget is hidden. +*/ +class QNLWidget : public QNeLWidget +{ + Q_OBJECT + +public: + QNLWidget(QWidget *parent); + virtual ~QNLWidget(); + + /// Set the update interval renderer + void setInterval(int msec); + + /// Set the background color. + void setBackgroundColor(NLMISC::CRGBA backgroundColor); + + float fps() const + { + return m_fps; + } + + inline NLMISC::CRGBA backgroundColor() const + { + return m_backgroundColor; + } + + NL3D::UDriver *driver() const + { + return m_driver; + } + + virtual QPaintEngine* paintEngine() const + { + return NULL; + } +Q_SIGNALS: + void updateData(); + void updatePreRender(); + void updatePostRender(); + +private Q_SLOTS: + void updateRender(); + +protected: + virtual void showEvent(QShowEvent *showEvent); + virtual void hideEvent(QHideEvent *hideEvent); + +#if defined(NL_OS_WINDOWS) + virtual bool winEvent(MSG *message, long *result); +#elif defined(NL_OS_MAC) + virtual bool macEvent(EventHandlerCallRef caller, EventRef event); +#elif defined(NL_OS_UNIX) + virtual bool x11Event(XEvent *event); +#endif + +private: + void init(); + void release(); + + QNLWidget(const QNLWidget &); + QNLWidget &operator=(const QNLWidget &); + + NL3D::UDriver *m_driver; + NLMISC::CRGBA m_backgroundColor; + + QTimer *m_mainTimer; + + bool m_initialized; + int m_interval; + float m_fps; + +}; /* class QNLWidget */ + +} /* namespace NLQT */ + + +#endif // QNEL_WIDGET_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.cpp new file mode 100644 index 000000000..e128710c4 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.cpp @@ -0,0 +1,54 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// 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 "simple_viewer.h" + +// Qt includes +#include +#include +#include + +// NeL includes + +// Project includes + +namespace Plugin +{ + +CSimpleViewer::CSimpleViewer(QWidget *parent) + : QWidget(parent) +{ + QGridLayout *gridLayout = new QGridLayout(this); + gridLayout->setObjectName(QString::fromUtf8("gridLayoutSimpleViewer")); + gridLayout->setContentsMargins(0, 0, 0, 0); + NLQT::QNLWidget *_nelWidget = new NLQT::QNLWidget(this); + gridLayout->addWidget(_nelWidget, 0, 0, 1, 1); +} + +bool CCoreListener::closeMainWindow() const +{ + int ret = QMessageBox::question(0, tr("Example close event hook"), + tr("Do you want to close window?"), + QMessageBox::Yes | QMessageBox::No); + + if (ret == QMessageBox::Yes) + return true; + else + return false; +} + +} /* namespace Plugin */ \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.h new file mode 100644 index 000000000..bbff7e9e0 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.h @@ -0,0 +1,54 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// 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 SIMPLE_VIEWER_H +#define SIMPLE_VIEWER_H + +// Project includes +#include "qnel_widget.h" +#include "../core/icore_listener.h" + +// Qt includes +#include + +class QWidget; + +namespace Plugin +{ + +class CSimpleViewer : public QWidget +{ + Q_OBJECT +public: + CSimpleViewer(QWidget *parent = 0); + virtual ~CSimpleViewer() {} +}; + +class CCoreListener : public Core::ICoreListener +{ + Q_OBJECT +public: + CCoreListener(QObject *parent = 0): ICoreListener(parent) {} + virtual ~CCoreListener() {} + + virtual bool closeMainWindow() const; +}; + +} // namespace Plugin + +#endif // SIMPLE_VIEWER_H 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..6140a3985 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp @@ -0,0 +1,122 @@ +// Project includes +#include "translation_manager_plugin.h" +#include "translation_manager_settings_page.h" +#include "simple_viewer.h" +// Project system includes +#include "../core/icore.h" +#include "../core/core_constants.h" +#include "../core/imenu_manager.h" +#include "../../extension_system/iplugin_spec.h" + +// NeL includes +#include "nel/misc/debug.h" + +// Qt includes +#include +#include +#include +#include +#include +#include + +namespace Plugin +{ +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; + + addAutoReleasedObject(new CTranslationManagerSettingsPage(this)); + addAutoReleasedObject(new CTranslationManagerContext(this)); + addAutoReleasedObject(new CCoreListener(this)); + return true; +} + +void TranslationManagerPlugin::extensionsInitialized() +{ + Core::ICore *core = Core::ICore::instance(); + Core::IMenuManager *menuManager = core->menuManager(); + //menuManager = _plugMan->getObject(); + // Menu Actions for plugin + QAction *aboutTManPlugin = new QAction("Translation Manager", this); + // Locations + QMenu *helpMenu = menuManager->menu(Core::Constants::M_HELP); + QAction *aboutQtAction = menuManager->action(Core::Constants::ABOUT_QT); + helpMenu->addSeparator(); + helpMenu->insertAction(aboutQtAction, aboutTManPlugin); + menuManager->menuBar()->addMenu("Translation Manager"); +} + +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); +} + +QString TranslationManagerPlugin::name() const +{ + return "Translation Manager"; +} + +QString TranslationManagerPlugin::version() const +{ + return "0.1"; +} + +QString TranslationManagerPlugin::vendor() const +{ + return "cemycc"; +} + +QString TranslationManagerPlugin::description() const +{ + return "OVQT plugin for translation files."; +} + +QStringList TranslationManagerPlugin::dependencies() const +{ + QStringList list; + list.append(Core::Constants::OVQT_CORE_PLUGIN); + list.append("ObjectViewer"); + return list; +} + +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(Plugin::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..c1bfc2548 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h @@ -0,0 +1,94 @@ +#ifndef TRANSLATION_MANAGER_PLUGIN_H +#define TRANSLATION_MANAGER_PLUGIN_H + +// Project includes +#include "../../extension_system/iplugin.h" +#include "../core/icontext.h" +#include "simple_viewer.h" + +// NeL includes +#include "nel/misc/app_context.h" + +// Qt includes +#include +#include + +namespace NLMISC +{ +class CLibraryContext; +} + +namespace ExtensionSystem +{ +class IPluginSpec; +} + +namespace Plugin +{ + +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); + + QString name() const; + QString version() const; + QString vendor() const; + QString description() const; + QStringList dependencies() const; + + 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(QObject *parent = 0): IContext(parent) + { + m_simpleViewer = new CSimpleViewer(); + } + + 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_simpleViewer; + } + + CSimpleViewer *m_simpleViewer; +}; + +} // 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..c3e4883d4 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp @@ -0,0 +1,67 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// 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 + +// NeL includes + +// Project includes + +namespace Plugin +{ + +CTranslationManagerSettingsPage::CTranslationManagerSettingsPage(QObject *parent) + : IOptionsPage(parent), + _currentPage(NULL) +{ +} + +QString CTranslationManagerSettingsPage::id() const +{ + return QLatin1String("TranslationManagerPage"); +} + +QString CTranslationManagerSettingsPage::trName() const +{ + return tr("Translation Manager page"); +} + +QString CTranslationManagerSettingsPage::category() const +{ + return QLatin1String("General"); +} + +QString CTranslationManagerSettingsPage::trCategory() const +{ + return tr("General"); +} + +QWidget *CTranslationManagerSettingsPage::createPage(QWidget *parent) +{ + _currentPage = new QWidget(parent); + _ui.setupUi(_currentPage); + return _currentPage; +} + +void CTranslationManagerSettingsPage::apply() +{ +} + +} /* 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..53f9068e1 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h @@ -0,0 +1,58 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// 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 Plugin +{ +/** +@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 QWidget *createPage(QWidget *parent); + + virtual void apply(); + virtual void finish() {} + +private: + QWidget *_currentPage; + Ui::CTranslationManagerSettingsPage _ui; +}; + +} // 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..951be0615 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui @@ -0,0 +1,92 @@ + + + CTranslationManagerSettingsPage + + + + 0 + 0 + 458 + 479 + + + + Form + + + + 0 + + + + + GroupBox + + + + + + PushButton + + + + + + + + + + PushButton + + + + + + + RadioButton + + + + + + + RadioButton + + + + + + + CheckBox + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + + + + From 0371b04509d46fb237373dcadc8fb1c57dfdd426 Mon Sep 17 00:00:00 2001 From: cemycc Date: Mon, 30 May 2011 20:56:22 +0300 Subject: [PATCH 05/34] Changed: #1307 Added extract bot names and UI dialog for plugin settings. --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/CMakeLists.txt | 2 +- .../translation_manager/extract_bot_names.cpp | 756 ++++++++++++++++++ .../translation_manager_plugin.cpp | 47 +- .../translation_manager_plugin.h | 8 + .../translation_manager_settings_page.cpp | 243 ++++++ .../translation_manager_settings_page.h | 16 +- .../translation_manager_settings_page.ui | 485 ++++++++--- 7 files changed, 1462 insertions(+), 95 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_bot_names.cpp diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt index ce85c682e..827db7487 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt @@ -30,7 +30,7 @@ SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC}) ADD_LIBRARY(ovqt_plugin_translation_manager MODULE ${SRC} ${OVQT_PLUG_TRANSLATION_MANAGER_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_PLUG_TRANSLATION_MANAGER_UI_HDRS}) -TARGET_LINK_LIBRARIES(ovqt_plugin_translation_manager ovqt_plugin_core nelmisc nel3d ${QT_LIBRARIES} ${QT_QTOPENGL_LIBRARY}) +TARGET_LINK_LIBRARIES(ovqt_plugin_translation_manager ovqt_plugin_core nelmisc nel3d nelligo nelgeorges ${QT_LIBRARIES} ${QT_QTOPENGL_LIBRARY}) NL_DEFAULT_PROPS(ovqt_plugin_translation_manager "NeL, Tools, 3D: Object Viewer Qt Plugin: Translation Manager") NL_ADD_RUNTIME_FLAGS(ovqt_plugin_translation_manager) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_bot_names.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_bot_names.cpp new file mode 100644 index 000000000..75a97d3bb --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_bot_names.cpp @@ -0,0 +1,756 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "nel/misc/types_nl.h" +#include "nel/misc/config_file.h" +#include "nel/misc/sheet_id.h" +#include "nel/misc/path.h" +#include "nel/misc/diff_tool.h" +#include "nel/georges/u_form.h" +#include "nel/georges/u_form_elm.h" +#include "nel/georges/load_form.h" +#include "nel/ligo/ligo_config.h" +#include "nel/ligo/primitive.h" +#include "nel/ligo/primitive_utils.h" + +using namespace std; +using namespace NLMISC; +using namespace NLLIGO; +using namespace STRING_MANAGER; + +vector Filters; + +static CLigoConfig LigoConfig; +static bool RemoveOlds = false; + +struct TCreatureInfo +{ + CSheetId SheetId; + bool ForceSheetName; + bool DisplayName; + + + void readGeorges (const NLMISC::CSmartPtr &form, const NLMISC::CSheetId &sheetId) + { + const NLGEORGES::UFormElm &item=form->getRootNode(); + + SheetId=sheetId; + item.getValueByName(ForceSheetName, "3d data.ForceDisplayCreatureName"); + item.getValueByName(DisplayName, "3d data.DisplayName"); + } + + void serial(NLMISC::IStream &f) + { + f.serial(SheetId); + f.serial(ForceSheetName); + f.serial(DisplayName); + } + + + static uint getVersion () + { + return 1; + } + + void removed() + { + } + +}; + +std::map Creatures; + +TCreatureInfo *getCreature(const std::string &sheetName) +{ + CSheetId id(sheetName+".creature"); + + if (Creatures.find(id) != Creatures.end()) + return &(Creatures.find(id)->second); + else + return NULL; +} + +string cleanupName(const std::string &name) +{ + string ret; + + for (uint i=0; i= 2) + { + if ( *ret.begin() == ucchar('$')) + { + ret=ret.substr(1); + } + if ( *ret.rbegin() == ucchar('$')) + { + ret = ret.substr(0, ret.size()-1); + } + } + ret = cleanupUcName(ret); + return ret; +} + +struct TEntryInfo +{ + string SheetName; +}; + +set GenericNames; +map SimpleNames; +set Functions; + + +string removeAndStoreFunction(const std::string &fullName) +{ + string::size_type pos = fullName.find("$"); + if (pos == string::npos) + return fullName; + else + { + // extract and store the function name + string ret; + + ret = fullName.substr(0, pos); + string::size_type pos2 = fullName.find("$", pos+1); + + string fct = fullName.substr(pos+1, pos2-(pos+1)); + + ret += fullName.substr(pos2+1); + + if (Functions.find(fct) == Functions.end()) + { + nldebug("Adding function '%s'", fct.c_str()); + Functions.insert(fct); + } + + return ret; + } +} + + +void addGenericName(const std::string &name, const std::string &sheetName) +{ + TCreatureInfo *c = getCreature(sheetName); + if (!c || c->ForceSheetName || !c->DisplayName) + return; + + if (SimpleNames.find(name) != SimpleNames.end()) + { + nldebug("Name '%s' is now a generic name", name.c_str()); + GenericNames.insert(name); + SimpleNames.erase(name); + + } + else if (GenericNames.find(name) == GenericNames.end()) + { + nldebug("Adding generic name '%s'", name.c_str()); + GenericNames.insert(name); + } +} + +void addSimpleName(const std::string &name, const std::string &sheetName) +{ + TCreatureInfo *c = getCreature(sheetName); + if (!c || c->ForceSheetName || !c->DisplayName) + return; + + if (SimpleNames.find(name) != SimpleNames.end()) + { + addGenericName(name, sheetName); + } + else if (GenericNames.find(name) != GenericNames.end()) + { + return; + } + else + { + nldebug("Adding simple name '%s'", name.c_str()); + + TEntryInfo ei; + ei.SheetName = sheetName; + + SimpleNames.insert(make_pair(name, ei)); + } +} + +int extractBotNamesAll(map > config_paths, string ligo_class_file, string trans_path, string work_path) +{ + //------------------------------------------------------------------- + // read the parameters + /*for (int i=2; i::iterator it = config_paths["paths"].begin(); it != config_paths["paths"].end(); ++it) + { + CPath::addSearchPath(*it, true, false); + } + for (std::list::iterator it = config_paths["pathsR"].begin(); it != config_paths["pathsR"].end(); ++it) + { + CPath::addSearchPath(*it, false, false); + } + + for (std::list::iterator it = config_paths["filters"].begin(); it != config_paths["filters"].end(); ++it) + { + Filters.push_back(*it); + } + + + //------------------------------------------------------------------- + // init the sheets + CSheetId::init(false); + const string PACKED_SHEETS_NAME = "bin/translation_tools_creature.packed_sheets"; + loadForm("creature", PACKED_SHEETS_NAME, Creatures, false, false); + + if (Creatures.empty()) + { + for (std::list::iterator it = config_paths["georges"].begin(); it != config_paths["georges"].end(); ++it) + CPath::addSearchPath((*it).c_str(), true, false); + + loadForm("creature", PACKED_SHEETS_NAME, Creatures, true); + } + + + //------------------------------------------------------------------- + // init ligo config + string ligoPath = CPath::lookup(ligo_class_file, true, true); + LigoConfig.readPrimitiveClass(ligoPath.c_str(), false); + NLLIGO::Register(); + + CPrimitiveContext::instance().CurrentLigoConfig = &LigoConfig; + + //------------------------------------------------------------------- + // ok, ready for the real work, + // first, read the primitives files and parse the primitives + vector files; + CPath::getFileList("primitive", files); + + for (uint i=0; i ps; + ps.buildSet(primDoc.RootNode, pred, result); + + for (uint i=0; igetPropertyByName("name", name); + result[i]->getPropertyByName("count", countStr); + result[i]->getPropertyByName("bot_sheet_look", sheetStr); + + uint32 count; + NLMISC::fromString(countStr, count); + + if (count != 0) + { + if (sheetStr.empty()) + { + nlwarning("In '%s', empty sheet !", buildPrimPath(result[i]).c_str()); + } + else + { + addGenericName(removeAndStoreFunction(name), sheetStr); + } + } + } + } + // look for bot template + { + TPrimitiveClassPredicate pred("bot_template_npc"); + TPrimitiveSet result; + + CPrimitiveSet ps; + ps.buildSet(primDoc.RootNode, pred, result); + + for (uint i=0; igetPropertyByName("name", name); + result[i]->getPropertyByName("sheet_look", sheetStr); + + if (sheetStr.empty()) + { + // take the sheet in the parent + result[i]->getParent()->getPropertyByName("bot_sheet_look", sheetStr); + } + + if (sheetStr.empty()) + { + nlwarning("In '%s', empty sheet !", buildPrimPath(result[i]).c_str()); + } + else + { + addGenericName(removeAndStoreFunction(name), sheetStr); + } + } + } + // look for npc_group + { + TPrimitiveClassPredicate pred("npc_group"); + TPrimitiveSet result; + + CPrimitiveSet ps; + ps.buildSet(primDoc.RootNode, pred, result); + + for (uint i=0; igetPropertyByName("name", name); + result[i]->getPropertyByName("count", countStr); + result[i]->getPropertyByName("bot_sheet_client", sheetStr); + + uint32 count; + NLMISC::fromString(countStr, count); + + if (count > 0 && sheetStr.empty()) + { + nlwarning("In '%s', empty sheet !", buildPrimPath(result[i]).c_str()); + } + else + { + if (count == 1) + { + addSimpleName(removeAndStoreFunction(name), sheetStr); + } + else if (count > 1) + { + addGenericName(removeAndStoreFunction(name), sheetStr); + } + } + } + } + // look for bot + { + TPrimitiveClassPredicate pred("npc_bot"); + TPrimitiveSet result; + + CPrimitiveSet ps; + ps.buildSet(primDoc.RootNode, pred, result); + + for (uint i=0; igetPropertyByName("name", name); + result[i]->getPropertyByName("sheet_client", sheetStr); + + if (sheetStr.empty()) + { + // take the sheet in the parent + result[i]->getParent()->getPropertyByName("bot_sheet_client", sheetStr); + } + + if (sheetStr.empty()) + { + nlwarning("In '%s', empty sheet !", buildPrimPath(result[i]).c_str()); + } + else + { + TEntryInfo ei; + addSimpleName(removeAndStoreFunction(name), sheetStr); + } + } + } + } + + //------------------------------------------------------------------- + // step 2 : load the reference file + + nlinfo("Looking for missing translation:"); + + TWorksheet botNames; + loadExcelSheet(work_path, botNames, true); + TWorksheet transBotNames; + loadExcelSheet(trans_path, transBotNames, true); + + TWorksheet fcts; + loadExcelSheet(work_path, fcts, true); + + + // add missing element + + uint nbAddSimpleName = 0; + uint nbAddFunction = 0; + uint nbAddGenericName = 0; + + uint botIdCol; + nlverify(botNames.findId(botIdCol)); + uint transIdCol; + nlverify(transBotNames.findId(transIdCol)); + uint fctsIdCol; + nlverify(fcts.findId(fctsIdCol)); + + // special treatment to add the sheet_name col + { + uint sheetCol; + if (!botNames.findCol(ucstring("sheet_name"), sheetCol)) + { + botNames.insertColumn(botNames.ColCount); + botNames.setData(0, botNames.ColCount-1, ucstring("sheet_name")); + } + + if (!transBotNames.findCol(ucstring("sheet_name"), sheetCol)) + { + transBotNames.insertColumn(transBotNames.ColCount); + transBotNames.setData(0, transBotNames.ColCount-1, ucstring("sheet_name")); + } + } + // 1 - simple names + { + nlinfo(" Simple names..."); + + + map::iterator first(SimpleNames.begin()), last(SimpleNames.end()); + for (; first != last; ++first) + { + uint rowIdx; + if (!botNames.findRow(botIdCol, first->first, rowIdx)) + { + // we need to add the entry + rowIdx = botNames.size(); + botNames.resize(botNames.size()+1); + + botNames.setData(rowIdx, ucstring("bot name"), first->first); + botNames.setData(rowIdx, ucstring("translated name"), first->first); + botNames.setData(rowIdx, ucstring("sheet_name"), first->second.SheetName); + + nbAddSimpleName++; + } + else + { + // set/update the sheet name info + // try to restore the existing translation + uint transRowIdx; + if (transBotNames.findRow(transIdCol, first->first, transRowIdx)) + { + ucstring wkBotName = botNames.getData(rowIdx, ucstring("bot name")); + ucstring wkSheetName = botNames.getData(rowIdx, ucstring("sheet_name")); + ucstring wkTranslationName = botNames.getData(rowIdx, ucstring("translated name")); + ucstring ucWkHash; + uint64 hash = CI18N::makeHash(wkBotName + wkTranslationName +wkSheetName); + CI18N::hashToUCString(hash, ucWkHash); + ucstring trUcHash = transBotNames[transRowIdx][0]; + bool isWkTranslationNameAGroupName = wkTranslationName.find(ucstring("$")) != ucstring::npos; + bool hashIsValide = std::equal(ucWkHash.begin(), ucWkHash.end(), trUcHash.begin()+1); + // Hash is equal get the translation + if (hashIsValide && !isWkTranslationNameAGroupName) + { + wkTranslationName = transBotNames.getData(transRowIdx, ucstring("translated name")); + wkSheetName = transBotNames.getData(transRowIdx, ucstring("sheet_name")); + botNames.setData(rowIdx, ucstring("translated name"), wkTranslationName); + botNames.setData(rowIdx, ucstring("sheet_name"), wkSheetName); + hash = CI18N::makeHash(wkBotName + wkTranslationName + wkSheetName); + // update the hash code + CI18N::hashToUCString(hash, transBotNames[transRowIdx][0]); + } + // bots_name.txt has been manually changed. We trust what the Level Designer has done. We don't destroy is work. + // or it is a simple + else + { + //use the "translated name" of the manually changed work/bot_name.txt + botNames.setData(rowIdx, ucstring("translated name"), wkTranslationName); + botNames.setData(rowIdx, ucstring("sheet_name"), wkSheetName); + } + } + } + } + } + + // 2 - generic names + + { + nlinfo(" Generic names..."); + + set::iterator first(GenericNames.begin()), last(GenericNames.end()); + for (; first != last; ++first) + { + string gnName = "gn_" + cleanupName(*first); + + ucstring fctsTitleId; + ucstring fctsName; + // add or modify the bot names + uint rowIdx; + if (!botNames.findRow(botIdCol, *first, rowIdx)) + { + // we need to add the entry + rowIdx = botNames.size(); + botNames.resize(botNames.size()+1); + + botNames.setData(rowIdx, ucstring("bot name"), *first); + botNames.setData(rowIdx, ucstring("translated name"), ucstring("$") + gnName + "$"); + botNames.setData(rowIdx, ucstring("sheet_name"), ucstring()); + fctsTitleId = gnName; + fctsName = *first; + + nbAddSimpleName++; + } + else + { + // look in the translated table to remember the translated name to write it in the string file + ucstring wkBotName = botNames.getData(rowIdx, ucstring("bot name")); + ucstring wkTranslationName = botNames.getData(rowIdx, ucstring("translated name")); + ucstring wkSheetName = botNames.getData(rowIdx, ucstring("sheet_name")); + + + nlinfo("Bot name:%s\n",wkBotName.toString().c_str()); + bool isWkTranslationNameAGroupName = wkTranslationName.find(ucstring("$")) != ucstring::npos; + + if ( isWkTranslationNameAGroupName ) //work name looks like "$gn_***$: do not modify + { + + //Do not change work/bot_name.txt + // update work/world_title.txt + + ucstring transName; + fctsTitleId = makeGroupName(wkTranslationName); + uint transRowIdx; + if (transBotNames.findRow(transIdCol, *first, transRowIdx)) + { + transName = transBotNames.getData(transRowIdx, ucstring("translated name")); + + if (transName.find(ucstring("$")) != ucstring::npos) + { + transName = fctsTitleId; + } + } + else + { + transName = fctsTitleId; + } + //Do not touch anything + botNames.setData(rowIdx, ucstring("translated name"), wkTranslationName); + botNames.setData(rowIdx, ucstring("sheet_name"), wkSheetName); + // fctsTitleId = makeGroupName(wkTranslationName); + fctsName = transName; + + } + else // WkTranslationName != "$gn*$" + { + uint transRowIdx; + ucstring transName; + ucstring wkSheetName; + // Get the translation as a simple name. + if (transBotNames.findRow(transIdCol, *first, transRowIdx)) + { + + transName = transBotNames.getData(transRowIdx, ucstring("translated name")); + ucstring trSheetName = transBotNames.getData(transRowIdx, ucstring("sheet_name")); + + //tr."translation name" is + if (transName.find(ucstring("$")) != ucstring::npos) + { + //get Translation, update hash + botNames[rowIdx][1] = transName; + botNames[rowIdx][2] = trSheetName; + fctsTitleId = makeGroupName(transName); + fctsName = makeGroupName(transName); + ucstring trNewUcHash; + uint64 hash = CI18N::makeHash(wkBotName + transName +trSheetName); + CI18N::hashToUCString(hash, trNewUcHash); + transBotNames[transRowIdx][0] = ucstring("_") + trNewUcHash; + } + else //botNames."translated name" != $gn_$ && tansName."translated name" != $gn_$ + { + + // get the translation back + //update work/bot_name.txt + wkTranslationName = ucstring("$")+gnName+"$"; + botNames[rowIdx][0] = wkBotName; + botNames[rowIdx][1] = wkTranslationName; + botNames[rowIdx][2] = wkSheetName; + + //update translated/bot_name.txt + + fctsName = transName; //transName + fctsTitleId = gnName; + ucstring trNewUcHash; + uint64 hash = CI18N::makeHash(botNames[rowIdx][0] + botNames[rowIdx][1] +botNames[rowIdx][2]); + CI18N::hashToUCString(hash, trNewUcHash); + transBotNames[transRowIdx][0] = ucstring("_") + trNewUcHash; + } + + } + else //There is no translation yet + { + fctsName = wkTranslationName; + wkTranslationName = ucstring("$")+gnName+"$"; + botNames[rowIdx][0] = wkBotName; + botNames[rowIdx][1] = wkTranslationName; + botNames[rowIdx][2] = wkSheetName; + fctsTitleId = gnName; + + + } + } + + } + + + // look for a corresponding entry + uint gnNameRow; + + + if (!fcts.findRow(fctsIdCol, fctsTitleId, gnNameRow)) + { + + // not found, add it + gnNameRow = fcts.size(); + fcts.resize(fcts.size()+1); + fcts.setData(gnNameRow, ucstring("title_id"), fctsTitleId); + fcts.setData(gnNameRow, ucstring("name"), fctsName); + nbAddGenericName++; + + } + else //Update + { + + } + } + } + + + // 3 - functions + { + nlinfo(" Functions..."); + + set::iterator first(Functions.begin()), last(Functions.end()); + for (; first != last; ++first) + { + string fctName = *first; + // look for a corresponding entry + uint functionRow; + if (!fcts.findRow(fctsIdCol, fctName, functionRow)) + { + // not found, add it + functionRow = fcts.size(); + fcts.resize(fcts.size()+1); + + fcts.setData(functionRow, ucstring("title_id"), fctName); + fcts.setData(functionRow, ucstring("name"), *first); + + nbAddFunction++; + } + } + } + + // display resum\E9 + nlinfo("Adding %u new simple name", nbAddSimpleName); + nlinfo("Adding %u new generic name", nbAddGenericName); + nlinfo("Adding %u new function name", nbAddFunction); + + // saving the modified files + + ucstring s = prepareExcelSheet(botNames); + CI18N::writeTextFile(work_path, s, false); + s = prepareExcelSheet(transBotNames); + CI18N::writeTextFile(trans_path, s, false); + s = prepareExcelSheet(fcts); + CI18N::writeTextFile(work_path, s, false); + + return 0; +} + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp index 6140a3985..233780ca5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp @@ -19,6 +19,8 @@ #include #include +int extractBotNamesAll(map > config_paths, string ligo_class_file, string trans_path, string work_path); + namespace Plugin { TranslationManagerPlugin::~TranslationManagerPlugin() @@ -54,7 +56,39 @@ void TranslationManagerPlugin::extensionsInitialized() QAction *aboutQtAction = menuManager->action(Core::Constants::ABOUT_QT); helpMenu->addSeparator(); helpMenu->insertAction(aboutQtAction, aboutTManPlugin); - menuManager->menuBar()->addMenu("Translation Manager"); + QMenu *transMenu = menuManager->menuBar()->addMenu("Translation Manager"); + /* Words extraction*/ + QAction *botnamesAct = new QAction("Extract bot_names", this); + connect(botnamesAct, SIGNAL(triggered()), this, SLOT(extractBotNames())); + transMenu->addAction(botnamesAct); +} + +void TranslationManagerPlugin::extractBotNames() +{ + // prepare the config paths + list paths,pathsR, georges, filters, languages; + string ligo, translation, work; + map > config_paths; + + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup("translationmanager"); + + paths = ConvertQStringList(settings->value("paths").toStringList()); /* paths */ + config_paths["paths"] = paths; + pathsR = ConvertQStringList(settings->value("pathsR").toStringList()); /* pathsR */ + config_paths["pathsR"] = pathsR; + georges = ConvertQStringList(settings->value("georges").toStringList()); /* georges */ + config_paths["georges"] = georges; + filters = ConvertQStringList(settings->value("filters").toStringList()); /* filters */ + config_paths["filters"] = filters; + languages = ConvertQStringList(settings->value("languages").toStringList()); /* languages */ + ligo = settings->value("ligo").toString().toStdString(); + translation = settings->value("translation").toString().toStdString(); + work = settings->value("work").toString().toStdString(); + settings->endGroup(); + + extractBotNamesAll(config_paths, ligo, translation, work); + } void TranslationManagerPlugin::setNelContext(NLMISC::INelContext *nelContext) @@ -67,6 +101,17 @@ void TranslationManagerPlugin::setNelContext(NLMISC::INelContext *nelContext) _LibContext = new NLMISC::CLibraryContext(*nelContext); } +list TranslationManagerPlugin::ConvertQStringList(QStringList listq) +{ + std::list stdlist; + Q_FOREACH(QString text, listq) + { + stdlist.push_back(text.toStdString()); + } + + return stdlist; +} + QString TranslationManagerPlugin::name() const { return "Translation Manager"; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h index c1bfc2548..07bf0d434 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h @@ -13,6 +13,8 @@ #include #include +using namespace std; + namespace NLMISC { class CLibraryContext; @@ -56,6 +58,11 @@ protected: private: ExtensionSystem::IPluginManager *_plugMan; QList _autoReleaseObjects; + list ConvertQStringList(QStringList list); + + +private Q_SLOTS: + void extractBotNames(); }; class CTranslationManagerContext: public Core::IContext @@ -87,6 +94,7 @@ public: } CSimpleViewer *m_simpleViewer; + }; } // namespace Plugin diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp index c3e4883d4..b3a731ae5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp @@ -18,15 +18,21 @@ #include "translation_manager_settings_page.h" // Qt includes +#include #include +#include +#include // NeL includes // Project includes +#include "../core/icore.h" namespace Plugin { +QString lastDir = "."; + CTranslationManagerSettingsPage::CTranslationManagerSettingsPage(QObject *parent) : IOptionsPage(parent), _currentPage(NULL) @@ -57,11 +63,248 @@ QWidget *CTranslationManagerSettingsPage::createPage(QWidget *parent) { _currentPage = new QWidget(parent); _ui.setupUi(_currentPage); + readSettings(); + connect(_ui.paths_add, SIGNAL(clicked()), this, SLOT(pathAdd())); + connect(_ui.paths_del, SIGNAL(clicked()), this, SLOT(pathDel())); + connect(_ui.pathsR_add, SIGNAL(clicked()), this, SLOT(pathRAdd())); + connect(_ui.pathsR_del, SIGNAL(clicked()), this, SLOT(pathRDel())); + connect(_ui.georges_add, SIGNAL(clicked()), this, SLOT(georgeAdd())); + connect(_ui.georges_del, SIGNAL(clicked()), this, SLOT(georgeDel())); + connect(_ui.filter_add, SIGNAL(clicked()), this, SLOT(filterAdd())); + connect(_ui.filter_del, SIGNAL(clicked()), this, SLOT(filterDel())); + connect(_ui.lang_add, SIGNAL(clicked()), this, SLOT(languageAdd())); + connect(_ui.lang_del, SIGNAL(clicked()), this, SLOT(languageDel())); + connect(_ui.translation_add, SIGNAL(clicked()), this, SLOT(translationAdd())); + connect(_ui.work_add, SIGNAL(clicked()), this, SLOT(workAdd())); + return _currentPage; } +void CTranslationManagerSettingsPage::pathAdd() +{ + QString newPath = QFileDialog::getExistingDirectory(_currentPage, "", lastDir); + if (!newPath.isEmpty()) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(newPath); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.paths_list->addItem(newItem); + lastDir = newPath; + } +} + +void CTranslationManagerSettingsPage::pathDel() +{ + QListWidgetItem *removeItem = _ui.paths_list->takeItem(_ui.paths_list->currentRow()); + if (!removeItem) + delete removeItem; +} + +void CTranslationManagerSettingsPage::pathRAdd() +{ + QString newPath = QFileDialog::getExistingDirectory(_currentPage, "", lastDir); + if (!newPath.isEmpty()) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(newPath); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.pathsR_list->addItem(newItem); + lastDir = newPath; + } +} + +void CTranslationManagerSettingsPage::pathRDel() +{ + QListWidgetItem *removeItem = _ui.pathsR_list->takeItem(_ui.pathsR_list->currentRow()); + if (!removeItem) + delete removeItem; +} + +void CTranslationManagerSettingsPage::georgeAdd() +{ + QString newPath = QFileDialog::getExistingDirectory(_currentPage, "", lastDir); + if (!newPath.isEmpty()) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(newPath); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.georges_list->addItem(newItem); + lastDir = newPath; + } +} + +void CTranslationManagerSettingsPage::georgeDel() +{ + QListWidgetItem *removeItem = _ui.georges_list->takeItem(_ui.georges_list->currentRow()); + if (!removeItem) + delete removeItem; +} + +void CTranslationManagerSettingsPage::filterAdd() +{ + QString newValue = _ui.filter_edit->text(); + if (!newValue.isEmpty()) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(newValue); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.filter_list->addItem(newItem); + } +} + +void CTranslationManagerSettingsPage::filterDel() +{ + QListWidgetItem *removeItem = _ui.filter_list->takeItem(_ui.filter_list->currentRow()); + if (!removeItem) + delete removeItem; +} + +void CTranslationManagerSettingsPage::languageAdd() +{ + QString newValue = _ui.lang_edit->text(); + if (!newValue.isEmpty()) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(newValue); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.lang_list->addItem(newItem); + } +} + +void CTranslationManagerSettingsPage::languageDel() +{ + QListWidgetItem *removeItem = _ui.lang_list->takeItem(_ui.lang_list->currentRow()); + if (!removeItem) + delete removeItem; +} + +void CTranslationManagerSettingsPage::translationAdd() +{ + QString newPath = QFileDialog::getExistingDirectory(_currentPage, ""); + if (!newPath.isEmpty()) + { + _ui.translation_edit->setText(newPath); + } +} + +void CTranslationManagerSettingsPage::workAdd() +{ + QString newPath = QFileDialog::getExistingDirectory(_currentPage, ""); + if (!newPath.isEmpty()) + { + _ui.work_edit->setText(newPath); + } +} + void CTranslationManagerSettingsPage::apply() { + writeSettings(); } +void CTranslationManagerSettingsPage::readSettings() +{ + QStringList paths, pathsR, georges, filters, languages; + QString ligo, translation, work; + + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup("translationmanager"); + + paths = settings->value("paths").toStringList(); /* paths */ + pathsR = settings->value("pathsR").toStringList(); /* pathsR */ + georges = settings->value("georges").toStringList(); /* georges */ + filters = settings->value("filters").toStringList(); /* filters */ + languages = settings->value("languages").toStringList(); /* languages */ + ligo = settings->value("ligo").toString(); + translation = settings->value("translation").toString(); + work = settings->value("work").toString(); + + settings->endGroup(); + /* paths */ + Q_FOREACH(QString path, paths) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(path); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.paths_list->addItem(newItem); + } + /* pathsR */ + Q_FOREACH(QString pathR, pathsR) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(pathR); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.pathsR_list->addItem(newItem); + } + /* georges */ + Q_FOREACH(QString george, georges) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(george); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.georges_list->addItem(newItem); + } + /* filter */ + Q_FOREACH(QString filter, filters) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(filter); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.filter_list->addItem(newItem); + } + /* languages */ + Q_FOREACH(QString lang, languages) + { + QListWidgetItem *newItem = new QListWidgetItem; + newItem->setText(lang); + newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); + _ui.lang_list->addItem(newItem); + } + /* ligo */ + _ui.ligo_edit->setText(ligo); + /* translation */ + _ui.translation_edit->setText(translation); + /* work */ + _ui.work_edit->setText(work); + +} + +void CTranslationManagerSettingsPage::writeSettings() +{ + QStringList paths, pathsR, georges, filters, languages; + QString ligo, translation, work; + /* paths */ + for (int i = 0; i < _ui.paths_list->count(); ++i) + paths << _ui.paths_list->item(i)->text(); + /* pathsR */ + for (int i = 0; i < _ui.pathsR_list->count(); ++i) + pathsR << _ui.pathsR_list->item(i)->text(); + /* georges */ + for (int i = 0; i < _ui.georges_list->count(); ++i) + georges << _ui.georges_list->item(i)->text(); + /* filters */ + for (int i = 0; i < _ui.filter_list->count(); ++i) + filters << _ui.filter_list->item(i)->text(); + /* languages */ + for (int i = 0; i < _ui.lang_list->count(); ++i) + languages << _ui.lang_list->item(i)->text(); + /* ligo path */ + ligo = _ui.ligo_edit->text(); + /* translations path*/ + translation = _ui.translation_edit->text(); + work = _ui.work_edit->text(); + + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup("translationmanager"); + settings->setValue("paths", paths); + settings->setValue("pathsR", pathsR); + settings->setValue("georges", georges); + settings->setValue("filters", filters); + settings->setValue("languages", languages); + settings->setValue("ligo", ligo); + settings->setValue("translation", translation); + settings->setValue("work", work); + settings->endGroup(); +} + + } /* namespace Plugin */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h index 53f9068e1..4fec51fb6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h @@ -47,10 +47,24 @@ public: virtual void apply(); virtual void finish() {} - +private Q_SLOTS: + void pathAdd(); + void pathDel(); + void pathRAdd(); + void pathRDel(); + void georgeAdd(); + void georgeDel(); + void filterAdd(); + void filterDel(); + void languageAdd(); + void languageDel(); + void translationAdd(); + void workAdd(); private: QWidget *_currentPage; Ui::CTranslationManagerSettingsPage _ui; + void writeSettings(); + void readSettings(); }; } // namespace Plugin diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui index 951be0615..c58533185 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui @@ -1,92 +1,393 @@ - - - CTranslationManagerSettingsPage - - - - 0 - 0 - 458 - 479 - - - - Form - - - - 0 - - - - - GroupBox - - - - - - PushButton - - - - - - - - - - PushButton - - - - - - - RadioButton - - - - - - - RadioButton - - - - - - - CheckBox - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - - - - - + + + CTranslationManagerSettingsPage + + + + 0 + 0 + 490 + 495 + + + + Form + + + + + + 1 + + + + Core paths + + + + + + + + + + Paths + + + + + + + Qt::Horizontal + + + + 318 + 20 + + + + + + + + dwadwadwa + + + + :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png + + + Qt::ToolButtonIconOnly + + + true + + + + + + + ... + + + + :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png + + + true + + + + + + + + + + + + + + + + + + Paths non recursives + + + + + + + Qt::Horizontal + + + + 218 + 20 + + + + + + + + + + + + :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png + + + true + + + + + + + ... + + + + :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png + + + true + + + + + + + + + + + + + + + + + + Georges Paths + + + + + + + Qt::Horizontal + + + + 258 + 20 + + + + + + + + + + + + :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png + + + true + + + + + + + + + + + :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png + + + true + + + + + + + + + + + + + + + Translation files paths + + + + + 9 + 230 + 450 + 201 + + + + + + + Ligo class file - This is the name of the world_editor_classes.xml file. + + + + + + + + + + Work directory + + + + + + + + + + + + ... + + + + + + + + + Translation directory + + + + + + + + + + + + ... + + + + + + + + + + + 9 + 10 + 211 + 221 + + + + + + + Filters + + + + + + + + + + + + + + :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png + + + true + + + + + + + + + + + :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png + + + true + + + + + + + + + + + + 240 + 10 + 221 + 221 + + + + + + + Languages + + + + + + + + + + + + + + :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png + + + true + + + + + + + + + + + :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png + + + true + + + + + + + + + + + + + + + + + + + From 624cb708131cbbd0297fcc7092548bd1d49b7da1 Mon Sep 17 00:00:00 2001 From: cemycc Date: Tue, 14 Jun 2011 18:01:21 +0300 Subject: [PATCH 06/34] Changed: #1307 Update the plugin to work with the latest plugin system --HG-- branch : gsoc2011-translationovqt --- .../src/plugins/translation_manager/extract_bot_names.cpp | 1 + .../src/plugins/translation_manager/simple_viewer.cpp | 2 ++ .../src/plugins/translation_manager/simple_viewer.h | 4 +++- .../translation_manager/translation_manager_plugin.cpp | 8 ++++---- .../translation_manager/translation_manager_plugin.h | 8 ++++++++ .../translation_manager_settings_page.cpp | 5 +++++ .../translation_manager_settings_page.h | 3 ++- .../translation_manager_settings_page.ui | 2 +- 8 files changed, 26 insertions(+), 7 deletions(-) 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 index 75a97d3bb..3a24127e3 100644 --- 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 @@ -36,6 +36,7 @@ vector Filters; static CLigoConfig LigoConfig; static bool RemoveOlds = false; + struct TCreatureInfo { CSheetId SheetId; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.cpp index e128710c4..1f6df9117 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.cpp @@ -37,6 +37,8 @@ CSimpleViewer::CSimpleViewer(QWidget *parent) gridLayout->setContentsMargins(0, 0, 0, 0); NLQT::QNLWidget *_nelWidget = new NLQT::QNLWidget(this); gridLayout->addWidget(_nelWidget, 0, 0, 1, 1); + + m_undoStack = new QUndoStack(this); } bool CCoreListener::closeMainWindow() const diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.h index bbff7e9e0..14b782c22 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.h @@ -25,7 +25,7 @@ // Qt includes #include - +#include class QWidget; namespace Plugin @@ -37,6 +37,8 @@ class CSimpleViewer : public QWidget public: CSimpleViewer(QWidget *parent = 0); virtual ~CSimpleViewer() {} + + QUndoStack *m_undoStack; }; class CCoreListener : public Core::ICoreListener diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp index 233780ca5..f82024c79 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp @@ -57,10 +57,10 @@ void TranslationManagerPlugin::extensionsInitialized() helpMenu->addSeparator(); helpMenu->insertAction(aboutQtAction, aboutTManPlugin); QMenu *transMenu = menuManager->menuBar()->addMenu("Translation Manager"); - /* Words extraction*/ - QAction *botnamesAct = new QAction("Extract bot_names", this); - connect(botnamesAct, SIGNAL(triggered()), this, SLOT(extractBotNames())); - transMenu->addAction(botnamesAct); + // Words extraction + QAction *botnamesAct = new QAction("Extract bot_names", this); + connect(botnamesAct, SIGNAL(triggered()), this, SLOT(extractBotNames())); + transMenu->addAction(botnamesAct); } void TranslationManagerPlugin::extractBotNames() diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h index 07bf0d434..0dc6e6510 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h @@ -92,6 +92,14 @@ public: { return m_simpleViewer; } + virtual QUndoStack *undoStack() + { + return m_simpleViewer->m_undoStack; + } + virtual void open() + { + + } CSimpleViewer *m_simpleViewer; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp index b3a731ae5..d99cc8642 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp @@ -59,6 +59,11 @@ QString CTranslationManagerSettingsPage::trCategory() const return tr("General"); } +QIcon CTranslationManagerSettingsPage::categoryIcon() const +{ + return QIcon(); +} + QWidget *CTranslationManagerSettingsPage::createPage(QWidget *parent) { _currentPage = new QWidget(parent); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h index 4fec51fb6..7a082f199 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h @@ -43,8 +43,9 @@ public: 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: diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui index c58533185..6da7b0d8b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui @@ -7,7 +7,7 @@ 0 0 490 - 495 + 482 From 32c07d0b62d332e259aa9e5c05820c6275ce1b5d Mon Sep 17 00:00:00 2001 From: cemycc Date: Tue, 21 Jun 2011 01:03:54 +0300 Subject: [PATCH 07/34] Changed: #1307 Added extract_bot_names --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/CMakeLists.txt | 6 +- .../translation_manager/extract_bot_names.cpp | 111 +++++----- .../translation_manager/qnel_widget.cpp | 197 ------------------ .../plugins/translation_manager/qnel_widget.h | 130 ------------ .../translation_manager/simple_viewer.cpp | 56 ----- .../translation_manager_main_window.cpp | 169 +++++++++++++++ ...er.h => translation_manager_main_window.h} | 40 +++- .../translation_manager_plugin.cpp | 50 +---- .../translation_manager_plugin.h | 18 +- .../translation_manager_settings_page.cpp | 42 ++-- .../translation_manager_settings_page.ui | 12 +- 11 files changed, 302 insertions(+), 529 deletions(-) delete mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.cpp delete mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.h delete mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp rename code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/{simple_viewer.h => translation_manager_main_window.h} (60%) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt index 827db7487..ec3980f05 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt @@ -10,11 +10,11 @@ SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin. ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h) SET(OVQT_PLUG_TRANSLATION_MANAGER_HDR translation_manager_plugin.h - qnel_widget.h - simple_viewer.h + translation_manager_main_window.h translation_manager_settings_page.h) -SET(OVQT_PLUG_TRANSLATION_MANAGER_UIS translation_manager_settings_page.ui) +SET(OVQT_PLUG_TRANSLATION_MANAGER_UIS translation_manager_settings_page.ui + translation_manager_main_window.ui) SET(QT_USE_QTGUI TRUE) SET(QT_USE_QTOPENGL TRUE) 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 index 3a24127e3..a5e5690ad 100644 --- 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 @@ -145,6 +145,15 @@ set GenericNames; map SimpleNames; set Functions; +set getGenericNames() +{ + return GenericNames; +} + +map getSimpleNames() +{ + return SimpleNames; +} string removeAndStoreFunction(const std::string &fullName) { @@ -221,40 +230,6 @@ void addSimpleName(const std::string &name, const std::string &sheetName) int extractBotNamesAll(map > config_paths, string ligo_class_file, string trans_path, string work_path) { - //------------------------------------------------------------------- - // read the parameters - /*for (int i=2; i::iterator it = config_paths["paths"].begin(); it != config_paths["paths"].end(); ++it) { CPath::addSearchPath(*it, true, false); @@ -269,7 +244,6 @@ int extractBotNamesAll(map > config_paths, string ligo_class Filters.push_back(*it); } - //------------------------------------------------------------------- // init the sheets CSheetId::init(false); @@ -451,26 +425,62 @@ int extractBotNamesAll(map > config_paths, string ligo_class } else { - TEntryInfo ei; addSimpleName(removeAndStoreFunction(name), sheetStr); } } } - } - + } + //------------------------------------------------------------------- // step 2 : load the reference file nlinfo("Looking for missing translation:"); + + string work_path_file = work_path + "/bot_names.txt"; + string trans_path_file = trans_path + "/bot_names.txt"; + string title_path_file = work_path + "/title_words_wk.txt"; + + TWorksheet botNames; + if (!CFile::fileExists(work_path_file) || !loadExcelSheet(work_path_file, botNames)) + { + botNames.resize(botNames.size() + 1); + botNames.insertColumn(botNames.ColCount); + botNames.setData(0,botNames.ColCount - 1,ucstring("bot name")); + botNames.insertColumn(botNames.ColCount); + botNames.setData(0,botNames.ColCount - 1,ucstring("translated name")); + botNames.insertColumn(botNames.ColCount); + botNames.setData(0,botNames.ColCount - 1,ucstring("sheet_name")); + } - TWorksheet botNames; - loadExcelSheet(work_path, botNames, true); - TWorksheet transBotNames; - loadExcelSheet(trans_path, transBotNames, true); + TWorksheet transBotNames; + if (!CFile::fileExists(trans_path_file) || !loadExcelSheet(trans_path_file, transBotNames)) + { + transBotNames.resize(transBotNames.size() + 1); + transBotNames.insertColumn(transBotNames.ColCount); + transBotNames.setData(0,transBotNames.ColCount - 1,ucstring("*HASH_VALUE")); + transBotNames.insertColumn(transBotNames.ColCount); + transBotNames.setData(0,transBotNames.ColCount - 1,ucstring("bot name")); + transBotNames.insertColumn(transBotNames.ColCount); + transBotNames.setData(0,transBotNames.ColCount - 1,ucstring("translated name")); + transBotNames.insertColumn(transBotNames.ColCount); + transBotNames.setData(0,transBotNames.ColCount - 1,ucstring("sheet_name")); + } - TWorksheet fcts; - loadExcelSheet(work_path, fcts, true); + TWorksheet fcts; + if (!CFile::fileExists(title_path_file) || !loadExcelSheet(title_path_file, fcts)) + { + fcts.resize(fcts.size() + 1); + fcts.insertColumn(fcts.ColCount); + fcts.setData(0,fcts.ColCount - 1,ucstring("title_id")); + fcts.insertColumn(fcts.ColCount); + fcts.setData(0,fcts.ColCount - 1,ucstring("name")); + fcts.insertColumn(fcts.ColCount); + fcts.setData(0,fcts.ColCount - 1,ucstring("women_name")); + } + loadExcelSheet(work_path_file, botNames, true); + loadExcelSheet(trans_path_file, transBotNames, true); + loadExcelSheet(title_path_file, fcts, true); // add missing element @@ -482,9 +492,9 @@ int extractBotNamesAll(map > config_paths, string ligo_class nlverify(botNames.findId(botIdCol)); uint transIdCol; nlverify(transBotNames.findId(transIdCol)); - uint fctsIdCol; + uint fctsIdCol; nlverify(fcts.findId(fctsIdCol)); - + // special treatment to add the sheet_name col { uint sheetCol; @@ -743,14 +753,13 @@ int extractBotNamesAll(map > config_paths, string ligo_class nlinfo("Adding %u new generic name", nbAddGenericName); nlinfo("Adding %u new function name", nbAddFunction); - // saving the modified files - + // saving the modified files ucstring s = prepareExcelSheet(botNames); - CI18N::writeTextFile(work_path, s, false); + CI18N::writeTextFile(work_path_file, s, false); s = prepareExcelSheet(transBotNames); - CI18N::writeTextFile(trans_path, s, false); + CI18N::writeTextFile(trans_path_file, s, false); s = prepareExcelSheet(fcts); - CI18N::writeTextFile(work_path, s, false); + CI18N::writeTextFile(title_path_file, s, false); return 0; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.cpp deleted file mode 100644 index 9a67abb80..000000000 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.cpp +++ /dev/null @@ -1,197 +0,0 @@ -// Object Viewer Qt - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// Copyright (C) 2011 Dzmitry Kamiahin -// -// 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 "qnel_widget.h" - -// STL includes - -// Qt includes -#include -#include - -// NeL includes -#include -#include -#include -#include - -namespace NLQT -{ - -QNLWidget::QNLWidget(QWidget *parent) - : QNeLWidget(parent), - m_driver(NULL), - m_initialized(false), - m_interval(25) -{ - setMouseTracking(true); - setFocusPolicy(Qt::StrongFocus); - - init(); -#ifdef Q_OS_LINUX - makeCurrent(); -#endif - m_mainTimer = new QTimer(this); - connect(m_mainTimer, SIGNAL(timeout()), this, SLOT(updateRender())); -} - -QNLWidget::~QNLWidget() -{ - release(); -} - -void QNLWidget::init() -{ - // create the driver - m_driver = NL3D::UDriver::createDriver(NULL, false, NULL); - nlassert(m_driver); - - // initialize the nel 3d viewport - m_driver->setDisplay((nlWindow)winId(), NL3D::UDriver::CMode(width(), height(), 32)); - - // set the cache size for the font manager(in bytes) - m_driver->setFontManagerMaxMemory(2097152); - - m_initialized = true; -} - -void QNLWidget::release() -{ - m_mainTimer->stop(); - delete m_mainTimer; - if (m_initialized) - { - m_driver->release(); - delete m_driver; - m_driver = NULL; - } -} - -void QNLWidget::setInterval(int msec) -{ - m_interval = msec; - m_mainTimer->setInterval(msec); -} - -void QNLWidget::setBackgroundColor(NLMISC::CRGBA backgroundColor) -{ - m_backgroundColor = backgroundColor; -} - -void QNLWidget::updateRender() -{ - if (isVisible()) - { - if (m_initialized) - m_driver->EventServer.pump(); - Q_EMIT updateData(); - - // Calc FPS - static sint64 lastTime = NLMISC::CTime::getPerformanceTime (); - sint64 newTime = NLMISC::CTime::getPerformanceTime (); - m_fps = float(1.0 / NLMISC::CTime::ticksToSecond (newTime-lastTime)); - lastTime = newTime; - - if (m_initialized && !m_driver->isLost()) - { - //_driver->activate(); - m_driver->clearBuffers(m_backgroundColor); - Q_EMIT updatePreRender(); - - Q_EMIT updatePostRender(); - // swap 3d buffers - m_driver->swapBuffers(); - } - } -} - -void QNLWidget::showEvent(QShowEvent *showEvent) -{ - QWidget::showEvent(showEvent); - m_driver->activate(); - m_mainTimer->start(m_interval); -} - -void QNLWidget::hideEvent(QHideEvent *hideEvent) -{ - m_mainTimer->stop(); - QWidget::hideEvent(hideEvent); -} - -#if defined(NL_OS_WINDOWS) - -typedef bool (*winProc)(NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); - -bool QNLWidget::winEvent(MSG *message, long *result) -{ - if (m_driver && m_driver->isActive()) - { - NL3D::IDriver *driver = dynamic_cast(m_driver)->getDriver(); - if (driver) - { - winProc proc = (winProc)driver->getWindowProc(); - return proc(driver, message->hwnd, message->message, message->wParam, message->lParam); - } - } - - return false; -} - -#elif defined(NL_OS_MAC) - -typedef bool (*cocoaProc)(NL3D::IDriver *, const void *e); - -bool QNLWidget::macEvent(EventHandlerCallRef caller, EventRef event) -{ - if(caller) - nlerror("You are using QtCarbon! Only QtCocoa supported, please upgrade Qt"); - - if (m_driver && m_driver->isActive()) - { - NL3D::IDriver *driver = dynamic_cast(m_driver)->getDriver(); - if (driver) - { - cocoaProc proc = (cocoaProc)driver->getWindowProc(); - return proc(driver, event); - } - } - - return false; -} - -#elif defined(NL_OS_UNIX) - -typedef bool (*x11Proc)(NL3D::IDriver *drv, XEvent *e); - -bool QNLWidget::x11Event(XEvent *event) -{ - if (m_driver && m_driver->isActive()) - { - NL3D::IDriver *driver = dynamic_cast(m_driver)->getDriver(); - if (driver) - { - x11Proc proc = (x11Proc)driver->getWindowProc(); - return proc(driver, event); - } - } - - return false; -} -#endif - -} /* namespace NLQT */ - diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.h deleted file mode 100644 index a54e6bb8a..000000000 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/qnel_widget.h +++ /dev/null @@ -1,130 +0,0 @@ -// Object Viewer Qt - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// Copyright (C) 2011 Dzmitry Kamiahin -// -// 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 QNEL_WIDGET_H -#define QNEL_WIDGET_H - -// NeL includes -#include -#include -#include - -// Qt includes -#include -#include - -class QAction; - -/* TODO every platform should use QWidget */ -#if defined(NL_OS_WINDOWS) -typedef QWidget QNeLWidget; -#elif defined(NL_OS_MAC) -typedef QWidget QNeLWidget; -#elif defined(NL_OS_UNIX) -typedef QGLWidget QNeLWidget; -#endif // NL_OS_UNIX - -namespace NL3D -{ -class UDriver; -class UScene; -} - -namespace NLQT -{ - -/** -@class QNLWidget -@brief Responsible for interaction between Qt and NeL. -@details Automatically begins to update the render if the widget is visible -or suspends the updating of render if the widget is hidden. -*/ -class QNLWidget : public QNeLWidget -{ - Q_OBJECT - -public: - QNLWidget(QWidget *parent); - virtual ~QNLWidget(); - - /// Set the update interval renderer - void setInterval(int msec); - - /// Set the background color. - void setBackgroundColor(NLMISC::CRGBA backgroundColor); - - float fps() const - { - return m_fps; - } - - inline NLMISC::CRGBA backgroundColor() const - { - return m_backgroundColor; - } - - NL3D::UDriver *driver() const - { - return m_driver; - } - - virtual QPaintEngine* paintEngine() const - { - return NULL; - } -Q_SIGNALS: - void updateData(); - void updatePreRender(); - void updatePostRender(); - -private Q_SLOTS: - void updateRender(); - -protected: - virtual void showEvent(QShowEvent *showEvent); - virtual void hideEvent(QHideEvent *hideEvent); - -#if defined(NL_OS_WINDOWS) - virtual bool winEvent(MSG *message, long *result); -#elif defined(NL_OS_MAC) - virtual bool macEvent(EventHandlerCallRef caller, EventRef event); -#elif defined(NL_OS_UNIX) - virtual bool x11Event(XEvent *event); -#endif - -private: - void init(); - void release(); - - QNLWidget(const QNLWidget &); - QNLWidget &operator=(const QNLWidget &); - - NL3D::UDriver *m_driver; - NLMISC::CRGBA m_backgroundColor; - - QTimer *m_mainTimer; - - bool m_initialized; - int m_interval; - float m_fps; - -}; /* class QNLWidget */ - -} /* namespace NLQT */ - - -#endif // QNEL_WIDGET_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.cpp deleted file mode 100644 index 1f6df9117..000000000 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Object Viewer Qt - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// Copyright (C) 2011 Dzmitry Kamiahin -// -// 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 "simple_viewer.h" - -// Qt includes -#include -#include -#include - -// NeL includes - -// Project includes - -namespace Plugin -{ - -CSimpleViewer::CSimpleViewer(QWidget *parent) - : QWidget(parent) -{ - QGridLayout *gridLayout = new QGridLayout(this); - gridLayout->setObjectName(QString::fromUtf8("gridLayoutSimpleViewer")); - gridLayout->setContentsMargins(0, 0, 0, 0); - NLQT::QNLWidget *_nelWidget = new NLQT::QNLWidget(this); - gridLayout->addWidget(_nelWidget, 0, 0, 1, 1); - - m_undoStack = new QUndoStack(this); -} - -bool CCoreListener::closeMainWindow() const -{ - int ret = QMessageBox::question(0, tr("Example close event hook"), - tr("Do you want to close window?"), - QMessageBox::Yes | QMessageBox::No); - - if (ret == QMessageBox::Yes) - return true; - else - return false; -} - -} /* namespace Plugin */ \ No newline at end of file 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..159e80e04 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp @@ -0,0 +1,169 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// 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_main_window.h" +// Project system includes +#include "../core/icore.h" +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +struct TEntryInfo +{ + string SheetName; +}; + +set getGenericNames(); +map getSimpleNames(); +int extractBotNamesAll(map > config_paths, string ligo_class_file, string trans_path, string work_path); + +namespace Plugin +{ + +CMainWindow::CMainWindow(QWidget *parent) + : QMainWindow(parent) +{ + _ui.setupUi(this); + + _toolMenu = new QMenu(tr("Primitives"), _ui.toolBar); + _ui.toolBar->addAction(_toolMenu->menuAction()); + + QAction *extractBotNames = _toolMenu->addAction(tr("Extract bot names")); + extractBotNames->setStatusTip(tr("Extract bot names from primitives")); + connect(extractBotNames, SIGNAL(triggered()), this, SLOT(extractBotNames())); + + + + readSettings(); + m_undoStack = new QUndoStack(this); +} + +void CMainWindow::readSettings() +{ + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup("translationmanager"); + + list paths = convertQStringList(settings->value("paths").toStringList()); /* paths */ + config_paths["paths"] = paths; + list pathsR = convertQStringList(settings->value("pathsR").toStringList()); /* pathsR */ + config_paths["pathsR"] = pathsR; + list georges = convertQStringList(settings->value("georges").toStringList()); /* georges */ + config_paths["georges"] = georges; + list filters = convertQStringList(settings->value("filters").toStringList()); /* filters */ + config_paths["filters"] = filters; + + languages = convertQStringList(settings->value("trlanguages").toStringList()); /* languages */ + ligo_path = settings->value("ligo").toString().toStdString(); + translation_path = settings->value("translation").toString().toStdString(); + work_path = settings->value("work").toString().toStdString(); + + settings->endGroup(); +} + +void CMainWindow::extractBotNames() +{ + if(verifySettings() == true) + { + // int extract_bot_names = extractBotNamesAll(config_paths, ligo_path, translation_path, work_path); + + QGridLayout* mainLayout = new QGridLayout(); + + + + //contentsWindow->setAllowedAreas(Qt::LeftDockWidgetArea); + + + QListWidget *listWidget = new QListWidget(this); + + mainLayout->addWidget(QListWidget); + + + + QTableWidget *tableWidget = new QTableWidget(this); + + tableWidget->setRowCount(10); + tableWidget->setColumnCount(5); + + mainLayout->addWidget(QTableWidget); + setCentralWidget(tableWidget); + } +} + + +bool CMainWindow::verifySettings() +{ + bool count_errors = false; + + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup("translationmanager"); + + if(settings->value("paths").toList().count() == 0 + || settings->value("pathsR").toList().count() == 0 + || settings->value("georges").toList().count() == 0 + || settings->value("filters").toList().count() == 0) + { + QErrorMessage error_settings; + error_settings.showMessage("Please write all the paths on the settings dialog."); + error_settings.exec(); + count_errors = true; + } + + if((settings->value("ligo").toString().isEmpty() + || settings->value("translation").toString().isEmpty() + || settings->value("work").toString().isEmpty() + || settings->value("trlanguages").toList().count() == 0) + && count_errors == false) + { + QErrorMessage error_settings; + error_settings.showMessage("Please write the paths for ligo, translation and work files and the languages on the settings dialog." + settings->value("trlanguages").toString()); + error_settings.exec(); + count_errors = true; + } + + settings->endGroup(); + + return !count_errors; + +} + +list CMainWindow::convertQStringList(QStringList listq) +{ + std::list stdlist; + + Q_FOREACH(QString text, listq) + { + stdlist.push_back(text.toStdString()); + } + + return stdlist; +} + +bool CCoreListener::closeMainWindow() const +{ + return true; +} + +} /* namespace Plugin */ \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h similarity index 60% rename from code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.h rename to code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h index 14b782c22..4e90c6088 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/simple_viewer.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h @@ -16,29 +16,53 @@ // along with this program. If not, see . -#ifndef SIMPLE_VIEWER_H -#define SIMPLE_VIEWER_H +#ifndef MAIN_WINDOW_H +#define MAIN_WINDOW_H // Project includes -#include "qnel_widget.h" #include "../core/icore_listener.h" // Qt includes #include #include +#include +#include +#include +#include + +#include "ui_translation_manager_main_window.h" +#include + class QWidget; +using namespace std; + namespace Plugin { -class CSimpleViewer : public QWidget +class CMainWindow : public QMainWindow { Q_OBJECT public: - CSimpleViewer(QWidget *parent = 0); - virtual ~CSimpleViewer() {} - - QUndoStack *m_undoStack; + CMainWindow(QWidget *parent = 0); + virtual ~CMainWindow() {} + QUndoStack *m_undoStack; +private: + Ui::CMainWindow _ui; + QMenu *_toolMenu; + map > config_paths; + list languages; + string ligo_path; + string translation_path; + string work_path; +private Q_SLOTS: + void extractBotNames(); +private: + void compareBotNames(); + bool verifySettings(); + void readSettings(); + list convertQStringList(QStringList listq); + }; class CCoreListener : public Core::ICoreListener diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp index f82024c79..91e7686d5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp @@ -1,7 +1,7 @@ // Project includes #include "translation_manager_plugin.h" #include "translation_manager_settings_page.h" -#include "simple_viewer.h" +#include "translation_manager_main_window.h" // Project system includes #include "../core/icore.h" #include "../core/core_constants.h" @@ -14,13 +14,12 @@ // Qt includes #include #include +#include #include #include #include #include -int extractBotNamesAll(map > config_paths, string ligo_class_file, string trans_path, string work_path); - namespace Plugin { TranslationManagerPlugin::~TranslationManagerPlugin() @@ -41,6 +40,7 @@ bool TranslationManagerPlugin::initialize(ExtensionSystem::IPluginManager *plugi addAutoReleasedObject(new CTranslationManagerSettingsPage(this)); addAutoReleasedObject(new CTranslationManagerContext(this)); addAutoReleasedObject(new CCoreListener(this)); + return true; } @@ -56,39 +56,6 @@ void TranslationManagerPlugin::extensionsInitialized() QAction *aboutQtAction = menuManager->action(Core::Constants::ABOUT_QT); helpMenu->addSeparator(); helpMenu->insertAction(aboutQtAction, aboutTManPlugin); - QMenu *transMenu = menuManager->menuBar()->addMenu("Translation Manager"); - // Words extraction - QAction *botnamesAct = new QAction("Extract bot_names", this); - connect(botnamesAct, SIGNAL(triggered()), this, SLOT(extractBotNames())); - transMenu->addAction(botnamesAct); -} - -void TranslationManagerPlugin::extractBotNames() -{ - // prepare the config paths - list paths,pathsR, georges, filters, languages; - string ligo, translation, work; - map > config_paths; - - QSettings *settings = Core::ICore::instance()->settings(); - settings->beginGroup("translationmanager"); - - paths = ConvertQStringList(settings->value("paths").toStringList()); /* paths */ - config_paths["paths"] = paths; - pathsR = ConvertQStringList(settings->value("pathsR").toStringList()); /* pathsR */ - config_paths["pathsR"] = pathsR; - georges = ConvertQStringList(settings->value("georges").toStringList()); /* georges */ - config_paths["georges"] = georges; - filters = ConvertQStringList(settings->value("filters").toStringList()); /* filters */ - config_paths["filters"] = filters; - languages = ConvertQStringList(settings->value("languages").toStringList()); /* languages */ - ligo = settings->value("ligo").toString().toStdString(); - translation = settings->value("translation").toString().toStdString(); - work = settings->value("work").toString().toStdString(); - settings->endGroup(); - - extractBotNamesAll(config_paths, ligo, translation, work); - } void TranslationManagerPlugin::setNelContext(NLMISC::INelContext *nelContext) @@ -101,17 +68,6 @@ void TranslationManagerPlugin::setNelContext(NLMISC::INelContext *nelContext) _LibContext = new NLMISC::CLibraryContext(*nelContext); } -list TranslationManagerPlugin::ConvertQStringList(QStringList listq) -{ - std::list stdlist; - Q_FOREACH(QString text, listq) - { - stdlist.push_back(text.toStdString()); - } - - return stdlist; -} - QString TranslationManagerPlugin::name() const { return "Translation Manager"; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h index 0dc6e6510..42515cb2f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h @@ -4,7 +4,7 @@ // Project includes #include "../../extension_system/iplugin.h" #include "../core/icontext.h" -#include "simple_viewer.h" +#include "translation_manager_main_window.h" // NeL includes #include "nel/misc/app_context.h" @@ -28,12 +28,13 @@ class IPluginSpec; namespace Plugin { + 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); @@ -58,11 +59,6 @@ protected: private: ExtensionSystem::IPluginManager *_plugMan; QList _autoReleaseObjects; - list ConvertQStringList(QStringList list); - - -private Q_SLOTS: - void extractBotNames(); }; class CTranslationManagerContext: public Core::IContext @@ -71,7 +67,7 @@ class CTranslationManagerContext: public Core::IContext public: CTranslationManagerContext(QObject *parent = 0): IContext(parent) { - m_simpleViewer = new CSimpleViewer(); + m_MainWindow = new CMainWindow(); } virtual ~CTranslationManagerContext() {} @@ -90,18 +86,18 @@ public: } virtual QWidget *widget() { - return m_simpleViewer; + return m_MainWindow; } virtual QUndoStack *undoStack() { - return m_simpleViewer->m_undoStack; + return m_MainWindow->m_undoStack; } virtual void open() { } - CSimpleViewer *m_simpleViewer; + CMainWindow *m_MainWindow; }; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp index d99cc8642..078a9c18c 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp @@ -68,7 +68,7 @@ QWidget *CTranslationManagerSettingsPage::createPage(QWidget *parent) { _currentPage = new QWidget(parent); _ui.setupUi(_currentPage); - readSettings(); + readSettings(); connect(_ui.paths_add, SIGNAL(clicked()), this, SLOT(pathAdd())); connect(_ui.paths_del, SIGNAL(clicked()), this, SLOT(pathDel())); connect(_ui.pathsR_add, SIGNAL(clicked()), this, SLOT(pathRAdd())); @@ -79,8 +79,8 @@ QWidget *CTranslationManagerSettingsPage::createPage(QWidget *parent) 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())); + connect(_ui.translation_add, SIGNAL(clicked()), this, SLOT(translationAdd())); + connect(_ui.work_add, SIGNAL(clicked()), this, SLOT(workAdd())); return _currentPage; } @@ -218,13 +218,13 @@ void CTranslationManagerSettingsPage::readSettings() pathsR = settings->value("pathsR").toStringList(); /* pathsR */ georges = settings->value("georges").toStringList(); /* georges */ filters = settings->value("filters").toStringList(); /* filters */ - languages = settings->value("languages").toStringList(); /* languages */ + languages = settings->value("trlanguages").toStringList(); /* languages */ ligo = settings->value("ligo").toString(); translation = settings->value("translation").toString(); work = settings->value("work").toString(); settings->endGroup(); - /* paths */ + // paths Q_FOREACH(QString path, paths) { QListWidgetItem *newItem = new QListWidgetItem; @@ -232,7 +232,7 @@ void CTranslationManagerSettingsPage::readSettings() newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); _ui.paths_list->addItem(newItem); } - /* pathsR */ + // pathsR Q_FOREACH(QString pathR, pathsR) { QListWidgetItem *newItem = new QListWidgetItem; @@ -240,7 +240,7 @@ void CTranslationManagerSettingsPage::readSettings() newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); _ui.pathsR_list->addItem(newItem); } - /* georges */ + // georges Q_FOREACH(QString george, georges) { QListWidgetItem *newItem = new QListWidgetItem; @@ -248,7 +248,7 @@ void CTranslationManagerSettingsPage::readSettings() newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); _ui.georges_list->addItem(newItem); } - /* filter */ + // filter Q_FOREACH(QString filter, filters) { QListWidgetItem *newItem = new QListWidgetItem; @@ -256,7 +256,7 @@ void CTranslationManagerSettingsPage::readSettings() newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); _ui.filter_list->addItem(newItem); } - /* languages */ + // languages Q_FOREACH(QString lang, languages) { QListWidgetItem *newItem = new QListWidgetItem; @@ -264,11 +264,11 @@ void CTranslationManagerSettingsPage::readSettings() newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); _ui.lang_list->addItem(newItem); } - /* ligo */ + // ligo _ui.ligo_edit->setText(ligo); - /* translation */ + // translation _ui.translation_edit->setText(translation); - /* work */ + // work _ui.work_edit->setText(work); } @@ -277,25 +277,26 @@ void CTranslationManagerSettingsPage::writeSettings() { QStringList paths, pathsR, georges, filters, languages; QString ligo, translation, work; - /* paths */ + // paths for (int i = 0; i < _ui.paths_list->count(); ++i) paths << _ui.paths_list->item(i)->text(); - /* pathsR */ + // pathsR for (int i = 0; i < _ui.pathsR_list->count(); ++i) pathsR << _ui.pathsR_list->item(i)->text(); - /* georges */ + // georges for (int i = 0; i < _ui.georges_list->count(); ++i) georges << _ui.georges_list->item(i)->text(); - /* filters */ + // filters for (int i = 0; i < _ui.filter_list->count(); ++i) filters << _ui.filter_list->item(i)->text(); - /* languages */ + // languages for (int i = 0; i < _ui.lang_list->count(); ++i) languages << _ui.lang_list->item(i)->text(); - /* ligo path */ + // ligo path ligo = _ui.ligo_edit->text(); - /* translations path*/ + // translations path translation = _ui.translation_edit->text(); + // work path work = _ui.work_edit->text(); QSettings *settings = Core::ICore::instance()->settings(); @@ -304,11 +305,12 @@ void CTranslationManagerSettingsPage::writeSettings() settings->setValue("pathsR", pathsR); settings->setValue("georges", georges); settings->setValue("filters", filters); - settings->setValue("languages", languages); + settings->setValue("trlanguages", languages); settings->setValue("ligo", ligo); settings->setValue("translation", translation); settings->setValue("work", work); settings->endGroup(); + settings->sync(); } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui index 6da7b0d8b..4c932b4f5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui @@ -7,7 +7,7 @@ 0 0 490 - 482 + 496 @@ -214,9 +214,9 @@ 9 - 230 - 450 - 201 + 190 + 454 + 161 @@ -280,7 +280,7 @@ 9 10 211 - 221 + 181 @@ -333,7 +333,7 @@ 240 10 221 - 221 + 181 From ed92fd2a786d1d20b349c710bae2cd6a366eb837 Mon Sep 17 00:00:00 2001 From: cemycc Date: Sat, 25 Jun 2011 16:42:45 +0300 Subject: [PATCH 08/34] Changed: #1307 Added editor for worksheet files. --HG-- branch : gsoc2011-translationovqt --- .../translation_manager_main_window.cpp | 122 +++++++++++++----- .../translation_manager_main_window.h | 34 ++++- .../translation_manager_main_window.ui | 57 ++++++++ 3 files changed, 183 insertions(+), 30 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.ui 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 index 159e80e04..5dedd7c70 100644 --- 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 @@ -18,6 +18,9 @@ #include "translation_manager_main_window.h" // Project system includes #include "../core/icore.h" +#include "../core/core_constants.h" +#include "../core/imenu_manager.h" +#include "../../extension_system/iplugin_spec.h" // Qt includes #include #include @@ -27,10 +30,14 @@ #include #include #include +#include #include #include #include #include +#include +#include + struct TEntryInfo { string SheetName; @@ -48,19 +55,97 @@ CMainWindow::CMainWindow(QWidget *parent) { _ui.setupUi(this); - _toolMenu = new QMenu(tr("Primitives"), _ui.toolBar); - _ui.toolBar->addAction(_toolMenu->menuAction()); - - QAction *extractBotNames = _toolMenu->addAction(tr("Extract bot names")); - extractBotNames->setStatusTip(tr("Extract bot names from primitives")); - connect(extractBotNames, SIGNAL(triggered()), this, SLOT(extractBotNames())); - - readSettings(); + createToolbar(); m_undoStack = new QUndoStack(this); } +void CMainWindow::createToolbar() +{ + // Tools menu + Core::IMenuManager *menuManager = Core::ICore::instance()->menuManager(); + QMenu *translationManagerMenu = new QMenu("Translation Manager"); + QAction *extractBotNamesAct = translationManagerMenu->addAction("Extract bot names"); + extractBotNamesAct->setStatusTip(tr("Extract bot names from primitives")); + QMenu *toolMenu = menuManager->menu(Core::Constants::M_TOOLS); + toolMenu->addMenu(translationManagerMenu); + + + // File menu + //QAction *action = menuManager->action(Core::Constants::NEW); + //_ui.toolBar->addAction(action); + openAct = menuManager->action(Core::Constants::OPEN); + _ui.toolBar->addAction(openAct); + connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + + saveAct = menuManager->action(Core::Constants::SAVE); + _ui.toolBar->addAction(saveAct); + connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); + //action = menuManager->action(Core::Constants::SAVE_AS); + //_ui.toolBar->addAction(action); + +} + +void CMainWindow::open() +{ + QString file_name = QFileDialog::getOpenFileName(this); + if (!file_name.isEmpty()) + { + STRING_MANAGER::TWorksheet wk_file; + if(loadExcelSheet(file_name.toStdString(), wk_file, true) == true) + { + QTableWidget *wk_table = new QTableWidget(); + wk_table->setToolTip(file_name); + wk_table->setWindowFilePath(file_name); + wk_table->setColumnCount(wk_file.ColCount); + wk_table->setRowCount(wk_file.size() - 1); + // read columns name + for(unsigned int i = 0; i < wk_file.ColCount; i++) + { + QTableWidgetItem *col = new QTableWidgetItem(); + ucstring col_name = wk_file.getData(0, i); + col->setText(tr(col_name.toString().c_str())); + + wk_table->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++) + { + QTableWidgetItem *row = new QTableWidgetItem(); + ucstring row_value = wk_file.getData(i, j); + row->setText(tr(row_value.toString().c_str())); + + wk_table->setItem(i - 1, j, row); + } + } + QMdiSubWindow *sub_window = new QMdiSubWindow(_ui.mdiArea); + sub_window->setWidget(wk_table); + wk_table->resizeColumnsToContents(); + wk_table->resizeRowsToContents(); + wk_table->showMaximized(); + sub_window->activateWindow(); + //_ui.mdiArea->addSubWindow(sub_window); + // set editor signals + connect(wk_table, SIGNAL(cellChanged(int,int) ), this, SLOT(sheetEditorChanged(int,int))); + } + } + +} + +void CMainWindow::sheetEditorChanged(int, int) +{ + saveAct->setEnabled(true); +} + +void CMainWindow::save() +{ + QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow(); + +} + void CMainWindow::readSettings() { QSettings *settings = Core::ICore::instance()->settings(); @@ -87,28 +172,7 @@ void CMainWindow::extractBotNames() { if(verifySettings() == true) { - // int extract_bot_names = extractBotNamesAll(config_paths, ligo_path, translation_path, work_path); - - QGridLayout* mainLayout = new QGridLayout(); - - - - //contentsWindow->setAllowedAreas(Qt::LeftDockWidgetArea); - - - QListWidget *listWidget = new QListWidget(this); - mainLayout->addWidget(QListWidget); - - - - QTableWidget *tableWidget = new QTableWidget(this); - - tableWidget->setRowCount(10); - tableWidget->setColumnCount(5); - - mainLayout->addWidget(QTableWidget); - setCentralWidget(tableWidget); } } 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 index 4e90c6088..863145bc5 100644 --- 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 @@ -22,6 +22,12 @@ // Project 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" + // Qt includes #include #include @@ -29,6 +35,8 @@ #include #include #include +#include + #include "ui_translation_manager_main_window.h" #include @@ -49,7 +57,10 @@ public: QUndoStack *m_undoStack; private: Ui::CMainWindow _ui; - QMenu *_toolMenu; + // actions + QAction *openAct; + QAction *saveAct; + // config map > config_paths; list languages; string ligo_path; @@ -57,12 +68,18 @@ private: string work_path; private Q_SLOTS: void extractBotNames(); + void open(); + void save(); + void sheetEditorChanged(int, int); private: void compareBotNames(); bool verifySettings(); void readSettings(); + void createMenus(); + void createToolbar(); list convertQStringList(QStringList listq); + }; class CCoreListener : public Core::ICoreListener @@ -75,6 +92,21 @@ public: virtual bool closeMainWindow() const; }; +class CMdiSubWindow : public QMdiSubWindow +{ + private: + int window_type; + public: + int getWType() + { + return window_type; + } + void setWType(int nType) + { + window_type = nType; + } +}; + } // namespace Plugin #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..395574415 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.ui @@ -0,0 +1,57 @@ + + + CMainWindow + + + + 0 + 0 + 883 + 576 + + + + MainWindow + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + true + + + + + + + + + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + + From fe125bbaebe1792c9e44f323a7354c6c18541432 Mon Sep 17 00:00:00 2001 From: cemycc Date: Sun, 26 Jun 2011 05:48:28 +0300 Subject: [PATCH 09/34] Changed: #1307 Added option for SaveAs and a windows list --HG-- branch : gsoc2011-translationovqt --- .../translation_manager_main_window.cpp | 175 ++++++++++++++++-- .../translation_manager_main_window.h | 17 ++ 2 files changed, 180 insertions(+), 12 deletions(-) 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 index 5dedd7c70..1866b3975 100644 --- 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 @@ -37,6 +37,10 @@ #include #include #include +#include +#include +#include + struct TEntryInfo { @@ -54,7 +58,8 @@ CMainWindow::CMainWindow(QWidget *parent) : QMainWindow(parent) { _ui.setupUi(this); - + _ui.mdiArea->closeAllSubWindows(); + connect(_ui.mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)),this, SLOT(activeSubWindowChanged())); readSettings(); createToolbar(); @@ -72,19 +77,55 @@ void CMainWindow::createToolbar() toolMenu->addMenu(translationManagerMenu); - // File menu - //QAction *action = menuManager->action(Core::Constants::NEW); - //_ui.toolBar->addAction(action); - openAct = menuManager->action(Core::Constants::OPEN); + // File menu + openAct = new QAction(QIcon(Core::Constants::ICON_OPEN), "&Open...", this); _ui.toolBar->addAction(openAct); connect(openAct, SIGNAL(triggered()), this, SLOT(open())); - saveAct = menuManager->action(Core::Constants::SAVE); + saveAct = new QAction(QIcon(Core::Constants::ICON_SAVE), "&Save...", this); _ui.toolBar->addAction(saveAct); connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); - //action = menuManager->action(Core::Constants::SAVE_AS); - //_ui.toolBar->addAction(action); - + + saveAsAct = new QAction(QIcon(Core::Constants::ICON_SAVE_AS), "&Save as...", this); + _ui.toolBar->addAction(saveAsAct); + connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); + + // Windows menu + windowMapper = new QSignalMapper(this); + connect(windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*))); + windowMenu = new QMenu(tr("&Windows..."), _ui.toolBar); + windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL)); + _ui.toolBar->addAction(windowMenu->menuAction()); + connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowsList())); + + +} + +void CMainWindow::activeSubWindowChanged() +{ + updateWindowsList(); +} + +void CMainWindow::updateWindowsList() +{ + int i = 0; + windowMenu->clear(); + QList windows = _ui.mdiArea->subWindowList(); + for (QList::iterator it = windows.begin(); it != windows.end(); ++it) { + QString window_file = QFileInfo((*it)->widget()->windowFilePath()).fileName(); + QString action_text; + if (i < 9) { + action_text = tr("&%1 %2").arg(i + 1).arg(window_file); + } else { + action_text = tr("%1 %2").arg(i + 1).arg(window_file); + } + QAction *action = windowMenu->addAction(action_text); + action->setCheckable(true); + action->setChecked((*it) == _ui.mdiArea->activeSubWindow()); + connect(action, SIGNAL(triggered()), windowMapper, SLOT(map())); + windowMapper->setMapping(action, windows.at(i)); + i++; + } } void CMainWindow::open() @@ -127,23 +168,126 @@ void CMainWindow::open() wk_table->resizeRowsToContents(); wk_table->showMaximized(); sub_window->activateWindow(); - //_ui.mdiArea->addSubWindow(sub_window); // set editor signals connect(wk_table, SIGNAL(cellChanged(int,int) ), this, SLOT(sheetEditorChanged(int,int))); + // windows menu + updateWindowsList(); + } else { + QErrorMessage error_settings; + error_settings.showMessage("This file is not a worksheet file."); + error_settings.exec(); } } } -void CMainWindow::sheetEditorChanged(int, int) +void CMainWindow::sheetEditorChanged(int row, int column) { saveAct->setEnabled(true); + QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow(); + if(modifiedCells.find(current_window) != modifiedCells.end()) // founded + { + list cells = modifiedCells[current_window]; + bool overwriteResult = false; + for(list::iterator it = cells.begin(); it != cells.end(); ++it) + { + if((*it).row == row && (*it).col == column ) + overwriteResult = true; + } + if(overwriteResult == false) + { + CCelPos v; + v.row = row; + v.col = column; + cells.push_back(v); + } + } else { // not found + list cells; + CCelPos v; + v.row = row; + v.col = column; + cells.push_back(v); + modifiedCells[current_window] = cells; + } } void CMainWindow::save() { QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow(); + + if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + { + QWidget *subwindow_widget = current_window->widget(); + QTableWidget *table_editor = qobject_cast(subwindow_widget); + QString file_path = table_editor->windowFilePath(); + + if(modifiedCells.find(current_window) != modifiedCells.end()) + { + STRING_MANAGER::TWorksheet wk_file; + loadExcelSheet(file_path.toStdString(), wk_file, true); + list cells = modifiedCells[current_window]; + for(list::iterator it = cells.begin(); it != cells.end(); ++it) + { + QTableWidgetItem* edited_item = table_editor->item((*it).row, (*it).col); + wk_file.setData((*it).row + 1, (*it).col, ucstring(edited_item->text().toStdString())); + cells.erase(it); + } + ucstring s = prepareExcelSheet(wk_file); + NLMISC::CI18N::writeTextFile(file_path.toStdString(), s, false); + if(cells.size() == 0) + modifiedCells.erase(current_window); + } + } +} +void CMainWindow::saveAs() +{ + QString file_name; + if (_ui.mdiArea->isActiveWindow()) + { + file_name = QFileDialog::getSaveFileName(this); + } + + if (!file_name.isEmpty()) + { + QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow(); + + if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + { + QWidget *subwindow_widget = current_window->widget(); + QTableWidget *table_editor = qobject_cast(subwindow_widget); + QString orig_file_path = table_editor->windowFilePath(); + STRING_MANAGER::TWorksheet new_file, wk_file; + loadExcelSheet(orig_file_path.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; + for(int i = 0; i < table_editor->rowCount(); i++) + { + rowIdx = new_file.size(); + new_file.resize(new_file.size() + 1); + for(int j = 0; j < table_editor->columnCount(); j++) + { + QTableWidgetItem* item = table_editor->item(i, j); + new_file.setData(rowIdx, j, ucstring(item->text().toStdString())); + } + } + ucstring s = prepareExcelSheet(new_file); + NLMISC::CI18N::writeTextFile(file_name.toStdString(), s, false); + } + + } + + QErrorMessage error_settings; + error_settings.showMessage( file_name); + error_settings.exec(); } void CMainWindow::readSettings() @@ -212,7 +356,14 @@ bool CMainWindow::verifySettings() return !count_errors; } - + + void CMainWindow::setActiveSubWindow(QWidget *window) + { + if (!window) + return; + _ui.mdiArea->setActiveSubWindow(qobject_cast(window)); + } + list CMainWindow::convertQStringList(QStringList listq) { std::list stdlist; 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 index 863145bc5..9d7cb8862 100644 --- 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 @@ -36,6 +36,8 @@ #include #include #include +#include + #include "ui_translation_manager_main_window.h" @@ -48,6 +50,12 @@ using namespace std; namespace Plugin { +struct CCelPos +{ + int col; + int row; +}; + class CMainWindow : public QMainWindow { Q_OBJECT @@ -57,9 +65,14 @@ public: QUndoStack *m_undoStack; private: Ui::CMainWindow _ui; + + map > modifiedCells; // actions QAction *openAct; QAction *saveAct; + QAction *saveAsAct; + QMenu *windowMenu; + QSignalMapper *windowMapper; // config map > config_paths; list languages; @@ -70,13 +83,17 @@ private Q_SLOTS: void extractBotNames(); void open(); void save(); + void saveAs(); void sheetEditorChanged(int, int); + void setActiveSubWindow(QWidget *window); + void activeSubWindowChanged(); private: void compareBotNames(); bool verifySettings(); void readSettings(); void createMenus(); void createToolbar(); + void updateWindowsList(); list convertQStringList(QStringList listq); From f19ebefbe69b326d25864223bf2f6b47258c25b1 Mon Sep 17 00:00:00 2001 From: cemycc Date: Mon, 27 Jun 2011 03:02:21 +0300 Subject: [PATCH 10/34] Changed: #1307 Added option to extract the botnames from primitives. --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/extract_bot_names.cpp | 28 ++- .../translation_manager_main_window.cpp | 192 +++++++++++++----- .../translation_manager_main_window.h | 2 + 3 files changed, 161 insertions(+), 61 deletions(-) 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 index a5e5690ad..66d7d1c69 100644 --- 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 @@ -155,6 +155,16 @@ map getSimpleNames() return SimpleNames; } +void cleanSimpleNames() +{ + SimpleNames.clear(); +} + +void cleanGenericNames() +{ + GenericNames.clear(); +} + string removeAndStoreFunction(const std::string &fullName) { string::size_type pos = fullName.find("$"); @@ -228,7 +238,7 @@ void addSimpleName(const std::string &name, const std::string &sheetName) } } -int extractBotNamesAll(map > config_paths, string ligo_class_file, string trans_path, string work_path) +void setPathsForPrimitives(map > config_paths, string ligo_class_file) { for (std::list::iterator it = config_paths["paths"].begin(); it != config_paths["paths"].end(); ++it) { @@ -265,8 +275,11 @@ int extractBotNamesAll(map > config_paths, string ligo_class LigoConfig.readPrimitiveClass(ligoPath.c_str(), false); NLLIGO::Register(); - CPrimitiveContext::instance().CurrentLigoConfig = &LigoConfig; + CPrimitiveContext::instance().CurrentLigoConfig = &LigoConfig; +} +void extractBotNamesFromPrimitives() +{ //------------------------------------------------------------------- // ok, ready for the real work, // first, read the primitives files and parse the primitives @@ -429,8 +442,13 @@ int extractBotNamesAll(map > config_paths, string ligo_class } } } - } - + } +} + +int extractBotNamesAll(map > config_paths, string ligo_class_file, string trans_path, string work_path) +{ + + /* //------------------------------------------------------------------- // step 2 : load the reference file @@ -760,7 +778,7 @@ int extractBotNamesAll(map > config_paths, string ligo_class CI18N::writeTextFile(trans_path_file, s, false); s = prepareExcelSheet(fcts); CI18N::writeTextFile(title_path_file, s, false); - +*/ return 0; } 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 index 1866b3975..946ed78fe 100644 --- 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 @@ -48,8 +48,13 @@ struct TEntryInfo }; set getGenericNames(); +void cleanGenericNames(); map getSimpleNames(); -int extractBotNamesAll(map > config_paths, string ligo_class_file, string trans_path, string work_path); +void cleanSimpleNames(); +void setPathsForPrimitives(map > config_paths, string ligo_class_file); +void extractBotNamesFromPrimitives(); +string cleanupName(const std::string &name); +ucstring cleanupUcName(const ucstring &name); namespace Plugin { @@ -61,6 +66,9 @@ CMainWindow::CMainWindow(QWidget *parent) _ui.mdiArea->closeAllSubWindows(); connect(_ui.mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)),this, SLOT(activeSubWindowChanged())); + // set extraction scripts counters + execution_count["extract_bot_names"] = 0; + readSettings(); createToolbar(); m_undoStack = new QUndoStack(this); @@ -68,28 +76,25 @@ CMainWindow::CMainWindow(QWidget *parent) void CMainWindow::createToolbar() { - // Tools menu - Core::IMenuManager *menuManager = Core::ICore::instance()->menuManager(); - QMenu *translationManagerMenu = new QMenu("Translation Manager"); - QAction *extractBotNamesAct = translationManagerMenu->addAction("Extract bot names"); - extractBotNamesAct->setStatusTip(tr("Extract bot names from primitives")); - QMenu *toolMenu = menuManager->menu(Core::Constants::M_TOOLS); - toolMenu->addMenu(translationManagerMenu); - - // File menu openAct = new QAction(QIcon(Core::Constants::ICON_OPEN), "&Open...", this); _ui.toolBar->addAction(openAct); - connect(openAct, SIGNAL(triggered()), this, SLOT(open())); - + 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())); - + 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()); + QAction *extractBotNamesAct = wordsExtractionMenu->addAction("&Extract bot names..."); + extractBotNamesAct->setStatusTip(tr("Extract bot names from primitives.")); + connect(extractBotNamesAct, SIGNAL(triggered()), this, SLOT(extractBotNames())); + // Windows menu windowMapper = new QSignalMapper(this); connect(windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*))); @@ -97,8 +102,6 @@ void CMainWindow::createToolbar() windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL)); _ui.toolBar->addAction(windowMenu->menuAction()); connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowsList())); - - } void CMainWindow::activeSubWindowChanged() @@ -136,32 +139,60 @@ void CMainWindow::open() STRING_MANAGER::TWorksheet wk_file; if(loadExcelSheet(file_name.toStdString(), wk_file, true) == true) { + bool hasHashValue = false; QTableWidget *wk_table = new QTableWidget(); wk_table->setToolTip(file_name); wk_table->setWindowFilePath(file_name); - wk_table->setColumnCount(wk_file.ColCount); + if(wk_file.getData(0, 0) == ucstring("*HASH_VALUE")) + { + wk_table->setColumnCount(wk_file.ColCount - 1); + hasHashValue = true; + } else { + wk_table->setColumnCount(wk_file.ColCount); + } wk_table->setRowCount(wk_file.size() - 1); // read columns name + for(unsigned int i = 0; i < wk_file.ColCount; i++) { - QTableWidgetItem *col = new QTableWidgetItem(); - ucstring col_name = wk_file.getData(0, i); - col->setText(tr(col_name.toString().c_str())); - - wk_table->setHorizontalHeaderItem(i, col); + 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(tr(col_name.toString().c_str())); + if(hasHashValue) + { + wk_table->setHorizontalHeaderItem(i - 1, col); + } else { + wk_table->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++) { - QTableWidgetItem *row = new QTableWidgetItem(); - ucstring row_value = wk_file.getData(i, j); - row->setText(tr(row_value.toString().c_str())); - - wk_table->setItem(i - 1, j, row); - } - } + 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(tr(row_value.toString().c_str())); + if(hasHashValue) + { + wk_table->setItem(i - 1, j - 1, row); + } else { + wk_table->setItem(i - 1, j, row); + } + } + } + } + QMdiSubWindow *sub_window = new QMdiSubWindow(_ui.mdiArea); sub_window->setWidget(wk_table); wk_table->resizeColumnsToContents(); @@ -170,7 +201,6 @@ void CMainWindow::open() sub_window->activateWindow(); // set editor signals connect(wk_table, SIGNAL(cellChanged(int,int) ), this, SLOT(sheetEditorChanged(int,int))); - // windows menu updateWindowsList(); } else { QErrorMessage error_settings; @@ -284,10 +314,81 @@ void CMainWindow::saveAs() } } - - QErrorMessage error_settings; - error_settings.showMessage( file_name); - error_settings.exec(); +} + +void CMainWindow::extractBotNames() +{ + if(verifySettings() == true) + { + QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow(); + if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + { + if(execution_count["extract_bot_names"] == 0) + setPathsForPrimitives(config_paths, ligo_path); + extractBotNamesFromPrimitives(); + execution_count["extract_bot_names"] = execution_count["extract_bot_names"] + 1; + + QWidget *subwindow_widget = current_window->widget(); + QTableWidget *table_editor = qobject_cast(subwindow_widget); + // get SimpleNames + { + map SimpleNames = getSimpleNames(); + map::iterator it(SimpleNames.begin()), last(SimpleNames.end()); + + for (; it != last; ++it) + { + QList search_results = table_editor->findItems(tr(it->first.c_str()), Qt::MatchExactly); + if(search_results.size() == 0) + { + const int currentRow = table_editor->rowCount(); + table_editor->setRowCount(currentRow + 1); + QTableWidgetItem *bot_name_row = new QTableWidgetItem(); + bot_name_row->setText(tr(it->first.c_str())); + bot_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, 0, bot_name_row); + QTableWidgetItem *translation_name_row = new QTableWidgetItem(); + translation_name_row->setBackgroundColor(QColor("#F75D59")); + translation_name_row->setText(tr(it->first.c_str())); + table_editor ->setItem(currentRow , 1, translation_name_row); + QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); + sheet_name_row->setText(tr(it->second.SheetName.c_str())); + sheet_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, 2, sheet_name_row); + } + } + cleanSimpleNames(); + } + // get GenericNames + { + set GenericNames = getGenericNames(); + set::iterator it(GenericNames.begin()), last(GenericNames.end()); + for (; it != last; ++it) + { + string gnName = "gn_" + cleanupName(*it); + QList search_results = table_editor->findItems(tr((*it).c_str()), Qt::MatchExactly); + if(search_results.size() == 0) + { + const int currentRow = table_editor->rowCount(); + table_editor->setRowCount(currentRow + 1); + QTableWidgetItem *bot_name_row = new QTableWidgetItem(); + bot_name_row->setText(tr((*it).c_str())); + bot_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, 0, bot_name_row); + QTableWidgetItem *translation_name_row = new QTableWidgetItem(); + translation_name_row->setBackgroundColor(QColor("#F75D59")); + translation_name_row->setText(tr(gnName.c_str())); + table_editor ->setItem(currentRow , 1, translation_name_row); + QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); + sheet_name_row->setText(" "); + sheet_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, 2, sheet_name_row); + } + } + cleanGenericNames(); + } + + } + } } void CMainWindow::readSettings() @@ -312,15 +413,6 @@ void CMainWindow::readSettings() settings->endGroup(); } -void CMainWindow::extractBotNames() -{ - if(verifySettings() == true) - { - - } -} - - bool CMainWindow::verifySettings() { bool count_errors = false; @@ -338,19 +430,7 @@ bool CMainWindow::verifySettings() error_settings.exec(); count_errors = true; } - - if((settings->value("ligo").toString().isEmpty() - || settings->value("translation").toString().isEmpty() - || settings->value("work").toString().isEmpty() - || settings->value("trlanguages").toList().count() == 0) - && count_errors == false) - { - QErrorMessage error_settings; - error_settings.showMessage("Please write the paths for ligo, translation and work files and the languages on the settings dialog." + settings->value("trlanguages").toString()); - error_settings.exec(); - count_errors = true; - } - + settings->endGroup(); return !count_errors; 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 index 9d7cb8862..4df21fa0b 100644 --- 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 @@ -79,6 +79,8 @@ private: string ligo_path; string translation_path; string work_path; + // counts + map execution_count; private Q_SLOTS: void extractBotNames(); void open(); From e55bbed5b4262a33154f46e122a40edb7739ef69 Mon Sep 17 00:00:00 2001 From: cemycc Date: Fri, 1 Jul 2011 21:51:41 +0300 Subject: [PATCH 11/34] Changed: #1307 New structure for subwindows from QMdiArea --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/CMakeLists.txt | 4 +- .../translation_manager/editor_worksheet.cpp | 353 +++++++++++++++++ .../translation_manager/editor_worksheet.h | 48 +++ .../translation_manager_editor.h | 35 ++ .../translation_manager_main_window.cpp | 371 +++++++----------- .../translation_manager_main_window.h | 52 ++- .../translation_manager_main_window.ui | 26 +- .../translation_manager_plugin.cpp | 2 +- 8 files changed, 606 insertions(+), 285 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt index ec3980f05..edc0a60e5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt @@ -11,7 +11,9 @@ SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin. SET(OVQT_PLUG_TRANSLATION_MANAGER_HDR translation_manager_plugin.h translation_manager_main_window.h - translation_manager_settings_page.h) + translation_manager_settings_page.h + translation_manager_editor.h + editor_worksheet.h) SET(OVQT_PLUG_TRANSLATION_MANAGER_UIS translation_manager_settings_page.ui translation_manager_main_window.ui) 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..ee32e3979 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp @@ -0,0 +1,353 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// 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 "editor_worksheet.h" +#include +// Qt includes +#include +#include +#include +#include +#include + +using namespace std; + +struct TEntryInfo +{ + string SheetName; +}; + +set getGenericNames(); +void cleanGenericNames(); +map getSimpleNames(); +void cleanSimpleNames(); +void setPathsForPrimitives(map > config_paths, string ligo_class_file); +void extractBotNamesFromPrimitives(); +string cleanupName(const std::string &name); +ucstring cleanupUcName(const ucstring &name); + +namespace Plugin { + + + +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(tr(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(tr(row_value.toString().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); + table_editor->resizeColumnsToContents(); + table_editor->resizeRowsToContents(); + // set editor signals + connect(table_editor, SIGNAL(cellChanged(int,int) ), this, SLOT(worksheetEditorChanged(int,int))); + } else { + QErrorMessage error; + error.showMessage("This file is not a worksheet file."); + error.exec(); + } + +} + +void CEditorWorksheet::activateWindow() +{ + showMaximized(); + +} + +void CEditorWorksheet::save() +{ + STRING_MANAGER::TWorksheet wk_file; + loadExcelSheet(current_file.toStdString(), wk_file, true); + 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++) + { + // maybe extra rows ? + if((unsigned)table_editor->rowCount() > (wk_file.size() - 1)) + { + rowIdx = wk_file.size(); + wk_file.resize(rowIdx + table_editor->rowCount() - wk_file.size() + 1); + } + for(int j = 0; j < table_editor->columnCount(); j++) + { + ucstring tvalue; + ucstring colname; + uint rowIdf; + QString tvalueQt = table_editor->item(i, j)->text(); + tvalue = ucstring(tvalueQt.toStdString()); + colname = wk_file.getData(0, j + colIdx); + + rowIdf = uint(i + 1); + if(wk_file.findRow(j + colIdx, colname, rowIdf)) + { + if(wk_file.getData(i + 1, j + colIdx) != tvalue) + { + wk_file.setData(i + 1, j + colIdx, tvalue); + } + } else { + wk_file.setData(i + 1, j + colIdx, tvalue); + } + } + } + if(hasHashValue) + { + // rewrite the hash codes + makeHashCode(wk_file, true); + } + // write to file + ucstring s = prepareExcelSheet(wk_file); + NLMISC::CI18N::writeTextFile(current_file.toStdString(), s, false); + setCurrentFile(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); + for(int j = 0; j < table_editor->columnCount(); j++) + { + QTableWidgetItem* item = table_editor->item(i, j); + new_file.setData(rowIdx, j + colIdx, ucstring(item->text().toStdString())); + } + } + if(hasHashValue) + { + // rewrite the hash codes + makeHashCode(wk_file, true); + } + ucstring s = prepareExcelSheet(new_file); + NLMISC::CI18N::writeTextFile(filename.toStdString(), s, false); + setCurrentFile(filename); +} + +void CEditorWorksheet::insertRow() +{ + int last_row = table_editor->rowCount(); + table_editor->setRowCount(last_row + 1); + for(int j = 0; j < table_editor->columnCount(); j++) + { + QTableWidgetItem* item = new QTableWidgetItem(); + //item->setText(QString(" ")); + table_editor->setItem(last_row, j, item); + } +} + +void CEditorWorksheet::deleteRow() +{ + int selected_row = table_editor->currentRow(); + QMessageBox msgBox; + msgBox.setText("The row will be deleted."); + msgBox.setInformativeText("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) + { + table_editor->removeRow(selected_row); + } + + table_editor->clearFocus(); + table_editor->clearSelection(); + return; +} + +void CEditorWorksheet::worksheetEditorChanged(int row, int column) +{ + +} + +void CEditorWorksheet::extractBotNames() +{ + bool modified = false; +// get SimpleNames + { + map SimpleNames = getSimpleNames(); + map::iterator it(SimpleNames.begin()), last(SimpleNames.end()); + + for (; it != last; ++it) + { + QList search_results = table_editor->findItems(tr(it->first.c_str()), Qt::MatchExactly); + if(search_results.size() == 0) + { + const int currentRow = table_editor->rowCount(); + table_editor->setRowCount(currentRow + 1); + QTableWidgetItem *bot_name_row = new QTableWidgetItem(); + bot_name_row->setText(tr(it->first.c_str())); + bot_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, 0, bot_name_row); + QTableWidgetItem *translation_name_row = new QTableWidgetItem(); + translation_name_row->setBackgroundColor(QColor("#F75D59")); + translation_name_row->setText(tr(it->first.c_str())); + table_editor ->setItem(currentRow , 1, translation_name_row); + QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); + sheet_name_row->setText(tr(it->second.SheetName.c_str())); + sheet_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, 2, sheet_name_row); + if(!modified) modified = true; + } + } + cleanSimpleNames(); + } + // get GenericNames + { + set GenericNames = getGenericNames(); + set::iterator it(GenericNames.begin()), last(GenericNames.end()); + for (; it != last; ++it) + { + string gnName = "gn_" + cleanupName(*it); + QList search_results = table_editor->findItems(tr((*it).c_str()), Qt::MatchExactly); + if(search_results.size() == 0) + { + const int currentRow = table_editor->rowCount(); + table_editor->setRowCount(currentRow + 1); + QTableWidgetItem *bot_name_row = new QTableWidgetItem(); + bot_name_row->setText(tr((*it).c_str())); + bot_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, 0, bot_name_row); + QTableWidgetItem *translation_name_row = new QTableWidgetItem(); + translation_name_row->setBackgroundColor(QColor("#F75D59")); + translation_name_row->setText(tr(gnName.c_str())); + table_editor ->setItem(currentRow , 1, translation_name_row); + QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); + sheet_name_row->setText(" "); + sheet_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, 2, sheet_name_row); + if(!modified) modified = true; + } + } + cleanGenericNames(); + } + if(modified) + { + setWindowModified(true); + } + +} + +void CEditorWorksheet::setCurrentFile(QString filename) +{ + QFileInfo *file = new QFileInfo(filename); + current_file = file->canonicalFilePath(); + setWindowModified(false); + setWindowTitle(file->fileName() + "[*]"); + setWindowFilePath(current_file); +} + +void CEditorWorksheet::closeEvent(QCloseEvent *event) +{ + close(); + event->accept(); + +} + +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; +} + +} + + 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..71e86af84 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h @@ -0,0 +1,48 @@ + +#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" + +// Qt includes +#include +#include +#include +#include +#include + +#include "translation_manager_editor.h" + +namespace Plugin { + +class CEditorWorksheet : public CEditor +{ + Q_OBJECT +private: + QTableWidget* table_editor; +public: + CEditorWorksheet(QMdiArea* parent) : CEditor(parent) {} + CEditorWorksheet() : CEditor() {} + void open(QString filename); + void save(); + void saveAs(QString filename); + void activateWindow(); + void extractBotNames(); + bool isBotNamesTable(); + void closeEvent(QCloseEvent *event); +private Q_SLOTS: + void worksheetEditorChanged(int,int); + void insertRow(); + void deleteRow(); +private: + void setCurrentFile(QString filename); + +}; + +}; +#endif /* EDITOR_WORKSHEET_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..605d11d6e --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h @@ -0,0 +1,35 @@ + +#ifndef TRANSLATION_MANAGER_EDITOR_H +#define TRANSLATION_MANAGER_EDITOR_H + +#include +#include +#include +#include + +namespace Plugin { + +class CEditor : public QMdiSubWindow { +Q_OBJECT +protected: + 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: + QString subWindowFilePath() + { + return 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 index 946ed78fe..8b8c50a22 100644 --- 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 @@ -16,6 +16,8 @@ // along with this program. If not, see . #include "translation_manager_main_window.h" +#include "editor_worksheet.h" + // Project system includes #include "../core/icore.h" #include "../core/core_constants.h" @@ -40,6 +42,9 @@ #include #include #include +#include +#include + struct TEntryInfo @@ -63,9 +68,12 @@ CMainWindow::CMainWindow(QWidget *parent) : QMainWindow(parent) { _ui.setupUi(this); + _ui.mdiArea->closeAllSubWindows(); connect(_ui.mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)),this, SLOT(activeSubWindowChanged())); - + windowMapper = new QSignalMapper(this); + connect(windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*))); + // set extraction scripts counters execution_count["extract_bot_names"] = 0; @@ -96,26 +104,52 @@ void CMainWindow::createToolbar() connect(extractBotNamesAct, SIGNAL(triggered()), this, SLOT(extractBotNames())); // Windows menu - windowMapper = new QSignalMapper(this); - connect(windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*))); windowMenu = new QMenu(tr("&Windows..."), _ui.toolBar); - windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL)); + windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL)); + updateWindowsList(); _ui.toolBar->addAction(windowMenu->menuAction()); connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowsList())); } +void CMainWindow::updateToolbar(QMdiSubWindow *window) +{ + if(_ui.mdiArea->subWindowList().size() > 0) + if(QString(window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + { + QAction *insertRowAct = windowMenu->addAction("Insert new row"); + connect(insertRowAct, SIGNAL(triggered()), window, SLOT(insertRow())); + QAction *deleteRowAct = windowMenu->addAction("Delete row"); + connect(deleteRowAct, SIGNAL(triggered()), window, SLOT(deleteRow())); + + } +} + +void CMainWindow::setActiveSubWindow(QWidget* window) +{ + if (!window) + { + return; + } + QMdiSubWindow *cwindow = qobject_cast(window); + _ui.mdiArea->setActiveSubWindow(cwindow); +} + void CMainWindow::activeSubWindowChanged() { - updateWindowsList(); + } void CMainWindow::updateWindowsList() { - int i = 0; windowMenu->clear(); - QList windows = _ui.mdiArea->subWindowList(); - for (QList::iterator it = windows.begin(); it != windows.end(); ++it) { - QString window_file = QFileInfo((*it)->widget()->windowFilePath()).fileName(); + 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 = tr("&%1 %2").arg(i + 1).arg(window_file); @@ -124,149 +158,49 @@ void CMainWindow::updateWindowsList() } QAction *action = windowMenu->addAction(action_text); action->setCheckable(true); - action->setChecked((*it) == _ui.mdiArea->activeSubWindow()); - connect(action, SIGNAL(triggered()), windowMapper, SLOT(map())); - windowMapper->setMapping(action, windows.at(i)); - i++; + action->setChecked(subWindows.at(i) == current_window); + connect(action, SIGNAL(triggered()), windowMapper, SLOT(map())); + windowMapper->setMapping(action, subWindows.at(i)); } } void CMainWindow::open() { QString file_name = QFileDialog::getOpenFileName(this); - if (!file_name.isEmpty()) - { - STRING_MANAGER::TWorksheet wk_file; - if(loadExcelSheet(file_name.toStdString(), wk_file, true) == true) - { - bool hasHashValue = false; - QTableWidget *wk_table = new QTableWidget(); - wk_table->setToolTip(file_name); - wk_table->setWindowFilePath(file_name); - if(wk_file.getData(0, 0) == ucstring("*HASH_VALUE")) - { - wk_table->setColumnCount(wk_file.ColCount - 1); - hasHashValue = true; - } else { - wk_table->setColumnCount(wk_file.ColCount); - } - wk_table->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(tr(col_name.toString().c_str())); - if(hasHashValue) - { - wk_table->setHorizontalHeaderItem(i - 1, col); - } else { - wk_table->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(tr(row_value.toString().c_str())); - if(hasHashValue) - { - wk_table->setItem(i - 1, j - 1, row); - } else { - wk_table->setItem(i - 1, j, row); - } - } + if(!file_name.isEmpty()) + { + list subWindows = convertSubWindowList(_ui.mdiArea->subWindowList()); + list::iterator it = subWindows.begin(); + CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + for(; it != subWindows.end(); ++it) + { + QString sw_file = (*it)->subWindowFilePath(); + if(file_name == sw_file) + { + if((*it) != current_window) + { + (*it)->activateWindow(); } + return; } - - QMdiSubWindow *sub_window = new QMdiSubWindow(_ui.mdiArea); - sub_window->setWidget(wk_table); - wk_table->resizeColumnsToContents(); - wk_table->resizeRowsToContents(); - wk_table->showMaximized(); - sub_window->activateWindow(); - // set editor signals - connect(wk_table, SIGNAL(cellChanged(int,int) ), this, SLOT(sheetEditorChanged(int,int))); - updateWindowsList(); - } else { - QErrorMessage error_settings; - error_settings.showMessage("This file is not a worksheet file."); - error_settings.exec(); + } + if(isWorksheetEditor(file_name)) + { + CEditorWorksheet *new_window = new CEditorWorksheet(_ui.mdiArea); + new_window->open(file_name); + new_window->activateWindow(); } } } -void CMainWindow::sheetEditorChanged(int row, int column) -{ - saveAct->setEnabled(true); - QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow(); - if(modifiedCells.find(current_window) != modifiedCells.end()) // founded - { - list cells = modifiedCells[current_window]; - bool overwriteResult = false; - for(list::iterator it = cells.begin(); it != cells.end(); ++it) - { - if((*it).row == row && (*it).col == column ) - overwriteResult = true; - } - if(overwriteResult == false) - { - CCelPos v; - v.row = row; - v.col = column; - cells.push_back(v); - } - } else { // not found - list cells; - CCelPos v; - v.row = row; - v.col = column; - cells.push_back(v); - modifiedCells[current_window] = cells; - } -} - void CMainWindow::save() { - QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow(); + CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor { - QWidget *subwindow_widget = current_window->widget(); - QTableWidget *table_editor = qobject_cast(subwindow_widget); - QString file_path = table_editor->windowFilePath(); - - if(modifiedCells.find(current_window) != modifiedCells.end()) - { - STRING_MANAGER::TWorksheet wk_file; - loadExcelSheet(file_path.toStdString(), wk_file, true); - list cells = modifiedCells[current_window]; - for(list::iterator it = cells.begin(); it != cells.end(); ++it) - { - QTableWidgetItem* edited_item = table_editor->item((*it).row, (*it).col); - wk_file.setData((*it).row + 1, (*it).col, ucstring(edited_item->text().toStdString())); - cells.erase(it); - } - ucstring s = prepareExcelSheet(wk_file); - NLMISC::CI18N::writeTextFile(file_path.toStdString(), s, false); - if(cells.size() == 0) - modifiedCells.erase(current_window); - } + current_window->save(); } } @@ -280,37 +214,10 @@ void CMainWindow::saveAs() if (!file_name.isEmpty()) { - QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow(); - + CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor { - QWidget *subwindow_widget = current_window->widget(); - QTableWidget *table_editor = qobject_cast(subwindow_widget); - QString orig_file_path = table_editor->windowFilePath(); - STRING_MANAGER::TWorksheet new_file, wk_file; - loadExcelSheet(orig_file_path.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; - for(int i = 0; i < table_editor->rowCount(); i++) - { - rowIdx = new_file.size(); - new_file.resize(new_file.size() + 1); - for(int j = 0; j < table_editor->columnCount(); j++) - { - QTableWidgetItem* item = table_editor->item(i, j); - new_file.setData(rowIdx, j, ucstring(item->text().toStdString())); - } - } - ucstring s = prepareExcelSheet(new_file); - NLMISC::CI18N::writeTextFile(file_name.toStdString(), s, false); + current_window->saveAs(file_name); } } @@ -320,72 +227,43 @@ void CMainWindow::extractBotNames() { if(verifySettings() == true) { - QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow(); - if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + CEditor* editor_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + if(QString(editor_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor { + CEditorWorksheet* current_window = qobject_cast(editor_window); + QString file_path = current_window->subWindowFilePath(); + if(!current_window->isBotNamesTable()) + { + list subWindows = convertSubWindowList(_ui.mdiArea->subWindowList()); + list::iterator it = subWindows.begin(); + bool finded = false; + for(; it != subWindows.end(), finded != true; ++it) + { + current_window = qobject_cast((*it)); + file_path = current_window->subWindowFilePath(); + if(current_window->isBotNamesTable()) + { + finded = true; + current_window->activateWindow(); + } + } + if(!finded) + { + open(); + current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + file_path = current_window->windowFilePath(); + } + } if(execution_count["extract_bot_names"] == 0) setPathsForPrimitives(config_paths, ligo_path); extractBotNamesFromPrimitives(); execution_count["extract_bot_names"] = execution_count["extract_bot_names"] + 1; - - QWidget *subwindow_widget = current_window->widget(); - QTableWidget *table_editor = qobject_cast(subwindow_widget); - // get SimpleNames - { - map SimpleNames = getSimpleNames(); - map::iterator it(SimpleNames.begin()), last(SimpleNames.end()); - - for (; it != last; ++it) - { - QList search_results = table_editor->findItems(tr(it->first.c_str()), Qt::MatchExactly); - if(search_results.size() == 0) - { - const int currentRow = table_editor->rowCount(); - table_editor->setRowCount(currentRow + 1); - QTableWidgetItem *bot_name_row = new QTableWidgetItem(); - bot_name_row->setText(tr(it->first.c_str())); - bot_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 0, bot_name_row); - QTableWidgetItem *translation_name_row = new QTableWidgetItem(); - translation_name_row->setBackgroundColor(QColor("#F75D59")); - translation_name_row->setText(tr(it->first.c_str())); - table_editor ->setItem(currentRow , 1, translation_name_row); - QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); - sheet_name_row->setText(tr(it->second.SheetName.c_str())); - sheet_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 2, sheet_name_row); - } - } - cleanSimpleNames(); - } - // get GenericNames - { - set GenericNames = getGenericNames(); - set::iterator it(GenericNames.begin()), last(GenericNames.end()); - for (; it != last; ++it) - { - string gnName = "gn_" + cleanupName(*it); - QList search_results = table_editor->findItems(tr((*it).c_str()), Qt::MatchExactly); - if(search_results.size() == 0) - { - const int currentRow = table_editor->rowCount(); - table_editor->setRowCount(currentRow + 1); - QTableWidgetItem *bot_name_row = new QTableWidgetItem(); - bot_name_row->setText(tr((*it).c_str())); - bot_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 0, bot_name_row); - QTableWidgetItem *translation_name_row = new QTableWidgetItem(); - translation_name_row->setBackgroundColor(QColor("#F75D59")); - translation_name_row->setText(tr(gnName.c_str())); - table_editor ->setItem(currentRow , 1, translation_name_row); - QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); - sheet_name_row->setText(" "); - sheet_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 2, sheet_name_row); - } - } - cleanGenericNames(); - } + + current_window->extractBotNames(); + // if(current_window->isWindowModified()) + // { + + // } } } @@ -413,6 +291,13 @@ void CMainWindow::readSettings() settings->endGroup(); } +void CMainWindow::debug(QString text) +{ + QErrorMessage error_settings; + error_settings.showMessage(text); + error_settings.exec(); +} + bool CMainWindow::verifySettings() { bool count_errors = false; @@ -436,14 +321,7 @@ bool CMainWindow::verifySettings() return !count_errors; } - - void CMainWindow::setActiveSubWindow(QWidget *window) - { - if (!window) - return; - _ui.mdiArea->setActiveSubWindow(qobject_cast(window)); - } - + list CMainWindow::convertQStringList(QStringList listq) { std::list stdlist; @@ -456,9 +334,36 @@ list CMainWindow::convertQStringList(QStringList listq) return stdlist; } +list CMainWindow::convertSubWindowList(QList listq) +{ + list subwindows; + QList::iterator it = listq.begin(); + + for(; it != listq.end(); ++it) + { + CEditor* current_window = qobject_cast((*it)); + subwindows.push_back(current_window); + } + + return subwindows; +} + +bool CMainWindow::isWorksheetEditor(QString filename) +{ + STRING_MANAGER::TWorksheet wk_file; + if(loadExcelSheet(filename.toStdString(), wk_file, true) == true) + { + return true; + } else { + return false; + } +} + bool CCoreListener::closeMainWindow() const { return true; } -} /* namespace Plugin */ \ No newline at end of file +} /* namespace Plugin */ + + 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 index 4df21fa0b..13a3ead97 100644 --- 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 @@ -33,29 +33,31 @@ #include #include #include -#include +#include #include #include #include - +#include "translation_manager_editor.h" #include "ui_translation_manager_main_window.h" #include class QWidget; + using namespace std; namespace Plugin { - -struct CCelPos -{ - int col; - int row; -}; +class CMdiSubWindow; + +struct WStatus +{ + bool modified; +}; + class CMainWindow : public QMainWindow { Q_OBJECT @@ -64,9 +66,8 @@ public: virtual ~CMainWindow() {} QUndoStack *m_undoStack; private: - Ui::CMainWindow _ui; - - map > modifiedCells; + + Ui::CMainWindow _ui; // actions QAction *openAct; QAction *saveAct; @@ -86,17 +87,22 @@ private Q_SLOTS: void open(); void save(); void saveAs(); - void sheetEditorChanged(int, int); - void setActiveSubWindow(QWidget *window); void activeSubWindowChanged(); + void setActiveSubWindow(QWidget *window); + void updateWindowsList(); + + void debug(QString text); // TODO private: - void compareBotNames(); + void updateToolbar(QMdiSubWindow *window); bool verifySettings(); void readSettings(); void createMenus(); void createToolbar(); - void updateWindowsList(); + list convertQStringList(QStringList listq); + list convertSubWindowList(QList listq); + bool isWorksheetEditor(QString filename); + }; @@ -111,21 +117,9 @@ public: virtual bool closeMainWindow() const; }; -class CMdiSubWindow : public QMdiSubWindow -{ - private: - int window_type; - public: - int getWType() - { - return window_type; - } - void setWType(int nType) - { - window_type = nType; - } -}; } // namespace Plugin + + #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 index 395574415..71c139e0a 100644 --- 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 @@ -16,27 +16,11 @@ - - - - 0 - 0 - - - - Qt::Horizontal - - - - true - - - - - - - - + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp index 91e7686d5..890c589e9 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp @@ -92,7 +92,7 @@ QStringList TranslationManagerPlugin::dependencies() const { QStringList list; list.append(Core::Constants::OVQT_CORE_PLUGIN); - list.append("ObjectViewer"); + //list.append("ObjectViewer"); return list; } From a4f222c6511c8aff6ed0172126e86e9108ef37f8 Mon Sep 17 00:00:00 2001 From: cemycc Date: Tue, 5 Jul 2011 05:01:13 +0300 Subject: [PATCH 12/34] Changed: #1307 Added extraction words options for: item, creature, sbrick, sphrase --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/CMakeLists.txt | 4 +- .../translation_manager/editor_worksheet.cpp | 108 +++- .../translation_manager/editor_worksheet.h | 21 +- .../translation_manager/extract_bot_names.cpp | 467 +-------------- .../translation_manager/extract_bot_names.h | 111 ++++ .../extract_new_sheet_names.cpp | 154 +++++ .../extract_new_sheet_names.h | 70 +++ .../translation_manager_editor.h | 16 + .../translation_manager_main_window.cpp | 190 +++++-- .../translation_manager_main_window.h | 24 +- .../translation_manager_plugin.cpp | 17 + .../translation_manager_plugin.h | 17 + .../translation_manager_settings_page.cpp | 120 +--- .../translation_manager_settings_page.h | 11 +- .../translation_manager_settings_page.ui | 533 ++++++------------ 15 files changed, 835 insertions(+), 1028 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_bot_names.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt index edc0a60e5..56195d6e0 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt @@ -13,7 +13,9 @@ SET(OVQT_PLUG_TRANSLATION_MANAGER_HDR translation_manager_plugin.h translation_manager_main_window.h translation_manager_settings_page.h translation_manager_editor.h - editor_worksheet.h) + editor_worksheet.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) 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 index ee32e3979..d19d28723 100644 --- 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 @@ -1,6 +1,6 @@ -// Object Viewer Qt - MMORPG Framework +// Translation Manager Plugin - OVQT Plugin // Copyright (C) 2010 Winch Gate Property Limited -// Copyright (C) 2011 Dzmitry Kamiahin +// 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 @@ -24,22 +24,10 @@ #include #include +#include "extract_bot_names.h" + using namespace std; -struct TEntryInfo -{ - string SheetName; -}; - -set getGenericNames(); -void cleanGenericNames(); -map getSimpleNames(); -void cleanSimpleNames(); -void setPathsForPrimitives(map > config_paths, string ligo_class_file); -void extractBotNamesFromPrimitives(); -string cleanupName(const std::string &name); -ucstring cleanupUcName(const ucstring &name); - namespace Plugin { @@ -251,12 +239,15 @@ void CEditorWorksheet::worksheetEditorChanged(int row, int column) } -void CEditorWorksheet::extractBotNames() +void CEditorWorksheet::extractBotNames(list filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig) { bool modified = false; -// get SimpleNames + ExtractBotNames ebn; + ebn.setRequiredSettings(filters, level_design_path); + ebn.extractBotNamesFromPrimitives(ligoConfig); + // get SimpleNames { - map SimpleNames = getSimpleNames(); + map SimpleNames = ebn.getSimpleNames(); map::iterator it(SimpleNames.begin()), last(SimpleNames.end()); for (; it != last; ++it) @@ -281,15 +272,15 @@ void CEditorWorksheet::extractBotNames() if(!modified) modified = true; } } - cleanSimpleNames(); + ebn.cleanSimpleNames(); } // get GenericNames { - set GenericNames = getGenericNames(); + set GenericNames = ebn.getGenericNames(); set::iterator it(GenericNames.begin()), last(GenericNames.end()); for (; it != last; ++it) { - string gnName = "gn_" + cleanupName(*it); + string gnName = "gn_" + ebn.cleanupName(*it); QList search_results = table_editor->findItems(tr((*it).c_str()), Qt::MatchExactly); if(search_results.size() == 0) { @@ -310,7 +301,7 @@ void CEditorWorksheet::extractBotNames() if(!modified) modified = true; } } - cleanGenericNames(); + ebn.cleanGenericNames(); } if(modified) { @@ -319,6 +310,77 @@ void CEditorWorksheet::extractBotNames() } +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; + for(i = 0; i < allWords.size(); i++) + { + string keyName = allWords[i]; + QList search_results = table_editor->findItems(tr(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; + } + const int currentRow = table_editor->rowCount(); + table_editor->setRowCount(currentRow + 1); + // keyName row + QTableWidgetItem *key_name_row = new QTableWidgetItem(); + key_name_row->setText(tr(keyName.c_str())); + key_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, knPos, key_name_row); + // nameColumn key + QTableWidgetItem *name_row = new QTableWidgetItem(); + name_row->setText(QString("") + tr(keyName.c_str())); + name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, nPos, name_row); + if(!modified) modified = true; + } + } + if(modified) + { + setWindowModified(true); + } +} + void CEditorWorksheet::setCurrentFile(QString filename) { QFileInfo *file = new QFileInfo(filename); 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 index 71e86af84..497e23913 100644 --- 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 @@ -1,3 +1,19 @@ +// 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 @@ -7,6 +23,7 @@ #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 @@ -16,6 +33,7 @@ #include #include "translation_manager_editor.h" +#include "extract_new_sheet_names.h" namespace Plugin { @@ -31,7 +49,8 @@ public: void save(); void saveAs(QString filename); void activateWindow(); - void extractBotNames(); + void extractBotNames(list filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig); + void extractWords(QString filename, QString columnId, IWordListBuilder &wordListBuilder); bool isBotNamesTable(); void closeEvent(QCloseEvent *event); private Q_SLOTS: 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 index 66d7d1c69..4de3d889d 100644 --- 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 @@ -1,5 +1,6 @@ -// Ryzom - MMORPG Framework +// 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 @@ -14,67 +15,18 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -#include "nel/misc/types_nl.h" -#include "nel/misc/config_file.h" -#include "nel/misc/sheet_id.h" -#include "nel/misc/path.h" -#include "nel/misc/diff_tool.h" -#include "nel/georges/u_form.h" -#include "nel/georges/u_form_elm.h" -#include "nel/georges/load_form.h" -#include "nel/ligo/ligo_config.h" -#include "nel/ligo/primitive.h" -#include "nel/ligo/primitive_utils.h" +#include "extract_bot_names.h" -using namespace std; -using namespace NLMISC; -using namespace NLLIGO; -using namespace STRING_MANAGER; -vector Filters; - -static CLigoConfig LigoConfig; static bool RemoveOlds = false; -struct TCreatureInfo + + +namespace Plugin { - CSheetId SheetId; - bool ForceSheetName; - bool DisplayName; - - void readGeorges (const NLMISC::CSmartPtr &form, const NLMISC::CSheetId &sheetId) - { - const NLGEORGES::UFormElm &item=form->getRootNode(); - - SheetId=sheetId; - item.getValueByName(ForceSheetName, "3d data.ForceDisplayCreatureName"); - item.getValueByName(DisplayName, "3d data.DisplayName"); - } - - void serial(NLMISC::IStream &f) - { - f.serial(SheetId); - f.serial(ForceSheetName); - f.serial(DisplayName); - } - - - static uint getVersion () - { - return 1; - } - - void removed() - { - } - -}; - -std::map Creatures; - -TCreatureInfo *getCreature(const std::string &sheetName) +TCreatureInfo *ExtractBotNames::getCreature(const std::string &sheetName) { CSheetId id(sheetName+".creature"); @@ -84,7 +36,7 @@ TCreatureInfo *getCreature(const std::string &sheetName) return NULL; } -string cleanupName(const std::string &name) +string ExtractBotNames::cleanupName(const std::string &name) { string ret; @@ -99,7 +51,7 @@ string cleanupName(const std::string &name) return ret; } -ucstring cleanupUcName(const ucstring &name) +ucstring ExtractBotNames::cleanupUcName(const ucstring &name) { ucstring ret; @@ -118,7 +70,7 @@ ucstring cleanupUcName(const ucstring &name) /* Removes first and last '$' */ -ucstring makeGroupName(const ucstring & translationName) +ucstring ExtractBotNames::makeGroupName(const ucstring & translationName) { ucstring ret = translationName; if (ret.size() >= 2) @@ -136,36 +88,31 @@ ucstring makeGroupName(const ucstring & translationName) return ret; } -struct TEntryInfo -{ - string SheetName; -}; -set GenericNames; -map SimpleNames; -set Functions; -set getGenericNames() + + +set ExtractBotNames::getGenericNames() { return GenericNames; } -map getSimpleNames() +map ExtractBotNames::getSimpleNames() { return SimpleNames; } -void cleanSimpleNames() +void ExtractBotNames::cleanSimpleNames() { SimpleNames.clear(); } -void cleanGenericNames() +void ExtractBotNames::cleanGenericNames() { GenericNames.clear(); } -string removeAndStoreFunction(const std::string &fullName) +string ExtractBotNames::removeAndStoreFunction(const std::string &fullName) { string::size_type pos = fullName.find("$"); if (pos == string::npos) @@ -193,7 +140,7 @@ string removeAndStoreFunction(const std::string &fullName) } -void addGenericName(const std::string &name, const std::string &sheetName) +void ExtractBotNames::addGenericName(const std::string &name, const std::string &sheetName) { TCreatureInfo *c = getCreature(sheetName); if (!c || c->ForceSheetName || !c->DisplayName) @@ -213,7 +160,7 @@ void addGenericName(const std::string &name, const std::string &sheetName) } } -void addSimpleName(const std::string &name, const std::string &sheetName) +void ExtractBotNames::addSimpleName(const std::string &name, const std::string &sheetName) { TCreatureInfo *c = getCreature(sheetName); if (!c || c->ForceSheetName || !c->DisplayName) @@ -238,18 +185,9 @@ void addSimpleName(const std::string &name, const std::string &sheetName) } } -void setPathsForPrimitives(map > config_paths, string ligo_class_file) +void ExtractBotNames::setRequiredSettings(list filters, string level_design_path) { - for (std::list::iterator it = config_paths["paths"].begin(); it != config_paths["paths"].end(); ++it) - { - CPath::addSearchPath(*it, true, false); - } - for (std::list::iterator it = config_paths["pathsR"].begin(); it != config_paths["pathsR"].end(); ++it) - { - CPath::addSearchPath(*it, false, false); - } - - for (std::list::iterator it = config_paths["filters"].begin(); it != config_paths["filters"].end(); ++it) + for (std::list::iterator it = filters.begin(); it != filters.end(); ++it) { Filters.push_back(*it); } @@ -262,35 +200,28 @@ void setPathsForPrimitives(map > config_paths, string ligo_c if (Creatures.empty()) { - for (std::list::iterator it = config_paths["georges"].begin(); it != config_paths["georges"].end(); ++it) - CPath::addSearchPath((*it).c_str(), true, false); - - loadForm("creature", PACKED_SHEETS_NAME, Creatures, true); + loadForm("creature", PACKED_SHEETS_NAME, Creatures, true); } - - - //------------------------------------------------------------------- - // init ligo config - string ligoPath = CPath::lookup(ligo_class_file, true, true); - LigoConfig.readPrimitiveClass(ligoPath.c_str(), false); - NLLIGO::Register(); - - CPrimitiveContext::instance().CurrentLigoConfig = &LigoConfig; + } -void extractBotNamesFromPrimitives() +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 > config_paths, string ligo_class_file, string trans_path, string work_path) -{ - - /* - //------------------------------------------------------------------- - // step 2 : load the reference file - - nlinfo("Looking for missing translation:"); - - string work_path_file = work_path + "/bot_names.txt"; - string trans_path_file = trans_path + "/bot_names.txt"; - string title_path_file = work_path + "/title_words_wk.txt"; - - TWorksheet botNames; - if (!CFile::fileExists(work_path_file) || !loadExcelSheet(work_path_file, botNames)) - { - botNames.resize(botNames.size() + 1); - botNames.insertColumn(botNames.ColCount); - botNames.setData(0,botNames.ColCount - 1,ucstring("bot name")); - botNames.insertColumn(botNames.ColCount); - botNames.setData(0,botNames.ColCount - 1,ucstring("translated name")); - botNames.insertColumn(botNames.ColCount); - botNames.setData(0,botNames.ColCount - 1,ucstring("sheet_name")); - } - - TWorksheet transBotNames; - if (!CFile::fileExists(trans_path_file) || !loadExcelSheet(trans_path_file, transBotNames)) - { - transBotNames.resize(transBotNames.size() + 1); - transBotNames.insertColumn(transBotNames.ColCount); - transBotNames.setData(0,transBotNames.ColCount - 1,ucstring("*HASH_VALUE")); - transBotNames.insertColumn(transBotNames.ColCount); - transBotNames.setData(0,transBotNames.ColCount - 1,ucstring("bot name")); - transBotNames.insertColumn(transBotNames.ColCount); - transBotNames.setData(0,transBotNames.ColCount - 1,ucstring("translated name")); - transBotNames.insertColumn(transBotNames.ColCount); - transBotNames.setData(0,transBotNames.ColCount - 1,ucstring("sheet_name")); - } - - TWorksheet fcts; - if (!CFile::fileExists(title_path_file) || !loadExcelSheet(title_path_file, fcts)) - { - fcts.resize(fcts.size() + 1); - fcts.insertColumn(fcts.ColCount); - fcts.setData(0,fcts.ColCount - 1,ucstring("title_id")); - fcts.insertColumn(fcts.ColCount); - fcts.setData(0,fcts.ColCount - 1,ucstring("name")); - fcts.insertColumn(fcts.ColCount); - fcts.setData(0,fcts.ColCount - 1,ucstring("women_name")); - } - - loadExcelSheet(work_path_file, botNames, true); - loadExcelSheet(trans_path_file, transBotNames, true); - loadExcelSheet(title_path_file, fcts, true); - - // add missing element - - uint nbAddSimpleName = 0; - uint nbAddFunction = 0; - uint nbAddGenericName = 0; - - uint botIdCol; - nlverify(botNames.findId(botIdCol)); - uint transIdCol; - nlverify(transBotNames.findId(transIdCol)); - uint fctsIdCol; - nlverify(fcts.findId(fctsIdCol)); - - // special treatment to add the sheet_name col - { - uint sheetCol; - if (!botNames.findCol(ucstring("sheet_name"), sheetCol)) - { - botNames.insertColumn(botNames.ColCount); - botNames.setData(0, botNames.ColCount-1, ucstring("sheet_name")); - } - - if (!transBotNames.findCol(ucstring("sheet_name"), sheetCol)) - { - transBotNames.insertColumn(transBotNames.ColCount); - transBotNames.setData(0, transBotNames.ColCount-1, ucstring("sheet_name")); - } - } - // 1 - simple names - { - nlinfo(" Simple names..."); - - - map::iterator first(SimpleNames.begin()), last(SimpleNames.end()); - for (; first != last; ++first) - { - uint rowIdx; - if (!botNames.findRow(botIdCol, first->first, rowIdx)) - { - // we need to add the entry - rowIdx = botNames.size(); - botNames.resize(botNames.size()+1); - - botNames.setData(rowIdx, ucstring("bot name"), first->first); - botNames.setData(rowIdx, ucstring("translated name"), first->first); - botNames.setData(rowIdx, ucstring("sheet_name"), first->second.SheetName); - - nbAddSimpleName++; - } - else - { - // set/update the sheet name info - // try to restore the existing translation - uint transRowIdx; - if (transBotNames.findRow(transIdCol, first->first, transRowIdx)) - { - ucstring wkBotName = botNames.getData(rowIdx, ucstring("bot name")); - ucstring wkSheetName = botNames.getData(rowIdx, ucstring("sheet_name")); - ucstring wkTranslationName = botNames.getData(rowIdx, ucstring("translated name")); - ucstring ucWkHash; - uint64 hash = CI18N::makeHash(wkBotName + wkTranslationName +wkSheetName); - CI18N::hashToUCString(hash, ucWkHash); - ucstring trUcHash = transBotNames[transRowIdx][0]; - bool isWkTranslationNameAGroupName = wkTranslationName.find(ucstring("$")) != ucstring::npos; - bool hashIsValide = std::equal(ucWkHash.begin(), ucWkHash.end(), trUcHash.begin()+1); - // Hash is equal get the translation - if (hashIsValide && !isWkTranslationNameAGroupName) - { - wkTranslationName = transBotNames.getData(transRowIdx, ucstring("translated name")); - wkSheetName = transBotNames.getData(transRowIdx, ucstring("sheet_name")); - botNames.setData(rowIdx, ucstring("translated name"), wkTranslationName); - botNames.setData(rowIdx, ucstring("sheet_name"), wkSheetName); - hash = CI18N::makeHash(wkBotName + wkTranslationName + wkSheetName); - // update the hash code - CI18N::hashToUCString(hash, transBotNames[transRowIdx][0]); - } - // bots_name.txt has been manually changed. We trust what the Level Designer has done. We don't destroy is work. - // or it is a simple - else - { - //use the "translated name" of the manually changed work/bot_name.txt - botNames.setData(rowIdx, ucstring("translated name"), wkTranslationName); - botNames.setData(rowIdx, ucstring("sheet_name"), wkSheetName); - } - } - } - } - } - - // 2 - generic names - - { - nlinfo(" Generic names..."); - - set::iterator first(GenericNames.begin()), last(GenericNames.end()); - for (; first != last; ++first) - { - string gnName = "gn_" + cleanupName(*first); - - ucstring fctsTitleId; - ucstring fctsName; - // add or modify the bot names - uint rowIdx; - if (!botNames.findRow(botIdCol, *first, rowIdx)) - { - // we need to add the entry - rowIdx = botNames.size(); - botNames.resize(botNames.size()+1); - - botNames.setData(rowIdx, ucstring("bot name"), *first); - botNames.setData(rowIdx, ucstring("translated name"), ucstring("$") + gnName + "$"); - botNames.setData(rowIdx, ucstring("sheet_name"), ucstring()); - fctsTitleId = gnName; - fctsName = *first; - - nbAddSimpleName++; - } - else - { - // look in the translated table to remember the translated name to write it in the string file - ucstring wkBotName = botNames.getData(rowIdx, ucstring("bot name")); - ucstring wkTranslationName = botNames.getData(rowIdx, ucstring("translated name")); - ucstring wkSheetName = botNames.getData(rowIdx, ucstring("sheet_name")); - - - nlinfo("Bot name:%s\n",wkBotName.toString().c_str()); - bool isWkTranslationNameAGroupName = wkTranslationName.find(ucstring("$")) != ucstring::npos; - - if ( isWkTranslationNameAGroupName ) //work name looks like "$gn_***$: do not modify - { - - //Do not change work/bot_name.txt - // update work/world_title.txt - - ucstring transName; - fctsTitleId = makeGroupName(wkTranslationName); - uint transRowIdx; - if (transBotNames.findRow(transIdCol, *first, transRowIdx)) - { - transName = transBotNames.getData(transRowIdx, ucstring("translated name")); - - if (transName.find(ucstring("$")) != ucstring::npos) - { - transName = fctsTitleId; - } - } - else - { - transName = fctsTitleId; - } - //Do not touch anything - botNames.setData(rowIdx, ucstring("translated name"), wkTranslationName); - botNames.setData(rowIdx, ucstring("sheet_name"), wkSheetName); - // fctsTitleId = makeGroupName(wkTranslationName); - fctsName = transName; - - } - else // WkTranslationName != "$gn*$" - { - uint transRowIdx; - ucstring transName; - ucstring wkSheetName; - // Get the translation as a simple name. - if (transBotNames.findRow(transIdCol, *first, transRowIdx)) - { - - transName = transBotNames.getData(transRowIdx, ucstring("translated name")); - ucstring trSheetName = transBotNames.getData(transRowIdx, ucstring("sheet_name")); - - //tr."translation name" is - if (transName.find(ucstring("$")) != ucstring::npos) - { - //get Translation, update hash - botNames[rowIdx][1] = transName; - botNames[rowIdx][2] = trSheetName; - fctsTitleId = makeGroupName(transName); - fctsName = makeGroupName(transName); - ucstring trNewUcHash; - uint64 hash = CI18N::makeHash(wkBotName + transName +trSheetName); - CI18N::hashToUCString(hash, trNewUcHash); - transBotNames[transRowIdx][0] = ucstring("_") + trNewUcHash; - } - else //botNames."translated name" != $gn_$ && tansName."translated name" != $gn_$ - { - - // get the translation back - //update work/bot_name.txt - wkTranslationName = ucstring("$")+gnName+"$"; - botNames[rowIdx][0] = wkBotName; - botNames[rowIdx][1] = wkTranslationName; - botNames[rowIdx][2] = wkSheetName; - - //update translated/bot_name.txt - - fctsName = transName; //transName - fctsTitleId = gnName; - ucstring trNewUcHash; - uint64 hash = CI18N::makeHash(botNames[rowIdx][0] + botNames[rowIdx][1] +botNames[rowIdx][2]); - CI18N::hashToUCString(hash, trNewUcHash); - transBotNames[transRowIdx][0] = ucstring("_") + trNewUcHash; - } - - } - else //There is no translation yet - { - fctsName = wkTranslationName; - wkTranslationName = ucstring("$")+gnName+"$"; - botNames[rowIdx][0] = wkBotName; - botNames[rowIdx][1] = wkTranslationName; - botNames[rowIdx][2] = wkSheetName; - fctsTitleId = gnName; - - - } - } - - } - - - // look for a corresponding entry - uint gnNameRow; - - - if (!fcts.findRow(fctsIdCol, fctsTitleId, gnNameRow)) - { - - // not found, add it - gnNameRow = fcts.size(); - fcts.resize(fcts.size()+1); - fcts.setData(gnNameRow, ucstring("title_id"), fctsTitleId); - fcts.setData(gnNameRow, ucstring("name"), fctsName); - nbAddGenericName++; - - } - else //Update - { - - } - } - } - - - // 3 - functions - { - nlinfo(" Functions..."); - - set::iterator first(Functions.begin()), last(Functions.end()); - for (; first != last; ++first) - { - string fctName = *first; - // look for a corresponding entry - uint functionRow; - if (!fcts.findRow(fctsIdCol, fctName, functionRow)) - { - // not found, add it - functionRow = fcts.size(); - fcts.resize(fcts.size()+1); - - fcts.setData(functionRow, ucstring("title_id"), fctName); - fcts.setData(functionRow, ucstring("name"), *first); - - nbAddFunction++; - } - } - } - - // display resum\E9 - nlinfo("Adding %u new simple name", nbAddSimpleName); - nlinfo("Adding %u new generic name", nbAddGenericName); - nlinfo("Adding %u new function name", nbAddFunction); - - // saving the modified files - ucstring s = prepareExcelSheet(botNames); - CI18N::writeTextFile(work_path_file, s, false); - s = prepareExcelSheet(transBotNames); - CI18N::writeTextFile(trans_path_file, s, false); - s = prepareExcelSheet(fcts); - CI18N::writeTextFile(title_path_file, s, false); -*/ - return 0; -} - + +} \ 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..9c4ea51d2 --- /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 Plugin +{ + +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..e881177bb --- /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 Plugin { + + + +// *************************************************************************** +/* + * Specialisation of IWordListBuilder to list sheets in a directory + */ + + +bool CSheetWordListBuilder::buildWordList(std::vector &allWords, string workSheetFileName) + { + SheetExt= toLower(SheetExt); + nlinfo("aaaa"); + // 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..007018a08 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.h @@ -0,0 +1,70 @@ +// 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 Plugin { + + +// *************************************************************************** +/* + * 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; + 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/translation_manager_editor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h index 605d11d6e..7af2b061d 100644 --- 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 @@ -1,3 +1,19 @@ +// 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 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 index 8b8c50a22..95a5fe95f 100644 --- 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 @@ -1,6 +1,6 @@ -// Object Viewer Qt - MMORPG Framework +// Translation Manager Plugin - OVQT Plugin // Copyright (C) 2010 Winch Gate Property Limited -// Copyright (C) 2011 Dzmitry Kamiahin +// 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 @@ -46,21 +46,6 @@ #include - -struct TEntryInfo -{ - string SheetName; -}; - -set getGenericNames(); -void cleanGenericNames(); -map getSimpleNames(); -void cleanSimpleNames(); -void setPathsForPrimitives(map > config_paths, string ligo_class_file); -void extractBotNamesFromPrimitives(); -string cleanupName(const std::string &name); -ucstring cleanupUcName(const ucstring &name); - namespace Plugin { @@ -74,9 +59,8 @@ CMainWindow::CMainWindow(QWidget *parent) windowMapper = new QSignalMapper(this); connect(windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*))); - // set extraction scripts counters - execution_count["extract_bot_names"] = 0; - + initialize_settings["georges"] = false; + initialize_settings["ligo"] = false; readSettings(); createToolbar(); m_undoStack = new QUndoStack(this); @@ -99,9 +83,33 @@ void CMainWindow::createToolbar() 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())); + // 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, "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, "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, "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, "sphrase"); // Windows menu windowMenu = new QMenu(tr("&Windows..."), _ui.toolBar); @@ -194,6 +202,29 @@ void CMainWindow::open() } +void CMainWindow::openWorkFile(QString file) +{ + QFileInfo* file_path = new QFileInfo(QString("%1/%2").arg(QString(work_path.c_str())).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; + QString text; + text.append("The "); + text.append(file_path->fileName()); + text.append(" file don't exists."); + error.showMessage(text); + error.exec(); + } + +} + void CMainWindow::save() { CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); @@ -223,49 +254,101 @@ void CMainWindow::saveAs() } } +void CMainWindow::initializeSettings(bool georges = false) +{ + if(georges == true && initialize_settings["georges"] == false) + { + CPath::addSearchPath(level_design_path + "/DFN", true, false); + CPath::addSearchPath(level_design_path + "/Game_elem/Creature", true, false); + initialize_settings["georges"] = true; + } + + if(initialize_settings["ligo"] == false) + { + //------------------------------------------------------------------- + // init ligo config + string ligoPath = CPath::lookup("world_editor_classes.xml", true, true); + ligoConfig.readPrimitiveClass(ligoPath.c_str(), false); + NLLIGO::Register(); + NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig = &ligoConfig; + initialize_settings["ligo"] = true; + } +} + +void CMainWindow::extractWords(QString type) +{ + CEditor* editor_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + CEditorWorksheet* current_window = qobject_cast(editor_window); + + // initializeSettings(false); + + CSheetWordListBuilder builder; + QString column_name; + + if(type == "item") + { + column_name = "item ID"; + builder.SheetExt = "sitem"; + builder.SheetPath = level_design_path + "/game_element/sitem"; + } else if(type == "creature") { + column_name = "creature ID"; + builder.SheetExt = "creature"; + builder.SheetPath = level_design_path + "/Game_elem/Creature/fauna"; + } else if(type == "sbrick") { + column_name = "sbrick ID"; + builder.SheetExt = "sbrick"; + builder.SheetPath = level_design_path + "/game_element/sbrick"; + } else if(type == "sphrase") { + column_name = "sphrase ID"; + builder.SheetExt = "sphrase"; + builder.SheetPath = level_design_path + "/game_element/sphrase"; + } + current_window->extractWords(current_window->windowFilePath(), column_name, builder); +} + void CMainWindow::extractBotNames() { if(verifySettings() == true) { + CEditorWorksheet* current_window; + if(_ui.mdiArea->subWindowList().size() > 0) + { CEditor* editor_window = qobject_cast(_ui.mdiArea->currentSubWindow()); if(QString(editor_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor { - CEditorWorksheet* current_window = qobject_cast(editor_window); + current_window = qobject_cast(editor_window); QString file_path = current_window->subWindowFilePath(); if(!current_window->isBotNamesTable()) { list subWindows = convertSubWindowList(_ui.mdiArea->subWindowList()); list::iterator it = subWindows.begin(); bool finded = false; - for(; it != subWindows.end(), finded != true; ++it) + + for(; it != subWindows.end(); ++it) { - current_window = qobject_cast((*it)); - file_path = current_window->subWindowFilePath(); - if(current_window->isBotNamesTable()) - { - finded = true; - current_window->activateWindow(); - } + current_window = qobject_cast((*it)); + file_path = current_window->subWindowFilePath(); + if(current_window->isBotNamesTable()) + { + finded = true; + current_window->activateWindow(); + } } if(!finded) { - open(); + openWorkFile("bot_names_wk.txt"); current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); file_path = current_window->windowFilePath(); } - } - if(execution_count["extract_bot_names"] == 0) - setPathsForPrimitives(config_paths, ligo_path); - extractBotNamesFromPrimitives(); - execution_count["extract_bot_names"] = execution_count["extract_bot_names"] + 1; - - current_window->extractBotNames(); - // if(current_window->isWindowModified()) - // { - - // } - + } } + } else { + openWorkFile("bot_names_wk.txt"); + current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + QString file_path = current_window->windowFilePath(); + } + initializeSettings(true); + current_window->extractBotNames(filters, level_design_path, ligoConfig); } } @@ -273,22 +356,14 @@ void CMainWindow::readSettings() { QSettings *settings = Core::ICore::instance()->settings(); settings->beginGroup("translationmanager"); - - list paths = convertQStringList(settings->value("paths").toStringList()); /* paths */ - config_paths["paths"] = paths; - list pathsR = convertQStringList(settings->value("pathsR").toStringList()); /* pathsR */ - config_paths["pathsR"] = pathsR; - list georges = convertQStringList(settings->value("georges").toStringList()); /* georges */ - config_paths["georges"] = georges; - list filters = convertQStringList(settings->value("filters").toStringList()); /* filters */ - config_paths["filters"] = filters; - + filters = convertQStringList(settings->value("filters").toStringList()); /* filters */ languages = convertQStringList(settings->value("trlanguages").toStringList()); /* languages */ - ligo_path = settings->value("ligo").toString().toStdString(); translation_path = settings->value("translation").toString().toStdString(); work_path = settings->value("work").toString().toStdString(); - - settings->endGroup(); + settings->endGroup(); + settings->beginGroup(Core::Constants::DATA_PATH_SECTION); + level_design_path = settings->value(Core::Constants::LEVELDESIGN_PATH).toString().toStdString(); + settings->endGroup(); } void CMainWindow::debug(QString text) @@ -305,10 +380,7 @@ bool CMainWindow::verifySettings() QSettings *settings = Core::ICore::instance()->settings(); settings->beginGroup("translationmanager"); - if(settings->value("paths").toList().count() == 0 - || settings->value("pathsR").toList().count() == 0 - || settings->value("georges").toList().count() == 0 - || settings->value("filters").toList().count() == 0) + if(settings->value("filters").toList().count() == 0) { QErrorMessage error_settings; error_settings.showMessage("Please write all the paths on the settings dialog."); 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 index 13a3ead97..b0d59fe29 100644 --- 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 @@ -1,6 +1,6 @@ -// Object Viewer Qt - MMORPG Framework +// Translation Manager Plugin - OVQT Plugin // Copyright (C) 2010 Winch Gate Property Limited -// Copyright (C) 2011 Dzmitry Kamiahin +// 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 @@ -27,6 +27,7 @@ #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 @@ -51,13 +52,6 @@ using namespace std; namespace Plugin { -class CMdiSubWindow; - -struct WStatus -{ - bool modified; -}; - class CMainWindow : public QMainWindow { Q_OBJECT @@ -75,15 +69,16 @@ private: QMenu *windowMenu; QSignalMapper *windowMapper; // config - map > config_paths; + map initialize_settings; + list filters; list languages; - string ligo_path; + string level_design_path; string translation_path; string work_path; - // counts - map execution_count; + NLLIGO::CLigoConfig ligoConfig; private Q_SLOTS: void extractBotNames(); + void extractWords(QString); void open(); void save(); void saveAs(); @@ -93,12 +88,13 @@ private Q_SLOTS: void debug(QString text); // TODO 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); list convertSubWindowList(QList listq); bool isWorksheetEditor(QString filename); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp index 890c589e9..caf677a0d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp @@ -1,3 +1,20 @@ +// 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" diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h index 42515cb2f..ed42b4882 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h @@ -1,3 +1,20 @@ +// 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 diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp index 078a9c18c..4870da41b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp @@ -1,6 +1,6 @@ -// Object Viewer Qt - MMORPG Framework +// Translation Manager Plugin - OVQT Plugin // Copyright (C) 2010 Winch Gate Property Limited -// Copyright (C) 2011 Dzmitry Kamiahin +// 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 @@ -69,12 +69,6 @@ QWidget *CTranslationManagerSettingsPage::createPage(QWidget *parent) _currentPage = new QWidget(parent); _ui.setupUi(_currentPage); readSettings(); - connect(_ui.paths_add, SIGNAL(clicked()), this, SLOT(pathAdd())); - connect(_ui.paths_del, SIGNAL(clicked()), this, SLOT(pathDel())); - connect(_ui.pathsR_add, SIGNAL(clicked()), this, SLOT(pathRAdd())); - connect(_ui.pathsR_del, SIGNAL(clicked()), this, SLOT(pathRDel())); - connect(_ui.georges_add, SIGNAL(clicked()), this, SLOT(georgeAdd())); - connect(_ui.georges_del, SIGNAL(clicked()), this, SLOT(georgeDel())); connect(_ui.filter_add, SIGNAL(clicked()), this, SLOT(filterAdd())); connect(_ui.filter_del, SIGNAL(clicked()), this, SLOT(filterDel())); connect(_ui.lang_add, SIGNAL(clicked()), this, SLOT(languageAdd())); @@ -85,66 +79,6 @@ QWidget *CTranslationManagerSettingsPage::createPage(QWidget *parent) return _currentPage; } -void CTranslationManagerSettingsPage::pathAdd() -{ - QString newPath = QFileDialog::getExistingDirectory(_currentPage, "", lastDir); - if (!newPath.isEmpty()) - { - QListWidgetItem *newItem = new QListWidgetItem; - newItem->setText(newPath); - newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - _ui.paths_list->addItem(newItem); - lastDir = newPath; - } -} - -void CTranslationManagerSettingsPage::pathDel() -{ - QListWidgetItem *removeItem = _ui.paths_list->takeItem(_ui.paths_list->currentRow()); - if (!removeItem) - delete removeItem; -} - -void CTranslationManagerSettingsPage::pathRAdd() -{ - QString newPath = QFileDialog::getExistingDirectory(_currentPage, "", lastDir); - if (!newPath.isEmpty()) - { - QListWidgetItem *newItem = new QListWidgetItem; - newItem->setText(newPath); - newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - _ui.pathsR_list->addItem(newItem); - lastDir = newPath; - } -} - -void CTranslationManagerSettingsPage::pathRDel() -{ - QListWidgetItem *removeItem = _ui.pathsR_list->takeItem(_ui.pathsR_list->currentRow()); - if (!removeItem) - delete removeItem; -} - -void CTranslationManagerSettingsPage::georgeAdd() -{ - QString newPath = QFileDialog::getExistingDirectory(_currentPage, "", lastDir); - if (!newPath.isEmpty()) - { - QListWidgetItem *newItem = new QListWidgetItem; - newItem->setText(newPath); - newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - _ui.georges_list->addItem(newItem); - lastDir = newPath; - } -} - -void CTranslationManagerSettingsPage::georgeDel() -{ - QListWidgetItem *removeItem = _ui.georges_list->takeItem(_ui.georges_list->currentRow()); - if (!removeItem) - delete removeItem; -} - void CTranslationManagerSettingsPage::filterAdd() { QString newValue = _ui.filter_edit->text(); @@ -208,15 +142,12 @@ void CTranslationManagerSettingsPage::apply() void CTranslationManagerSettingsPage::readSettings() { - QStringList paths, pathsR, georges, filters, languages; + QStringList filters, languages; QString ligo, translation, work; QSettings *settings = Core::ICore::instance()->settings(); settings->beginGroup("translationmanager"); - paths = settings->value("paths").toStringList(); /* paths */ - pathsR = settings->value("pathsR").toStringList(); /* pathsR */ - georges = settings->value("georges").toStringList(); /* georges */ filters = settings->value("filters").toStringList(); /* filters */ languages = settings->value("trlanguages").toStringList(); /* languages */ ligo = settings->value("ligo").toString(); @@ -224,30 +155,6 @@ void CTranslationManagerSettingsPage::readSettings() work = settings->value("work").toString(); settings->endGroup(); - // paths - Q_FOREACH(QString path, paths) - { - QListWidgetItem *newItem = new QListWidgetItem; - newItem->setText(path); - newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - _ui.paths_list->addItem(newItem); - } - // pathsR - Q_FOREACH(QString pathR, pathsR) - { - QListWidgetItem *newItem = new QListWidgetItem; - newItem->setText(pathR); - newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - _ui.pathsR_list->addItem(newItem); - } - // georges - Q_FOREACH(QString george, georges) - { - QListWidgetItem *newItem = new QListWidgetItem; - newItem->setText(george); - newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - _ui.georges_list->addItem(newItem); - } // filter Q_FOREACH(QString filter, filters) { @@ -264,8 +171,6 @@ void CTranslationManagerSettingsPage::readSettings() newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); _ui.lang_list->addItem(newItem); } - // ligo - _ui.ligo_edit->setText(ligo); // translation _ui.translation_edit->setText(translation); // work @@ -275,25 +180,14 @@ void CTranslationManagerSettingsPage::readSettings() void CTranslationManagerSettingsPage::writeSettings() { - QStringList paths, pathsR, georges, filters, languages; + QStringList filters, languages; QString ligo, translation, work; - // paths - for (int i = 0; i < _ui.paths_list->count(); ++i) - paths << _ui.paths_list->item(i)->text(); - // pathsR - for (int i = 0; i < _ui.pathsR_list->count(); ++i) - pathsR << _ui.pathsR_list->item(i)->text(); - // georges - for (int i = 0; i < _ui.georges_list->count(); ++i) - georges << _ui.georges_list->item(i)->text(); // filters for (int i = 0; i < _ui.filter_list->count(); ++i) filters << _ui.filter_list->item(i)->text(); // languages for (int i = 0; i < _ui.lang_list->count(); ++i) languages << _ui.lang_list->item(i)->text(); - // ligo path - ligo = _ui.ligo_edit->text(); // translations path translation = _ui.translation_edit->text(); // work path @@ -301,12 +195,8 @@ void CTranslationManagerSettingsPage::writeSettings() QSettings *settings = Core::ICore::instance()->settings(); settings->beginGroup("translationmanager"); - settings->setValue("paths", paths); - settings->setValue("pathsR", pathsR); - settings->setValue("georges", georges); settings->setValue("filters", filters); - settings->setValue("trlanguages", languages); - settings->setValue("ligo", ligo); + settings->setValue("trlanguages", languages); settings->setValue("translation", translation); settings->setValue("work", work); settings->endGroup(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h index 7a082f199..1cf19787a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h @@ -1,6 +1,6 @@ -// Object Viewer Qt - MMORPG Framework +// Translation Manager Plugin - OVQT Plugin // Copyright (C) 2010 Winch Gate Property Limited -// Copyright (C) 2011 Dzmitry Kamiahin +// 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 @@ -15,7 +15,6 @@ // 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 @@ -49,12 +48,6 @@ public: virtual void apply(); virtual void finish() {} private Q_SLOTS: - void pathAdd(); - void pathDel(); - void pathRAdd(); - void pathRDel(); - void georgeAdd(); - void georgeDel(); void filterAdd(); void filterDel(); void languageAdd(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui index 4c932b4f5..aaa4337f4 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.ui @@ -6,388 +6,181 @@ 0 0 - 490 - 496 + 533 + 478 Form - - - - - 1 - - - - Core paths - - - - - - - - - - Paths - - - - - - - Qt::Horizontal - - - - 318 - 20 - - - - - - - - dwadwadwa - - - - :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png - - - Qt::ToolButtonIconOnly - - - true - - - - - - - ... - - - - :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png - - - true - - - - - - - - - - - - - - - - - - Paths non recursives - - - - - - - Qt::Horizontal - - - - 218 - 20 - - - - - - - - - - - - :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png - - - true - - - - - - - ... - - - - :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png - - - true - - - - - - - - - - - - - - - - - - Georges Paths - - - - - - - Qt::Horizontal - - - - 258 - 20 - - - - - - - - - - - - :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png - - - true - - - - - - - - - - - :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png - - - true - - - - - - - - - - - - - - - Translation files paths - - - - - 9 - 190 - 454 - 161 - + + + + 0 + 10 + 531 + 421 + + + + Translation Manager Plugin + + + + + 0 + 30 + 521 + 232 + + + + + + + Filters - - - - - Ligo class file - This is the name of the world_editor_classes.xml file. - - - - - - - - - - Work directory - - - - - - - - - - - - ... - - - - - - - - - Translation directory - - - - - - - - - - - - ... - - - - - - - - - - 9 - 10 - 211 - 181 - + + + + + + + + - - - - - Filters - - - - - - - - - - - - - - :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png - - - true - - - - - - - - - - - :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png - - - true - - - - - - - - - - - - 240 - 10 - 221 - 181 - + + + :/core/icons/ic_nel_add_item.png:/core/icons/ic_nel_add_item.png + + + true - - - - - Languages - - - - - - - - - - - - - - :/icons/ic_nel_add_item.png:/icons/ic_nel_add_item.png - - - true - - - - - - - - - - - :/icons/ic_nel_delete_item.png:/icons/ic_nel_delete_item.png - - - true - - - - - - - - - - - + + + + + + + + + :/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 + + + + + + + + + + ... + + + + + + - - + From d54daf3ef254232a66f56f18fb11f5e7008337c5 Mon Sep 17 00:00:00 2001 From: cemycc Date: Wed, 6 Jul 2011 04:56:58 +0300 Subject: [PATCH 13/34] Added: #1307 Added extraction from primitives --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/editor_worksheet.cpp | 135 +++++++++++- .../translation_manager/editor_worksheet.h | 2 + .../extract_new_sheet_names.cpp | 13 +- .../extract_new_sheet_names.h | 1 + .../translation_manager_main_window.cpp | 203 +++++++++++++----- .../translation_manager_main_window.h | 3 +- 6 files changed, 292 insertions(+), 65 deletions(-) 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 index d19d28723..83c67e7a6 100644 --- 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 @@ -25,6 +25,7 @@ #include #include "extract_bot_names.h" +#include "translation_manager_constants.h" using namespace std; @@ -38,7 +39,7 @@ void CEditorWorksheet::open(QString filename) if(loadExcelSheet(filename.toStdString(), wk_file, true) == true) { bool hasHashValue = false; - table_editor = new QTableWidget(); + table_editor = new QTableWidget(); if(wk_file.getData(0, 0) == ucstring("*HASH_VALUE")) { table_editor->setColumnCount(wk_file.ColCount - 1); @@ -105,8 +106,7 @@ void CEditorWorksheet::open(QString filename) void CEditorWorksheet::activateWindow() { - showMaximized(); - + showMaximized(); } void CEditorWorksheet::save() @@ -209,7 +209,6 @@ void CEditorWorksheet::insertRow() for(int j = 0; j < table_editor->columnCount(); j++) { QTableWidgetItem* item = new QTableWidgetItem(); - //item->setText(QString(" ")); table_editor->setItem(last_row, j, item); } } @@ -236,7 +235,8 @@ void CEditorWorksheet::deleteRow() void CEditorWorksheet::worksheetEditorChanged(int row, int column) { - + if(!isWindowModified()) + setWindowModified(true); } void CEditorWorksheet::extractBotNames(list filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig) @@ -378,9 +378,73 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis if(modified) { setWindowModified(true); + table_editor->scrollToBottom(); } } +void CEditorWorksheet::mergeWorksheetFile(QString filename) +{ + STRING_MANAGER::TWorksheet wk_file; + if(loadExcelSheet(filename.toStdString(), wk_file, true) == true) + { + bool hasHashValue = false; + 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(tr(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(tr(row_value.toString().c_str())); + if(hasHashValue) + { + table_editor->setItem(i - 1, j - 1, row); + } else { + table_editor->setItem(i - 1, j, row); + } + } + } + } + } else { + QErrorMessage error; + error.showMessage("This file is not a worksheet file."); + error.exec(); + } + +} + void CEditorWorksheet::setCurrentFile(QString filename) { QFileInfo *file = new QFileInfo(filename); @@ -392,9 +456,35 @@ void CEditorWorksheet::setCurrentFile(QString filename) void CEditorWorksheet::closeEvent(QCloseEvent *event) { - close(); - event->accept(); - + 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(); + } } bool CEditorWorksheet::isBotNamesTable() @@ -410,6 +500,35 @@ bool CEditorWorksheet::isBotNamesTable() 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"; + } else if(type.toAscii() == Constants::WK_CONTINENT) { + column_name = "placeId"; + } else if(type.toAscii() == Constants::WK_STABLE) { + 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 index 497e23913..39f4aafa1 100644 --- 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 @@ -49,9 +49,11 @@ public: void save(); void saveAs(QString filename); void activateWindow(); + void mergeWorksheetFile(QString filename); void extractBotNames(list filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig); void extractWords(QString filename, QString columnId, IWordListBuilder &wordListBuilder); bool isBotNamesTable(); + bool isSheetTable(QString type); void closeEvent(QCloseEvent *event); private Q_SLOTS: void worksheetEditorChanged(int,int); 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 index e881177bb..e0626bc6b 100644 --- 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 @@ -108,12 +108,12 @@ bool CRegionPrimWordListBuilder::buildWordList(std::vector &allWords, st // ok, read the file CPrimitives PrimDoc; CPrimitiveContext::instance().CurrentPrimitive = &PrimDoc; - // if (!loadXmlPrimitiveFile(PrimDoc, allFiles[i], LigoConfig)) - // { - // nlwarning("Error: cannot open file '%s'. '%s' Aborted", allFiles[i].c_str(), workSheetFileName.c_str()); - // CPrimitiveContext::instance().CurrentPrimitive = NULL; - // return false; - // } + if (!loadXmlPrimitiveFile(PrimDoc, allFiles[i], LigoConfig)) + { + nlwarning("Error: cannot open file '%s'. '%s' Aborted", allFiles[i].c_str(), workSheetFileName.c_str()); + CPrimitiveContext::instance().CurrentPrimitive = NULL; + return false; + } CPrimitiveContext::instance().CurrentPrimitive = NULL; // For all primitives of interest @@ -141,6 +141,7 @@ bool CRegionPrimWordListBuilder::buildWordList(std::vector &allWords, st // avoid duplicate if(allWordSet.insert(primName).second) { + nlinfo(primName.c_str()); //TODO: delete allWords.push_back(primName); } } 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 index 007018a08..8c9151e2e 100644 --- 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 @@ -60,6 +60,7 @@ struct CRegionPrimWordListBuilder : public IWordListBuilder { string PrimPath; vector PrimFilter; + NLLIGO::CLigoConfig LigoConfig; virtual bool buildWordList(std::vector &allWords, string workSheetFileName); }; 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 index 95a5fe95f..daff3923d 100644 --- 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 @@ -16,6 +16,7 @@ // along with this program. If not, see . #include "translation_manager_main_window.h" +#include "translation_manager_constants.h" #include "editor_worksheet.h" // Project system includes @@ -86,7 +87,9 @@ void CMainWindow::createToolbar() // 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())); + 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))); @@ -94,23 +97,37 @@ void CMainWindow::createToolbar() QAction *extractItemWordsAct = wordsExtractionMenu->addAction("&Extract item words..."); extractItemWordsAct->setStatusTip(tr("Extract item words")); connect(extractItemWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); - wordsExtractionMapper->setMapping(extractItemWordsAct, "item"); + wordsExtractionMapper->setMapping(extractItemWordsAct, tr(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, "creature"); + wordsExtractionMapper->setMapping(extractCreatureWordsAct, tr(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, "sbrick"); + wordsExtractionMapper->setMapping(extractSbrickWordsAct, tr(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, "sphrase"); - + wordsExtractionMapper->setMapping(extractSphraseWordsAct, tr(Constants::WK_SPHRASE)); + // extract place and region names + QAction *extractPlaceNamesAct = wordsExtractionMenu->addAction("&Extract place and region names..."); + extractPlaceNamesAct->setStatusTip(tr("Extract place and region names")); + connect(extractPlaceNamesAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); + wordsExtractionMapper->setMapping(extractPlaceNamesAct, tr(Constants::WK_PLACE)); + // extract continent names + QAction *extractContinentNamesAct = wordsExtractionMenu->addAction("&Extract continent names..."); + extractContinentNamesAct->setStatusTip(tr("Extract continent names")); + connect(extractContinentNamesAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); + wordsExtractionMapper->setMapping(extractContinentNamesAct, tr(Constants::WK_CONTINENT)); + // extract stable names + QAction *extractStableNamesAct = wordsExtractionMenu->addAction("&Extract stable names..."); + extractStableNamesAct->setStatusTip(tr("Extract stable names")); + connect(extractStableNamesAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); + wordsExtractionMapper->setMapping(extractStableNamesAct, tr(Constants::WK_STABLE)); // Windows menu windowMenu = new QMenu(tr("&Windows..."), _ui.toolBar); windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL)); @@ -144,7 +161,7 @@ void CMainWindow::setActiveSubWindow(QWidget* window) void CMainWindow::activeSubWindowChanged() { - + } void CMainWindow::updateWindowsList() @@ -215,11 +232,7 @@ void CMainWindow::openWorkFile(QString file) } } else { QErrorMessage error; - QString text; - text.append("The "); - text.append(file_path->fileName()); - text.append(" file don't exists."); - error.showMessage(text); + error.showMessage(QString("The %1 file don't exists.").arg(file_path->fileName())); error.exec(); } @@ -227,11 +240,14 @@ void CMainWindow::openWorkFile(QString file) void CMainWindow::save() { - CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - - if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + if(_ui.mdiArea->subWindowList().size() > 0) { - current_window->save(); + CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + + if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + { + current_window->save(); + } } } @@ -275,35 +291,111 @@ void CMainWindow::initializeSettings(bool georges = false) } } -void CMainWindow::extractWords(QString type) +void CMainWindow::extractWords(QString typeq) { - CEditor* editor_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - CEditorWorksheet* current_window = qobject_cast(editor_window); - - // initializeSettings(false); - - CSheetWordListBuilder builder; - QString column_name; - - if(type == "item") - { - column_name = "item ID"; - builder.SheetExt = "sitem"; - builder.SheetPath = level_design_path + "/game_element/sitem"; - } else if(type == "creature") { - column_name = "creature ID"; - builder.SheetExt = "creature"; - builder.SheetPath = level_design_path + "/Game_elem/Creature/fauna"; - } else if(type == "sbrick") { - column_name = "sbrick ID"; - builder.SheetExt = "sbrick"; - builder.SheetPath = level_design_path + "/game_element/sbrick"; - } else if(type == "sphrase") { - column_name = "sphrase ID"; - builder.SheetExt = "sphrase"; - builder.SheetPath = level_design_path + "/game_element/sphrase"; - } - current_window->extractWords(current_window->windowFilePath(), column_name, builder); + if(verifySettings() == true) + { + CEditorWorksheet* current_window; + if(_ui.mdiArea->subWindowList().size() > 0) + { + CEditor* editor_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + if(QString(editor_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + { + current_window = qobject_cast(editor_window); + QString file_path = current_window->subWindowFilePath(); + if(!current_window->isSheetTable(typeq)) + { + list subWindows = convertSubWindowList(_ui.mdiArea->subWindowList()); + list::iterator it = subWindows.begin(); + bool finded = false; + + for(; it != subWindows.end(); ++it) + { + current_window = qobject_cast((*it)); + file_path = current_window->subWindowFilePath(); + if(current_window->isSheetTable(typeq)) + { + finded = true; + current_window->activateWindow(); + } + } + if(!finded) + { + openWorkFile(typeq); + if(_ui.mdiArea->subWindowList().size() > 0) + { + current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + QString file_path = current_window->windowFilePath(); + } else { + return; + } + } + } + } + } else { + openWorkFile(typeq); + if(_ui.mdiArea->subWindowList().size() > 0) + { + current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + QString file_path = current_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 + "/game_element/sitem"; + isSheet = true; + } else if(typeq.toAscii() == Constants::WK_CREATURE) { + column_name = "creature ID"; + builderS.SheetExt = "creature"; + builderS.SheetPath = level_design_path + "/Game_elem/Creature/fauna"; + isSheet = true; + } else if(typeq.toAscii() == Constants::WK_SBRICK) { + column_name = "sbrick ID"; + builderS.SheetExt = "sbrick"; + builderS.SheetPath = level_design_path + "/game_element/sbrick"; + isSheet = true; + } else if(typeq.toAscii() == Constants::WK_SPHRASE) { + column_name = "sphrase ID"; + builderS.SheetExt = "sphrase"; + builderS.SheetPath = level_design_path + "/game_element/sphrase"; + isSheet = true; + } else if(typeq.toAscii() == Constants::WK_PLACE) { + column_name = "placeId"; + builderP.PrimPath = primitives_path; + builderP.PrimFilter.push_back("region_*.primitive"); + builderP.PrimFilter.push_back("indoors_*.primitive"); + isSheet = false; + } else if(typeq.toAscii() == Constants::WK_CONTINENT) { + column_name = "placeId"; + builderP.PrimPath = primitives_path; + builderP.PrimFilter.push_back("continent_*.primitive"); + isSheet = false; + } else if(typeq.toAscii() == Constants::WK_STABLE) { + column_name = "placeId"; + builderP.PrimPath = primitives_path; + builderP.PrimFilter.push_back("stable_*.primitive"); + isSheet = false; + } + + if(isSheet) + { + current_window->extractWords(current_window->windowFilePath(), column_name, builderS); + } else { + initializeSettings(false); + current_window->extractWords(current_window->windowFilePath(), column_name, builderP); + } + } + } void CMainWindow::extractBotNames() @@ -336,16 +428,26 @@ void CMainWindow::extractBotNames() } if(!finded) { - openWorkFile("bot_names_wk.txt"); - current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - file_path = current_window->windowFilePath(); + openWorkFile(tr(Constants::WK_BOTNAMES)); + if(_ui.mdiArea->subWindowList().size() > 0) + { + current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + QString file_path = current_window->windowFilePath(); + } else { + return; + } } } } } else { - openWorkFile("bot_names_wk.txt"); - current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - QString file_path = current_window->windowFilePath(); + openWorkFile(tr(Constants::WK_BOTNAMES)); + if(_ui.mdiArea->subWindowList().size() > 0) + { + current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + QString file_path = current_window->windowFilePath(); + } else { + return; + } } initializeSettings(true); current_window->extractBotNames(filters, level_design_path, ligoConfig); @@ -363,6 +465,7 @@ void CMainWindow::readSettings() settings->endGroup(); settings->beginGroup(Core::Constants::DATA_PATH_SECTION); level_design_path = settings->value(Core::Constants::LEVELDESIGN_PATH).toString().toStdString(); + primitives_path = QString(Core::Constants::PRIMITIVES_PATH).toStdString(); settings->endGroup(); } 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 index b0d59fe29..2ee796bd0 100644 --- 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 @@ -73,12 +73,13 @@ private: list filters; list languages; string level_design_path; + string primitives_path; string translation_path; string work_path; NLLIGO::CLigoConfig ligoConfig; private Q_SLOTS: void extractBotNames(); - void extractWords(QString); + void extractWords(QString typeq); void open(); void save(); void saveAs(); From 766420cd11803a307bdb2ee5d25e68abc938469a Mon Sep 17 00:00:00 2001 From: cemycc Date: Fri, 8 Jul 2011 18:22:51 +0300 Subject: [PATCH 14/34] Added: #1307 Merge options for translation files from local directory and from FTP server --HG-- branch : gsoc2011-translationovqt --- .../src/plugins/core/core_constants.h | 117 ----------------- .../translation_manager/CMakeLists.txt | 9 +- .../translation_manager/editor_worksheet.cpp | 119 +++++++++--------- .../translation_manager/editor_worksheet.h | 1 + .../extract_new_sheet_names.cpp | 1 - .../translation_manager_main_window.cpp | 82 ++++++++---- .../translation_manager_main_window.h | 4 +- 7 files changed, 132 insertions(+), 201 deletions(-) delete mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_constants.h 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 deleted file mode 100644 index 2acf4f731..000000000 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/core/core_constants.h +++ /dev/null @@ -1,117 +0,0 @@ -// Object Viewer Qt - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// Copyright (C) 2010 Dzmitry Kamiahin -// -// 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 CORE_CONSTANTS_H -#define CORE_CONSTANTS_H - -namespace Core -{ -namespace Constants -{ - -const char * const OVQT_VERSION_LONG = "0.1"; -const char * const OVQT_VENDOR = "Ryzom Core"; -const char * const OVQT_YEAR = "2010, 2011"; -const char * const OVQT_CORE_PLUGIN = "Core"; - -//mainwindow -const char * const MAIN_WINDOW = "ObjectViewerQt.MainWindow"; - -//menubar -const char * const MENU_BAR = "ObjectViewerQt.MenuBar"; - -//menus -const char * const M_FILE = "ObjectViewerQt.Menu.File"; -const char * const M_EDIT = "ObjectViewerQt.Menu.Edit"; -const char * const M_VIEW = "ObjectViewerQt.Menu.View"; -const char * const M_SCENE = "ObjectViewerQt.Menu.Scene"; -const char * const M_TOOLS = "ObjectViewerQt.Menu.Tools"; -const char * const M_WINDOW = "ObjectViewerQt.Menu.Window"; -const char * const M_HELP = "ObjectViewerQt.Menu.Help"; - -const char * const M_FILE_RECENTFILES = "ObjectViewerQt.Menu.File.RecentFiles"; -const char * const M_SHEET = "ObjectViewerQt.Menu.Sheet"; - -//actions -const char * const NEW = "ObjectViewerQt.New"; -const char * const OPEN = "ObjectViewerQt.Open"; -const char * const SAVE = "ObjectViewerQt.Save"; -const char * const SAVE_AS = "ObjectViewerQt.SaveAs"; -const char * const SAVE_ALL = "ObjectViewerQt.SaveAll"; -const char * const EXIT = "ObjectViewerQt.Exit"; - -const char * const UNDO = "ObjectViewerQt.Undo"; -const char * const REDO = "ObjectViewerQt.Redo"; -const char * const CUT = "ObjectViewerQt.Cut"; -const char * const COPY = "ObjectViewerQt.Copy"; -const char * const PASTE = "ObjectViewerQt.Paste"; -const char * const DEL = "ObjectViewerQt.Del"; -const char * const FIND = "ObjectViewerQt.Find"; -const char * const SELECT_ALL = "ObjectViewerQt.SelectAll"; -const char * const GOTO_POS = "ObjectViewerQt.Goto"; - -const char * const SETTINGS = "ObjectViewerQt.Settings"; -const char * const TOGGLE_FULLSCREEN = "ObjectViewerQt.ToggleFullScreen"; - -const char * const CLOSE = "ObjectViewerQt.Close"; -const char * const CLOSEALL = "ObjectViewerQt.CloseAll"; -const char * const CLOSEOTHERS = "ObjectViewerQt.CloseOthers"; -const char * const ABOUT = "ObjectViewerQt.About"; -const char * const ABOUT_PLUGINS = "ObjectViewerQt.AboutPlugins"; -const char * const ABOUT_QT = "ObjectViewerQt.AboutQt"; - -//settings -const char * const SETTINGS_CATEGORY_GENERAL = "general"; -const char * const SETTINGS_CATEGORY_GENERAL_ICON = ":/icons/ic_nel_generic_settings.png"; -const char * const SETTINGS_TR_CATEGORY_GENERAL = QT_TR_NOOP("General"); - -const char * const MAIN_WINDOW_SECTION = "MainWindow"; -const char * const MAIN_WINDOW_STATE = "WindowState"; -const char * const MAIN_WINDOW_GEOMETRY = "WindowGeometry"; -const char * const QT_STYLE = "QtStyle"; -const char * const QT_PALETTE = "QtPalette"; - -const char * const LANGUAGE = "Language"; -const char * const PLUGINS_PATH = "PluginPath"; -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 REMAP_EXTENSIONS = "RemapExtensions"; - -const char * const LOG_SECTION = "LogSettings"; -const char * const LOG_ERROR = "LogError"; -const char * const LOG_WARNING = "LogWarning"; -const char * const LOG_DEBUG = "LogDebug"; -const char * const LOG_ASSERT = "LogAssert"; -const char * const LOG_INFO = "LogInfo"; - -//resources -const char * const ICON_NEL = ":/core/images/nel.png"; -const char * const ICON_SETTINGS = ":/core/images/preferences.png"; -const char * const ICON_PILL = ":/core/icons/ic_nel_pill.png"; -const char * const ICON_OPEN = ":/core/icons/ic_nel_open.png"; -const char * const ICON_NEW = ":/core/icons/ic_nel_new.png"; -const char * const ICON_SAVE = ":/core/icons/ic_nel_save.png"; -const char * const ICON_SAVE_AS = ":/core/icons/ic_nel_save_as.png"; -const char * const ICON_CRASH = ":/core/icons/ic_nel_crash.png"; - -} // namespace Constants -} // namespace Core - -#endif // CORE_CONSTANTS_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt index 56195d6e0..59f11c4f8 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt @@ -13,15 +13,20 @@ 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 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) + translation_manager_main_window.ui + source_selection.ui + ftp_selection.ui) 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}) @@ -34,7 +39,7 @@ SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC}) ADD_LIBRARY(ovqt_plugin_translation_manager MODULE ${SRC} ${OVQT_PLUG_TRANSLATION_MANAGER_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_PLUG_TRANSLATION_MANAGER_UI_HDRS}) -TARGET_LINK_LIBRARIES(ovqt_plugin_translation_manager ovqt_plugin_core nelmisc nel3d nelligo nelgeorges ${QT_LIBRARIES} ${QT_QTOPENGL_LIBRARY}) +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) 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 index 83c67e7a6..de20db5ec 100644 --- 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 @@ -139,14 +139,14 @@ void CEditorWorksheet::save() colname = wk_file.getData(0, j + colIdx); rowIdf = uint(i + 1); - if(wk_file.findRow(j + colIdx, colname, rowIdf)) + if(wk_file.findRow(j + colIdx, colname, rowIdf)) // search for the row { - if(wk_file.getData(i + 1, j + colIdx) != tvalue) + if(wk_file.getData(i + 1, j + colIdx) != tvalue) // verify the current value { - wk_file.setData(i + 1, j + colIdx, tvalue); + wk_file.setData(i + 1, j + colIdx, tvalue); // change the value } } else { - wk_file.setData(i + 1, j + colIdx, tvalue); + wk_file.setData(i + 1, j + colIdx, tvalue); // insert the value } } } @@ -382,67 +382,74 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis } } +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; + bool hasHashValue = false; + int colIndex = 0; 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(tr(col_name.toString().c_str())); - if(hasHashValue) - { - table_editor->setHorizontalHeaderItem(i - 1, col); - } else { - table_editor->setHorizontalHeaderItem(i, col); - } - } - } - + colIndex = 1; + } // read rows for(unsigned int i = 1; i < wk_file.size(); i++) { - for(unsigned int j = 0; j < wk_file.ColCount; j++) + // search with the first column + ucstring rowId = wk_file.getData(i,colIndex); + QList search_results = table_editor->findItems(tr(rowId.toString().c_str()), Qt::MatchExactly); + if(search_results.size() == 0) { - 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(tr(row_value.toString().c_str())); - if(hasHashValue) - { - table_editor->setItem(i - 1, j - 1, row); - } else { - table_editor->setItem(i - 1, j, row); - } - } - } - } - } else { - QErrorMessage error; - error.showMessage("This file is not a worksheet file."); - error.exec(); - } - + 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("This file is not a worksheet file."); + error.exec(); + } } void CEditorWorksheet::setCurrentFile(QString filename) @@ -514,11 +521,7 @@ bool CEditorWorksheet::isSheetTable(QString type) column_name = "sphrase ID"; } else if(type.toAscii() == Constants::WK_PLACE) { column_name = "placeId"; - } else if(type.toAscii() == Constants::WK_CONTINENT) { - column_name = "placeId"; - } else if(type.toAscii() == Constants::WK_STABLE) { - column_name = "placeId"; - } + } bool status = true; if(table_editor->horizontalHeaderItem(0)->text() != column_name || table_editor->horizontalHeaderItem(1)->text() != "name") 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 index 39f4aafa1..95ee140d1 100644 --- 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 @@ -50,6 +50,7 @@ public: 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); bool isBotNamesTable(); 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 index e0626bc6b..f2369fc1c 100644 --- 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 @@ -141,7 +141,6 @@ bool CRegionPrimWordListBuilder::buildWordList(std::vector &allWords, st // avoid duplicate if(allWordSet.insert(primName).second) { - nlinfo(primName.c_str()); //TODO: delete allWords.push_back(primName); } } 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 index daff3923d..548aa4b37 100644 --- 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 @@ -18,6 +18,7 @@ #include "translation_manager_main_window.h" #include "translation_manager_constants.h" #include "editor_worksheet.h" +#include "ftp_selection.h" // Project system includes #include "../core/icore.h" @@ -114,20 +115,15 @@ void CMainWindow::createToolbar() connect(extractSphraseWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); wordsExtractionMapper->setMapping(extractSphraseWordsAct, tr(Constants::WK_SPHRASE)); // extract place and region names - QAction *extractPlaceNamesAct = wordsExtractionMenu->addAction("&Extract place and region names..."); - extractPlaceNamesAct->setStatusTip(tr("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, tr(Constants::WK_PLACE)); - // extract continent names - QAction *extractContinentNamesAct = wordsExtractionMenu->addAction("&Extract continent names..."); - extractContinentNamesAct->setStatusTip(tr("Extract continent names")); - connect(extractContinentNamesAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); - wordsExtractionMapper->setMapping(extractContinentNamesAct, tr(Constants::WK_CONTINENT)); - // extract stable names - QAction *extractStableNamesAct = wordsExtractionMenu->addAction("&Extract stable names..."); - extractStableNamesAct->setStatusTip(tr("Extract stable names")); - connect(extractStableNamesAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); - wordsExtractionMapper->setMapping(extractStableNamesAct, tr(Constants::WK_STABLE)); + // 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 windowMenu = new QMenu(tr("&Windows..."), _ui.toolBar); windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL)); @@ -375,16 +371,6 @@ void CMainWindow::extractWords(QString typeq) builderP.PrimFilter.push_back("region_*.primitive"); builderP.PrimFilter.push_back("indoors_*.primitive"); isSheet = false; - } else if(typeq.toAscii() == Constants::WK_CONTINENT) { - column_name = "placeId"; - builderP.PrimPath = primitives_path; - builderP.PrimFilter.push_back("continent_*.primitive"); - isSheet = false; - } else if(typeq.toAscii() == Constants::WK_STABLE) { - column_name = "placeId"; - builderP.PrimPath = primitives_path; - builderP.PrimFilter.push_back("stable_*.primitive"); - isSheet = false; } if(isSheet) @@ -454,6 +440,58 @@ void CMainWindow::extractBotNames() } } +void CMainWindow::mergeSingleFile() +{ + CEditor* editor_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + CSourceDialog *dialog = new CSourceDialog(this); + map methods; + // 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(); + if(dialog->selected_item == local_item) // Local directory + { + QString file_name; + if (_ui.mdiArea->subWindowList().size() > 0) + { + file_name = QFileDialog::getOpenFileName(this); + } else { + return; + } + + if(QString(editor_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + { + 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(QString("The file: %1 has different columns from the current file in editor.").arg(file_name)); + error.exec(); + } + } + } else if(dialog->selected_item == ftp_item) { // Ftp directory + CFtpSelection* ftp_dialog = new CFtpSelection(this); + ftp_dialog->show(); + ftp_dialog->exec(); + } else { + return; + } + + +} + void CMainWindow::readSettings() { QSettings *settings = Core::ICore::instance()->settings(); 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 index 2ee796bd0..95e4cbaa1 100644 --- 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 @@ -38,9 +38,11 @@ #include #include #include +#include #include "translation_manager_editor.h" +#include "source_selection.h" #include "ui_translation_manager_main_window.h" #include @@ -86,7 +88,7 @@ private Q_SLOTS: void activeSubWindowChanged(); void setActiveSubWindow(QWidget *window); void updateWindowsList(); - + void mergeSingleFile(); void debug(QString text); // TODO private: void openWorkFile(QString file); From 4c0141184041197b78bdea764b82f5f39aea3bcb Mon Sep 17 00:00:00 2001 From: cemycc Date: Fri, 8 Jul 2011 18:31:59 +0300 Subject: [PATCH 15/34] Added: #1307 Ui deffs for merge source selection and ftp selection --HG-- branch : gsoc2011-translationovqt --- .../TranslationManagerPlugin.cbp | 32 ++++ .../TranslationManagerPlugin.layout | 4 + .../translation_manager/ftp_selection.cpp | 121 ++++++++++++++ .../translation_manager/ftp_selection.h | 46 ++++++ .../translation_manager/ftp_selection.ui | 135 ++++++++++++++++ .../nbproject/Package-Default.bash | 75 +++++++++ .../nbproject/configurations.xml | 147 ++++++++++++++++++ .../nbproject/private/configurations.xml | 41 +++++ .../nbproject/private/private.properties | 0 .../nbproject/private/private.xml | 17 ++ .../nbproject/project.properties | 0 .../translation_manager/nbproject/project.xml | 23 +++ .../translation_manager/source_selection.cpp | 37 +++++ .../translation_manager/source_selection.h | 37 +++++ .../translation_manager/source_selection.ui | 70 +++++++++ .../translation_manager_constants.h | 27 ++++ 16 files changed, 812 insertions(+) create mode 100644 code/TranslationManagerPlugin/TranslationManagerPlugin.cbp create mode 100644 code/TranslationManagerPlugin/TranslationManagerPlugin.layout create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.ui create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/Package-Default.bash create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/configurations.xml create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/configurations.xml create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/private.properties create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/private.xml create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/project.properties create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/project.xml create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.ui create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_constants.h diff --git a/code/TranslationManagerPlugin/TranslationManagerPlugin.cbp b/code/TranslationManagerPlugin/TranslationManagerPlugin.cbp new file mode 100644 index 000000000..f8c6d49c1 --- /dev/null +++ b/code/TranslationManagerPlugin/TranslationManagerPlugin.cbp @@ -0,0 +1,32 @@ + + + + + + diff --git a/code/TranslationManagerPlugin/TranslationManagerPlugin.layout b/code/TranslationManagerPlugin/TranslationManagerPlugin.layout new file mode 100644 index 000000000..23b67ddb1 --- /dev/null +++ b/code/TranslationManagerPlugin/TranslationManagerPlugin.layout @@ -0,0 +1,4 @@ + + + + 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..dbc1144a8 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.cpp @@ -0,0 +1,121 @@ + +#include "ftp_selection.h" + +#include +#include +namespace Plugin +{ + 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.cancelButton, SIGNAL(clicked()), this, SLOT(CancelButtonClicked())); + + // 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); + } + + 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))); + + 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()); + } + } + + void CFtpSelection::FtpCommandFinished(int, bool error) + { + 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::List) + { + if (isDirectory.isEmpty()) { + _ui.fileList->addTopLevelItem(new QTreeWidgetItem(QStringList() << tr(""))); + _ui.fileList->setEnabled(false); + } + } + } + + 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() ? ":/images/dir.png" : ":/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(); + //TODO: cursor + return; + } + } + + void CFtpSelection::DoneButtonClicked() + { + + } + + void CFtpSelection::CancelButtonClicked() + { + + } +} 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..195abfc85 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.h @@ -0,0 +1,46 @@ +/* + * 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 "ui_ftp_selection.h" + +using namespace std; + +namespace Plugin { + + class CFtpSelection : public QDialog + { + Q_OBJECT + private: + Ui::FtpSelectionDialog _ui; + QFtp *conn; + QHash isDirectory; + QString currentPath; + private Q_SLOTS: + void processItem(QTreeWidgetItem*,int); + void CancelButtonClicked(); + void ConnectButtonClicked(); + void DoneButtonClicked(); + void FtpCommandFinished(int, bool error); + void AddToList(const QUrlInfo &urlInfo); + public: + 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.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.ui new file mode 100644 index 000000000..c23a7137b --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.ui @@ -0,0 +1,135 @@ + + + FtpSelectionDialog + + + + 0 + 0 + 383 + 547 + + + + Dialog + + + + + 10 + 10 + 371 + 501 + + + + FTP Server informations + + + + + 0 + 130 + 371 + 411 + + + + Content + + + + + 0 + 20 + 141 + 21 + + + + Please select the file + + + + + + 0 + 40 + 361 + 311 + + + + + 1 + + + + + + + + 1 + 29 + 361 + 107 + + + + + + + Ftp server + + + + + + + + + + Connect + + + + + + + + + + + + + + + + + 10 + 500 + 361 + 33 + + + + + + + Done + + + + + + + Cancel + + + + + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/Package-Default.bash b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/Package-Default.bash new file mode 100644 index 000000000..d50edf611 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/Package-Default.bash @@ -0,0 +1,75 @@ +#!/bin/bash -x + +# +# Generated - do not edit! +# + +# Macros +TOP=`pwd` +CND_PLATFORM=GNU-Linux-x86 +CND_CONF=Default +CND_DISTDIR=dist +CND_BUILDDIR=build +NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging +TMPDIRNAME=tmp-packaging +OUTPUT_PATH=../../../../../../../build/bin/object_viewer_qt +OUTPUT_BASENAME=object_viewer_qt +PACKAGE_TOP_DIR=translationmanager/ + +# Functions +function checkReturnCode +{ + rc=$? + if [ $rc != 0 ] + then + exit $rc + fi +} +function makeDirectory +# $1 directory path +# $2 permission (optional) +{ + mkdir -p "$1" + checkReturnCode + if [ "$2" != "" ] + then + chmod $2 "$1" + checkReturnCode + fi +} +function copyFileToTmpDir +# $1 from-file path +# $2 to-file path +# $3 permission +{ + cp "$1" "$2" + checkReturnCode + if [ "$3" != "" ] + then + chmod $3 "$2" + checkReturnCode + fi +} + +# Setup +cd "${TOP}" +mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package +rm -rf ${NBTMPDIR} +mkdir -p ${NBTMPDIR} + +# Copy files and create directories and links +cd "${TOP}" +makeDirectory "${NBTMPDIR}/translationmanager/bin" +copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 + + +# Generate tar file +cd "${TOP}" +rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/translationmanager.tar +cd ${NBTMPDIR} +tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/translationmanager.tar * +checkReturnCode + +# Cleanup +cd "${TOP}" +rm -rf ${NBTMPDIR} diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/configurations.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/configurations.xml new file mode 100644 index 000000000..66a3d7f05 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/configurations.xml @@ -0,0 +1,147 @@ + + + + + + + + + + + + + ../../../../../../../build/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ui_translation_manager_settings_page.h + + + + + + + + + + + + + ../../../../../../include/nel/misc/app_context.h + ../../../../../../include/nel/misc/common.h + ../../../../../../include/nel/misc/debug.h + ../../../../../../include/nel/misc/displayer.h + ../../../../../../include/nel/misc/log.h + ../../../../../../include/nel/misc/mem_displayer.h + ../../../../../../include/nel/misc/mutex.h + ../../../../../../include/nel/misc/string_common.h + ../../../../../../include/nel/misc/time_nl.h + ../../../../../../include/nel/misc/types_nl.h + + + + + + + + ../../extension_system/iplugin.h + ../../extension_system/iplugin_manager.h + ../../extension_system/iplugin_spec.h + + + + ../core/core_constants.h + ../core/core_global.h + ../core/icontext.h + ../core/icore.h + ../core/icore_listener.h + ../core/imenu_manager.h + ../core/ioptions_page.h + + + + + editor_worksheet.cpp + editor_worksheet.h + extract_bot_names.cpp + extract_bot_names.h + extract_new_sheet_names.cpp + extract_new_sheet_names.h + source_selection.cpp + source_selection.h + translation_manager_constants.h + translation_manager_editor.h + translation_manager_main_window.cpp + translation_manager_main_window.h + translation_manager_plugin.cpp + translation_manager_plugin.h + translation_manager_settings_page.cpp + translation_manager_settings_page.h + + + ../../../../../../../build/Makefile + + + ^(nbproject)$ + + . + + ../../../../../../../build/Makefile + + + + LOCAL_SOURCES + default + + + + ../../../../../../../build + ${MAKE} -f Makefile ovqt_plugin_translation_manager + ${MAKE} -f Makefile clean + ../../../../../../../build/bin/object_viewer_qt + + + + + + ../../../../../../include + + + + + + + ../../../../../../../build/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager + ../../../../../../include + + + + + + + ../../../../../../../build/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager + ../../../../../../include + + + + + + + ../../../../../../../build/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager + + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/configurations.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/configurations.xml new file mode 100644 index 000000000..c4febd942 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/configurations.xml @@ -0,0 +1,41 @@ + + + ../../../../../../../build/Makefile + + + + localhost + 2 + + + + + + + + + + + + + + + + + gdb + + + + "${OUTPUT_PATH}" + + "${OUTPUT_PATH}" + + true + 0 + 0 + + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/private.properties b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/private.properties new file mode 100644 index 000000000..e69de29bb diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/private.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/private.xml new file mode 100644 index 000000000..c6e5619d5 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/private.xml @@ -0,0 +1,17 @@ + + + + true + + + 0 + 0 + + + + + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/project.properties b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/project.properties new file mode 100644 index 000000000..e69de29bb diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/project.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/project.xml new file mode 100644 index 000000000..68607a434 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/project.xml @@ -0,0 +1,23 @@ + + + org.netbeans.modules.cnd.makeproject + + + translation_manager + + cpp + h + UTF-8 + + + . + + + + Default + 0 + + + + + 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..6bc048b0b --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.cpp @@ -0,0 +1,37 @@ + +#include + +#include "source_selection.h" + +namespace Plugin +{ + + +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.listWidget->setSortingEnabled(false); +} + +void CSourceDialog::setSourceOptions(map options) +{ + map::iterator it; + + for(it = options.begin(); it != options.end(); ++it) + { + _ui.listWidget->addItem((*it).first); + } +} + +void CSourceDialog::OkButtonClicked() +{ + selected_item = _ui.listWidget->currentItem(); + reject(); +} + +} 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..074ad5b86 --- /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 Plugin +{ + class CSourceDialog : public QDialog + { + Q_OBJECT + private: + Ui::SourceSelectionDialog _ui; + + private Q_SLOTS: + + void OkButtonClicked(); + 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..6e6f822fe --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.ui @@ -0,0 +1,70 @@ + + + SourceSelectionDialog + + + Qt::WindowModal + + + true + + + + 0 + 0 + 396 + 197 + + + + Dialog + + + true + + + + + 10 + 10 + 381 + 181 + + + + Select source for merge operation + + + + + 10 + 30 + 361 + 141 + + + + + + + + + + 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..b6bdc8315 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_constants.h @@ -0,0 +1,27 @@ +/* + * 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 Plugin +{ + namespace Constants + { + 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 */ + From 03e08b730a6f33d8b2ffe4f0af5a4be52977289a Mon Sep 17 00:00:00 2001 From: cemycc Date: Tue, 12 Jul 2011 22:02:05 +0300 Subject: [PATCH 16/34] Changed: #1307 Added implementation of undo/redo framework partial --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/editor_worksheet.cpp | 17 ++++++++-- .../translation_manager/editor_worksheet.h | 33 +++++++++++++++++-- .../translation_manager_editor.h | 6 ++++ .../translation_manager_main_window.cpp | 7 ++-- 4 files changed, 56 insertions(+), 7 deletions(-) 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 index de20db5ec..5f38d29f1 100644 --- 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 @@ -95,7 +95,8 @@ void CEditorWorksheet::open(QString filename) table_editor->resizeColumnsToContents(); table_editor->resizeRowsToContents(); // set editor signals - connect(table_editor, SIGNAL(cellChanged(int,int) ), this, SLOT(worksheetEditorChanged(int,int))); + connect(table_editor, SIGNAL(itemChanged(QTableWidgetItem*) ), this, SLOT(worksheetEditorChanged(QTableWidgetItem*))); + connect(table_editor, SIGNAL(itemDoubleClicked(QTableWidgetItem*) ), this, SLOT(worksheetEditorCellEntered(QTableWidgetItem*))); } else { QErrorMessage error; error.showMessage("This file is not a worksheet file."); @@ -233,8 +234,19 @@ void CEditorWorksheet::deleteRow() return; } -void CEditorWorksheet::worksheetEditorChanged(int row, int column) +void CEditorWorksheet::worksheetEditorCellEntered(QTableWidgetItem * item) { + temp_content = item->text(); +} + +void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item) +{ + if(temp_content != item->text()) + { + QString i_text = item->text(); + current_stack->push(new CUndoWorksheetCommand(item, temp_content, i_text)); + } + if(!isWindowModified()) setWindowModified(true); } @@ -494,6 +506,7 @@ void CEditorWorksheet::closeEvent(QCloseEvent *event) } } + bool CEditorWorksheet::isBotNamesTable() { bool status = true; 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 index 95ee140d1..3723a6b70 100644 --- 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 @@ -31,6 +31,9 @@ #include #include #include +#include +#include + #include "translation_manager_editor.h" #include "extract_new_sheet_names.h" @@ -40,11 +43,12 @@ namespace Plugin { class CEditorWorksheet : public CEditor { Q_OBJECT -private: - QTableWidget* table_editor; +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); @@ -57,7 +61,8 @@ public: bool isSheetTable(QString type); void closeEvent(QCloseEvent *event); private Q_SLOTS: - void worksheetEditorChanged(int,int); + void worksheetEditorCellEntered(QTableWidgetItem * item); + void worksheetEditorChanged(QTableWidgetItem * item); void insertRow(); void deleteRow(); private: @@ -65,6 +70,28 @@ private: }; +class CUndoWorksheetCommand : public QUndoCommand +{ +public: + CUndoWorksheetCommand(QTableWidgetItem* item, const QString &ocontent, QString ccontent) : QUndoCommand("Insert characters in cells"), m_item(item), m_ocontent(ocontent), m_ccontent(ccontent) { } + + virtual void redo() + { + + //m_ccontent = m_item->text(); + m_item->setText(m_ccontent); + + } + virtual void undo() + { + m_item->setText(m_ocontent); + } +private: + QTableWidgetItem* m_item; + QString m_ocontent; + QString m_ccontent; }; + +} #endif /* EDITOR_WORKSHEET_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 index 7af2b061d..ff947b1d1 100644 --- 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 @@ -22,12 +22,14 @@ #include #include #include +#include namespace Plugin { class CEditor : public QMdiSubWindow { Q_OBJECT protected: + QUndoStack* current_stack; QString current_file; int editor_type; public: @@ -42,6 +44,10 @@ public: { return current_file; } + void setUndoStack(QUndoStack* stack) + { + current_stack = stack; + } }; } 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 index 548aa4b37..6cf9c3f1d 100644 --- 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 @@ -65,7 +65,9 @@ CMainWindow::CMainWindow(QWidget *parent) initialize_settings["ligo"] = false; readSettings(); createToolbar(); - m_undoStack = new QUndoStack(this); + m_undoStack = new QUndoStack(this); + _ui.toolBar->addAction(m_undoStack->createUndoAction(this)); + _ui.toolBar->addAction(m_undoStack->createRedoAction(this)); } void CMainWindow::createToolbar() @@ -207,7 +209,8 @@ void CMainWindow::open() } if(isWorksheetEditor(file_name)) { - CEditorWorksheet *new_window = new CEditorWorksheet(_ui.mdiArea); + CEditorWorksheet *new_window = new CEditorWorksheet(_ui.mdiArea); + new_window->setUndoStack(m_undoStack); new_window->open(file_name); new_window->activateWindow(); } From d035dfcb0534c8ef8f21a9e33a977d575b418a2b Mon Sep 17 00:00:00 2001 From: cemycc Date: Wed, 13 Jul 2011 01:43:42 +0300 Subject: [PATCH 17/34] Changed: #1307 Minor fix on QMainWindow reported here: http://ryzomcore.etherpad.opennel.org/12 --HG-- branch : gsoc2011-translationovqt --- .../src/plugins/core/core_constants.h | 2 +- .../translation_manager/editor_worksheet.cpp | 3 +- .../translation_manager/editor_worksheet.h | 175 ++++++------ .../translation_manager_main_window.cpp | 267 ++++++++---------- .../translation_manager_main_window.h | 17 +- .../translation_manager_settings_page.cpp | 16 +- 6 files changed, 220 insertions(+), 260 deletions(-) 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 562947716..ffd21b49a 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,7 +91,7 @@ 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 PRIMITIVES_PATH = "/home/cemycc/Ryzom/work/ryzom/code/ryzom/common/data_leveldesign/primitives"; +const char * const PRIMITIVES_PATH = "D:/Ryzom/ryzom/code/ryzom/common/data_leveldesign/primitives"; const char * const ASSETS_PATH = "AssetsPath"; const char * const REMAP_EXTENSIONS = "RemapExtensions"; 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 index 5f38d29f1..6d233dab9 100644 --- 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 @@ -243,8 +243,7 @@ void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item) { if(temp_content != item->text()) { - QString i_text = item->text(); - current_stack->push(new CUndoWorksheetCommand(item, temp_content, i_text)); + current_stack->push(new CUndoWorksheetCommand(table_editor, item, temp_content)); } if(!isWindowModified()) 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 index 3723a6b70..f25a786ec 100644 --- 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 @@ -1,97 +1,100 @@ -// 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 - - -#include "translation_manager_editor.h" -#include "extract_new_sheet_names.h" - -namespace Plugin { - -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); - 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(); -private: - void setCurrentFile(QString filename); - -}; - +// 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 + + +#include "translation_manager_editor.h" +#include "extract_new_sheet_names.h" + +namespace Plugin { + +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); + 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(); +private: + void setCurrentFile(QString filename); + +}; + class CUndoWorksheetCommand : public QUndoCommand { public: - CUndoWorksheetCommand(QTableWidgetItem* item, const QString &ocontent, QString ccontent) : QUndoCommand("Insert characters in cells"), m_item(item), m_ocontent(ocontent), m_ccontent(ccontent) { } + 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_item->text(); + } - virtual void redo() + void redo() { - - //m_ccontent = m_item->text(); - m_item->setText(m_ccontent); - + m_item->setText(m_ccontent); } - virtual void undo() - { + void undo() + { m_item->setText(m_ocontent); + } + private: + QTableWidget* m_table; QTableWidgetItem* m_item; - QString m_ocontent; QString m_ccontent; -}; - -} -#endif /* EDITOR_WORKSHEET_H */ - + QString m_ocontent; +}; + +} +#endif /* EDITOR_WORKSHEET_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 index 6cf9c3f1d..466b57a38 100644 --- 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 @@ -17,7 +17,6 @@ #include "translation_manager_main_window.h" #include "translation_manager_constants.h" -#include "editor_worksheet.h" #include "ftp_selection.h" // Project system includes @@ -63,11 +62,12 @@ CMainWindow::CMainWindow(QWidget *parent) initialize_settings["georges"] = false; initialize_settings["ligo"] = false; + + connect(Core::ICore::instance(), SIGNAL(changeSettings()), this, SLOT(readSettings())); readSettings(); createToolbar(); - m_undoStack = new QUndoStack(this); - _ui.toolBar->addAction(m_undoStack->createUndoAction(this)); - _ui.toolBar->addAction(m_undoStack->createRedoAction(this)); + m_undoStack = new QUndoStack(this); + } void CMainWindow::createToolbar() @@ -132,6 +132,18 @@ void CMainWindow::createToolbar() updateWindowsList(); _ui.toolBar->addAction(windowMenu->menuAction()); connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowsList())); + + // Undo, Redo actions + // ----------------------------- + Core::ICore *core = Core::ICore::instance(); + Core::IMenuManager *menuManager = core->menuManager(); + 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); } void CMainWindow::updateToolbar(QMdiSubWindow *window) @@ -159,7 +171,7 @@ void CMainWindow::setActiveSubWindow(QWidget* window) void CMainWindow::activeSubWindowChanged() { - + //TODO: nothing to be done here atm } void CMainWindow::updateWindowsList() @@ -192,35 +204,26 @@ void CMainWindow::open() QString file_name = QFileDialog::getOpenFileName(this); if(!file_name.isEmpty()) { - list subWindows = convertSubWindowList(_ui.mdiArea->subWindowList()); - list::iterator it = subWindows.begin(); - CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - for(; it != subWindows.end(); ++it) + CEditor *editor = getEditorByWindowFilePath(file_name); + if(editor != NULL) + { + editor->activateWindow(); + return; + } + if(isWorksheetEditor(file_name)) { - QString sw_file = (*it)->subWindowFilePath(); - if(file_name == sw_file) - { - if((*it) != current_window) - { - (*it)->activateWindow(); - } - return; - } - } - if(isWorksheetEditor(file_name)) - { CEditorWorksheet *new_window = new CEditorWorksheet(_ui.mdiArea); new_window->setUndoStack(m_undoStack); new_window->open(file_name); new_window->activateWindow(); - } + } } } void CMainWindow::openWorkFile(QString file) { - QFileInfo* file_path = new QFileInfo(QString("%1/%2").arg(QString(work_path.c_str())).arg(file)); + QFileInfo* file_path = new QFileInfo(QString("%1/%2").arg(work_path).arg(file)); if(file_path->exists()) { if(isWorksheetEditor(file_path->filePath())) @@ -273,8 +276,8 @@ void CMainWindow::initializeSettings(bool georges = false) { if(georges == true && initialize_settings["georges"] == false) { - CPath::addSearchPath(level_design_path + "/DFN", true, false); - CPath::addSearchPath(level_design_path + "/Game_elem/Creature", true, 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; } @@ -294,54 +297,21 @@ void CMainWindow::extractWords(QString typeq) { if(verifySettings() == true) { - CEditorWorksheet* current_window; - if(_ui.mdiArea->subWindowList().size() > 0) - { - CEditor* editor_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - if(QString(editor_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor - { - current_window = qobject_cast(editor_window); - QString file_path = current_window->subWindowFilePath(); - if(!current_window->isSheetTable(typeq)) - { - list subWindows = convertSubWindowList(_ui.mdiArea->subWindowList()); - list::iterator it = subWindows.begin(); - bool finded = false; - - for(; it != subWindows.end(); ++it) - { - current_window = qobject_cast((*it)); - file_path = current_window->subWindowFilePath(); - if(current_window->isSheetTable(typeq)) - { - finded = true; - current_window->activateWindow(); - } - } - if(!finded) - { - openWorkFile(typeq); - if(_ui.mdiArea->subWindowList().size() > 0) - { - current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - QString file_path = current_window->windowFilePath(); - } else { - return; - } - } - } - } - } else { - openWorkFile(typeq); - if(_ui.mdiArea->subWindowList().size() > 0) - { - current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - QString file_path = current_window->windowFilePath(); - } else { - return; - } - - } + 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; @@ -351,26 +321,26 @@ void CMainWindow::extractWords(QString typeq) if(typeq.toAscii() == Constants::WK_ITEM) { column_name = "item ID"; builderS.SheetExt = "sitem"; - builderS.SheetPath = level_design_path + "/game_element/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 + "/Game_elem/Creature/fauna"; + 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 + "/game_element/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 + "/game_element/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; + builderP.PrimPath = primitives_path.toStdString(); builderP.PrimFilter.push_back("region_*.primitive"); builderP.PrimFilter.push_back("indoors_*.primitive"); isSheet = false; @@ -378,12 +348,12 @@ void CMainWindow::extractWords(QString typeq) if(isSheet) { - current_window->extractWords(current_window->windowFilePath(), column_name, builderS); + editor_window->extractWords(editor_window->windowFilePath(), column_name, builderS); } else { initializeSettings(false); - current_window->extractWords(current_window->windowFilePath(), column_name, builderP); - } - } + editor_window->extractWords(editor_window->windowFilePath(), column_name, builderP); + } + } } @@ -391,55 +361,22 @@ void CMainWindow::extractBotNames() { if(verifySettings() == true) { - CEditorWorksheet* current_window; - if(_ui.mdiArea->subWindowList().size() > 0) - { - CEditor* editor_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - if(QString(editor_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor - { - current_window = qobject_cast(editor_window); - QString file_path = current_window->subWindowFilePath(); - if(!current_window->isBotNamesTable()) - { - list subWindows = convertSubWindowList(_ui.mdiArea->subWindowList()); - list::iterator it = subWindows.begin(); - bool finded = false; - - for(; it != subWindows.end(); ++it) - { - current_window = qobject_cast((*it)); - file_path = current_window->subWindowFilePath(); - if(current_window->isBotNamesTable()) - { - finded = true; - current_window->activateWindow(); - } - } - if(!finded) - { - openWorkFile(tr(Constants::WK_BOTNAMES)); - if(_ui.mdiArea->subWindowList().size() > 0) - { - current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - QString file_path = current_window->windowFilePath(); - } else { - return; - } - } - } - } - } else { - openWorkFile(tr(Constants::WK_BOTNAMES)); - if(_ui.mdiArea->subWindowList().size() > 0) - { - current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - QString file_path = current_window->windowFilePath(); - } else { - return; - } - } + 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; + } initializeSettings(true); - current_window->extractBotNames(filters, level_design_path, ligoConfig); + editor_window->extractBotNames(convertQStringList(filters), level_design_path.toStdString(), ligoConfig); } } @@ -498,15 +435,17 @@ void CMainWindow::mergeSingleFile() void CMainWindow::readSettings() { QSettings *settings = Core::ICore::instance()->settings(); + // translation manager settings settings->beginGroup("translationmanager"); - filters = convertQStringList(settings->value("filters").toStringList()); /* filters */ - languages = convertQStringList(settings->value("trlanguages").toStringList()); /* languages */ - translation_path = settings->value("translation").toString().toStdString(); - work_path = settings->value("work").toString().toStdString(); + 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().toStdString(); - primitives_path = QString(Core::Constants::PRIMITIVES_PATH).toStdString(); + level_design_path = settings->value(Core::Constants::LEVELDESIGN_PATH).toString(); + primitives_path = QString(Core::Constants::PRIMITIVES_PATH); //TODO settings->endGroup(); } @@ -521,23 +460,53 @@ bool CMainWindow::verifySettings() { bool count_errors = false; - QSettings *settings = Core::ICore::instance()->settings(); - settings->beginGroup("translationmanager"); - - if(settings->value("filters").toList().count() == 0) + if(level_design_path.isNull() || primitives_path.isNull() || work_path.isNull()) { QErrorMessage error_settings; error_settings.showMessage("Please write all the paths on the settings dialog."); error_settings.exec(); count_errors = true; } - - settings->endGroup(); return !count_errors; } +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 = NULL) +{ + Q_FOREACH(QMdiSubWindow *subWindow, _ui.mdiArea->subWindowList()) + { + CEditor *currentEditor = qobject_cast(subWindow); + if(QString(currentEditor->widget()->metaObject()->className()) == "QTableWidget") + { + CEditorWorksheet *editor = qobject_cast(currentEditor); + if(!type.isNull()) + if(editor->isSheetTable(type)) + { + return editor; + } + else + if(editor->isBotNamesTable()) + { + return editor; + } + } + } + return NULL; +} + + list CMainWindow::convertQStringList(QStringList listq) { std::list stdlist; @@ -550,20 +519,6 @@ list CMainWindow::convertQStringList(QStringList listq) return stdlist; } -list CMainWindow::convertSubWindowList(QList listq) -{ - list subwindows; - QList::iterator it = listq.begin(); - - for(; it != listq.end(); ++it) - { - CEditor* current_window = qobject_cast((*it)); - subwindows.push_back(current_window); - } - - return subwindows; -} - bool CMainWindow::isWorksheetEditor(QString filename) { STRING_MANAGER::TWorksheet wk_file; 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 index 95e4cbaa1..ffb87b4b8 100644 --- 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 @@ -45,6 +45,7 @@ #include "source_selection.h" #include "ui_translation_manager_main_window.h" #include +#include "editor_worksheet.h" class QWidget; @@ -72,12 +73,12 @@ private: QSignalMapper *windowMapper; // config map initialize_settings; - list filters; - list languages; - string level_design_path; - string primitives_path; - string translation_path; - string work_path; + 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(); @@ -99,7 +100,9 @@ private: void createToolbar(); void initializeSettings(bool georges); list convertQStringList(QStringList listq); - list convertSubWindowList(QList listq); + CEditor* getEditorByWindowFilePath(const QString &fileName); + // Worksheet specific functions + CEditorWorksheet* getEditorByWorksheetType(const QString &type); bool isWorksheetEditor(QString filename); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp index 4870da41b..fbd713ac6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp @@ -46,17 +46,17 @@ QString CTranslationManagerSettingsPage::id() const QString CTranslationManagerSettingsPage::trName() const { - return tr("Translation Manager page"); + return tr("Translation Manager"); } QString CTranslationManagerSettingsPage::category() const { - return QLatin1String("General"); + return QLatin1String("Translation Manager"); } QString CTranslationManagerSettingsPage::trCategory() const { - return tr("General"); + return tr("Translation Manager"); } QIcon CTranslationManagerSettingsPage::categoryIcon() const @@ -195,12 +195,12 @@ void CTranslationManagerSettingsPage::writeSettings() 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->setValue("filters", filters); + settings->setValue("trlanguages", languages); + settings->setValue("translation", translation); + settings->setValue("work", work); settings->endGroup(); - settings->sync(); + settings->sync(); } From 8ad55aae3640a9d30ef509c23e858fe73f345025 Mon Sep 17 00:00:00 2001 From: cemycc Date: Wed, 13 Jul 2011 10:39:39 +0300 Subject: [PATCH 18/34] Changed: #1307 Fixing a bug with the extraction options --HG-- branch : gsoc2011-translationovqt --- .../src/plugins/translation_manager/editor_worksheet.cpp | 2 +- .../src/plugins/translation_manager/editor_worksheet.h | 4 ++-- .../translation_manager/extract_new_sheet_names.cpp | 1 - .../translation_manager_main_window.cpp | 7 ++++--- 4 files changed, 7 insertions(+), 7 deletions(-) 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 index 6d233dab9..f34fdb430 100644 --- 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 @@ -243,7 +243,7 @@ void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item) { if(temp_content != item->text()) { - current_stack->push(new CUndoWorksheetCommand(table_editor, item, temp_content)); + //current_stack->push(new CUndoWorksheetCommand(table_editor, item, temp_content)); } if(!isWindowModified()) 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 index f25a786ec..2c8539922 100644 --- 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 @@ -80,11 +80,11 @@ public: void redo() { - m_item->setText(m_ccontent); + //m_item->setText(m_ccontent); } void undo() { - m_item->setText(m_ocontent); + //m_item->setText(m_ocontent); } 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 index f2369fc1c..b9411c74e 100644 --- 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 @@ -34,7 +34,6 @@ namespace Plugin { bool CSheetWordListBuilder::buildWordList(std::vector &allWords, string workSheetFileName) { SheetExt= toLower(SheetExt); - nlinfo("aaaa"); // verify the directory is correct if(!CFile::isDirectory(SheetPath)) { 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 index 466b57a38..20d7e57c1 100644 --- 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 @@ -483,7 +483,7 @@ CEditor *CMainWindow::getEditorByWindowFilePath(const QString &fileName) return NULL; } -CEditorWorksheet *CMainWindow::getEditorByWorksheetType(const QString &type = NULL) +CEditorWorksheet *CMainWindow::getEditorByWorksheetType(const QString &type) { Q_FOREACH(QMdiSubWindow *subWindow, _ui.mdiArea->subWindowList()) { @@ -491,16 +491,17 @@ CEditorWorksheet *CMainWindow::getEditorByWorksheetType(const QString &type = NU if(QString(currentEditor->widget()->metaObject()->className()) == "QTableWidget") { CEditorWorksheet *editor = qobject_cast(currentEditor); - if(!type.isNull()) + if(type != NULL) { if(editor->isSheetTable(type)) { return editor; } - else + } else { if(editor->isBotNamesTable()) { return editor; } + } } } return NULL; From 6fbe07b6f45bc864d56eeac567c744eb46eb60e9 Mon Sep 17 00:00:00 2001 From: cemycc Date: Wed, 13 Jul 2011 19:47:15 +0300 Subject: [PATCH 19/34] Changed: #1307 Added Undo Commands for edit, insertand delete items on table and for words extraction --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/editor_worksheet.cpp | 44 ++++-- .../translation_manager/editor_worksheet.h | 130 ++++++++++++++++-- .../translation_manager/source_selection.cpp | 9 +- .../translation_manager/source_selection.h | 27 ++-- .../translation_manager_main_window.cpp | 23 +--- .../translation_manager_main_window.h | 9 +- 6 files changed, 179 insertions(+), 63 deletions(-) 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 index f34fdb430..5323ded1a 100644 --- 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 @@ -15,8 +15,6 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -#include "editor_worksheet.h" -#include // Qt includes #include #include @@ -24,8 +22,11 @@ #include #include +// Project includes +#include "editor_worksheet.h" #include "extract_bot_names.h" #include "translation_manager_constants.h" +#include using namespace std; @@ -206,12 +207,7 @@ void CEditorWorksheet::saveAs(QString filename) void CEditorWorksheet::insertRow() { int last_row = table_editor->rowCount(); - table_editor->setRowCount(last_row + 1); - for(int j = 0; j < table_editor->columnCount(); j++) - { - QTableWidgetItem* item = new QTableWidgetItem(); - table_editor->setItem(last_row, j, item); - } + current_stack->push(new CUndoWorksheetNewCommand(table_editor, last_row)); } void CEditorWorksheet::deleteRow() @@ -223,10 +219,9 @@ void CEditorWorksheet::deleteRow() msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes); msgBox.setDefaultButton(QMessageBox::No); int ret = msgBox.exec(); - if(ret == QMessageBox::Yes) { - table_editor->removeRow(selected_row); + current_stack->push(new CUndoWorksheetDeleteCommand(table_editor, selected_row)); } table_editor->clearFocus(); @@ -237,6 +232,7 @@ void CEditorWorksheet::deleteRow() void CEditorWorksheet::worksheetEditorCellEntered(QTableWidgetItem * item) { temp_content = item->text(); + current_stack->push(new CUndoWorksheetCommand(table_editor, item, temp_content)); } void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item) @@ -250,9 +246,12 @@ void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item) 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); @@ -271,7 +270,7 @@ void CEditorWorksheet::extractBotNames(list filters, string level_design QTableWidgetItem *bot_name_row = new QTableWidgetItem(); bot_name_row->setText(tr(it->first.c_str())); bot_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 0, bot_name_row); + table_editor ->setItem(currentRow, 0, bot_name_row); QTableWidgetItem *translation_name_row = new QTableWidgetItem(); translation_name_row->setBackgroundColor(QColor("#F75D59")); translation_name_row->setText(tr(it->first.c_str())); @@ -281,6 +280,12 @@ void CEditorWorksheet::extractBotNames(list filters, string level_design sheet_name_row->setBackgroundColor(QColor("#F75D59")); table_editor ->setItem(currentRow, 2, sheet_name_row); if(!modified) modified = true; + CTableWidgetItemStore bot_name_row_s(bot_name_row, currentRow, 0); + new_items.push_back(bot_name_row_s); + CTableWidgetItemStore translation_name_row_s(translation_name_row, currentRow, 1); + new_items.push_back(translation_name_row_s); + CTableWidgetItemStore sheet_name_row_s(sheet_name_row, currentRow, 2); + new_items.push_back(sheet_name_row_s); } } ebn.cleanSimpleNames(); @@ -310,10 +315,18 @@ void CEditorWorksheet::extractBotNames(list filters, string level_design sheet_name_row->setBackgroundColor(QColor("#F75D59")); table_editor ->setItem(currentRow, 2, sheet_name_row); if(!modified) modified = true; + CTableWidgetItemStore bot_name_row_s(bot_name_row, currentRow, 0); + new_items.push_back(bot_name_row_s); + CTableWidgetItemStore translation_name_row_s(translation_name_row, currentRow, 1); + new_items.push_back(translation_name_row_s); + CTableWidgetItemStore sheet_name_row_s(sheet_name_row, currentRow, 2); + new_items.push_back(sheet_name_row_s); } } ebn.cleanGenericNames(); - } + } + + current_stack->push(new CUndoWorksheetExtraction(new_items, table_editor)); if(modified) { setWindowModified(true); @@ -355,6 +368,7 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis return; } bool modified = false; + QList new_items; for(i = 0; i < allWords.size(); i++) { string keyName = allWords[i]; @@ -384,8 +398,14 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis name_row->setBackgroundColor(QColor("#F75D59")); table_editor ->setItem(currentRow, nPos, name_row); if(!modified) modified = true; + CTableWidgetItemStore key_name_row_s(key_name_row, currentRow, knPos); + new_items.push_back(key_name_row_s); + CTableWidgetItemStore name_row_s(name_row, currentRow, nPos); + new_items.push_back(name_row_s); + } } + current_stack->push(new CUndoWorksheetExtraction(new_items, table_editor)); if(modified) { setWindowModified(true); 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 index 2c8539922..983dba4bc 100644 --- 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 @@ -32,9 +32,9 @@ #include #include #include -#include - +#include +// Project includes #include "translation_manager_editor.h" #include "extract_new_sheet_names.h" @@ -70,29 +70,141 @@ private: }; +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 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_item->text(); + m_ccontent = m_ocontent; } void redo() { - //m_item->setText(m_ccontent); + if(m_item->text() == m_ocontent) + { + m_item->setText(m_ccontent); + } } void undo() { - //m_item->setText(m_ocontent); - - } - + 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_ccontent; 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); + } + } + + 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; }; } 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 index 6bc048b0b..cf38ed589 100644 --- 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 @@ -10,12 +10,11 @@ namespace Plugin CSourceDialog::CSourceDialog(QWidget *parent): QDialog(parent) { _ui.setupUi(this); - // Set signal and slot for "OK Button" - + // 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.listWidget->setSortingEnabled(false); + // Set signal and slot for "Cancel Button" + connect(_ui.cancel_button, SIGNAL(clicked()), this, SLOT(reject())); + _ui.listWidget->setSortingEnabled(false); } void CSourceDialog::setSourceOptions(map options) 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 index 074ad5b86..f15a8778a 100644 --- 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 @@ -14,22 +14,21 @@ using namespace std; namespace Plugin { - class CSourceDialog : public QDialog - { - Q_OBJECT - private: - Ui::SourceSelectionDialog _ui; - - private Q_SLOTS: - void OkButtonClicked(); - public: - CSourceDialog(QWidget *parent = 0); - ~CSourceDialog(){} - void setSourceOptions(map options); - QListWidgetItem *selected_item; +class CSourceDialog : public QDialog +{ + Q_OBJECT +private: + Ui::SourceSelectionDialog _ui; + QListWidgetItem *selected_item; +private Q_SLOTS: + void OkButtonClicked(); +public: + CSourceDialog(QWidget *parent = 0); + ~CSourceDialog(){} + void setSourceOptions(map options); +}; - }; } 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 index 20d7e57c1..bb4fa27d1 100644 --- 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 @@ -15,29 +15,20 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -#include "translation_manager_main_window.h" -#include "translation_manager_constants.h" -#include "ftp_selection.h" - // Project system includes #include "../core/icore.h" #include "../core/core_constants.h" #include "../core/imenu_manager.h" #include "../../extension_system/iplugin_spec.h" + // Qt includes #include #include -#include -#include #include #include #include #include #include -#include -#include -#include -#include #include #include #include @@ -46,6 +37,11 @@ #include #include +// Plugin includes +#include "translation_manager_main_window.h" +#include "translation_manager_constants.h" +#include "ftp_selection.h" + namespace Plugin { @@ -449,13 +445,6 @@ void CMainWindow::readSettings() settings->endGroup(); } -void CMainWindow::debug(QString text) -{ - QErrorMessage error_settings; - error_settings.showMessage(text); - error_settings.exec(); -} - bool CMainWindow::verifySettings() { bool count_errors = false; 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 index ffb87b4b8..63a8934d7 100644 --- 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 @@ -19,7 +19,7 @@ #ifndef MAIN_WINDOW_H #define MAIN_WINDOW_H -// Project includes +// Project system includes #include "../core/icore_listener.h" // Nel includes @@ -33,14 +33,13 @@ #include #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" @@ -62,8 +61,7 @@ public: CMainWindow(QWidget *parent = 0); virtual ~CMainWindow() {} QUndoStack *m_undoStack; -private: - +private: Ui::CMainWindow _ui; // actions QAction *openAct; @@ -90,7 +88,6 @@ private Q_SLOTS: void setActiveSubWindow(QWidget *window); void updateWindowsList(); void mergeSingleFile(); - void debug(QString text); // TODO private: void openWorkFile(QString file); void updateToolbar(QMdiSubWindow *window); From 10d5831ac4ba541ef75e5be99398187899df4685 Mon Sep 17 00:00:00 2001 From: cemycc Date: Wed, 13 Jul 2011 22:34:00 +0300 Subject: [PATCH 20/34] Changed: #1307 I have clean my branch, removing temp files --HG-- branch : gsoc2011-translationovqt --- .../TranslationManagerPlugin.cbp | 32 ---- .../TranslationManagerPlugin.layout | 4 - .../nbproject/Package-Default.bash | 75 --------- .../nbproject/configurations.xml | 147 ------------------ .../nbproject/private/configurations.xml | 41 ----- .../nbproject/private/private.properties | 0 .../nbproject/private/private.xml | 17 -- .../nbproject/project.properties | 0 .../translation_manager/nbproject/project.xml | 23 --- 9 files changed, 339 deletions(-) delete mode 100644 code/TranslationManagerPlugin/TranslationManagerPlugin.cbp delete mode 100644 code/TranslationManagerPlugin/TranslationManagerPlugin.layout delete mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/Package-Default.bash delete mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/configurations.xml delete mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/configurations.xml delete mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/private.properties delete mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/private.xml delete mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/project.properties delete mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/project.xml diff --git a/code/TranslationManagerPlugin/TranslationManagerPlugin.cbp b/code/TranslationManagerPlugin/TranslationManagerPlugin.cbp deleted file mode 100644 index f8c6d49c1..000000000 --- a/code/TranslationManagerPlugin/TranslationManagerPlugin.cbp +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - diff --git a/code/TranslationManagerPlugin/TranslationManagerPlugin.layout b/code/TranslationManagerPlugin/TranslationManagerPlugin.layout deleted file mode 100644 index 23b67ddb1..000000000 --- a/code/TranslationManagerPlugin/TranslationManagerPlugin.layout +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/Package-Default.bash b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/Package-Default.bash deleted file mode 100644 index d50edf611..000000000 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/Package-Default.bash +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash -x - -# -# Generated - do not edit! -# - -# Macros -TOP=`pwd` -CND_PLATFORM=GNU-Linux-x86 -CND_CONF=Default -CND_DISTDIR=dist -CND_BUILDDIR=build -NBTMPDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tmp-packaging -TMPDIRNAME=tmp-packaging -OUTPUT_PATH=../../../../../../../build/bin/object_viewer_qt -OUTPUT_BASENAME=object_viewer_qt -PACKAGE_TOP_DIR=translationmanager/ - -# Functions -function checkReturnCode -{ - rc=$? - if [ $rc != 0 ] - then - exit $rc - fi -} -function makeDirectory -# $1 directory path -# $2 permission (optional) -{ - mkdir -p "$1" - checkReturnCode - if [ "$2" != "" ] - then - chmod $2 "$1" - checkReturnCode - fi -} -function copyFileToTmpDir -# $1 from-file path -# $2 to-file path -# $3 permission -{ - cp "$1" "$2" - checkReturnCode - if [ "$3" != "" ] - then - chmod $3 "$2" - checkReturnCode - fi -} - -# Setup -cd "${TOP}" -mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package -rm -rf ${NBTMPDIR} -mkdir -p ${NBTMPDIR} - -# Copy files and create directories and links -cd "${TOP}" -makeDirectory "${NBTMPDIR}/translationmanager/bin" -copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}bin/${OUTPUT_BASENAME}" 0755 - - -# Generate tar file -cd "${TOP}" -rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/translationmanager.tar -cd ${NBTMPDIR} -tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/translationmanager.tar * -checkReturnCode - -# Cleanup -cd "${TOP}" -rm -rf ${NBTMPDIR} diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/configurations.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/configurations.xml deleted file mode 100644 index 66a3d7f05..000000000 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/configurations.xml +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - - - - - - - ../../../../../../../build/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ui_translation_manager_settings_page.h - - - - - - - - - - - - - ../../../../../../include/nel/misc/app_context.h - ../../../../../../include/nel/misc/common.h - ../../../../../../include/nel/misc/debug.h - ../../../../../../include/nel/misc/displayer.h - ../../../../../../include/nel/misc/log.h - ../../../../../../include/nel/misc/mem_displayer.h - ../../../../../../include/nel/misc/mutex.h - ../../../../../../include/nel/misc/string_common.h - ../../../../../../include/nel/misc/time_nl.h - ../../../../../../include/nel/misc/types_nl.h - - - - - - - - ../../extension_system/iplugin.h - ../../extension_system/iplugin_manager.h - ../../extension_system/iplugin_spec.h - - - - ../core/core_constants.h - ../core/core_global.h - ../core/icontext.h - ../core/icore.h - ../core/icore_listener.h - ../core/imenu_manager.h - ../core/ioptions_page.h - - - - - editor_worksheet.cpp - editor_worksheet.h - extract_bot_names.cpp - extract_bot_names.h - extract_new_sheet_names.cpp - extract_new_sheet_names.h - source_selection.cpp - source_selection.h - translation_manager_constants.h - translation_manager_editor.h - translation_manager_main_window.cpp - translation_manager_main_window.h - translation_manager_plugin.cpp - translation_manager_plugin.h - translation_manager_settings_page.cpp - translation_manager_settings_page.h - - - ../../../../../../../build/Makefile - - - ^(nbproject)$ - - . - - ../../../../../../../build/Makefile - - - - LOCAL_SOURCES - default - - - - ../../../../../../../build - ${MAKE} -f Makefile ovqt_plugin_translation_manager - ${MAKE} -f Makefile clean - ../../../../../../../build/bin/object_viewer_qt - - - - - - ../../../../../../include - - - - - - - ../../../../../../../build/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager - ../../../../../../include - - - - - - - ../../../../../../../build/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager - ../../../../../../include - - - - - - - ../../../../../../../build/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager - - - - - - diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/configurations.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/configurations.xml deleted file mode 100644 index c4febd942..000000000 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/configurations.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - ../../../../../../../build/Makefile - - - - localhost - 2 - - - - - - - - - - - - - - - - - gdb - - - - "${OUTPUT_PATH}" - - "${OUTPUT_PATH}" - - true - 0 - 0 - - - - - - diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/private.properties b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/private.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/private.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/private.xml deleted file mode 100644 index c6e5619d5..000000000 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/private/private.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - true - - - 0 - 0 - - - - - - - - - diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/project.properties b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/project.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/project.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/project.xml deleted file mode 100644 index 68607a434..000000000 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/nbproject/project.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - org.netbeans.modules.cnd.makeproject - - - translation_manager - - cpp - h - UTF-8 - - - . - - - - Default - 0 - - - - - From cfa72440745c01d20615058d49aba55b296dbc08 Mon Sep 17 00:00:00 2001 From: cemycc Date: Fri, 15 Jul 2011 00:38:16 +0300 Subject: [PATCH 21/34] Added #1307 Full support for FTP merge options and icons for FTP window. This is the last commit for the first milestone. --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/CMakeLists.txt | 2 + .../translation_manager/ftp_selection.cpp | 90 +++++++++++++++--- .../translation_manager/ftp_selection.h | 7 +- .../translation_manager/ftp_selection.qrc | 7 ++ .../translation_manager/ftp_selection.ui | 84 ++++++++-------- .../translation_manager/images/cdtoparent.png | Bin 0 -> 139 bytes .../translation_manager/images/dir.png | Bin 0 -> 154 bytes .../translation_manager/images/file.png | Bin 0 -> 129 bytes .../translation_manager/source_selection.h | 4 +- .../translation_manager_main_window.cpp | 73 +++++++++----- .../translation_manager_main_window.h | 2 +- 11 files changed, 188 insertions(+), 81 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.qrc create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/images/cdtoparent.png create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/images/dir.png create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/images/file.png diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt index 59f11c4f8..7e7da7e99 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt @@ -24,6 +24,8 @@ SET(OVQT_PLUG_TRANSLATION_MANAGER_UIS translation_manager_settings_page.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) 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 index dbc1144a8..68abd456f 100644 --- 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 @@ -10,14 +10,21 @@ namespace Plugin _ui.setupUi(this); connect(_ui.connectButton, SIGNAL(clicked()), this, SLOT(ConnectButtonClicked())); connect(_ui.doneButton, SIGNAL(clicked()), this, SLOT(DoneButtonClicked())); - connect(_ui.cancelButton, SIGNAL(clicked()), this, SLOT(CancelButtonClicked())); + connect(_ui.cdToParrent, SIGNAL(clicked()), this, SLOT(cdToParent())); + connect(_ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject())); - // file list + // 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; } void CFtpSelection::ConnectButtonClicked() @@ -25,7 +32,9 @@ namespace Plugin 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); @@ -44,6 +53,9 @@ namespace Plugin void CFtpSelection::FtpCommandFinished(int, bool error) { + #ifndef QT_NO_CURSOR + setCursor(Qt::ArrowCursor); + #endif if (conn->currentCommand() == QFtp::ConnectToHost) { if (error) @@ -64,6 +76,20 @@ namespace Plugin 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()) { @@ -82,7 +108,7 @@ namespace Plugin item->setText(3, urlInfo.group()); item->setText(4, urlInfo.lastModified().toString("MMM dd yyyy")); - QPixmap pixmap(urlInfo.isDir() ? ":/images/dir.png" : ":/images/file.png"); + QPixmap pixmap(urlInfo.isDir() ? ":/translationManager/images/dir.png" : ":/translationManager/images/file.png"); item->setIcon(0, pixmap); isDirectory[urlInfo.name()] = urlInfo.isDir(); @@ -104,18 +130,58 @@ namespace Plugin currentPath += name; conn->cd(name); conn->list(); - //TODO: cursor + #ifndef QT_NO_CURSOR + setCursor(Qt::WaitCursor); + #endif return; - } + } + _ui.doneButton->setEnabled(true); } - + + 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(); + } + 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(); } - void CFtpSelection::CancelButtonClicked() - { - - } } 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 index 195abfc85..64ea136c4 100644 --- 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 @@ -9,11 +9,12 @@ #define FTP_SELECTION_H #include +#include #include #include #include +#include #include -#include #include "ui_ftp_selection.h" @@ -30,13 +31,15 @@ namespace Plugin { QHash isDirectory; QString currentPath; private Q_SLOTS: + void cdToParent(); void processItem(QTreeWidgetItem*,int); - void CancelButtonClicked(); void ConnectButtonClicked(); void DoneButtonClicked(); void FtpCommandFinished(int, bool error); void AddToList(const QUrlInfo &urlInfo); public: + bool status; + QFile *file; CFtpSelection(QWidget* parent = 0); ~CFtpSelection() {} }; 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 index c23a7137b..b8b0bf447 100644 --- 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 @@ -6,8 +6,8 @@ 0 0 - 383 - 547 + 388 + 560 @@ -19,7 +19,7 @@ 10 10 371 - 501 + 541 @@ -28,10 +28,10 @@ - 0 + 10 130 - 371 - 411 + 351 + 361 @@ -40,7 +40,7 @@ - 0 + 10 20 141 21 @@ -53,9 +53,9 @@ - 0 + 10 40 - 361 + 331 311 @@ -69,10 +69,10 @@ - 1 + 11 29 - 361 - 107 + 351 + 101 @@ -98,38 +98,44 @@ + + + :/translationManager/images/cdtoparent.png:/translationManager/images/cdtoparent.png + + + + + + + + + 0 + 500 + 371 + 33 + + + + + + + Done + + + + + + + Cancel + - - - - 10 - 500 - 361 - 33 - - - - - - - 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 0000000000000000000000000000000000000000..24b618082900a68c531862777d8b95d6e55d4e7f GIT binary patch literal 139 zcmeAS@N?(olHy`uVBq!ia0vp^{2(?58;~rMGjRk`oCO|{#X#BvjNMLV+W{H2o-U3d z8t0P}92)*d7z94}|Npn+a literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..0ce5ae75fcfd96151c964bf48165b31556295312 GIT binary patch literal 154 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#X#BvjNMLV+W{Fqo-U3d z7QM*{5+(`H&dmIO(a>|&`8k%K|NpON6PcyqT#)Hz#Tve vk7T)V%?=a~xXSt@VFzQthxtA}mJAF%>wkJ2U`u`rG?&5C)z4*}Q$iB}ZY?ls literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..be6c53089ab9e9eba8477b56acbf44df81220934 GIT binary patch literal 129 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6I14-?i-EKU7`vU!wgWPZJzX3_ zG|nd{D6qWxpX_A9`Xa%8l~4}XKV|KMAqN options); + QListWidgetItem *selected_item; }; } 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 index bb4fa27d1..52e423156 100644 --- 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 @@ -380,7 +380,26 @@ 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(QString(editor_window->widget()->metaObject()->className()) != "QTableWidget") // 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"); @@ -392,40 +411,44 @@ void CMainWindow::mergeSingleFile() dialog->setSourceOptions(methods); dialog->show(); dialog->exec(); + // get the file for merge if(dialog->selected_item == local_item) // Local directory { - QString file_name; - if (_ui.mdiArea->subWindowList().size() > 0) - { - file_name = QFileDialog::getOpenFileName(this); - } else { - return; - } - - if(QString(editor_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor - { - 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(QString("The file: %1 has different columns from the current file in editor.").arg(file_name)); - error.exec(); - } - } + file_name = QFileDialog::getOpenFileName(this); } else if(dialog->selected_item == ftp_item) { // Ftp directory CFtpSelection* ftp_dialog = new CFtpSelection(this); ftp_dialog->show(); ftp_dialog->exec(); + if(ftp_dialog->status == true) + { + file_name = ftp_dialog->file->fileName(); + } } else { 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(QString("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(QString("Please remove the file from ftp server manually. The file is located on the same directory with OVQT application.")); + error.exec(); + } + + } } void CMainWindow::readSettings() 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 index 63a8934d7..bd21f698d 100644 --- 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 @@ -70,7 +70,7 @@ private: QMenu *windowMenu; QSignalMapper *windowMapper; // config - map initialize_settings; + QMap initialize_settings; QList filters; QList languages; QString level_design_path; From 6fb8d197cf1ecb24c914d4e406aabffa948c3eb1 Mon Sep 17 00:00:00 2001 From: cemycc Date: Wed, 27 Jul 2011 01:01:00 +0300 Subject: [PATCH 22/34] Changed: #1307 Added the base files for phrase editor and new method to save the editor type --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/CMakeLists.txt | 1 + .../translation_manager/editor_phrase.cpp.txt | 53 ++++++++++++++++++ .../translation_manager/editor_phrase.h.txt | 48 ++++++++++++++++ .../translation_manager/editor_worksheet.cpp | 1 + .../translation_manager_constants.h | 3 + .../translation_manager_editor.h | 6 +- .../translation_manager_main_window.cpp | 56 +++++++++++++------ 7 files changed, 150 insertions(+), 18 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp.txt create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h.txt diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt index 7e7da7e99..0f520c9d8 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt @@ -16,6 +16,7 @@ SET(OVQT_PLUG_TRANSLATION_MANAGER_HDR translation_manager_plugin.h source_selection.h ftp_selection.h editor_worksheet.h + editor_phrase.h extract_new_sheet_names.h extract_bot_names.h) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp.txt new file mode 100644 index 000000000..83d360d8a --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp.txt @@ -0,0 +1,53 @@ +// 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 + +// Project includes +#include "editor_phrase.h" +#include "translation_manager_constants.h" + +using namespace std; + +namespace Plugin { + +void CEditorPhrase::open(QString filename) +{ + +} + +void CEditorPhrase::activateWindow() +{ + +} + +void CEditorPhrase::save() +{ + +} + +void CEditorPhrase::saveAs(QString filename) +{ + +} + + +} \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h.txt new file mode 100644 index 000000000..539314eaf --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h.txt @@ -0,0 +1,48 @@ +// 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 + +// Project includes +#include "translation_manager_editor.h" + +namespace Plugin { + +class CEditorPhrase : public CEditor +{ + Q_OBJECT +public: + CEditorPhrase(QMdiArea* parent) : CEditor(parent) {} + CEditorPhrase() : CEditor() {} + void open(QString filename); + void save(); + void saveAs(QString filename); + void activateWindow(); +}; + +} + +#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 index 5323ded1a..2c7261805 100644 --- 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 @@ -93,6 +93,7 @@ void CEditorWorksheet::open(QString filename) setCurrentFile(filename); setAttribute(Qt::WA_DeleteOnClose); setWidget(table_editor); + editor_type = Constants::ED_SHEET; table_editor->resizeColumnsToContents(); table_editor->resizeRowsToContents(); // set editor signals 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 index b6bdc8315..3cb66181b 100644 --- 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 @@ -12,6 +12,9 @@ namespace Plugin { 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"; 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 index ff947b1d1..767dd90de 100644 --- 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 @@ -31,7 +31,7 @@ Q_OBJECT protected: QUndoStack* current_stack; QString current_file; - int editor_type; + int editor_type; public: CEditor(QMdiArea* parent) : QMdiSubWindow(parent) {} CEditor() : QMdiSubWindow() {} @@ -40,6 +40,10 @@ public: virtual void saveAs(QString filename) =0; virtual void activateWindow() =0; public: + int eType() + { + return editor_type; + } QString subWindowFilePath() { return current_file; 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 index 52e423156..e6fa9508a 100644 --- 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 @@ -206,6 +206,10 @@ void CMainWindow::open() 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); @@ -213,6 +217,9 @@ void CMainWindow::open() new_window->open(file_name); new_window->activateWindow(); } + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif } } @@ -241,11 +248,13 @@ void CMainWindow::save() if(_ui.mdiArea->subWindowList().size() > 0) { CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - - if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor - { - current_window->save(); - } + #ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); + #endif + current_window->save(); + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif } } @@ -258,13 +267,15 @@ void CMainWindow::saveAs() } if (!file_name.isEmpty()) - { - CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor - { - current_window->saveAs(file_name); - } - + { + 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 } } @@ -341,14 +352,19 @@ void CMainWindow::extractWords(QString typeq) 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 } } @@ -371,8 +387,14 @@ void CMainWindow::extractBotNames() 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); + editor_window->extractBotNames(convertQStringList(filters), level_design_path.toStdString(), ligoConfig); + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif } } @@ -392,7 +414,7 @@ void CMainWindow::mergeSingleFile() return; } - if(QString(editor_window->widget()->metaObject()->className()) != "QTableWidget") // Sheet Editor + if(editor_window->eType() != Constants::ED_SHEET) // Sheet Editor { QErrorMessage error; error.showMessage(QString("Please open or activate the window with a sheet file.")); @@ -500,7 +522,7 @@ CEditorWorksheet *CMainWindow::getEditorByWorksheetType(const QString &type) Q_FOREACH(QMdiSubWindow *subWindow, _ui.mdiArea->subWindowList()) { CEditor *currentEditor = qobject_cast(subWindow); - if(QString(currentEditor->widget()->metaObject()->className()) == "QTableWidget") + if(currentEditor->eType() == Constants::ED_SHEET) { CEditorWorksheet *editor = qobject_cast(currentEditor); if(type != NULL) { From 23f1309995a522e870c448cfa3acb2f1bad337fe Mon Sep 17 00:00:00 2001 From: cemycc Date: Wed, 3 Aug 2011 23:08:56 +0300 Subject: [PATCH 23/34] Changed: #1307 Added Phrase editor files and base functions --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/editor_phrase.cpp | 116 ++++++++++++++++++ .../translation_manager/editor_phrase.cpp.txt | 53 -------- .../{editor_phrase.h.txt => editor_phrase.h} | 6 + .../translation_manager/editor_worksheet.cpp | 10 +- .../translation_manager/editor_worksheet.h | 2 - .../translation_manager_editor.h | 10 ++ .../translation_manager_main_window.cpp | 24 +++- .../translation_manager_main_window.h | 3 +- 8 files changed, 158 insertions(+), 66 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp delete mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp.txt rename code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/{editor_phrase.h.txt => editor_phrase.h} (86%) 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..4036f8425 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp @@ -0,0 +1,116 @@ +// 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 + +// Project includes +#include "editor_phrase.h" +#include "translation_manager_constants.h" + +using namespace std; + +namespace Plugin { + +void CEditorPhrase::open(QString filename) +{ + vector phrases; + if(readPhraseFile(filename.toStdString(), phrases, false)) + { + text_edit = new QTextEdit(); + // read the file content + QFile file(filename); + QTextStream in(&file); + // set the file content to the text edit + QString content = in.readAll(); + text_edit->setText(content); + // window settings + setCurrentFile(filename); + setAttribute(Qt::WA_DeleteOnClose); + setWidget(text_edit); + editor_type = Constants::ED_PHRASE; + current_file = filename; + } else { + QErrorMessage error; + error.showMessage("This file is not a phrase file."); + error.exec(); + } +} + +void CEditorPhrase::activateWindow() +{ + showMaximized(); +} + +void CEditorPhrase::save() +{ + QFile file(current_file); + QTextStream out(&file); + out<toPlainText(); + setCurrentFile(current_file); +} + +void CEditorPhrase::saveAs(QString filename) +{ + QFile file(filename); + QTextStream out(&file); + 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.cpp.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp.txt deleted file mode 100644 index 83d360d8a..000000000 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp.txt +++ /dev/null @@ -1,53 +0,0 @@ -// 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 - -// Project includes -#include "editor_phrase.h" -#include "translation_manager_constants.h" - -using namespace std; - -namespace Plugin { - -void CEditorPhrase::open(QString filename) -{ - -} - -void CEditorPhrase::activateWindow() -{ - -} - -void CEditorPhrase::save() -{ - -} - -void CEditorPhrase::saveAs(QString filename) -{ - -} - - -} \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h similarity index 86% rename from code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h.txt rename to code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h index 539314eaf..21152ad16 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.h @@ -20,11 +20,14 @@ // Qt includes #include +#include +#include #include #include #include #include #include +#include // Project includes #include "translation_manager_editor.h" @@ -34,6 +37,8 @@ namespace Plugin { class CEditorPhrase : public CEditor { Q_OBJECT +private: + QTextEdit *text_edit; public: CEditorPhrase(QMdiArea* parent) : CEditor(parent) {} CEditorPhrase() : CEditor() {} @@ -41,6 +46,7 @@ public: void save(); void saveAs(QString filename); void activateWindow(); + void closeEvent(QCloseEvent *event); }; } 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 index 2c7261805..39b86d76a 100644 --- 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 @@ -202,6 +202,7 @@ void CEditorWorksheet::saveAs(QString filename) } ucstring s = prepareExcelSheet(new_file); NLMISC::CI18N::writeTextFile(filename.toStdString(), s, false); + current_file = filename; setCurrentFile(filename); } @@ -484,15 +485,6 @@ void CEditorWorksheet::mergeWorksheetFile(QString filename) } } -void CEditorWorksheet::setCurrentFile(QString filename) -{ - QFileInfo *file = new QFileInfo(filename); - current_file = file->canonicalFilePath(); - setWindowModified(false); - setWindowTitle(file->fileName() + "[*]"); - setWindowFilePath(current_file); -} - void CEditorWorksheet::closeEvent(QCloseEvent *event) { if(isWindowModified()) 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 index 983dba4bc..a124188bc 100644 --- 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 @@ -65,8 +65,6 @@ private Q_SLOTS: void worksheetEditorChanged(QTableWidgetItem * item); void insertRow(); void deleteRow(); -private: - void setCurrentFile(QString filename); }; 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 index 767dd90de..39ef74f2a 100644 --- 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 @@ -23,6 +23,7 @@ #include #include #include +#include namespace Plugin { @@ -52,6 +53,15 @@ public: { current_stack = stack; } + void setCurrentFile(QString filename) + { + QFileInfo *file = new QFileInfo(filename); + current_file = file->canonicalFilePath(); + setWindowModified(false); + setWindowTitle(file->fileName() + "[*]"); + setWindowFilePath(current_file); + } + }; } 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 index e6fa9508a..f12c6a830 100644 --- 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 @@ -217,6 +217,14 @@ void CMainWindow::open() 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 @@ -559,12 +567,26 @@ bool CMainWindow::isWorksheetEditor(QString filename) STRING_MANAGER::TWorksheet wk_file; if(loadExcelSheet(filename.toStdString(), wk_file, true) == true) { - return true; + if(wk_file.ColCount > 1) + return true; + else + return false; } else { return false; } } +bool CMainWindow::isPhraseEditor(QString filename) +{ + vector phrases; + if(readPhraseFile(filename.toStdString(), phrases, false)) + { + return true; + } else { + return false; + } +} + bool CCoreListener::closeMainWindow() const { return true; 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 index bd21f698d..c58ce9826 100644 --- 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 @@ -45,6 +45,7 @@ #include "ui_translation_manager_main_window.h" #include #include "editor_worksheet.h" +#include "editor_phrase.h" class QWidget; @@ -101,7 +102,7 @@ private: // Worksheet specific functions CEditorWorksheet* getEditorByWorksheetType(const QString &type); bool isWorksheetEditor(QString filename); - + bool isPhraseEditor(QString filename); }; From 44804ea77038136fe074ee6c53ff2b517b9ca372 Mon Sep 17 00:00:00 2001 From: cemycc Date: Thu, 4 Aug 2011 17:19:17 +0300 Subject: [PATCH 24/34] Changed: #1307 Added some features and making little modifications --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/editor_phrase.cpp | 62 +- .../translation_manager/editor_worksheet.cpp | 1145 +++++++++-------- .../translation_manager/editor_worksheet.h | 2 + .../translation_manager_main_window.cpp | 57 +- .../translation_manager_main_window.h | 16 +- .../translation_manager_plugin.cpp | 8 +- .../translation_manager_plugin.h | 4 +- 7 files changed, 681 insertions(+), 613 deletions(-) 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 index 4036f8425..b202b1cbb 100644 --- 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 @@ -80,37 +80,37 @@ void CEditorPhrase::saveAs(QString 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(); - } +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_worksheet.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp index 39b86d76a..a6ef28d36 100644 --- 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 @@ -1,562 +1,583 @@ -// 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 - -// Project includes -#include "editor_worksheet.h" -#include "extract_bot_names.h" -#include "translation_manager_constants.h" -#include - -using namespace std; - -namespace Plugin { - - - -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(tr(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(tr(row_value.toString().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*))); - } else { - QErrorMessage error; - error.showMessage("This file is not a worksheet file."); - error.exec(); - } - -} - -void CEditorWorksheet::activateWindow() -{ - showMaximized(); -} - -void CEditorWorksheet::save() -{ - STRING_MANAGER::TWorksheet wk_file; - loadExcelSheet(current_file.toStdString(), wk_file, true); - 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++) - { - // maybe extra rows ? - if((unsigned)table_editor->rowCount() > (wk_file.size() - 1)) - { - rowIdx = wk_file.size(); - wk_file.resize(rowIdx + table_editor->rowCount() - wk_file.size() + 1); - } - for(int j = 0; j < table_editor->columnCount(); j++) - { - ucstring tvalue; - ucstring colname; - uint rowIdf; - QString tvalueQt = table_editor->item(i, j)->text(); - tvalue = ucstring(tvalueQt.toStdString()); - colname = wk_file.getData(0, j + colIdx); - - rowIdf = uint(i + 1); - if(wk_file.findRow(j + colIdx, colname, rowIdf)) // search for the row - { - if(wk_file.getData(i + 1, j + colIdx) != tvalue) // verify the current value - { - wk_file.setData(i + 1, j + colIdx, tvalue); // change the value - } - } else { - wk_file.setData(i + 1, j + colIdx, tvalue); // insert the value - } - } - } - if(hasHashValue) - { - // rewrite the hash codes - makeHashCode(wk_file, true); - } - // write to file - ucstring s = prepareExcelSheet(wk_file); - NLMISC::CI18N::writeTextFile(current_file.toStdString(), s, false); - setCurrentFile(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); - for(int j = 0; j < table_editor->columnCount(); j++) - { - QTableWidgetItem* item = table_editor->item(i, j); - new_file.setData(rowIdx, j + colIdx, ucstring(item->text().toStdString())); - } - } - 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("The row will be deleted."); - msgBox.setInformativeText("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(tr(it->first.c_str()), Qt::MatchExactly); - if(search_results.size() == 0) - { - const int currentRow = table_editor->rowCount(); - table_editor->setRowCount(currentRow + 1); - QTableWidgetItem *bot_name_row = new QTableWidgetItem(); - bot_name_row->setText(tr(it->first.c_str())); - bot_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 0, bot_name_row); - QTableWidgetItem *translation_name_row = new QTableWidgetItem(); - translation_name_row->setBackgroundColor(QColor("#F75D59")); - translation_name_row->setText(tr(it->first.c_str())); - table_editor ->setItem(currentRow , 1, translation_name_row); - QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); - sheet_name_row->setText(tr(it->second.SheetName.c_str())); - sheet_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 2, sheet_name_row); - if(!modified) modified = true; - CTableWidgetItemStore bot_name_row_s(bot_name_row, currentRow, 0); - new_items.push_back(bot_name_row_s); - CTableWidgetItemStore translation_name_row_s(translation_name_row, currentRow, 1); - new_items.push_back(translation_name_row_s); - CTableWidgetItemStore sheet_name_row_s(sheet_name_row, currentRow, 2); - new_items.push_back(sheet_name_row_s); - } - } - 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(tr((*it).c_str()), Qt::MatchExactly); - if(search_results.size() == 0) - { - const int currentRow = table_editor->rowCount(); - table_editor->setRowCount(currentRow + 1); - QTableWidgetItem *bot_name_row = new QTableWidgetItem(); - bot_name_row->setText(tr((*it).c_str())); - bot_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 0, bot_name_row); - QTableWidgetItem *translation_name_row = new QTableWidgetItem(); - translation_name_row->setBackgroundColor(QColor("#F75D59")); - translation_name_row->setText(tr(gnName.c_str())); - table_editor ->setItem(currentRow , 1, translation_name_row); - QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); - sheet_name_row->setText(" "); - sheet_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 2, sheet_name_row); - if(!modified) modified = true; - CTableWidgetItemStore bot_name_row_s(bot_name_row, currentRow, 0); - new_items.push_back(bot_name_row_s); - CTableWidgetItemStore translation_name_row_s(translation_name_row, currentRow, 1); - new_items.push_back(translation_name_row_s); - CTableWidgetItemStore sheet_name_row_s(sheet_name_row, currentRow, 2); - new_items.push_back(sheet_name_row_s); - } - } - ebn.cleanGenericNames(); - } - - current_stack->push(new CUndoWorksheetExtraction(new_items, table_editor)); - if(modified) - { - setWindowModified(true); - } - -} - -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(tr(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; - } - const int currentRow = table_editor->rowCount(); - table_editor->setRowCount(currentRow + 1); - // keyName row - QTableWidgetItem *key_name_row = new QTableWidgetItem(); - key_name_row->setText(tr(keyName.c_str())); - key_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, knPos, key_name_row); - // nameColumn key - QTableWidgetItem *name_row = new QTableWidgetItem(); - name_row->setText(QString("") + tr(keyName.c_str())); - name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, nPos, name_row); - if(!modified) modified = true; - CTableWidgetItemStore key_name_row_s(key_name_row, currentRow, knPos); - new_items.push_back(key_name_row_s); - CTableWidgetItemStore name_row_s(name_row, currentRow, nPos); - new_items.push_back(name_row_s); - - } - } - current_stack->push(new CUndoWorksheetExtraction(new_items, table_editor)); - if(modified) - { - setWindowModified(true); - table_editor->scrollToBottom(); - } -} - -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(tr(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("This file is not a worksheet file."); - error.exec(); - } -} - -void CEditorWorksheet::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(); - } -} - - -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; -} - -} - - +// 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 Plugin { + + + +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(tr(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(tr(row_value.toString().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() +{ + STRING_MANAGER::TWorksheet wk_file; + loadExcelSheet(current_file.toStdString(), wk_file, true); + 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++) + { + // maybe extra rows ? + if((unsigned)table_editor->rowCount() > (wk_file.size() - 1)) + { + rowIdx = wk_file.size(); + wk_file.resize(rowIdx + table_editor->rowCount() - wk_file.size() + 1); + } + for(int j = 0; j < table_editor->columnCount(); j++) + { + ucstring tvalue; + ucstring colname; + uint rowIdf; + QString tvalueQt = table_editor->item(i, j)->text(); + tvalue = ucstring(tvalueQt.toStdString()); + colname = wk_file.getData(0, j + colIdx); + + rowIdf = uint(i + 1); + if(wk_file.findRow(j + colIdx, colname, rowIdf)) // search for the row + { + if(wk_file.getData(i + 1, j + colIdx) != tvalue) // verify the current value + { + wk_file.setData(i + 1, j + colIdx, tvalue); // change the value + } + } else { + wk_file.setData(i + 1, j + colIdx, tvalue); // insert the value + } + } + } + if(hasHashValue) + { + // rewrite the hash codes + makeHashCode(wk_file, true); + } + // write to file + ucstring s = prepareExcelSheet(wk_file); + NLMISC::CI18N::writeTextFile(current_file.toStdString(), s, false); + setCurrentFile(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); + for(int j = 0; j < table_editor->columnCount(); j++) + { + QTableWidgetItem* item = table_editor->item(i, j); + new_file.setData(rowIdx, j + colIdx, ucstring(item->text().toStdString())); + } + } + 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("The row will be deleted."); + msgBox.setInformativeText("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(tr(it->first.c_str()), Qt::MatchExactly); + if(search_results.size() == 0) + { + const int currentRow = table_editor->rowCount(); + table_editor->setRowCount(currentRow + 1); + QTableWidgetItem *bot_name_row = new QTableWidgetItem(); + bot_name_row->setText(tr(it->first.c_str())); + bot_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, 0, bot_name_row); + QTableWidgetItem *translation_name_row = new QTableWidgetItem(); + translation_name_row->setBackgroundColor(QColor("#F75D59")); + translation_name_row->setText(tr(it->first.c_str())); + table_editor ->setItem(currentRow , 1, translation_name_row); + QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); + sheet_name_row->setText(tr(it->second.SheetName.c_str())); + sheet_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, 2, sheet_name_row); + if(!modified) modified = true; + CTableWidgetItemStore bot_name_row_s(bot_name_row, currentRow, 0); + new_items.push_back(bot_name_row_s); + CTableWidgetItemStore translation_name_row_s(translation_name_row, currentRow, 1); + new_items.push_back(translation_name_row_s); + CTableWidgetItemStore sheet_name_row_s(sheet_name_row, currentRow, 2); + new_items.push_back(sheet_name_row_s); + } + } + 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(tr((*it).c_str()), Qt::MatchExactly); + if(search_results.size() == 0) + { + const int currentRow = table_editor->rowCount(); + table_editor->setRowCount(currentRow + 1); + QTableWidgetItem *bot_name_row = new QTableWidgetItem(); + bot_name_row->setText(tr((*it).c_str())); + bot_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, 0, bot_name_row); + QTableWidgetItem *translation_name_row = new QTableWidgetItem(); + translation_name_row->setBackgroundColor(QColor("#F75D59")); + translation_name_row->setText(tr(gnName.c_str())); + table_editor ->setItem(currentRow , 1, translation_name_row); + QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); + sheet_name_row->setText(" "); + sheet_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, 2, sheet_name_row); + if(!modified) modified = true; + CTableWidgetItemStore bot_name_row_s(bot_name_row, currentRow, 0); + new_items.push_back(bot_name_row_s); + CTableWidgetItemStore translation_name_row_s(translation_name_row, currentRow, 1); + new_items.push_back(translation_name_row_s); + CTableWidgetItemStore sheet_name_row_s(sheet_name_row, currentRow, 2); + new_items.push_back(sheet_name_row_s); + } + } + 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(tr(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; + } + const int currentRow = table_editor->rowCount(); + table_editor->setRowCount(currentRow + 1); + // keyName row + QTableWidgetItem *key_name_row = new QTableWidgetItem(); + key_name_row->setText(tr(keyName.c_str())); + key_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, knPos, key_name_row); + // nameColumn key + QTableWidgetItem *name_row = new QTableWidgetItem(); + name_row->setText(QString("") + tr(keyName.c_str())); + name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, nPos, name_row); + if(!modified) modified = true; + CTableWidgetItemStore key_name_row_s(key_name_row, currentRow, knPos); + new_items.push_back(key_name_row_s); + CTableWidgetItemStore name_row_s(name_row, currentRow, nPos); + new_items.push_back(name_row_s); + + } + } + current_stack->push(new CUndoWorksheetExtraction(new_items, table_editor)); + if(modified) + { + setWindowModified(true); + table_editor->scrollToBottom(); + } +} + +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(tr(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("This file is not a worksheet file."); + error.exec(); + } +} + +void CEditorWorksheet::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(); + } +} + + +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 index a124188bc..0cb0602e2 100644 --- 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 @@ -65,6 +65,7 @@ private Q_SLOTS: void worksheetEditorChanged(QTableWidgetItem * item); void insertRow(); void deleteRow(); + void contextMenuEvent(QContextMenuEvent *e); }; @@ -123,6 +124,7 @@ public: { QTableWidgetItem* item = new QTableWidgetItem(); m_table->setItem(m_rowID, j, item); + m_table->scrollToBottom(); } } 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 index f12c6a830..47f6f95ea 100644 --- 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 @@ -1,3 +1,4 @@ + // Translation Manager Plugin - OVQT Plugin // Copyright (C) 2010 Winch Gate Property Limited // Copyright (C) 2011 Emanuel Costea @@ -123,16 +124,14 @@ void CMainWindow::createToolbar() mergeSingleFileAct->setStatusTip(tr("Merge worksheet file from local or remote directory")); connect(mergeSingleFileAct, SIGNAL(triggered()), this, SLOT(mergeSingleFile())); // Windows menu - windowMenu = new QMenu(tr("&Windows..."), _ui.toolBar); - windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL)); + Core::ICore *core = Core::ICore::instance(); + Core::IMenuManager *menuManager = core->menuManager(); + windowMenu = menuManager->menuBar()->addMenu("Window"); updateWindowsList(); - _ui.toolBar->addAction(windowMenu->menuAction()); connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowsList())); // Undo, Redo actions // ----------------------------- - Core::ICore *core = Core::ICore::instance(); - Core::IMenuManager *menuManager = core->menuManager(); QAction* undoAction = menuManager->action(Core::Constants::UNDO); if (undoAction != 0) _ui.toolBar->addAction(undoAction); @@ -147,10 +146,15 @@ void CMainWindow::updateToolbar(QMdiSubWindow *window) if(_ui.mdiArea->subWindowList().size() > 0) if(QString(window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor { - QAction *insertRowAct = windowMenu->addAction("Insert new row"); - connect(insertRowAct, SIGNAL(triggered()), window, SLOT(insertRow())); - QAction *deleteRowAct = windowMenu->addAction("Delete row"); + //setContextMenuPolicy(Qt::ActionsContextMenu); + QAction *insertRowAct = new QAction("Insert new row", this); + connect(insertRowAct, SIGNAL(triggered()), window, SLOT(insertRow())); + //addAction(insertRowAct); + windowMenu->addAction(insertRowAct); + QAction *deleteRowAct = new QAction("Delete row", this); connect(deleteRowAct, SIGNAL(triggered()), window, SLOT(deleteRow())); + //addAction(deleteRowAct); + windowMenu->addAction(deleteRowAct); } } @@ -167,7 +171,7 @@ void CMainWindow::setActiveSubWindow(QWidget* window) void CMainWindow::activeSubWindowChanged() { - //TODO: nothing to be done here atm + } void CMainWindow::updateWindowsList() @@ -187,10 +191,11 @@ void CMainWindow::updateWindowsList() } else { action_text = tr("%1 %2").arg(i + 1).arg(window_file); } - QAction *action = windowMenu->addAction(action_text); + QAction *action = new QAction(action_text, this); action->setCheckable(true); action->setChecked(subWindows.at(i) == current_window); - connect(action, SIGNAL(triggered()), windowMapper, SLOT(map())); + connect(action, SIGNAL(triggered()), windowMapper, SLOT(map())); + windowMenu->addAction(action); windowMapper->setMapping(action, subWindows.at(i)); } } @@ -589,7 +594,35 @@ bool CMainWindow::isPhraseEditor(QString filename) bool CCoreListener::closeMainWindow() const { - return 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(); + switch (ret) + { + case QMessageBox::Save: + currentEditor->save(); + return true; + break; + case QMessageBox::Discard: + return true; + break; + case QMessageBox::Cancel: + return false; + break; + default: + break; + } + } + + } } } /* namespace Plugin */ 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 index c58ce9826..dfc67d1f2 100644 --- 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 @@ -62,8 +62,9 @@ public: CMainWindow(QWidget *parent = 0); virtual ~CMainWindow() {} QUndoStack *m_undoStack; -private: - Ui::CMainWindow _ui; +public: + Ui::CMainWindow _ui; +private: // actions QAction *openAct; QAction *saveAct; @@ -111,13 +112,20 @@ class CCoreListener : public Core::ICoreListener { Q_OBJECT public: - CCoreListener(QObject *parent = 0): ICoreListener(parent) {} - virtual ~CCoreListener() {} + CCoreListener(CMainWindow* mainWindow, QObject *parent = 0): ICoreListener(parent) + { + m_MainWindow = mainWindow; + } + virtual ~CCoreListener() {} virtual bool closeMainWindow() const; + +public: + CMainWindow *m_MainWindow; }; + } // namespace Plugin diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp index caf677a0d..c98eed5be 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp @@ -53,10 +53,12 @@ bool TranslationManagerPlugin::initialize(ExtensionSystem::IPluginManager *plugi { Q_UNUSED(errorString); _plugMan = pluginManager; + // create the mainwindow + CMainWindow *mainWindow = new CMainWindow(); addAutoReleasedObject(new CTranslationManagerSettingsPage(this)); - addAutoReleasedObject(new CTranslationManagerContext(this)); - addAutoReleasedObject(new CCoreListener(this)); + addAutoReleasedObject(new CTranslationManagerContext(mainWindow, this)); + addAutoReleasedObject(new CCoreListener(mainWindow, this)); return true; } @@ -75,6 +77,8 @@ void TranslationManagerPlugin::extensionsInitialized() helpMenu->insertAction(aboutQtAction, aboutTManPlugin); } + + void TranslationManagerPlugin::setNelContext(NLMISC::INelContext *nelContext) { #ifdef NL_OS_WINDOWS diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h index ed42b4882..8c91d64cd 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h @@ -82,9 +82,9 @@ class CTranslationManagerContext: public Core::IContext { Q_OBJECT public: - CTranslationManagerContext(QObject *parent = 0): IContext(parent) + CTranslationManagerContext(CMainWindow* mainWindow, QObject *parent = 0): IContext(parent) { - m_MainWindow = new CMainWindow(); + m_MainWindow = mainWindow; } virtual ~CTranslationManagerContext() {} From 2cd15276560bf62cfb97e92840768cf55e7a943a Mon Sep 17 00:00:00 2001 From: cemycc Date: Tue, 9 Aug 2011 01:55:46 +0300 Subject: [PATCH 25/34] Changed: #1307 Added undo/redo for editor and a little syntaxhighliter --HG-- branch : gsoc2011-translationovqt --- .../src/plugins/CMakeLists.txt | 5 +- .../src/plugins/core/core_constants.h | 3 +- .../translation_manager/editor_phrase.cpp | 38 +++- .../translation_manager/editor_phrase.h | 178 +++++++++++++++++- .../translation_manager_main_window.cpp | 53 ++++-- .../translation_manager_main_window.h | 1 + 6 files changed, 248 insertions(+), 30 deletions(-) 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 99df2d874..6db50dac3 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 @@ -7,11 +7,8 @@ ADD_SUBDIRECTORY(disp_sheet_id) ADD_SUBDIRECTORY(object_viewer) ADD_SUBDIRECTORY(zone_painter) ADD_SUBDIRECTORY(georges_editor) -<<<<<<< local ADD_SUBDIRECTORY(translation_manager) -======= - # Ryzom Specific Plugins IF(WITH_RYZOM AND WITH_RYZOM_TOOLS) ADD_SUBDIRECTORY(mission_compiler) -ENDIF(WITH_RYZOM AND WITH_RYZOM_TOOLS)>>>>>>> other +ENDIF(WITH_RYZOM AND WITH_RYZOM_TOOLS) 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 389b9a9fa..cfe6b7e80 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,9 +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 PRIMITIVES_PATH = "D:/Ryzom/ryzom/code/ryzom/common/data_leveldesign/primitives"; -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/translation_manager/editor_phrase.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp index b202b1cbb..2e5a576ab 100644 --- 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 @@ -24,6 +24,10 @@ #include #include #include +#include +#include +#include + // Project includes #include "editor_phrase.h" @@ -38,19 +42,24 @@ void CEditorPhrase::open(QString filename) vector phrases; if(readPhraseFile(filename.toStdString(), phrases, false)) { - text_edit = new QTextEdit(); + text_edit = new QTextEdit(this); + 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); - QTextStream in(&file); - // set the file content to the text edit - QString content = in.readAll(); - text_edit->setText(content); + file.open(QIODevice::ReadOnly | QIODevice::Text); + // set the file content to the text edit + QByteArray data = file.readAll(); + text_edit->append(data); // window settings setCurrentFile(filename); setAttribute(Qt::WA_DeleteOnClose); - setWidget(text_edit); editor_type = Constants::ED_PHRASE; current_file = filename; + connect(text_edit->document(), SIGNAL(contentsChange(int, int, int)), this, SLOT(contentsChangeNow(int position, int charsRemoved, int charsAdded))); + connect(text_edit->document(), SIGNAL(contentsChanged()), this, SLOT(docContentsChanged())); } else { QErrorMessage error; error.showMessage("This file is not a phrase file."); @@ -58,6 +67,19 @@ void CEditorPhrase::open(QString filename) } } +void CEditorPhrase::contentsChangeNow(int position, int charsRemoved, int charsAdded) +{ + if(charsRemoved > 0) + current_stack->push(new CUndoPhraseRemoveCommand(position-charsRemoved, charsRemoved, text_edit)); + else if(charsAdded > 0) + current_stack->push(new CUndoPhraseInsertCommand(position, text_edit->toPlainText().right(charsAdded), text_edit)); +} + +void CEditorPhrase::docContentsChanged() +{ + setWindowModified(true); +} + void CEditorPhrase::activateWindow() { showMaximized(); @@ -66,6 +88,7 @@ void CEditorPhrase::activateWindow() void CEditorPhrase::save() { QFile file(current_file); + file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); out<toPlainText(); setCurrentFile(current_file); @@ -74,12 +97,15 @@ void CEditorPhrase::save() void CEditorPhrase::saveAs(QString filename) { QFile file(filename); + file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); out<toPlainText(); current_file = filename; setCurrentFile(current_file); } + + void CEditorPhrase::closeEvent(QCloseEvent *event) { if(isWindowModified()) 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 index 21152ad16..c792d0b21 100644 --- 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 @@ -28,6 +28,7 @@ #include #include #include +#include // Project includes #include "translation_manager_editor.h" @@ -37,7 +38,7 @@ namespace Plugin { class CEditorPhrase : public CEditor { Q_OBJECT -private: +public: QTextEdit *text_edit; public: CEditorPhrase(QMdiArea* parent) : CEditor(parent) {} @@ -47,6 +48,181 @@ public: void saveAs(QString filename); void activateWindow(); void closeEvent(QCloseEvent *event); +public Q_SLOTS: + void contentsChangeNow(int, int, int); + void docContentsChanged(); + +}; + +class CUndoPhraseInsertCommand : public QUndoCommand +{ +public: + CUndoPhraseInsertCommand(int index, const QString &chars, QTextEdit *document, QUndoCommand *parent = 0) : QUndoCommand("Insert characters", parent), + m_index(index), + m_chars(chars), + m_document(document) + { } + + virtual void redo() + { + QString text = m_document->toPlainText(); + text.insert(m_index, m_chars); + m_document->clear(); + m_document->setPlainText(text); + } + + virtual void undo() + { + QString text = m_document->toPlainText(); + text.remove(m_index, m_chars.length()); + m_document->clear(); + m_document->setPlainText(text); + m_document->undo(); + } + +private: + int m_index; + QString m_chars; + QTextEdit* m_document; + +}; + +class CUndoPhraseRemoveCommand : public QUndoCommand +{ +public: + CUndoPhraseRemoveCommand(int index, int count, QTextEdit *document, QUndoCommand *parent = 0) : QUndoCommand("Remove characters", parent), + m_index(index), + m_count(count), + m_document(document) + { } + + virtual void redo() + { + QString text = m_document->toPlainText(); + m_removedChars = text.mid(m_index, m_count); + text.remove(m_index, m_count); + m_document->clear(); + m_document->setPlainText(text); + } + + virtual void undo() + { + QString text = m_document->toPlainText(); + text.insert(m_index, m_removedChars); + m_document->clear(); + m_document->setPlainText(text); + } +private: + int m_index; + int m_count; + QString m_removedChars; + QTextEdit* m_document; + +}; + +class SyntaxHighlighter : public QSyntaxHighlighter +{ +public: + SyntaxHighlighter(QTextEdit *parent) : QSyntaxHighlighter(parent) + { + HighlightingRule rule; + + keywordFormat.setForeground(Qt::darkBlue); + keywordFormat.setFontWeight(QFont::Bold); + QStringList keywordPatterns; + keywordPatterns << "\\bchar\\b" << "\\bclass\\b" << "\\bconst\\b" + << "\\bdouble\\b" << "\\benum\\b" << "\\bexplicit\\b" + << "\\bfriend\\b" << "\\binline\\b" << "\\bint\\b" + << "\\blong\\b" << "\\bnamespace\\b" << "\\boperator\\b" + << "\\bprivate\\b" << "\\bprotected\\b" << "\\bpublic\\b" + << "\\bshort\\b" << "\\bsignals\\b" << "\\bsigned\\b" + << "\\bslots\\b" << "\\bstatic\\b" << "\\bstruct\\b" + << "\\btemplate\\b" << "\\btypedef\\b" << "\\btypename\\b" + << "\\bunion\\b" << "\\bunsigned\\b" << "\\bvirtual\\b" + << "\\bvoid\\b" << "\\bvolatile\\b"; + Q_FOREACH(const QString &pattern, keywordPatterns) { + rule.pattern = QRegExp(pattern); + rule.format = keywordFormat; + highlightingRules.append(rule); + } + + classFormat.setFontWeight(QFont::Bold); + classFormat.setForeground(Qt::darkMagenta); + rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b"); + rule.format = classFormat; + 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("\\b[A-Za-z0-9_]+(?=\\()"); + 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; }; } 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 index 47f6f95ea..efa7743cd 100644 --- 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 @@ -221,7 +221,7 @@ void CMainWindow::open() new_window->setUndoStack(m_undoStack); new_window->open(file_name); new_window->activateWindow(); - } + } // phrase editor if(isPhraseEditor(file_name)) { @@ -592,8 +592,33 @@ bool CMainWindow::isPhraseEditor(QString filename) } } +/* void CMainWindow::keyPressEvent(QKeyEvent *event) +{ + CEditorPhrase* editor = qobject_cast(_ui.mdiArea->currentSubWindow()); + + QString chars = event->text(); + int index = editor->text_edit->textCursor().position(); + + switch (event->key()) + { + case Qt::Key_Backspace: + if (index > 0) + m_undoStack->push(new CUndoPhraseRemoveCommand(index--, 1, editor->text_edit)); + break; + case Qt::Key_Delete: + if (index < editor->text_edit->toPlainText().length()) + m_undoStack->push(new CUndoPhraseRemoveCommand(index, 1, editor->text_edit)); + break; + default: + if (!chars.isEmpty()) + m_undoStack->push(new CUndoPhraseInsertCommand(index, chars, editor->text_edit)); + break; + } +} */ + bool CCoreListener::closeMainWindow() const { + bool okToClose = true; Q_FOREACH(QMdiSubWindow *subWindow, m_MainWindow->_ui.mdiArea->subWindowList()) { CEditor *currentEditor = qobject_cast(subWindow); @@ -605,24 +630,18 @@ bool CCoreListener::closeMainWindow() const msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Save); int ret = msgBox.exec(); - switch (ret) - { - case QMessageBox::Save: - currentEditor->save(); - return true; - break; - case QMessageBox::Discard: - return true; - break; - case QMessageBox::Cancel: - return false; - break; - default: - break; - } + if(ret == QMessageBox::Save) + { + currentEditor->save(); + } + else if(ret == QMessageBox::Cancel) + { + okToClose = false; + break; + } } - } + return okToClose; } } /* namespace Plugin */ 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 index dfc67d1f2..02146a9dd 100644 --- 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 @@ -104,6 +104,7 @@ private: CEditorWorksheet* getEditorByWorksheetType(const QString &type); bool isWorksheetEditor(QString filename); bool isPhraseEditor(QString filename); + }; From a983374b2ab609a42d991512ae80a9d4889c58ce Mon Sep 17 00:00:00 2001 From: cemycc Date: Thu, 11 Aug 2011 19:16:46 +0300 Subject: [PATCH 26/34] Changed: #1307 Added tab view on QMdiArea, new syntax highliter and added base functions for Undo/Redo framework --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/editor_phrase.cpp | 33 ++++++++---- .../translation_manager/editor_phrase.h | 52 +++++++++---------- .../translation_manager/editor_worksheet.cpp | 2 +- .../translation_manager/editor_worksheet.h | 2 +- .../translation_manager/extract_bot_names.cpp | 2 +- .../translation_manager/extract_bot_names.h | 2 +- .../extract_new_sheet_names.cpp | 3 +- .../extract_new_sheet_names.h | 3 +- .../translation_manager/ftp_selection.cpp | 2 +- .../translation_manager/ftp_selection.h | 2 +- .../translation_manager/source_selection.cpp | 2 +- .../translation_manager/source_selection.h | 2 +- .../translation_manager_constants.h | 2 +- .../translation_manager_editor.h | 2 +- .../translation_manager_main_window.cpp | 26 +--------- .../translation_manager_main_window.h | 2 +- .../translation_manager_main_window.ui | 9 +++- .../translation_manager_plugin.cpp | 5 +- .../translation_manager_plugin.h | 2 +- .../translation_manager_settings_page.cpp | 2 +- .../translation_manager_settings_page.h | 2 +- 21 files changed, 79 insertions(+), 80 deletions(-) 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 index 2e5a576ab..081dc455b 100644 --- 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 @@ -35,14 +35,15 @@ using namespace std; -namespace Plugin { +namespace TranslationManager { void CEditorPhrase::open(QString filename) { vector phrases; if(readPhraseFile(filename.toStdString(), phrases, false)) { - text_edit = new QTextEdit(this); + 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); @@ -58,7 +59,6 @@ void CEditorPhrase::open(QString filename) setAttribute(Qt::WA_DeleteOnClose); editor_type = Constants::ED_PHRASE; current_file = filename; - connect(text_edit->document(), SIGNAL(contentsChange(int, int, int)), this, SLOT(contentsChangeNow(int position, int charsRemoved, int charsAdded))); connect(text_edit->document(), SIGNAL(contentsChanged()), this, SLOT(docContentsChanged())); } else { QErrorMessage error; @@ -67,13 +67,28 @@ void CEditorPhrase::open(QString filename) } } -void CEditorPhrase::contentsChangeNow(int position, int charsRemoved, int charsAdded) +/* void CTextEdit::keyPressEvent(QKeyEvent *event) { - if(charsRemoved > 0) - current_stack->push(new CUndoPhraseRemoveCommand(position-charsRemoved, charsRemoved, text_edit)); - else if(charsAdded > 0) - current_stack->push(new CUndoPhraseInsertCommand(position, text_edit->toPlainText().right(charsAdded), text_edit)); -} + QString chars = event->text(); + int index = textCursor().position(); + + switch(event->key()) + { + case Qt::Key_Backspace: + if (index > 0) + m_undoStack->push(new CUndoPhraseRemoveCommand(index--, 1, this)); + break; + case Qt::Key_Delete: + if (index < toPlainText().length()) + m_undoStack->push(new CUndoPhraseRemoveCommand(index, 1, this)); + break; + default: + if (!chars.isEmpty()) + m_undoStack->push(new CUndoPhraseInsertCommand(index, chars, this)); + break; + } + +} */ void CEditorPhrase::docContentsChanged() { 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 index c792d0b21..d542b6e34 100644 --- 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 @@ -29,17 +29,33 @@ #include #include #include +#include +#include // Project includes #include "translation_manager_editor.h" -namespace Plugin { +namespace TranslationManager { + +class CTextEdit : public QTextEdit +{ + Q_OBJECT +private: + QUndoStack* m_undoStack; +public: + CTextEdit(QWidget* parent = 0) : QTextEdit(parent) { } + //void keyPressEvent(QKeyEvent *event); + void setUndoStack(QUndoStack* undoStack) + { + m_undoStack = undoStack; + } +}; class CEditorPhrase : public CEditor { Q_OBJECT public: - QTextEdit *text_edit; + CTextEdit *text_edit; public: CEditorPhrase(QMdiArea* parent) : CEditor(parent) {} CEditorPhrase() : CEditor() {} @@ -49,7 +65,6 @@ public: void activateWindow(); void closeEvent(QCloseEvent *event); public Q_SLOTS: - void contentsChangeNow(int, int, int); void docContentsChanged(); }; @@ -127,30 +142,12 @@ public: { HighlightingRule rule; - keywordFormat.setForeground(Qt::darkBlue); - keywordFormat.setFontWeight(QFont::Bold); - QStringList keywordPatterns; - keywordPatterns << "\\bchar\\b" << "\\bclass\\b" << "\\bconst\\b" - << "\\bdouble\\b" << "\\benum\\b" << "\\bexplicit\\b" - << "\\bfriend\\b" << "\\binline\\b" << "\\bint\\b" - << "\\blong\\b" << "\\bnamespace\\b" << "\\boperator\\b" - << "\\bprivate\\b" << "\\bprotected\\b" << "\\bpublic\\b" - << "\\bshort\\b" << "\\bsignals\\b" << "\\bsigned\\b" - << "\\bslots\\b" << "\\bstatic\\b" << "\\bstruct\\b" - << "\\btemplate\\b" << "\\btypedef\\b" << "\\btypename\\b" - << "\\bunion\\b" << "\\bunsigned\\b" << "\\bvirtual\\b" - << "\\bvoid\\b" << "\\bvolatile\\b"; - Q_FOREACH(const QString &pattern, keywordPatterns) { - rule.pattern = QRegExp(pattern); - rule.format = keywordFormat; - highlightingRules.append(rule); - } + translateStringFormat.setFontWeight(QFont::Bold); + translateStringFormat.setForeground(Qt::darkMagenta); + rule.pattern = QRegExp("\\[.+\\]"); + rule.format = translateStringFormat; + highlightingRules.append(rule); - classFormat.setFontWeight(QFont::Bold); - classFormat.setForeground(Qt::darkMagenta); - rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b"); - rule.format = classFormat; - highlightingRules.append(rule); singleLineCommentFormat.setForeground(Qt::red); rule.pattern = QRegExp("//[^\n]*"); @@ -166,7 +163,7 @@ public: functionFormat.setFontItalic(true); functionFormat.setForeground(Qt::blue); - rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()"); + rule.pattern = QRegExp("\\(.+\\)"); rule.format = functionFormat; highlightingRules.append(rule); @@ -223,6 +220,7 @@ public: QTextCharFormat multiLineCommentFormat; QTextCharFormat quotationFormat; QTextCharFormat functionFormat; + QTextCharFormat translateStringFormat; }; } 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 index a6ef28d36..ce02837c8 100644 --- 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 @@ -32,7 +32,7 @@ using namespace std; -namespace Plugin { +namespace TranslationManager { 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 index 0cb0602e2..839601047 100644 --- 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 @@ -38,7 +38,7 @@ #include "translation_manager_editor.h" #include "extract_new_sheet_names.h" -namespace Plugin { +namespace TranslationManager { class CEditorWorksheet : public CEditor { 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 index 4de3d889d..e8ed68bbf 100644 --- 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 @@ -23,7 +23,7 @@ static bool RemoveOlds = false; -namespace Plugin +namespace TranslationManager { TCreatureInfo *ExtractBotNames::getCreature(const std::string &sheetName) 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 index 9c4ea51d2..df1cb39ca 100644 --- 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 @@ -35,7 +35,7 @@ using namespace NLMISC; using namespace NLLIGO; using namespace STRING_MANAGER; -namespace Plugin +namespace TranslationManager { struct TCreatureInfo 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 index b9411c74e..5d0b9b455 100644 --- 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 @@ -21,7 +21,8 @@ using namespace NLMISC; using namespace NLLIGO; using namespace STRING_MANAGER; -namespace Plugin { +namespace TranslationManager +{ 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 index 8c9151e2e..ca7295f91 100644 --- 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 @@ -35,7 +35,8 @@ using namespace NLMISC; using namespace NLLIGO; using namespace STRING_MANAGER; -namespace Plugin { +namespace TranslationManager +{ // *************************************************************************** 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 index 68abd456f..b3f637b80 100644 --- 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 @@ -3,7 +3,7 @@ #include #include -namespace Plugin +namespace TranslationManager { CFtpSelection::CFtpSelection(QWidget *parent): QDialog(parent) { 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 index 64ea136c4..7a90271a9 100644 --- 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 @@ -20,7 +20,7 @@ using namespace std; -namespace Plugin { +namespace TranslationManager { class CFtpSelection : public QDialog { 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 index cf38ed589..18c49f3e3 100644 --- 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 @@ -3,7 +3,7 @@ #include "source_selection.h" -namespace Plugin +namespace TranslationManager { 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 index ab0100fc3..99636d410 100644 --- 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 @@ -12,7 +12,7 @@ using namespace std; -namespace Plugin +namespace TranslationManager { class CSourceDialog : public QDialog 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 index 3cb66181b..dcb91676b 100644 --- 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 @@ -8,7 +8,7 @@ #ifndef TRANSLATION_MANAGER_CONSTANTS_H #define TRANSLATION_MANAGER_CONSTANTS_H -namespace Plugin +namespace TranslationManager { namespace Constants { 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 index 39ef74f2a..bc46769c1 100644 --- 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 @@ -25,7 +25,7 @@ #include #include -namespace Plugin { +namespace TranslationManager { class CEditor : public QMdiSubWindow { Q_OBJECT 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 index efa7743cd..5856f9c7d 100644 --- 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 @@ -44,7 +44,7 @@ #include "ftp_selection.h" -namespace Plugin +namespace TranslationManager { CMainWindow::CMainWindow(QWidget *parent) @@ -592,30 +592,6 @@ bool CMainWindow::isPhraseEditor(QString filename) } } -/* void CMainWindow::keyPressEvent(QKeyEvent *event) -{ - CEditorPhrase* editor = qobject_cast(_ui.mdiArea->currentSubWindow()); - - QString chars = event->text(); - int index = editor->text_edit->textCursor().position(); - - switch (event->key()) - { - case Qt::Key_Backspace: - if (index > 0) - m_undoStack->push(new CUndoPhraseRemoveCommand(index--, 1, editor->text_edit)); - break; - case Qt::Key_Delete: - if (index < editor->text_edit->toPlainText().length()) - m_undoStack->push(new CUndoPhraseRemoveCommand(index, 1, editor->text_edit)); - break; - default: - if (!chars.isEmpty()) - m_undoStack->push(new CUndoPhraseInsertCommand(index, chars, editor->text_edit)); - break; - } -} */ - bool CCoreListener::closeMainWindow() const { bool okToClose = true; 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 index 02146a9dd..6b9822031 100644 --- 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 @@ -52,7 +52,7 @@ class QWidget; using namespace std; -namespace Plugin +namespace TranslationManager { class CMainWindow : public QMainWindow 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 index 71c139e0a..6f2cd2815 100644 --- 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 @@ -18,7 +18,14 @@ - + + + QMdiArea::TabbedView + + + true + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp index c98eed5be..3efbdd0e8 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp @@ -37,7 +37,7 @@ #include #include -namespace Plugin +namespace TranslationManager { TranslationManagerPlugin::~TranslationManagerPlugin() { @@ -137,8 +137,9 @@ ExtensionSystem::IPluginSpec *TranslationManagerPlugin::pluginByName(const QStri if (spec->name() == name) return spec; return 0; + } } -Q_EXPORT_PLUGIN(Plugin::TranslationManagerPlugin) +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 index 8c91d64cd..94c75d628 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h @@ -42,7 +42,7 @@ namespace ExtensionSystem class IPluginSpec; } -namespace Plugin +namespace TranslationManager { class CTranslationManagerContext; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp index fbd713ac6..09588da7d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.cpp @@ -28,7 +28,7 @@ // Project includes #include "../core/icore.h" -namespace Plugin +namespace TranslationManager { QString lastDir = "."; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h index 1cf19787a..34caea5e1 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_settings_page.h @@ -26,7 +26,7 @@ class QWidget; -namespace Plugin +namespace TranslationManager { /** @class CTranslationManagerSettingsPage From ba7dfeb9072c4acf296f2bb3bc7da5732199ecd4 Mon Sep 17 00:00:00 2001 From: cemycc Date: Fri, 12 Aug 2011 15:00:22 +0300 Subject: [PATCH 27/34] Changed: #1307 Added undo/redo for Phrase Editor. Works great --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/editor_phrase.cpp | 6 ++ .../translation_manager/editor_phrase.h | 71 +++++-------------- 2 files changed, 22 insertions(+), 55 deletions(-) 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 index 081dc455b..6033ecb38 100644 --- 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 @@ -60,6 +60,7 @@ void CEditorPhrase::open(QString filename) 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."); @@ -67,6 +68,11 @@ void CEditorPhrase::open(QString filename) } } +void CEditorPhrase::newUndoCommandAdded() +{ + current_stack->push(new CUndoPhraseNewCommand(text_edit)); +} + /* void CTextEdit::keyPressEvent(QKeyEvent *event) { QString chars = event->text(); 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 index d542b6e34..f26dec73e 100644 --- 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 @@ -43,7 +43,10 @@ class CTextEdit : public QTextEdit private: QUndoStack* m_undoStack; public: - CTextEdit(QWidget* parent = 0) : QTextEdit(parent) { } + CTextEdit(QWidget* parent = 0) : QTextEdit(parent) + { + setUndoRedoEnabled(true); + } //void keyPressEvent(QKeyEvent *event); void setUndoStack(QUndoStack* undoStack) { @@ -66,73 +69,31 @@ public: void closeEvent(QCloseEvent *event); public Q_SLOTS: void docContentsChanged(); + void newUndoCommandAdded(); }; -class CUndoPhraseInsertCommand : public QUndoCommand +class CUndoPhraseNewCommand : public QUndoCommand { public: - CUndoPhraseInsertCommand(int index, const QString &chars, QTextEdit *document, QUndoCommand *parent = 0) : QUndoCommand("Insert characters", parent), - m_index(index), - m_chars(chars), - m_document(document) - { } - - virtual void redo() - { - QString text = m_document->toPlainText(); - text.insert(m_index, m_chars); - m_document->clear(); - m_document->setPlainText(text); - } - - virtual void undo() - { - QString text = m_document->toPlainText(); - text.remove(m_index, m_chars.length()); - m_document->clear(); - m_document->setPlainText(text); - m_document->undo(); - } - -private: - int m_index; - QString m_chars; - QTextEdit* m_document; - -}; - -class CUndoPhraseRemoveCommand : public QUndoCommand -{ -public: - CUndoPhraseRemoveCommand(int index, int count, QTextEdit *document, QUndoCommand *parent = 0) : QUndoCommand("Remove characters", parent), - m_index(index), - m_count(count), - m_document(document) + CUndoPhraseNewCommand(CTextEdit *textEdit, QUndoCommand *parent = 0) + : QUndoCommand("Inserting/Removing characters", parent), + m_textEdit(textEdit) { } - virtual void redo() + ~CUndoPhraseNewCommand() {} + + void undo() { - QString text = m_document->toPlainText(); - m_removedChars = text.mid(m_index, m_count); - text.remove(m_index, m_count); - m_document->clear(); - m_document->setPlainText(text); + m_textEdit->undo(); } - virtual void undo() + void redo() { - QString text = m_document->toPlainText(); - text.insert(m_index, m_removedChars); - m_document->clear(); - m_document->setPlainText(text); + m_textEdit->redo(); } private: - int m_index; - int m_count; - QString m_removedChars; - QTextEdit* m_document; - + CTextEdit* m_textEdit; }; class SyntaxHighlighter : public QSyntaxHighlighter From b83fb39a9431172a60db1af01439cb83bc89bb21 Mon Sep 17 00:00:00 2001 From: cemycc Date: Wed, 17 Aug 2011 11:54:00 +0300 Subject: [PATCH 28/34] Changed: #1307 Added support for unicode format on editors --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/editor_phrase.cpp | 10 ++++++++-- .../translation_manager/editor_worksheet.cpp | 16 +++++++++------- .../translation_manager_main_window.cpp | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) 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 index 6033ecb38..696bd41b1 100644 --- 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 @@ -27,7 +27,8 @@ #include #include #include - +#include +#include // Project includes #include "editor_phrase.h" @@ -51,8 +52,9 @@ void CEditorPhrase::open(QString filename) // read the file content QFile file(filename); file.open(QIODevice::ReadOnly | QIODevice::Text); + QTextStream in(&file); // set the file content to the text edit - QByteArray data = file.readAll(); + QString data = in.readAll(); text_edit->append(data); // window settings setCurrentFile(filename); @@ -111,6 +113,8 @@ void CEditorPhrase::save() QFile file(current_file); file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); + out.setCodec("UTF-8"); + out.setGenerateByteOrderMark(true); out<toPlainText(); setCurrentFile(current_file); } @@ -120,6 +124,8 @@ 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); 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 index ce02837c8..6e71a9290 100644 --- 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 @@ -1,4 +1,4 @@ -// Translation Manager Plugin - OVQT Plugin +// Translation Manager Plugin - OVQT Plugin // Copyright (C) 2010 Winch Gate Property Limited // Copyright (C) 2011 Emanuel Costea // @@ -82,7 +82,7 @@ void CEditorWorksheet::open(QString filename) } else { QTableWidgetItem *row = new QTableWidgetItem(); ucstring row_value = wk_file.getData(i, j); - row->setText(tr(row_value.toString().c_str())); + row->setText(QString::fromUtf8(row_value.toUtf8().c_str())); if(hasHashValue) { table_editor->setItem(i - 1, j - 1, row); @@ -157,8 +157,8 @@ void CEditorWorksheet::save() ucstring tvalue; ucstring colname; uint rowIdf; - QString tvalueQt = table_editor->item(i, j)->text(); - tvalue = ucstring(tvalueQt.toStdString()); + QString tvalueQt = table_editor->item(i, j)->text(); + tvalue.fromUtf8(std::string(tvalueQt.toUtf8())); colname = wk_file.getData(0, j + colIdx); rowIdf = uint(i + 1); @@ -166,10 +166,10 @@ void CEditorWorksheet::save() { if(wk_file.getData(i + 1, j + colIdx) != tvalue) // verify the current value { - wk_file.setData(i + 1, j + colIdx, tvalue); // change the value + wk_file.setData(i + 1, j + colIdx, tvalue); // change the value } } else { - wk_file.setData(i + 1, j + colIdx, tvalue); // insert the value + wk_file.setData(i + 1, j + colIdx, tvalue); // insert the value } } } @@ -209,10 +209,12 @@ void CEditorWorksheet::saveAs(QString filename) { 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); - new_file.setData(rowIdx, j + colIdx, ucstring(item->text().toStdString())); + tvalue.fromUtf8(std::string(item->text().toUtf8())); + new_file.setData(rowIdx, j + colIdx, tvalue); } } if(hasHashValue) 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 index 5856f9c7d..365304c5b 100644 --- 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 @@ -37,7 +37,7 @@ #include #include #include - +#include // Plugin includes #include "translation_manager_main_window.h" #include "translation_manager_constants.h" From ec3fcf5ef370c7b77bd39f617c024876afb63416 Mon Sep 17 00:00:00 2001 From: cemycc Date: Thu, 18 Aug 2011 00:58:26 +0300 Subject: [PATCH 29/34] Changed: #1307 Making some little modifcations in code. Open now saves the last directory --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/editor_phrase.cpp | 31 +--- .../translation_manager/editor_worksheet.cpp | 161 +++++------------- .../translation_manager/editor_worksheet.h | 25 +-- .../translation_manager/ftp_selection.ui | 96 +++++------ .../translation_manager_main_window.cpp | 46 +++-- 5 files changed, 134 insertions(+), 225 deletions(-) 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 index 696bd41b1..c1633c3be 100644 --- 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 @@ -75,29 +75,6 @@ void CEditorPhrase::newUndoCommandAdded() current_stack->push(new CUndoPhraseNewCommand(text_edit)); } -/* void CTextEdit::keyPressEvent(QKeyEvent *event) -{ - QString chars = event->text(); - int index = textCursor().position(); - - switch(event->key()) - { - case Qt::Key_Backspace: - if (index > 0) - m_undoStack->push(new CUndoPhraseRemoveCommand(index--, 1, this)); - break; - case Qt::Key_Delete: - if (index < toPlainText().length()) - m_undoStack->push(new CUndoPhraseRemoveCommand(index, 1, this)); - break; - default: - if (!chars.isEmpty()) - m_undoStack->push(new CUndoPhraseInsertCommand(index, chars, this)); - break; - } - -} */ - void CEditorPhrase::docContentsChanged() { setWindowModified(true); @@ -110,13 +87,7 @@ void CEditorPhrase::activateWindow() void CEditorPhrase::save() { - QFile file(current_file); - file.open(QIODevice::WriteOnly | QIODevice::Text); - QTextStream out(&file); - out.setCodec("UTF-8"); - out.setGenerateByteOrderMark(true); - out<toPlainText(); - setCurrentFile(current_file); + saveAs(current_file); } void CEditorPhrase::saveAs(QString filename) 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 index 6e71a9290..c957e6506 100644 --- 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 @@ -34,8 +34,6 @@ using namespace std; namespace TranslationManager { - - void CEditorWorksheet::open(QString filename) { STRING_MANAGER::TWorksheet wk_file; @@ -134,54 +132,7 @@ void CEditorWorksheet::activateWindow() void CEditorWorksheet::save() { - STRING_MANAGER::TWorksheet wk_file; - loadExcelSheet(current_file.toStdString(), wk_file, true); - 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++) - { - // maybe extra rows ? - if((unsigned)table_editor->rowCount() > (wk_file.size() - 1)) - { - rowIdx = wk_file.size(); - wk_file.resize(rowIdx + table_editor->rowCount() - wk_file.size() + 1); - } - for(int j = 0; j < table_editor->columnCount(); j++) - { - ucstring tvalue; - ucstring colname; - uint rowIdf; - QString tvalueQt = table_editor->item(i, j)->text(); - tvalue.fromUtf8(std::string(tvalueQt.toUtf8())); - colname = wk_file.getData(0, j + colIdx); - - rowIdf = uint(i + 1); - if(wk_file.findRow(j + colIdx, colname, rowIdf)) // search for the row - { - if(wk_file.getData(i + 1, j + colIdx) != tvalue) // verify the current value - { - wk_file.setData(i + 1, j + colIdx, tvalue); // change the value - } - } else { - wk_file.setData(i + 1, j + colIdx, tvalue); // insert the value - } - } - } - if(hasHashValue) - { - // rewrite the hash codes - makeHashCode(wk_file, true); - } - // write to file - ucstring s = prepareExcelSheet(wk_file); - NLMISC::CI18N::writeTextFile(current_file.toStdString(), s, false); - setCurrentFile(current_file); + saveAs(current_file); } void CEditorWorksheet::saveAs(QString filename) @@ -238,8 +189,8 @@ void CEditorWorksheet::deleteRow() { int selected_row = table_editor->currentRow(); QMessageBox msgBox; - msgBox.setText("The row will be deleted."); - msgBox.setInformativeText("Do you want to delete the selected row ?"); + 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(); @@ -286,30 +237,15 @@ void CEditorWorksheet::extractBotNames(list filters, string level_design for (; it != last; ++it) { - QList search_results = table_editor->findItems(tr(it->first.c_str()), Qt::MatchExactly); + QList search_results = table_editor->findItems(QString(it->first.c_str()), Qt::MatchExactly); if(search_results.size() == 0) { - const int currentRow = table_editor->rowCount(); - table_editor->setRowCount(currentRow + 1); - QTableWidgetItem *bot_name_row = new QTableWidgetItem(); - bot_name_row->setText(tr(it->first.c_str())); - bot_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 0, bot_name_row); - QTableWidgetItem *translation_name_row = new QTableWidgetItem(); - translation_name_row->setBackgroundColor(QColor("#F75D59")); - translation_name_row->setText(tr(it->first.c_str())); - table_editor ->setItem(currentRow , 1, translation_name_row); - QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); - sheet_name_row->setText(tr(it->second.SheetName.c_str())); - sheet_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 2, sheet_name_row); - if(!modified) modified = true; - CTableWidgetItemStore bot_name_row_s(bot_name_row, currentRow, 0); - new_items.push_back(bot_name_row_s); - CTableWidgetItemStore translation_name_row_s(translation_name_row, currentRow, 1); - new_items.push_back(translation_name_row_s); - CTableWidgetItemStore sheet_name_row_s(sheet_name_row, currentRow, 2); - new_items.push_back(sheet_name_row_s); + QList records; + records.push_back(tr(it->first.c_str())); + records.push_back(tr(it->first.c_str())); + records.push_back(tr(it->second.SheetName.c_str())); + insertTableRecords(records, new_items); + if(!modified) modified = true; } } ebn.cleanSimpleNames(); @@ -321,30 +257,15 @@ void CEditorWorksheet::extractBotNames(list filters, string level_design for (; it != last; ++it) { string gnName = "gn_" + ebn.cleanupName(*it); - QList search_results = table_editor->findItems(tr((*it).c_str()), Qt::MatchExactly); + QList search_results = table_editor->findItems(QString((*it).c_str()), Qt::MatchExactly); if(search_results.size() == 0) { - const int currentRow = table_editor->rowCount(); - table_editor->setRowCount(currentRow + 1); - QTableWidgetItem *bot_name_row = new QTableWidgetItem(); - bot_name_row->setText(tr((*it).c_str())); - bot_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 0, bot_name_row); - QTableWidgetItem *translation_name_row = new QTableWidgetItem(); - translation_name_row->setBackgroundColor(QColor("#F75D59")); - translation_name_row->setText(tr(gnName.c_str())); - table_editor ->setItem(currentRow , 1, translation_name_row); - QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); - sheet_name_row->setText(" "); - sheet_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 2, sheet_name_row); + QList records; + records.push_back(tr((*it).c_str())); + records.push_back(tr(gnName.c_str())); + records.push_back(" "); + insertTableRecords(records, new_items); if(!modified) modified = true; - CTableWidgetItemStore bot_name_row_s(bot_name_row, currentRow, 0); - new_items.push_back(bot_name_row_s); - CTableWidgetItemStore translation_name_row_s(translation_name_row, currentRow, 1); - new_items.push_back(translation_name_row_s); - CTableWidgetItemStore sheet_name_row_s(sheet_name_row, currentRow, 2); - new_items.push_back(sheet_name_row_s); } } ebn.cleanGenericNames(); @@ -399,8 +320,7 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis string keyName = allWords[i]; QList search_results = table_editor->findItems(tr(keyName.c_str()), Qt::MatchExactly); if(search_results.size() == 0) - { - + { int knPos = 0, nPos = 0; if(workSheet.getData(0, 0) == ucstring("*HASH_VALUE")) { @@ -409,25 +329,13 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis } else { knPos = keyColIndex; nPos = nameColIndex; - } - const int currentRow = table_editor->rowCount(); - table_editor->setRowCount(currentRow + 1); - // keyName row - QTableWidgetItem *key_name_row = new QTableWidgetItem(); - key_name_row->setText(tr(keyName.c_str())); - key_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, knPos, key_name_row); - // nameColumn key - QTableWidgetItem *name_row = new QTableWidgetItem(); - name_row->setText(QString("") + tr(keyName.c_str())); - name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, nPos, name_row); - if(!modified) modified = true; - CTableWidgetItemStore key_name_row_s(key_name_row, currentRow, knPos); - new_items.push_back(key_name_row_s); - CTableWidgetItemStore name_row_s(name_row, currentRow, nPos); - new_items.push_back(name_row_s); + } + QList records; + records.push_back(tr(keyName.c_str())); + records.push_back(QString("") + tr(keyName.c_str())); + insertTableRecords(records, new_items); + if(!modified) modified = true; } } current_stack->push(new CUndoWorksheetExtraction(new_items, table_editor)); @@ -438,6 +346,23 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis } } +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; @@ -503,7 +428,7 @@ void CEditorWorksheet::mergeWorksheetFile(QString filename) } } else { QErrorMessage error; - error.showMessage("This file is not a worksheet file."); + error.showMessage(tr("This file is not a worksheet file.")); error.exec(); } } @@ -513,8 +438,8 @@ void CEditorWorksheet::closeEvent(QCloseEvent *event) if(isWindowModified()) { QMessageBox msgBox; - msgBox.setText("The document has been modified."); - msgBox.setInformativeText("Do you want to save your changes?"); + 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(); 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 index 839601047..487a9eea8 100644 --- 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 @@ -40,6 +40,18 @@ 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 @@ -57,6 +69,7 @@ public: 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); @@ -69,18 +82,6 @@ private Q_SLOTS: }; -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 CUndoWorksheetCommand : public QUndoCommand { public: 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 index b8b0bf447..444a7d97e 100644 --- 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 @@ -6,7 +6,7 @@ 0 0 - 388 + 446 560 @@ -18,7 +18,7 @@ 10 10 - 371 + 421 541 @@ -29,9 +29,9 @@ 10 - 130 - 351 - 361 + 110 + 401 + 381 @@ -55,7 +55,7 @@ 10 40 - 331 + 381 311 @@ -69,49 +69,9 @@ - 11 - 29 - 351 - 101 - - - - - - - Ftp server - - - - - - - - - - Connect - - - - - - - - - - - :/translationManager/images/cdtoparent.png:/translationManager/images/cdtoparent.png - - - - - - - - - 0 + 10 500 - 371 + 401 33 @@ -132,6 +92,46 @@ + + + + 10 + 20 + 411 + 81 + + + + + + + Ftp server + + + + + + + + + + + + + + :/translationManager/images/cdtoparent.png:/translationManager/images/cdtoparent.png + + + + + + + Connect + + + + + 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 index 365304c5b..ee509c8ad 100644 --- 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 @@ -37,7 +37,6 @@ #include #include #include -#include // Plugin includes #include "translation_manager_main_window.h" #include "translation_manager_constants.h" @@ -70,7 +69,7 @@ CMainWindow::CMainWindow(QWidget *parent) void CMainWindow::createToolbar() { // File menu - openAct = new QAction(QIcon(Core::Constants::ICON_OPEN), "&Open...", this); + 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); @@ -147,11 +146,11 @@ void CMainWindow::updateToolbar(QMdiSubWindow *window) if(QString(window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor { //setContextMenuPolicy(Qt::ActionsContextMenu); - QAction *insertRowAct = new QAction("Insert new row", this); + QAction *insertRowAct = new QAction(tr("Insert new row"), this); connect(insertRowAct, SIGNAL(triggered()), window, SLOT(insertRow())); //addAction(insertRowAct); windowMenu->addAction(insertRowAct); - QAction *deleteRowAct = new QAction("Delete row", this); + QAction *deleteRowAct = new QAction(tr("Delete row"), this); connect(deleteRowAct, SIGNAL(triggered()), window, SLOT(deleteRow())); //addAction(deleteRowAct); windowMenu->addAction(deleteRowAct); @@ -202,7 +201,14 @@ void CMainWindow::updateWindowsList() void CMainWindow::open() { - QString file_name = QFileDialog::getOpenFileName(this); + 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); @@ -303,14 +309,22 @@ void CMainWindow::initializeSettings(bool georges = false) if(initialize_settings["ligo"] == false) { - //------------------------------------------------------------------- - // init ligo config - string ligoPath = CPath::lookup("world_editor_classes.xml", true, true); - ligoConfig.readPrimitiveClass(ligoPath.c_str(), false); - NLLIGO::Register(); - NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig = &ligoConfig; - initialize_settings["ligo"] = true; + 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"); + } } + } void CMainWindow::extractWords(QString typeq) @@ -510,7 +524,7 @@ bool CMainWindow::verifySettings() if(level_design_path.isNull() || primitives_path.isNull() || work_path.isNull()) { QErrorMessage error_settings; - error_settings.showMessage("Please write all the paths on the settings dialog."); + error_settings.showMessage(tr("Please write all the paths on the settings dialog.")); error_settings.exec(); count_errors = true; } @@ -574,11 +588,9 @@ bool CMainWindow::isWorksheetEditor(QString filename) { if(wk_file.ColCount > 1) return true; - else - return false; - } else { - return false; } + + return false; } bool CMainWindow::isPhraseEditor(QString filename) From 2a9293b72ac3807468d1deae17a87848677d963f Mon Sep 17 00:00:00 2001 From: cemycc Date: Mon, 22 Aug 2011 14:42:51 +0300 Subject: [PATCH 30/34] Changed: #1307 Added documentation and minor fixes --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/editor_worksheet.cpp | 20 ++-- .../translation_manager/ftp_selection.cpp | 6 +- .../translation_manager/source_selection.cpp | 1 + .../translation_manager_main_window.cpp | 107 ++++++++++-------- 4 files changed, 75 insertions(+), 59 deletions(-) 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 index c957e6506..c8a101e0f 100644 --- 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 @@ -59,7 +59,7 @@ void CEditorWorksheet::open(QString filename) } else { QTableWidgetItem *col = new QTableWidgetItem(); ucstring col_name = wk_file.getData(0, i); - col->setText(tr(col_name.toString().c_str())); + col->setText(QString(col_name.toString().c_str())); if(hasHashValue) { table_editor->setHorizontalHeaderItem(i - 1, col); @@ -241,9 +241,9 @@ void CEditorWorksheet::extractBotNames(list filters, string level_design if(search_results.size() == 0) { QList records; - records.push_back(tr(it->first.c_str())); - records.push_back(tr(it->first.c_str())); - records.push_back(tr(it->second.SheetName.c_str())); + 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; } @@ -261,8 +261,8 @@ void CEditorWorksheet::extractBotNames(list filters, string level_design if(search_results.size() == 0) { QList records; - records.push_back(tr((*it).c_str())); - records.push_back(tr(gnName.c_str())); + 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; @@ -318,7 +318,7 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis for(i = 0; i < allWords.size(); i++) { string keyName = allWords[i]; - QList search_results = table_editor->findItems(tr(keyName.c_str()), Qt::MatchExactly); + QList search_results = table_editor->findItems(QString(keyName.c_str()), Qt::MatchExactly); if(search_results.size() == 0) { int knPos = 0, nPos = 0; @@ -332,8 +332,8 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis } QList records; - records.push_back(tr(keyName.c_str())); - records.push_back(QString("") + tr(keyName.c_str())); + records.push_back(QString(keyName.c_str())); + records.push_back(QString("") + QString(keyName.c_str())); insertTableRecords(records, new_items); if(!modified) modified = true; } @@ -412,7 +412,7 @@ void CEditorWorksheet::mergeWorksheetFile(QString filename) { // search with the first column ucstring rowId = wk_file.getData(i,colIndex); - QList search_results = table_editor->findItems(tr(rowId.toString().c_str()), Qt::MatchExactly); + QList search_results = table_editor->findItems(QString(rowId.toString().c_str()), Qt::MatchExactly); if(search_results.size() == 0) { const int lastRow = table_editor->rowCount(); 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 index b3f637b80..41a8072e2 100644 --- 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 @@ -27,6 +27,7 @@ namespace TranslationManager status = false; } + // Connection with the FTP Server. We retrieve the file list. void CFtpSelection::ConnectButtonClicked() { conn = new QFtp(this); @@ -51,6 +52,7 @@ namespace TranslationManager } } + // Get the user action. void CFtpSelection::FtpCommandFinished(int, bool error) { #ifndef QT_NO_CURSOR @@ -98,7 +100,7 @@ namespace TranslationManager } } } - + // Make the file list with directories and files void CFtpSelection::AddToList(const QUrlInfo &urlInfo) { QTreeWidgetItem *item = new QTreeWidgetItem; @@ -138,6 +140,7 @@ namespace TranslationManager _ui.doneButton->setEnabled(true); } + // Exit from a directory void CFtpSelection::cdToParent() { #ifndef QT_NO_CURSOR @@ -155,6 +158,7 @@ namespace TranslationManager conn->list(); } + // Done action void CFtpSelection::DoneButtonClicked() { QString fileName = _ui.fileList->currentItem()->text(0); 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 index 18c49f3e3..b4733c7b9 100644 --- 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 @@ -17,6 +17,7 @@ CSourceDialog::CSourceDialog(QWidget *parent): QDialog(parent) _ui.listWidget->setSortingEnabled(false); } +// Insert options in the source dialog. Options like: from FTP Server, from Local directory etc. void CSourceDialog::setSourceOptions(map options) { map::iterator it; 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 index ee509c8ad..8f9a213bf 100644 --- 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 @@ -51,8 +51,7 @@ CMainWindow::CMainWindow(QWidget *parent) { _ui.setupUi(this); - _ui.mdiArea->closeAllSubWindows(); - connect(_ui.mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)),this, SLOT(activeSubWindowChanged())); + _ui.mdiArea->closeAllSubWindows(); windowMapper = new QSignalMapper(this); connect(windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*))); @@ -66,6 +65,7 @@ CMainWindow::CMainWindow(QWidget *parent) } +// Functions that will insert the plugin buttons void CMainWindow::createToolbar() { // File menu @@ -96,27 +96,27 @@ void CMainWindow::createToolbar() QAction *extractItemWordsAct = wordsExtractionMenu->addAction("&Extract item words..."); extractItemWordsAct->setStatusTip(tr("Extract item words")); connect(extractItemWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); - wordsExtractionMapper->setMapping(extractItemWordsAct, tr(Constants::WK_ITEM)); + 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, tr(Constants::WK_CREATURE)); + 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, tr(Constants::WK_SBRICK)); + 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, tr(Constants::WK_SPHRASE)); + 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, tr(Constants::WK_PLACE)); + wordsExtractionMapper->setMapping(extractPlaceNamesAct, QString(Constants::WK_PLACE)); // Merge options // ----------------------------- QAction *mergeSingleFileAct = wordsExtractionMenu->addAction("&Merge worksheet file..."); @@ -140,24 +140,23 @@ void CMainWindow::createToolbar() _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 { - //setContextMenuPolicy(Qt::ActionsContextMenu); QAction *insertRowAct = new QAction(tr("Insert new row"), this); connect(insertRowAct, SIGNAL(triggered()), window, SLOT(insertRow())); - //addAction(insertRowAct); windowMenu->addAction(insertRowAct); QAction *deleteRowAct = new QAction(tr("Delete row"), this); connect(deleteRowAct, SIGNAL(triggered()), window, SLOT(deleteRow())); - //addAction(deleteRowAct); windowMenu->addAction(deleteRowAct); } } +// Set the active subwindow void CMainWindow::setActiveSubWindow(QWidget* window) { if (!window) @@ -168,13 +167,11 @@ void CMainWindow::setActiveSubWindow(QWidget* window) _ui.mdiArea->setActiveSubWindow(cwindow); } -void CMainWindow::activeSubWindowChanged() -{ - -} - +// 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(); @@ -186,9 +183,9 @@ void CMainWindow::updateWindowsList() QString window_file = QFileInfo(subWindows.at(i)->windowFilePath()).fileName(); QString action_text; if (i < 9) { - action_text = tr("&%1 %2").arg(i + 1).arg(window_file); + action_text = QString("&%1 %2").arg(i + 1).arg(window_file); } else { - action_text = tr("%1 %2").arg(i + 1).arg(window_file); + action_text = QString("%1 %2").arg(i + 1).arg(window_file); } QAction *action = new QAction(action_text, this); action->setCheckable(true); @@ -196,9 +193,12 @@ void CMainWindow::updateWindowsList() connect(action, SIGNAL(triggered()), windowMapper, SLOT(map())); windowMenu->addAction(action); windowMapper->setMapping(action, subWindows.at(i)); - } + } + + } } +// Open signal void CMainWindow::open() { QSettings *settings = Core::ICore::instance()->settings(); @@ -243,6 +243,7 @@ void CMainWindow::open() } +// 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)); @@ -262,6 +263,7 @@ void CMainWindow::openWorkFile(QString file) } +// Save signal void CMainWindow::save() { if(_ui.mdiArea->subWindowList().size() > 0) @@ -277,6 +279,7 @@ void CMainWindow::save() } } +// Save as signal void CMainWindow::saveAs() { QString file_name; @@ -298,6 +301,7 @@ void CMainWindow::saveAs() } } +// This function is needed by extraction. void CMainWindow::initializeSettings(bool georges = false) { if(georges == true && initialize_settings["georges"] == false) @@ -327,6 +331,7 @@ void CMainWindow::initializeSettings(bool georges = false) } +// Extracting words void CMainWindow::extractWords(QString typeq) { if(verifySettings() == true) @@ -396,6 +401,7 @@ void CMainWindow::extractWords(QString typeq) } +// Extract bot names from primitives void CMainWindow::extractBotNames() { if(verifySettings() == true) @@ -425,6 +431,7 @@ void CMainWindow::extractBotNames() } } +// Merge the content for 2 worksheet files void CMainWindow::mergeSingleFile() { CEditor* editor_window = qobject_cast(_ui.mdiArea->currentSubWindow()); @@ -485,7 +492,7 @@ void CMainWindow::mergeSingleFile() current_window->mergeWorksheetFile(file_name); } else { QErrorMessage error; - error.showMessage(QString("The file: %1 has different columns from the current file in editor.").arg(file_name)); + 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) @@ -493,13 +500,14 @@ void CMainWindow::mergeSingleFile() if(!ftp_dialog->file->remove()) { QErrorMessage error; - error.showMessage(QString("Please remove the file from ftp server manually. The file is located on the same directory with OVQT application.")); + 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(); @@ -517,6 +525,7 @@ void CMainWindow::readSettings() settings->endGroup(); } +// Verify the settings bool CMainWindow::verifySettings() { bool count_errors = false; @@ -533,6 +542,36 @@ bool CMainWindow::verifySettings() } +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()) @@ -604,34 +643,6 @@ bool CMainWindow::isPhraseEditor(QString filename) } } -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; -} - } /* namespace Plugin */ From 76b8fbad674d015dedb119a26fdc6e7c7d6da4b4 Mon Sep 17 00:00:00 2001 From: sfb Date: Sat, 22 Oct 2011 14:23:54 -0500 Subject: [PATCH 31/34] Changed: Fixed an error when cancelling a merge window, added double click support on merge source. Fixed window scaling on merge windows. --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/ftp_selection.ui | 219 ++++++++---------- .../translation_manager/source_selection.cpp | 16 +- .../translation_manager/source_selection.h | 1 + .../translation_manager/source_selection.ui | 78 +++---- .../translation_manager_main_window.cpp | 20 +- 5 files changed, 159 insertions(+), 175 deletions(-) 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 index 444a7d97e..7b3041c04 100644 --- 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 @@ -6,133 +6,112 @@ 0 0 - 446 - 560 + 640 + 576 Dialog - - - - 10 - 10 - 421 - 541 - - - - FTP Server informations - - - - - 10 - 110 - 401 - 381 - - - - Content - - - - - 10 - 20 - 141 - 21 - - - - Please select the file + + + + + 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 + + + + + + - - - - 10 - 40 - 381 - 311 - - - - - 1 - - - - - - - - 10 - 500 - 401 - 33 - - - - - - - Done - - - - - - - Cancel - - - - - - - - - 10 - 20 - 411 - 81 - - - - - - - Ftp server - - - - - - - - - - - - - - :/translationManager/images/cdtoparent.png:/translationManager/images/cdtoparent.png - - - - - - - Connect - - - - - - + + 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 index b4733c7b9..3015b447d 100644 --- 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 @@ -14,7 +14,9 @@ CSourceDialog::CSourceDialog(QWidget *parent): QDialog(parent) 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.listWidget->setSortingEnabled(false); + _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. @@ -24,14 +26,20 @@ void CSourceDialog::setSourceOptions(map options) for(it = options.begin(); it != options.end(); ++it) { - _ui.listWidget->addItem((*it).first); + _ui.sourceSelectionListWidget->addItem((*it).first); } } void CSourceDialog::OkButtonClicked() { - selected_item = _ui.listWidget->currentItem(); - reject(); + 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 index 99636d410..d32bfcb02 100644 --- 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 @@ -22,6 +22,7 @@ private: Ui::SourceSelectionDialog _ui; private Q_SLOTS: void OkButtonClicked(); + void itemDoubleClicked(QListWidgetItem *item); public: CSourceDialog(QWidget *parent = 0); ~CSourceDialog(){} 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 index 6e6f822fe..e64ba78c4 100644 --- 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 @@ -12,8 +12,8 @@ 0 0 - 396 - 197 + 316 + 155 @@ -22,48 +22,38 @@ true - - - - 10 - 10 - 381 - 181 - - - - Select source for merge operation - - - - - 10 - 30 - 361 - 141 - - - - - - - - - - OK - - - - - - - Cancel - - - - - - + + + + + Select source for merge operation + + + + + + + + + + + OK + + + + + + + Cancel + + + + + + + + + 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 index 8151ea234..651050835 100644 --- 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 @@ -472,17 +472,23 @@ void CMainWindow::mergeSingleFile() if(dialog->selected_item == local_item) // Local directory { file_name = QFileDialog::getOpenFileName(this); - } else if(dialog->selected_item == ftp_item) { // Ftp directory + } + else if(dialog->selected_item == ftp_item) // Ftp directory + { CFtpSelection* ftp_dialog = new CFtpSelection(this); ftp_dialog->show(); - ftp_dialog->exec(); - if(ftp_dialog->status == true) - { + + if(ftp_dialog->exec() && ftp_dialog->status == true) file_name = ftp_dialog->file->fileName(); - } - } else { + + 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); From f658be4ab9ac9bb508c41286c677b5a57d82d655 Mon Sep 17 00:00:00 2001 From: sfb Date: Sat, 22 Oct 2011 16:58:07 -0500 Subject: [PATCH 32/34] Changed: Added header to fix mission compiler. --HG-- branch : gsoc2011-translationovqt --- .../plugins/mission_compiler/mission_compiler_main_window.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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); From b967f41eab9731a1d5ddd0c32caa53d1f3672589 Mon Sep 17 00:00:00 2001 From: sfb Date: Sat, 22 Oct 2011 16:58:55 -0500 Subject: [PATCH 33/34] Changed: Converted to new plugin spec. --HG-- branch : gsoc2011-translationovqt --- .../ovqt_plugin_translation_manager.xml | 10 ++++++ .../translation_manager_main_window.cpp | 4 +-- .../translation_manager_plugin.cpp | 32 ++----------------- .../translation_manager_plugin.h | 6 ---- 4 files changed, 14 insertions(+), 38 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ovqt_plugin_translation_manager.xml 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/translation_manager_main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp index 651050835..23509bd20 100644 --- 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 @@ -19,7 +19,7 @@ // Project system includes #include "../core/icore.h" #include "../core/core_constants.h" -#include "../core/imenu_manager.h" +#include "../core/menu_manager.h" #include "../../extension_system/iplugin_spec.h" // Qt includes @@ -124,7 +124,7 @@ void CMainWindow::createToolbar() connect(mergeSingleFileAct, SIGNAL(triggered()), this, SLOT(mergeSingleFile())); // Windows menu Core::ICore *core = Core::ICore::instance(); - Core::IMenuManager *menuManager = core->menuManager(); + Core::MenuManager *menuManager = core->menuManager(); windowMenu = menuManager->menuBar()->addMenu("Window"); updateWindowsList(); connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowsList())); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp index 3efbdd0e8..a40c8e969 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp @@ -22,7 +22,7 @@ // Project system includes #include "../core/icore.h" #include "../core/core_constants.h" -#include "../core/imenu_manager.h" +#include "../core/menu_manager.h" #include "../../extension_system/iplugin_spec.h" // NeL includes @@ -66,7 +66,7 @@ bool TranslationManagerPlugin::initialize(ExtensionSystem::IPluginManager *plugi void TranslationManagerPlugin::extensionsInitialized() { Core::ICore *core = Core::ICore::instance(); - Core::IMenuManager *menuManager = core->menuManager(); + Core::MenuManager *menuManager = core->menuManager(); //menuManager = _plugMan->getObject(); // Menu Actions for plugin QAction *aboutTManPlugin = new QAction("Translation Manager", this); @@ -89,34 +89,6 @@ void TranslationManagerPlugin::setNelContext(NLMISC::INelContext *nelContext) _LibContext = new NLMISC::CLibraryContext(*nelContext); } -QString TranslationManagerPlugin::name() const -{ - return "Translation Manager"; -} - -QString TranslationManagerPlugin::version() const -{ - return "0.1"; -} - -QString TranslationManagerPlugin::vendor() const -{ - return "cemycc"; -} - -QString TranslationManagerPlugin::description() const -{ - return "OVQT plugin for translation files."; -} - -QStringList TranslationManagerPlugin::dependencies() const -{ - QStringList list; - list.append(Core::Constants::OVQT_CORE_PLUGIN); - //list.append("ObjectViewer"); - return list; -} - void TranslationManagerPlugin::addAutoReleasedObject(QObject *obj) { _plugMan->addObject(obj); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h index 94c75d628..f9cb6798c 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.h @@ -59,12 +59,6 @@ public: void setNelContext(NLMISC::INelContext *nelContext); - QString name() const; - QString version() const; - QString vendor() const; - QString description() const; - QStringList dependencies() const; - void addAutoReleasedObject(QObject *obj); QObject *objectByName(const QString &name) const; From 35bd31a2db398355ba8272c3b2ba5d8c9812da34 Mon Sep 17 00:00:00 2001 From: sfb Date: Sat, 22 Oct 2011 17:09:55 -0500 Subject: [PATCH 34/34] Changed: Removed unnecessary help menu entry. --HG-- branch : gsoc2011-translationovqt --- .../translation_manager_plugin.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp index a40c8e969..a43311506 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp @@ -65,16 +65,7 @@ bool TranslationManagerPlugin::initialize(ExtensionSystem::IPluginManager *plugi void TranslationManagerPlugin::extensionsInitialized() { - Core::ICore *core = Core::ICore::instance(); - Core::MenuManager *menuManager = core->menuManager(); - //menuManager = _plugMan->getObject(); - // Menu Actions for plugin - QAction *aboutTManPlugin = new QAction("Translation Manager", this); - // Locations - QMenu *helpMenu = menuManager->menu(Core::Constants::M_HELP); - QAction *aboutQtAction = menuManager->action(Core::Constants::ABOUT_QT); - helpMenu->addSeparator(); - helpMenu->insertAction(aboutQtAction, aboutTManPlugin); + }