Permalink
Browse files

Clean up the tooltip for the life preserver tray: will now list the l…

…atest snapshot for each managed dataset/zpool.

Also clean up the ordering of the available snapshots - they should always list in the proper chronological order for snapshots that life-preserver created, with an additional section at the end for any other snapshots that are available for that data subset.
  • Loading branch information...
1 parent da39501 commit 539d8eb1d642b883547ed222d68cb85c0dd31ba8 Ken Moore committed Aug 26, 2013
Showing with 55 additions and 15 deletions.
  1. +31 −7 src-qt4/life-preserver/LPTray.cpp
  2. +3 −1 src-qt4/life-preserver/LPTray.h
  3. +21 −7 src-qt4/life-preserver/mainUI.cpp
@@ -2,6 +2,7 @@
//PUBLIC
LPTray::LPTray() : QSystemTrayIcon(){
+ initPhase = true; //flag that we are in the startup process
//Start up the log file watcher
QString logfile = "/var/log/lpreserver/lpreserver.log";
watcher = new QFileSystemWatcher();
@@ -46,7 +47,7 @@ LPTray::~LPTray(){
// ===============
// PRIVATE FUNCTIONS
// ===============
-void LPTray::parseLogMessage(QString log){
+void LPTray::parseLogMessage(QString log, bool quiet){
//Divide up the log into it's sections
QString timestamp = log.section(":",0,2).simplified();
QString time = timestamp.section(" ",3,3).simplified();
@@ -56,10 +57,10 @@ void LPTray::parseLogMessage(QString log){
qDebug() << "New Log Message:" << log;
if(message.contains("creating snapshot")){
dev = message.section(" ",-1).simplified();
- this->showMessage( time, QString(tr("Creating snapshot for %1")).arg(dev), QSystemTrayIcon::Information, 5000);
+ if(!quiet){ this->showMessage( time, QString(tr("Creating snapshot for %1")).arg(dev), QSystemTrayIcon::Information, 5000); }
//Just set the standard idle icon
this->setIcon( QIcon(":/images/tray-icon-idle.png") );
-// }else if(message.contains("pruning snapshot")){
+ setIdleToolTip();
}else if(message.contains("starting replication")){
startWorkingIcon();
//Setup the file watcher for this new log file
@@ -81,9 +82,9 @@ void LPTray::parseLogMessage(QString log){
}
//Clean up and show messages
repTotK.clear();
- this->setToolTip("");
+ setIdleToolTip();
dev = message.section(" ",-1).simplified();
- this->showMessage( time, QString(tr("Finished replication for %1")).arg(dev), QSystemTrayIcon::Information, 5000);
+ if(!quiet){ this->showMessage( time, QString(tr("Finished replication for %1")).arg(dev), QSystemTrayIcon::Information, 5000); }
}else if( message.contains("FAILED replication") ){
stopWorkingIcon();
//Stop the file wather from watching the status file and clean up
@@ -98,7 +99,7 @@ void LPTray::parseLogMessage(QString log){
QString file = log.section("LOGFILE:",1,1).simplified();
QString tt = QString(tr("%1: Replication Failed on %2")).arg(time,dev) +"\n"+ QString(tr("Logfile available at: %1")).arg(file);
this->setToolTip(tt);
- this->showMessage( time, QString(tr("Replication Error for %1")).arg(dev), QSystemTrayIcon::Information, 5000);
+ if(!quiet){ this->showMessage( time, QString(tr("Replication Error for %1")).arg(dev), QSystemTrayIcon::Information, 5000); }
this->setIcon(QIcon(":/images/tray-icon-failed.png"));
}else{
//Just set the standard idle icon
@@ -138,6 +139,28 @@ void LPTray::parseStatusMessage(QString stat){
}
}
+void LPTray::setIdleToolTip(){
+ //Get the last snapshot created
+ QStringList dsList = LPBackend::listDatasets();
+ if(dsList.isEmpty()){
+ this->setToolTip(tr("Automatic Backups Disabled"));
+ }else{
+ //Grab the newest snapshot from each dataset
+ QString tt; //tooltip
+ for(int i=0; i<dsList.length(); i++){
+ QStringList snaps = LPBackend::listLPSnapshots(dsList[0]);
+ if(!tt.isEmpty()){ tt.append("\n"); } //put each dataset on a new line
+ if(snaps.isEmpty()){
+ tt.append( QString(tr("%1: No snapshots available")).arg(dsList[0]) );
+ }else{
+ tt.append( QString(tr("%1: %2 available")).arg(dsList[0],snaps[0]) );
+ }
+ }
+ this->setToolTip(tt);
+ }
+
+}
+
void LPTray::startWorkingIcon(){
this->setIcon( QIcon(":/images/tray-icon-active7.png"));
//wNum = 1; //start on the first image
@@ -170,6 +193,7 @@ double LPTray::displayToDoubleK(QString displayNumber){
// ===============
void LPTray::firstCheck(){
slotNewLogMessage("/var/log/lpreserver/lpreserver.log");
+ initPhase = false; //done with initializations
}
void LPTray::slotNewLogMessage(QString file){
@@ -180,7 +204,7 @@ void LPTray::slotNewLogMessage(QString file){
QString log;
while( !LFStream->atEnd() ){ log = LFStream->readLine(); }
//Now parse the log line and do stuff with it
- parseLogMessage(log);
+ parseLogMessage(log,initPhase);
}else{
//Replication status update
//get the last line from the file
@@ -28,9 +28,11 @@ class LPTray : public QSystemTrayIcon{
QTextStream *LFStream, *SFStream;
QString repTotK, lastSize;
int wNum; //internal tracking of which frame of the icon animation we are on
+ bool initPhase;
- void parseLogMessage(QString);
+ void parseLogMessage(QString, bool quiet = false);
void parseStatusMessage(QString);
+ void setIdleToolTip();
void startWorkingIcon();
void stopWorkingIcon();
double displayToDoubleK(QString);
@@ -50,6 +50,7 @@ LPDataset mainUI::newDataset(QString ds){
LPDataset DSC;
//List all the mountpoints in this dataset
QStringList subsets = LPBackend::listDatasetSubsets(ds);
+ QStringList lpsnaps = LPBackend::listLPSnapshots(ds);
//populate the list of snapshots available for each mountpoint
for(int i=0; i<subsets.length(); i++){
//qDebug() << "Subset:" << subsets[i];
@@ -60,7 +61,18 @@ LPDataset mainUI::newDataset(QString ds){
subsets.removeAt(i);
i--;
}else{
- DSC.subsetHash.insert(subsets[i],snaps); //add it to the internal container hash
+ QStringList subsnaps;
+ //only list the valid snapshots that life preserver created
+ for(int s=0; s<lpsnaps.length(); s++){
+ int index = snaps.indexOf(lpsnaps[s]);
+ if(index > -1){ subsnaps << lpsnaps[s]; snaps.removeAt(index); }
+ }
+ //Now list all the other available snapshots (no certain ordering)
+ if(!snaps.isEmpty()){
+ subsnaps << "--"; //so we know that this is a divider between the sections
+ subsnaps << snaps;
+ }
+ DSC.subsetHash.insert(subsets[i],subsnaps); //add it to the internal container hash
}
}
//Get the time for the latest life-preserver snapshot (and total number)
@@ -75,14 +87,13 @@ LPDataset mainUI::newDataset(QString ds){
DSC.numberOfSnapshots = "0";
DSC.latestSnapshot= "";
}else{
- QStringList fSnap = DSC.subsetHash[subsets[0]].filter("auto-"); //filtered snapshot list (just life preserver snapshots)
- DSC.numberOfSnapshots = QString::number(fSnap.length());
- if(fSnap.isEmpty()){ DSC.latestSnapshot=""; }
+ DSC.numberOfSnapshots = QString::number(lpsnaps.length());
+ if(lpsnaps.isEmpty()){ DSC.latestSnapshot=""; }
else if(ci > -1 && ci < CLIST.length()){
QString sna = CLIST[ci].section(":::",1,1);
if(sna != "-"){ DSC.latestSnapshot= sna; }
else{ DSC.latestSnapshot = ""; }
- }else{ DSC.latestSnapshot=fSnap[0]; }
+ }else{ DSC.latestSnapshot=lpsnaps[0]; }
}
//List the replication status
if(RLIST.contains(ds) && (ci > -1)){
@@ -185,9 +196,12 @@ void mainUI::updateMenus(){
if(snaps.isEmpty()){ continue; }
QMenu *menu = new QMenu(subsets[i],this);
for(int s =0; s<snaps.length(); s++){
- QAction *act = new QAction(snaps[s],this);
+ if(snaps[s] == "--"){ menu->addSeparator(); }
+ else{
+ QAction *act = new QAction(snaps[s],this);
act->setWhatsThis(ds+":::"+subsets[i]+":::"+snaps[s]);
- menu->addAction(act);
+ menu->addAction(act);
+ }
}
revMenu->addMenu(menu);
brMenu->addMenu(menu);

0 comments on commit 539d8eb

Please sign in to comment.