summaryrefslogtreecommitdiff
path: root/wizard/rootpartition.cpp
blob: 7a979d667571eef2f18e8122a954b3ec28689b98 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <QtGui>
#include "rootpartition.h"
#include "../listdelegate.h"
#include "../listitem.h"
#include "../mainwizard.h"

wpRootPartition::wpRootPartition(QWidget *parent) : QWizardPage(parent)
{
  setupUi(this);
  backend = Backend::instance();
  connect(backend, SIGNAL(receivedDataLine(QString,QString)), this, SLOT(receivedDataLine(QString,QString)));
  connect(backend, SIGNAL(receivedCommand(QString,QString)), this, SLOT(receivedCommand(QString,QString)));
  connect(backend, SIGNAL(finishedCommand(QString)), this, SLOT(backendFinishedCommand(QString)));
  connect(rootPartitionDev, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(updateComplete()));
  connect(chkAdvanced, SIGNAL(stateChanged(int)), this, SLOT(updateComplete()));
  rootPartitionDev->setItemDelegate(new ListDelegate(this));
  
  checkPassed = false;
}

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

void wpRootPartition::clearPage()
{
  backend->exec("send_possible_root_partitions");
  rootPartitionDev->clear();
  backend->exec("send_possible_root_filesystems");
  rootPartitionFs->clear();
  
  checkPassed = false;
}

void wpRootPartition::receivedDataLine(QString data, QString line)
{
  if(data == "possible_root_partitions")
  {
    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);
    rootPartitionDev->addItem(item);
  }
  if(data == "possible_root_filesystems")
  {
    rootPartitionFs->addItem(line);
  }
}

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

bool wpRootPartition::isComplete() const
{
  if(!chkAdvanced->isChecked() && !rootPartitionDev->currentItem()) return false;
  return true;
}

void wpRootPartition::backendFinishedCommand(QString command)
{
  if(this->wizard()->currentId() != MainWizard::Page_RootPartition) return;
  
  if(command == "check_partitions_for_install" && checkPassed)
  {
    this->wizard()->next();
  }
}

void wpRootPartition::receivedCommand(QString command, QString args)
{
  if(this->wizard()->currentId() != MainWizard::Page_RootPartition) return;
  
  if(command == "error") checkPassed = false;
}

bool wpRootPartition::validatePage()
{
  if(!isComplete()) return false;
  if(checkPassed)
  {
    checkPassed = false;
    return true;
  }
  if(rootPartitionDev->currentItem())
    backend->exec(QString("hdmap_set %1:/:%2:auto")
	  .arg(rootPartitionDev->currentItem()->data(ListItem::ItemData).toString())
	  .arg(chkFormat->isChecked() ? rootPartitionFs->currentText() : ""));
    backend->exec("fill_hdmap");
  
  if(chkAdvanced->isChecked()) return true;
  
  backend->exec("check_partitions_for_install");
  checkPassed = true; // if an error occurrs receivedCommand will set it to false.
  return false; 
}

int wpRootPartition::nextId() const
{
    if(chkAdvanced->isChecked())
      return MainWizard::Page_HdMap;
    else
      return MainWizard::Page_Bootloader;
}