src/stats/stats.cpp

Go to the documentation of this file.
00001 
00008 #include "stats.h"
00009 #include "../mainwindowimpl.h"
00010 #include "../thread/sshexecutethread.h"
00011 #include <QDebug>
00012 #include <QStandardItemModel>
00013 #include <QMovie>
00014 
00015 Stats::Stats(QWidget *parent)
00016     : QWidget(parent)
00017 {
00018     setupUi(this);
00019     connect(actionRefresh, SIGNAL(triggered()), this, SLOT(refresh()));
00020 
00021     // Set the model of the treeView and configure it
00022     model =  new QStandardItemModel(0, 6, parent);
00023 
00024     model->setHeaderData(0, Qt::Horizontal, QObject::tr("JOBNAME"));
00025     model->setHeaderData(1, Qt::Horizontal, QObject::tr("USERNAME"));
00026     model->setHeaderData(2, Qt::Horizontal, QObject::tr("STATE"));
00027     model->setHeaderData(3, Qt::Horizontal, QObject::tr("PROC"));
00028     model->setHeaderData(4, Qt::Horizontal, QObject::tr("REMAINING"));
00029     model->setHeaderData(5, Qt::Horizontal, QObject::tr("STARTTIME"));
00030 
00031     treeView->setModel(model);
00032     treeView->setRootIsDecorated(false);
00033     treeView->setAlternatingRowColors(true);
00034     treeView->setSortingEnabled(true);
00035     treeView->setUniformRowHeights(true);
00036 
00037     // Set the delegate of the treeView and configure it
00038     delegate = new StatsDelegate(this->treeView);
00039     treeView->setItemDelegate(delegate);
00040 
00041     treeView->setContextMenuPolicy(Qt::CustomContextMenu);
00042     QObject::connect(treeView, SIGNAL(customContextMenuRequested( const QPoint &)),
00043                      delegate, SLOT(onCustomContextMenuRequested( const QPoint &)));
00044 
00045 }
00046 
00047 
00048 void Stats::addJobEntry(const QString &jobname,
00049               const QString &username, const QString &state,
00050               const QString &proc, const QString &remaining, const QString &starttime)
00051 {
00052     model->insertRow(0);
00053     model->setData(model->index(0, 0), jobname);
00054     model->setData(model->index(0, 1), username);
00055     model->setData(model->index(0, 2), state);
00056     model->setData(model->index(0, 3), proc);
00057     model->setData(model->index(0, 4), remaining);
00058     model->setData(model->index(0, 5), starttime);
00059 }
00060 
00061 
00062 
00063 void Stats::clearJobListing ()
00064 {
00065     model->removeRows(0, model->rowCount());
00066 }
00067 
00068 void Stats::refresh()
00069 {
00070     Myssh & ssh = dynamic_cast<MainWindowImpl*>(window())->_ssh;
00071 
00072 
00073     if (ssh.isConnected())
00074     {
00075         QMovie * movie = new QMovie(":/imgs/anim.gif");
00076         lAnim->setMovie(movie);
00077         movie->start();
00078 
00079         SSHExecuteThread * thread = new SSHExecuteThread(&ssh, QString("showq"));
00080         QObject::connect (thread, SIGNAL(cmdSent(QStringList)), this, SLOT(onJobsReceived(QStringList)));
00081         thread->start();
00082     }
00083 }
00084 
00085 void Stats::onJobsReceived(QStringList outerr)
00086 {
00087     QString showq;
00088     QStringList l, l2;
00089     QStringList::const_iterator constIterator;
00090 
00091     showq = outerr[0];
00092 
00093     this->clearJobListing();
00094 
00095     l = showq.split('\n');
00096     for (constIterator = l.constBegin(); constIterator != l.constEnd(); ++constIterator)
00097     {
00098         QString id,
00099                 username,
00100                 state,
00101                 nbproc,
00102                 remaining,
00103                 starttime;
00104 
00105         l2 = (*constIterator).split(QRegExp("\\s+"));
00106         if (l2.count() == 9
00107             && l2[1] != "Active" && l2[1] != "of" && l2[1] != "Idle")
00108         {
00109             id = l2[0];
00110             username = l2[1];
00111             state = l2[2];
00112             nbproc = l2[3];
00113             remaining = l2[4];
00114             starttime = l2[5]+" "+l2[6]+" "+l2[7]+" "+l2[8];
00115             addJobEntry(id, username, state, nbproc, remaining, starttime);
00116         }
00117     }
00118 
00119     lAnim->clear();
00120 }
00121 

Generated on Mon Mar 16 18:46:05 2009 for QCJM by  doxygen 1.5.4