Added #1307 Full support for FTP merge options and icons for FTP window. This is the last commit for the first milestone.

This commit is contained in:
cemycc 2011-07-15 00:38:16 +03:00
parent e8412dd711
commit 907a09526b
11 changed files with 188 additions and 81 deletions

View file

@ -24,6 +24,8 @@ SET(OVQT_PLUG_TRANSLATION_MANAGER_UIS translation_manager_settings_page.ui
source_selection.ui source_selection.ui
ftp_selection.ui) ftp_selection.ui)
SET(OVQT_PLUG_TRANSLATION_MANAGER_RCS ftp_selection.qrc)
SET(QT_USE_QTGUI TRUE) SET(QT_USE_QTGUI TRUE)
SET(QT_USE_QTOPENGL TRUE) SET(QT_USE_QTOPENGL TRUE)
SET(QT_USE_QTNETWORK TRUE) SET(QT_USE_QTNETWORK TRUE)

View file

@ -10,7 +10,8 @@ namespace Plugin
_ui.setupUi(this); _ui.setupUi(this);
connect(_ui.connectButton, SIGNAL(clicked()), this, SLOT(ConnectButtonClicked())); connect(_ui.connectButton, SIGNAL(clicked()), this, SLOT(ConnectButtonClicked()));
connect(_ui.doneButton, SIGNAL(clicked()), this, SLOT(DoneButtonClicked())); 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))); connect(_ui.fileList, SIGNAL(itemActivated(QTreeWidgetItem*,int)),this, SLOT(processItem(QTreeWidgetItem*,int)));
@ -18,6 +19,12 @@ namespace Plugin
_ui.fileList->setRootIsDecorated(false); _ui.fileList->setRootIsDecorated(false);
_ui.fileList->setHeaderLabels(QStringList() << tr("Name") << tr("Size") << tr("Owner") << tr("Group") << tr("Time")); _ui.fileList->setHeaderLabels(QStringList() << tr("Name") << tr("Size") << tr("Owner") << tr("Group") << tr("Time"));
_ui.fileList->header()->setStretchLastSection(false); _ui.fileList->header()->setStretchLastSection(false);
// buttons
_ui.cdToParrent->setEnabled(false);
_ui.doneButton->setEnabled(false);
status = false;
} }
void CFtpSelection::ConnectButtonClicked() void CFtpSelection::ConnectButtonClicked()
@ -25,7 +32,9 @@ namespace Plugin
conn = new QFtp(this); conn = new QFtp(this);
connect(conn, SIGNAL(commandFinished(int,bool)), this, SLOT(FtpCommandFinished(int,bool))); connect(conn, SIGNAL(commandFinished(int,bool)), this, SLOT(FtpCommandFinished(int,bool)));
connect(conn, SIGNAL(listInfo(QUrlInfo)), this, SLOT(AddToList(QUrlInfo))); connect(conn, SIGNAL(listInfo(QUrlInfo)), this, SLOT(AddToList(QUrlInfo)));
#ifndef QT_NO_CURSOR
setCursor(Qt::WaitCursor);
#endif
QUrl url(_ui.url->text()); QUrl url(_ui.url->text());
if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) { if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) {
conn->connectToHost(_ui.url->text(), 21); conn->connectToHost(_ui.url->text(), 21);
@ -44,6 +53,9 @@ namespace Plugin
void CFtpSelection::FtpCommandFinished(int, bool error) void CFtpSelection::FtpCommandFinished(int, bool error)
{ {
#ifndef QT_NO_CURSOR
setCursor(Qt::ArrowCursor);
#endif
if (conn->currentCommand() == QFtp::ConnectToHost) if (conn->currentCommand() == QFtp::ConnectToHost)
{ {
if (error) if (error)
@ -64,6 +76,20 @@ namespace Plugin
conn->list(); 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 (conn->currentCommand() == QFtp::List)
{ {
if (isDirectory.isEmpty()) { if (isDirectory.isEmpty()) {
@ -82,7 +108,7 @@ namespace Plugin
item->setText(3, urlInfo.group()); item->setText(3, urlInfo.group());
item->setText(4, urlInfo.lastModified().toString("MMM dd yyyy")); 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); item->setIcon(0, pixmap);
isDirectory[urlInfo.name()] = urlInfo.isDir(); isDirectory[urlInfo.name()] = urlInfo.isDir();
@ -104,18 +130,58 @@ namespace Plugin
currentPath += name; currentPath += name;
conn->cd(name); conn->cd(name);
conn->list(); conn->list();
//TODO: cursor #ifndef QT_NO_CURSOR
setCursor(Qt::WaitCursor);
#endif
return; 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() 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;
} }
void CFtpSelection::CancelButtonClicked() 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();
}
} }
}

View file

@ -9,11 +9,12 @@
#define FTP_SELECTION_H #define FTP_SELECTION_H
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QUrl>
#include <QtGui/QDialog> #include <QtGui/QDialog>
#include <QtCore/QString> #include <QtCore/QString>
#include <QtGui/QWidget> #include <QtGui/QWidget>
#include <QtCore/Qfile>
#include <QtNetwork> #include <QtNetwork>
#include <QtCore/QUrl>
#include "ui_ftp_selection.h" #include "ui_ftp_selection.h"
@ -30,13 +31,15 @@ namespace Plugin {
QHash<QString, bool> isDirectory; QHash<QString, bool> isDirectory;
QString currentPath; QString currentPath;
private Q_SLOTS: private Q_SLOTS:
void cdToParent();
void processItem(QTreeWidgetItem*,int); void processItem(QTreeWidgetItem*,int);
void CancelButtonClicked();
void ConnectButtonClicked(); void ConnectButtonClicked();
void DoneButtonClicked(); void DoneButtonClicked();
void FtpCommandFinished(int, bool error); void FtpCommandFinished(int, bool error);
void AddToList(const QUrlInfo &urlInfo); void AddToList(const QUrlInfo &urlInfo);
public: public:
bool status;
QFile *file;
CFtpSelection(QWidget* parent = 0); CFtpSelection(QWidget* parent = 0);
~CFtpSelection() {} ~CFtpSelection() {}
}; };

View file

@ -0,0 +1,7 @@
<RCC>
<qresource prefix="translationManager">
<file>images/cdtoparent.png</file>
<file>images/dir.png</file>
<file>images/file.png</file>
</qresource>
</RCC>

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>383</width> <width>388</width>
<height>547</height> <height>560</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -19,7 +19,7 @@
<x>10</x> <x>10</x>
<y>10</y> <y>10</y>
<width>371</width> <width>371</width>
<height>501</height> <height>541</height>
</rect> </rect>
</property> </property>
<property name="title"> <property name="title">
@ -28,10 +28,10 @@
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBox_2">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>10</x>
<y>130</y> <y>130</y>
<width>371</width> <width>351</width>
<height>411</height> <height>361</height>
</rect> </rect>
</property> </property>
<property name="title"> <property name="title">
@ -40,7 +40,7 @@
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_4">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>10</x>
<y>20</y> <y>20</y>
<width>141</width> <width>141</width>
<height>21</height> <height>21</height>
@ -53,9 +53,9 @@
<widget class="QTreeWidget" name="fileList"> <widget class="QTreeWidget" name="fileList">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>10</x>
<y>40</y> <y>40</y>
<width>361</width> <width>331</width>
<height>311</height> <height>311</height>
</rect> </rect>
</property> </property>
@ -69,10 +69,10 @@
<widget class="QWidget" name="layoutWidget"> <widget class="QWidget" name="layoutWidget">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>1</x> <x>11</x>
<y>29</y> <y>29</y>
<width>361</width> <width>351</width>
<height>107</height> <height>101</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
@ -98,17 +98,20 @@
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
<property name="icon">
<iconset resource="ftp_selection.qrc">
<normaloff>:/translationManager/images/cdtoparent.png</normaloff>:/translationManager/images/cdtoparent.png</iconset>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget>
<widget class="QWidget" name="layoutWidget"> <widget class="QWidget" name="layoutWidget">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>10</x> <x>0</x>
<y>500</y> <y>500</y>
<width>361</width> <width>371</width>
<height>33</height> <height>33</height>
</rect> </rect>
</property> </property>
@ -130,6 +133,9 @@
</layout> </layout>
</widget> </widget>
</widget> </widget>
<resources/> </widget>
<resources>
<include location="ftp_selection.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

View file

@ -20,13 +20,13 @@ class CSourceDialog : public QDialog
Q_OBJECT Q_OBJECT
private: private:
Ui::SourceSelectionDialog _ui; Ui::SourceSelectionDialog _ui;
QListWidgetItem *selected_item;
private Q_SLOTS: private Q_SLOTS:
void OkButtonClicked(); void OkButtonClicked();
public: public:
CSourceDialog(QWidget *parent = 0); CSourceDialog(QWidget *parent = 0);
~CSourceDialog(){} ~CSourceDialog(){}
void setSourceOptions(map<QListWidgetItem*, int> options); void setSourceOptions(map<QListWidgetItem*, int> options);
QListWidgetItem *selected_item;
}; };
} }

