Commit d7de619d authored by Chris Schlaeger's avatar Chris Schlaeger
Browse files

more work done on the process list header menues; README added

svn path=/trunk/kdeutils/ktop/; revision=17010
parent 05e8c2dc
......@@ -53,7 +53,6 @@ typedef struct
bool sortable;
int alignment;
KeyFunc key;
OSProcessList::SORTKEY sortMethod;
} TABCOLUMN;
static const char* intKey(const char* text);
......@@ -75,7 +74,7 @@ static TABCOLUMN TabCol[] =
{ "", 0, true, true, false, 1, 0 },
{ "Name", 0, true, true, true, 1, 0 },
{ "PID", 0, true, true, true, 2, intKey },
{ "User ID", 0, true, false, true, 1, 0 },
{ "User", 0, true, false, true, 1, 0 },
{ "CPU", 0, true, false, true, 2, percentKey },
{ "Time", 0, true, false, true, 2, timeKey },
{ "Nice", 0, true, false, true, 2, intKey },
......@@ -171,6 +170,15 @@ ProcessList::ProcessList(QWidget *parent = 0, const char* name = 0)
}
initTabCol();
// Create popup menu for RMB clicks on table header
headerPM = new QPopupMenu();
connect(headerPM, SIGNAL(activated(int)),
this, SLOT(handleRMBPopup(int)));
headerPM->insertItem(i18n("Remove Column"), HEADER_REMOVE);
headerPM->insertItem(i18n("Add Column"), HEADER_ADD);
headerPM->insertItem(i18n("Help on Column"), HEADER_HELP);
}
ProcessList::~ProcessList()
......@@ -181,6 +189,8 @@ ProcessList::~ProcessList()
// switch off timer
if (timer_id != NONE)
killTimer(timer_id);
delete(headerPM);
}
void
......@@ -217,16 +227,14 @@ ProcessList::setSorting(int column, bool inc)
* columns may be invisible we have to map the view column to the table
* column.
*/
int tcol, vcol;
for (tcol = vcol = 0; vcol < column; tcol++)
if (TabCol[tcol].visible)
vcol++;
int tcol = mapV2T(column);
if (sortColumn == tcol)
increasing = !inc;
else
sortColumn = tcol;
QListView::setSorting(vcol, increasing);
QListView::setSorting(column, increasing);
}
void
......@@ -244,7 +252,7 @@ ProcessList::setSortColumn(int c, bool inc)
increasing = inc;
}
int
int
ProcessList::setAutoUpdateMode(bool mode)
{
/*
......@@ -285,8 +293,6 @@ ProcessList::load()
{
pl.clear();
pl.setSortCriteria(TabCol[sortColumn].sortMethod);
// request current list of processes
if (!pl.update())
{
......@@ -477,30 +483,70 @@ ProcessList::initTabCol(void)
setAllColumnsShowFocus(TRUE);
}
int
ProcessList::mapV2T(int vcol)
{
int tcol;
int i = 0;
for (tcol = 0; !TabCol[tcol].visible || (i < vcol); tcol++)
if (TabCol[tcol].visible)
i++;
return (tcol);
}
int
ProcessList::mapT2V(int tcol)
{
int vcol = 0;
for (int i = 0; i < tcol; i++)
if (TabCol[i].visible)
vcol++;
return (vcol);
}
void
ProcessList::handleRMBPopup(int item)
{
printf("Item: %d\n", item);
switch (item)
{
case HEADER_REMOVE:
/*
* The icon, name and PID columns cannot be removed, so currColumn
* must be greater than 2.
*/
if (currColumn > 2)
{
TabCol[mapV2T(currColumn)].visible = FALSE;
update();
}
break;
case HEADER_ADD:
break;
case HEADER_HELP:
break;
}
}
void
ProcessList::mousePressEvent(QMouseEvent* e)
{
/*
* I haven't found a better way to catch RMB clicks on the header than
* this hacking of the mousePressEvent function. RMB clicks are dealt
* with, all other events are passed through to the base class
* implementation.
*/
if (e->button() == RightButton)
{
if (e->pos().y() <= 0)
{
printf("Column: %d\n", header()->cellAt(e->pos().x()));
QPopupMenu* pm = new QPopupMenu();
connect(pm, SIGNAL(activated(int)),
this, SLOT(handleRMBPopup(int)));
pm->insertItem(i18n("Remove Column"));
pm->insertItem(i18n("Help on Column"));
pm->insertItem(i18n("Add Column"));
pm->popup(QCursor::pos());
// delete pm;
/*
* e->pos().y() <= 0 means header.
*/
currColumn = header()->cellAt(e->pos().x());
headerPM->popup(QCursor::pos());
}
else
{
......
......@@ -46,6 +46,8 @@ public:
virtual const char* key(int column, bool) const;
} ;
class QPopupMenu;
/**
* This class implements a widget that displays processes in a table. The
* KTabListBox is used for the handling of the table. The widget has four
......@@ -58,12 +60,14 @@ class ProcessList : public QListView
Q_OBJECT
public:
enum rateID
// items of "Refresh-Rate" combo box
enum
{
UPDATE_SLOW = 0,
UPDATE_MEDIUM,
UPDATE_FAST
};
// items of "Filter" combo box
enum
{
FILTER_ALL = 0,
......@@ -147,12 +151,6 @@ public:
signals:
void popupMenu(int, int);
public slots:
void hideColumn(int col)
{
printf("Request to hide columnd %d\n", col);
}
protected:
virtual void mousePressEvent(QMouseEvent* e);
......@@ -160,6 +158,14 @@ private slots:
void handleRMBPopup(int item);
private:
// items of table header RMB popup menu
enum
{
HEADER_REMOVE = 0,
HEADER_ADD,
HEADER_HELP
};
// timer multipliers for different refresh rates
enum
{
UPDATE_SLOW_VALUE = 20,
......@@ -190,15 +196,29 @@ private:
timer_id = startTimer(timer_interval);
}
/*
* Since some columns of our process table might be invisible the columns
* of the QListView and the data structure do not match. We have to map
* the visible columns to the table columns (V2T).
*/
int mapV2T(int vcol);
/*
* This function maps a table columns index to a visible columns index.
*/
int mapT2V(int tcol);
int filtermode;
int sortColumn;
bool increasing;
int update_rate;
int currColumn;
int timer_interval;
int timer_id;
OSProcessList pl;
KtopIconList* icons;
QPopupMenu* headerPM;
};
#endif
This CVS version of KTop is work in progress! Although I only try to
check in reasonably stable versions, I cannot guarantee this. I
typically develop on SuSE Linux 6.0 with 2.2 kernel. If your system is
different, this program might not even compile.
If you want to join this development please contact me first. Please
do *NOT* check in unsolicited code as I might am rearranging the code
and merging becomes a real headache so your code will be lost.
This does not mean that I don't appreciate your help. Especially
porting to other platforms is difficult for me. I have introduced a
nice interface so porting is fairly easy. See OSStatus.cpp if you are
interested. I really like to have a Solaris 2.x and HPUX 7 port!
16-Feb-1999 Chris Schlaeger <cs@axys.de>
Begin3
Title: KTop - The KDE Task Manager
Version: 0.9.9
Entered-date: Feb 08 99
Version: 1.0.0
Entered-date: Mar xx 1999
Entered-by: cs@axys.de (Chris Schlaeger)
Description: The KDE Task Manager
Keywords: KDE, Qt, gui, X11, top, ps, pstree, load, cpu, process
......@@ -11,7 +11,8 @@ Author3: ralf@bj-ig.de (Ralf Mueller)
Author4: nicknet@planete.net (Nicolas Leclercq)
Author5: cs@axys.de (Chris Schlaeger)
Maintained-by: cs@axys.de (Chris Schlaeger)
Primary-site: ftp://ftp.kde.org
Primary-site: ftp://ftp.kde.org/pub/kde/stable/apps/utils
Original-site: http://www.ert.rwth-aachen.de/~schlaege/ktop
Platform: Linux 2.x or FreeBSD, needs Qt 1.4x and the KDE 1.x libs
Copying-policy: GPL
End
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment