Permalink
Browse files

Add the new Template UI manager to Warden, Now we can create / remove

jail templates, and during jail creation, pick from them
  • Loading branch information...
1 parent f2cdd39 commit 6c1dd87ab25bc8558f9a7c54f96505645b878b7c @kmoore134 kmoore134 committed Jun 12, 2013
@@ -0,0 +1,150 @@
+/****************************************************************************
+** ui.h extension file, included from the uic-generated form implementation.
+**
+** If you want to add, delete, or rename functions or slots, use
+** Qt Designer to update this file, preserving your code.
+**
+** You should not define a constructor or destructor in this file.
+** Instead, write your code in functions called init() and destroy().
+** These will automatically be called by the form's constructor and
+** destructor.
+*****************************************************************************/
+#include "dialogTemplates.h"
+#include "QInputDialog"
+#include "QProcess"
+#include "QDebug"
+
+
+void dialogTemplates::programInit()
+{
+ connect( pushClose, SIGNAL(clicked()), this, SLOT( slotClose() ) );
+ connect( pushRemove, SIGNAL(clicked()), this, SLOT( slotRemove() ) );
+ connect( pushAdd, SIGNAL(clicked()), this, SLOT( slotAdd() ) );
+ loadTemps();
+}
+
+void dialogTemplates::loadTemps()
+{
+ listTemps->clear();
+
+ // Load the templates
+ QProcess m;
+ m.start(QString("warden"), QStringList() << "template" << "list");
+ while(m.state() == QProcess::Starting || m.state() == QProcess::Running) {
+ m.waitForFinished(200);
+ QCoreApplication::processEvents();
+ }
+ int i = 0;
+ QString tmp;
+ while (m.canReadLine()) {
+ i++;
+ tmp = m.readLine().simplified();
+ // Skip first two header lines
+ if ( i > 2)
+ new QTreeWidgetItem( listTemps, QStringList() << tmp.section(" ", 0, 0) \
+ << tmp.section(" - ", 1, 1).remove(tmp.section(" - ", 1, 1).lastIndexOf("("), tmp.size() ) \
+ << tmp.section("(", 1,1).replace(")", "") );
+ }
+
+}
+
+void dialogTemplates::slotAdd()
+{
+ bool ok;
+
+ QString type = QInputDialog::getItem( this, "System Type", "System Type", QStringList() << "TrueOS" << "FreeBSD", 0, false);
+ if ( type != "FreeBSD" && type != "TrueOS" )
+ return;
+
+ QString ver = QInputDialog::getText(this, tr("System Version"),
+ tr("What version do you wish to fetch?"), QLineEdit::Normal,
+ "9.1-RELEASE", &ok);
+ if (!ok || ver.isEmpty())
+ return;
+
+ QString arch = QInputDialog::getItem( this, "System Arch", "System Architecture", QStringList() << "amd64" << "i386", 0, false);
+ if ( arch != "amd64" && type != "i386" )
+ return;
+
+ QString nick = QInputDialog::getText(this, tr("Template Nickname"),
+ tr("Enter a nickname for this template:"), QLineEdit::Normal,
+ "mytemplate", &ok);
+ if (!ok || nick.isEmpty())
+ return;
+
+ dialogOutput = new dialogDisplayOutput();
+ dialogOutput->setModal(true);
+ dialogOutput->programInit(FALSE);
+ dialogOutput->setDialogCaption("Creating Template:");
+ dialogOutput->setDialogText("");
+ dialogOutput->show();
+
+ QProcess m;
+ m.setProcessChannelMode(QProcess::MergedChannels);
+ m.setReadChannel(QProcess::StandardOutput);
+
+ QStringList flags;
+ flags << "template" << "create";
+ if ( type == "TrueOS" )
+ flags << "-trueos" << ver;
+ else
+ flags << "-fbsd" << ver;
+
+ flags << "-arch" << arch;
+
+ flags << "-nick" << nick;
+
+
+ m.start(QString("warden"), flags);
+ while(m.state() == QProcess::Starting || m.state() == QProcess::Running) {
+ m.waitForFinished(200);
+ while (m.canReadLine()) {
+ dialogOutput->appendDialogText(m.readLine().simplified() + "\n");
+ }
+ QCoreApplication::processEvents();
+ }
+ while (m.canReadLine()) {
+ dialogOutput->appendDialogText(m.readLine().simplified() + "\n");
+ }
+ dialogOutput->setCloseHide(FALSE);
+ loadTemps();
+
+}
+
+void dialogTemplates::slotRemove()
+{
+ if ( ! listTemps->currentItem())
+ return;
+
+ dialogOutput = new dialogDisplayOutput();
+ dialogOutput->setModal(true);
+ dialogOutput->programInit(FALSE);
+ dialogOutput->setDialogCaption("Removing Template: " + listTemps->currentItem()->text(0));
+ dialogOutput->setDialogText("");
+ dialogOutput->show();
+
+ dialogOutput->appendDialogText("Removing template:" + listTemps->currentItem()->text(0) + "\n");
+
+ QProcess m;
+ m.setProcessChannelMode(QProcess::MergedChannels);
+ m.setReadChannel(QProcess::StandardOutput);
+
+ m.start(QString("warden"), QStringList() << "template" << "delete" << listTemps->currentItem()->text(0));
+ while(m.state() == QProcess::Starting || m.state() == QProcess::Running) {
+ m.waitForFinished(200);
+ while (m.canReadLine()) {
+ dialogOutput->appendDialogText(m.readLine().simplified() + "\n");
+ }
+ QCoreApplication::processEvents();
+ }
+ while (m.canReadLine()) {
+ dialogOutput->appendDialogText(m.readLine().simplified() + "\n");
+ }
+ dialogOutput->setCloseHide(FALSE);
+ loadTemps();
+}
+
+void dialogTemplates::slotClose()
+{
+ close();
+}
@@ -0,0 +1,33 @@
+
+#ifndef DIALOGTEMPLATES_H
+#define DIALOGTEMPLATES_H
+
+#include "ui_dialogTemplates.h"
+#include "dialogdisplayoutput.h"
+
+class dialogTemplates : public QDialog, private Ui::dialogTemplates
+{
+ Q_OBJECT
+
+public:
+ dialogTemplates() : QDialog()
+ {
+ setupUi(this);
+ }
+
+ void programInit();
+
+public slots:
+
+private slots:
+ void slotAdd();
+ void slotRemove();
+ void slotClose();
+
+private:
+ dialogDisplayOutput *dialogOutput;
+ void loadTemps();
+
+signals:
+} ;
+#endif // DIALOGTEMPLATES_H
@@ -0,0 +1,185 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>dialogTemplates</class>
+ <widget class="QDialog" name="dialogTemplates">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>424</width>
+ <height>273</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Jail Templates</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0" colspan="2">
+ <widget class="QTreeWidget" name="listTemps">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="indentation">
+ <number>0</number>
+ </property>
+ <property name="uniformRowHeights">
+ <bool>false</bool>
+ </property>
+ <property name="itemsExpandable">
+ <bool>true</bool>
+ </property>
+ <property name="sortingEnabled">
+ <bool>true</bool>
+ </property>
+ <property name="allColumnsShowFocus">
+ <bool>true</bool>
+ </property>
+ <property name="headerHidden">
+ <bool>false</bool>
+ </property>
+ <attribute name="headerVisible">
+ <bool>true</bool>
+ </attribute>
+ <attribute name="headerCascadingSectionResizes">
+ <bool>false</bool>
+ </attribute>
+ <attribute name="headerDefaultSectionSize">
+ <number>90</number>
+ </attribute>
+ <attribute name="headerMinimumSectionSize">
+ <number>90</number>
+ </attribute>
+ <attribute name="headerShowSortIndicator" stdset="0">
+ <bool>true</bool>
+ </attribute>
+ <attribute name="headerStretchLastSection">
+ <bool>true</bool>
+ </attribute>
+ <column>
+ <property name="text">
+ <string notr="true">Nickname</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string notr="true">Version</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string notr="true">Arch</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="2">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>298</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushAdd">
+ <property name="minimumSize">
+ <size>
+ <width>32</width>
+ <height>32</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>32</width>
+ <height>32</height>
+ </size>
+ </property>
+ <property name="toolTip">
+ <string>Add a new Jail</string>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="icon">
+ <iconset resource="warden.qrc">
+ <normaloff>:/edit_add.png</normaloff>:/edit_add.png</iconset>
+ </property>
+ <property name="iconSize">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushRemove">
+ <property name="minimumSize">
+ <size>
+ <width>32</width>
+ <height>32</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>32</width>
+ <height>32</height>
+ </size>
+ </property>
+ <property name="toolTip">
+ <string>Remove the selected Jail</string>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="icon">
+ <iconset resource="warden.qrc">
+ <normaloff>:/edit_remove.png</normaloff>:/edit_remove.png</iconset>
+ </property>
+ <property name="iconSize">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="2" column="0">
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="2" column="1">
+ <widget class="QPushButton" name="pushClose">
+ <property name="text">
+ <string>&amp;Close</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources>
+ <include location="warden.qrc"/>
+ </resources>
+ <connections/>
+</ui>
@@ -65,7 +65,11 @@
</layout>
</item>
<item row="0" column="0">
- <widget class="QTextEdit" name="lineDisplay"/>
+ <widget class="QTextEdit" name="lineDisplay">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
</item>
</layout>
</widget>
Oops, something went wrong.

0 comments on commit 6c1dd87

Please sign in to comment.