~lubuntu-dev/lxde/libfm-qt-debian-git

« back to all changes in this revision

Viewing changes to src/fileoperationdialog.cpp

  • Committer: Alf Gaida
  • Date: 2015-12-17 15:45:00 UTC
  • Revision ID: git-v1:99d4cf5e0b3761023e2285ffb96a79d050f0bdf4
Tags: upstream/0.10.0+20151214
Adding upstream version 0.10.0+20151214.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 - 2015  Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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
 
17
 *
 
18
 */
 
19
 
 
20
 
 
21
#include "fileoperationdialog.h"
 
22
#include "fileoperation.h"
 
23
#include "renamedialog.h"
 
24
#include <QMessageBox>
 
25
#include "ui_file-operation-dialog.h"
 
26
 
 
27
namespace Fm {
 
28
 
 
29
FileOperationDialog::FileOperationDialog(FileOperation* _operation):
 
30
  QDialog(NULL),
 
31
  operation(_operation),
 
32
  defaultOption(-1) {
 
33
 
 
34
  ui = new Ui::FileOperationDialog();
 
35
  ui->setupUi(this);
 
36
 
 
37
  QString title;
 
38
  QString message;
 
39
  switch(_operation->type()) {
 
40
  case FM_FILE_OP_MOVE:
 
41
      title = tr("Move files");
 
42
      message = tr("Moving the following files to destination folder:");
 
43
      break;
 
44
  case FM_FILE_OP_COPY:
 
45
      title = tr("Copy Files");
 
46
      message = tr("Copying the following files to destination folder:");
 
47
      break;
 
48
  case FM_FILE_OP_TRASH:
 
49
      title = tr("Trash Files");
 
50
      message = tr("Moving the following files to trash can:");
 
51
      break;
 
52
  case FM_FILE_OP_DELETE:
 
53
      title = tr("Delete Files");
 
54
      message = tr("Deleting the following files");
 
55
      ui->dest->hide();
 
56
      ui->destLabel->hide();
 
57
      break;
 
58
  case FM_FILE_OP_LINK:
 
59
      title = tr("Create Symlinks");
 
60
      message = tr("Creating symlinks for the following files:");
 
61
      break;
 
62
  case FM_FILE_OP_CHANGE_ATTR:
 
63
      title = tr("Change Attributes");
 
64
      message = tr("Changing attributes of the following files:");
 
65
      ui->dest->hide();
 
66
      ui->destLabel->hide();
 
67
      break;
 
68
  case FM_FILE_OP_UNTRASH:
 
69
      title = tr("Restore Trashed Files");
 
70
      message = tr("Restoring the following files from trash can:");
 
71
      ui->dest->hide();
 
72
      ui->destLabel->hide();
 
73
      break;
 
74
  }
 
75
  ui->message->setText(message);
 
76
  setWindowTitle(title);
 
77
}
 
78
 
 
79
 
 
80
FileOperationDialog::~FileOperationDialog() {
 
81
  delete ui;
 
82
}
 
83
 
 
84
void FileOperationDialog::setDestPath(FmPath* dest) {
 
85
  char* pathStr = fm_path_display_name(dest, false);
 
86
  ui->dest->setText(QString::fromUtf8(pathStr));
 
87
  g_free(pathStr);
 
88
}
 
89
 
 
90
void FileOperationDialog::setSourceFiles(FmPathList* srcFiles) {
 
91
  GList* l;
 
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));
 
96
    g_free(pathStr);
 
97
  }
 
98
}
 
99
 
 
100
int FileOperationDialog::ask(QString question, char*const* options) {
 
101
  // TODO: implement FileOperationDialog::ask()
 
102
  return 0;
 
103
}
 
104
 
 
105
int FileOperationDialog::askRename(FmFileInfo* src, FmFileInfo* dest, QString& new_name) {
 
106
  int ret;
 
107
  if(defaultOption == -1) { // default action is not set, ask the user
 
108
    RenameDialog dlg(src, dest, this);
 
109
    dlg.exec();
 
110
    switch(dlg.action()) {
 
111
      case RenameDialog::ActionOverwrite:
 
112
        ret = FM_FILE_OP_OVERWRITE;
 
113
        if(dlg.applyToAll())
 
114
          defaultOption = ret;
 
115
        break;
 
116
      case RenameDialog::ActionRename:
 
117
        ret = FM_FILE_OP_RENAME;
 
118
        new_name = dlg.newName();
 
119
        break;
 
120
      case RenameDialog::ActionIgnore:
 
121
        ret = FM_FILE_OP_SKIP;
 
122
        if(dlg.applyToAll())
 
123
          defaultOption = ret;
 
124
        break;
 
125
      default:
 
126
        ret = FM_FILE_OP_CANCEL;
 
127
        break;
 
128
    }
 
129
  }
 
130
  else
 
131
    ret = defaultOption;
 
132
  return ret;
 
133
}
 
134
 
 
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)
 
139
      return FM_JOB_ABORT;
 
140
  }
 
141
  return FM_JOB_CONTINUE;
 
142
}
 
143
 
 
144
void FileOperationDialog::setCurFile(QString cur_file) {
 
145
  ui->curFile->setText(cur_file);
 
146
}
 
147
 
 
148
void FileOperationDialog::setPercent(unsigned int percent) {
 
149
  ui->progressBar->setValue(percent);
 
150
}
 
151
 
 
152
void FileOperationDialog::setRemainingTime(unsigned int sec) {
 
153
  unsigned int min = 0;
 
154
  unsigned int hr = 0;
 
155
  if(sec > 60) {
 
156
    min = sec / 60;
 
157
    sec %= 60;
 
158
    if(min > 60) {
 
159
      hr = min / 60;
 
160
      min %= 60;
 
161
    }
 
162
  }
 
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')));
 
167
}
 
168
 
 
169
void FileOperationDialog::setPrepared() {
 
170
}
 
171
 
 
172
void FileOperationDialog::reject() {
 
173
  operation->cancel();
 
174
  QDialog::reject();
 
175
}
 
176
 
 
177
 
 
178
} // namespace Fm