View file

@ -380,7 +380,26 @@ void CMainWindow::mergeSingleFile()
{ {
CEditor* editor_window = qobject_cast<CEditor*>(_ui.mdiArea->currentSubWindow()); CEditor* editor_window = qobject_cast<CEditor*>(_ui.mdiArea->currentSubWindow());
CSourceDialog *dialog = new CSourceDialog(this); CSourceDialog *dialog = new CSourceDialog(this);
CFtpSelection* ftp_dialog;
map<QListWidgetItem*, int> methods; map<QListWidgetItem*, int> 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 // create items
QListWidgetItem* local_item = new QListWidgetItem(); QListWidgetItem* local_item = new QListWidgetItem();
local_item->setText("Local directory"); local_item->setText("Local directory");
@ -392,18 +411,22 @@ void CMainWindow::mergeSingleFile()
dialog->setSourceOptions(methods); dialog->setSourceOptions(methods);
dialog->show(); dialog->show();
dialog->exec(); dialog->exec();
// get the file for merge
if(dialog->selected_item == local_item) // Local directory if(dialog->selected_item == local_item) // Local directory
{
QString file_name;
if (_ui.mdiArea->subWindowList().size() > 0)
{ {
file_name = QFileDialog::getOpenFileName(this); 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 { } else {
return; return;
} }
if(QString(editor_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor
{
editor_window->activateWindow(); editor_window->activateWindow();
CEditorWorksheet* current_window = qobject_cast<CEditorWorksheet*>(editor_window); CEditorWorksheet* current_window = qobject_cast<CEditorWorksheet*>(editor_window);
if(current_window->windowFilePath() == file_name) if(current_window->windowFilePath() == file_name)
@ -416,16 +439,16 @@ void CMainWindow::mergeSingleFile()
error.showMessage(QString("The file: %1 has different columns from the current file in editor.").arg(file_name)); error.showMessage(QString("The file: %1 has different columns from the current file in editor.").arg(file_name));
error.exec(); error.exec();
} }
} if(dialog->selected_item == ftp_item)
} else if(dialog->selected_item == ftp_item) { // Ftp directory {
CFtpSelection* ftp_dialog = new CFtpSelection(this); if(!ftp_dialog->file->remove())
ftp_dialog->show(); {
ftp_dialog->exec(); QErrorMessage error;
} else { error.showMessage(QString("Please remove the file from ftp server manually. The file is located on the same directory with OVQT application."));
return; error.exec();
} }
}
} }
void CMainWindow::readSettings() void CMainWindow::readSettings()

View file

@ -70,7 +70,7 @@ private:
QMenu *windowMenu; QMenu *windowMenu;
QSignalMapper *windowMapper; QSignalMapper *windowMapper;
// config // config
map<string,bool> initialize_settings; QMap<string,bool> initialize_settings;
QList<QString> filters; QList<QString> filters;
QList<QString> languages; QList<QString> languages;
QString level_design_path; QString level_design_path;