source: src-qt4/life-preserver/lp-gui/LPConfig.cpp @ 194a5d3

releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 194a5d3 was 194a5d3, checked in by Ken Moore <ken@…>, 7 months ago

Finish updating the main Life preserver GUI to reflect the new scheduling options in lpreserver.

  • Property mode set to 100644
File size: 8.0 KB
Line 
1#include "LPConfig.h"
2#include "ui_LPConfig.h"
3
4LPConfig::LPConfig(QWidget *parent) : QDialog(parent), ui(new Ui::LPConfig){
5  ui->setupUi(this); //initialize the designer UI
6  qDebug() << "Initializing Configuration Dialog";
7  //initialize the output variables as necessary
8  localChanged = false;
9  remoteChanged = false;
10  //Variables that will be changed when loading the dataset properties
11       
12  //now connect the buttons
13  connect(ui->tool_apply,SIGNAL(clicked()), this,SLOT(slotApplyChanges()) );
14  connect(ui->tool_cancel,SIGNAL(clicked()), this, SLOT(slotCancelConfig()) );
15  connect(ui->push_scanNetwork, SIGNAL(clicked()), this, SLOT(autoDetectReplicationTargets()) );
16}
17
18LPConfig::~LPConfig(){
19       
20}
21
22void LPConfig::loadDataset(QString ds, bool replicated){
23  ui->label_dataset->setText(ds);
24  loadDatasetConfiguration(ds, replicated);
25}
26
27//==========
28//     PRIVATE
29// ==========
30void LPConfig::loadDatasetConfiguration(QString dataset, bool replicated){
31  qDebug() <<" - Loading dataset configuration:" << dataset;
32  //Load the dataset values
33  isReplicated = replicated;
34  // - Local settings
35  if( !LPBackend::datasetInfo(dataset, localSchedule, localSnapshots) ){
36    localSchedule = 1; //daily at 1 AM
37    localSnapshots = 7;
38  }       
39  // - Replication settings
40  bool ok=false;
41  if(isReplicated){
42    ok = LPBackend::replicationInfo(dataset, remoteHost, remoteUser, remotePort, remoteDataset, remoteFreq);
43  }
44  if(!ok){
45    isReplicated = false;
46    remotePort = 22;
47    remoteFreq = -1; //sync
48    remoteHost = "";
49    remoteUser = "";
50    remoteDataset = "";
51  }
52  //Now put the values into the UI
53  // - local settings
54  if(localSchedule == -5){ //5 minutes
55    ui->combo_local_schedule->setCurrentIndex(5);         
56  }else if(localSchedule == -10){ //10 minutes
57    ui->combo_local_schedule->setCurrentIndex(4);       
58  }else if(localSchedule == -30){ //30 minutes
59    ui->combo_local_schedule->setCurrentIndex(3);         
60  }else if(localSchedule == -60){ //assume hourly
61    ui->combo_local_schedule->setCurrentIndex(2);       
62  }else if(localSchedule > 0 && localSchedule < 24){ //daily @ hour
63    ui->combo_local_schedule->setCurrentIndex(1);
64    ui->time_local_daily->setTime( QTime(localSchedule, 0) );
65  }else{ //assume auto
66    localSchedule = -999; //just to make sure it does not match anything else
67    ui->combo_local_schedule->setCurrentIndex(0);
68  }
69  setLocalKeepNumber();
70       
71  // - Replication settings
72  ui->groupReplicate->setChecked(isReplicated);
73  ui->lineHostName->setText(remoteHost);
74  ui->lineUserName->setText(remoteUser);
75  ui->lineRemoteDataset->setText(remoteDataset);
76  ui->spinPort->setValue(remotePort);
77  if(remoteFreq >=0 && remoteFreq < 24){
78    ui->combo_remote_schedule->setCurrentIndex(1); //Daily @
79    ui->time_replicate->setTime( QTime(remoteFreq,0) );
80  }else if(remoteFreq == -60){
81    ui->combo_remote_schedule->setCurrentIndex(2); //Hourly
82  }else if(remoteFreq == -30){
83    ui->combo_remote_schedule->setCurrentIndex(3); // 30 minutes
84  }else if(remoteFreq == -10){
85    ui->combo_remote_schedule->setCurrentIndex(4); // 10 minutes
86  }else{
87    remoteFreq = -999; //just to make sure it is the "other" case
88    ui->combo_remote_schedule->setCurrentIndex(0); // Sync
89  }
90  //Now update the visibility of items appropriately
91  on_combo_local_schedule_currentIndexChanged(ui->combo_local_schedule->currentIndex());
92  on_combo_remote_schedule_currentIndexChanged(ui->combo_remote_schedule->currentIndex());
93}
94
95void LPConfig::checkForChanges(){
96  //Checks for changes to the settings while also updating the output variables to match the GUI
97       
98  localChanged = false;
99  remoteChanged = false;
100  //Local Settings
101  int nSchedule;
102  int schint = ui->combo_local_schedule->currentIndex();
103  if(schint == 0){ nSchedule = -999; } //Auto
104  if(schint == 1){ nSchedule = ui->time_local_daily->time().hour(); } //daily @ hour
105  else if(schint == 2){ nSchedule = -60; } //hourly
106  else if(schint == 3){ nSchedule = -30; } //30 min
107  else if(schint == 4){ nSchedule = -10; } //10 min
108  else{ nSchedule = -5; } //5 min
109  int nTotSnaps;
110  if( ui->combo_local_keepunits->currentIndex() == 0 && (schint != 1) ){ //days
111    int numperday = 1440/(-nSchedule);
112    nTotSnaps = numperday * ui->spin_local_numkeep->value();
113  }else{ //total number (or daily snapshots)
114    nTotSnaps = ui->spin_local_numkeep->value();
115  }
116  if(nSchedule != localSchedule){localChanged = true; localSchedule = nSchedule; }
117  if(nTotSnaps != localSnapshots){ localChanged = true; localSnapshots = nTotSnaps; }
118 
119  //Replication Settings
120  bool updateSSHKey = false;
121  if(isReplicated != ui->groupReplicate->isChecked()){
122    remoteChanged = true;
123    isReplicated = ui->groupReplicate->isChecked();
124    if(isReplicated){ updateSSHKey = true; }
125  }
126  QString tmp = ui->lineHostName->text().simplified();
127  if( tmp != remoteHost ){ remoteChanged = true; remoteHost = tmp; updateSSHKey=true;}
128  tmp = ui->lineUserName->text().simplified();
129  if( tmp != remoteUser ){ remoteChanged = true; remoteUser = tmp; updateSSHKey=true;}
130  tmp = ui->lineRemoteDataset->text().simplified();
131  if( tmp != remoteDataset ){ remoteChanged = true; remoteDataset = tmp; }
132  if( ui->spinPort->value() != remotePort){ remoteChanged = true; remotePort = ui->spinPort->value(); updateSSHKey=true;}
133 
134  int nFreq = ui->combo_remote_schedule->currentIndex();
135  if(nFreq == 0){
136    nFreq = -999; //Sync
137  }else if(nFreq==1){
138    nFreq = ui->time_replicate->time().hour(); //Daily @
139  }else if(nFreq==2){
140    nFreq = -60; //Hourly
141  }else if(nFreq==3){
142    nFreq = -30; //30 minutes
143  }else{
144    nFreq = -10; //10 minutes
145  }
146  if( nFreq != remoteFreq ){ remoteChanged = true; remoteFreq = nFreq; }
147
148  if(updateSSHKey){
149    //Prompt for the SSH key generation
150    LPBackend::setupSSHKey(remoteHost, remoteUser, remotePort);
151  }
152}
153
154void LPConfig::setLocalKeepNumber(){
155  if(localSchedule >=0){
156    ui->combo_local_keepunits->setCurrentIndex(0); //num days
157    ui->spin_local_numkeep->setValue(localSnapshots);   
158  }else{
159    int numperday = 1440/(-localSchedule);
160    if( localSnapshots % numperday == 0 ){
161        //daily
162        ui->combo_local_keepunits->setCurrentIndex(0); //num days
163        ui->spin_local_numkeep->setValue(localSnapshots/numperday);
164    }else{
165        //odd number of snapshots - must be total
166        ui->combo_local_keepunits->setCurrentIndex(1); //num total
167        ui->spin_local_numkeep->setValue(localSnapshots);
168    }
169  }
170}
171
172// =============
173//    PRIVATE SLOTS
174// =============
175void LPConfig::slotApplyChanges(){
176  checkForChanges();
177  this->close();
178}
179
180void LPConfig::slotCancelConfig(){
181  //Make sure it is flagged as unchanged before closing
182  localChanged = false;
183  remoteChanged = false; 
184  this->close();
185}
186
187void LPConfig::on_combo_local_schedule_currentIndexChanged(int index){
188  //Adjust whether the daily time box is visible
189  ui->time_local_daily->setVisible( (index == 1) );
190  //Show the Number to keep options if applicable
191  ui->spin_local_numkeep->setVisible( (index!=0) );
192  ui->label_local_keep->setVisible( (index!=0) );
193  ui->combo_local_keepunits->setVisible( (index!=0) );
194}
195
196void LPConfig::on_combo_remote_schedule_currentIndexChanged(int index){
197  //Adjust whether the daily time box is visible
198  ui->time_replicate->setVisible( (index == 1) );
199}
200
201void LPConfig::autoDetectReplicationTargets(){
202  QStringList targs = LPGUtils::scanNetworkSSH(); // <name>:::<address>:::<port>
203  if(targs.isEmpty()){
204    QMessageBox::warning(this,tr("No Network Targets"), tr("We could not find any systems on the local network with SSH availability (port 22)") );
205    return;
206  }
207  //Ask the user to select a target
208  QStringList targets;
209  for(int i=0; i<targs.length(); i++){
210    targets << targs[i].section(":::",0,0);
211  }
212  bool ok;
213  QString target = QInputDialog::getItem(this, tr("Select Replication Target"), tr("Hostname:"), targets, 0, false, &ok);
214  if(!ok || target.isEmpty() ){ return; } //cancelled
215  //Now look for that target in the list of info
216  for(int i=0; i<targs.length(); i++){
217    if(targs[i].startsWith(target+":::")){
218      ui->lineHostName->setText(targs[i].section(":::",1,1));
219      ui->spinPort->setValue( targs[i].section(":::",2,2).toInt() );
220      break;
221    }
222  }
223}
Note: See TracBrowser for help on using the repository browser.