-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyoujianpage.cpp
172 lines (164 loc) · 5.66 KB
/
youjianpage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "youjianpage.h"
#include "ui_youjianpage.h"
YouJianPage::YouJianPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::YouJianPage)
{
ui->setupUi(this);
//新建文档最后一个自定义的文本框
connect(youjianplus,&QLineEdit::returnPressed,[=](){
//把用户自定义的项目添加到youjianlist列表
youjianlist.append(youjianplus->text());
//添加用户自定义项目到.Templates
QFile tmp(homedir+"/.Templates/"+youjianplus->text());
tmp.open(QIODevice::ReadWrite|QIODevice::Text);
tmp.close();
//清空文本框
youjianplus->setText("");
//刷新列表
updateYoujianUI();});
QDir tmpdir;
tmpdir.mkpath(homedir+"/.Templates");
//获取.Templates目录下所有文件
QString dirpath = homedir+"/.Templates";
QDir dir(dirpath);
QStringList nameFilters;
nameFilters << "*.*";
files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name);
//新建文档列表
youjianlist<<(files);
youjianlist<<("DOC 文档.doc");
youjianlist<<("DOCX 文档.docx");
youjianlist<<("PPT 演示文稿.ppt");
youjianlist<<("PPTX 演示文稿.pptx");
youjianlist<<("XLS 工作表.xls");
youjianlist<<("XLSX 工作表.xlsx");
youjianlist<<("PDF 文档.pdf");
youjianlist<<("TXT 文档.txt");
youjianlist<<("AI 图像.ai");
youjianlist<<("SVG 图像.svg");
youjianlist<<("PSD 图像.psd");
//更多工具列表
gsjulist<<"右键刷新";
gsjulist<<"Hash检验";
gsjulist<<"显示隐藏文件";
gsjulist<<"彻底删除";
gsjulist<<"复制路径";
gsjuflist<<"Refresh.desktop";
gsjuflist<<"Hash.desktop";
gsjuflist<<"Show.desktop";
gsjuflist<<"del.desktop";
gsjuflist<<"copyfilepath.desktop";
//获得oem-menuextensions目录下所有文件
dirpath = "/usr/share/deepin/dde-file-manager/oem-menuextensions";
QDir dir_2(dirpath);
nameFilters.clear();
nameFilters << "*.desktop";
files_2 = dir_2.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name);
for (int i=0;i<30;i++) {
youjian[i]=new QCheckBox;
}
updateYoujianUI();
updateGsjuUI();
}
void YouJianPage::updateGsjuUI()
{
int x=0,y=0;
ui->gridLayout_7->setColumnStretch(0,1);
ui->gridLayout_7->setColumnStretch(1,1);
for (int i=0;i<gsjulist.count();i++,x++) {
if(x==2)
{
x=0;
y++;
}
gsju[i]=new QPushButton;
ui->gridLayout_7->addWidget(gsju[i],y,x);
gsju[i]->setText(gsjulist[i]);
gsju[i]->setStatusTip(gsjuflist[i]);
//gsju[i]->statusTip()
gsju[i]->setCheckable(true);
gsjuCheckState[i]=false;
if(files_2.indexOf(gsjuflist[i])!=-1)
{
gsjuCheckState[i]=true;
gsju[i]->setChecked(gsjuCheckState[i]);
}
connect(gsju[i],&QPushButton::clicked,[=](){if(gsjuCheckState[i]==true){
QProcess *cmd=new QProcess;
cmd->start("pkexec rm -rf /usr/share/deepin/dde-file-manager/oem-menuextensions/"+gsju[i]->statusTip());
gsjuCheckState[i]=false;
cmd->waitForStarted();
}else {
QDir tmpdir;
tmpdir.mkpath("/tmp/youjian");
QFile::copy(":/kjfs/"+gsju[i]->statusTip(),"/tmp/youjian/"+gsju[i]->statusTip());
QProcess *cmd=new QProcess;
cmd->start("pkexec mv -f /tmp/youjian/"+gsju[i]->statusTip()+" /usr/share/deepin/dde-file-manager/oem-menuextensions/"+gsju[i]->statusTip());
gsjuCheckState[i]=true;
cmd->waitForStarted();
}});
}
}
void YouJianPage::updateYoujianUI()
{
QString dirpath = homedir+"/.Templates";
QDir dir(dirpath);
QStringList nameFilters;
nameFilters << "*.*";
files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name);
youjianlist = youjianlist.toSet().toList();
int x=0,y=0;
ui->gridLayout_3->setColumnStretch(0,1);
ui->gridLayout_3->setColumnStretch(1,1);
for (int i=0;i<=youjianlist.count();i++,x++) {
if(x==2)
{
x=0;
y++;
}
if(i==youjianlist.count())
{
youjianplus->setPlaceholderText("自定义 文件名.后缀");
ui->gridLayout_3->addWidget(youjianplus,y,x);
break;
}
ui->gridLayout_3->addWidget(youjian[i],y,x);
youjian[i]->setText(youjianlist[i]);
bool yesno=false;
if(files.indexOf(youjianlist[i])!=-1)
{
youjian[i]->setCheckState(Qt::Checked);
bool yesno=false;
}
connect(youjian[i],&QCheckBox::stateChanged,[=](){if(youjian[i]->checkState()==Qt::Unchecked){
QFile tmp(homedir+"/.Templates/"+youjian[i]->text());
tmp.remove();
}else {
QFile tmp(homedir+"/.Templates/"+youjian[i]->text());
tmp.open(QIODevice::ReadWrite|QIODevice::Text);
tmp.close();
}});
}
}
void YouJianPage::setTheme(bool isDark,QColor color)
{
// 菜单图标
if(isDark){
// 黑色模式
QPalette *palette = new QPalette;
palette->setColor(QPalette::Window,QColor("#282828"));
palette->setColor(QPalette::Base,QColor("#282828"));
ui->scrollArea->setPalette(*palette);
}else {
// 亮色模式
QPalette *palette = new QPalette;
palette->setColor(QPalette::Window,QColor("#FFFFFF"));
palette->setColor(QPalette::Base,QColor("#FFFFFF"));
ui->scrollArea->setPalette(*palette);
}
}
YouJianPage::~YouJianPage()
{
delete ui;
}