├── HTYFileManager ├── HTYFileManager.pro ├── ID3.png ├── README.md ├── desktop_property.jpg ├── files.qrc ├── form_disk.cpp ├── form_disk.h ├── form_disk.ui ├── homepage.png ├── icon.png ├── iconpreview.cpp ├── iconpreview.h ├── install.sh ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── preview.jpg ├── preview_table.png ├── previewbg.jpg ├── propertydesktop.cpp ├── propertydesktop.h └── propertydesktop.ui /HTYFileManager: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonichy/HTYFileManager/ab1122fcf9c78bdb8504e5cf0169326280039e38/HTYFileManager -------------------------------------------------------------------------------- /HTYFileManager.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | TARGET = HTYFileManager 6 | TEMPLATE = app 7 | 8 | SOURCES += main.cpp\ 9 | mainwindow.cpp \ 10 | propertydesktop.cpp \ 11 | iconpreview.cpp \ 12 | form_disk.cpp 13 | 14 | HEADERS += mainwindow.h \ 15 | propertydesktop.h \ 16 | iconpreview.h \ 17 | form_disk.h 18 | 19 | FORMS += mainwindow.ui \ 20 | propertydesktop.ui \ 21 | form_disk.ui 22 | 23 | RESOURCES += \ 24 | files.qrc 25 | -------------------------------------------------------------------------------- /ID3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonichy/HTYFileManager/ab1122fcf9c78bdb8504e5cf0169326280039e38/ID3.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Qt 海天鹰文件管理器 2 | Linux 平台基于 Qt 的文件管理程序,文件操作需谨慎,个人软件仅供学习,若有损失概不负责。 3 | 已编译好的 HTYFileManager 程序适用 64 位 Linux 系统 Qt5.15 环境,双击运行,其他版本请自行编译。 4 | install.sh 用于生成和复制 desktop 到用户目录,以便在启动菜单显示。 5 | ![alt](homepage.png) 6 | ![alt](preview.jpg) 7 | ![alt](preview_table.png) 8 | 9 | 支持:文件右键菜单新增移动到、复制到、设为壁纸。 10 | 已知问题:无法获取挂载的分区,无法删除多个文件,无法删除非空的文件夹。 11 | 12 | ### 支持MP3的ID3V1信息 13 | ![alt](ID3.png) 14 | 15 | ### 支持一键创建 desktop 快捷方式和修改 desktop 属性。 16 | ![alt](desktop_property.jpg) 17 | 18 | ### 支持压缩和解压缩: 19 | 压缩功能需要安装 zip:sudo apt-get install zip 20 | 解压缩功能需要安装 unzip:sudo apt-get install unzip -------------------------------------------------------------------------------- /desktop_property.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonichy/HTYFileManager/ab1122fcf9c78bdb8504e5cf0169326280039e38/desktop_property.jpg -------------------------------------------------------------------------------- /files.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | icon.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /form_disk.cpp: -------------------------------------------------------------------------------- 1 | #include "form_disk.h" 2 | #include "ui_form_disk.h" 3 | #include 4 | #include 5 | 6 | Form_disk::Form_disk(QWidget *parent) : 7 | QWidget(parent), 8 | ui(new Ui::Form_disk) 9 | { 10 | ui->setupUi(this); 11 | ui->label_icon->setPixmap(QIcon::fromTheme("drive-harddisk").pixmap(70,70)); 12 | } 13 | 14 | Form_disk::~Form_disk() 15 | { 16 | delete ui; 17 | } 18 | 19 | void Form_disk::init() 20 | { 21 | QFontMetrics fontMetrics(ui->label->font()); 22 | QString name_elide = fontMetrics.elidedText(name, Qt::ElideRight, ui->label->width()); 23 | ui->label->setText(name_elide); 24 | ui->label->setToolTip(name); 25 | qint64 bytesUsed = bytesTotal - bytesFree; 26 | ui->label_bytes->setText(BS(bytesUsed) + " / " + BS(bytesTotal)); 27 | ui->progressBar->setRange(0, 100); 28 | int value = 100 * bytesUsed / bytesTotal; 29 | //qDebug() << value; 30 | ui->progressBar->setValue(value); 31 | QString style; 32 | if(value < 60){ 33 | style = "QProgressBar { border: 1px solid gray; border-radius: 5px; background: white; }" 34 | "QProgressBar::chunk { background-color: dodgerblue; }"; 35 | }else if(value < 80){ 36 | style = "QProgressBar { border: 1px solid gray; border-radius: 5px; background: white; }" 37 | "QProgressBar::chunk { background-color: orange; }"; 38 | }else{ 39 | style = "QProgressBar { border: 1px solid gray; border-radius: 5px; background: white; }" 40 | "QProgressBar::chunk { background-color: red; }"; 41 | } 42 | ui->progressBar->setStyleSheet(style); 43 | } 44 | 45 | QString Form_disk::BS(qint64 b) 46 | { 47 | QString s = ""; 48 | if (b > 999999999) { 49 | s = QString::number(b/(1024*1024*1024)) + " GB"; 50 | } else { 51 | if (b > 999999){ 52 | s = QString::number(b/(1024*1024)) + " MB"; 53 | } else { 54 | if (b > 999) { 55 | s = QString::number(b/1024) + " KB"; 56 | } else { 57 | s = QString::number(b)+" B"; 58 | } 59 | } 60 | } 61 | return s; 62 | } -------------------------------------------------------------------------------- /form_disk.h: -------------------------------------------------------------------------------- 1 | #ifndef FORM_DISK_H 2 | #define FORM_DISK_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class Form_disk; 8 | } 9 | 10 | class Form_disk : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit Form_disk(QWidget *parent = 0); 16 | ~Form_disk(); 17 | Ui::Form_disk *ui; 18 | qint64 bytesFree, bytesTotal; 19 | QString mountPath, name; 20 | QByteArray device, fileSystemType; 21 | void init(); 22 | 23 | private: 24 | QString BS(qint64 b); 25 | 26 | }; 27 | 28 | #endif // FORM_DISK_H -------------------------------------------------------------------------------- /form_disk.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form_disk 4 | 5 | 6 | 7 | 0 8 | 0 9 | 120 10 | 150 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | background: transparent; 18 | 19 | 20 | 21 | 0 22 | 23 | 24 | 5 25 | 26 | 27 | 0 28 | 29 | 30 | 5 31 | 32 | 33 | 5 34 | 35 | 36 | 37 | 38 | 0 39 | 40 | 41 | 10 42 | 43 | 44 | 45 | 46 | 47 | 70 48 | 70 49 | 50 | 51 | 52 | 53 | 70 54 | 70 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | TextLabel 68 | 69 | 70 | Qt::AlignCenter 71 | 72 | 73 | 74 | 75 | 76 | 77 | TextLabel 78 | 79 | 80 | Qt::AlignCenter 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 16777215 89 | 10 90 | 91 | 92 | 93 | border: 1px solid gray; 94 | border-radius: 5px; 95 | 96 | 97 | 24 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /homepage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonichy/HTYFileManager/ab1122fcf9c78bdb8504e5cf0169326280039e38/homepage.png -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonichy/HTYFileManager/ab1122fcf9c78bdb8504e5cf0169326280039e38/icon.png -------------------------------------------------------------------------------- /iconpreview.cpp: -------------------------------------------------------------------------------- 1 | #include "iconpreview.h" 2 | #include 3 | #include 4 | #include 5 | 6 | IconPreview::IconPreview() 7 | { 8 | 9 | } 10 | 11 | QIcon IconPreview::getIcon(QString path) 12 | { 13 | QImageReader reader(path); 14 | reader.setAutoTransform(true); 15 | QImage image = reader.read(); 16 | QPixmap pixmap = QPixmap::fromImage(image.scaled(QSize(200,200), Qt::KeepAspectRatio)); 17 | QFileInfo FI(path); 18 | if(FI.isSymLink()){ 19 | QPainter painter(&pixmap); 20 | painter.drawPixmap(100, 100, QIcon::fromTheme("emblem-symbolic-link").pixmap(100, 100, QIcon::Normal, QIcon::On)); 21 | } 22 | return QIcon(pixmap); 23 | } -------------------------------------------------------------------------------- /iconpreview.h: -------------------------------------------------------------------------------- 1 | #ifndef ICONPREVIEW_H 2 | #define ICONPREVIEW_H 3 | 4 | #include 5 | 6 | class IconPreview 7 | { 8 | 9 | public: 10 | IconPreview(); 11 | QIcon getIcon(QString path); 12 | 13 | }; 14 | 15 | #endif // ICONPREVIEW_H -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | filename=HTYFileManager 2 | s="[Desktop Entry]\nName=海天鹰文件管理器\nComment=海天鹰文件管理器\nExec=`pwd`/$filename %u\nIcon=`pwd`/icon.png\nPath=`pwd`\nTerminal=false\nType=Application\nMimeType=inode/directory;\nCategories=System;" 3 | echo -e $s > $filename.desktop 4 | cp `pwd`/$filename.desktop ~/.local/share/applications/$filename.desktop -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | // 日志 6 | void writeLog(QString s){ 7 | QDateTime currentDateTime = QDateTime::currentDateTime(); 8 | s = "[" + currentDateTime.toString("yyyy/MM/dd HH:mm:ss") + "] " + s + "\n"; 9 | QFile file(QApplication::applicationDirPath() + "/log.txt"); 10 | if (file.open(QFile::WriteOnly | QIODevice::Append)) { 11 | file.write(s.toUtf8()); 12 | file.close(); 13 | } 14 | } 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | QApplication a(argc, argv); 19 | a.setOrganizationName("HTY"); 20 | a.setApplicationName("HTYFileManager"); 21 | qSetMessagePattern("[ %{file}: %{line} ] %{message}"); 22 | 23 | QString log = ""; 24 | for(int i=0; i 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | MainWindow::MainWindow(QWidget *parent) : 31 | QMainWindow(parent), 32 | ui(new Ui::MainWindow), 33 | settings(QCoreApplication::organizationName(), QCoreApplication::applicationName()) 34 | { 35 | ui->setupUi(this); 36 | readSettings(); 37 | isShowHidden = false; 38 | setStyleSheet("#listWidget { background-image:url(bg.jpg); }" 39 | "QListWidget::item { background:transparent; }" 40 | "QListWidget::item:selected { background: rgba(0,0,0,30); color: blue;} "); 41 | ui->tableWidget->setVisible(false); 42 | ui->action_icon->setIcon(style()->standardIcon(QStyle::SP_FileDialogListView)); 43 | QActionGroup *AG = new QActionGroup(this); 44 | AG->addAction(ui->action_icon); 45 | AG->addAction(ui->action_list); 46 | 47 | dirTrash = QDir::homePath() + "/.local/share/Trash/files"; 48 | dirTrashInfo = QDir::homePath() + "/.local/share/Trash/info"; 49 | lineEdit_location = new QLineEdit(path, this); 50 | ui->mainToolBar->addWidget(lineEdit_location); 51 | connect(lineEdit_location, SIGNAL(returnPressed()), this, SLOT(lineEditLocationReturnPressed())); 52 | lineEdit_search = new QLineEdit("", this); 53 | lineEdit_search->setPlaceholderText("搜索"); 54 | QAction *action_clear_lineEditSearch = new QAction; 55 | action_clear_lineEditSearch->setIcon(QIcon::fromTheme("edit-clear")); 56 | connect(action_clear_lineEditSearch, &QAction::triggered, [=]{ 57 | lineEdit_search->clear(); 58 | genList(path); 59 | }); 60 | lineEdit_search->addAction(action_clear_lineEditSearch, QLineEdit::TrailingPosition); 61 | lineEdit_search->setFixedWidth(100); 62 | ui->mainToolBar->addWidget(lineEdit_search); 63 | //connect(lineEdit_search, SIGNAL(textChanged(QString)), this, SLOT(search())); 64 | connect(lineEdit_search, SIGNAL(returnPressed()), this, SLOT(search())); 65 | 66 | genHomePage(); 67 | 68 | //connect(ui->listWidget,SIGNAL(clicked(QModelIndex)),this,SLOT(listWidgetClicked(QModelIndex))); 69 | connect(ui->listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(listWidgetItemClicked(QListWidgetItem*))); 70 | connect(ui->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(listWidgetItemSelectionChanged())); 71 | connect(ui->listWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(listWidgetDoubleClicked(QModelIndex))); 72 | connect(ui->listWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenu(QPoint))); 73 | connect(ui->listWidget, SIGNAL(itemChanged(QListWidgetItem)), this, SLOT(listWidgetItemChanged(QListWidgetItem))); 74 | 75 | connect(ui->listWidget_partition, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuPartition(QPoint))); 76 | 77 | verticalScrollBar = ui->listWidget->verticalScrollBar(); 78 | connect(verticalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(verticalScrollBarValueChanged(int))); 79 | /* 80 | QShortcut *shortCutReturnListWidget = new QShortcut(QKeySequence(Qt::Key_Return), ui->listWidget); 81 | shortCutReturnListWidget->setObjectName("shortCutReturnListWidget"); 82 | connect(shortCutReturnListWidget, SIGNAL(activated()),this, SLOT(enterOpen())); 83 | 84 | QShortcut *shortCutEnterListWidget = new QShortcut(QKeySequence(Qt::Key_Enter), ui->listWidget); 85 | shortCutEnterListWidget->setObjectName("shortCutEnterListWidget"); 86 | connect(shortCutEnterListWidget, SIGNAL(activated()),this, SLOT(enterOpen())); 87 | 88 | QShortcut *shortCutReturnTableWidget = new QShortcut(QKeySequence(Qt::Key_Return), ui->tableWidget); 89 | shortCutReturnTableWidget->setObjectName("shortCutReturnTableWidget"); 90 | connect(shortCutReturnTableWidget, SIGNAL(activated()),this, SLOT(enterOpen())); 91 | 92 | QShortcut *shortCutEnterTableWidget = new QShortcut(QKeySequence(Qt::Key_Enter), ui->tableWidget); 93 | shortCutEnterTableWidget->setObjectName("shortCutEnterTableWidget"); 94 | connect(shortCutEnterTableWidget, SIGNAL(activated()),this, SLOT(enterOpen())); 95 | */ 96 | connect(new QShortcut(QKeySequence(Qt::Key_Backspace), this), SIGNAL(activated()), this, SLOT(on_action_back_triggered())); 97 | connect(new QShortcut(QKeySequence(Qt::Key_Delete), this), SIGNAL(activated()), this, SLOT(trashDelete())); 98 | connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_C), this), SIGNAL(activated()), this, SLOT(copy())); 99 | connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_V), this), SIGNAL(activated()), this, SLOT(paste())); 100 | connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_H), this), SIGNAL(activated()), this, SLOT(switchHidden())); 101 | connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Plus), this), SIGNAL(activated()), this, SLOT(zoomIn())); 102 | connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Minus), this), SIGNAL(activated()), this, SLOT(zoomOut())); 103 | connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_0), this), SIGNAL(activated()), this, SLOT(zoom1())); 104 | connect(new QShortcut(QKeySequence(Qt::Key_F2), this), SIGNAL(activated()), this, SLOT(rename())); 105 | connect(new QShortcut(QKeySequence(Qt::Key_F5), this), SIGNAL(activated()), this, SLOT(refresh())); 106 | 107 | 108 | QStringList header; 109 | header << "名称" << "修改时间" << "大小" << "类型" << "歌名" << "歌手" << "专辑" << "年代" << "注释"; 110 | ui->tableWidget->setHorizontalHeaderLabels(header); 111 | connect(ui->tableWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(tableWidgetDoubleClicked(QModelIndex))); 112 | connect(ui->tableWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(viewContextMenuTV(QPoint))); 113 | 114 | dialogPD = new PropertyDesktop(this); 115 | connect(dialogPD, SIGNAL(accepted()), dialogPD, SLOT(saveDesktop())); 116 | 117 | sortMenu = new QMenu(this); 118 | action_sortName = new QAction(sortMenu); 119 | action_sortSize = new QAction(sortMenu); 120 | action_sortType = new QAction(sortMenu); 121 | action_sortTime = new QAction(sortMenu); 122 | action_sortName->setText("名称"); 123 | action_sortSize->setText("大小"); 124 | action_sortType->setText("类型"); 125 | action_sortTime->setText("修改时间"); 126 | action_sortName->setCheckable(true); 127 | action_sortSize->setCheckable(true); 128 | action_sortType->setCheckable(true); 129 | action_sortTime->setCheckable(true); 130 | action_sortName->setChecked(true); 131 | QActionGroup *actionGroupSort = new QActionGroup(this); 132 | sortMenu->addAction(actionGroupSort->addAction(action_sortName)); 133 | sortMenu->addAction(actionGroupSort->addAction(action_sortSize)); 134 | sortMenu->addAction(actionGroupSort->addAction(action_sortType)); 135 | sortMenu->addAction(actionGroupSort->addAction(action_sortTime)); 136 | 137 | QStringList args = QApplication::arguments(); 138 | qDebug() << args; 139 | if (args.length() > 1) { 140 | path = args.at(1); 141 | if (path.startsWith("file://")) { 142 | QUrl url(args.at(1)); 143 | path = url.toLocalFile(); 144 | } 145 | qDebug() << path; 146 | if (!path.contains("/")) { 147 | QEventLoop loop; 148 | QProcess *process = new QProcess; 149 | process->start("pwd"); 150 | connect(process, &QProcess::readyReadStandardOutput, [=, &loop](){ 151 | QString pwd = process->readAllStandardOutput().trimmed(); 152 | path = pwd + "/" +path; 153 | qDebug() << path; 154 | loop.quit(); 155 | }); 156 | loop.exec(); 157 | } 158 | lineEdit_location->setText(path); 159 | lineEditLocationReturnPressed(); 160 | ui->computerWidget->hide(); 161 | if (ui->action_icon->isChecked()) 162 | ui->listWidget->show(); 163 | if (ui->action_list->isChecked()) 164 | ui->tableWidget->show(); 165 | } 166 | } 167 | 168 | MainWindow::~MainWindow() 169 | { 170 | delete ui; 171 | } 172 | 173 | void MainWindow::on_action_changelog_triggered() 174 | { 175 | QString s = "2.12\n2021-11\n增加打开方式,支持设置默认APP。\n修改默认终端x-terminal-emulator通用。\n\n2.11\n2021-08\n恢复直接删除(不进回收站),修复没有写路径参数取不到路径无法删除的问题。\n\n2.10\n2020-06\n文件夹排在前面。\n实现图标模式排序。\n实现搜索(过滤)功能。\n修复盘符文字太宽挤开图标。\n\n2.9\n2020-04\n适配虚拟路径:trash:\\\\\\。\n\n2.8\n2020-03\n增加Git项目打包zip,tar.gz。\n\n2.7\n2019-09\n增加分区属性窗口。\n自定义分区控件,增加分区进度条。\n2019-07\n简化打开文件。\nresize自动滚动到选中文件的第一个。\n修复回收站文件还原没有刷新。\n使用Qt内部方法创建链接,识别链接并绘制链接角标。\n增加缩放快捷键。\n\n2.6\n2019-06\n增加:隐藏分区,取消隐藏分区功能。\n\n2.5\n2019-05\n修复:复制文件显示名而不是真实文件名导致粘贴失败的问题。\n修复:desktop属性窗口主题图标无法显示的问题。\n区分文件属性和文件夹属性。\n\n2.4\n2019-04\n导航增加系统盘。\n关闭时保存窗口位置和大小。\ndesktop属性窗口增加文件路径(只读)。\n粘贴文件后修改文件时间(>=5.10)。\n增加创建链接。\n\n2.3\n2018-12\n切换目录时设置导航栏。\n本地创建desktop失败,询问是否在桌面创建。\n修复显示文管主页时,地址栏打开路径不显示文件列表的问题。\ndesktop文件增加以管理员身份打开。\ndesktop无图标则显示默认图标。\n2018-11\n修复未知文件不显示图标问题。\n右键菜单移动文件后自动刷新当前目录。\n添加到深度文管目录打开方式列表。\n导航列表增加挂载分区,增加主页。\n\n2.2\n2018-07\n增加显示隐藏快捷键,刷新快捷键,增加图片打开方式。\n\n2.1\n2018-05\n列表模式可以显示MP3的ID3信息。\n\n2.0\n2018-04\n使用 QListWidget + Dir 遍历代替 QListView + QFileSystemModel,可以自定义文件图标。\n\n1.0\n2017-10\n增加文本文件打开方式菜单。\n文件列表回车快捷键与地址栏回车键冲突,引起有文件选中时地址栏回车无效,无文件选中时程序崩溃,暂时保留地址栏回车信号,取消程序的回车快捷键。\n粘贴有重名选择不覆盖将命名为副件XXX。\n2017-08\n多选复制粘贴删除成功,增加复制粘贴删除快捷键。\n增加搜索(过滤)。\n更新日志太长,由消息框改为文本框。\n2017-07\n增加视频文件打开方式,增加rmvb文件打开方式。\n增加背景图。\n增加压缩和解压缩菜单。\n2017-06\n属性窗体读取系统图标,增加回车键进入文件夹,增加退格键回到上层目录。\n属性窗体增加显示系统文件默认图标。\n从主窗体中分离属性窗体的代码。\n2017-05\n右键菜单增加【在终端中打开】。\n文件夹增加深度文管和Thunar打开方式。\n修复desktop已经存在,创建desktop会追加内容的BUG。\n单击文件在状态栏显示文件的MIME。\n2017-04\n图片右键菜单增加【设为壁纸】。\n文件右键菜单增加【移动到】、【复制到】。\n增加是否覆盖对话框。\ndesktop文件属性支持打开执行路径。\nQListView、QTableView实现排序。\n图标、列表按钮实现按下效果。\n实现删除文件到回收站,从回收站还原,优化回收站菜单。\n引号括起来,解决文件名含空格双击打不开的问题。\n增加列表模式右键菜单。\n增加管理员身份打开文件或文件夹。\n双击desktop文件,读取执行参数启动程序。\n增加修改desktop文件属性。\n解决QGridLayout单元格图标居中问题。\n增加读取desktop文件属性。\n增加新建文件夹,删除新建文件夹。\n程序右键增加创建快捷方式。\n图片的右键属性增加缩略图。\n2017-03\n增加左侧导航栏。\n增加右键菜单,增加复制、剪切、删除、属性功能。\n增加QTableView以列表形式显示,按钮切换图标、列表模式。\n增加后退功能。\n使用QListView以图标形式显示。"; 176 | QDialog *dialog = new QDialog; 177 | dialog->setWindowTitle("更新历史"); 178 | dialog->setFixedSize(400,300); 179 | QVBoxLayout *vbox = new QVBoxLayout; 180 | QTextBrowser *textBrowser = new QTextBrowser; 181 | textBrowser->setText(s); 182 | textBrowser->zoomIn(); 183 | vbox->addWidget(textBrowser); 184 | QHBoxLayout *hbox = new QHBoxLayout; 185 | QPushButton *pushButtonConfirm = new QPushButton("确定"); 186 | hbox->addStretch(); 187 | hbox->addWidget(pushButtonConfirm); 188 | hbox->addStretch(); 189 | vbox->addLayout(hbox); 190 | dialog->setLayout(vbox); 191 | dialog->show(); 192 | connect(pushButtonConfirm, SIGNAL(clicked()), dialog, SLOT(accept())); 193 | if(dialog->exec() == QDialog::Accepted){ 194 | dialog->close(); 195 | } 196 | } 197 | 198 | void MainWindow::on_action_about_triggered() 199 | { 200 | QMessageBox aboutMB(QMessageBox::NoIcon, "关于", "海天鹰文件管理器 2.12\n一款基于 Qt5 的文件管理器。\n作者:海天鹰\nE-mail: sonichy@163.com\n主页:https://github.com/sonichy/HTYFileManager\n参考:\n右键菜单:http://windrocblog.sinaapp.com/?p=1016\n二级菜单:http://blog.csdn.net/u011417605/article/details/51219019\nQAction组群单选:http://qiusuoge.com/12287.html\nQListView添加项目:http://blog.csdn.net/u010142953/article/details/46694419\n修改文本:http://blog.csdn.net/caoshangpa/article/details/51775147\n获取系统文件图标:http://www.cnblogs.com/RainyBear/p/5223103.html"); 201 | aboutMB.setIconPixmap(QPixmap(":/icon.png")); 202 | aboutMB.exec(); 203 | } 204 | 205 | void MainWindow::nav(QListWidgetItem *item) 206 | { 207 | path = item->data(LOCATION_OF_REAL_PATH).toString(); 208 | //qDebug() << path; 209 | lineEdit_location->setText(path); 210 | if(path == "computer://"){ 211 | ui->computerWidget->show(); 212 | ui->listWidget->hide(); 213 | ui->tableWidget->hide(); 214 | }else{ 215 | ui->computerWidget->hide(); 216 | if(ui->action_icon->isChecked())ui->listWidget->show(); 217 | if(ui->action_list->isChecked())ui->tableWidget->show(); 218 | genList(path); 219 | } 220 | } 221 | 222 | void MainWindow::listWidgetDoubleClicked(QModelIndex index) 223 | { 224 | Q_UNUSED(index); 225 | //qDebug() << "listWidgetDoubleClicked()" << index.data().toString(); 226 | open(list.at(ui->listWidget->currentRow()).absoluteFilePath()); 227 | } 228 | 229 | void MainWindow::tableWidgetDoubleClicked(QModelIndex index) 230 | { 231 | Q_UNUSED(index); 232 | //qDebug() << "tableWidgetDoubleClicked()" << index.data().toString(); 233 | open(list.at(ui->tableWidget->currentRow()).absoluteFilePath()); 234 | } 235 | 236 | void MainWindow::open(QString newpath) 237 | { 238 | qDebug() << "newpath:" << newpath; 239 | QFileInfo FI(newpath); 240 | if (FI.isDir() || newpath == "/" || newpath == "trash:///") { 241 | //lineEditLocation->setText(newpath); 242 | path = newpath; 243 | genList(path); 244 | } else { 245 | QProcess *process = new QProcess; 246 | QString MIME = QMimeDatabase().mimeTypeForFile(newpath).name(); 247 | qDebug() << MIME; 248 | if (MIME == "application/x-desktop") { 249 | QString sexec = readSettings(newpath, "Desktop Entry", "Exec"); 250 | process->setWorkingDirectory(readSettings(newpath, "Desktop Entry", "Path")); 251 | qDebug() << sexec; 252 | process->start(sexec); 253 | } else if (MIME == "application/vnd.appimage") { 254 | process->start(newpath); 255 | } else { 256 | QDesktopServices::openUrl(QUrl(newpath)); 257 | } 258 | } 259 | } 260 | 261 | //void MainWindow::listWidgetClicked(QModelIndex index) 262 | void MainWindow::listWidgetItemClicked(QListWidgetItem *item) 263 | { 264 | Q_UNUSED(item); 265 | //qDebug() << index.data().toString(); 266 | qDebug() << "listWidgetItemClicked"; 267 | QString filepath = list.at(ui->listWidget->currentRow()).absoluteFilePath(); 268 | //QString MIME = QMimeDatabase().mimeTypeForFile(filepath).name(); 269 | QString MIME = QMimeDatabase().mimeTypeForFile(filepath).comment();//MIME翻译 270 | ui->statusBar->showMessage("类型: " + MIME + ", 大小: " + BS(QFileInfo(filepath).size(),2) + ", 访问时间: " + QFileInfo(filepath).lastRead().toString("yyyy-MM-dd hh:mm:ss") + ", 修改时间: " + QFileInfo(filepath).lastModified().toString("yyyy-MM-dd hh:mm:ss")); 271 | } 272 | 273 | void MainWindow::lineEditLocationReturnPressed() 274 | { 275 | qDebug() << "lineEditLocationReturnPressed"; 276 | QString newpath = lineEdit_location->text(); 277 | QFileInfo FI(newpath); 278 | if (FI.isDir() || newpath == "trash:///") { 279 | path = newpath; 280 | ui->computerWidget->hide(); 281 | ui->listWidget->show(); 282 | genList(path); 283 | } 284 | } 285 | 286 | void MainWindow::on_action_back_triggered() 287 | { 288 | if(path != "/"){ 289 | int n = lineEdit_location->text().lastIndexOf("/"); 290 | qDebug() << n; 291 | QString newpath = ""; 292 | if (n>0) { 293 | newpath = lineEdit_location->text().left(n); 294 | } else { 295 | newpath = "/"; 296 | } 297 | lineEdit_location->setText(newpath); 298 | path = newpath; 299 | genList(path); 300 | } 301 | } 302 | 303 | void MainWindow::on_action_forward_triggered() 304 | { 305 | 306 | } 307 | 308 | void MainWindow::on_action_icon_triggered() 309 | { 310 | if(path != "computer://"){ 311 | ui->listWidget->setVisible(true); 312 | ui->tableWidget->setVisible(false); 313 | } 314 | } 315 | 316 | void MainWindow::on_action_list_triggered() 317 | { 318 | if(path != "computer://"){ 319 | ui->listWidget->setVisible(false); 320 | ui->tableWidget->setVisible(true); 321 | } 322 | } 323 | 324 | void MainWindow::customContextMenu(const QPoint &pos) 325 | { 326 | QAction *action_copy, *action_cut, *action_rename, *action_trash, *action_emptyTrash, *action_delete, *action_restore, *action_paste, *action_newfolder, *action_sort, *action_property, *action_desktop, *action_gksu, *action_copyto, *action_moveto, *action_setWallpaper, *action_terminal, *action_zip, *action_unzip, *action_createLink; 327 | QModelIndex index = ui->listWidget->indexAt(pos); 328 | //QString filepath = path + "/" + index.data(Qt::DisplayRole).toString(); 329 | QString filepath = ""; 330 | if (index.isValid()) 331 | filepath = list.at(ui->listWidget->currentRow()).absoluteFilePath(); 332 | qDebug() << filepath; 333 | QString filename = QFileInfo(filepath).fileName(); 334 | QString MIME = QMimeDatabase().mimeTypeForFile(filepath).name(); 335 | qDebug() << MIME; 336 | QString filetype = MIME.left(MIME.indexOf("/")); 337 | 338 | QList actions, actions_recommend_app; 339 | QAction *action_openwith = new QAction(this); 340 | action_openwith->setText("打开方式"); 341 | actions.append(action_openwith); 342 | QMenu *menu_openwith = new QMenu(this); 343 | action_openwith->setMenu(menu_openwith); 344 | QStringList SL_mimeinfo_cache; 345 | SL_mimeinfo_cache << "/usr/share/applications/mimeinfo.cache" << QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.local/share/applications/mimeinfo.cache"; 346 | for (int k=0; ksetFileName(SL_mimeinfo_cache.at(k)); 350 | bool ok = file->open(QIODevice::ReadOnly); 351 | if (ok) { 352 | QTextStream TS(file); 353 | QString s = TS.readAll(); 354 | file->close(); 355 | QStringList SL = s.split("\n"); 356 | SL = SL.filter(MIME + "="); 357 | for (int i=0; isetProperty("path", desktop); 372 | action->setText(sName); 373 | QIcon icon; 374 | if (sIcon == "") 375 | sIcon = "applications-system-symbolic"; 376 | if (QFileInfo(sIcon).isFile()) { 377 | icon = QIcon(sIcon); 378 | } else { 379 | icon = QIcon::fromTheme(sIcon); 380 | } 381 | action->setIcon(icon); 382 | connect(action, &QAction::triggered, [=](){ 383 | QProcess *process = new QProcess; 384 | process->setWorkingDirectory(path); 385 | qDebug() << sExec; 386 | process->setProgram(sExec); 387 | process->setArguments(QStringList() << filepath); 388 | bool b = process->startDetached(); 389 | qDebug() << b; 390 | }); 391 | menu_openwith->addAction(action); 392 | actions_recommend_app.append(action); 393 | } 394 | } 395 | } 396 | } 397 | 398 | QAction *action_choose_default_app = new QAction(menu_openwith); 399 | action_choose_default_app->setText("选择默认程序&C"); 400 | menu_openwith->addAction(action_choose_default_app); 401 | connect(action_choose_default_app, &QAction::triggered, [=](){ 402 | QDialog *dialog = new QDialog(this); 403 | dialog->setWindowTitle("打开方式"); 404 | dialog->setFixedSize(600,500); 405 | QVBoxLayout *vbox = new QVBoxLayout; 406 | dialog->setLayout(vbox); 407 | QLabel *label = new QLabel("推荐应用 " + QString::number(actions_recommend_app.size())); 408 | vbox->addWidget(label); 409 | QListWidget *listWidget_recommend_app = new QListWidget(dialog); 410 | listWidget_recommend_app->setViewMode(QListView::IconMode); 411 | listWidget_recommend_app->setDragDropMode(QAbstractItemView::NoDragDrop); 412 | vbox->addWidget(listWidget_recommend_app); 413 | foreach (QAction *action, actions_recommend_app) { 414 | QListWidgetItem *LWI; 415 | LWI = new QListWidgetItem(action->icon(), action->text()); 416 | LWI->setData(LOCATION_OF_REAL_PATH, action->property("path")); 417 | LWI->setSizeHint(QSize(120,120)); 418 | listWidget_recommend_app->insertItem(listWidget_recommend_app->count() + 1, LWI); 419 | } 420 | 421 | QHBoxLayout *hbox = new QHBoxLayout; 422 | vbox->addLayout(hbox); 423 | label = new QLabel("其他应用"); 424 | hbox->addWidget(label); 425 | QLineEdit *lineEdit = new QLineEdit(dialog); 426 | QAction *action_lineEdit_filter = new QAction(lineEdit); 427 | action_lineEdit_filter->setIcon(QIcon::fromTheme("search")); 428 | lineEdit->addAction(action_lineEdit_filter, QLineEdit::LeadingPosition); 429 | QAction *action_lineEdit_clear = new QAction(lineEdit); 430 | action_lineEdit_clear->setIcon(QIcon::fromTheme("edit-clear")); 431 | lineEdit->addAction(action_lineEdit_clear, QLineEdit::TrailingPosition); 432 | hbox->addWidget(lineEdit); 433 | hbox->addStretch(); 434 | 435 | QListWidget *listWidget_app = new QListWidget(dialog); 436 | listWidget_app->setViewMode(QListView::IconMode); 437 | listWidget_app->setDragDropMode(QAbstractItemView::NoDragDrop); 438 | vbox->addWidget(listWidget_app); 439 | connect(action_lineEdit_filter, &QAction::triggered, [=](){ 440 | openwith_filter(listWidget_app, lineEdit->text(), label); 441 | }); 442 | //快捷键冲突 443 | // connect(lineEdit, &QLineEdit::returnPressed, [=](){ 444 | // openwith_filter(listWidget_app, lineEdit->text(), label); 445 | // }); 446 | connect(action_lineEdit_clear, &QAction::triggered, [=](){ 447 | lineEdit->clear(); 448 | openwith_filter(listWidget_app, "", label); 449 | }); 450 | openwith_filter(listWidget_app, "", label); 451 | 452 | //2个QListWidget单选 453 | connect(listWidget_recommend_app, &QListWidget::itemSelectionChanged, [=](){ 454 | QList list_recommend_app_selected = listWidget_recommend_app->selectedItems(); 455 | if (list_recommend_app_selected.size() != 0) { 456 | listWidget_app->setCurrentRow(-1); 457 | } 458 | }); 459 | connect(listWidget_app, &QListWidget::itemSelectionChanged, [=](){ 460 | QList list_app_selected = listWidget_app->selectedItems(); 461 | if (list_app_selected.size() != 0) { 462 | listWidget_recommend_app->setCurrentRow(-1); 463 | } 464 | }); 465 | 466 | hbox = new QHBoxLayout; 467 | hbox->addStretch(); 468 | vbox->addLayout(hbox); 469 | QCheckBox *checkBox_default_app = new QCheckBox("设为默认"); 470 | hbox->addWidget(checkBox_default_app); 471 | QPushButton *pushButton_cancel = new QPushButton("取消"); 472 | connect(pushButton_cancel, &QPushButton::pressed, [=](){ 473 | dialog->close(); 474 | }); 475 | hbox->addWidget(pushButton_cancel); 476 | QPushButton *pushButton_confirm = new QPushButton("确定"); 477 | connect(pushButton_confirm, &QPushButton::pressed, [=](){ 478 | QListWidgetItem *LWI; 479 | QList list_recommend_app_selected = listWidget_recommend_app->selectedItems(); 480 | if (list_recommend_app_selected.size() != 0) { 481 | LWI = listWidget_recommend_app->selectedItems().first(); 482 | } else { 483 | LWI = listWidget_app->selectedItems().first(); 484 | } 485 | QString desktop = LWI->data(LOCATION_OF_REAL_PATH).toString(); 486 | QString sExec = readSettings(desktop, "Desktop Entry", "Exec"); 487 | sExec = sExec.left(sExec.indexOf(" ")); 488 | QProcess *process = new QProcess; 489 | process->setWorkingDirectory(path); 490 | qDebug() << sExec; 491 | process->setProgram(sExec); 492 | process->setArguments(QStringList() << filepath); 493 | bool b = process->startDetached(); 494 | qDebug() << b; 495 | dialog->close(); 496 | if (checkBox_default_app->isChecked()) { 497 | QString default_apps = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/mimeapps.list"; 498 | QFile *file = new QFile; 499 | file->setFileName(default_apps); 500 | QString s=""; 501 | bool ok = file->open(QIODevice::ReadOnly); 502 | if (ok) { 503 | QTextStream TS(file); 504 | s = TS.readAll(); 505 | file->close(); 506 | } 507 | file->setFileName(default_apps); 508 | ok = file->open(QFile::WriteOnly); 509 | if (ok) { 510 | QFileInfo FI(desktop); 511 | QTextStream TS(file); 512 | s.replace(QRegularExpression(MIME + "=.*\n"), MIME + "=" + FI.fileName() + "\n"); 513 | TS << s; 514 | file->close(); 515 | } 516 | } 517 | }); 518 | hbox->addWidget(pushButton_confirm); 519 | dialog->show(); 520 | }); 521 | 522 | action_copy = new QAction(this); 523 | action_copy->setText("复制&C"); //不加&弹出菜单无法响应按键,加了后不需要setShortcut 524 | action_copy->setIcon(QIcon::fromTheme("edit-copy")); 525 | actions.append(action_copy); 526 | 527 | action_cut = new QAction(this); 528 | action_cut->setText("剪切&X"); 529 | action_cut->setIcon(QIcon::fromTheme("edit-cut")); 530 | actions.append(action_cut); 531 | 532 | action_paste = new QAction(this); 533 | action_paste->setText("粘贴&V"); 534 | action_paste->setIcon(QIcon::fromTheme("edit-paste")); 535 | actions.append(action_paste); 536 | 537 | action_rename = new QAction(this); 538 | action_rename->setText("重命名&M"); 539 | actions.append(action_rename); 540 | 541 | action_moveto = new QAction(this); 542 | action_moveto->setText("移动到..."); 543 | actions.append(action_moveto); 544 | 545 | action_copyto = new QAction(this); 546 | action_copyto->setText("复制到..."); 547 | actions.append(action_copyto); 548 | 549 | action_zip = new QAction(this); 550 | action_zip->setText("压缩"); 551 | action_zip->setIcon(QIcon::fromTheme("file-roller")); 552 | actions.append(action_zip); 553 | 554 | action_unzip = new QAction(this); 555 | action_unzip->setText("解压到当前目录"); 556 | action_unzip->setIcon(QIcon::fromTheme("file-roller")); 557 | actions.append(action_unzip); 558 | 559 | QAction *action_git_tar_gz = new QAction(this); 560 | action_git_tar_gz->setText("Git打包tar.gz"); 561 | action_git_tar_gz->setIcon(QIcon::fromTheme("file-roller")); 562 | actions.append(action_git_tar_gz); 563 | 564 | QAction *action_git_zip = new QAction(this); 565 | action_git_zip->setText("Git打包zip"); 566 | action_git_zip->setIcon(QIcon::fromTheme("file-roller")); 567 | actions.append(action_git_zip); 568 | 569 | action_trash = new QAction(this); 570 | action_trash->setText("移至回收站"); 571 | action_trash->setIcon(QIcon::fromTheme("user-trash-full")); 572 | actions.append(action_trash); 573 | 574 | action_emptyTrash = new QAction(this); 575 | action_emptyTrash->setText("清空回收站"); 576 | action_emptyTrash->setIcon(QIcon::fromTheme("user-trash")); 577 | actions.append(action_emptyTrash); 578 | 579 | action_delete = new QAction(this); 580 | action_delete->setText("删除"); 581 | action_delete->setIcon(QIcon::fromTheme("edit-delete")); 582 | actions.append(action_delete); 583 | 584 | action_restore = new QAction(this); 585 | action_restore->setText("还原"); 586 | actions.append(action_restore); 587 | 588 | action_newfolder = new QAction(this); 589 | action_newfolder->setText("新建文件夹"); 590 | action_newfolder->setIcon(QIcon::fromTheme("folder-new")); 591 | actions.append(action_newfolder); 592 | 593 | action_sort = new QAction(this); 594 | action_sort->setText("排序方式"); 595 | actions.append(action_sort); 596 | action_sort->setMenu(sortMenu); 597 | 598 | action_setWallpaper = new QAction(this); 599 | action_setWallpaper->setText("设为壁纸"); 600 | action_setWallpaper->setIcon(QIcon::fromTheme("preferences-desktop-wallpaper")); 601 | actions.append(action_setWallpaper); 602 | 603 | action_property = new QAction(this); 604 | action_property->setText("属性&R"); 605 | action_property->setIcon(QIcon::fromTheme("document-properties")); 606 | actions.append(action_property); 607 | 608 | action_terminal = new QAction(this); 609 | action_terminal->setText("在终端中打开&T"); 610 | action_terminal->setIcon(QIcon::fromTheme("utilities-terminal")); 611 | actions.append(action_terminal); 612 | 613 | action_desktop = new QAction(this); 614 | action_desktop->setText("创建快捷方式"); 615 | actions.append(action_desktop); 616 | 617 | action_gksu = new QAction(this); 618 | action_gksu->setText("以管理员身份打开"); 619 | actions.append(action_gksu); 620 | 621 | action_createLink = new QAction(this); 622 | action_createLink->setText("创建链接"); 623 | action_createLink->setIcon(QIcon::fromTheme("emblem-symbolic-link")); 624 | actions.append(action_createLink); 625 | 626 | if (MIME != "inode/directory") { 627 | action_zip->setVisible(false); 628 | } 629 | 630 | if (MIME != "application/zip") { 631 | action_unzip->setVisible(true); 632 | } 633 | 634 | if (MIME != "application/x-executable" && MIME != "application/x-shellscript" && MIME != "application/x-ms-dos-executable" && MIME !="application/x-sharedlib" && MIME != "application/vnd.appimage") 635 | action_desktop->setVisible(false); 636 | 637 | if (filetype != "image") { 638 | action_setWallpaper->setVisible(false); 639 | } 640 | 641 | //qDebug() << path << dirTrash; 642 | if (path == dirTrash) { 643 | action_openwith->setVisible(false); 644 | action_paste->setVisible(false); 645 | action_moveto->setVisible(false); 646 | action_copyto->setVisible(false); 647 | action_unzip->setVisible(false); 648 | action_trash->setVisible(false); 649 | action_gksu->setVisible(false); 650 | action_rename->setVisible(false); 651 | action_newfolder->setVisible(false); 652 | action_terminal->setVisible(false); 653 | action_setWallpaper->setVisible(false); 654 | action_createLink->setVisible(false); 655 | if (index.isValid()) action_emptyTrash->setVisible(false); 656 | } else { 657 | //action_delete->setVisible(false); 658 | action_restore->setVisible(false); 659 | action_emptyTrash->setVisible(false); 660 | } 661 | if (index.isValid()) { 662 | action_newfolder->setVisible(false); 663 | action_sort->setVisible(false); 664 | action_git_tar_gz->setVisible(false); 665 | action_git_zip->setVisible(false); 666 | } else { 667 | qDebug() << "viewContextMenu: index is not valid"; 668 | action_copy->setVisible(false); 669 | action_cut->setVisible(false); 670 | action_rename->setVisible(false); 671 | action_trash->setVisible(false); 672 | action_delete->setVisible(false); 673 | action_gksu->setVisible(false); 674 | action_restore->setVisible(false); 675 | action_createLink->setVisible(false); 676 | QDir dir_git(path + "/.git"); 677 | if (!dir_git.exists()) { 678 | action_git_tar_gz->setVisible(false); 679 | action_git_zip->setVisible(false); 680 | } 681 | } 682 | if (QFileInfo(filepath).isFile()) 683 | action_terminal->setVisible(false); 684 | if (QFileInfo(filepath).isSymLink()) 685 | action_createLink->setVisible(false); 686 | 687 | QAction *result_action = QMenu::exec(actions, ui->listWidget->mapToGlobal(pos)); 688 | 689 | if (result_action == action_copy) { 690 | copy(); 691 | return; 692 | } 693 | 694 | if (result_action == action_cut) { 695 | cut = 1; 696 | copy(); 697 | return; 698 | } 699 | 700 | if (result_action == action_paste) { 701 | paste(); 702 | /* 703 | qDebug() << "paste"; 704 | for(int i=0; istatusBar->showMessage("清空回收站..."); 753 | delDir(dirTrash); 754 | genList(dirTrash); 755 | ui->statusBar->showMessage(""); 756 | } 757 | return; 758 | } 759 | 760 | if (result_action == action_delete) { 761 | deleteFiles(); 762 | return; 763 | } 764 | 765 | if (result_action == action_restore) { 766 | qDebug() << "restore" << filepath; 767 | QString spath = ""; 768 | QString pathinfo = QDir::homePath()+"/.local/share/Trash/info/" + QFileInfo(filepath).fileName() + ".trashinfo"; 769 | QFile file(pathinfo); 770 | file.open(QIODevice::ReadOnly); 771 | while (!file.atEnd()) { 772 | QString sl = file.readLine().replace("\n",""); 773 | //qDebug() << sl; 774 | if(sl.left(sl.indexOf("=")).toLower() == "path"){ 775 | spath = sl.mid(sl.indexOf("=")+1); 776 | break; 777 | } 778 | } 779 | qDebug() << spath; 780 | if (QFile::copy(filepath, spath)) { 781 | QFile::remove(filepath); 782 | QFile::remove(QDir::homePath() + "/.local/share/Trash/info/" + QFileInfo(filepath).fileName() + ".trashinfo"); 783 | genList(path); 784 | } 785 | return; 786 | } 787 | 788 | if (result_action == action_newfolder) { 789 | QDir *dir = new QDir; 790 | if(!dir->mkdir(path + "/" + "新建文件夹")){ 791 | QMessageBox::warning(this, "创建文件夹", "文件夹已经存在!"); 792 | } 793 | return; 794 | } 795 | 796 | if (result_action == action_rename) { 797 | QDialog *dialog = new QDialog(this); 798 | dialog->setWindowFlags(Qt::Tool); 799 | dialog->setFixedSize(200,100); 800 | dialog->setWindowTitle("重命名"); 801 | QVBoxLayout *vbox = new QVBoxLayout; 802 | QLineEdit *lineEdit = new QLineEdit; 803 | lineEdit->setText(filename); 804 | vbox->addWidget(lineEdit); 805 | QHBoxLayout *hbox = new QHBoxLayout; 806 | QPushButton *pushButtonConfirm = new QPushButton("确定"); 807 | QPushButton *pushButtonCancel = new QPushButton("取消"); 808 | hbox->addWidget(pushButtonConfirm); 809 | hbox->addWidget(pushButtonCancel); 810 | vbox->addLayout(hbox); 811 | dialog->setLayout(vbox); 812 | connect(pushButtonConfirm, SIGNAL(clicked()), dialog, SLOT(accept())); 813 | connect(pushButtonCancel, SIGNAL(clicked()), dialog, SLOT(reject())); 814 | if(dialog->exec() == QDialog::Accepted){ 815 | QString newName = QFileInfo(filepath).absolutePath() + "/" + lineEdit->text(); 816 | qDebug() << "rename" << filepath << newName; 817 | if (QFile::rename(filepath, newName)) { 818 | genList(QFileInfo(filepath).absolutePath()); 819 | } else { 820 | QMessageBox::critical(nullptr, "错误", "无法重命名文件,该文件已存在!", QMessageBox::Ok); 821 | } 822 | } 823 | dialog->close(); 824 | return; 825 | } 826 | 827 | if (result_action == action_property) { 828 | if (index.isValid()) { 829 | if (MIME == "application/x-desktop") { 830 | QString sExec = readSettings(filepath, "Desktop Entry", "Exec"); 831 | QString sName = readSettings(filepath, "Desktop Entry", "Name"); 832 | QString sIcon = readSettings(filepath, "Desktop Entry", "Icon"); 833 | QString sPath = readSettings(filepath, "Desktop Entry", "Path"); 834 | QString sComment = readSettings(filepath, "Desktop Entry", "Comment"); 835 | QString sCategories = readSettings(filepath, "Desktop Entry", "Categories"); 836 | //dialogPD->ui->lineEditPathDesktop->setText(filepath); 837 | dialogPD->filePath = filepath; 838 | if (sIcon.contains("/")) { 839 | dialogPD->ui->pushButton_icon->setIcon(QIcon(sIcon)); 840 | } else { 841 | dialogPD->ui->pushButton_icon->setIcon(QIcon::fromTheme(sIcon)); 842 | } 843 | //dialogPD->ui->lineEditIcon->setText(sicon); 844 | dialogPD->iconPath = sIcon; 845 | dialogPD->ui->lineEdit_filepath->setText(filepath); 846 | dialogPD->ui->lineEdit_name->setText(sName); 847 | dialogPD->ui->lineEdit_name->setCursorPosition(0); 848 | dialogPD->ui->lineEdit_exec->setText(sExec); 849 | dialogPD->ui->lineEdit_exec->setCursorPosition(0); 850 | dialogPD->ui->lineEdit_path->setText(sPath); 851 | dialogPD->ui->lineEdit_path->setCursorPosition(0); 852 | dialogPD->ui->lineEdit_comment->setText(sComment); 853 | dialogPD->ui->lineEdit_comment->setCursorPosition(0); 854 | dialogPD->ui->lineEdit_categories->setText(sCategories); 855 | dialogPD->ui->lineEdit_categories->setCursorPosition(0); 856 | dialogPD->show(); 857 | } else { 858 | qDebug() << "property" << filepath; 859 | QString path1 = ""; 860 | if (QFileInfo(filepath).isSymLink()) { 861 | path1 = "链接路径:\t" + QFileInfo(filepath).symLinkTarget(); 862 | } else { 863 | path1 = "路径:\t" + path; 864 | } 865 | QMessageBox MBox(QMessageBox::NoIcon, "属性", path1 + "\n文件名:\t" + QFileInfo(filepath).fileName() + "\n大小:\t" + BS(QFileInfo(filepath).size(),2) + "\n类型:\t" + QMimeDatabase().mimeTypeForFile(filepath).name() + "\n访问时间:\t" + QFileInfo(filepath).lastRead().toString("yyyy-MM-dd hh:mm:ss") + "\n修改时间:\t" + QFileInfo(filepath).lastModified().toString("yyyy-MM-dd hh:mm:ss")); 866 | QIcon icon = ui->listWidget->currentItem()->icon(); 867 | MBox.setIconPixmap(icon.pixmap(QSize(150,150))); 868 | MBox.setWindowFlags(Qt::Tool); 869 | MBox.exec(); 870 | } 871 | }else{ 872 | QMessageBox MBox(QMessageBox::NoIcon, "文件夹属性", "路径:\t" + path + "\n大小:\t" + BS(QFileInfo(path).size(),2) + "\n访问时间:\t" + QFileInfo(path).lastRead().toString("yyyy-MM-dd hh:mm:ss") + "\n修改时间:\t" + QFileInfo(path).lastModified().toString("yyyy-MM-dd hh:mm:ss")); 873 | MBox.setIconPixmap(QIcon::fromTheme("folder").pixmap(QSize(150,150))); 874 | MBox.exec(); 875 | } 876 | return; 877 | } 878 | 879 | if (result_action == action_desktop) { 880 | qDebug() << "Create desktop file"; 881 | QString iconName = "icon.png"; 882 | if (MIME == "application/vnd.appimage") 883 | iconName = QFileInfo(filepath).baseName() + ".png"; 884 | QString sExec; 885 | if (MIME=="application/x-ms-dos-executable") { 886 | sExec = "deepin-wine " + filepath; 887 | }else{ 888 | sExec = filepath; 889 | } 890 | QFile file(QFileInfo(filepath).absolutePath() + "/" + QFileInfo(filepath).baseName() + ".desktop"); 891 | if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { 892 | QString str = "[Desktop Entry]\nName=" + QFileInfo(filepath).baseName() + "\nComment=\nExec=" + sExec + "\nIcon=" + QFileInfo(filepath).absolutePath() + "/" + iconName + "\nPath=" + QFileInfo(filepath).absolutePath() + "\nTerminal=false\nType=Application\nMimeType=\nCategories="; 893 | qDebug() << str; 894 | QTextStream in(&file); 895 | in << str; 896 | file.close(); 897 | genList(path); 898 | } else { 899 | //QMessageBox::warning(this,"错误","不能创建 " + filepath + ".desktop", QMessageBox::Yes); 900 | QMessageBox MB(QMessageBox::Question, "错误", "不能创建 " + filepath + ".desktop,是否在桌面创建?", QMessageBox::Yes | QMessageBox::No, nullptr); 901 | if (MB.exec() == QMessageBox::Yes) { 902 | file.setFileName(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/" + QFileInfo(filepath).baseName() + ".desktop"); 903 | if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { 904 | iconName = QFileInfo(filepath).baseName(); 905 | QString str = "[Desktop Entry]\nName=" + QFileInfo(filepath).baseName() + "\nComment=\nExec=" + sExec + "\nIcon=" + iconName + "\nPath=" + QFileInfo(filepath).absolutePath() + "\nTerminal=false\nType=Application\nMimeType=\nCategories="; 906 | qDebug() << str; 907 | QTextStream in(&file); 908 | in << str; 909 | file.close(); 910 | genList(path); 911 | } 912 | } 913 | } 914 | return; 915 | } 916 | 917 | if (result_action == action_gksu) { 918 | QString cmd; 919 | QProcess *process = new QProcess; 920 | if (filetype == "text" || MIME == "application/x-desktop") { 921 | cmd = "gksu gedit " + filepath; 922 | } 923 | if (MIME == "inode/directory") { 924 | cmd = "gksu " + QDir::currentPath() + "/HTYFileManager " + filepath; 925 | } 926 | qDebug() << cmd; 927 | //process->start(cmd); 928 | process->setProgram(cmd); 929 | process->startDetached(); 930 | } 931 | 932 | if (result_action == action_terminal) { 933 | QProcess *process = new QProcess; 934 | process->setWorkingDirectory(path); 935 | QString cmd = "x-terminal-emulator"; 936 | qDebug() << cmd; 937 | process->setProgram(cmd); 938 | process->startDetached(); 939 | } 940 | 941 | if (result_action == action_sortName) { 942 | qDebug() << "sort by name"; 943 | sortFlags = QDir::Name | QDir::DirsFirst; 944 | genList(path); 945 | } 946 | 947 | if (result_action == action_sortSize) { 948 | qDebug() << "sort by size"; 949 | sortFlags = QDir::Size | QDir::DirsFirst; 950 | genList(path); 951 | } 952 | 953 | if (result_action == action_sortType) { 954 | qDebug() << "sort by type"; 955 | sortFlags = QDir::Type | QDir::DirsFirst; 956 | genList(path); 957 | } 958 | 959 | if(result_action == action_sortTime){ 960 | qDebug() << "sort by time"; 961 | sortFlags = QDir::Time | QDir::DirsFirst; 962 | genList(path); 963 | } 964 | 965 | if (result_action == action_copyto) { 966 | if (dir == "") dir = "/home"; 967 | dir = QFileDialog::getExistingDirectory(this, "选择路径", dir, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); 968 | 969 | if (dir != "") { 970 | QString newName = dir + "/" + QFileInfo(filepath).fileName(); 971 | qDebug() << "copyto:" << filepath << newName; 972 | if (!QFile::copy(filepath, newName)) { 973 | QMessageBox::StandardButton SB = QMessageBox::warning(nullptr, "覆盖", "是否覆盖 "+newName+" ?", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); 974 | if (SB == QMessageBox::Yes) { 975 | if (!QFile::remove(newName)) { 976 | QMessageBox::critical(nullptr, "错误", "无法覆盖新文件 "+newName); 977 | } else { 978 | qDebug() << "copyto" << newName; 979 | refresh(); 980 | } 981 | if (!QFile::copy(filepath, newName)) { 982 | QMessageBox::critical(nullptr, "错误", "粘贴失败!"); 983 | } else { 984 | qDebug() << "copy" << filepath << newName; 985 | } 986 | } 987 | }else{ 988 | #if(QT_VERSION >= QT_VERSION_CHECK(5,10,0)) 989 | QFile file(newName); 990 | file.open(QIODevice::ReadOnly); 991 | qDebug() << "修改粘贴文件时间为原文件时间" << file.setFileTime(QFileInfo(filepath).lastModified(), QFileDevice::FileModificationTime); 992 | file.close(); 993 | #endif 994 | } 995 | } 996 | return; 997 | } 998 | 999 | if (result_action == action_moveto) { 1000 | if (dir == "") dir = "/home"; 1001 | dir = QFileDialog::getExistingDirectory(this, "选择路径", dir, QFileDialog::ShowDirsOnly |QFileDialog::DontResolveSymlinks); 1002 | if (dir != "") { 1003 | QList selected_files = ui->listWidget->selectedItems(); 1004 | for (int i=0; itext(); 1006 | QString newName = dir + "/" + selected_files.at(i)->text(); 1007 | qDebug() << "moveto:" << fp << newName; 1008 | if (QFile::copy(fp, newName)) { 1009 | qDebug() << "copy" << fp << newName; 1010 | if (QFile::remove(fp)) { 1011 | qDebug() << "remove" << fp; 1012 | }else{ 1013 | QMessageBox::critical(nullptr, "错误", "无法删除源文件 " + fp); 1014 | } 1015 | }else{ 1016 | QMessageBox::StandardButton SB = QMessageBox::warning(nullptr, "覆盖", "是否覆盖 " + newName + " ?", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); 1017 | if (SB == QMessageBox::Yes) { 1018 | if (QFile::remove(newName)) { 1019 | qDebug() << "remove" << newName; 1020 | refresh(); 1021 | } else { 1022 | QMessageBox::critical(nullptr, "错误", "无法覆盖新文件 " + newName); 1023 | } 1024 | if (!QFile::copy(fp, newName)) { 1025 | QMessageBox::critical(nullptr, "错误", "粘贴失败!"); 1026 | } else { 1027 | qDebug() << "copy" << fp << newName; 1028 | if (!QFile::remove(fp)) { 1029 | QMessageBox::critical(nullptr, "错误", "无法删除源文件 " + fp); 1030 | } else { 1031 | qDebug() << "remove" << fp; 1032 | } 1033 | } 1034 | } 1035 | } 1036 | } 1037 | } 1038 | refresh(); 1039 | return; 1040 | } 1041 | 1042 | if (result_action == action_setWallpaper) { 1043 | QString cmd = "gsettings set org.gnome.desktop.background picture-uri \"file://" + filepath + "\""; 1044 | qDebug() << "setWallpaper:" << cmd; 1045 | QProcess *process = new QProcess; 1046 | process->start(cmd); 1047 | return; 1048 | } 1049 | 1050 | if (result_action == action_zip) { 1051 | QString cmd = "zip -rj " + filepath + ".zip " + filepath; 1052 | qDebug() << cmd; 1053 | QProcess *process = new QProcess; 1054 | process->start(cmd); 1055 | return; 1056 | } 1057 | 1058 | if (result_action == action_unzip) { 1059 | QString cmd = "unzip -d " + QFileInfo(filepath).absolutePath() + "/" + QFileInfo(filepath).baseName() + " " + filepath; 1060 | qDebug() << cmd; 1061 | QProcess *process = new QProcess; 1062 | process->start(cmd); 1063 | return; 1064 | } 1065 | 1066 | if (result_action == action_git_tar_gz) { 1067 | QProcess *process1 = new QProcess; 1068 | QProcess *process2 = new QProcess; 1069 | process1->setStandardOutputProcess(process2); 1070 | process1->setWorkingDirectory(path); 1071 | process2->setWorkingDirectory(path); 1072 | connect(process1, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput())); 1073 | connect(process1, SIGNAL(readyReadStandardError()), this, SLOT(processError())); 1074 | connect(process2, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput())); 1075 | connect(process2, SIGNAL(readyReadStandardError()), this, SLOT(processError())); 1076 | process1->start("git ls-files"); 1077 | process2->start("xargs tar -czvf " + QFileInfo(path).fileName() + ".tar.gz"); 1078 | if(process2->waitForFinished()) 1079 | genList(path); 1080 | return; 1081 | } 1082 | 1083 | if (result_action == action_git_zip) { 1084 | QProcess *process1 = new QProcess; 1085 | process1->setWorkingDirectory(path); 1086 | connect(process1, SIGNAL(readyReadStandardError()), this, SLOT(processError())); 1087 | process1->start("git ls-files"); 1088 | process1->waitForFinished(); 1089 | QString s = QString(process1->readAllStandardOutput()).replace("\n"," "); 1090 | qDebug() << s; 1091 | s = "zip " + QFileInfo(path).fileName() + ".zip -xi " + s; 1092 | qDebug() << s; 1093 | connect(process1, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput())); 1094 | process1->start(s); 1095 | if (process1->waitForFinished()) 1096 | genList(path); 1097 | return; 1098 | } 1099 | 1100 | if (result_action == action_createLink) { 1101 | QString dest = QFileInfo(filepath).absolutePath() + "/快捷方式-" + QFileInfo(filepath).fileName(); 1102 | QFile file(filepath); 1103 | if (file.link(dest)) 1104 | genList(QFileInfo(filepath).absolutePath()); 1105 | return; 1106 | } 1107 | 1108 | foreach (QAction* action, actions) { 1109 | action->deleteLater(); 1110 | } 1111 | } 1112 | 1113 | /* 1114 | void MainWindow::viewContextMenuTV(const QPoint &position) 1115 | { 1116 | QAction *action_copy,*action_cut,*action_rename,*action_trash,*action_delete,*action_paste,*action_newdir,*action_property,*action_desktop,*action_gksu; 1117 | QModelIndex index = ui->tableWidget->indexAt(position); 1118 | //QString filepath = index.data(QFileSystemModel::FilePathRole).toString(); 1119 | QString filename = QFileInfo(filepath).fileName(); 1120 | QString MIME = QMimeDatabase().mimeTypeForFile(filepath).name(); 1121 | qDebug() << MIME; 1122 | QString filetype = MIME.left(MIME.indexOf("/")); 1123 | 1124 | QList actions; 1125 | action_copy = new QAction(this); 1126 | action_copy->setText("复制"); 1127 | actions.append(action_copy); 1128 | 1129 | action_cut = new QAction(this); 1130 | action_cut->setText("剪切"); 1131 | actions.append(action_cut); 1132 | 1133 | action_rename = new QAction(this); 1134 | action_rename->setText("重命名"); 1135 | actions.append(action_rename); 1136 | 1137 | action_delete = new QAction(this); 1138 | action_delete->setText("删除"); 1139 | actions.append(action_delete); 1140 | 1141 | action_paste = new QAction(this); 1142 | action_paste->setText("粘贴"); 1143 | actions.append(action_paste); 1144 | 1145 | action_newdir = new QAction(this); 1146 | action_newdir->setText("新建文件夹"); 1147 | actions.append(action_newdir); 1148 | 1149 | action_property = new QAction(this); 1150 | action_property->setText("属性"); 1151 | actions.append(action_property); 1152 | 1153 | action_desktop = new QAction(this); 1154 | action_desktop->setText("创建快捷方式"); 1155 | actions.append(action_desktop); 1156 | 1157 | action_gksu = new QAction(this); 1158 | action_gksu->setText("以管理员身份打开"); 1159 | actions.append(action_gksu); 1160 | 1161 | if(MIME != "application/x-executable") action_desktop->setVisible(false); 1162 | 1163 | if(!index.isValid()){ 1164 | qDebug() << "viewContextMenu: index is not valid"; 1165 | action_copy->setVisible(false); 1166 | action_cut->setVisible(false); 1167 | action_rename->setVisible(false); 1168 | action_delete->setVisible(false); 1169 | action_gksu->setVisible(false); 1170 | } 1171 | 1172 | QAction *result_action = QMenu::exec(actions, ui->tableView->mapToGlobal(position)); 1173 | 1174 | if(result_action == action_copy){ 1175 | source=filepath; 1176 | qDebug() << "copy" << source; 1177 | return; 1178 | } 1179 | 1180 | if(result_action == action_cut){ 1181 | qDebug() << "cut" << source; 1182 | source=filepath; 1183 | cut=1; 1184 | return; 1185 | } 1186 | 1187 | if(result_action == action_paste){ 1188 | QString newName = path + "/" + QFileInfo(source).fileName(); 1189 | qDebug() << "paste" << source << newName; 1190 | if(!QFile::copy(source, newName)){ 1191 | QMessageBox::critical(NULL, "错误", "粘贴失败!", QMessageBox::Ok); 1192 | }else{ 1193 | if(cut){ 1194 | if(!QFile::remove(source)){ 1195 | QMessageBox::critical(NULL, "错误", "无法删除剪切的源文件 "+source, QMessageBox::Ok); 1196 | } 1197 | } 1198 | cut=0; 1199 | } 1200 | return; 1201 | } 1202 | 1203 | if(result_action == action_delete){ 1204 | qDebug() << "delete" << filepath; 1205 | if(MIME == "inode/directory"){ 1206 | QDir *dir = new QDir; 1207 | if(!dir->rmdir(filepath)){ 1208 | QMessageBox::critical(this,"错误","无法删除文件夹 "+filepath); 1209 | } 1210 | }else{ 1211 | if(!QFile::remove(filepath)){ 1212 | QMessageBox::critical(NULL, "错误", "无法删除文件 "+filepath); 1213 | } 1214 | } 1215 | return; 1216 | } 1217 | 1218 | if(result_action == action_newdir){ 1219 | QDir *dir = new QDir; 1220 | if(!dir->mkdir(path+"/"+"新建文件夹")){ 1221 | QMessageBox::warning(this,"创建文件夹","文件夹已经存在!"); 1222 | } 1223 | return; 1224 | } 1225 | 1226 | if(result_action == action_rename){ 1227 | QDialog *dialog = new QDialog(this); 1228 | dialog->setWindowTitle("重命名"); 1229 | QVBoxLayout *vbox = new QVBoxLayout; 1230 | QLineEdit *lineEdit = new QLineEdit; 1231 | lineEdit->setText(filename); 1232 | vbox->addWidget(lineEdit); 1233 | QHBoxLayout *hbox = new QHBoxLayout; 1234 | QPushButton *btnConfirm = new QPushButton("确定"); 1235 | QPushButton *btnCancel = new QPushButton("取消"); 1236 | hbox->addWidget(btnConfirm); 1237 | hbox->addWidget(btnCancel); 1238 | vbox->addLayout(hbox); 1239 | dialog->setLayout(vbox); 1240 | connect(btnConfirm, SIGNAL(clicked()), dialog, SLOT(accept())); 1241 | connect(btnCancel, SIGNAL(clicked()), dialog, SLOT(reject())); 1242 | if(dialog->exec() == QDialog::Accepted){ 1243 | QString newName = QFileInfo(filepath).absolutePath() + "/" + lineEdit->text(); 1244 | qDebug() << "rename" << filepath << newName; 1245 | if(!QFile::rename(filepath, newName)){ 1246 | QMessageBox::critical(NULL, "错误", "无法重命名文件,该文件已存在!", QMessageBox::Ok); 1247 | } 1248 | } 1249 | dialog->close(); 1250 | return; 1251 | } 1252 | 1253 | if(result_action == action_property){ 1254 | if(MIME == "application/x-desktop"){ 1255 | pathDesktop = filepath; 1256 | QString sname = "", sexec = "", spath = "", scomment = ""; 1257 | QFile file(filepath); 1258 | file.open(QIODevice::ReadOnly); 1259 | while(!file.atEnd()){ 1260 | QString sl = file.readLine().replace("\n",""); 1261 | qDebug() << sl; 1262 | if(sl.left(sl.indexOf("=")).toLower() == "name"){ 1263 | sname = sl.mid(sl.indexOf("=") + 1); 1264 | continue; 1265 | } 1266 | if(sl.left(sl.indexOf("=")).toLower() == "exec"){ 1267 | sexec = sl.mid(sl.indexOf("=")+1); 1268 | continue; 1269 | } 1270 | if(sl.left(sl.indexOf("=")).toLower() == "icon"){ 1271 | pathIcon = sl.mid(sl.indexOf("=") + 1); 1272 | continue; 1273 | } 1274 | if(sl.left(sl.indexOf("=")).toLower() == "path"){ 1275 | spath=sl.mid(sl.indexOf("=") + 1); 1276 | continue; 1277 | } 1278 | if(sl.left(sl.indexOf("=")).toLower() == "comment"){ 1279 | scomment = sl.mid(sl.indexOf("=") + 1); 1280 | continue; 1281 | } 1282 | } 1283 | dialogPD->ui->pushButtonIcon->setIcon(QIcon(pathIcon)); 1284 | dialogPD->ui->lineEditIcon->setText(pathIcon); 1285 | dialogPD->ui->lineEditName->setText(sname); 1286 | dialogPD->ui->lineEditName->setCursorPosition(0); 1287 | dialogPD->ui->lineEditExec->setText(sexec); 1288 | dialogPD->ui->lineEditExec->setCursorPosition(0); 1289 | dialogPD->ui->lineEditPath->setText(spath); 1290 | dialogPD->ui->lineEditPath->setCursorPosition(0); 1291 | dialogPD->ui->lineEditComment->setText(scomment); 1292 | dialogPD->ui->lineEditComment->setCursorPosition(0); 1293 | dialogPD->show(); 1294 | }else{ 1295 | qDebug() << "property" << filepath; 1296 | QMessageBox MBox(QMessageBox::NoIcon, "属性", "文件名:\t" + QFileInfo(filepath).fileName() + "\n大小:\t" + BS(QFileInfo(filepath).size(),2) + "\n类型:\t" + QMimeDatabase().mimeTypeForFile(filepath).name() + "\n访问时间:\t" + QFileInfo(filepath).lastRead().toString("yyyy-MM-dd hh:mm:ss") + "\n修改时间:\t" + QFileInfo(filepath).lastModified().toString("yyyy-MM-dd hh:mm:ss")); 1297 | if(filetype == "image"){ 1298 | QSize iconSize(200,200); 1299 | MBox.setIconPixmap(QPixmap(filepath).scaled(iconSize, Qt::KeepAspectRatio)); 1300 | } 1301 | MBox.exec(); 1302 | } 1303 | return; 1304 | } 1305 | 1306 | if(result_action == action_desktop) { 1307 | qDebug() << "Create desktop file"; 1308 | QString str = "[Desktop Entry]\nName=" + QFileInfo(filepath).fileName() + "\nComment=\nExec=" + filepath + "\nIcon=" + QFileInfo(filepath).absolutePath() + "/icon.png\nPath=" + QFileInfo(filepath).absolutePath() + "\nTerminal=false\nType=Application\nMimeType=\nCategories="; 1309 | QFile file(QFileInfo(filepath).absolutePath() + "/" + QFileInfo(filepath).fileName() + ".desktop"); 1310 | if(!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)){ 1311 | QMessageBox::warning(this,"错误","不能创建 "+filepath+".desktop",QMessageBox::Yes); 1312 | } 1313 | QTextStream in(&file); 1314 | in << str; 1315 | file.close(); 1316 | return; 1317 | } 1318 | 1319 | if(result_action == action_gksu) { 1320 | QProcess *proc = new QProcess; 1321 | if(filetype == "text"){ 1322 | proc->start("gksu gedit " + filepath); 1323 | } 1324 | if(MIME == "inode/directory"){ 1325 | proc->start("gksu " + QDir::currentPath() + "/HTYFileManager " + filepath); 1326 | } 1327 | } 1328 | 1329 | foreach(QAction* action, actions) { 1330 | action->deleteLater(); 1331 | } 1332 | } 1333 | */ 1334 | 1335 | void MainWindow::customContextMenuPartition(const QPoint &pos) 1336 | { 1337 | QModelIndex index = ui->listWidget_partition->indexAt(pos); 1338 | QListWidgetItem *LWI = ui->listWidget_partition->itemAt(pos); 1339 | QAction *action_hide, *action_property; 1340 | QList actions; 1341 | action_hide = new QAction(this); 1342 | action_hide->setText("隐藏"); 1343 | actions.append(action_hide); 1344 | 1345 | action_property = new QAction(this); 1346 | action_property->setText("属性&R"); 1347 | actions.append(action_property); 1348 | 1349 | if (index.isValid()) { 1350 | 1351 | }else{ 1352 | action_hide->setVisible(false); 1353 | } 1354 | 1355 | //在菜单中显示快捷键(QT5.7已经显示,不需要) 1356 | #if (QT_VERSION >= QT_VERSION_CHECK(5,10,0)) 1357 | foreach(QAction *action, actions){ 1358 | action->setShortcutVisibleInContextMenu(true); 1359 | } 1360 | #endif 1361 | 1362 | QAction *result_action = QMenu::exec(actions, ui->listWidget_partition->mapToGlobal(pos)); 1363 | 1364 | if (result_action == action_hide) { 1365 | QString name = QFileInfo(LWI->data(LOCATION_OF_REAL_PATH).toString()).fileName(); 1366 | qDebug() << name; 1367 | if(name != ""){ 1368 | QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName()); 1369 | if(settings.value("partition_hide") == ""){ 1370 | settings.setValue("partition_hide", name); 1371 | }else{ 1372 | settings.setValue("partition_hide", settings.value("partition_hide").toString() + ";" + name); 1373 | } 1374 | genHomePage(); 1375 | } 1376 | return; 1377 | } 1378 | 1379 | if (result_action == action_property) { 1380 | if (index.isValid()) { 1381 | Form_disk *form_disk = (Form_disk*)(ui->listWidget_partition->itemWidget(ui->listWidget_partition->currentItem())); 1382 | QDialog *dialog = new QDialog; 1383 | dialog->setWindowTitle("属性"); 1384 | dialog->setFixedSize(300,250); 1385 | QVBoxLayout *vbox = new QVBoxLayout; 1386 | QLabel *label = new QLabel; 1387 | label->setAlignment(Qt::AlignCenter); 1388 | label->setPixmap(*form_disk->ui->label_icon->pixmap()); 1389 | vbox->addWidget(label); 1390 | label = new QLabel(form_disk->name); 1391 | label->setAlignment(Qt::AlignCenter); 1392 | vbox->addWidget(label); 1393 | QHBoxLayout *hbox = new QHBoxLayout; 1394 | label = new QLabel(form_disk->device); 1395 | hbox->addWidget(label); 1396 | int value = 100 * (form_disk->bytesTotal - form_disk->bytesFree) / form_disk->bytesTotal; 1397 | label = new QLabel(QString::number(value) +" %"); 1398 | label->setAlignment(Qt::AlignRight); 1399 | hbox->addWidget(label); 1400 | vbox->addLayout(hbox); 1401 | QProgressBar *progressBar = new QProgressBar; 1402 | progressBar->setRange(0,100); 1403 | progressBar->setValue(value); 1404 | progressBar->setFixedHeight(10); 1405 | progressBar->setFormat(""); 1406 | QString style; 1407 | if(value < 60){ 1408 | style = "QProgressBar { border: 1px solid gray; border-radius: 5px; background: white; }" 1409 | "QProgressBar::chunk { background-color: dodgerblue; }"; 1410 | }else if(value < 80){ 1411 | style = "QProgressBar { border: 1px solid gray; border-radius: 5px; background: white; }" 1412 | "QProgressBar::chunk { background-color: orange; }"; 1413 | }else{ 1414 | style = "QProgressBar { border: 1px solid gray; border-radius: 5px; background: white; }" 1415 | "QProgressBar::chunk { background-color: red; }"; 1416 | } 1417 | progressBar->setStyleSheet(style); 1418 | vbox->addWidget(progressBar); 1419 | QGridLayout *gridLayout = new QGridLayout; 1420 | label = new QLabel("文件系统"); 1421 | gridLayout->addWidget(label,0,0,Qt::AlignRight); 1422 | label = new QLabel(form_disk->fileSystemType); 1423 | gridLayout->addWidget(label,0,1); 1424 | label = new QLabel("总容量"); 1425 | gridLayout->addWidget(label,1,0,Qt::AlignRight); 1426 | label = new QLabel(BS(form_disk->bytesTotal,2)); 1427 | gridLayout->addWidget(label,1,1); 1428 | label = new QLabel("已用容量"); 1429 | gridLayout->addWidget(label,2,0,Qt::AlignRight); 1430 | label = new QLabel(BS(form_disk->bytesTotal - form_disk->bytesFree,2)); 1431 | gridLayout->addWidget(label,2,1); 1432 | label = new QLabel("可用容量"); 1433 | gridLayout->addWidget(label,3,0,Qt::AlignRight); 1434 | label = new QLabel(BS(form_disk->bytesFree,2)); 1435 | gridLayout->addWidget(label,3,1); 1436 | vbox->addLayout(gridLayout); 1437 | dialog->setLayout(vbox); 1438 | dialog->exec(); 1439 | }else{ 1440 | QDialog *dialog = new QDialog; 1441 | dialog->setWindowTitle("属性"); 1442 | dialog->setFixedSize(200,100); 1443 | QVBoxLayout *vbox = new QVBoxLayout; 1444 | QLabel *label = new QLabel("隐藏的分区"); 1445 | vbox->addWidget(label); 1446 | QString partition_hide = settings.value("partition_hide", "").toString(); 1447 | if (partition_hide != "") { 1448 | QStringList SL_partition_hide = partition_hide.split(";"); 1449 | for (int i=0; isetChecked(true); 1452 | connect(checkBox, static_cast(&QCheckBox::stateChanged), [=](int state){ 1453 | if (state == Qt::Checked) { 1454 | settings.sync(); 1455 | QString partition_hide1 = settings.value("partition_hide", "").toString(); 1456 | if(partition_hide1 == ""){ 1457 | partition_hide1 = checkBox->text(); 1458 | }else{ 1459 | partition_hide1 = partition_hide1 + ";" + checkBox->text(); 1460 | } 1461 | settings.setValue("partition_hide", partition_hide1); 1462 | } else if (state == Qt::PartiallyChecked) { 1463 | 1464 | } else if (state == Qt::Unchecked) { 1465 | settings.sync(); 1466 | QString partition_hide1 = settings.value("partition_hide", "").toString(); 1467 | QStringList SL_partition_hide1 = partition_hide1.split(";"); 1468 | if(SL_partition_hide1.contains(checkBox->text())){ 1469 | for(int j=0; jtext()){ 1471 | SL_partition_hide1.removeAt(j); 1472 | } 1473 | } 1474 | } 1475 | QString s = ""; 1476 | for(int j=0; jaddWidget(checkBox); 1488 | } 1489 | } 1490 | QPushButton *pushButton_confirm = new QPushButton("确定"); 1491 | QPushButton *pushButton_cancel = new QPushButton("取消"); 1492 | QHBoxLayout *hbox = new QHBoxLayout; 1493 | hbox->addStretch(); 1494 | hbox->addWidget(pushButton_confirm); 1495 | hbox->addWidget(pushButton_cancel); 1496 | hbox->addStretch(); 1497 | vbox->addLayout(hbox); 1498 | dialog->setLayout(vbox); 1499 | connect(pushButton_confirm, SIGNAL(clicked()), dialog, SLOT(accept())); 1500 | connect(pushButton_cancel, SIGNAL(clicked()), dialog, SLOT(reject())); 1501 | if(dialog->exec() == QDialog::Accepted){ 1502 | genHomePage(); 1503 | } 1504 | dialog->close(); 1505 | return; 1506 | } 1507 | } 1508 | 1509 | } 1510 | 1511 | void MainWindow::wheelEvent(QWheelEvent *e) 1512 | { 1513 | if(QApplication::keyboardModifiers() == Qt::ControlModifier){ 1514 | qDebug() << ui->listWidget->iconSize() << ui->listWidget->gridSize(); 1515 | if(e->delta() > 0){ 1516 | zoomIn(); 1517 | }else{ 1518 | zoomOut(); 1519 | } 1520 | } 1521 | } 1522 | 1523 | void MainWindow::zoomIn() 1524 | { 1525 | if(!ui->listWidget->isHidden()) 1526 | if(ui->listWidget->gridSize().width() < 400){ 1527 | ui->listWidget->setIconSize(QSize(ui->listWidget->iconSize().width()+30, ui->listWidget->iconSize().height()+30)); 1528 | //ui->listWidget->setGridSize(QSize(ui->listWidget->gridSize().width()+20, ui->listWidget->gridSize().height()+20)); 1529 | ui->listWidget->setGridSize(2*ui->listWidget->iconSize()); 1530 | } 1531 | } 1532 | 1533 | void MainWindow::zoomOut() 1534 | { 1535 | if(!ui->listWidget->isHidden()) 1536 | if(ui->listWidget->gridSize().width() > 80){ 1537 | ui->listWidget->setIconSize(QSize(ui->listWidget->iconSize().width()-30, ui->listWidget->iconSize().height()-30)); 1538 | //ui->listWidget->setGridSize(QSize(ui->listWidget->gridSize().width()-20, ui->listWidget->gridSize().height()-20)); 1539 | ui->listWidget->setGridSize(2*ui->listWidget->iconSize()); 1540 | } 1541 | } 1542 | 1543 | void MainWindow::zoom1() 1544 | { 1545 | if(!ui->listWidget->isHidden()){ 1546 | ui->listWidget->setIconSize(QSize(50, 50)); 1547 | ui->listWidget->setGridSize(QSize(100, 100)); 1548 | } 1549 | } 1550 | 1551 | QString MainWindow::BS(qint64 b, int digits) 1552 | { 1553 | QString s = ""; 1554 | if (b > 999999999) { 1555 | s = QString::number(b/(1024*1024*1024.0), 'f', digits) + " GB"; 1556 | } else { 1557 | if (b > 999999){ 1558 | s = QString::number(b/(1024*1024.0), 'f', digits) + " MB"; 1559 | } else { 1560 | if (b > 999) { 1561 | s = QString::number(b/1024.0, 'f', digits) + " KB"; 1562 | } else { 1563 | s = QString::number(b)+" B"; 1564 | } 1565 | } 1566 | } 1567 | return s; 1568 | } 1569 | 1570 | void MainWindow::enterOpen() 1571 | { 1572 | qDebug() << sender()->objectName(); 1573 | if (sender()->objectName().contains("ListWidget")) { 1574 | if(ui->listWidget->currentRow() != -1){ 1575 | open(list.at(ui->listWidget->currentRow()).absoluteFilePath()); 1576 | } 1577 | } else if (sender()->objectName().contains("TableWidget")) { 1578 | if(ui->tableWidget->currentRow() != -1){ 1579 | open(list.at(ui->tableWidget->currentRow()).absoluteFilePath()); 1580 | } 1581 | } 1582 | } 1583 | 1584 | void MainWindow::search() 1585 | { 1586 | qDebug() << "search"; 1587 | genList(path); 1588 | } 1589 | 1590 | void MainWindow::trashFiles() 1591 | { 1592 | if (!QDir(dirTrash).exists()) 1593 | QDir().mkpath(dirTrash); 1594 | if (!QDir(dirTrashInfo).exists()) 1595 | QDir().mkpath(dirTrashInfo); 1596 | modelIndexList = ui->listWidget->selectionModel()->selectedIndexes(); 1597 | foreach (QModelIndex modelIndex, modelIndexList) { 1598 | QString filepath = modelIndex.data(LOCATION_OF_REAL_PATH).toString(); 1599 | qDebug() << "trash" << filepath; 1600 | #if (QT_VERSION >= QT_VERSION_CHECK(5,15,0)) 1601 | QFile file(filepath); 1602 | if (file.moveToTrash()) 1603 | genList(path); 1604 | else 1605 | QMessageBox::critical(nullptr, "错误", "删除失败\n" + filepath); 1606 | #else 1607 | QString MIME = QMimeDatabase().mimeTypeForFile(filepath).name(); 1608 | QString newName = dirTrash + "/" + QFileInfo(filepath).fileName(); 1609 | if(QFileInfo(filepath).isSymLink()){ 1610 | QFile file(newName); 1611 | bool b = file.link(QFileInfo(filepath).symLinkTarget()); 1612 | qDebug() << newName << QFileInfo(filepath).symLinkTarget() << b; 1613 | if (b) { 1614 | QString pathinfo = dirTrashInfo + "/" + QFileInfo(filepath).fileName() + ".trashinfo"; 1615 | QFile filei(pathinfo); 1616 | if (filei.open(QIODevice::WriteOnly | QIODevice::Text)) { 1617 | QTextStream stream(&filei); 1618 | QDateTime time; 1619 | time = QDateTime::currentDateTime(); 1620 | stream << "[Trash Info]\nPath=" + filepath + "\nDeletionDate=" + time.toString("yyyy-MM-ddThh:mm:ss"); 1621 | filei.close(); 1622 | } 1623 | //if (!QFile::remove(filepath)) { 1624 | // QMessageBox::critical(NULL, "错误", "无法删除链接 " + filepath); 1625 | //} 1626 | genList(path); 1627 | } else { 1628 | QMessageBox::critical(this, "错误", "无法在回收站创建链接\n" + file.errorString()); 1629 | } 1630 | } else { 1631 | if (MIME == "inode/directory") { 1632 | QDir *dir = new QDir; 1633 | if (dir->rmdir(filepath)) { 1634 | genList(path); 1635 | } else { 1636 | QMessageBox::critical(this, "错误", "无法删除文件夹\n" + filepath); 1637 | } 1638 | } else { 1639 | if (QFile::copy(filepath, newName)) { 1640 | genList(path); 1641 | QString pathinfo = QDir::homePath() + "/.local/share/Trash/info/" + QFileInfo(filepath).fileName() + ".trashinfo"; 1642 | QFile file(pathinfo); 1643 | if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { 1644 | QTextStream stream(&file); 1645 | QDateTime time; 1646 | time = QDateTime::currentDateTime(); 1647 | stream << "[Trash Info]\nPath=" + filepath + "\nDeletionDate=" + time.toString("yyyy-MM-ddThh:mm:ss"); 1648 | file.close(); 1649 | } 1650 | if (!QFile::remove(filepath)) { 1651 | QMessageBox::critical(nullptr, "错误", "无法删除文件 " + filepath); 1652 | } 1653 | } else { 1654 | QMessageBox::critical(nullptr, "错误", "无法移动 " + filepath + " 到回收站"); 1655 | } 1656 | } 1657 | } 1658 | #endif 1659 | } 1660 | } 1661 | 1662 | void MainWindow::deleteFiles() 1663 | { 1664 | modelIndexList = ui->listWidget->selectionModel()->selectedIndexes(); 1665 | foreach (QModelIndex modelIndex, modelIndexList) { 1666 | QString filepath = modelIndex.data(LOCATION_OF_REAL_PATH).toString(); 1667 | qDebug() << "delete" << filepath; 1668 | QString MIME = QMimeDatabase().mimeTypeForFile(filepath).name(); 1669 | if (MIME == "inode/directory") { 1670 | QDir *dir = new QDir; 1671 | if (!dir->rmdir(filepath)) { 1672 | QMessageBox::critical(this, "错误", "无法删除文件夹 " + filepath); 1673 | } 1674 | } else { 1675 | if (QFile::remove(filepath)) { 1676 | if (QFileInfo(filepath).absolutePath() == dirTrash) 1677 | QFile::remove(dirTrashInfo + "/" + QFileInfo(filepath).fileName() + ".trashinfo"); 1678 | } else { 1679 | QMessageBox::critical(nullptr, "错误", "无法删除文件 " + filepath); 1680 | } 1681 | } 1682 | } 1683 | genList(path); 1684 | } 1685 | 1686 | // 递归删除文件夹 https://blog.csdn.net/u013399898/article/details/50382808 1687 | bool MainWindow::delDir(QString dirpath) 1688 | { 1689 | ui->statusBar->showMessage("删除文件夹 " + dirpath); 1690 | QDir dir(dirpath); 1691 | dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); //设置过滤 1692 | QFileInfoList fileList = dir.entryInfoList(); // 获取所有的文件信息 1693 | foreach (QFileInfo file, fileList){ //遍历文件信息 1694 | if (file.isFile()) { // 是文件,删除 1695 | ui->statusBar->showMessage("删除文件 " + file.fileName()); 1696 | bool b = file.dir().remove(file.fileName()); 1697 | if(file.dir() == dirTrash && b) 1698 | QFile::remove(dirTrashInfo + "/" + file.fileName() + ".trashinfo"); 1699 | } else { // 递归删除 1700 | delDir(file.absoluteFilePath()); 1701 | } 1702 | } 1703 | if(dirpath != dirTrash || dirpath != dirTrashInfo) 1704 | return dir.rmpath(dir.absolutePath()); // 删除文件夹 1705 | return true; 1706 | } 1707 | 1708 | void MainWindow::trashDelete() 1709 | { 1710 | if (path == dirTrash) { 1711 | deleteFiles(); 1712 | } else { 1713 | trashFiles(); 1714 | } 1715 | } 1716 | 1717 | void MainWindow::copy() 1718 | { 1719 | qDebug() << "copy"; 1720 | QList selected_items = ui->listWidget->selectedItems(); 1721 | SL_selected_files.clear(); 1722 | for(int i=0; idata(LOCATION_OF_REAL_PATH).toString(); 1724 | //QFileInfo fileInfo = selected_items.at(i)->data(FILE_INFO); 1725 | qDebug() << "copy:add(" << fp << ")"; 1726 | SL_selected_files.append(fp); 1727 | } 1728 | } 1729 | 1730 | void MainWindow::paste() 1731 | { 1732 | qDebug() << "paste"; 1733 | for(int i=0; i= QT_VERSION_CHECK(5,10,0)) 1772 | QFile file(newName); 1773 | qDebug() << "修改粘贴文件时间为原文件时间" << file.setFileTime(QFileInfo(source).lastModified(), QFileDevice::FileModificationTime); 1774 | #endif 1775 | if(cut){//如果是剪切 1776 | if(!QFile::remove(source)){ 1777 | QMessageBox::critical(nullptr, "错误", "无法删除剪切的源文件 " + source, QMessageBox::Ok); 1778 | } 1779 | } 1780 | cut=0; 1781 | genList(path); 1782 | } 1783 | } 1784 | } 1785 | } 1786 | 1787 | void MainWindow::genList(QString spath) 1788 | { 1789 | qDebug() << "genList" << spath; 1790 | appendLog("genList(" + spath + ")"); 1791 | if (spath == "trash:///") 1792 | spath = dirTrash; 1793 | else 1794 | lineEdit_location->setText(spath); 1795 | 1796 | for (int i=0; ilistWidget_nav->count(); i++) { 1797 | QString LWI_path = ui->listWidget_nav->item(i)->data(LOCATION_OF_REAL_PATH).toString(); 1798 | //qDebug() << "listWidget_nav.path" << LWI_path << spath.contains(LWI_path); 1799 | if (LWI_path != "/" && LWI_path != QDir::homePath() && spath.contains(LWI_path)) { 1800 | ui->listWidget_nav->setCurrentRow(i); 1801 | break; 1802 | } 1803 | } 1804 | 1805 | QTime time; 1806 | time.start(); 1807 | ui->listWidget->clear(); 1808 | ui->tableWidget->setRowCount(0); 1809 | // 读取文件夹下所有文件 https://www.cnblogs.com/findumars/p/6006129.html 1810 | QDir dir(spath); 1811 | if (isShowHidden) { 1812 | dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot | QDir::Hidden); 1813 | } else { 1814 | dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); 1815 | } 1816 | dir.setSorting(sortFlags); 1817 | list.clear(); 1818 | list = dir.entryInfoList(); 1819 | for (int i = 0; i < list.size(); i++) { 1820 | QString sname="", TAG="", Title="", Artist="", Album="", Year="", Comment=""; 1821 | QFileInfo fileInfo = list.at(i); 1822 | sname = fileInfo.fileName(); 1823 | if (sname.contains(lineEdit_search->text()) || lineEdit_search->text() == ""){ 1824 | QIcon icon; 1825 | QString MIME = QMimeDatabase().mimeTypeForFile(fileInfo.absoluteFilePath()).name(); 1826 | //QString filetype = MIME.left(MIME.indexOf("/")); 1827 | if (MIME == "application/x-desktop") { 1828 | sname = readSettings(fileInfo.absoluteFilePath(), "Desktop Entry", "Name"); 1829 | QString sicon = readSettings(fileInfo.absoluteFilePath(), "Desktop Entry", "Icon"); 1830 | //qDebug() << sicon; 1831 | if (sicon == "") 1832 | sicon = "applications-system-symbolic"; 1833 | if (QFileInfo(sicon).isFile()) { 1834 | icon = QIcon(sicon); 1835 | } else { 1836 | icon = QIcon::fromTheme(sicon); 1837 | } 1838 | } else if (MIME == "inode/directory") { 1839 | icon = QIcon::fromTheme("folder"); 1840 | } else if (fileInfo.suffix() == "mp3") { 1841 | QFile file(fileInfo.absoluteFilePath()); 1842 | file.open(QIODevice::ReadOnly); 1843 | QString ID3,Ver,Revision,Flag; 1844 | bool ok; 1845 | qint64 size; 1846 | ID3 = QString(file.read(3)); 1847 | icon = QIcon::fromTheme(MIME.replace("/","-")); 1848 | QTextCodec *TC = QTextCodec::codecForName("GBK"); 1849 | if (ID3 == "ID3") { 1850 | Ver = QString::number(file.read(1).toHex().toInt(&ok,16)); 1851 | Revision = QString::number(file.read(1).toHex().toInt(&ok,16)); 1852 | Flag = QString::number(file.read(1).toHex().toInt(&ok,16)); 1853 | //size = file.read(4).toHex().toLongLong(&ok,16); 1854 | size = (file.read(1).toHex().toInt(&ok,16) & 0xEF) << 21 | (file.read(1).toHex().toInt(&ok,16) & 0xEF) << 14 | (file.read(1).toHex().toInt(&ok,16) & 0xEF) << 7 | file.read(1).toHex().toInt(&ok,16) & 0xEF; 1855 | while (file.pos() < size) { 1856 | QString FTag(file.read(4)); 1857 | qint64 FSize = file.read(4).toHex().toLongLong(&ok,16); 1858 | //qint64 FSize = file.read(1).toHex().toInt(&ok,16) << 24 | file.read(1).toHex().toInt(&ok,16) << 16 | file.read(1).toHex().toInt(&ok,16) << 8 | file.read(1).toHex().toInt(&ok,16); 1859 | Flag = QString::number(file.read(2).toHex().toInt(&ok,16)); 1860 | QByteArray BA = file.read(FSize); 1861 | if (FTag == "APIC") { 1862 | BA = BA.right(FSize-14); 1863 | QPixmap pixmap; 1864 | ok = pixmap.loadFromData(BA); 1865 | if(ok){ 1866 | icon = QIcon(pixmap); 1867 | } 1868 | break; 1869 | } else if (FTag == "TYER") { 1870 | if(BA.contains("\xFF\xFE")){ 1871 | Year = QString::fromUtf16(reinterpret_cast(BA.mid(3,FSize-3).data())); 1872 | }else{ 1873 | Year = BA.mid(1,FSize-2); 1874 | } 1875 | } else if (FTag == "COMM") { 1876 | QString language = BA.mid(1,3); 1877 | Comment = language + " "+ QString::fromUtf16(reinterpret_cast(BA.mid(10,FSize-12).data())); 1878 | } else if (FTag == "TIT2") { 1879 | QByteArray UFlag = BA.left(1); 1880 | if(UFlag.toHex().toInt() == 0){ 1881 | Title = TC->toUnicode(BA); 1882 | }else{ 1883 | Title = QString::fromUtf16(reinterpret_cast(BA.right(FSize-3).data())); 1884 | } 1885 | } else if (FTag == "TPE1") { 1886 | QByteArray UFlag = BA.left(1); 1887 | if (UFlag.toHex().toInt() == 0) { 1888 | Artist = TC->toUnicode(BA); 1889 | } else { 1890 | Artist = QString::fromUtf16(reinterpret_cast(BA.right(FSize-3).data())); 1891 | } 1892 | } else if (FTag == "TALB") { 1893 | QByteArray UFlag = BA.left(1); 1894 | if (UFlag.toHex().toInt() == 0) { 1895 | Album = TC->toUnicode(BA); 1896 | } else { 1897 | Album = QString::fromUtf16(reinterpret_cast(BA.right(FSize-3).data())); 1898 | } 1899 | } 1900 | } 1901 | } 1902 | qint64 pos = file.size()-128; 1903 | file.seek(pos); 1904 | TAG = QString(file.read(3)); 1905 | if (TAG == "TAG") { 1906 | Title = TC->toUnicode(file.read(30)); 1907 | Artist = TC->toUnicode(file.read(30)); 1908 | Album = TC->toUnicode(file.read(30)); 1909 | Year = QString(file.read(4)); 1910 | Comment = TC->toUnicode(file.read(28)); 1911 | } 1912 | } else { 1913 | icon = QIcon::fromTheme(MIME.replace("/", "-")); 1914 | if(icon.isNull()){ 1915 | icon = QIcon::fromTheme("unknown"); 1916 | } 1917 | } 1918 | 1919 | if (fileInfo.isSymLink()) { 1920 | QPixmap pixmap = icon.pixmap(200, 200, QIcon::Normal, QIcon::On); 1921 | QPainter painter(&pixmap); 1922 | painter.drawPixmap(100, 100, QIcon::fromTheme("emblem-symbolic-link").pixmap(100, 100, QIcon::Normal, QIcon::On)); 1923 | icon = QIcon(pixmap); 1924 | } 1925 | 1926 | QListWidgetItem *LWI; 1927 | LWI = new QListWidgetItem(icon, sname); 1928 | LWI->setData(LOCATION_OF_REAL_PATH, fileInfo.absoluteFilePath()); 1929 | //LWI->setData(FILE_INFO, fileInfo); 1930 | LWI->setSizeHint(QSize(100,100)); 1931 | ui->listWidget->insertItem(i, LWI); 1932 | ui->statusBar->showMessage("正在预览:" + QString::number(i) + "/" + QString::number(list.size())); 1933 | ui->tableWidget ->insertRow(i); 1934 | ui->tableWidget->setItem(i, 0, new QTableWidgetItem(QIcon(icon),sname)); 1935 | ui->tableWidget->setItem(i, 1, new QTableWidgetItem(fileInfo.lastModified().toString("yyyy/MM/dd HH:mm:ss"))); 1936 | ui->tableWidget->setItem(i, 2, new QTableWidgetItem(BS(fileInfo.size(),2))); 1937 | ui->tableWidget->setItem(i, 3, new QTableWidgetItem(QMimeDatabase().mimeTypeForFile(fileInfo.filePath()).name())); 1938 | ui->tableWidget->setItem(i, 4, new QTableWidgetItem(Title)); 1939 | ui->tableWidget->setItem(i, 5, new QTableWidgetItem(Artist)); 1940 | ui->tableWidget->setItem(i, 6, new QTableWidgetItem(Album)); 1941 | ui->tableWidget->setItem(i, 7, new QTableWidgetItem(Year)); 1942 | ui->tableWidget->setItem(i, 8, new QTableWidgetItem(Comment)); 1943 | } 1944 | } 1945 | ui->tableWidget->resizeColumnsToContents(); 1946 | iconPreview(0); 1947 | isPreviewFinish = false; 1948 | if (spath == dirTrash) { 1949 | ui->statusBar->showMessage(QString::number(list.size()) + " 项目"); 1950 | } else { 1951 | ui->statusBar->showMessage("预览 " + QString::number(list.size()) + " 个文件,耗时: " + QString::number(time.elapsed()/1000) + " 秒"); 1952 | } 1953 | } 1954 | 1955 | QString MainWindow::readSettings(QString path, QString group, QString key) 1956 | { 1957 | QSettings settings(path, QSettings::IniFormat); 1958 | settings.setIniCodec("UTF-8"); 1959 | settings.beginGroup(group); 1960 | QString value = settings.value(key).toString(); 1961 | return value; 1962 | } 1963 | 1964 | void MainWindow::verticalScrollBarValueChanged(int v) 1965 | { 1966 | // 图片缩略图,硬盘读取高,分页读取 1967 | qDebug() << v << verticalScrollBar->maximum(); 1968 | if (v == verticalScrollBar->maximum()) isPreviewFinish = true; 1969 | if (!isPreviewFinish) iconPreview(v); 1970 | } 1971 | 1972 | void MainWindow::iconPreview(int v) 1973 | { 1974 | int rowCount = ui->listWidget->height() / ui->listWidget->gridSize().height(); 1975 | int columnCount = ui->listWidget->width() / ui->listWidget->gridSize().width(); 1976 | int itemCount = rowCount * columnCount; 1977 | qDebug() << "itemCount" << itemCount; 1978 | int scrolledRow = v/ui->listWidget->gridSize().height(); 1979 | qDebug() << "scrolledRow" << scrolledRow; 1980 | int startItem = scrolledRow * columnCount; 1981 | int endItem = startItem + itemCount; 1982 | qDebug() << "start:" << startItem << "end:" << endItem; 1983 | for (int i = startItem; i < endItem; i++) { 1984 | if (i < list.size()) { 1985 | QFileInfo fileInfo = list.at(i); 1986 | //QPixmap pixmap; 1987 | QString MIME = QMimeDatabase().mimeTypeForFile(fileInfo.absoluteFilePath()).name(); 1988 | QString filetype = MIME.left(MIME.indexOf("/")); 1989 | if (filetype == "image") { 1990 | //QImageReader reader(fileInfo.absoluteFilePath()); 1991 | //reader.setAutoTransform(true); 1992 | //QImage image = reader.read(); 1993 | //ui->listWidget->item(i)->setIcon(QIcon(QPixmap::fromImage(image.scaled(QSize(200,200), Qt::KeepAspectRatio)))); 1994 | IconPreview *iconPreview = new IconPreview(); 1995 | ui->listWidget->item(i)->setIcon(iconPreview->getIcon(fileInfo.absoluteFilePath())); 1996 | } 1997 | } 1998 | } 1999 | } 2000 | 2001 | void MainWindow::listWidgetItemSelectionChanged() 2002 | { 2003 | qDebug() << "listWidgetItemSelectionChanged()" << ui->listWidget->currentItem(); 2004 | } 2005 | 2006 | void MainWindow::switchHidden() 2007 | { 2008 | isShowHidden = !isShowHidden; 2009 | genList(path); 2010 | } 2011 | 2012 | void MainWindow::refresh() 2013 | { 2014 | if(path == "computer://"){ 2015 | genHomePage(); 2016 | }else{ 2017 | genList(path); 2018 | } 2019 | } 2020 | 2021 | void MainWindow::rename() 2022 | { 2023 | QList list = ui->listWidget->selectedItems(); 2024 | foreach(QListWidgetItem *LWI, list) { 2025 | //LWI->setFlags(LWI->flags() | Qt::ItemIsEditable); 2026 | ui->listWidget->openPersistentEditor(LWI); 2027 | } 2028 | } 2029 | 2030 | void MainWindow::listWidgetItemChanged(QListWidgetItem *LWI) 2031 | { 2032 | //QListWidgetItem *LWI = ui->listWidget->currentItem(); 2033 | //LWI->setFlags(LWI->flags() & (~Qt::ItemIsEditable)); 2034 | //QString oldName = LWI->text(); 2035 | QString oldName = ui->listWidget->currentItem()->text(); 2036 | QString oldPath = path + "/" + oldName; 2037 | QString newPath = path + "/" + LWI->text(); 2038 | qDebug() << "rename" << oldPath << newPath; 2039 | if (QFile::rename(oldPath, newPath)) { 2040 | genList(path); 2041 | }else{ 2042 | LWI->setText(oldName); 2043 | QMessageBox::critical(nullptr, "错误", oldName + " 无法重命名为 " + LWI->text() + " !", QMessageBox::Ok); 2044 | } 2045 | } 2046 | 2047 | void MainWindow::closeEvent(QCloseEvent *event) 2048 | { 2049 | settings.setValue("geometry", saveGeometry()); 2050 | settings.setValue("windowState", saveState()); 2051 | QMainWindow::closeEvent(event); 2052 | } 2053 | 2054 | void MainWindow::readSettings() 2055 | { 2056 | restoreGeometry(settings.value("geometry").toByteArray()); 2057 | restoreState(settings.value("windowState").toByteArray()); 2058 | } 2059 | 2060 | void MainWindow::genHomePage() 2061 | { 2062 | ui->listWidget_nav->clear(); 2063 | ui->listWidget_userdir->clear(); 2064 | ui->listWidget_partition->clear(); 2065 | //左侧导航列表 2066 | QListWidgetItem *LWI; 2067 | LWI = new QListWidgetItem(QIcon::fromTheme("folder-home"),"主目录"); 2068 | LWI->setData(LOCATION_OF_REAL_PATH, QDir::homePath()); 2069 | ui->listWidget_nav->insertItem(0, LWI); 2070 | LWI = new QListWidgetItem(QIcon::fromTheme("folder-desktop"),"桌面"); 2071 | LWI->setData(LOCATION_OF_REAL_PATH, QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); 2072 | ui->listWidget_nav->insertItem(1, LWI); 2073 | LWI = new QListWidgetItem(QIcon::fromTheme("folder-videos"),"视频"); 2074 | LWI->setData(LOCATION_OF_REAL_PATH, QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)); 2075 | ui->listWidget_nav->insertItem(2, LWI); 2076 | ui->listWidget_userdir->insertItem(0, LWI); 2077 | LWI = new QListWidgetItem(QIcon::fromTheme("folder-pictures"),"图片"); 2078 | LWI->setData(LOCATION_OF_REAL_PATH, QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); 2079 | ui->listWidget_nav->insertItem(3, LWI); 2080 | ui->listWidget_userdir->insertItem(1, LWI); 2081 | LWI = new QListWidgetItem(QIcon::fromTheme("folder-music"),"音乐"); 2082 | LWI->setData(LOCATION_OF_REAL_PATH, QStandardPaths::writableLocation(QStandardPaths::MusicLocation)); 2083 | ui->listWidget_nav->insertItem(4, LWI); 2084 | ui->listWidget_userdir->insertItem(2, LWI); 2085 | LWI = new QListWidgetItem(QIcon::fromTheme("folder-documents"),"文档"); 2086 | LWI->setData(LOCATION_OF_REAL_PATH, QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); 2087 | ui->listWidget_nav->insertItem(5, LWI); 2088 | ui->listWidget_userdir->insertItem(3, LWI); 2089 | LWI = new QListWidgetItem(QIcon::fromTheme("folder-downloads"),"下载"); 2090 | LWI->setData(LOCATION_OF_REAL_PATH, QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); 2091 | ui->listWidget_nav->insertItem(6, LWI); 2092 | ui->listWidget_userdir->insertItem(4, LWI); 2093 | LWI = new QListWidgetItem(QIcon::fromTheme("user-trash"),"回收站"); 2094 | LWI->setData(LOCATION_OF_REAL_PATH, QDir::homePath() + "/.local/share/Trash/files"); 2095 | ui->listWidget_nav->insertItem(7, LWI); 2096 | LWI = new QListWidgetItem(style()->standardIcon(QStyle::SP_ComputerIcon),"计算机"); 2097 | LWI->setData(LOCATION_OF_REAL_PATH, "computer://"); 2098 | ui->listWidget_nav->insertItem(8, LWI); 2099 | LWI = new QListWidgetItem(style()->standardIcon(QStyle::SP_DriveHDIcon),"系统盘"); 2100 | LWI->setData(LOCATION_OF_REAL_PATH, "/"); 2101 | ui->listWidget_nav->insertItem(9, LWI); 2102 | //connect(ui->listWidget_nav, SIGNAL(clicked(QModelIndex)), this, SLOT(nav(QModelIndex))); 2103 | connect(ui->listWidget_nav, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(nav(QListWidgetItem*))); 2104 | 2105 | //首页 2106 | LWI = new QListWidgetItem(QIcon::fromTheme("folder-videos"),"视频"); 2107 | LWI->setData(LOCATION_OF_REAL_PATH, QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)); 2108 | ui->listWidget_userdir->insertItem(0, LWI); 2109 | LWI = new QListWidgetItem(QIcon::fromTheme("folder-pictures"),"图片"); 2110 | LWI->setData(LOCATION_OF_REAL_PATH, QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); 2111 | ui->listWidget_userdir->insertItem(1, LWI); 2112 | LWI = new QListWidgetItem(QIcon::fromTheme("folder-music"),"音乐"); 2113 | LWI->setData(LOCATION_OF_REAL_PATH, QStandardPaths::writableLocation(QStandardPaths::MusicLocation)); 2114 | ui->listWidget_userdir->insertItem(2, LWI); 2115 | LWI = new QListWidgetItem(QIcon::fromTheme("folder-documents"),"文档"); 2116 | LWI->setData(LOCATION_OF_REAL_PATH, QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); 2117 | ui->listWidget_userdir->insertItem(3, LWI); 2118 | LWI = new QListWidgetItem(QIcon::fromTheme("folder-downloads"),"下载"); 2119 | LWI->setData(LOCATION_OF_REAL_PATH, QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); 2120 | ui->listWidget_userdir->insertItem(4, LWI); 2121 | connect(ui->listWidget_userdir, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(nav(QListWidgetItem*))); 2122 | connect(ui->listWidget_partition, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(nav(QListWidgetItem*))); 2123 | 2124 | //系统盘 2125 | QStorageInfo storage("/"); 2126 | QString mountPath = storage.rootPath(); 2127 | LWI = new QListWidgetItem(QIcon::fromTheme("drive-harddisk"), "系统盘"); 2128 | LWI->setData(LOCATION_OF_REAL_PATH, mountPath); 2129 | Form_disk *form_disk = new Form_disk; 2130 | form_disk->ui->label->setText("系统盘"); 2131 | form_disk->mountPath = mountPath; 2132 | form_disk->device = storage.device(); 2133 | form_disk->fileSystemType = storage.fileSystemType(); 2134 | form_disk->bytesFree = storage.bytesFree(); 2135 | form_disk->bytesTotal = storage.bytesTotal(); 2136 | form_disk->init(); 2137 | LWI = new QListWidgetItem(ui->listWidget_partition); 2138 | LWI->setSizeHint(QSize(120,130)); 2139 | LWI->setData(LOCATION_OF_REAL_PATH, mountPath); 2140 | ui->listWidget_partition->setItemWidget(LWI, form_disk); 2141 | ui->listWidget_partition->addItem(LWI); 2142 | //获取挂载路径 2143 | settings.sync(); 2144 | QString partition_hide = settings.value("partition_hide", "").toString(); 2145 | //qDebug() << partition_hide; 2146 | foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) { 2147 | if (storage.isValid() && storage.isReady()) { 2148 | //qDebug() << "mount" << storage.name(); 2149 | QString name = storage.name(); 2150 | if(name != ""){ 2151 | bool isHidePartition = false; 2152 | if(partition_hide != ""){ 2153 | QStringList SL_partition_hide = partition_hide.split(";"); 2154 | for(int i=0; isetData(LOCATION_OF_REAL_PATH, mountPath); 2164 | ui->listWidget_nav->insertItem(ui->listWidget_nav->count(), LWI); 2165 | Form_disk *form_disk = new Form_disk; 2166 | form_disk->name = name; 2167 | form_disk->mountPath = mountPath; 2168 | form_disk->device = storage.device(); 2169 | form_disk->fileSystemType = storage.fileSystemType(); 2170 | form_disk->bytesFree = storage.bytesFree(); 2171 | form_disk->bytesTotal = storage.bytesTotal(); 2172 | form_disk->init(); 2173 | LWI = new QListWidgetItem(ui->listWidget_partition); 2174 | LWI->setSizeHint(QSize(120,130)); 2175 | LWI->setData(LOCATION_OF_REAL_PATH, mountPath); 2176 | ui->listWidget_partition->setItemWidget(LWI, form_disk); 2177 | ui->listWidget_partition->addItem(LWI); 2178 | } 2179 | } 2180 | } 2181 | } 2182 | 2183 | ui->listWidget_nav->setCurrentRow(8); 2184 | path = "computer://"; 2185 | lineEdit_location->setText(path); 2186 | ui->listWidget->hide(); 2187 | } 2188 | 2189 | void MainWindow::resizeEvent(QResizeEvent *event) 2190 | { 2191 | Q_UNUSED(event); 2192 | QList LWIs = ui->listWidget->selectedItems(); 2193 | if (LWIs.size() > 0) 2194 | ui->listWidget->scrollToItem(LWIs.at(0), QAbstractItemView::PositionAtCenter); 2195 | } 2196 | 2197 | void MainWindow::processOutput() 2198 | { 2199 | QProcess *process = qobject_cast(sender()); 2200 | QString s = QString(process->readAllStandardOutput()); 2201 | qDebug() << s; 2202 | } 2203 | 2204 | void MainWindow::processError() 2205 | { 2206 | QProcess *process = qobject_cast(sender()); 2207 | QString s = QString(process->readAllStandardError()); 2208 | qDebug() << s; 2209 | } 2210 | 2211 | void MainWindow::appendLog(QString s) 2212 | { 2213 | QDateTime currentDateTime = QDateTime::currentDateTime(); 2214 | s = currentDateTime.toString("yyyy/MM/dd HH:mm:ss") + " : " + s + "\n"; 2215 | QString path1 = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); 2216 | QDir dir(path1); 2217 | if (!dir.exists()) 2218 | dir.mkpath(path1); 2219 | path1 = path1 + "/HTYFileManager.log"; 2220 | qDebug() << path1; 2221 | QFile file(path1); 2222 | if (file.open(QFile::WriteOnly | QFile::Append)) { 2223 | file.write(s.toUtf8()); 2224 | file.close(); 2225 | } 2226 | } 2227 | 2228 | void MainWindow::openwith_filter(QListWidget *listWidget, QString text, QLabel *label) 2229 | { 2230 | listWidget->clear(); 2231 | QStringList SL_desktop_path; 2232 | SL_desktop_path << "/usr/share/applications/" << QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.local/share/applications/"; 2233 | int count=0; 2234 | for(int j=0; jsetText("其他应用 " + QString::number(count)); 2245 | for (int i = 0; isetData(LOCATION_OF_REAL_PATH, filepath); 2262 | LWI->setSizeHint(QSize(120,120)); 2263 | listWidget->insertItem(listWidget->count() + 1, LWI); 2264 | } 2265 | } 2266 | }; -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #define LOCATION_OF_REAL_PATH Qt::UserRole + 1 5 | 6 | #include "propertydesktop.h" 7 | #include "ui_propertydesktop.h" 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace Ui { 17 | class MainWindow; 18 | } 19 | 20 | class MainWindow : public QMainWindow 21 | { 22 | Q_OBJECT 23 | 24 | public: 25 | explicit MainWindow(QWidget *parent = 0); 26 | ~MainWindow(); 27 | 28 | private: 29 | Ui::MainWindow *ui; 30 | QString BS(qint64 b, int digits); 31 | QLineEdit *lineEdit_location, *lineEdit_search; 32 | QString path, source, pathIcon, pathDesktop, dir, pathSource, dirTrash, dirTrashInfo; 33 | int cut; 34 | PropertyDesktop *dialogPD; 35 | QMenu *sortMenu; 36 | QAction *action_sortName, *action_sortSize, *action_sortType, *action_sortTime; 37 | QModelIndexList modelIndexList; 38 | //QList selected_files; 39 | QStringList SL_selected_files; 40 | //QFileInfoList SL_selected_files; 41 | void trashFiles(); 42 | void deleteFiles(); 43 | QString readSettings(QString path, QString group, QString key); 44 | void open(QString path); 45 | QFileInfoList list; 46 | bool delDir(QString dirpath); 47 | QScrollBar *verticalScrollBar; 48 | void iconPreview(int v); 49 | bool isPreviewFinish, isShowHidden; 50 | //QFileSystemWatcher *watcher; 51 | void readSettings(); 52 | void genHomePage(); 53 | QSettings settings; 54 | QDir::SortFlags sortFlags = QDir::Name | QDir::DirsFirst; 55 | void appendLog(QString s); 56 | void openwith_filter(QListWidget *listWidget, QString text, QLabel *label); 57 | 58 | protected: 59 | void wheelEvent(QWheelEvent*); 60 | void closeEvent(QCloseEvent *event); 61 | void resizeEvent(QResizeEvent *event); 62 | 63 | private slots: 64 | void on_action_changelog_triggered(); 65 | void on_action_about_triggered(); 66 | void on_action_icon_triggered(); 67 | void on_action_list_triggered(); 68 | void on_action_back_triggered(); 69 | void on_action_forward_triggered(); 70 | //void nav(QModelIndex index); 71 | void nav(QListWidgetItem *item); 72 | //void listWidgetClicked(QModelIndex index); 73 | void listWidgetDoubleClicked(QModelIndex index); 74 | void listWidgetItemClicked(QListWidgetItem *item); 75 | void listWidgetItemSelectionChanged(); 76 | void tableWidgetDoubleClicked(QModelIndex index); 77 | void lineEditLocationReturnPressed(); 78 | void customContextMenu(const QPoint &pos); 79 | //void viewContextMenuTV(const QPoint &pos); 80 | void customContextMenuPartition(const QPoint &pos); 81 | void enterOpen(); 82 | void search(); 83 | void trashDelete(); 84 | void copy(); 85 | void paste(); 86 | void genList(QString spath); 87 | void verticalScrollBarValueChanged(int v); 88 | void switchHidden(); 89 | void refresh(); 90 | void rename(); 91 | void listWidgetItemChanged(QListWidgetItem *LWI); 92 | void zoomIn(); 93 | void zoomOut(); 94 | void zoom1(); 95 | void processOutput(); 96 | void processError(); 97 | 98 | }; 99 | 100 | #endif // MAINWINDOW_H -------------------------------------------------------------------------------- /mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | 海天鹰文件管理器 15 | 16 | 17 | 18 | :/icon.png:/icon.png 19 | 20 | 21 | true 22 | 23 | 24 | 25 | 26 | 0 27 | 28 | 29 | 0 30 | 31 | 32 | 0 33 | 34 | 35 | 0 36 | 37 | 38 | 0 39 | 40 | 41 | 42 | 43 | 0 44 | 45 | 46 | 47 | 48 | 49 | 0 50 | 0 51 | 52 | 53 | 54 | 55 | 150 56 | 0 57 | 58 | 59 | 60 | 61 | 150 62 | 16777215 63 | 64 | 65 | 66 | true 67 | 68 | 69 | QAbstractItemView::NoEditTriggers 70 | 71 | 72 | 73 | 74 | 75 | 76 | background-color: rgb(255, 255, 255); 77 | 78 | 79 | 80 | 81 | 82 | 83 | 12 84 | 85 | 86 | 87 | border-bottom:1px solid #cccccc; 88 | padding-left:5px; 89 | 90 | 91 | 用户目录 92 | 93 | 94 | 95 | 96 | 97 | 98 | border:none; 99 | 100 | 101 | 102 | 70 103 | 70 104 | 105 | 106 | 107 | QListView::Static 108 | 109 | 110 | QListView::Adjust 111 | 112 | 113 | 50 114 | 115 | 116 | 117 | 120 118 | 100 119 | 120 | 121 | 122 | QListView::IconMode 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 12 131 | 132 | 133 | 134 | border-bottom:1px solid #cccccc; 135 | padding-left:5px; 136 | 137 | 138 | 内置磁盘 139 | 140 | 141 | 142 | 143 | 144 | 145 | Qt::CustomContextMenu 146 | 147 | 148 | border:none; 149 | 150 | 151 | 152 | 70 153 | 70 154 | 155 | 156 | 157 | QListView::Static 158 | 159 | 160 | QListView::Adjust 161 | 162 | 163 | 50 164 | 165 | 166 | 167 | 150 168 | 130 169 | 170 | 171 | 172 | QListView::IconMode 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 0 183 | 184 | 185 | 186 | 187 | Qt::CustomContextMenu 188 | 189 | 190 | true 191 | 192 | 193 | QAbstractItemView::ExtendedSelection 194 | 195 | 196 | 197 | 50 198 | 50 199 | 200 | 201 | 202 | QListView::Adjust 203 | 204 | 205 | 50 206 | 207 | 208 | 209 | 120 210 | 120 211 | 212 | 213 | 214 | QListView::IconMode 215 | 216 | 217 | 218 | 219 | 220 | 221 | Qt::CustomContextMenu 222 | 223 | 224 | true 225 | 226 | 227 | QAbstractItemView::NoEditTriggers 228 | 229 | 230 | QAbstractItemView::ExtendedSelection 231 | 232 | 233 | QAbstractItemView::SelectRows 234 | 235 | 236 | false 237 | 238 | 239 | true 240 | 241 | 242 | 9 243 | 244 | 245 | false 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 0 268 | 0 269 | 800 270 | 26 271 | 272 | 273 | 274 | 275 | 帮助 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | false 285 | 286 | 287 | TopToolBarArea 288 | 289 | 290 | false 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | .. 302 | 303 | 304 | 关于 305 | 306 | 307 | 308 | 309 | 310 | .. 311 | 312 | 313 | 后退 314 | 315 | 316 | 后退 317 | 318 | 319 | 320 | 321 | 322 | .. 323 | 324 | 325 | 前进 326 | 327 | 328 | 前进 329 | 330 | 331 | 332 | 333 | true 334 | 335 | 336 | true 337 | 338 | 339 | 图标 340 | 341 | 342 | 图标 343 | 344 | 345 | 346 | 347 | true 348 | 349 | 350 | 351 | 352 | 353 | 列表 354 | 355 | 356 | 357 | 15 358 | 359 | 360 | 361 | 362 | 363 | 364 | .. 365 | 366 | 367 | 更新日志 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | -------------------------------------------------------------------------------- /preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonichy/HTYFileManager/ab1122fcf9c78bdb8504e5cf0169326280039e38/preview.jpg -------------------------------------------------------------------------------- /preview_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonichy/HTYFileManager/ab1122fcf9c78bdb8504e5cf0169326280039e38/preview_table.png -------------------------------------------------------------------------------- /previewbg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sonichy/HTYFileManager/ab1122fcf9c78bdb8504e5cf0169326280039e38/previewbg.jpg -------------------------------------------------------------------------------- /propertydesktop.cpp: -------------------------------------------------------------------------------- 1 | #include "propertydesktop.h" 2 | #include "ui_propertydesktop.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | PropertyDesktop::PropertyDesktop(QWidget *parent) : 10 | QDialog(parent), 11 | ui(new Ui::PropertyDesktop) 12 | { 13 | ui->setupUi(this); 14 | setWindowFlags(Qt::Tool); 15 | setFixedSize(400,400); 16 | ui->buttonBox->button(QDialogButtonBox::Ok)->setText("保存"); 17 | ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消"); 18 | //ui->gridLayout->itemAtPosition(0,0)->setAlignment(Qt::AlignCenter); 19 | connect(ui->pushButton_icon, SIGNAL(clicked(bool)), this, SLOT(changeIcon())); 20 | 21 | QAction *action_exec = new QAction(this); 22 | action_exec->setIcon(QIcon::fromTheme("folder")); 23 | action_exec->setToolTip("选择文件"); 24 | connect(action_exec, SIGNAL(triggered(bool)), this, SLOT(changeExec())); 25 | ui->lineEdit_exec->addAction(action_exec,QLineEdit::TrailingPosition); 26 | connect(ui->lineEdit_exec, SIGNAL(textChanged(QString)), this, SLOT(lineEditExecTextChanged(QString))); 27 | 28 | QAction *action_path = new QAction(this); 29 | action_path->setIcon(QIcon::fromTheme("folder")); 30 | action_path->setToolTip("打开路径"); 31 | connect(action_path, SIGNAL(triggered(bool)), this, SLOT(openPath())); 32 | ui->lineEdit_path->addAction(action_path, QLineEdit::TrailingPosition); 33 | 34 | } 35 | 36 | PropertyDesktop::~PropertyDesktop() 37 | { 38 | delete ui; 39 | } 40 | 41 | void PropertyDesktop::changeIcon() 42 | { 43 | QString newpath = QFileDialog::getOpenFileName(this,"选择图片", iconPath, "图片文件(*.jpg *.jpeg *.png *.bmp *.svg *.ico)"); 44 | if (newpath != "") { 45 | ui->pushButton_icon->setIcon(QIcon(newpath)); 46 | iconPath = newpath; 47 | } 48 | } 49 | 50 | void PropertyDesktop::changeExec() 51 | { 52 | QString newpath = QFileDialog::getOpenFileName(this,"选择可执行文件", QFileInfo(ui->lineEdit_exec->text()).absolutePath()); 53 | if (newpath != "") { 54 | ui->lineEdit_exec->setText(newpath); 55 | } 56 | } 57 | 58 | void PropertyDesktop::openPath() 59 | { 60 | QProcess *proc = new QProcess; 61 | QString cmd = QApplication::applicationDirPath() + "/HTYFileManager " + ui->lineEdit_path->text(); 62 | qDebug() << cmd; 63 | proc->start(cmd); 64 | } 65 | 66 | void PropertyDesktop::saveDesktop(){ 67 | qDebug() << "saveDesktop"; 68 | QString strAll; 69 | QStringList SL; 70 | QFile readFile(filePath); 71 | if (readFile.open((QIODevice::ReadOnly | QIODevice::Text))) { 72 | QTextStream stream(&readFile); 73 | strAll = stream.readAll(); 74 | } 75 | readFile.close(); 76 | QFile writeFile(filePath); 77 | if (writeFile.open(QIODevice::WriteOnly | QIODevice::Text)) { 78 | QTextStream stream(&writeFile); 79 | SL = strAll.split("\n"); 80 | for (int i=0; ilineEdit_path->setText(QFileInfo(newpath).absolutePath()); 114 | } -------------------------------------------------------------------------------- /propertydesktop.h: -------------------------------------------------------------------------------- 1 | #ifndef PROPERTYDESKTOP_H 2 | #define PROPERTYDESKTOP_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class PropertyDesktop; 8 | } 9 | 10 | class PropertyDesktop : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit PropertyDesktop(QWidget *parent = 0); 16 | ~PropertyDesktop(); 17 | Ui::PropertyDesktop *ui; 18 | QString filePath, iconPath; 19 | 20 | private: 21 | void writeSettings(QString path, QString group, QString key, QString value); 22 | 23 | private slots: 24 | void changeIcon(); 25 | void changeExec(); 26 | void openPath(); 27 | void lineEditExecTextChanged(QString newpath); 28 | 29 | //public slots: 30 | void saveDesktop(); 31 | }; 32 | 33 | #endif // PROPERTYDESKTOP_H 34 | -------------------------------------------------------------------------------- /propertydesktop.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | PropertyDesktop 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 404 11 | 12 | 13 | 14 | 属性 15 | 16 | 17 | 18 | 5 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 0 27 | 0 28 | 29 | 30 | 31 | 名称: 32 | 33 | 34 | 35 | 36 | 37 | 38 | 说明: 39 | 40 | 41 | 42 | 43 | 44 | 45 | 路径: 46 | 47 | 48 | 49 | 50 | 51 | 52 | 执行: 53 | 54 | 55 | 56 | 57 | 58 | 59 | 类别: 60 | 61 | 62 | 63 | 64 | 65 | 66 | 文件路径: 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 0 99 | 0 100 | 101 | 102 | 103 | 104 | 100 105 | 100 106 | 107 | 108 | 109 | 110 | 100 111 | 100 112 | 113 | 114 | 115 | PointingHandCursor 116 | 117 | 118 | 119 | 90 120 | 90 121 | 122 | 123 | 124 | true 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | Qt::Horizontal 136 | 137 | 138 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 139 | 140 | 141 | true 142 | 143 | 144 | 145 | 146 | 147 | 148 | lineEdit_name 149 | lineEdit_exec 150 | lineEdit_path 151 | lineEdit_comment 152 | lineEdit_categories 153 | 154 | 155 | 156 | 157 | buttonBox 158 | accepted() 159 | PropertyDesktop 160 | accept() 161 | 162 | 163 | 248 164 | 254 165 | 166 | 167 | 157 168 | 274 169 | 170 | 171 | 172 | 173 | buttonBox 174 | rejected() 175 | PropertyDesktop 176 | reject() 177 | 178 | 179 | 316 180 | 260 181 | 182 | 183 | 286 184 | 274 185 | 186 | 187 | 188 | 189 | 190 | --------------------------------------------------------------------------------