bugagent.cpp
author insilmaril
Tue, 09 Mar 2010 08:28:49 +0000
changeset 830 b5537d245165
parent 825 1ad892c1a709
permissions -rw-r--r--
Minor bugfix: editSortBack is no toggle action
     1 #include "bugagent.h"
     2 
     3 #include "branchitem.h"
     4 #include "mainwindow.h"
     5 #include "vymmodel.h"
     6 
     7 extern Main *mainWindow;
     8 
     9 BugAgent::BugAgent (BranchItem *bi,const QString &bug)
    10 {
    11 	if (!bi) 
    12 	{
    13 		qWarning ("Const BugAgent: bi==NULL");
    14 		return;
    15 	}
    16 	branchID=bi->getID();
    17 	modelID=bi->getModel()->getID();
    18 	bugID=bug;
    19 
    20 	script="test/vym-bug.pl";
    21 
    22 	p=new Process;
    23 
    24 	connect (p, SIGNAL (finished(int,QProcess::ExitStatus) ), 
    25 		this, SLOT (processFinished(int,QProcess::ExitStatus) ));
    26 
    27 	p->start (script,QStringList()<<bugID);
    28 	if (!p->waitForStarted())
    29 	{
    30 		qWarning()<<"BugAgent::getBugzillaData couldn't start "<<script;
    31 		return;
    32 	}	
    33 }
    34 
    35 BugAgent::~BugAgent ()
    36 {
    37 	delete p;
    38 }
    39 
    40 void BugAgent::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
    41 {
    42 	if (exitStatus==QProcess::NormalExit)
    43 	{
    44 		VymModel *model=mainWindow->getModel (modelID);
    45 		if (model)
    46 		{
    47 			BranchItem *bi=(BranchItem*)(model->findID (branchID));		
    48 			if (bi)
    49 			{
    50 				QString oldsel=model->getSelectString ();
    51 				model->select (bi);
    52 
    53 				// Now do needed changes:
    54 
    55 				QString result=p->getStdout();
    56 				while (result.endsWith("\n")) result.chop(1); 
    57 				//qWarning() << QString(result);
    58 				QString err=p->getErrout();
    59 				if (!err.isEmpty())
    60 				{
    61 					qWarning() << "VM::BugAgent Error:\n";
    62 					qWarning() <<err;
    63 				}
    64 				else if (!result.isEmpty())
    65 				{
    66 					QString heading,cdate,mdate,state,whiteboard;
    67 					QRegExp re("short_desc:(.*)\n");
    68 					re.setMinimal(true);
    69 					if (re.indexIn (result) !=-1) heading=re.cap(1);
    70 
    71 					re.setPattern ("creation_ts:(.*)\n");
    72 					if (re.indexIn (result) !=-1) cdate=re.cap(1);
    73 
    74 					re.setPattern ("delta_ts:(.*)\n");
    75 					if (re.indexIn (result) !=-1) mdate=re.cap(1);
    76 
    77 					re.setPattern ("bug_status:(.*)\n");
    78 					if (re.indexIn (result) !=-1) state=re.cap(1);
    79 
    80 					re.setPattern ("status_whiteboard:(.*)\n");
    81 					if (re.indexIn (result) !=-1) whiteboard=re.cap(1);
    82 
    83 					model->setHeading (bugID + " - " + heading);
    84 					qDebug() << "VM: heading="<<heading;
    85 					qDebug() << "VM:   cdate="<<cdate;
    86 					qDebug() << "VM:   mdate="<<mdate;
    87 					qDebug() << "VM:   state="<<state;
    88 					qDebug() << "VM:  wboard="<<whiteboard;
    89 					
    90 					//qDebug() <<"VM::getBugzillaData  "<<script<<" returned:\n";
    91 					//qDebug() <<QString(result);
    92 				} else	
    93 					qWarning() << "VM::getBugzillaData "<<script<<"  returned nothing\n";
    94 
    95 
    96 
    97 				// Changes finished
    98 				model->select (oldsel);
    99 			} else
   100 				qWarning ()<<"BugAgent: Found model, but not branch #"<<branchID;
   101 		} else
   102 			qWarning ()<<"BugAgent: Couldn't find model #"<<modelID;
   103 	} else		
   104 		qWarning()<< "BugAgent: Process finished with exitCode="<<exitCode;
   105 	delete (this);
   106 }
   107 
   108 
   109