Fixed delete dialog silent fail
[qtfileman:qtfileman.git] / src / deletedialog.cpp
1 #include "deletedialog.h"
2 #include "ui_deletedialog.h"
3
4 #include "filedeleter.h"
5
6 #include <QFileInfo>
7
8 DeleteDialog::DeleteDialog(FileDeleter *d, QWidget *parent) :
9     QDialog(parent),
10     ui(new Ui::DeleteDialog)
11 {
12     ui->setupUi(this);
13     connect(d, SIGNAL(prepareProgress(int)), this, SLOT(prepareProgress(int)));
14     connect(d, SIGNAL(delProgress(int,QString)),
15             this, SLOT(delProgress(int,QString)));
16     connect(d, SIGNAL(endDelete(bool)), this, SLOT(endDelete(bool)));
17     connect(d, SIGNAL(fail(QString)),
18             this, SLOT(delError(QString)));
19     connect(ui->buttonAbort, SIGNAL(clicked()), d, SLOT(abortDelete()));
20     connect(ui->buttonClose, SIGNAL(clicked()), this, SLOT(close()));
21 }
22
23 DeleteDialog::~DeleteDialog()
24 {
25     delete ui;
26 }
27
28 void DeleteDialog::changeEvent(QEvent *e)
29 {
30     QDialog::changeEvent(e);
31     switch (e->type()) {
32     case QEvent::LanguageChange:
33         ui->retranslateUi(this);
34         break;
35     default:
36         break;
37     }
38 }
39
40 void DeleteDialog::prepareProgress(int itemCount)
41 {
42     ui->buttonAbort->setEnabled(true);
43     ui->buttonClose->setEnabled(false);
44     ui->progressBar->setValue(0);
45     ui->label->setText(tr("Preparing to delete %1 files").arg(itemCount));
46 }
47
48 void DeleteDialog::delProgress(int percent, const QString &item)
49 {
50     ui->progressBar->setValue(percent);
51     ui->label->setText(tr("Deleting %1")
52                        .arg(QFontMetrics(ui->label->font())
53                             .elidedText(item, Qt::ElideLeft, width())));
54 }
55
56 void DeleteDialog::delError(const QString &itemOfFail)
57 {
58     ui->label->setText(tr("Error deleting %1").arg(itemOfFail));
59 }
60
61 void DeleteDialog::endDelete(bool canceled)
62 {
63     if (!canceled)
64         ui->label->setText(tr("Delete Finished Ok"));
65     ui->buttonAbort->setEnabled(false);
66     ui->buttonClose->setEnabled(true);
67 }