#include <QtGui>
#include <QtNetwork>
#include "mainwindow.h"
#include"showfile.h"
#include"util.h"
MainWindow::MainWindow(QWidget *parent)
: QDialog(parent), fileTrans(0), networkSession(0)
{
InitView();
InitSlot();
}
QSize MainWindow::sizeHint() const
{
return QSize(800, 600);
}
//初始化窗口部件
void MainWindow::InitView()
{
serverLabel = new QLabel(tr("服务器:"));
serverLineEdit = new QLineEdit("127.0.0.1");
serverLabel->setBuddy(serverLineEdit);
userNameLabel=new QLabel(tr("用户名:"));
userNameLineEdit=new QLineEdit();
userNameLabel->setBuddy(userNameLineEdit);
passwordLabel=new QLabel(tr("密码:"));
passwordLineEdit=new QLineEdit();
passwordLineEdit->setEchoMode(QLineEdit::Password);
passwordLabel->setBuddy(passwordLineEdit);
connectButton = new QPushButton(tr("连接"));
connectButton->setDefault(true);
clientPathLabel=new QLabel(tr("本地:"));
clientPathLineEdit=new QLineEdit();
clientPathLineEdit->setEnabled(false);
clientPathLabel->setBuddy(clientPathLineEdit);
clientCdToParentButton = new QPushButton;
clientCdToParentButton->setIcon(QPixmap(":/images/cdtoparent.png"));
clientCdToParentButton->setEnabled(false);
clientFileList = new ShowFile;
clientFileList->setEnabled(true);
clientFileList->setRootIsDecorated(false);
clientFileList->setHeaderLabels(QStringList() << tr("名称") << tr("大小") << tr("所属用户") << tr("修改日期"));
clientFileList->header()->setStretchLastSection(false);
serverPathLabel=new QLabel(tr("远程:"));
serverPathLineEdit=new QLineEdit();
serverPathLineEdit->setDisabled(true);
serverPathLabel->setBuddy(serverPathLineEdit);
serverCdToParentButton = new QPushButton;
serverCdToParentButton->setIcon(QPixmap(":/images/cdtoparent.png"));
serverCdToParentButton->setEnabled(false);
serverFileList = new ShowFile;
serverFileList->setEnabled(true);
serverFileList->setRootIsDecorated(false);
serverFileList->setHeaderLabels(QStringList() << tr("名称") << tr("大小") << tr("用户") << tr("修改日期"));
serverFileList->header()->setStretchLastSection(false);
statusLabel = new QLabel(tr("请输入服务器IP及用户名、密码."));
quitButton = new QPushButton(tr("退出"));
buttonBox = new QDialogButtonBox;
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
progressDialog = new QProgressDialog(this);
QHBoxLayout *hLayout1 = new QHBoxLayout;
hLayout1->addWidget(serverLabel);
hLayout1->addWidget(serverLineEdit);
hLayout1->addWidget(userNameLabel);
hLayout1->addWidget(userNameLineEdit);
hLayout1->addWidget(passwordLabel);
hLayout1->addWidget(passwordLineEdit);
hLayout1->addWidget(connectButton);
// QSplitter *splitter=new QSplitter(Qt::Horizontal);
// QWidget *widget = new QWidget(splitter);
QHBoxLayout *hLayout211 = new QHBoxLayout;
hLayout211->addWidget(clientPathLabel);
hLayout211->addWidget(clientPathLineEdit);
hLayout211->addWidget(clientCdToParentButton);
QVBoxLayout *vLayout21=new QVBoxLayout();
vLayout21->addLayout(hLayout211);
vLayout21->addWidget(clientFileList);
// splitter->addWidget(widget);
// QWidget *widget1 = new QWidget(splitter);
QHBoxLayout *hLayout221 = new QHBoxLayout;
hLayout221->addWidget(serverPathLabel);
hLayout221->addWidget(serverPathLineEdit);
hLayout221->addWidget(serverCdToParentButton);
QVBoxLayout *vLayout22=new QVBoxLayout();
vLayout22->addLayout(hLayout221);
vLayout22->addWidget(serverFileList);
// splitter->addWidget(widget1);
QHBoxLayout *hLayout2 = new QHBoxLayout;
hLayout2->addLayout(vLayout21);
hLayout2->addLayout(vLayout22);
// QSplitter *splitter1=new QSplitter(Qt::Vertical,splitter);
// QSplitter *splitter2=new QSplitter(Qt::Vertical,splitter);
// QSplitter *splitter11=new QSplitter(Qt::Horizontal,splitter1);
// splitter11->addWidget(clientPathLabel);
// splitter11->addWidget(clientPathLineEdit);
// splitter1->addWidget(clientFileList);
// QSplitter *splitter12=new QSplitter(Qt::Horizontal,splitter2);
// splitter12->addWidget(serverPathLabel);
// splitter12->addWidget(serverPathLineEdit);
// splitter12->addWidget(serverCdToParentButton);
// splitter2->addWidget(serverFileList);
QHBoxLayout *hLayout3 = new QHBoxLayout;
hLayout3->addWidget(statusLabel);
hLayout3->addWidget(buttonBox);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(hLayout1);
mainLayout->addLayout(hLayout2);
mainLayout->addLayout(hLayout3);
setLayout(mainLayout);
downloadAction = new QAction(tr("下载"), this);
uploadAction = new QAction(tr("上传"), this);
uploadAction->setEnabled(false);
setWindowTitle(tr("NFDS"));
QString clientRoot = "/";
QDir rootDir(clientRoot);
clientPathLineEdit->setText(clientRoot);
QStringList string;
string << "*" ;
QFileInfoList list=rootDir.entryInfoList(string,QDir::AllEntries|QDir::NoDotAndDotDot,QDir::DirsFirst);
clientFileList->showClientFile(list,clientIsDir);
}
//初始化信号槽
void MainWindow::InitSlot()
{
connect(clientFileList,SIGNAL(itemPressed(QTreeWidgetItem*,int)),
this,SLOT(SlotClientRbnClicked(QTreeWidgetItem*,int)));
connect(clientFileList, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
this, SLOT(SlotClientToChild(QTreeWidgetItem*,int)));
connect(serverFileList, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
this, SLOT(SlotServerToChild(QTreeWidgetItem*,int)));
connect(serverFileList,SIGNAL(itemPressed(QTreeWidgetItem *, int)),
this,SLOT(SlotServerRbnClicked(QTreeWidgetItem *, int)));
connect(connectButton, SIGNAL(clicked()), this, SLOT(SlotConnectOrDisconnect()));
connect(clientCdToParentButton,SIGNAL(clicked()), this, SLOT(SlotClientToParent()));
connect(serverCdToParentButton, SIGNAL(clicked()), this, SLOT(SlotServerToParent()));
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
connect(downloadAction, SIGNAL(triggered()), this, SLOT(SlotDownload()));
connect(uploadAction, SIGNAL(triggered()), this, SLOT(SlotUpload()));
}
//![0]
void MainWindow::SlotConnectOrDisconnect()
{
if (fileTrans) {
fileTrans->abort();
fileTrans->deleteLater();
fileTrans = 0;
serverFileList->clear();
serverPathLineEdit->clear();
//![0]
serverFileList->setEnabled(false);
serverCdToParentButton->setEnabled(false);
connectButton->setEnabled(true);
connectButton->setText(tr("连接"));
uploadAction->setEnabled(false);
#ifndef QT_NO_CURSOR
setCursor(Qt::ArrowCursor);
#endif
statusLabel->setText(tr("请输入服务器IP及用户名、密码."));
return;
}
#ifndef QT_NO_CURSOR
setCursor(Qt::WaitCursor);
#endif
if (!networkSession || !networkSession->isOpen())
{
if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
if (!networkSession) {
// Get saved network configuration
QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
settings.beginGroup(QLatin1String("QtNetwork"));
const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
settings.endGroup();
// If the saved network configuration is not currently discovered use the system default
QNetworkConfiguration config = manager.configurationFromI
基于qt实现的简单FTP客户端
5星 · 超过95%的资源 需积分: 49 124 浏览量
2015-07-06
22:48:53
上传
评论 7
收藏 32KB RAR 举报
秋分冬至
- 粉丝: 6
- 资源: 2
最新资源
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
- 音乐展示网页、基于Stenography的图像数字水印添加与提取,以及基于颜色矩和Tamura算法的图像相似度评估算法py源码
- 基于EmguCV(OpenCV .net封装),图像数字水印加解密算法的实现,其中包含最低有效位算法,离散傅里叶变换算法+文档书
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