#include "filemanager.h"
#include "ui_filemanager.h"
#include<QDebug>
FileManager::FileManager(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::FileManager)
{
ui->setupUi(this);
connect(this,SIGNAL(Init()),this,SLOT(Root()));
connect(ui->lwt_File,SIGNAL(itemDoubleClicked(QListWidgetItem*)),this,SLOT(ItemDoubleClicked(QListWidgetItem*)));
connect(ui->btn_Root,SIGNAL(clicked()),this,SLOT(Root()));
connect(ui->btn_UDisk,SIGNAL(clicked()),this,SLOT(UDisk()));
connect(ui->btn_Copy,SIGNAL(clicked()),this,SLOT(Copy()));
connect(ui->btn_Cut,SIGNAL(clicked()),this,SLOT(Cut()));
connect(ui->btn_Paste,SIGNAL(clicked()),this,SLOT(Paste()));
connect(ui->btn_Delete,SIGNAL(clicked()),this,SLOT(Delete()));
connect(ui->btn_Enter,SIGNAL(clicked()),this,SLOT(Enter()));
connect(ui->btn_Up,SIGNAL(clicked()),this,SLOT(Up()));
connect(ui->btn_Exit,SIGNAL(clicked()),this,SLOT(Exit()));
UDiskPath=NULL;
copyFile=NULL;
copyFlag=0;
emit Init();
}
FileManager::~FileManager()
{
delete ui;
}
void FileManager::ShowFile(QDir dir)
{
ui->lwt_File->clear();
QFileInfoList fileList=dir.entryInfoList();
for (int i=0;i<dir.count();i++)
{
QIcon icon;
QListWidgetItem *item=new QListWidgetItem (fileList.at(i).fileName());
if (fileList.at(i).isDir())
icon.addFile(QString::fromUtf8(":/Pic/Menu"), QSize(), QIcon::Normal, QIcon::Off);
else icon.addFile(QString::fromUtf8(":/Pic/File"), QSize(), QIcon::Normal, QIcon::Off);
item->setIcon(icon);
ui->lwt_File->addItem(item);
}
}
void FileManager::ChangePath(QString path)
{
dir.setPath(path);
dirPath=dir.absolutePath();
ui->let_Menu->setText(dir.absolutePath());
}
void FileManager::Go()
{
QFileInfo file;
if (ui->let_Menu->text()==dirPath)
{
if (ui->lwt_File->selectedItems().count()>0)
file.setFile(dir,ui->lwt_File->selectedItems().first()->text());
else file.setFile(dir.dirName());
}
else {
file.setFile(ui->let_Menu->text());
if (!file.isDir())
if (ui->lwt_File->selectedItems().count()>0)
file.setFile(dir,ui->lwt_File->selectedItems().first()->text());
else file.setFile(dir.dirName());
}
if (file.isDir())
{
ChangePath(file.filePath());
ShowFile(dir);
}
else {
ChangePath(file.path());
ShowFile(dir);
QProcess *pro=new QProcess();
pro->start(file.filePath());
}
}
void FileManager::PasteFile(QString oldFileName, QString newFileName)
{
QFileInfo file(oldFileName);
if (file.isDir())
{
QDir oldMenu,newMenu;
oldMenu.setPath(oldFileName);
newMenu.mkdir(newFileName);
QFileInfoList fileList=oldMenu.entryInfoList();
for (int i=2;i<fileList.count();i++)
PasteFile(oldFileName+"/"+fileList.at(i).fileName(),newFileName+"/"+fileList.at(i).fileName());
}
else
QFile::copy(oldFileName,newFileName);
}
void FileManager::DeleteFile(QString fileName)
{
QFileInfo file(fileName);
if (file.isDir())
{
QDir fileDir;
fileDir.setPath(fileName);
QFileInfoList fileList=fileDir.entryInfoList();
for (int i=2;i<fileList.count();i++)
DeleteFile(fileName+"/"+fileList.at(i).fileName());
fileDir.rmdir(fileName);
}
else
QFile::remove(fileName);
}
void FileManager::Root()
{
ChangePath("/");
ShowFile(dir);
}
void FileManager::UDisk()
{
if (UDiskPath==NULL)
return;
ChangePath(*UDiskPath);
ShowFile(dir);
}
void FileManager::Copy()
{
GetCopyFile(0);
}
void FileManager::Cut()
{
GetCopyFile(1);
}
void FileManager::Paste()
{
if (copyFile->filePath=="/")
copyFile->filePath="";
if (dirPath=="/")
dirPath="";
PasteFile(copyFile->filePath+"/"+copyFile->fileName,dirPath+"/"+copyFile->fileName);
if (copyFile->filePath=="")
copyFile->filePath="/";
if (dirPath=="")
dirPath="/";
dir.setPath(dirPath);
ShowFile(dir);
}
void FileManager::Delete()
{
if (ui->lwt_File->selectedItems().count()<=0)
return;
if (dirPath=="/")
dirPath="";
DeleteFile(dirPath+"/"+ui->lwt_File->selectedItems().first()->text());
if (dirPath=="")
dirPath="/";
dir.setPath(dirPath);
ShowFile(dir);
}
void FileManager::Enter()
{
Go();
}
void FileManager::Up()
{
dir.cd("..");
ChangePath(dir.path());
ShowFile(dir);
}
void FileManager::Exit()
{
exit(0);
}
void FileManager::ItemDoubleClicked(QListWidgetItem*)
{
Go();
}
void FileManager::GetCopyFile(int function)
{
if (ui->lwt_File->selectedItems().count()<=0)
return;
copyFlag=function;
copyFile=new CopyFile(dirPath,ui->lwt_File->selectedItems().first()->text());
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于QT+Linux的简易文件管理器包括文件(夹)的创建删除复制粘贴.zip
共10个文件
cpp:2个
jpg:2个
user:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 45 浏览量
2023-12-27
16:02:02
上传
评论
收藏 11KB ZIP 举报
温馨提示
基于QT+Linux的简易文件管理器包括文件(夹)的创建删除复制粘贴.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于QT+Linux的简易文件管理器包括文件(夹)的创建删除复制粘贴.zip (10个子文件)
Y-123
2332424
FileManager
filemanager.ui 4KB
FileManager.pro.user 17KB
main.cpp 178B
FileManager.pro 395B
File.jpg 1KB
filemanager.cpp 5KB
Pic.qrc 146B
Menu.jpg 1KB
filemanager.h 1KB
FileManager.pro.user.1.3 28KB
G
共 10 条
- 1
资源评论
m0_74456535
- 粉丝: 89
- 资源: 725
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功