source: src-qt4/warden-gui/dialogTemplates.cpp @ 6c1dd87

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since 6c1dd87 was 6c1dd87, checked in by Kris Moore <kris@…>, 14 months ago

Add the new Template UI manager to Warden, Now we can create / remove
jail templates, and during jail creation, pick from them

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/****************************************************************************
2** ui.h extension file, included from the uic-generated form implementation.
3**
4** If you want to add, delete, or rename functions or slots, use
5** Qt Designer to update this file, preserving your code.
6**
7** You should not define a constructor or destructor in this file.
8** Instead, write your code in functions called init() and destroy().
9** These will automatically be called by the form's constructor and
10** destructor.
11*****************************************************************************/
12#include "dialogTemplates.h"
13#include "QInputDialog"
14#include "QProcess"
15#include "QDebug"
16
17
18void dialogTemplates::programInit()
19{
20   connect( pushClose, SIGNAL(clicked()), this, SLOT( slotClose() ) );
21   connect( pushRemove, SIGNAL(clicked()), this, SLOT( slotRemove() ) );
22   connect( pushAdd, SIGNAL(clicked()), this, SLOT( slotAdd() ) );
23   loadTemps();
24}
25
26void dialogTemplates::loadTemps()
27{
28   listTemps->clear();
29
30   // Load the templates
31   QProcess m;
32   m.start(QString("warden"), QStringList() << "template" << "list");
33   while(m.state() == QProcess::Starting || m.state() == QProcess::Running) {
34      m.waitForFinished(200);
35      QCoreApplication::processEvents();
36   }
37   int i = 0; 
38   QString tmp;
39   while (m.canReadLine()) {
40     i++;
41     tmp = m.readLine().simplified();
42     // Skip first two header lines
43     if ( i > 2)
44       new QTreeWidgetItem( listTemps, QStringList() << tmp.section(" ", 0, 0) \
45        << tmp.section(" - ", 1, 1).remove(tmp.section(" - ", 1, 1).lastIndexOf("("), tmp.size() ) \
46        << tmp.section("(", 1,1).replace(")", "") );
47   }
48
49}
50
51void dialogTemplates::slotAdd()
52{
53    bool ok;
54
55    QString type = QInputDialog::getItem( this, "System Type", "System Type", QStringList() << "TrueOS" << "FreeBSD", 0, false);
56    if ( type != "FreeBSD" && type != "TrueOS" )
57       return;
58
59    QString ver = QInputDialog::getText(this, tr("System Version"),
60                                          tr("What version do you wish to fetch?"), QLineEdit::Normal,
61                                          "9.1-RELEASE", &ok);
62    if (!ok || ver.isEmpty())
63       return;
64
65    QString arch = QInputDialog::getItem( this, "System Arch", "System Architecture", QStringList() << "amd64" << "i386", 0, false);
66    if ( arch != "amd64" && type != "i386" )
67       return;
68
69    QString nick = QInputDialog::getText(this, tr("Template Nickname"),
70                                          tr("Enter a nickname for this template:"), QLineEdit::Normal,
71                                          "mytemplate", &ok);
72    if (!ok || nick.isEmpty())
73       return;
74
75   dialogOutput = new dialogDisplayOutput();
76   dialogOutput->setModal(true);
77   dialogOutput->programInit(FALSE);
78   dialogOutput->setDialogCaption("Creating Template:");
79   dialogOutput->setDialogText("");
80   dialogOutput->show();
81
82   QProcess m;
83   m.setProcessChannelMode(QProcess::MergedChannels);
84   m.setReadChannel(QProcess::StandardOutput);
85
86   QStringList flags;
87   flags << "template" << "create";
88   if ( type == "TrueOS" )
89     flags << "-trueos" << ver;
90   else
91     flags << "-fbsd" << ver;
92
93   flags << "-arch" << arch;
94
95   flags << "-nick" << nick;
96
97
98   m.start(QString("warden"), flags);
99   while(m.state() == QProcess::Starting || m.state() == QProcess::Running) {
100      m.waitForFinished(200);
101      while (m.canReadLine()) {
102        dialogOutput->appendDialogText(m.readLine().simplified() + "\n");
103      }
104      QCoreApplication::processEvents();
105   }
106   while (m.canReadLine()) {
107     dialogOutput->appendDialogText(m.readLine().simplified() + "\n");
108   }
109   dialogOutput->setCloseHide(FALSE);
110   loadTemps();
111
112}
113
114void dialogTemplates::slotRemove()
115{
116   if ( ! listTemps->currentItem()) 
117      return;
118
119   dialogOutput = new dialogDisplayOutput();
120   dialogOutput->setModal(true);
121   dialogOutput->programInit(FALSE);
122   dialogOutput->setDialogCaption("Removing Template: " + listTemps->currentItem()->text(0));
123   dialogOutput->setDialogText("");
124   dialogOutput->show();
125
126   dialogOutput->appendDialogText("Removing template:" + listTemps->currentItem()->text(0) + "\n");
127
128   QProcess m;
129   m.setProcessChannelMode(QProcess::MergedChannels);
130   m.setReadChannel(QProcess::StandardOutput);
131
132   m.start(QString("warden"), QStringList() << "template" << "delete" << listTemps->currentItem()->text(0));
133   while(m.state() == QProcess::Starting || m.state() == QProcess::Running) {
134      m.waitForFinished(200);
135      while (m.canReadLine()) {
136        dialogOutput->appendDialogText(m.readLine().simplified() + "\n");
137      }
138      QCoreApplication::processEvents();
139   }
140   while (m.canReadLine()) {
141     dialogOutput->appendDialogText(m.readLine().simplified() + "\n");
142   }
143   dialogOutput->setCloseHide(FALSE);
144   loadTemps();
145}
146
147void dialogTemplates::slotClose()
148{
149  close();
150}
Note: See TracBrowser for help on using the repository browser.