summaryrefslogtreecommitdiff
path: root/wizard/bootloader.cpp
blob: 0b4ccf8be7dbbbef8f24af46e74240d7df4f93ab (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <QtGui>
#include "bootloader.h"
#include "../listdelegate.h"
#include "../listitem.h"

wpBootloader::wpBootloader(QWidget *parent) : QWizardPage(parent)
{
  setupUi(this);
  backend = Backend::instance();
  connect(backend, SIGNAL(receivedDataLine(QString,QString)), this, SLOT(receivedDataLine(QString,QString)));
  connect(backend, SIGNAL(finishedCommand(QString)), this, SLOT(backendFinishedCommand(QString)));
  connect(bootloader, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(updateComplete()));
  connect(bootloaderTarget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(updateComplete()));
  bootloaderTarget->setItemDelegate(new ListDelegate(this));
}

void wpBootloader::initializePage()
{
  clearPage();
}

void wpBootloader::clearPage()
{
  backend->exec("send_bootloaders");
  bootloader->clear();
  backend->exec("send_bootloader_targets");
  bootloaderTarget->clear();
}

void wpBootloader::receivedDataLine(QString data, QString line)
{
  if(data == "bootloaders")
  {
    QListWidgetItem *item = new QListWidgetItem(QIcon::fromTheme("system-run"), line);
    bootloader->addItem(item);
  }
  if(data == "bootloader_targets")
  {
    QString dev = line.section(" ",0,0);
    qlonglong size = line.section(" ",1,1).toLongLong();
    QString desc = QString("%1 (%L2)").arg(backend->sizeToString(size)).arg(size);
    desc += "<br />" + line.section(" ",2);
    QListWidgetItem *item = new ListItem(dev, desc, "drive-harddisk", dev);
    bootloaderTarget->addItem(item);
  }
}

void wpBootloader::backendFinishedCommand(QString command)
{
  if(command == "send_bootloaders")
  {
    bootloader->setCurrentRow(0);
  }
  if(command == "send_bootloader_targets")
  {
    bootloaderTarget->setCurrentRow(0);
  }
}

void wpBootloader::updateComplete()
{
  emit completeChanged();
}

bool wpBootloader::isComplete() const
{
  if(!bootloader->currentItem()) return false;
  if(!bootloaderTarget->currentItem()) return false;
  return true;
}

bool wpBootloader::validatePage()
{
  if(!isComplete()) return false;
  backend->cfg("bootloader", bootloader->currentItem()->text().section(" ",0,0).toLower());
  backend->cfg("bootloader_target", bootloaderTarget->currentItem()->data(ListItem::ItemData).toString());
  return true;
}