summaryrefslogtreecommitdiff
path: root/wizard/hdmap.cpp
blob: 10c332405989219e13a13872e5ee628ccfdaefa4 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <QtGui>
#include "hdmap.h"
#include "../listdelegate.h"
#include "../listitem.h"
#include "../mainwizard.h"

wpHdMap::wpHdMap(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)));
  tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);

  checkPassed = false;
}

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

void wpHdMap::clearPage()
{
  backend->exec("send_possible_root_filesystems");
  filesystems.clear();
  backend->exec("fill_hdmap");
  
  tableWidget->setColumnCount(4);
  tableWidget->setHorizontalHeaderLabels(QStringList() << tr("Partition") << tr("Mountpoint") << tr("Format with") << tr("Automount"));
  
//   tableWidget->horizontalHeader()->setResizeMode(1,QHeaderView::Stretch);
//   tableWidget->horizontalHeader()->setResizeMode(2,QHeaderView::Stretch);
//   tableWidget->horizontalHeader()->setResizeMode(3,QHeaderView::Stretch);
}

void wpHdMap::receivedDataLine(QString data, QString line)
{
  if(data == "possible_root_filesystems")
  {
    filesystems << line.trimmed();
  }
}

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

void wpHdMap::backendFinishedCommand(QString command)
{
  if(this->wizard()->currentId() != MainWizard::Page_HdMap) return;
  
  if(command == "fill_hdmap")
  {
  
    QStringList hdmap = backend->cfg("hdmap").split("\n");
  
    tableWidget->setRowCount(hdmap.count());  
    for(int row = 0; row < hdmap.count(); row++)
    {
      QTableWidgetItem *partition = new QTableWidgetItem(hdmap.at(row).section(":",0,0));
      partition->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
      tableWidget->setItem(row, 0, partition);
      QLineEdit *mountpoint = new QLineEdit(this);
      mountpoint->setText(hdmap.at(row).section(":",1,1));
      tableWidget->setCellWidget(row, 1, mountpoint);
      QComboBox *filesystem = new QComboBox(this);
      filesystem->addItem("");
      filesystem->addItems(filesystems);
      filesystem->setCurrentIndex(filesystems.indexOf(hdmap.at(row).section(":",2,2))+1);
      tableWidget->setCellWidget(row, 2, filesystem);
      QCheckBox *automount = new QCheckBox(this);
      automount->setText(tr("mount on boot"));
      if(hdmap.at(row).section(":",3,3) == "auto") automount->setChecked(true); else automount->setChecked(false);
      tableWidget->setCellWidget(row, 3, automount);
    }

    checkPassed = false;
  }
  else if(command == "check_partitions_for_install" && checkPassed)
  {
    this->wizard()->next();
  }
}

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

bool wpHdMap::isComplete() const
{
//  if(!rootPartitionDev->currentItem()) return false;
  return true;
}

bool wpHdMap::validatePage()
{
  if(!isComplete()) return false;
  if(checkPassed)
  {
    checkPassed = false;
    return true;
  }
  QStringList* hdmap = new QStringList();
  for(int row = 0; row < tableWidget->rowCount(); row++)
  {
    hdmap->append(QString("%1:%2:%3:%4")
      .arg(tableWidget->item(row,0)->text())
      .arg(qobject_cast<QLineEdit*>(tableWidget->cellWidget(row,1))->text())
      .arg(qobject_cast<QComboBox*>(tableWidget->cellWidget(row,2))->currentText())
      .arg(qobject_cast<QCheckBox*>(tableWidget->cellWidget(row,3))->isChecked() ? "auto" : ""));
  }
  backend->cfg("hdmap", hdmap->join("\n"));
//   backend->exec(QString("hdmap_set %1").arg(hdmap->join("\n")));
  backend->exec("check_partitions_for_install");
  checkPassed = true; // if an error occurrs receivedCommand will set it to false.
  return false;
}