2
* Copyright (C) 2012 - 2015 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "fileoperationdialog.h"
22
#include "fileoperation.h"
23
#include "renamedialog.h"
24
#include <QMessageBox>
25
#include "ui_file-operation-dialog.h"
29
FileOperationDialog::FileOperationDialog(FileOperation* _operation):
31
operation(_operation),
34
ui = new Ui::FileOperationDialog();
39
switch(_operation->type()) {
41
title = tr("Move files");
42
message = tr("Moving the following files to destination folder:");
45
title = tr("Copy Files");
46
message = tr("Copying the following files to destination folder:");
48
case FM_FILE_OP_TRASH:
49
title = tr("Trash Files");
50
message = tr("Moving the following files to trash can:");
52
case FM_FILE_OP_DELETE:
53
title = tr("Delete Files");
54
message = tr("Deleting the following files");
56
ui->destLabel->hide();
59
title = tr("Create Symlinks");
60
message = tr("Creating symlinks for the following files:");
62
case FM_FILE_OP_CHANGE_ATTR:
63
title = tr("Change Attributes");
64
message = tr("Changing attributes of the following files:");
66
ui->destLabel->hide();
68
case FM_FILE_OP_UNTRASH:
69
title = tr("Restore Trashed Files");
70
message = tr("Restoring the following files from trash can:");
72
ui->destLabel->hide();
75
ui->message->setText(message);
76
setWindowTitle(title);
80
FileOperationDialog::~FileOperationDialog() {
84
void FileOperationDialog::setDestPath(FmPath* dest) {
85
char* pathStr = fm_path_display_name(dest, false);
86
ui->dest->setText(QString::fromUtf8(pathStr));
90
void FileOperationDialog::setSourceFiles(FmPathList* srcFiles) {
92
for(l = fm_path_list_peek_head_link(srcFiles); l; l = l->next) {
93
FmPath* path = FM_PATH(l->data);
94
char* pathStr = fm_path_display_name(path, false);
95
ui->sourceFiles->addItem(QString::fromUtf8(pathStr));
100
int FileOperationDialog::ask(QString question, char*const* options) {
101
// TODO: implement FileOperationDialog::ask()
105
int FileOperationDialog::askRename(FmFileInfo* src, FmFileInfo* dest, QString& new_name) {
107
if(defaultOption == -1) { // default action is not set, ask the user
108
RenameDialog dlg(src, dest, this);
110
switch(dlg.action()) {
111
case RenameDialog::ActionOverwrite:
112
ret = FM_FILE_OP_OVERWRITE;
116
case RenameDialog::ActionRename:
117
ret = FM_FILE_OP_RENAME;
118
new_name = dlg.newName();
120
case RenameDialog::ActionIgnore:
121
ret = FM_FILE_OP_SKIP;
126
ret = FM_FILE_OP_CANCEL;
135
FmJobErrorAction FileOperationDialog::error(GError* err, FmJobErrorSeverity severity) {
136
if(severity >= FM_JOB_ERROR_MODERATE) {
137
QMessageBox::critical(this, tr("Error"), QString::fromUtf8(err->message));
138
if(severity == FM_JOB_ERROR_CRITICAL)
141
return FM_JOB_CONTINUE;
144
void FileOperationDialog::setCurFile(QString cur_file) {
145
ui->curFile->setText(cur_file);
148
void FileOperationDialog::setPercent(unsigned int percent) {
149
ui->progressBar->setValue(percent);
152
void FileOperationDialog::setRemainingTime(unsigned int sec) {
153
unsigned int min = 0;
163
ui->timeRemaining->setText(QString("%1:%2:%3")
164
.arg(hr, 2, 10, QChar('0'))
165
.arg(min, 2, 10, QChar('0'))
166
.arg(sec, 2, 10, QChar('0')));
169
void FileOperationDialog::setPrepared() {
172
void FileOperationDialog::reject() {