2
* Copyright (C) 2013 ~ 2015 National University of Defense Technology(NUDT) & Kylin Ltd.
5
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; version 3.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include <QStringList>
21
#include <QCloseEvent>
23
#include "shredmanager.h"
24
#include <QFileDialog>
26
#include <QVBoxLayout>
27
#include <QHBoxLayout>
30
#include <QPushButton>
35
ShredDialog::ShredDialog(ShredManager *plugin, QDialog *parent)
38
setWindowFlags(Qt::FramelessWindowHint);
39
this->setStyleSheet("QDialog{border: 1px solid white;border-radius:1px;background-color: #ffffff;}");
40
this->setWindowIcon(QIcon(":/res/youker-assistant.png"));
41
this->setFixedSize(500, 471);
42
process_plugin = plugin;
44
shredSettings = new QSettings(YOUKER_COMPANY_SETTING, YOUKER_SETTING_FILE_NAME_SETTING);
45
shredSettings->setIniCodec("UTF-8");
47
title_bar = new KylinTitleBar();
50
toolkits = new Toolkits(0, this->width(), this->height());
52
select_edit = new QLineEdit();
53
select_edit->setStyleSheet("QLineEdit{border:1px solid #bebebe;}");
54
select_edit->setFixedWidth(400);
55
select_edit->setReadOnly(true);
56
select_btn = new KylinEditButton(select_edit);
57
shred_btn = new QPushButton();
58
cacel_btn = new QPushButton();
59
shred_btn->setFixedSize(91, 25);
60
shred_btn->setObjectName("blackButton");
61
shred_btn->setFocusPolicy(Qt::NoFocus);
62
cacel_btn->setFixedSize(91, 25);
63
cacel_btn->setObjectName("blackButton");
64
cacel_btn->setFocusPolicy(Qt::NoFocus);
66
QHBoxLayout *layout1 = new QHBoxLayout();
67
layout1->addStretch();
68
layout1->addWidget(select_edit);
69
layout1->addStretch();
71
QHBoxLayout *layout2 = new QHBoxLayout();
72
layout2->addStretch();
73
layout2->addWidget(shred_btn);
74
layout2->addWidget(cacel_btn);
75
layout2->addStretch();
76
layout2->setMargin(0);
78
QVBoxLayout *layout = new QVBoxLayout();
80
layout->addLayout(layout1);
81
layout->addLayout(layout2);
83
layout->setSpacing(10);
85
QVBoxLayout *main_layout = new QVBoxLayout();
86
main_layout->addWidget(title_bar);
87
main_layout->addLayout(layout);
88
main_layout->setSpacing(20);
89
main_layout->setMargin(0);
90
main_layout->setContentsMargins(0, 0, 0, 0);
91
setLayout(main_layout);
97
ShredDialog::~ShredDialog()
99
if (shredSettings != NULL)
101
shredSettings->sync();
102
delete shredSettings;
103
shredSettings = NULL;
107
void ShredDialog::setLanguage()
109
this->setWindowTitle(tr("Shred Manager"));
110
select_edit->setText(tr("No select any file which need to be shredded"));
111
shred_btn->setText(tr("Shred File"));
112
cacel_btn->setText(tr("Deselect"));
115
void ShredDialog::initConnect()
117
connect(select_btn, SIGNAL(clicked()), this, SLOT(onSelectButtonClicked()));
118
connect(shred_btn, SIGNAL(clicked()), this, SLOT(onShredButtonClicked()));
119
connect(cacel_btn, SIGNAL(clicked()), this, SLOT(onCacelButtonClicked()));
120
// connect(title_bar, SIGNAL(showMinDialog()), this, SLOT(onMinButtonClicked()));
121
connect(title_bar,SIGNAL(closeDialog()), this, SLOT(onCloseButtonClicked()));
124
void ShredDialog::onCloseButtonClicked()
129
//void ShredDialog::onMinButtonClicked()
131
// this->showMinimized();
135
QString ShredDialog::getCurrrentSkinName()
137
shredSettings->beginGroup("Background");
138
QString skin = shredSettings->value("Path").toString();
140
skin = ":/background/res/skin/1.png";
143
QStringList skinlist;
144
QString path = "/var/lib/youker-assistant-daemon/default/";
146
picdir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
147
picdir.setSorting(QDir::Size | QDir::Reversed);
149
filters << "*.jpg" << "*.png";
150
picdir.setNameFilters(filters);
151
QFileInfoList list = picdir.entryInfoList();
152
if(list.size() < 1) {
153
skinlist << ":/background/res/skin/1.png" << ":/background/res/skin/2.png" << ":/background/res/skin/3.png" << ":/background/res/skin/4.png";
156
for (int j = 0; j < list.size(); ++j) {
157
QFileInfo fileInfo = list.at(j);
158
skinlist << path + fileInfo.fileName();
160
skinlist << ":/background/res/skin/1.png" << ":/background/res/skin/2.png" << ":/background/res/skin/3.png" << ":/background/res/skin/4.png";
163
QList<QString>::Iterator it = skinlist.begin(), itend = skinlist.end();
165
for(;it != itend; it++)
173
skin = skinlist.at(0);
176
shredSettings->endGroup();
177
shredSettings->sync();
181
void ShredDialog::initTitleBar()
183
QString skin = this->getCurrrentSkinName();
184
title_bar->setTitleWidth(500);
185
title_bar->setTitleName(tr("Shred Manager"));
186
// title_bar->setTitleBackgound(":/background/res/skin/1.png");
187
title_bar->setTitleBackgound(skin);
190
void ShredDialog::resetSkin()
192
QString skin = this->getCurrrentSkinName();
193
title_bar->resetBackground(skin);
196
//void ShredDialog::onSelecteComboActivated(int index)
200
void ShredDialog::onSelectButtonClicked()
202
// QString fileName=QFileDialog::getOpenFileName(0, tr("Select file"), QDir::homePath(), tr("All Files(*)"));
204
QStringList fileNameList;
206
QFileDialog* fd = new QFileDialog(this);
207
// fd->setStyleSheet("QFileDialog{background-color:blue;}");
208
fd->resize(500, 471);
209
fd->setFilter(tr("Allfile(*)"));
210
// fd->setFilter( "Allfile(*.*);;mp3file(*.mp3);;wmafile(*.wma);;wavefile(*.wav)");
211
fd->setViewMode(QFileDialog::List);//设置浏览模式,有 列表(list) 模式和 详细信息(detail)两种方式
212
if (fd->exec() == QDialog::Accepted)
214
fileNameList = fd->selectedFiles();
215
fileName = fileNameList[0];
216
select_edit->setText(fileName);
222
void ShredDialog::onShredButtonClicked()
224
if(select_edit->text().length() == 0 || !select_edit->text().contains("/"))
226
toolkits->alertMSG(this->frameGeometry().topLeft().x(), this->frameGeometry().topLeft().y(), tr("Select file!"));
231
QByteArray ba = select_edit->text().toUtf8();
233
int result = do_file(ch);
237
toolkits->alertMSG(this->frameGeometry().topLeft().x(), this->frameGeometry().topLeft().y(), tr("Shred successfully!"));
238
select_edit->setText(tr("No select any file which need to be shredded"));
243
toolkits->alertMSG(this->frameGeometry().topLeft().x(), this->frameGeometry().topLeft().y(), tr("Shred failed!"));
248
void ShredDialog::onCacelButtonClicked()
250
select_edit->setText(tr("No select any file which need to be shredded"));
253
void ShredDialog::closeEvent(QCloseEvent *event)
256
// emit SignalClose();