src/stats/statsdelegate.cpp

Go to the documentation of this file.
00001 
00008 #include "statsdelegate.h"
00009 #include "../mainwindowimpl.h"
00010 #include "../thread/sshexecutethread.h"
00011 #include <QTreeView>
00012 #include <QMenu>
00013 #include <QAbstractItemView>
00014 
00015 #include <QDebug>
00016 
00022 StatsDelegate::StatsDelegate(QObject *parent)
00023         : QItemDelegate(parent)
00024 {
00025 }
00026 
00033 void StatsDelegate::onCustomContextMenuRequested(const QPoint & pos)
00034 {
00035     QWidget * parent = dynamic_cast<QWidget*>(this->parent());
00036     QModelIndex idx = dynamic_cast<QAbstractItemView *>(parent)->indexAt(pos);
00037     Myssh & ssh = dynamic_cast<MainWindowImpl*>(parent->window())->_ssh;
00038     if (idx.isValid())
00039     {
00040         QString cmd;
00041         QModelIndex idx2JobName = idx.model()->index(idx.row(), 0);
00042         QModelIndex idx2UserName = idx.model()->index(idx.row(), 1);
00043         QModelIndex idx2State = idx.model()->index(idx.row(), 2);
00044         QString JobName = idx2JobName.data().toString();
00045         QString UserName = idx2UserName.data().toString();
00046         QString State = idx2State.data().toString();
00047 
00048         QMenu menu(parent);
00049         QAction *killAction;
00050         QAction *suspendAction;
00051         QAction *resumeAction;
00052 
00053         killAction = menu.addAction(tr("&Stop this Job"));
00054         killAction->setEnabled(true);
00055         resumeAction = menu.addAction(tr("&Resume this Job"));
00056         resumeAction->setEnabled(true);
00057         suspendAction = menu.addAction(tr("&Pause this Job"));
00058         suspendAction->setEnabled(true);
00059 
00060         const QAction *result = menu.exec(parent->mapToGlobal(pos));
00061         if (result == killAction)
00062             cmd = QString("qsig -s KILL "+JobName);
00063         else if (result == suspendAction)
00064             cmd = QString("qsig -s SUSPEND "+JobName);
00065         else if (result == resumeAction)
00066             cmd = QString("qsig -s RESUME "+JobName);
00067         SSHExecuteThread * thread = new SSHExecuteThread(&ssh, cmd);
00068         QObject::connect (thread, SIGNAL(cmdSent(QStringList)), this, SLOT(onCommandSent(QStringList)));
00069         thread->start();
00070     }
00071 }
00072 
00073 
00082 void StatsDelegate::onCommandSent(QStringList outerrcmd)
00083 {
00084     QWidget * parent = dynamic_cast<QWidget*>(this->parent());
00085     MainWindowImpl* win = dynamic_cast<MainWindowImpl*>(parent->window());
00086     QString msg;
00087 
00088     if (outerrcmd[1].isEmpty())
00089     {
00090         //Command sent
00091         msg = tr("Command %1 executed.").arg(outerrcmd[2]);
00092         win->logs->addLog(msg);
00093         win->stats->refresh();
00094     } else {
00095         //Error while executing the command
00096         msg = tr("Command %1 could not be executed.\n Error: %2").arg(outerrcmd[2]).arg(outerrcmd[1]);
00097         win->logs->addLog(msg);
00098     }
00099 }
00100 

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