#include "serverfilestreeview.h"
ServerFilesTreeView::ServerFilesTreeView(QWidget *parent) :
QWidget(parent)
{
initialize();
setUserDefineStyle();
setWinLayout();
sigAndSlotConnect();
}
ServerFilesTreeView::~ServerFilesTreeView()
{
release();
}
void ServerFilesTreeView::updatePath(QString path)
{
QString CurrentPath = QString("%1%2/%3").arg("Path=").arg(m_currentPath).arg(path);
//p_label_path->setText(CurrentPath);
}
void ServerFilesTreeView::clearItems()
{
while(p_fileList->topLevelItemCount() > 0)
{
delete p_fileList->topLevelItem(0);
}
}
void ServerFilesTreeView::initialize()
{
m_filename = new FileNameWidget();
m_filename->hide();
p_label_path = new QLabel();
p_label_path->setFixedHeight(30);
for(int i = 0; i< 7;i++)
{
p_pushButton[i] = new QPushButton();
}
p_frameLeft = new QFrame();
p_frameTop = new QFrame();
p_VlayoutRight = new QVBoxLayout();
p_VayoutMaint = new QVBoxLayout();
p_HlayoutLeft = new QHBoxLayout();
p_HlayoutBottom = new QHBoxLayout();
p_HlayoutTop = new QHBoxLayout();
p_fileList = new QTreeWidget();
p_fileList->setStyleSheet("QTreeView::item::selected{background-color:rgb(130, 255, 241);} QTreeView::item::hover{background-color:green;}");
p_fileList->setEnabled(false);
p_fileList->setRootIsDecorated(false);
p_fileList->setHeaderLabels(QStringList() << tr("Name") << tr("Size")<< tr("Date Modifiled"));
p_fileList->header()->setStretchLastSection(true);
p_progressDialog = new QProgressDialog(this);
}
void ServerFilesTreeView::release()
{
delete p_label_path;
delete p_progressDialog;
for(int i = 0; i< 7;i++)
{
delete p_pushButton[i];
}
delete p_fileList;
delete p_VlayoutRight;
delete p_HlayoutLeft;
delete p_frameTop;
delete p_frameLeft;
delete p_HlayoutTop;
delete p_HlayoutBottom;
delete p_VayoutMaint;
}
void ServerFilesTreeView::setUserDefineStyle()
{
p_pushButton[0]->setText("下载");
p_pushButton[1]->setText("复制");
p_pushButton[2]->setText("上传");
p_pushButton[3]->setText("重命名");
p_pushButton[4]->setText("删除");
p_pushButton[5]->setText("返回上级");
p_pushButton[6]->setText("新建文件夹");
p_HlayoutLeft->setSpacing(0);
p_HlayoutLeft->setContentsMargins(0,0,0,0);
p_HlayoutLeft->setSpacing(2);
p_HlayoutLeft->setContentsMargins(2,2,2,2);
p_HlayoutTop->setSpacing(0);
p_HlayoutTop->setContentsMargins(2,2,2,2);
resize(800,600);
}
void ServerFilesTreeView::setWinLayout()
{
p_HlayoutTop->addWidget(p_label_path);
p_frameTop->setLayout(p_HlayoutTop);
p_VlayoutRight->addWidget(p_pushButton[0]);
p_VlayoutRight->addWidget(p_pushButton[1]);
p_VlayoutRight->addWidget(p_pushButton[2]);
p_VlayoutRight->addWidget(p_pushButton[3]);
p_VlayoutRight->addWidget(p_pushButton[4]);
p_VlayoutRight->addWidget(p_pushButton[5]);
p_VlayoutRight->addWidget(p_pushButton[6]);
p_HlayoutLeft->addWidget(p_fileList);
p_frameLeft->setLayout(p_HlayoutLeft);
p_HlayoutBottom->addWidget(p_frameLeft,9);
p_HlayoutBottom->addLayout(p_VlayoutRight,1);
p_VayoutMaint->addWidget(p_frameTop);
p_VayoutMaint->addLayout(p_HlayoutBottom);
setLayout(p_VayoutMaint);
}
void ServerFilesTreeView::sigAndSlotConnect()
{
connect(p_fileList, SIGNAL(itemActivated(QTreeWidgetItem*,int)),this, SLOT(slotEnterDir(QTreeWidgetItem*,int)));
connect(p_fileList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),this, SLOT(slotEnableDownloadButton()));
connect(p_pushButton[5],SIGNAL(clicked()),this,SLOT(slotCdToParent()));
connect(p_pushButton[0],SIGNAL(clicked()),this,SLOT(slotDownloadFile()));
connect(p_pushButton[4],SIGNAL(clicked()),this,SLOT(slotDeleteFile()));
connect(p_pushButton[6],SIGNAL(clicked()),this,SLOT(slotMkdir()));
connect(p_pushButton[3],SIGNAL(clicked()),this,SLOT(slotRename()));
connect(p_pushButton[2],SIGNAL(clicked()),this,SLOT(slotUpFile()));
connect(m_filename,&FileNameWidget::signalFileName,this,[=](QString filename){
QString oldName = p_fileList->currentItem()->text(0);
m_filename->hide();
emit sigRename(oldName,filename);
});
connect(m_filename,&FileNameWidget::signalMakeDir,this,[=](QString filename){
emit sigMkdir(m_currentPath + "/"+filename);
m_filename->hide();
});
}
QString ServerFilesTreeView::formatSize(qint64 size)
{
QString result = "0";
double value = 0.00;
if(size > 0 && size < ValueMax_B)
{
result = QString("%1").arg(size)+QString("B");
}
else if((size >= ValueMax_B) && (size < ValueMax_KB))
{
value = size/ValueMax_B;
result = QString::number(value,'f',1)+QString("KB");
}
else if((size >= ValueMax_KB) && (size < ValueMax_MB))
{
value = size/ValueMax_KB;
result = QString::number(value,'f',1)+QString("MB");
}
else if((size >= ValueMax_MB) && (size < ValueMax_G))
{
value = size/ValueMax_MB;
result = QString::number(value,'f',1)+QString("G");
}
return result;
}
void ServerFilesTreeView::updateTreeWidget()
{
p_fileList->clear();
}
void ServerFilesTreeView::slotAddToList(const QUrlInfo &urlInfo)
{
QTreeWidgetItem *item = new QTreeWidgetItem;
item->setText(0, urlInfo.name());
if(urlInfo.isDir())
{
item->setText(1, QString(""));
}
else
{
item->setText(1, formatSize(urlInfo.size()));
}
item->setText(2, urlInfo.lastModified().toString("MMM dd yyyy"));
QPixmap pixmap(urlInfo.isDir() ? ":/images/dir.png" : ":/images/file.png");
item->setIcon(0, pixmap);
m_isDirectory[urlInfo.name()] = urlInfo.isDir();
if(urlInfo.isDir())
{
p_fileList->insertTopLevelItem(0,item);
}
else if(urlInfo.isFile())
{
int index = p_fileList->model()->rowCount();
p_fileList->insertTopLevelItem(index,item);
}
if (!p_fileList->currentItem())
{
p_fileList->setCurrentItem(p_fileList->topLevelItem(0));
p_fileList->setEnabled(true);
}
updatePath(p_fileList->currentItem()->text(0));
}
void ServerFilesTreeView::slotEnterDir(QTreeWidgetItem *item, int /*column*/)
{
QString name = item->text(0);
if (m_isDirectory.value(name))
{
p_fileList->clear();
m_isDirectory.clear();
m_currentPath += '/';
m_currentPath += name;
emit sigcdDir(name);
return;
}
}
void ServerFilesTreeView::slotCdToParent()
{
p_fileList->clear();
m_isDirectory.clear();
m_currentPath = m_currentPath.left(m_currentPath.lastIndexOf('/'));
if (m_currentPath.isEmpty())
{
updatePath("");
emit sigcdDir("/");
}
else
{
updatePath(m_currentPath);
emit sigcdDir(m_currentPath);
}
}
#include <QFileDialog>
#include <QDebug>
void ServerFilesTreeView::slotDownloadFile()
{
QString dir = QFileDialog::getExistingDirectory(this, tr("选择下载路径"), "/home", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
//QString filepath = QFileDialog::getExistingDirectory();
QString fileName = dir+"/"+p_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;
}
qDebug()<<"down path"<<fileName;
emit sigGetFile(fileName);
p_progressDialog->setLabelText(tr("Downloading %1...").arg(fileName));
p_progressDialog->exec();
}
void ServerFilesTreeView::slotDeleteFile()
{
QString fileName = p_fileList->currentItem()->text(0);
if(m_isDirectory.value(fileName))
{
fileName = m_currentPath + "/" +f
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 1、该项目是个人毕设项目源码,评审分达到95分,都经过严格调试,确保可以运行!放心下载使用。 该项目资源主要针对计算机、自动化等相关专业的学生或从业者下载使用,也可作为期末课程设计、课程大作业、毕业设计等。 2、具有较高的学习借鉴价值!基础能力强的可以在此基础上修改调整,以实现类似其他功能。 开发工具:Qt Creator 开发技术:QT,C++ 本文的功能需求主要体现在两个方面,一个是客户端功能,一个是服务器端功能。 客户端的功能主要有用户登录、上传文件、下载文件、浏览文件。在文件传输系统的客户端,首先进行初始化,初始化包括IP地址和端口号的输入,然后连接服务器,用户在登录界面输入登录信息进行登录,登录成功之后可以进行以下操作:用户在客户端请求发送文件上传,请求成功之后上传文件,用户请求文件下载,请求成功后下载文件,当文件下载成功后可以浏览文件。 服务器端的功能主要有用户登录、服务器配置、并发服务器、上传下载管理、系统日志。在文件传输系统的服务器端,用户需要先进行登录,只有输入正确的登录信息才能进行登录,在服务器的图形主界面上,可以进行相关配置,可以对管理员和用户信息进行添加,本文是支持多线程服务的,可以对多线程进行管理,包括设置线程数量,用户在服务器端可以对上传下载进行管理,主要是对用户的上传和下载权限进行管理,用户也可以在服务器端查看用户上传的文件,进行文件浏览,用户在服务器上负责监听
资源推荐
资源详情
资源评论
收起资源包目录
基于SSL协议的FTP文件传输系统设计与开发+sql数据库(毕设源码).zip (19个子文件)
项目说明.md 1KB
FtpClient_Tree
FtpClient_Tree.pro.user 40KB
FtpClient_Tree.pro.user.1a5ea46.3.3-pre1 33KB
FtpClient_Tree.pro 1KB
FileNameWidget.ui 4KB
FileNameWidget.h 599B
FileTool.h 369B
main.cpp 186B
source.qrc 173B
serverfilestreeview.cpp 9KB
FileNameWidget.cpp 872B
ftpclient.cpp 9KB
ftpclient.h 2KB
images
cdtoparent.png 120B
file.png 129B
dir.png 131B
usersdellappdatalocaltemptmpwkkdba 0B
FileTool.cpp 273B
serverfilestreeview.h 2KB
共 19 条
- 1
资源评论
- ipeqgt2024-01-18非常有用的资源,可以直接使用,对我很有用,果断支持!
z同学的编程之路
- 粉丝: 1812
- 资源: 2129
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功