summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-01-29 09:35:52 (UTC)
committer mickeyl <mickeyl>2005-01-29 09:35:52 (UTC)
commitd4cf8c6020c46e5dc97b75f3a9781ddc15416b3a (patch) (unidiff)
treec17be6e75e277c3fa0378f352f45766f75031cdb
parentf85af28663814f3262f5ecfcd20a4b4f67c23067 (diff)
downloadopie-d4cf8c6020c46e5dc97b75f3a9781ddc15416b3a.zip
opie-d4cf8c6020c46e5dc97b75f3a9781ddc15416b3a.tar.gz
opie-d4cf8c6020c46e5dc97b75f3a9781ddc15416b3a.tar.bz2
fix 1505 and suck sysinfo files into the tree instead of cross referencing
eventually we may find that graph and load are of universal usage, then they should appear in some kind of library
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ChangeLog1
-rw-r--r--noncore/applets/memoryapplet/graph.cpp183
-rw-r--r--noncore/applets/memoryapplet/graph.h89
-rw-r--r--noncore/applets/memoryapplet/load.cpp212
-rw-r--r--noncore/applets/memoryapplet/load.h60
-rw-r--r--noncore/applets/memoryapplet/memory.cpp165
-rw-r--r--noncore/applets/memoryapplet/memory.h63
-rw-r--r--noncore/applets/memoryapplet/memoryapplet.pro14
-rw-r--r--noncore/applets/memoryapplet/swapfile.cpp15
9 files changed, 794 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index f2cf5c5..14be30b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,138 +1,139 @@
1 2005-??-??Opie 1.1.9 1 2005-??-??Opie 1.1.9
2 2
3 New Features 3 New Features
4 ------------ 4 ------------
5 * Number of icon columns in Launcher is customizable through Launcher.conf (hrw,zecke,mickeyl) 5 * Number of icon columns in Launcher is customizable through Launcher.conf (hrw,zecke,mickeyl)
6 * Number of icon columns in Launcher is customizable through LauncherSettings (mickeyl) 6 * Number of icon columns in Launcher is customizable through LauncherSettings (mickeyl)
7 7
8 Fixed Bugs 8 Fixed Bugs
9 ---------- 9 ----------
10 * #1501 - Fixed bug in todo sql backend (eilers) 10 * #1501 - Fixed bug in todo sql backend (eilers)
11 * #1505 - Added more Swap sizes in memoryapplet (mickeyl)
11 * #1525 - Hopefully fixed double alarms and not removing alarms set with the Clock application (zecke) 12 * #1525 - Hopefully fixed double alarms and not removing alarms set with the Clock application (zecke)
12 * #1533 - Security Owner Dialog (shown in case of unsuccessfull authentiacation) wasn't able to display information in non latin1 encoding (zecke) 13 * #1533 - Security Owner Dialog (shown in case of unsuccessfull authentiacation) wasn't able to display information in non latin1 encoding (zecke)
13 * n.a. - Removed hard coded font sizes in a couple of inputmethods (mickeyl) 14 * n.a. - Removed hard coded font sizes in a couple of inputmethods (mickeyl)
14 * n.a. - Removed MediumDlg appearing prior to FirstUsage wizard (i.e. calibration) (mickeyl) 15 * n.a. - Removed MediumDlg appearing prior to FirstUsage wizard (i.e. calibration) (mickeyl)
15 16
16 Internal 17 Internal
17 -------- 18 --------
18 * Added the Qtopia 1.7 SDK macros for quick-apps to easa compilation of 3rd party apps against our headers (mickeyl) 19 * Added the Qtopia 1.7 SDK macros for quick-apps to easa compilation of 3rd party apps against our headers (mickeyl)
19 * You can now use the Opie build system in combination with a OpenEmbedded staging area which makes a nice cross development environment (mickeyl) 20 * You can now use the Opie build system in combination with a OpenEmbedded staging area which makes a nice cross development environment (mickeyl)
20 * Made Opie compilable with Qt/Embedded 2.3.10 (ar) 21 * Made Opie compilable with Qt/Embedded 2.3.10 (ar)
21 * Changed Launcher to get default orientation from ODevice w/ QWS_DISPLAY overriding (mickeyl) 22 * Changed Launcher to get default orientation from ODevice w/ QWS_DISPLAY overriding (mickeyl)
22 23
23 2004-11-26Opie 1.1.8 24 2004-11-26Opie 1.1.8
24 25
25 New Features 26 New Features
26 ------------ 27 ------------
27 * PackageManager supports installation of local ipkg files (drw) 28 * PackageManager supports installation of local ipkg files (drw)
28 * PackageManager supports linking of applications to root (drw) 29 * PackageManager supports linking of applications to root (drw)
29 * PackageManager supports src/gz feeds (drw,wimpie) 30 * PackageManager supports src/gz feeds (drw,wimpie)
30 * Added a syslog information tab to sysinfo (mickeyl) 31 * Added a syslog information tab to sysinfo (mickeyl)
31 * Added new, more consistent, PIM icons + a GIMP teplate (ar) 32 * Added new, more consistent, PIM icons + a GIMP teplate (ar)
32 33
33 Fixed Bugs 34 Fixed Bugs
34 ---------- 35 ----------
35 * #1017 - Tetrix doesn't display correctly for high resolution screens (drw) 36 * #1017 - Tetrix doesn't display correctly for high resolution screens (drw)
36 * #1269 - VCards were imported into personal area if it was activated (eilers) 37 * #1269 - VCards were imported into personal area if it was activated (eilers)
37 * #1464 - Packagemanager dont set active filter after install a package (drw) 38 * #1464 - Packagemanager dont set active filter after install a package (drw)
38 * #1479 - Improved VCard-Parser to import VCards created by Evolution 2 and Apple Addressbook (eilers) 39 * #1479 - Improved VCard-Parser to import VCards created by Evolution 2 and Apple Addressbook (eilers)
39 * #1493 - Fixed one column layout bug of the launcher (hrw) 40 * #1493 - Fixed one column layout bug of the launcher (hrw)
40 * n.a. - PackageManager - (Minor UI tweak) in filter dialog, when option is enabled, set focus to widget that corresponds to that option (drw) 41 * n.a. - PackageManager - (Minor UI tweak) in filter dialog, when option is enabled, set focus to widget that corresponds to that option (drw)
41 * n.a. - PackageManager - (Minor UI tweak) fix double entry in source feed configuration when adding a new feed (drw) 42 * n.a. - PackageManager - (Minor UI tweak) fix double entry in source feed configuration when adding a new feed (drw)
42 * n.a. - Battery Applet - fix sizing of battery info popup (drw,mickeyl) 43 * n.a. - Battery Applet - fix sizing of battery info popup (drw,mickeyl)
43 44
44 Internal 45 Internal
45 -------- 46 --------
46 * Moved libopie1 to unsupported (mickeyl) 47 * Moved libopie1 to unsupported (mickeyl)
47 * Implemented generic queryByExample() with incremental searching. A lot of internal changes of the Pim2-library (eilers) 48 * Implemented generic queryByExample() with incremental searching. A lot of internal changes of the Pim2-library (eilers)
48 * Added fast and full featured and incremental sorted() for SQL addressbook backend (eilers) 49 * Added fast and full featured and incremental sorted() for SQL addressbook backend (eilers)
49 50
50 2004-11-14Opie 1.1.7 51 2004-11-14Opie 1.1.7
51 52
52 New Features 53 New Features
53 ------------ 54 ------------
54 * libOpieDB now uses SQLite V3 instead V2. Remember to upgrade your database files! (eilers) 55 * libOpieDB now uses SQLite V3 instead V2. Remember to upgrade your database files! (eilers)
55 * Backup now uses the busy indicator when backing up and restore (ar) 56 * Backup now uses the busy indicator when backing up and restore (ar)
56 * OpiePlayer2 gained adding of Directories to the playlist (zecke) 57 * OpiePlayer2 gained adding of Directories to the playlist (zecke)
57 * OpiePlayer2 better error handling (zecke) 58 * OpiePlayer2 better error handling (zecke)
58 * OpiePlayer2 progress indication while streaming (zecke) 59 * OpiePlayer2 progress indication while streaming (zecke)
59 * OpiePlayer2 ported to use libxine 1.0.0-rc6a (brad,zecke) 60 * OpiePlayer2 ported to use libxine 1.0.0-rc6a (brad,zecke)
60 * Ported brightnessapplet from Qtopia 1.7 (mickeyl) 61 * Ported brightnessapplet from Qtopia 1.7 (mickeyl)
61 * Opie-Eye got a Digital Camera File Backend (alwin,zecke) 62 * Opie-Eye got a Digital Camera File Backend (alwin,zecke)
62 * Support for Tuxpad1 of Tradesquare.NL (mickeyl,zecke) 63 * Support for Tuxpad1 of Tradesquare.NL (mickeyl,zecke)
63 * Opie-Console use Custom Font and Size in a Profile (harlekin) 64 * Opie-Console use Custom Font and Size in a Profile (harlekin)
64 * Opie-Console transparently log the Output and Input to a file (harlekin) 65 * Opie-Console transparently log the Output and Input to a file (harlekin)
65 * Added new O-menu icon to lock the PDA immediately: opie-lockapplet (clem) 66 * Added new O-menu icon to lock the PDA immediately: opie-lockapplet (clem)
66 * Opie-Security now hides the plugin-based authentication tabs if no auth. plugin package is installed (clem) 67 * Opie-Security now hides the plugin-based authentication tabs if no auth. plugin package is installed (clem)
67 * Opie-Security gained a 'test authentication' button (clem) 68 * Opie-Security gained a 'test authentication' button (clem)
68 * Opie-Eye got a more unique layout (menubar), a slideshow, user can setup some defaults 69 * Opie-Eye got a more unique layout (menubar), a slideshow, user can setup some defaults
69 * Opie-Mail improve the handling of POP mail boxes (alwin) 70 * Opie-Mail improve the handling of POP mail boxes (alwin)
70 * Both Opie-Eye and Opie-Mail were greatly improved due the hard work of Rajko Albrecht(alwin) 71 * Both Opie-Eye and Opie-Mail were greatly improved due the hard work of Rajko Albrecht(alwin)
71 * Opie IRC - backports of the 'NeIRC fork' (zecke) 72 * Opie IRC - backports of the 'NeIRC fork' (zecke)
72 73
73 Fixed Bugs 74 Fixed Bugs
74 ---------- 75 ----------
75 * #501 - Pickboard is able to show 'Umlaute' (TT,zecke) 76 * #501 - Pickboard is able to show 'Umlaute' (TT,zecke)
76 * #608 - Make Opie usable for left handed users (zecke) 77 * #608 - Make Opie usable for left handed users (zecke)
77 * #957 - Import of VCards/VTodos/VEvents with BASE64 encoding (ljp,zecke) 78 * #957 - Import of VCards/VTodos/VEvents with BASE64 encoding (ljp,zecke)
78 * #1245 - Opie-Go 'paused' (zecke) 79 * #1245 - Opie-Go 'paused' (zecke)
79 * #1358 - DocTab didn't show any MimeTypes (was fixed earlier) (zecke) 80 * #1358 - DocTab didn't show any MimeTypes (was fixed earlier) (zecke)
80 * #1380 - QDateBookAccess::remove() doesn't remove entries (eilers, zecke) 81 * #1380 - QDateBookAccess::remove() doesn't remove entries (eilers, zecke)
81 * #1395 - Build VNC Backend with gcc3.4 82 * #1395 - Build VNC Backend with gcc3.4
82 * #1440 - The icon of opie-mobilemsg is missing (CoreDump) 83 * #1440 - The icon of opie-mobilemsg is missing (CoreDump)
83 * #1426 - Add missing opie-bartender Icon (CoreDump) 84 * #1426 - Add missing opie-bartender Icon (CoreDump)
84 * #1445 - Opie-Sheet Has No Icon (CoreDump) 85 * #1445 - Opie-Sheet Has No Icon (CoreDump)
85 * #1448 - Brightness Applet added (mickeyl) 86 * #1448 - Brightness Applet added (mickeyl)
86 * #1450 - ZSame didn't clear the bonus item after winning a game (zecke) 87 * #1450 - ZSame didn't clear the bonus item after winning a game (zecke)
87 * #1482 - Fix OFileSelector to be able to sort by size (zecke) 88 * #1482 - Fix OFileSelector to be able to sort by size (zecke)
88 * n.a. - Opie-mail: fixed some crasher, some layout-problems 89 * n.a. - Opie-mail: fixed some crasher, some layout-problems
89 * n.a. - Converted applications to not hardcode /opt/QtPalmtop but to use QPEApplication::qpeDir (zecke) 90 * n.a. - Converted applications to not hardcode /opt/QtPalmtop but to use QPEApplication::qpeDir (zecke)
90 * n.a. - Converted usage of qpeDir() not to include a '/' as first charachter of the string (zecke) 91 * n.a. - Converted usage of qpeDir() not to include a '/' as first charachter of the string (zecke)
91 * n.a. - Build system: Enable distcc and ccache when crosscompiling too, and use them everywhere we can (clem) 92 * n.a. - Build system: Enable distcc and ccache when crosscompiling too, and use them everywhere we can (clem)
92 * n.a. - Build system: Fix deps in several config.in (and fix scripts/deps.pl too) to stop breaking builds, especially with make -j highNumber (clem) 93 * n.a. - Build system: Fix deps in several config.in (and fix scripts/deps.pl too) to stop breaking builds, especially with make -j highNumber (clem)
93 * n.a. - Removed hardcoded icon size in a couple of applets (mickeyl) 94 * n.a. - Removed hardcoded icon size in a couple of applets (mickeyl)
94 95
95 Internal 96 Internal
96 -------- 97 --------
97 * Opie-Qashmoney has been moved to unsupported (mickeyl) 98 * Opie-Qashmoney has been moved to unsupported (mickeyl)
98 * Opie-Ubrowser has been moved to unsupported (mickeyl) 99 * Opie-Ubrowser has been moved to unsupported (mickeyl)
99 100
100 2004-09-17Opie 1.1.6 101 2004-09-17Opie 1.1.6
101 102
102 New Features 103 New Features
103 ------------ 104 ------------
104 * Fifteen gained configurable number of items (zecke) 105 * Fifteen gained configurable number of items (zecke)
105 * Fifteen can have custom background images (zecke) 106 * Fifteen can have custom background images (zecke)
106 * Added daemonizing capabilities to QWS Server [via Qt/Embedded] (mickeyl) 107 * Added daemonizing capabilities to QWS Server [via Qt/Embedded] (mickeyl)
107 * Integrated the new security framework into libopie2 (zecke,clem) 108 * Integrated the new security framework into libopie2 (zecke,clem)
108 * Converted the launcher to use the new security framework (zecke) 109 * Converted the launcher to use the new security framework (zecke)
109 * Backup can now handle custom locations for backup and restore (ar) 110 * Backup can now handle custom locations for backup and restore (ar)
110 * Implemented right-on-hold feedback (wimpie,zecke) 111 * Implemented right-on-hold feedback (wimpie,zecke)
111 * Lots of new features in opie-reader (tim,pohly) 112 * Lots of new features in opie-reader (tim,pohly)
112 * Build system cleanups (schurig) 113 * Build system cleanups (schurig)
113 114
114 Fixed Bugs 115 Fixed Bugs
115 -------- 116 --------
116 * #1005 - Fixed backup to CompactFlash (ar) 117 * #1005 - Fixed backup to CompactFlash (ar)
117 * #1167 - Fixed Opie write crashing on more text than one page (ar) 118 * #1167 - Fixed Opie write crashing on more text than one page (ar)
118 * #1225 - Fixed repeated light flashing on Zaurus with keyz (mickeyl) 119 * #1225 - Fixed repeated light flashing on Zaurus with keyz (mickeyl)
119 * #1359 - Fixed bookmarks in Gutenbrowser (ljp) 120 * #1359 - Fixed bookmarks in Gutenbrowser (ljp)
120 * #1361 - Fixed auto upercase in Opie-Addressbook (eilers) 121 * #1361 - Fixed auto upercase in Opie-Addressbook (eilers)
121 * #1370 - Pimconverter now reacts on cancel key (eilers) 122 * #1370 - Pimconverter now reacts on cancel key (eilers)
122 * #1376 - Bring back the capslock/numlock display (zecke) 123 * #1376 - Bring back the capslock/numlock display (zecke)
123 * #1383 - Language settings now warns about losing open apps (Markus Litz) 124 * #1383 - Language settings now warns about losing open apps (Markus Litz)
124 * #1393 - Fixed line wrap issues in opie-console for the default profile (mickeyl) 125 * #1393 - Fixed line wrap issues in opie-console for the default profile (mickeyl)
125 * #1394 - Fixed oversized headline in opie-login (coredump) 126 * #1394 - Fixed oversized headline in opie-login (coredump)
126 * #1396 - Opie-console captures the escape key and vim is working (zecke) 127 * #1396 - Opie-console captures the escape key and vim is working (zecke)
127 * #1401 - Scrollbar is now only visible if necessary in DocTab (mickeyl) 128 * #1401 - Scrollbar is now only visible if necessary in DocTab (mickeyl)
128 129
129 2004-07-06Opie 1.1.4 130 2004-07-06Opie 1.1.4
130 131
131 New Features 132 New Features
132 ------------ 133 ------------
133 * Added four themes courtesy Robert Griebl (http://www.softforge.de/zstyle) 134 * Added four themes courtesy Robert Griebl (http://www.softforge.de/zstyle)
134 * Added Conversion tool for pim-data (eilers) 135 * Added Conversion tool for pim-data (eilers)
135 * Introduced new OPimAccessFactory and OBackendFactory which simplyfies database access (eilers) 136 * Introduced new OPimAccessFactory and OBackendFactory which simplyfies database access (eilers)
136 * Modified the PIM API for providing generic use of OPimRecords (eilers) 137 * Modified the PIM API for providing generic use of OPimRecords (eilers)
137 * Clicking on the application symbol now iterates over the application's top level widgets if already raised (zecke) 138 * Clicking on the application symbol now iterates over the application's top level widgets if already raised (zecke)
138 139
diff --git a/noncore/applets/memoryapplet/graph.cpp b/noncore/applets/memoryapplet/graph.cpp
new file mode 100644
index 0000000..0b02bf7
--- a/dev/null
+++ b/noncore/applets/memoryapplet/graph.cpp
@@ -0,0 +1,183 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qpainter.h>
22#include <qpixmap.h>
23#include "graph.h"
24
25void GraphData::clear()
26{
27 names.clear();
28 values.resize(0);
29}
30
31void GraphData::addItem( const QString &name, int value )
32{
33 names.append( name );
34 values.resize( values.size() + 1 );
35 values[values.size()-1] = value;
36}
37
38Graph::Graph(QWidget *parent, const char *name, WFlags f )
39 : QFrame( parent, name, f )
40{
41}
42
43PieGraph::PieGraph(QWidget *parent, const char *name, WFlags f )
44 : Graph( parent, name, f )
45{
46}
47
48void PieGraph::drawContents( QPainter *p )
49{
50 int size = QMIN( contentsRect().width(), contentsRect().height() ) - 1;
51
52 int total = 0;
53 for ( unsigned i = 0; i < data->count(); i++ )
54 total += data->value(i);
55
56 int angle = 0;
57 for ( unsigned i = 0; i < data->count(); i++ ) {
58 int len;
59 if ( i == data->count() - 1 || !total )
60 len = 5760 - angle;
61 else
62 len = data->value(i) * 5760 / total;
63 QColor col;
64 col.setHsv( i * 360 / data->count(), 255, 255 );
65 p->setBrush( col );
66 p->drawPie ( contentsRect().x(), contentsRect().y(),
67 size, size, angle, len+32 );
68 angle += len;
69 }
70}
71
72BarGraph::BarGraph(QWidget *parent, const char *name, WFlags f )
73 : Graph( parent, name, f )
74{
75 setMinimumHeight( 10 );
76 setMaximumHeight( 45 );
77}
78
79void BarGraph::drawContents( QPainter *p )
80{
81 int h = contentsRect().height();
82 int y = contentsRect().top();
83
84 int total = 0;
85 for ( unsigned i = 0; i < data->count(); i++ )
86 total += data->value(i);
87
88 int pos = 0;
89 for ( unsigned i = 0; i < data->count(); i++ ) {
90 int len;
91 if ( i == data->count() - 1 || !total )
92 len = contentsRect().width() - pos;
93 else
94 len = data->value(i) * contentsRect().width() / total;
95 QColor col;
96 col.setHsv( i * 360 / data->count(), 255, 255 );
97 drawSegment( p, QRect(contentsRect().x() + pos, y, len, h), col );
98 pos += len;
99 }
100}
101
102void BarGraph::drawSegment( QPainter *p, const QRect &r, const QColor &c )
103{
104 if ( QPixmap::defaultDepth() > 8 ) {
105 QColor topgrad = c.light(170);
106 QColor botgrad = c.dark();
107
108 int h1, h2, s1, s2, v1, v2;
109 topgrad.hsv( &h1, &s1, &v1 );
110 botgrad.hsv( &h2, &s2, &v2 );
111 int ng = r.height();
112 for ( int j =0; j < ng; j++ ) {
113 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1),
114 s1 + ((s2-s1)*j)/(ng-1),
115 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
116 p->drawLine( r.x(), r.top()+j, r.x()+r.width(), r.top()+j );
117 }
118 } else {
119 p->fillRect( r.x(), r.top(), r.width(), r.height(), c );
120 }
121}
122
123
124GraphLegend::GraphLegend( QWidget *parent, const char *name, WFlags f )
125 : QFrame( parent, name, f )
126{
127 horz = FALSE;
128}
129
130void GraphLegend::setOrientation(Orientation o)
131{
132 horz = o == Horizontal;
133}
134
135void GraphLegend::drawContents( QPainter *p )
136{
137 int total = 0;
138 for ( unsigned i = 0; i < data->count(); i++ )
139 total += data->value(i);
140
141 int tw = width()/data->count()-1;
142 int th = height()/(horz ? 1 : data->count());
143 if ( th > p->fontMetrics().height() )
144 th = p->fontMetrics().height();
145 int x = 0;
146 int y = 0;
147 for ( unsigned i = 0; i < data->count(); i++ ) {
148 QColor col;
149 col.setHsv( i * 360 / data->count(), 255, 255 );
150 p->setBrush( col );
151 p->drawRect( x+1, y+1, th - 2, th - 2 );
152 p->drawText( x+th + 1, y + p->fontMetrics().ascent()+1, data->name(i) );
153 if ( horz ) {
154 x += tw;
155 } else {
156 y += th;
157 }
158 }
159}
160
161QSize GraphLegend::sizeHint() const
162{
163 int th = fontMetrics().height() + 2;
164 int maxw = 0;
165 for ( unsigned i = 0; i < data->count(); i++ ) {
166 int w = fontMetrics().width( data->name(i) );
167 if ( w > maxw )
168 maxw = w;
169 }
170 if ( 0 && horz ) {
171 return QSize( maxw * data->count(), th );
172 } else {
173 return QSize( maxw, th * data->count() );
174 }
175}
176
177void GraphLegend::setData( const GraphData *p )
178{
179 data = p;
180 int th = fontMetrics().height();
181 setMinimumHeight( th * ( horz ? 1 : data->count() ) );
182 updateGeometry();
183}
diff --git a/noncore/applets/memoryapplet/graph.h b/noncore/applets/memoryapplet/graph.h
new file mode 100644
index 0000000..5a65e79
--- a/dev/null
+++ b/noncore/applets/memoryapplet/graph.h
@@ -0,0 +1,89 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qframe.h>
22#include <qarray.h>
23#include <qstringlist.h>
24
25class GraphData
26{
27public:
28 void clear();
29 void addItem( const QString &name, int value );
30
31 const QString &name( int i ) const { return names[i]; }
32 int value( int i ) const { return values[i]; }
33 unsigned count() const { return values.size(); }
34
35private:
36 QStringList names;
37 QArray<int> values;
38};
39
40class Graph : public QFrame
41{
42 Q_OBJECT
43public:
44 Graph( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
45
46 void setData( const GraphData *p ) { data = p; }
47
48protected:
49 const GraphData *data;
50};
51
52class PieGraph : public Graph
53{
54 Q_OBJECT
55public:
56 PieGraph( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
57
58protected:
59 virtual void drawContents( QPainter *p );
60};
61
62class BarGraph : public Graph
63{
64 Q_OBJECT
65public:
66 BarGraph( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
67
68protected:
69 virtual void drawContents( QPainter *p );
70 void drawSegment( QPainter *p, const QRect &r, const QColor &c );
71};
72
73class GraphLegend : public QFrame
74{
75 Q_OBJECT
76public:
77 GraphLegend( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
78
79 void setData( const GraphData *p );
80 virtual QSize sizeHint() const;
81 void setOrientation(Orientation o);
82
83protected:
84 virtual void drawContents( QPainter *p );
85
86private:
87 const GraphData *data;
88 bool horz;
89};
diff --git a/noncore/applets/memoryapplet/load.cpp b/noncore/applets/memoryapplet/load.cpp
new file mode 100644
index 0000000..d9d7a66
--- a/dev/null
+++ b/noncore/applets/memoryapplet/load.cpp
@@ -0,0 +1,212 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <stdio.h>
22
23#include <qfile.h>
24#include <qlayout.h>
25#include <qlabel.h>
26#include <qpainter.h>
27#include <qpixmap.h>
28#include <qtextstream.h>
29#include <qtimer.h>
30#include <qwhatsthis.h>
31
32#include "load.h"
33
34LoadInfo::LoadInfo( QWidget *parent, const char *name, WFlags f )
35 : QWidget( parent, name, f )
36{
37 QVBoxLayout *vb = new QVBoxLayout( this, 6 );
38
39 QString cpuInfo = getCpuInfo();
40 if ( !cpuInfo.isNull() )
41 vb->addWidget( new QLabel( cpuInfo, this ) );
42 vb->addWidget( new Load( this ), 100 );
43 QLabel *l = new QLabel( this );
44 l->setPixmap( makeLabel( red, tr("Application CPU usage (%)") ) );
45 vb->addWidget( l, 1 );
46 l = new QLabel( this );
47 l->setPixmap( makeLabel( green, tr("System CPU usage (%)") ) );
48 vb->addWidget( l, 1 );
49 vb->addStretch(50);
50
51 QWhatsThis::add( this, tr( "This page shows how much this device's processor is being used." ) );
52}
53
54QPixmap LoadInfo::makeLabel( const QColor &col, const QString &text )
55{
56 int h = fontMetrics().height();
57 QPixmap pm( 20 + fontMetrics().width( text ), h );
58 QPainter p( &pm );
59 p.fillRect( pm.rect(), colorGroup().background() );
60 p.fillRect( 0, h/2-4, 18, h/2+3, black );
61 p.setPen( col );
62 p.drawLine( 2, h/2, 15, h/2 );
63 p.setPen( colorGroup().text() );
64 p.drawText( 20, fontMetrics().ascent(), text );
65
66 return pm;
67}
68
69QString LoadInfo::getCpuInfo()
70{
71 bool haveInfo = FALSE;
72 QString info = tr("Type: ");
73 QFile f( "/proc/cpuinfo" );
74 if ( f.open( IO_ReadOnly ) ) {
75 QTextStream ts( &f );
76
77 while ( !ts.atEnd() ) {
78 QString s = ts.readLine();
79 if ( s.find( "model name" ) == 0 ) {
80 info += s.mid( s.find( ':' ) + 2 );
81 haveInfo = TRUE;
82 } else if ( s.find( "cpu MHz" ) == 0 ) {
83 double mhz = s.mid( s.find( ':' ) + 2 ).toDouble();
84 info += " " + QString::number( mhz, 'f', 0 );
85 info += "MHz";
86 break;
87 } else if ( s.find( "Processor" ) == 0 ) {
88 info += s.mid( s.find( ':' ) + 2 );
89 haveInfo = TRUE;
90 break;
91#ifdef __MIPSEL__
92 } else if ( s.find( "cpu model" ) == 0 ) {
93 info += " " + s.mid( s.find( ':' ) + 2 );
94 break;
95 } else if ( s.find( "cpu" ) == 0 ) {
96 info += s.mid( s.find( ':' ) + 2 );
97 haveInfo = TRUE;
98#endif
99 }
100 }
101 }
102
103 if ( !haveInfo )
104 info = QString();
105
106 return info;
107}
108
109Load::Load( QWidget *parent, const char *name, WFlags f )
110 : QWidget( parent, name, f )
111{
112 setMinimumHeight( 30 );
113 setBackgroundColor( black );
114 points = 100;
115 setMinimumWidth( points );
116 userLoad = new double [points];
117 systemLoad = new double [points];
118 for ( int i = 0; i < points; i++ ) {
119 userLoad[i] = 0.0;
120 systemLoad[i] = 0.0;
121 }
122 maxLoad = 1.3;
123 QTimer *timer = new QTimer( this );
124 connect( timer, SIGNAL(timeout()), SLOT(timeout()) );
125 timer->start( 2000 );
126 gettimeofday( &last, 0 );
127 first = TRUE;
128 timeout();
129}
130
131void Load::paintEvent( QPaintEvent * )
132{
133 QPainter p( this );
134
135 int h = height() - 5;
136
137 int mult = (int)(h / maxLoad);
138
139 p.setPen( gray );
140 p.drawLine( 0, h - mult, width(), h - mult );
141 p.drawText( 0, h - mult, "100" );
142 p.drawText( 0, h, "0" );
143
144 p.setPen( green );
145 for ( int i = 1; i < points; i++ ) {
146 int x1 = (i - 1) * width() / points;
147 int x2 = i * width() / points;
148 p.drawLine( x1, h - systemLoad[i-1] * mult,
149 x2, h - systemLoad[i] * mult );
150 }
151
152 p.setPen( red );
153 for ( int i = 1; i < points; i++ ) {
154 int x1 = (i - 1) * width() / points;
155 int x2 = i * width() / points;
156 p.drawLine( x1, h - userLoad[i-1] * mult,
157 x2, h - userLoad[i] * mult );
158 }
159}
160
161void Load::timeout()
162{
163 int user;
164 int usernice;
165 int sys;
166 int idle;
167 FILE *fp;
168 fp = fopen( "/proc/stat", "r" );
169 fscanf( fp, "cpu %d %d %d %d", &user, &usernice, &sys, &idle );
170 fclose( fp );
171 struct timeval now;
172 gettimeofday( &now, 0 );
173 int tdiff = now.tv_usec - last.tv_usec;
174 tdiff += (now.tv_sec - last.tv_sec) * 1000000;
175 tdiff /= 10000;
176
177 int udiff = user - lastUser;
178 int sdiff = sys - lastSys;
179 if ( tdiff > 0 ) {
180 double uload = (double)udiff / (double)tdiff;
181 double sload = (double)sdiff / (double)tdiff;
182 if ( !first ) {
183 for ( int i = 1; i < points; i++ ) {
184 userLoad[i-1] = userLoad[i];
185 systemLoad[i-1] = systemLoad[i];
186 }
187 userLoad[points-1] = uload;
188 systemLoad[points-1] = sload;
189 // scroll( -width()/points, 0, QRect( 0, 0, width() - width()/points + 1, height() ) );
190 repaint( TRUE );
191 double ml = 1.3;
192 /*
193 for ( int i = 0; i < points; i++ ) {
194 if ( userLoad[i] > ml )
195 ml = userLoad[i];
196 }
197 */
198 if ( maxLoad != ml ) {
199 maxLoad = ml;
200 update();
201 }
202 }
203
204 last = now;
205 lastUser = user;
206 lastSys = sys;
207 first = FALSE;
208 } else if ( tdiff < 0 ) {
209 last = now;
210 }
211}
212
diff --git a/noncore/applets/memoryapplet/load.h b/noncore/applets/memoryapplet/load.h
new file mode 100644
index 0000000..e7f5388
--- a/dev/null
+++ b/noncore/applets/memoryapplet/load.h
@@ -0,0 +1,60 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <sys/time.h>
22#include <qwidget.h>
23
24/*
25 Little load meter
26*/
27class Load : public QWidget {
28 Q_OBJECT
29public:
30 Load( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
31
32protected:
33 void paintEvent( QPaintEvent *ev );
34
35private slots:
36 void timeout();
37
38private:
39 int points;
40 double *userLoad;
41 double *systemLoad;
42 double maxLoad;
43 struct timeval last;
44 int lastUser;
45 int lastUsernice;
46 int lastSys;
47 int lastIdle;
48 bool first;
49};
50
51class LoadInfo : public QWidget
52{
53 Q_OBJECT
54public:
55 LoadInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
56
57private:
58 QPixmap makeLabel( const QColor &col, const QString &text );
59 QString getCpuInfo();
60};
diff --git a/noncore/applets/memoryapplet/memory.cpp b/noncore/applets/memoryapplet/memory.cpp
new file mode 100644
index 0000000..05349e4
--- a/dev/null
+++ b/noncore/applets/memoryapplet/memory.cpp
@@ -0,0 +1,165 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qlabel.h>
22#include <qtimer.h>
23#include <qfile.h>
24#include <qtextstream.h>
25#include <qlayout.h>
26#include <qwhatsthis.h>
27#include "graph.h"
28#include "memory.h"
29
30MemoryInfo::MemoryInfo( QWidget *parent, const char *name, WFlags f )
31 : QWidget( parent, name, f )
32{
33 QVBoxLayout *vb = new QVBoxLayout( this, 5 );
34
35 totalMem = new QLabel( this );
36 vb->addWidget( totalMem );
37
38 data = new GraphData();
39 graph = new BarGraph( this );
40 graph->setFrameStyle( QFrame::Panel | QFrame::Sunken );
41 vb->addWidget( graph, 1 );
42 graph->setData( data );
43
44 legend = new GraphLegend( this );
45 vb->addWidget( legend );
46 legend->setData( data );
47
48 swapMem = new QLabel( this );
49 vb->addWidget( swapMem );
50
51 swapdata = new GraphData();
52 swapgraph = new BarGraph( this );
53 swapgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken );
54 vb->addWidget( swapgraph, 1 );
55 swapgraph->setData( swapdata );
56
57 swaplegend = new GraphLegend( this );
58 vb->addWidget( swaplegend );
59 swaplegend->setData( swapdata );
60
61 vb->addStretch( 1 );
62 updateData();
63
64 QTimer *t = new QTimer( this );
65 connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) );
66 t->start( 5000 );
67
68 QWhatsThis::add( this, tr( "This page shows how memory (i.e. RAM) is being allocated on your device.\nMemory is categorized as follows:\n\n1. Used - memory used to by Opie and any running applications.\n2. Buffers - temporary storage used to improve performance\n3. Cached - information that has recently been used, but has not been freed yet.\n4. Free - memory not currently used by Opie or any running applications." ) );
69
70}
71
72MemoryInfo::~MemoryInfo()
73{
74 delete data;
75}
76
77void MemoryInfo::updateData()
78{
79 QFile file( "/proc/meminfo" );
80
81 if ( file.open( IO_ReadOnly ) )
82 {
83 // local variables
84 QString line;
85 QString identifier;
86 QString value;
87 int position;
88 QTextStream t( &file );
89
90 while ( !t.atEnd() )
91 {
92 // read a line
93 line = t.readLine();
94
95 // extract identifier and value from line
96 position = line.find( ":" );
97 identifier = line.left( position );
98 value = line.mid( position + 1, line.length() - position - 3 );
99 value = value.stripWhiteSpace();
100
101 // copy values in variables
102 if ( identifier == "MemTotal" )
103 {
104 total = value.toULong();
105 } else if ( identifier == "MemFree" )
106 {
107 memfree = value.toULong();
108 } else if ( identifier == "Buffers" )
109 {
110 buffers = value.toULong();
111 } else if ( identifier == "Cached" )
112 {
113 cached = value.toULong();
114 } else if ( identifier == "SwapCached" )
115 {
116 } else if ( identifier == "SwapTotal" )
117 {
118 swaptotal = value.toULong();
119 } else if ( identifier == "SwapFree" )
120 {
121 swapfree = value.toULong();
122 }
123 }
124
125 file.close();
126
127 // calculate values
128 used = total - memfree;
129 swapused = swaptotal - swapfree;
130 realUsed = total - ( buffers + cached + memfree );
131
132 // visualize values
133 totalMem->setText( tr( "Total Memory: %1 kB" ).arg( total ) );
134 data->clear();
135 data->addItem( tr("Used (%1 kB)").arg(realUsed), realUsed );
136 data->addItem( tr("Buffers (%1 kB)").arg(buffers), buffers );
137 data->addItem( tr("Cached (%1 kB)").arg(cached), cached );
138 data->addItem( tr("Free (%1 kB)").arg(memfree), memfree );
139
140 graph->hide();
141 graph->show();
142 legend->update();
143
144 if (swaptotal > 0)
145 {
146 swapMem->setText( tr( "Total Swap: %1 kB" ).arg( swaptotal ) );
147 swapdata->clear();
148 swapdata->addItem( tr("Used (%1 kB)").arg(swapused), swapused );
149 swapdata->addItem( tr("Free (%1 kB)").arg(swapfree), swapfree );
150
151 swapMem->show();
152 swapgraph->show();
153 swaplegend->show();
154
155 swapgraph->repaint( FALSE );
156 swaplegend->update();
157 }
158 else
159 {
160 swapMem->hide();
161 swapgraph->hide();
162 swaplegend->hide();
163 }
164 }
165}
diff --git a/noncore/applets/memoryapplet/memory.h b/noncore/applets/memoryapplet/memory.h
new file mode 100644
index 0000000..f655604
--- a/dev/null
+++ b/noncore/applets/memoryapplet/memory.h
@@ -0,0 +1,63 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef MEMORY_H
22#define MEMORY_H
23
24#include <qwidget.h>
25
26class GraphData;
27class Graph;
28class GraphLegend;
29class QLabel;
30
31class MemoryInfo : public QWidget
32{
33 Q_OBJECT
34public:
35 MemoryInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
36 ~MemoryInfo();
37
38 unsigned long total;
39 unsigned long used;
40 unsigned long memfree;
41 unsigned long buffers;
42 unsigned long cached;
43 unsigned long realUsed;
44 unsigned long swaptotal;
45 unsigned long swapused;
46 unsigned long swapfree;
47
48private slots:
49 void updateData();
50
51private:
52 QLabel *totalMem;
53 GraphData *data;
54 Graph *graph;
55 GraphLegend *legend;
56
57 QLabel* swapMem;
58 GraphData *swapdata;
59 Graph *swapgraph;
60 GraphLegend *swaplegend;
61};
62
63#endif
diff --git a/noncore/applets/memoryapplet/memoryapplet.pro b/noncore/applets/memoryapplet/memoryapplet.pro
index 57bb1c9..1dfc02f 100644
--- a/noncore/applets/memoryapplet/memoryapplet.pro
+++ b/noncore/applets/memoryapplet/memoryapplet.pro
@@ -1,22 +1,22 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt plugin warn_on 2CONFIG += qt plugin warn_on
3HEADERS = ../../settings/sysinfo/graph.h \ 3HEADERS = graph.h \
4 ../../settings/sysinfo/load.h \ 4 load.h \
5 ../../settings/sysinfo/memory.h \ 5 memory.h \
6 memorymeter.h \ 6 memorymeter.h \
7 memorystatus.h \ 7 memorystatus.h \
8 swapfile.h 8 swapfile.h
9SOURCES = ../../settings/sysinfo/graph.cpp \ 9SOURCES = graph.cpp \
10 ../../settings/sysinfo/load.cpp \ 10 load.cpp \
11 ../../settings/sysinfo/memory.cpp \ 11 memory.cpp \
12 memorymeter.cpp \ 12 memorymeter.cpp \
13 memorystatus.cpp \ 13 memorystatus.cpp \
14 swapfile.cpp 14 swapfile.cpp
15TARGET = memoryapplet 15TARGET = memoryapplet
16DESTDIR = $(OPIEDIR)/plugins/applets 16DESTDIR = $(OPIEDIR)/plugins/applets
17INCLUDEPATH += $(OPIEDIR)/include 17INCLUDEPATH += $(OPIEDIR)/include
18DEPENDPATH += 18DEPENDPATH +=
19VERSION = 1.0.0 19VERSION = 1.0.1
20LIBS += -lqpe -lopiecore2 -lopieui2 20LIBS += -lqpe -lopiecore2 -lopieui2
21 21
22include( $(OPIEDIR)/include.pro ) 22include( $(OPIEDIR)/include.pro )
diff --git a/noncore/applets/memoryapplet/swapfile.cpp b/noncore/applets/memoryapplet/swapfile.cpp
index 96010c8..4609c13 100644
--- a/noncore/applets/memoryapplet/swapfile.cpp
+++ b/noncore/applets/memoryapplet/swapfile.cpp
@@ -1,439 +1,452 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "swapfile.h" 21#include "swapfile.h"
22 22
23/* OPIE */ 23/* OPIE */
24#include <opie2/odebug.h> 24#include <opie2/odebug.h>
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26using namespace Opie::Core; 26using namespace Opie::Core;
27 27
28/* QT */ 28/* QT */
29#include <qfile.h> 29#include <qfile.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qlabel.h> 31#include <qlabel.h>
32#include <qtimer.h> 32#include <qtimer.h>
33#include <qlayout.h> 33#include <qlayout.h>
34#include <qpushbutton.h> 34#include <qpushbutton.h>
35#include <qhbuttongroup.h> 35#include <qhbuttongroup.h>
36#include <qradiobutton.h> 36#include <qradiobutton.h>
37#include <qlineedit.h> 37#include <qlineedit.h>
38#include <qprogressbar.h> 38#include <qprogressbar.h>
39#include <qcombobox.h> 39#include <qcombobox.h>
40#include <qvgroupbox.h> 40#include <qvgroupbox.h>
41#include <qhbox.h> 41#include <qhbox.h>
42#include <qmessagebox.h> 42#include <qmessagebox.h>
43#include <qcopchannel_qws.h> 43#include <qcopchannel_qws.h>
44 44
45/* STD */ 45/* STD */
46#include <stdio.h> 46#include <stdio.h>
47#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h> 48#include <string.h>
49#include <unistd.h> 49#include <unistd.h>
50#include <fcntl.h> 50#include <fcntl.h>
51#include <sys/vfs.h> 51#include <sys/vfs.h>
52#include <mntent.h> 52#include <mntent.h>
53#include <unistd.h> 53#include <unistd.h>
54#include <sys/types.h> 54#include <sys/types.h>
55 55
56Swapfile::Swapfile( QWidget *parent, const char *name, WFlags f ) 56Swapfile::Swapfile( QWidget *parent, const char *name, WFlags f )
57 : QWidget( parent, name, f ) 57 : QWidget( parent, name, f )
58{ 58{
59 // are we running as root? 59 // are we running as root?
60 isRoot = geteuid() == 0; 60 isRoot = geteuid() == 0;
61 61
62 QVBoxLayout* vb = new QVBoxLayout(this, 5); 62 QVBoxLayout* vb = new QVBoxLayout(this, 5);
63 63
64 QHButtonGroup* cfsdRBG = new QHButtonGroup(tr("Swapfile location"), this); 64 QHButtonGroup* cfsdRBG = new QHButtonGroup(tr("Swapfile location"), this);
65 cfsdRBG->setRadioButtonExclusive(true); 65 cfsdRBG->setRadioButtonExclusive(true);
66 vb->addWidget(cfsdRBG); 66 vb->addWidget(cfsdRBG);
67 67
68 ramRB = new QRadioButton(tr("RAM"), cfsdRBG); 68 ramRB = new QRadioButton(tr("RAM"), cfsdRBG);
69 cfRB = new QRadioButton(tr("CF Card"), cfsdRBG); 69 cfRB = new QRadioButton(tr("CF Card"), cfsdRBG);
70 sdRB = new QRadioButton(tr("SD Card"), cfsdRBG); 70 sdRB = new QRadioButton(tr("SD Card"), cfsdRBG);
71 71
72 QHBox *hb1 = new QHBox(this); 72 QHBox *hb1 = new QHBox(this);
73 hb1->setSpacing(5); 73 hb1->setSpacing(5);
74 74
75 swapPath1 = new QLineEdit(hb1); 75 swapPath1 = new QLineEdit(hb1);
76 swapPath1->setEnabled(false); 76 swapPath1->setEnabled(false);
77 77
78 QPushButton* swapOn = new QPushButton(tr(" On "), hb1); 78 QPushButton* swapOn = new QPushButton(tr(" On "), hb1);
79 QPushButton* swapOff = new QPushButton(tr(" Off "), hb1); 79 QPushButton* swapOff = new QPushButton(tr(" Off "), hb1);
80 vb->addWidget(hb1); 80 vb->addWidget(hb1);
81 81
82 QVGroupBox* box1 = new QVGroupBox(tr("Manage Swapfile"), this); 82 QVGroupBox* box1 = new QVGroupBox(tr("Manage Swapfile"), this);
83 vb->addWidget(box1); 83 vb->addWidget(box1);
84 84
85 QHBox *hb2 = new QHBox(box1); 85 QHBox *hb2 = new QHBox(box1);
86 hb2->setSpacing(5); 86 hb2->setSpacing(5);
87 QPushButton* mkSwap = new QPushButton(tr("Generate"), hb2); 87 QPushButton* mkSwap = new QPushButton(tr("Generate"), hb2);
88 QPushButton* rmSwap = new QPushButton(tr("Remove"), hb2); 88 QPushButton* rmSwap = new QPushButton(tr("Remove"), hb2);
89 89
90 QHBox *hb3 = new QHBox(box1); 90 QHBox *hb3 = new QHBox(box1);
91 hb3->setSpacing(5); 91 hb3->setSpacing(5);
92 swapSize = new QComboBox(hb3); 92 swapSize = new QComboBox(hb3);
93 swapSize->insertStringList(QStringList::split(",", tr("2 Mb,4 Mb,6 Mb,8 Mb"))); 93 swapSize->insertStringList(QStringList::split(",", tr("2 Mb,4 Mb,6 Mb,8 Mb,16 Mb,32 Mb,64 Mb")));
94 94
95 mkswapProgress = new QProgressBar(3, hb3); 95 mkswapProgress = new QProgressBar(3, hb3);
96 mkswapProgress->setCenterIndicator(true); 96 mkswapProgress->setCenterIndicator(true);
97 97
98 QHBox *hb4 = new QHBox(this); 98 QHBox *hb4 = new QHBox(this);
99 hb4->setSpacing(5); 99 hb4->setSpacing(5);
100 100
101 swapStatusIcon = new QLabel(hb4); 101 swapStatusIcon = new QLabel(hb4);
102 swapStatus = new QLabel("", hb4); 102 swapStatus = new QLabel("", hb4);
103 hb4->setStretchFactor(swapStatus, 99); 103 hb4->setStretchFactor(swapStatus, 99);
104 vb->addWidget(hb4); 104 vb->addWidget(hb4);
105 105
106 connect(swapOn, SIGNAL(clicked()), this, SLOT(swapon())); 106 connect(swapOn, SIGNAL(clicked()), this, SLOT(swapon()));
107 connect(swapOff, SIGNAL(clicked()), this, SLOT(swapoff())); 107 connect(swapOff, SIGNAL(clicked()), this, SLOT(swapoff()));
108 connect(cfRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); 108 connect(cfRB, SIGNAL(clicked()), this, SLOT(cfsdchecked()));
109 connect(sdRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); 109 connect(sdRB, SIGNAL(clicked()), this, SLOT(cfsdchecked()));
110 connect(ramRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); 110 connect(ramRB, SIGNAL(clicked()), this, SLOT(cfsdchecked()));
111 connect(mkSwap, SIGNAL(clicked()), this, SLOT(makeswapfile())); 111 connect(mkSwap, SIGNAL(clicked()), this, SLOT(makeswapfile()));
112 connect(rmSwap, SIGNAL(clicked()), this, SLOT(removeswapfile())); 112 connect(rmSwap, SIGNAL(clicked()), this, SLOT(removeswapfile()));
113 113
114 cfRB->setEnabled(FALSE); 114 cfRB->setEnabled(FALSE);
115 sdRB->setEnabled(FALSE); 115 sdRB->setEnabled(FALSE);
116 116
117 QCopChannel *pcmciaChannel = new QCopChannel("QPE/Card", this); 117 QCopChannel *pcmciaChannel = new QCopChannel("QPE/Card", this);
118 connect(pcmciaChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(cardnotify(const QCString&,const QByteArray&))); 118 connect(pcmciaChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(cardnotify(const QCString&,const QByteArray&)));
119 QCopChannel *sdChannel = new QCopChannel("QPE/Card", this); 119 QCopChannel *sdChannel = new QCopChannel("QPE/Card", this);
120 connect(sdChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(cardnotify(const QCString&,const QByteArray&))); 120 connect(sdChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(cardnotify(const QCString&,const QByteArray&)));
121 121
122 cardInPcmcia0 = FALSE; 122 cardInPcmcia0 = FALSE;
123 cardInPcmcia1 = FALSE; 123 cardInPcmcia1 = FALSE;
124 cardInSd = FALSE; 124 cardInSd = FALSE;
125 125
126 Swapfile::status(); 126 Swapfile::status();
127 Swapfile::getStatusPcmcia(); 127 Swapfile::getStatusPcmcia();
128 Swapfile::getStatusSd(); 128 Swapfile::getStatusSd();
129} 129}
130 130
131int Swapfile::exec(const QString& arg) 131int Swapfile::exec(const QString& arg)
132{ 132{
133 return system((!isRoot ? "sudo " : "") + arg); 133 return system((!isRoot ? "sudo " : "") + arg);
134} 134}
135 135
136 136
137Swapfile::~Swapfile() 137Swapfile::~Swapfile()
138{ 138{
139} 139}
140 140
141void Swapfile::cardnotify(const QCString & msg, const QByteArray &) 141void Swapfile::cardnotify(const QCString & msg, const QByteArray &)
142{ 142{
143 if (msg == "stabChanged()") 143 if (msg == "stabChanged()")
144 { 144 {
145 getStatusPcmcia(); 145 getStatusPcmcia();
146 } 146 }
147 else if (msg == "mtabChanged()") 147 else if (msg == "mtabChanged()")
148 { 148 {
149 getStatusSd(); 149 getStatusSd();
150 } 150 }
151} 151}
152 152
153void Swapfile::getStatusPcmcia() 153void Swapfile::getStatusPcmcia()
154{ 154{
155 155
156 bool cardWas0 = cardInPcmcia0;// remember last state 156 bool cardWas0 = cardInPcmcia0;// remember last state
157 bool cardWas1 = cardInPcmcia1; 157 bool cardWas1 = cardInPcmcia1;
158 158
159 QString fileName; 159 QString fileName;
160 160
161 // one of these 3 files should exist 161 // one of these 3 files should exist
162 if (QFile::exists("/var/run/stab")) { 162 if (QFile::exists("/var/run/stab")) {
163 fileName = "/var/run/stab"; 163 fileName = "/var/run/stab";
164 } else if (QFile::exists("/var/state/pcmcia/stab")) { 164 } else if (QFile::exists("/var/state/pcmcia/stab")) {
165 fileName = "/var/state/pcmcia/stab"; 165 fileName = "/var/state/pcmcia/stab";
166 } else { 166 } else {
167 fileName = "/var/lib/pcmcia/stab"; 167 fileName = "/var/lib/pcmcia/stab";
168 } 168 }
169 169
170 QFile f(fileName); 170 QFile f(fileName);
171 171
172 if (f.open(IO_ReadOnly)) { 172 if (f.open(IO_ReadOnly)) {
173 QStringList list; 173 QStringList list;
174 QTextStream stream(&f); 174 QTextStream stream(&f);
175 QString streamIn; 175 QString streamIn;
176 streamIn = stream.read(); 176 streamIn = stream.read();
177 list = QStringList::split("\n", streamIn); 177 list = QStringList::split("\n", streamIn);
178 for (QStringList::Iterator line = list.begin(); line != list.end(); 178 for (QStringList::Iterator line = list.begin(); line != list.end();
179 line++) { 179 line++) {
180 if ((*line).startsWith("Socket 0:")) { 180 if ((*line).startsWith("Socket 0:")) {
181 if ((*line).startsWith("Socket 0: empty") && cardInPcmcia0) { 181 if ((*line).startsWith("Socket 0: empty") && cardInPcmcia0) {
182 cardInPcmcia0 = FALSE; 182 cardInPcmcia0 = FALSE;
183 } else if (!(*line).startsWith("Socket 0: empty") 183 } else if (!(*line).startsWith("Socket 0: empty")
184 && !cardInPcmcia0) { 184 && !cardInPcmcia0) {
185 cardInPcmcia0 = TRUE; 185 cardInPcmcia0 = TRUE;
186 } 186 }
187 } else if ((*line).startsWith("Socket 1:")) { 187 } else if ((*line).startsWith("Socket 1:")) {
188 if ((*line).startsWith("Socket 1: empty") && cardInPcmcia1) { 188 if ((*line).startsWith("Socket 1: empty") && cardInPcmcia1) {
189 cardInPcmcia1 = FALSE; 189 cardInPcmcia1 = FALSE;
190 } else if (!(*line).startsWith("Socket 1: empty") 190 } else if (!(*line).startsWith("Socket 1: empty")
191 && !cardInPcmcia1) { 191 && !cardInPcmcia1) {
192 cardInPcmcia1 = TRUE; 192 cardInPcmcia1 = TRUE;
193 } 193 }
194 } 194 }
195 } 195 }
196 f.close(); 196 f.close();
197 197
198 if (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1) { 198 if (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1) {
199 QString text = QString::null; 199 QString text = QString::null;
200 QString what = QString::null; 200 QString what = QString::null;
201 if (cardWas0 != cardInPcmcia0) { 201 if (cardWas0 != cardInPcmcia0) {
202 if (cardInPcmcia0) { 202 if (cardInPcmcia0) {
203 cfRB->setEnabled(TRUE); 203 cfRB->setEnabled(TRUE);
204 } else { 204 } else {
205 cfRB->setChecked(FALSE); 205 cfRB->setChecked(FALSE);
206 cfRB->setEnabled(FALSE); 206 cfRB->setEnabled(FALSE);
207 } 207 }
208 } 208 }
209 209
210 if (cardWas1 != cardInPcmcia1) { 210 if (cardWas1 != cardInPcmcia1) {
211 if (cardInPcmcia1) { 211 if (cardInPcmcia1) {
212 cfRB->setEnabled(TRUE); 212 cfRB->setEnabled(TRUE);
213 } else { 213 } else {
214 cfRB->setChecked(FALSE); 214 cfRB->setChecked(FALSE);
215 cfRB->setEnabled(FALSE); 215 cfRB->setEnabled(FALSE);
216 } 216 }
217 } 217 }
218 } 218 }
219 } else { 219 } else {
220 // no file found 220 // no file found
221 odebug << "no file found" << oendl; 221 odebug << "no file found" << oendl;
222 cardInPcmcia0 = FALSE; 222 cardInPcmcia0 = FALSE;
223 cardInPcmcia1 = FALSE; 223 cardInPcmcia1 = FALSE;
224 } 224 }
225 Swapfile::cfsdchecked(); 225 Swapfile::cfsdchecked();
226} 226}
227 227
228 228
229void Swapfile::getStatusSd() 229void Swapfile::getStatusSd()
230{ 230{
231 231
232 bool cardWas = cardInSd;// remember last state 232 bool cardWas = cardInSd;// remember last state
233 cardInSd = FALSE; 233 cardInSd = FALSE;
234 234
235#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 235#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
236 struct mntent *me; 236 struct mntent *me;
237 FILE *mntfp = setmntent("/etc/mtab", "r"); 237 FILE *mntfp = setmntent("/etc/mtab", "r");
238 238
239 if (mntfp) { 239 if (mntfp) {
240 while ((me = getmntent(mntfp)) != 0) { 240 while ((me = getmntent(mntfp)) != 0) {
241 QString fs = me->mnt_fsname; 241 QString fs = me->mnt_fsname;
242 if (fs.left(14) == "/dev/mmc/part1" || fs.left(7) == "/dev/sd" 242 if (fs.left(14) == "/dev/mmc/part1" || fs.left(7) == "/dev/sd"
243 || fs.left(9) == "/dev/mmcd") { 243 || fs.left(9) == "/dev/mmcd") {
244 cardInSd = TRUE; 244 cardInSd = TRUE;
245 show(); 245 show();
246 } 246 }
247 } 247 }
248 endmntent(mntfp); 248 endmntent(mntfp);
249 } 249 }
250 250
251 if (cardWas != cardInSd) { 251 if (cardWas != cardInSd) {
252 QString text = QString::null; 252 QString text = QString::null;
253 QString what = QString::null; 253 QString what = QString::null;
254 if (cardInSd) { 254 if (cardInSd) {
255 sdRB->setEnabled(TRUE); 255 sdRB->setEnabled(TRUE);
256 } else { 256 } else {
257 sdRB->setChecked(FALSE); 257 sdRB->setChecked(FALSE);
258 sdRB->setEnabled(FALSE); 258 sdRB->setEnabled(FALSE);
259 } 259 }
260 } 260 }
261#else 261#else
262#error "Not on Linux" 262#error "Not on Linux"
263#endif 263#endif
264 Swapfile::cfsdchecked(); 264 Swapfile::cfsdchecked();
265} 265}
266 266
267int rc=0; 267int rc=0;
268 268
269void Swapfile::swapon() 269void Swapfile::swapon()
270{ 270{
271 char swapcmd[128] ="swapon "; 271 char swapcmd[128] ="swapon ";
272 Swapfile::cfsdchecked(); 272 Swapfile::cfsdchecked();
273 strcat(swapcmd,swapPath1->text()); 273 strcat(swapcmd,swapPath1->text());
274 char *runcmd = swapcmd; 274 char *runcmd = swapcmd;
275 rc = exec(QString("%1").arg(runcmd)); 275 rc = exec(QString("%1").arg(runcmd));
276 if (rc != 0) { 276 if (rc != 0) {
277 setStatusMessage("Failed to attach swapfile.", true); 277 setStatusMessage("Failed to attach swapfile.", true);
278 } 278 }
279 else { 279 else {
280 /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ 280 /* QMessageBox::information(this, "Information", "Swapfile is active!"); */
281 setStatusMessage("Swapfile activated."); 281 setStatusMessage("Swapfile activated.");
282 } 282 }
283 Swapfile::status(); 283 Swapfile::status();
284} 284}
285 285
286 286
287void Swapfile::setStatusMessage(const QString& text, bool error /* = false */) 287void Swapfile::setStatusMessage(const QString& text, bool error /* = false */)
288{ 288{
289 swapStatus->setText("<b>" + text + "</b>"); 289 swapStatus->setText("<b>" + text + "</b>");
290 swapStatusIcon->setPixmap(Resource::loadPixmap(error ? "close" : "done")); 290 swapStatusIcon->setPixmap(Resource::loadPixmap(error ? "close" : "done"));
291} 291}
292 292
293 293
294void Swapfile::swapoff() 294void Swapfile::swapoff()
295{ 295{
296 char swapcmd[128] ="swapoff "; 296 char swapcmd[128] ="swapoff ";
297 if (Swapfile::cfRB->isChecked() == TRUE) 297 if (Swapfile::cfRB->isChecked() == TRUE)
298 Swapfile::cfsdchecked(); 298 Swapfile::cfsdchecked();
299 strcat(swapcmd,swapPath1->text()); 299 strcat(swapcmd,swapPath1->text());
300 char *runcmd = swapcmd; 300 char *runcmd = swapcmd;
301 rc = exec(QString("%1").arg(runcmd)); 301 rc = exec(QString("%1").arg(runcmd));
302 if (rc != 0) { 302 if (rc != 0) {
303 setStatusMessage(tr("Failed to detach swapfile."), true); 303 setStatusMessage(tr("Failed to detach swapfile."), true);
304 } 304 }
305 else { 305 else {
306 /* QMessageBox::information(this, "Information", "Swapfile is inactive!"); */ 306 /* QMessageBox::information(this, "Information", "Swapfile is inactive!"); */
307 setStatusMessage(tr("Swapfile deactivated.")); 307 setStatusMessage(tr("Swapfile deactivated."));
308 /* Swapfile::swapPath->clear();*/ 308 /* Swapfile::swapPath->clear();*/
309 } 309 }
310 Swapfile::status(); 310 Swapfile::status();
311} 311}
312 312
313void Swapfile::cfsdchecked() 313void Swapfile::cfsdchecked()
314{ 314{
315 /* Swapfile::swapPath->clear();*/ 315 /* Swapfile::swapPath->clear();*/
316 Swapfile::swapPath1->clear(); 316 Swapfile::swapPath1->clear();
317 if (Swapfile::ramRB->isChecked() == TRUE) 317 if (Swapfile::ramRB->isChecked() == TRUE)
318 { 318 {
319 Swapfile::swapPath1->insert("/home/swapfile"); 319 Swapfile::swapPath1->insert("/home/swapfile");
320 } 320 }
321 if (Swapfile::sdRB->isChecked() == TRUE) 321 if (Swapfile::sdRB->isChecked() == TRUE)
322 { 322 {
323 Swapfile::swapPath1->insert("/mnt/card/swapfile"); 323 Swapfile::swapPath1->insert("/mnt/card/swapfile");
324 } 324 }
325 if (Swapfile::cfRB->isChecked() == TRUE) 325 if (Swapfile::cfRB->isChecked() == TRUE)
326 { 326 {
327 Swapfile::swapPath1->insert("/mnt/cf/swapfile"); 327 Swapfile::swapPath1->insert("/mnt/cf/swapfile");
328 } 328 }
329 /*Swapfile::swapPath->insert(Swapfile::swapPath1->text());*/ 329 /*Swapfile::swapPath->insert(Swapfile::swapPath1->text());*/
330} 330}
331 331
332void Swapfile::makeswapfile() 332void Swapfile::makeswapfile()
333{ 333{
334 int i = swapSize->currentItem(); 334 int i = swapSize->currentItem();
335 335
336 mkswapProgress->setProgress(1); 336 mkswapProgress->setProgress(1);
337 switch ( i ) { 337 switch ( i ) {
338 case 0: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=2048").arg(swapPath1->text())); 338 case 0: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=2048").arg(swapPath1->text()));
339 break; 339 break;
340 case 1: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=4096").arg(swapPath1->text())); 340 case 1: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=4096").arg(swapPath1->text()));
341 break; 341 break;
342 case 2: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=6144").arg(swapPath1->text())); 342 case 2: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=6144").arg(swapPath1->text()));
343 break; 343 break;
344 case 3: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=8192").arg(swapPath1->text())); 344 case 3: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=8192").arg(swapPath1->text()));
345 break; 345 break;
346 case 4: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=16384").arg(swapPath1->text()));
347 break;
348 case 5: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=32768").arg(swapPath1->text()));
349 break;
350 case 6: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=65536").arg(swapPath1->text()));
351 break;
352
346 } 353 }
347 if (rc != 0) { 354 if (rc != 0) {
348 setStatusMessage(tr("Failed to create swapfile."), true); 355 setStatusMessage(tr("Failed to create swapfile."), true);
349 } 356 }
350 357
351 mkswapProgress->setProgress(2); 358 mkswapProgress->setProgress(2);
352 rc=exec(QString("mkswap %1").arg(swapPath1->text())); 359 rc=exec(QString("mkswap %1").arg(swapPath1->text()));
353 if (rc != 0) { 360 if (rc != 0) {
354 setStatusMessage(tr("Failed to initialize swapfile."), true); 361 setStatusMessage(tr("Failed to initialize swapfile."), true);
355 } 362 }
356 mkswapProgress->setProgress(3); 363 mkswapProgress->setProgress(3);
357 mkswapProgress->reset(); 364 mkswapProgress->reset();
358 setStatusMessage(tr("Swapfile created.")); 365 setStatusMessage(tr("Swapfile created."));
359} 366}
360 367
361void Swapfile::removeswapfile() 368void Swapfile::removeswapfile()
362{ 369{
363 exec(QString("swapoff %1").arg(swapPath1->text())); 370 exec(QString("swapoff %1").arg(swapPath1->text()));
364 rc=exec(QString("rm -rf %1").arg(swapPath1->text())); 371 rc=exec(QString("rm -rf %1").arg(swapPath1->text()));
365 if (rc != 0) { 372 if (rc != 0) {
366 setStatusMessage(tr("Failed to remove swapfile."), true); 373 setStatusMessage(tr("Failed to remove swapfile."), true);
367 } 374 }
368 Swapfile::status(); 375 Swapfile::status();
369 Swapfile::cfsdchecked(); 376 Swapfile::cfsdchecked();
370 setStatusMessage(tr("Swapfile removed.")); 377 setStatusMessage(tr("Swapfile removed."));
371} 378}
372 379
373void Swapfile::status() 380void Swapfile::status()
374{ 381{
375 FILE *fp; 382 FILE *fp;
376 char buffer[128], swapfile[128], temp[128]; 383 char buffer[128], swapfile[128], temp[128];
377 int swapsize=2000, i=1; 384 int swapsize=2000, i=1;
378 385
379 fp=fopen("/proc/swaps", "r"); 386 fp=fopen("/proc/swaps", "r");
380 while ( (fgets(buffer,128,fp)) != NULL ) { 387 while ( (fgets(buffer,128,fp)) != NULL ) {
381 sscanf(buffer, "%s %s %d %s %s\n", swapfile, temp, &swapsize, temp, temp); 388 sscanf(buffer, "%s %s %d %s %s\n", swapfile, temp, &swapsize, temp, temp);
382 } 389 }
383 fclose(fp); 390 fclose(fp);
384 391
385 ramRB->setChecked(FALSE); 392 ramRB->setChecked(FALSE);
386 cfRB->setChecked(FALSE); 393 cfRB->setChecked(FALSE);
387 sdRB->setChecked(FALSE); 394 sdRB->setChecked(FALSE);
388 395
389 i=strcmp(swapfile, "/home/swapfile"); 396 i=strcmp(swapfile, "/home/swapfile");
390 if ( i == 0 ) { 397 if ( i == 0 ) {
391 ramRB->setChecked(TRUE); 398 ramRB->setChecked(TRUE);
392 /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ 399 /* QMessageBox::information(this, "Information", "Swapfile is active!"); */
393 setStatusMessage(tr("Swapfile activated.")); 400 setStatusMessage(tr("Swapfile activated."));
394 } 401 }
395 i=strcmp(swapfile, "/usr/mnt.rom/cf/swapfile"); 402 i=strcmp(swapfile, "/usr/mnt.rom/cf/swapfile");
396 if ( i == 0 ) { 403 if ( i == 0 ) {
397 cfRB->setChecked(TRUE); 404 cfRB->setChecked(TRUE);
398 /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ 405 /* QMessageBox::information(this, "Information", "Swapfile is active!"); */
399 setStatusMessage(tr("Swapfile activated.")); 406 setStatusMessage(tr("Swapfile activated."));
400 } 407 }
401 i=strcmp(swapfile, "/mnt/cf/swapfile"); 408 i=strcmp(swapfile, "/mnt/cf/swapfile");
402 if ( i == 0 ) { 409 if ( i == 0 ) {
403 cfRB->setChecked(TRUE); 410 cfRB->setChecked(TRUE);
404 /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ 411 /* QMessageBox::information(this, "Information", "Swapfile is active!"); */
405 setStatusMessage(tr("Swapfile activated.")); 412 setStatusMessage(tr("Swapfile activated."));
406 } 413 }
407 i=strcmp(swapfile, "/usr/mnt.rom/card/swapfile"); 414 i=strcmp(swapfile, "/usr/mnt.rom/card/swapfile");
408 if ( i == 0 ) { 415 if ( i == 0 ) {
409 sdRB->setChecked(TRUE); 416 sdRB->setChecked(TRUE);
410 /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ 417 /* QMessageBox::information(this, "Information", "Swapfile is active!"); */
411 setStatusMessage(tr("Swapfile activated.")); 418 setStatusMessage(tr("Swapfile activated."));
412 } 419 }
413 i=strcmp(swapfile, "/mnt/card/swapfile"); 420 i=strcmp(swapfile, "/mnt/card/swapfile");
414 if ( i == 0 ) { 421 if ( i == 0 ) {
415 sdRB->setChecked(TRUE); 422 sdRB->setChecked(TRUE);
416 /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ 423 /* QMessageBox::information(this, "Information", "Swapfile is active!"); */
417 setStatusMessage(tr("Swapfile activated.")); 424 setStatusMessage(tr("Swapfile activated."));
418 } 425 }
419 426
420 Swapfile::cfsdchecked(); 427 Swapfile::cfsdchecked();
421 428
422 429
423 swapsize /=1000; 430 swapsize /=1000;
424 431
425 switch ( swapsize ) { 432 switch ( swapsize ) {
426 case 2: swapSize->setCurrentItem(0); 433 case 2: swapSize->setCurrentItem(0);
427 break; 434 break;
428 case 4: swapSize->setCurrentItem(1); 435 case 4: swapSize->setCurrentItem(1);
429 break; 436 break;
430 case 6: swapSize->setCurrentItem(2); 437 case 6: swapSize->setCurrentItem(2);
431 break; 438 break;
432 case 8: swapSize->setCurrentItem(3); 439 case 8: swapSize->setCurrentItem(3);
433 break; 440 break;
441 case 16: swapSize->setCurrentItem(4);
442 break;
443 case 32: swapSize->setCurrentItem(5);
444 break;
445 case 64: swapSize->setCurrentItem(6);
446 break;
434 } 447 }
435 448
436 449
437} 450}
438 451
439 452