void EventWatcher::ReadLPRepFile(){ static QString stat = ""; static QString repTotK = ""; static QString lastSize = ""; //Open/Read any new info in the file QFile LPlogfile(LPLOG); if( !LPlogfile.open(QIODevice::ReadOnly) ){ return; } //could not open file QTextStream STREAM(&LPlogfile); if(LPrep_pos<=0 || !STREAM.seek(LPrep_pos) ){ //New file location stat.clear(); repTotK.clear(); lastSize.clear(); } QStringList info = STREAM.readAll().split("\n"); LPrep_pos = STREAM.pos(); LPlogfile.close(); //Now parse the new info line-by-line for(int i=0; i<info.length(); i++){ QString line = info[i]; if(line.contains("estimated size is")){ repTotK = line.section("size is ",1,1,QString::SectionSkipEmpty).simplified(); } //save the total size to replicate else if(line.startsWith("send from ")){} else if(line.startsWith("TIME ")){} else if(line.startsWith("warning: ")){} //start of an error else{ stat = line; } //only save the relevant/latest status line } if(!stat.isEmpty()){ //qDebug() << "New Status Message:" << stat; //Divide up the status message into sections stat.replace("\t"," "); QString dataset = stat.section(" ",2,2,QString::SectionSkipEmpty).section("/",0,0).simplified(); QString cSize = stat.section(" ",1,1,QString::SectionSkipEmpty); //Now Setup the tooltip if(cSize != lastSize){ //don't update the info if the same size info QString percent; if(!repTotK.isEmpty() && repTotK!="??"){ //calculate the percentage double tot = displayToDoubleK(repTotK); double c = displayToDoubleK(cSize); if( tot!=-1 & c!=-1){ double p = (c*100)/tot; p = int(p*10)/10.0; //round to 1 decimel places percent = QString::number(p) + "%"; } } if(repTotK.isEmpty()){ repTotK = "??"; } //Format the info string QString status = cSize+"/"+repTotK; if(!percent.isEmpty()){ status.append(" ("+percent+")"); } QString txt = QString(tr("Replicating %1: %2")).arg(dataset, status); lastSize = cSize; //save the current size for later //Now set the current process status HASH.insert(120,"RUNNING"); HASH.insert(121,dataset); HASH.insert(122,txt); HASH.insert(123,txt); emit sendLPEvent("replication", 0, txt); } } }
void LPWatcher::readReplicationFile(){ QString stat; while( !RFSTREAM->atEnd() ){ QString line = RFSTREAM->readLine(); if(line.contains("total estimated size")){ repTotK = line.section(" ",-1).simplified(); } //save the total size to replicate else if(line.startsWith("send from ")){} else if(line.startsWith("TIME ")){} else if(line.startsWith("warning: ")){} //start of an error else{ stat = line; } //only save the relevant/latest status line } if(!stat.isEmpty()){ //qDebug() << "New Status Message:" << stat; //Divide up the status message into sections stat.replace("\t"," "); QString dataset = stat.section(" ",2,2,QString::SectionSkipEmpty).section("/",0,0).simplified(); QString cSize = stat.section(" ",1,1,QString::SectionSkipEmpty); //Now Setup the tooltip if(cSize != lastSize){ //don't update the info if the same size info QString percent; if(!repTotK.isEmpty()){ //calculate the percentage double tot = displayToDoubleK(repTotK); double c = displayToDoubleK(cSize); if( tot!=-1 & c!=-1){ double p = (c*100)/tot; p = int(p*10)/10.0; //round to 1 decimel places percent = QString::number(p) + "%"; } } if(repTotK.isEmpty()){ repTotK = "??"; } //Format the info string QString status = cSize+"/"+repTotK; if(!percent.isEmpty()){ status.append(" ("+percent+")"); } QString txt = QString(tr("Replicating %1: %2")).arg(dataset, status); lastSize = cSize; //save the current size for later //Now set the current process status LOGS.insert(20,"RUNNING"); LOGS.insert(21,dataset); LOGS.insert(22,txt); LOGS.insert(23,txt); emit MessageAvailable(""); } } }