File: import-dialog.cpp

package info (click to toggle)
higan 098-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 11,904 kB
  • ctags: 13,286
  • sloc: cpp: 108,285; ansic: 778; makefile: 32; sh: 18
file content (52 lines) | stat: -rw-r--r-- 1,417 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
ImportDialog::ImportDialog() {
  importDialog = this;

  onClose([&] {
    stopButton.setEnabled(false).setText("Stopping ...");
    abort = true;
  });
  layout.setMargin(5);
  stopButton.setText("Stop").onActivate([&] { doClose(); });

  setTitle("icarus - Importing ...");
  setSize({480, layout.minimumSize().height()});
  setCentered();
}

auto ImportDialog::run(lstring locations) -> void {
  abort = false;
  errors.reset();
  unsigned position = 0;

  setVisible(true);
  for(auto& location : locations) {
    auto name = nall::basename(location);

    if(abort) {
      errors.append(string{"[", name, "] aborted"});
      continue;
    }

    statusLabel.setText(name);
    double progress = 100.0 * (double)position++ / (double)locations.size() + 0.5;
    progressBar.setPosition((unsigned)progress);
    Application::processEvents();

    if(!icarus.import(location)) {
      errors.append(string{"[", name, "] ", icarus.error()});
    }
  }
  setVisible(false);

  if(errors) {
    string message{"Import completed, but with ", errors.size(), " error", errors.size() ? "s" : "", ". View log?"};
    if(MessageDialog().setTitle("icarus").setText(message).question() == "Yes") {
      errorDialog->show(errors.merge("\n"));
    } else {
      scanDialog->show();
    }
  } else {
    MessageDialog().setTitle("icarus").setText("Import completed successfully.").information();
    scanDialog->show();
  }
}