source: src-qt4/life-preserver/lp-gui/LPConfig.cpp @ 6a2483b

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since 6a2483b was 6a2483b, checked in by Ken Moore <ken@…>, 10 months ago

Remove the old life-preserver from the src-qt4/life-preserver dir, and replace it with src-qt4/life-preserver/lp-tray and src-qt4/life-preserver/lp-gui.

  • Property mode set to 100644
File size: 5.7 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}
16
17LPConfig::~LPConfig(){
18       
19}
20
21void LPConfig::loadDataset(QString ds, bool replicated){
22  ui->label_dataset->setText(ds);
23  loadDatasetConfiguration(ds, replicated);
24}
25
26//==========
27//     PRIVATE
28// ==========
29void LPConfig::loadDatasetConfiguration(QString dataset, bool replicated){
30  qDebug() <<" - Loading dataset configuration:" << dataset;
31  //Load the dataset values
32  isReplicated = replicated;
33  // - Local settings
34  if( !LPBackend::datasetInfo(dataset, localSchedule, localSnapshots) ){
35    localSchedule = 1; //daily at 1 AM
36    localSnapshots = 7;
37  }       
38  // - Replication settings
39  bool ok=false;
40  if(isReplicated){
41    ok = LPBackend::replicationInfo(dataset, remoteHost, remoteUser, remotePort, remoteDataset, remoteFreq);
42  }
43  if(!ok){
44    isReplicated = false;
45    remotePort = 22;
46    remoteFreq = -1; //sync
47    remoteHost = "";
48    remoteUser = "";
49    remoteDataset = "";
50  }
51  //Now put the values into the UI
52  // - local settings
53  if(localSchedule == -5){ //5 minutes
54    ui->combo_local_schedule->setCurrentIndex(4);         
55  }else if(localSchedule == -10){ //10 minutes
56    ui->combo_local_schedule->setCurrentIndex(3);       
57  }else if(localSchedule == -30){ //30 minutes
58    ui->combo_local_schedule->setCurrentIndex(2);         
59  }else if(localSchedule > 0 && localSchedule < 24){ //daily @ hour
60    ui->combo_local_schedule->setCurrentIndex(0);
61    ui->time_local_daily->setTime( QTime(localSchedule, 0) );
62  }else{ //assume hourly
63    localSchedule = -60;
64    ui->combo_local_schedule->setCurrentIndex(1);         
65  }
66  setLocalKeepNumber();
67       
68  // - Replication settings
69  ui->groupReplicate->setChecked(isReplicated);
70  ui->lineHostName->setText(remoteHost);
71  ui->lineUserName->setText(remoteUser);
72  ui->lineRemoteDataset->setText(remoteDataset);
73  ui->spinPort->setValue(remotePort);
74  if(remoteFreq >=0 && remoteFreq < 24){
75    ui->radioRepTime->setChecked(true);
76    ui->time_replicate->setTime( QTime(remoteFreq,0) );
77  }else{
78    ui->radioSYNC->setChecked(true);
79  }
80 
81}
82
83void LPConfig::checkForChanges(){
84  //Checks for changes to the settings while also updating the output variables to match the GUI
85       
86  localChanged = false;
87  remoteChanged = false;
88  //Local Settings
89  int nSchedule;
90  int schint = ui->combo_local_schedule->currentIndex();
91  if(schint == 0){ nSchedule = ui->time_local_daily->time().hour(); } //daily @ hour
92  else if(schint == 1){ nSchedule = -60; } //hourly
93  else if(schint == 2){ nSchedule = -30; } //30 min
94  else if(schint == 3){ nSchedule = -10; } //10 min
95  else{ nSchedule = -5; } //5 min
96  int nTotSnaps;
97  if( ui->combo_local_keepunits->currentIndex() == 0 && (schint != 0) ){ //days
98    int numperday = 1440/(-nSchedule);
99    nTotSnaps = numperday * ui->spin_local_numkeep->value();
100  }else{ //total number (or daily snapshots)
101    nTotSnaps = ui->spin_local_numkeep->value();
102  }
103  if(nSchedule != localSchedule){localChanged = true; localSchedule = nSchedule; }
104  if(nTotSnaps != localSnapshots){ localChanged = true; localSnapshots = nTotSnaps; }
105 
106  //Replication Settings
107  bool updateSSHKey = false;
108  if(isReplicated != ui->groupReplicate->isChecked()){
109    remoteChanged = true;
110    isReplicated = ui->groupReplicate->isChecked();
111    if(isReplicated){ updateSSHKey = true; }
112  }
113  QString tmp = ui->lineHostName->text().simplified();
114  if( tmp != remoteHost ){ remoteChanged = true; remoteHost = tmp; updateSSHKey=true;}
115  tmp = ui->lineUserName->text().simplified();
116  if( tmp != remoteUser ){ remoteChanged = true; remoteUser = tmp; updateSSHKey=true;}
117  tmp = ui->lineRemoteDataset->text().simplified();
118  if( tmp != remoteDataset ){ remoteChanged = true; remoteDataset = tmp; }
119  if( ui->spinPort->value() != remotePort){ remoteChanged = true; remotePort = ui->spinPort->value(); updateSSHKey=true;}
120  int nFreq = -1;
121  if(ui->radioRepTime->isChecked()){
122    nFreq = ui->time_replicate->time().hour();
123  }
124  if(nFreq < 0){
125    if( remoteFreq >= 0 && remoteFreq < 24){remoteChanged = true; remoteFreq = nFreq;}
126  }else{
127    if( nFreq != remoteFreq ){ remoteChanged = true; remoteFreq = nFreq; }
128  }
129  if(updateSSHKey){
130    //Prompt for the SSH key generation
131    LPBackend::setupSSHKey(remoteHost, remoteUser, remotePort);
132  }
133}
134
135void LPConfig::setLocalKeepNumber(){
136  if(localSchedule >=0){
137    ui->combo_local_keepunits->setCurrentIndex(0); //num days
138    ui->spin_local_numkeep->setValue(localSnapshots);   
139  }else{
140    int numperday = 1440/(-localSchedule);
141    if( localSnapshots % numperday == 0 ){
142        //daily
143        ui->combo_local_keepunits->setCurrentIndex(0); //num days
144        ui->spin_local_numkeep->setValue(localSnapshots/numperday);
145    }else{
146        //odd number of snapshots - must be total
147        ui->combo_local_keepunits->setCurrentIndex(1); //num total
148        ui->spin_local_numkeep->setValue(localSnapshots);
149    }
150  }
151}
152
153// =============
154//    PRIVATE SLOTS
155// =============
156void LPConfig::slotApplyChanges(){
157  checkForChanges();
158  this->close();
159}
160
161void LPConfig::slotCancelConfig(){
162  //Make sure it is flagged as unchanged before closing
163  localChanged = false;
164  remoteChanged = false; 
165  this->close();
166}
167
168void LPConfig::on_combo_local_schedule_currentIndexChanged(int index){
169  //Adjust whether the daily time box is visible
170  ui->time_local_daily->setVisible( (index == 0) );
171}
Note: See TracBrowser for help on using the repository browser.