~feng-kylin/youker-assistant/youker-assistant

« back to all changes in this revision

Viewing changes to shredmanager/shreddialog.cpp

  • Committer: lixiang
  • Date: 2018-03-06 03:13:06 UTC
  • Revision ID: lixiang@kylinos.cn-20180306031306-fd7qnru3vm4a1xjd
Rewrite with Qt5, and add system monitor

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013 ~ 2015 National University of Defense Technology(NUDT) & Kylin Ltd.
3
 
 *
4
 
 * Authors:
5
 
 *  Kobe Lee    xiangli@ubuntukylin.com/kobe24_lixiang@126.com
6
 
 *
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.
10
 
 *
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.
15
 
 *
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/>.
18
 
 */
19
 
 
20
 
#include <QStringList>
21
 
#include <QCloseEvent>
22
 
#include <QBitmap>
23
 
#include "shredmanager.h"
24
 
#include <QFileDialog>
25
 
#include <QDir>
26
 
#include <QVBoxLayout>
27
 
#include <QHBoxLayout>
28
 
#include <QLabel>
29
 
#include <QLineEdit>
30
 
#include <QPushButton>
31
 
#include <QComboBox>
32
 
#include <QDebug>
33
 
#include "filewipe.h"
34
 
 
35
 
ShredDialog::ShredDialog(ShredManager *plugin, QDialog *parent)
36
 
    :QDialog(parent)
37
 
{
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;
43
 
 
44
 
    shredSettings = new QSettings(YOUKER_COMPANY_SETTING, YOUKER_SETTING_FILE_NAME_SETTING);
45
 
    shredSettings->setIniCodec("UTF-8");
46
 
 
47
 
    title_bar = new KylinTitleBar();
48
 
    initTitleBar();
49
 
 
50
 
    toolkits = new Toolkits(0, this->width(), this->height());
51
 
 
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);
65
 
 
66
 
    QHBoxLayout *layout1 = new QHBoxLayout();
67
 
    layout1->addStretch();
68
 
    layout1->addWidget(select_edit);
69
 
    layout1->addStretch();
70
 
 
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);
77
 
 
78
 
    QVBoxLayout *layout = new QVBoxLayout();
79
 
    layout->addStretch();
80
 
    layout->addLayout(layout1);
81
 
    layout->addLayout(layout2);
82
 
    layout->addStretch();
83
 
    layout->setSpacing(10);
84
 
 
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);
92
 
 
93
 
    this->setLanguage();
94
 
    this->initConnect();
95
 
}
96
 
 
97
 
ShredDialog::~ShredDialog()
98
 
{
99
 
    if (shredSettings != NULL)
100
 
    {
101
 
        shredSettings->sync();
102
 
        delete shredSettings;
103
 
        shredSettings = NULL;
104
 
    }
105
 
}
106
 
 
107
 
void ShredDialog::setLanguage()
108
 
{
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"));
113
 
}
114
 
 
115
 
void ShredDialog::initConnect()
116
 
{
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()));
122
 
}
123
 
 
124
 
void ShredDialog::onCloseButtonClicked()
125
 
{
126
 
    this->close();
127
 
}
128
 
 
129
 
//void ShredDialog::onMinButtonClicked()
130
 
//{
131
 
//    this->showMinimized();
132
 
////    this->hide();
133
 
//}
134
 
 
135
 
QString ShredDialog::getCurrrentSkinName()
136
 
{
137
 
    shredSettings->beginGroup("Background");
138
 
    QString skin = shredSettings->value("Path").toString();
139
 
    if(skin.isEmpty()) {
140
 
        skin = ":/background/res/skin/1.png";
141
 
    }
142
 
    else {
143
 
        QStringList skinlist;
144
 
        QString path = "/var/lib/youker-assistant-daemon/default/";
145
 
        QDir picdir(path);
146
 
        picdir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
147
 
        picdir.setSorting(QDir::Size | QDir::Reversed);
148
 
        QStringList filters;
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";
154
 
        }
155
 
        else {
156
 
            for (int j = 0; j < list.size(); ++j) {
157
 
                QFileInfo fileInfo = list.at(j);
158
 
                skinlist << path + fileInfo.fileName();
159
 
            }
160
 
            skinlist << ":/background/res/skin/1.png" << ":/background/res/skin/2.png" << ":/background/res/skin/3.png" << ":/background/res/skin/4.png";
161
 
        }
162
 
 
163
 
        QList<QString>::Iterator it = skinlist.begin(), itend = skinlist.end();
164
 
        bool flag = false;
165
 
        for(;it != itend; it++)
166
 
        {
167
 
            if(*it == skin) {
168
 
                flag = true;
169
 
                break;
170
 
            }
171
 
        }
172
 
        if (flag == false) {
173
 
            skin = skinlist.at(0);
174
 
        }
175
 
    }
176
 
    shredSettings->endGroup();
177
 
    shredSettings->sync();
178
 
    return skin;
179
 
}
180
 
 
181
 
void ShredDialog::initTitleBar()
182
 
{
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);
188
 
}
189
 
 
190
 
void ShredDialog::resetSkin()
191
 
{
192
 
    QString skin = this->getCurrrentSkinName();
193
 
    title_bar->resetBackground(skin);
194
 
}
195
 
 
196
 
//void ShredDialog::onSelecteComboActivated(int index)
197
 
//{
198
 
//}
199
 
 
200
 
void ShredDialog::onSelectButtonClicked()
201
 
{
202
 
//    QString fileName=QFileDialog::getOpenFileName(0, tr("Select file"), QDir::homePath(), tr("All Files(*)"));
203
 
 
204
 
    QStringList fileNameList;
205
 
    QString fileName;
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)
213
 
    {
214
 
        fileNameList = fd->selectedFiles();
215
 
        fileName = fileNameList[0];
216
 
        select_edit->setText(fileName);
217
 
    }
218
 
    else
219
 
        fd->close();
220
 
}
221
 
 
222
 
void ShredDialog::onShredButtonClicked()
223
 
{
224
 
    if(select_edit->text().length() == 0 || !select_edit->text().contains("/"))
225
 
    {
226
 
        toolkits->alertMSG(this->frameGeometry().topLeft().x(), this->frameGeometry().topLeft().y(), tr("Select file!"));
227
 
    }
228
 
    else
229
 
    {
230
 
        char* ch;
231
 
        QByteArray ba = select_edit->text().toUtf8();
232
 
        ch=ba.data();
233
 
        int result = do_file(ch);
234
 
        if (result == 0)
235
 
        {
236
 
            //success
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"));
239
 
        }
240
 
        else
241
 
        {
242
 
            //failed
243
 
            toolkits->alertMSG(this->frameGeometry().topLeft().x(), this->frameGeometry().topLeft().y(), tr("Shred failed!"));
244
 
        }
245
 
    }
246
 
}
247
 
 
248
 
void ShredDialog::onCacelButtonClicked()
249
 
{
250
 
    select_edit->setText(tr("No select any file which need to be shredded"));
251
 
}
252
 
 
253
 
void ShredDialog::closeEvent(QCloseEvent *event)
254
 
{
255
 
    event->accept();
256
 
//  emit SignalClose();
257
 
}