00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "memorystatus.h"
00021 #include "memory.h"
00022 #include "swapfile.h"
00023
00024 #include <qpainter.h>
00025 #include <qpushbutton.h>
00026 #include <qdrawutil.h>
00027 #include <qlabel.h>
00028
00029 #include <qlayout.h>
00030
00031 using namespace Opie::Ui;
00032 MemoryStatus::MemoryStatus(QWidget *parent, WFlags f )
00033 : QFrame(parent, 0, f), mi(0), sf(0)
00034 {
00035 setCaption( tr("Memory Status") );
00036
00037
00038 QVBoxLayout *lay = new QVBoxLayout( this );
00039 tab = new OTabWidget( this, "tabwidget", OTabWidget::Global );
00040 lay->addWidget( tab );
00041 tab->addTab( mi = new MemoryInfo( tab ), "memory/memorytabicon", tr("Memory") );
00042 tab->addTab( sf = new Swapfile( tab ), "memory/storagetabicon", tr("Swapfile") );
00043
00044 QLabel* about = new QLabel(tr("<center><b>Memory Monitor Plugin</b><br>"
00045 "Copyright (C) 2003 Anton Maslovsky<br>"
00046 "<<a href=\"mailto:my-zaurus@narod.ru\">my-zaurus@narod.ru</a>><br>"
00047 "<a href=\"http://my-zaurus.narod.ru\">http://my-zaurus.narod.ru</a><br>"
00048 "Based on source code from:<br> qswap (udoseidel@gmx.de) <br> Battery Applet (trolltech.com) <br> SysInfo (OPIE)<br><br>"
00049 "This program is licensed under GNU GPL.</center>"), tab);
00050
00051 tab->addTab( about, "memory/info", tr("About") );
00052
00053 tab->setCurrentTab( tr( "Memory" ) );
00054 }
00055
00056 int MemoryStatus::percent()
00057 {
00058 if (mi == 0)
00059 return 100;
00060
00061 int total = mi->total;
00062 if (mi->swaptotal > 0)
00063 total += mi->swaptotal;
00064
00065 int used = mi->realUsed;
00066 if (mi->swapused > 0)
00067 total += mi->swapused;
00068
00069 return ((total - used) * 100)/total;
00070 }
00071
00072 QSize MemoryStatus::sizeHint() const
00073 {
00074 QSize s = tab->size();
00075 s.setWidth(200);
00076 s.setHeight((mi->swaptotal > 0) ? 220 : 200);
00077 return s;
00078 }
00079
00080 MemoryStatus::~MemoryStatus()
00081 {
00082 }