summaryrefslogtreecommitdiff
path: root/wizard/rootpartition.cpp
blob: b02037053c8b3c75976e2c94e2fc64d58d12a126 (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
#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(rootPartitionDev, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(updateComplete()));
  connect(chkAdvanced, SIGNAL(stateChanged(int)), this, SLOT(updateComplete()));
  
  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")
  {
    QListWidgetItem *item = new QListWidgetItem(QIcon::fromTheme("drive-harddisk"), line);
    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(command == "check_partitions_for_install" && checkPassed)
  {
    this->wizard()->next();
  }
}

void wpRootPartition::receivedCommand(QString command, QString args)
{
  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()->text().section(" ",0,0))
	  .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;
}