Permalink
Browse files

Get the new life preserver dataset configuration GUI working. The onl…

…y thing missing is a way to prod the backend for the current dataset frequency and number of snapshots to keep.
  • Loading branch information...
Ken Moore
Ken Moore committed Aug 15, 2013
1 parent 4d17985 commit dbee72ba1c27b35aba2e40ed8a3658714a0d255d
@@ -138,7 +138,7 @@ bool LPBackend::removeDataset(QString dataset){
}
bool LPBackend::datasetInfo(QString dataset, int& time, int& numToKeep){
- QString cmd = "lpreserver cronsnap";
+ QString cmd = "lpreserver cronsnap " + dataset;
//Need output, so run this in a QProcess
QProcess *proc = new QProcess;
proc->setProcessChannelMode(QProcess::MergedChannels);
View
@@ -0,0 +1,165 @@
+#include "LPConfig.h"
+#include "ui_LPConfig.h"
+
+LPConfig::LPConfig(QWidget *parent) : QDialog(parent), ui(new Ui::LPConfig){
+ ui->setupUi(this); //initialize the designer UI
+ qDebug() << "Initializing Configuration Dialog";
+ //initialize the output variables as necessary
+ localChanged = false;
+ remoteChanged = false;
+ //Variables that will be changed when loading the dataset properties
+
+ //now connect the buttons
+ connect(ui->tool_apply,SIGNAL(clicked()), this,SLOT(slotApplyChanges()) );
+ connect(ui->tool_cancel,SIGNAL(clicked()), this, SLOT(slotCancelConfig()) );
+}
+
+LPConfig::~LPConfig(){
+
+}
+
+void LPConfig::loadDataset(QString ds, bool replicated){
+ ui->label_dataset->setText(ds);
+ loadDatasetConfiguration(ds, replicated);
+}
+
+//==========
+// PRIVATE
+// ==========
+void LPConfig::loadDatasetConfiguration(QString dataset, bool replicated){
+ qDebug() <<" - Loading dataset configuration:" << dataset;
+ //Load the dataset values
+ isReplicated = replicated;
+ // - Local settings
+ if( !LPBackend::datasetInfo(dataset, localSchedule, localSnapshots) ){
+ localSchedule = 1; //daily at 1 AM
+ localSnapshots = 7;
+ }
+ // - Replication settings
+ bool ok=false;
+ if(isReplicated){
+ ok = LPBackend::replicationInfo(dataset, remoteHost, remoteUser, remotePort, remoteDataset, remoteFreq);
+ }
+ if(!ok){
+ isReplicated = false;
+ remotePort = 22;
+ remoteFreq = -1; //sync
+ remoteHost = "";
+ remoteUser = "";
+ remoteDataset = "";
+ }
+ //Now put the values into the UI
+ // - local settings
+ if(localSchedule == -5){ //5 minutes
+ ui->combo_local_schedule->setCurrentIndex(4);
+ }else if(localSchedule == -10){ //10 minutes
+ ui->combo_local_schedule->setCurrentIndex(3);
+ }else if(localSchedule == -30){ //30 minutes
+ ui->combo_local_schedule->setCurrentIndex(2);
+ }else if(localSchedule > 0 && localSchedule < 24){ //daily @ hour
+ ui->combo_local_schedule->setCurrentIndex(0);
+ ui->time_local_daily->setTime( QTime(localSchedule, 0) );
+ }else{ //assume hourly
+ localSchedule = -60;
+ ui->combo_local_schedule->setCurrentIndex(1);
+ }
+ setLocalKeepNumber();
+
+ // - Replication settings
+ ui->groupReplicate->setChecked(isReplicated);
+ ui->lineHostName->setText(remoteHost);
+ ui->lineUserName->setText(remoteUser);
+ ui->lineRemoteDataset->setText(remoteDataset);
+ ui->spinPort->setValue(remotePort);
+ if(remoteFreq >=0 && remoteFreq < 24){
+ ui->radioRepTime->setChecked(true);
+ ui->time_replicate->setTime( QTime(remoteFreq,0) );
+ }else{
+ ui->radioSYNC->setChecked(true);
+ }
+
+}
+
+void LPConfig::checkForChanges(){
+ //Checks for changes to the settings while also updating the output variables to match the GUI
+
+ localChanged = false;
+ remoteChanged = false;
+ //Local Settings
+ int nSchedule;
+ int schint = ui->combo_local_schedule->currentIndex();
+ if(schint == 0){ nSchedule = ui->time_local_daily->time().hour(); } //daily @ hour
+ else if(schint == 1){ nSchedule = -60; } //hourly
+ else if(schint == 2){ nSchedule = -30; } //30 min
+ else if(schint == 3){ nSchedule = -10; } //10 min
+ else{ nSchedule = -5; } //5 min
+ int nTotSnaps;
+ if( ui->combo_local_keepunits->currentIndex() == 0 && (schint != 0) ){ //days
+ int numperday = 1440/(-nSchedule);
+ nTotSnaps = numperday * ui->spin_local_numkeep->value();
+ }else{ //total number (or daily snapshots)
+ nTotSnaps = ui->spin_local_numkeep->value();
+ }
+ if(nSchedule != localSchedule){localChanged = true; localSchedule = nSchedule; }
+ if(nTotSnaps != localSnapshots){ localChanged = true; localSnapshots = nTotSnaps; }
+
+ //Replication Settings
+ if(isReplicated != ui->groupReplicate->isChecked()){
+ remoteChanged = true;
+ isReplicated = ui->groupReplicate->isChecked();
+ }
+ QString tmp = ui->lineHostName->text().simplified();
+ if( tmp != remoteHost ){ remoteChanged = true; remoteHost = tmp; }
+ tmp = ui->lineUserName->text().simplified();
+ if( tmp != remoteUser ){ remoteChanged = true; remoteUser = tmp; }
+ tmp = ui->lineRemoteDataset->text().simplified();
+ if( tmp != remoteDataset ){ remoteChanged = true; remoteDataset = tmp; }
+ if( ui->spinPort->value() != remotePort){ remoteChanged = true; remotePort = ui->spinPort->value(); }
+ int nFreq = -1;
+ if(ui->radioRepTime->isChecked()){
+ nFreq = ui->time_replicate->time().hour();
+ }
+ if(nFreq < 0){
+ if( remoteFreq >= 0 && remoteFreq < 24){remoteChanged = true; remoteFreq = nFreq;}
+ }else{
+ if( nFreq != remoteFreq ){ remoteChanged = true; remoteFreq = nFreq; }
+ }
+}
+
+void LPConfig::setLocalKeepNumber(){
+ if(localSchedule >=0){
+ ui->combo_local_keepunits->setCurrentIndex(0); //num days
+ ui->spin_local_numkeep->setValue(localSnapshots);
+ }else{
+ int numperday = 1440/(-localSchedule);
+ if( localSnapshots % numperday == 0 ){
+ //daily
+ ui->combo_local_keepunits->setCurrentIndex(0); //num days
+ ui->spin_local_numkeep->setValue(localSnapshots/numperday);
+ }else{
+ //odd number of snapshots - must be total
+ ui->combo_local_keepunits->setCurrentIndex(1); //num total
+ ui->spin_local_numkeep->setValue(localSnapshots);
+ }
+ }
+}
+
+// =============
+// PRIVATE SLOTS
+// =============
+void LPConfig::slotApplyChanges(){
+ checkForChanges();
+ this->close();
+}
+
+void LPConfig::slotCancelConfig(){
+ //Make sure it is flagged as unchanged before closing
+ localChanged = false;
+ remoteChanged = false;
+ this->close();
+}
+
+void LPConfig::on_combo_local_schedule_currentIndexChanged(int index){
+ //Adjust whether the daily time box is visible
+ ui->time_local_daily->setVisible( (index == 0) );
+}
View
@@ -0,0 +1,39 @@
+#ifndef _LP_CONFIG_H
+#define _LP_CONFIG_H
+
+#include <QDialog>
+#include <QString>
+#include <QDebug>
+
+#include "LPBackend.h"
+
+namespace Ui{
+ class LPConfig;
+}
+
+class LPConfig : public QDialog{
+ Q_OBJECT
+public:
+ LPConfig(QWidget* parent = 0);
+ ~LPConfig();
+
+ void loadDataset(QString, bool);
+
+ //Output variables
+ bool localChanged, remoteChanged, isReplicated;
+ int localSchedule, localSnapshots, remotePort, remoteFreq;
+ QString remoteHost, remoteUser, remoteDataset;
+
+private:
+ Ui::LPConfig *ui;
+ void loadDatasetConfiguration(QString, bool);
+ void checkForChanges();
+ void setLocalKeepNumber();
+
+private slots:
+ void slotApplyChanges();
+ void slotCancelConfig();
+ void on_combo_local_schedule_currentIndexChanged(int);
+};
+
+#endif
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
- <class>Dialog</class>
- <widget class="QDialog" name="Dialog">
+ <class>LPConfig</class>
+ <widget class="QDialog" name="LPConfig">
<property name="geometry">
<rect>
<x>0</x>
@@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
- <string>Dialog</string>
+ <string>Configure Dataset</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
@@ -30,9 +30,9 @@
</widget>
</item>
<item row="0" column="1">
- <widget class="QLabel" name="label_2">
+ <widget class="QLabel" name="label_dataset">
<property name="text">
- <string>/home/user</string>
+ <string notr="true">sample</string>
</property>
</widget>
</item>
@@ -50,6 +50,12 @@
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
<property name="text">
<string>Schedule:</string>
</property>
@@ -58,7 +64,7 @@
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
- <widget class="QComboBox" name="comboBox">
+ <widget class="QComboBox" name="combo_local_schedule">
<item>
<property name="text">
<string>Daily</string>
@@ -87,9 +93,23 @@
</widget>
</item>
<item>
- <widget class="QTimeEdit" name="timeEdit">
+ <widget class="QTimeEdit" name="time_local_daily">
+ <property name="maximumTime">
+ <time>
+ <hour>23</hour>
+ <minute>0</minute>
+ <second>0</second>
+ </time>
+ </property>
+ <property name="minimumTime">
+ <time>
+ <hour>1</hour>
+ <minute>0</minute>
+ <second>0</second>
+ </time>
+ </property>
<property name="displayFormat">
- <string>h AP</string>
+ <string>@ h AP</string>
</property>
</widget>
</item>
@@ -98,10 +118,17 @@
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
- <widget class="QSpinBox" name="spinBox"/>
+ <widget class="QSpinBox" name="spin_local_numkeep">
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>800</number>
+ </property>
+ </widget>
</item>
<item>
- <widget class="QComboBox" name="comboBox_2">
+ <widget class="QComboBox" name="combo_local_keepunits">
<item>
<property name="text">
<string>Days</string>
@@ -118,8 +145,14 @@
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
+ <property name="font">
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
<property name="text">
- <string>Number:</string>
+ <string>Keep:</string>
</property>
</widget>
</item>
@@ -266,7 +299,7 @@
</widget>
</item>
<item>
- <widget class="QTimeEdit" name="timeEdit_2">
+ <widget class="QTimeEdit" name="time_replicate">
<property name="displayFormat">
<string>h AP</string>
</property>
@@ -313,23 +346,39 @@
</spacer>
</item>
<item>
- <widget class="QToolButton" name="tool_save">
+ <widget class="QToolButton" name="tool_apply">
<property name="text">
<string>Apply</string>
</property>
+ <property name="icon">
+ <iconset resource="lPreserve.qrc">
+ <normaloff>:/images/backup-ok.png</normaloff>:/images/backup-ok.png</iconset>
+ </property>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonTextBesideIcon</enum>
+ </property>
</widget>
</item>
<item>
- <widget class="QToolButton" name="toolButton">
+ <widget class="QToolButton" name="tool_cancel">
<property name="text">
<string>Cancel</string>
</property>
+ <property name="icon">
+ <iconset resource="lPreserve.qrc">
+ <normaloff>:/images/application-exit.png</normaloff>:/images/application-exit.png</iconset>
+ </property>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonTextBesideIcon</enum>
+ </property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
- <resources/>
+ <resources>
+ <include location="lPreserve.qrc"/>
+ </resources>
<connections/>
</ui>
Oops, something went wrong.

0 comments on commit dbee72b

Please sign in to comment.