From f5984da292062ef4446d443b780eb5b3ea1d36e8 Mon Sep 17 00:00:00 2001 From: cemycc Date: Fri, 15 Jul 2011 00:38:16 +0300 Subject: [PATCH] Added #1307 Full support for FTP merge options and icons for FTP window. This is the last commit for the first milestone. --- .../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;