Ksetiwatch API Documentation


userinfo.cpp

Go to the documentation of this file.
00001 /***************************************************************************/
00014 #include <stdio.h>
00015 #include <kapp.h>
00016 #include <klocale.h>
00017 #include <kdebug.h>
00018 
00019 #include <qheader.h>
00020 #include <qpainter.h>
00021 
00022 #include "ksetiwatch.h"
00023 #include "userinfo.h"
00024 #include "setiloc.h"
00025 
00026 /*------------------------------------------------------------------------ */
00027 QString UserInfoListViewItem::key(int column, bool) const
00028 {
00029 // return value must be static
00030 static QString ret;
00031 QString val;
00032 double tmp;
00033 
00034 if(column == 2)
00035   {
00036   val = text(column);
00037   tmp = val.toDouble();
00038   val.sprintf("%f", tmp);
00039   ret = val.rightJustify(32, '0');
00040   }
00041 else if(column == 3 || column == 4)
00042   {
00043   int colon;
00044   int d(0), h(0), m(0), s(0);
00045 
00046   val = text(column);
00047   colon = val.contains(':');
00048   if(colon == 2)
00049     sscanf(text(column), "%d:%d:%d", &h, &m, &s);
00050   else if(colon == 3)
00051     sscanf(text(column), "%dd:%d:%d:%d", &d, &h, &m, &s);
00052   tmp = 86400*d + 3600*h + 60*m + s;
00053   ret.sprintf("%032d", (int)tmp);
00054   }
00055 else
00056   ret = text(column);
00057 
00058 return(ret);
00059 }
00060 
00061 
00062 /*------------------------------------------------------------------------ */
00063 UserInfo::UserInfo(QWidget* parent, const char* name) : QWidget(parent,name)
00064 {
00065 Ksetiwatch::TableColumn uitc[] =
00066   {
00067   {i18n("Location"), -1, AlignLeft},
00068   {i18n("Name"), -1, AlignLeft},
00069   {i18n("WU Completed"), -1, AlignRight},
00070   {i18n("Total CPU Time"), -1, AlignRight},
00071   {i18n("Average CPU Time"), -1, AlignRight},
00072   {i18n("Last Result"), 150, AlignRight},
00073   {i18n("Register Time"), 150, AlignRight}
00074   };
00075 
00076 QListView_1= new popListView(this);
00077 QListView_1->setShowSortIndicator(false);
00078 QListView_1->setPopupStyle(popListView::ShowAnywhere);
00079 QListView_1->move(5,1);
00080 
00081 for(int i=0; i<(int)(sizeof(uitc)/sizeof(uitc[0])); i++)
00082   {
00083   QListView_1->addColumn(uitc[i].text,-1);
00084   if(uitc[i].width != -1) QListView_1->setColumnWidth(i, uitc[i].width);    
00085   QListView_1->setColumnAlignment(i, uitc[i].alignment);
00086   }
00087 
00088 connect(QListView_1->header(), SIGNAL(sectionClicked(int)),
00089                          this, SLOT(toggleSorting(int)));
00090 sortingorder = true;
00091 
00092 lvDict.setAutoDelete(true);
00093 
00094 refreshList();
00095 }
00096 
00097 /*------------------------------------------------------------------------ */
00098 UserInfo::~UserInfo()
00099 {
00100 }
00101 
00102 /*------------------------------------------------------------------------ */
00103 void UserInfo::resizeEvent(QResizeEvent*)
00104 {
00105 QListView_1->resize(this->width()-10, this->height()-5);
00106 }
00107 
00108 /*------------------------------------------------------------------------ */
00109 void UserInfo::paintEvent(QPaintEvent* e)
00110 {
00111 QListView_1->setGridEnabled(globalopts->DrawGrid);
00112 QWidget::paintEvent(e);
00113 }
00114 
00115 /*------------------------------------------------------------------------ */
00116 void UserInfo::refreshList()
00117 {
00118 SetiLoc *loc;
00119 
00120 for(loc=Ksetiwatch::locationList().first(); loc != 0;
00121     loc=Ksetiwatch::locationList().next())
00122   {
00123   UserInfoListViewItem* it = lvDict[loc->id()];
00124   if(it == 0)
00125     slotUpdateList(loc, Ksetiwatch::ListAdd);
00126   else
00127     refreshListItem(loc, it);
00128   }
00129 }
00130 
00131 /*------------------------------------------------------------------------ */
00132 void UserInfo::refreshListItem(SetiLoc* loc, UserInfoListViewItem* it)
00133 {
00134 if(loc && it == 0)
00135     it = lvDict[loc->id()];
00136 if(loc && it)
00137   {
00138   it->setText(ColLocation, loc->description());
00139   if(loc->exists(SetiLoc::SC_UserInfoFile))
00140     {
00141     it->setText(ColName,       loc->userName());
00142     it->setText(ColWuCompl,    QString::number(loc->numberOfResults()));
00143     it->setText(ColTotalTime,  SetiLoc::convertTime(loc->totalCPUTime(), globalopts->hms));
00144     it->setText(ColAvrgTime,   SetiLoc::convertTime(loc->averageCPUTime(), globalopts->hms));
00145     it->setText(ColLastResult, "  " + loc->lastResultTimeString());
00146     it->setText(ColRegTime,    "  " + loc->registerTimeString());
00147     }
00148   else
00149     {
00150     it->setText(ColName,       QString::null);
00151     it->setText(ColWuCompl,    QString::null);
00152     it->setText(ColTotalTime,  QString::null);
00153     it->setText(ColAvrgTime,   QString::null);
00154     it->setText(ColLastResult, QString::null);
00155     it->setText(ColRegTime,    QString::null);
00156     }
00157   }
00158 }
00159 
00160 /*------------------------------------------------------------------------ */
00161 void UserInfo::slotUpdateList(SetiLoc* loc, int type)
00162 {
00163 UserInfoListViewItem* it;
00164 
00165 switch(type)
00166   {
00167   case Ksetiwatch::ListAdd:
00168     {
00169     it = new UserInfoListViewItem(QListView_1);
00170     if(it)
00171       {
00172       lvDict.insert(loc->id(), it);
00173       connect(loc,  SIGNAL(updatedUserInfoData()),
00174               this, SLOT(slotUpdateUserInfoData()));
00175       refreshListItem(loc, it);
00176       }
00177     break;
00178     }
00179   case Ksetiwatch::ListEdit:
00180     {
00181     refreshListItem(loc);
00182     break;
00183     }
00184   case Ksetiwatch::ListDelete:
00185     {
00186     disconnect(loc,  SIGNAL(updatedUserInfoData()),
00187                this, SLOT(slotUpdateUserInfoData()));
00188     lvDict.remove(loc->id());
00189     break;
00190     }
00191   }
00192 }
00193 
00194 /*------------------------------------------------------------------------ */
00195 void UserInfo::toggleSorting(int column)
00196 {
00197 sortingorder = !sortingorder;
00198 QListView_1->setSorting(column, sortingorder);
00199 }
00200 
00201 /*------------------------------------------------------------------------ */
00202 void UserInfo::slotUpdateUserInfoData()
00203 {
00204 SetiLoc* loc = (SetiLoc*)(sender());
00205 
00206 if(loc)
00207   refreshListItem(loc);
00208 }
00209 
00210 #include "userinfo.moc"
KDE Logo
This file is part of the documentation for Ksetiwatch API Version 2.6.1.
Documentation copyright © 2000-2003 Gordon Machel.
Generated on Fri Jun 6 00:28:16 2003 by doxygen 1.2.18, written by Dimitri van Heesch, © 1997-2002