-rw-r--r-- | noncore/applets/memoryapplet/config.in | 6 | ||||
-rw-r--r-- | noncore/applets/memoryapplet/opie-memoryapplet.control | 2 | ||||
-rw-r--r-- | noncore/applets/memoryapplet/swapfile.cpp | 4 |
3 files changed, 6 insertions, 6 deletions
diff --git a/noncore/applets/memoryapplet/config.in b/noncore/applets/memoryapplet/config.in index a35e35d..a06f888 100644 --- a/noncore/applets/memoryapplet/config.in +++ b/noncore/applets/memoryapplet/config.in | |||
@@ -1,6 +1,6 @@ | |||
1 | config MEMORYAPPLET | 1 | config MEMORYAPPLET |
2 | boolean "opie-memoryapplet (view memory status and manage a swap file)" | 2 | boolean "opie-memoryapplet (view memory status and manage a swap file)" |
3 | default "y" | 3 | default "y" |
4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2UI && SYSINFO | 4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2UI && SYSINFO |
5 | comment "opie-memoryapplet needs a libqpe, libopie2ui and sysinfo" | 5 | comment "opie-memoryapplet needs a libqpe, libopie2core, libopie2ui and sysinfo" |
6 | depends ! ( LIBOPIE && SYSINFO ) | 6 | depends ! (( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2UI && SYSINFO) |
diff --git a/noncore/applets/memoryapplet/opie-memoryapplet.control b/noncore/applets/memoryapplet/opie-memoryapplet.control index c01a93f..40f1ec1 100644 --- a/noncore/applets/memoryapplet/opie-memoryapplet.control +++ b/noncore/applets/memoryapplet/opie-memoryapplet.control | |||
@@ -1,10 +1,10 @@ | |||
1 | Package: opie-memoryapplet | 1 | Package: opie-memoryapplet |
2 | Files: plugins/applets/libmemoryapplet.so* pics/memory | 2 | Files: plugins/applets/libmemoryapplet.so* pics/memory |
3 | Priority: optional | 3 | Priority: optional |
4 | Section: opie/applets | 4 | Section: opie/applets |
5 | Maintainer: Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 5 | Maintainer: Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
6 | Architecture: arm | 6 | Architecture: arm |
7 | Depends: task-opie-minimal, libopieui2 | 7 | Depends: task-opie-minimal, libopiecore2, libopieui2 |
8 | Description: Memory Applet | 8 | Description: Memory Applet |
9 | This applet displays the amount of free memory and manages the swap partition | 9 | This applet displays the amount of free memory and manages the swap partition |
10 | Version: $QPE_VERSION$EXTRAVERSION | 10 | Version: $QPE_VERSION$EXTRAVERSION |
diff --git a/noncore/applets/memoryapplet/swapfile.cpp b/noncore/applets/memoryapplet/swapfile.cpp index 50c173b..cd16d6d 100644 --- a/noncore/applets/memoryapplet/swapfile.cpp +++ b/noncore/applets/memoryapplet/swapfile.cpp | |||
@@ -1,458 +1,458 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2002-2005 the Opie Team <opie-devel@handhelds.org> | 3 | ** Copyright (C) 2002-2005 the Opie Team <opie-devel@handhelds.org> |
4 | ** | 4 | ** |
5 | ** This file is part of Opie Environment. | 5 | ** This file is part of Opie Environment. |
6 | ** | 6 | ** |
7 | ** This file may be distributed and/or modified under the terms of the | 7 | ** This file may be distributed and/or modified under the terms of the |
8 | ** GNU General Public License version 2 as published by the Free Software | 8 | ** GNU General Public License version 2 as published by the Free Software |
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
10 | ** packaging of this file. | 10 | ** packaging of this file. |
11 | ** | 11 | ** |
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
14 | ** | 14 | ** |
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
16 | ** | 16 | ** |
17 | ** Contact info@trolltech.com if any conditions of this licensing are | 17 | ** Contact info@trolltech.com if any conditions of this licensing are |
18 | ** not clear to you. | 18 | ** not clear to you. |
19 | ** | 19 | ** |
20 | **********************************************************************/ | 20 | **********************************************************************/ |
21 | 21 | ||
22 | #include "swapfile.h" | 22 | #include "swapfile.h" |
23 | 23 | ||
24 | /* OPIE */ | 24 | /* OPIE */ |
25 | #include <opie2/odebug.h> | 25 | #include <opie2/odebug.h> |
26 | #include <qpe/resource.h> | 26 | #include <opie2/oresource.h> |
27 | using namespace Opie::Core; | 27 | using namespace Opie::Core; |
28 | 28 | ||
29 | /* QT */ | 29 | /* QT */ |
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | #include <qtextstream.h> | 31 | #include <qtextstream.h> |
32 | #include <qlabel.h> | 32 | #include <qlabel.h> |
33 | #include <qtimer.h> | 33 | #include <qtimer.h> |
34 | #include <qlayout.h> | 34 | #include <qlayout.h> |
35 | #include <qpushbutton.h> | 35 | #include <qpushbutton.h> |
36 | #include <qhbuttongroup.h> | 36 | #include <qhbuttongroup.h> |
37 | #include <qradiobutton.h> | 37 | #include <qradiobutton.h> |
38 | #include <qlineedit.h> | 38 | #include <qlineedit.h> |
39 | #include <qprogressbar.h> | 39 | #include <qprogressbar.h> |
40 | #include <qcombobox.h> | 40 | #include <qcombobox.h> |
41 | #include <qvgroupbox.h> | 41 | #include <qvgroupbox.h> |
42 | #include <qhbox.h> | 42 | #include <qhbox.h> |
43 | #include <qmessagebox.h> | 43 | #include <qmessagebox.h> |
44 | #include <qcopchannel_qws.h> | 44 | #include <qcopchannel_qws.h> |
45 | 45 | ||
46 | /* STD */ | 46 | /* STD */ |
47 | #include <stdio.h> | 47 | #include <stdio.h> |
48 | #include <stdlib.h> | 48 | #include <stdlib.h> |
49 | #include <string.h> | 49 | #include <string.h> |
50 | #include <unistd.h> | 50 | #include <unistd.h> |
51 | #include <fcntl.h> | 51 | #include <fcntl.h> |
52 | #include <sys/vfs.h> | 52 | #include <sys/vfs.h> |
53 | #include <mntent.h> | 53 | #include <mntent.h> |
54 | #include <unistd.h> | 54 | #include <unistd.h> |
55 | #include <sys/types.h> | 55 | #include <sys/types.h> |
56 | 56 | ||
57 | Swapfile::Swapfile( QWidget *parent, const char *name, WFlags f ) | 57 | Swapfile::Swapfile( QWidget *parent, const char *name, WFlags f ) |
58 | : QWidget( parent, name, f ) | 58 | : QWidget( parent, name, f ) |
59 | { | 59 | { |
60 | if ( !QFile::exists( "/proc/swaps" ) ) | 60 | if ( !QFile::exists( "/proc/swaps" ) ) |
61 | { | 61 | { |
62 | QLabel *text = new QLabel( tr( "Swap disabled in kernel" ), this ); | 62 | QLabel *text = new QLabel( tr( "Swap disabled in kernel" ), this ); |
63 | return; | 63 | return; |
64 | } | 64 | } |
65 | // are we running as root? | 65 | // are we running as root? |
66 | isRoot = geteuid() == 0; | 66 | isRoot = geteuid() == 0; |
67 | 67 | ||
68 | QVBoxLayout* vb = new QVBoxLayout(this, 5); | 68 | QVBoxLayout* vb = new QVBoxLayout(this, 5); |
69 | 69 | ||
70 | QHButtonGroup* cfsdRBG = new QHButtonGroup(tr("Swapfile location"), this); | 70 | QHButtonGroup* cfsdRBG = new QHButtonGroup(tr("Swapfile location"), this); |
71 | cfsdRBG->setRadioButtonExclusive(true); | 71 | cfsdRBG->setRadioButtonExclusive(true); |
72 | vb->addWidget(cfsdRBG); | 72 | vb->addWidget(cfsdRBG); |
73 | 73 | ||
74 | ramRB = new QRadioButton(tr("RAM"), cfsdRBG); | 74 | ramRB = new QRadioButton(tr("RAM"), cfsdRBG); |
75 | cfRB = new QRadioButton(tr("CF Card"), cfsdRBG); | 75 | cfRB = new QRadioButton(tr("CF Card"), cfsdRBG); |
76 | sdRB = new QRadioButton(tr("SD Card"), cfsdRBG); | 76 | sdRB = new QRadioButton(tr("SD Card"), cfsdRBG); |
77 | 77 | ||
78 | QHBox *hb1 = new QHBox(this); | 78 | QHBox *hb1 = new QHBox(this); |
79 | hb1->setSpacing(5); | 79 | hb1->setSpacing(5); |
80 | 80 | ||
81 | swapPath1 = new QLineEdit(hb1); | 81 | swapPath1 = new QLineEdit(hb1); |
82 | swapPath1->setEnabled(false); | 82 | swapPath1->setEnabled(false); |
83 | 83 | ||
84 | QPushButton* swapOn = new QPushButton(tr(" On "), hb1); | 84 | QPushButton* swapOn = new QPushButton(tr(" On "), hb1); |
85 | QPushButton* swapOff = new QPushButton(tr(" Off "), hb1); | 85 | QPushButton* swapOff = new QPushButton(tr(" Off "), hb1); |
86 | vb->addWidget(hb1); | 86 | vb->addWidget(hb1); |
87 | 87 | ||
88 | QVGroupBox* box1 = new QVGroupBox(tr("Manage Swapfile"), this); | 88 | QVGroupBox* box1 = new QVGroupBox(tr("Manage Swapfile"), this); |
89 | vb->addWidget(box1); | 89 | vb->addWidget(box1); |
90 | 90 | ||
91 | QHBox *hb2 = new QHBox(box1); | 91 | QHBox *hb2 = new QHBox(box1); |
92 | hb2->setSpacing(5); | 92 | hb2->setSpacing(5); |
93 | QPushButton* mkSwap = new QPushButton(tr("Generate"), hb2); | 93 | QPushButton* mkSwap = new QPushButton(tr("Generate"), hb2); |
94 | QPushButton* rmSwap = new QPushButton(tr("Remove"), hb2); | 94 | QPushButton* rmSwap = new QPushButton(tr("Remove"), hb2); |
95 | 95 | ||
96 | QHBox *hb3 = new QHBox(box1); | 96 | QHBox *hb3 = new QHBox(box1); |
97 | hb3->setSpacing(5); | 97 | hb3->setSpacing(5); |
98 | swapSize = new QComboBox(hb3); | 98 | swapSize = new QComboBox(hb3); |
99 | swapSize->insertStringList(QStringList::split(",", tr("2 Mb,4 Mb,6 Mb,8 Mb,16 Mb,32 Mb,64 Mb"))); | 99 | swapSize->insertStringList(QStringList::split(",", tr("2 Mb,4 Mb,6 Mb,8 Mb,16 Mb,32 Mb,64 Mb"))); |
100 | 100 | ||
101 | mkswapProgress = new QProgressBar(3, hb3); | 101 | mkswapProgress = new QProgressBar(3, hb3); |
102 | mkswapProgress->setCenterIndicator(true); | 102 | mkswapProgress->setCenterIndicator(true); |
103 | 103 | ||
104 | QHBox *hb4 = new QHBox(this); | 104 | QHBox *hb4 = new QHBox(this); |
105 | hb4->setSpacing(5); | 105 | hb4->setSpacing(5); |
106 | 106 | ||
107 | swapStatusIcon = new QLabel(hb4); | 107 | swapStatusIcon = new QLabel(hb4); |
108 | swapStatus = new QLabel("", hb4); | 108 | swapStatus = new QLabel("", hb4); |
109 | hb4->setStretchFactor(swapStatus, 99); | 109 | hb4->setStretchFactor(swapStatus, 99); |
110 | vb->addWidget(hb4); | 110 | vb->addWidget(hb4); |
111 | 111 | ||
112 | connect(swapOn, SIGNAL(clicked()), this, SLOT(swapon())); | 112 | connect(swapOn, SIGNAL(clicked()), this, SLOT(swapon())); |
113 | connect(swapOff, SIGNAL(clicked()), this, SLOT(swapoff())); | 113 | connect(swapOff, SIGNAL(clicked()), this, SLOT(swapoff())); |
114 | connect(cfRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); | 114 | connect(cfRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); |
115 | connect(sdRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); | 115 | connect(sdRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); |
116 | connect(ramRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); | 116 | connect(ramRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); |
117 | connect(mkSwap, SIGNAL(clicked()), this, SLOT(makeswapfile())); | 117 | connect(mkSwap, SIGNAL(clicked()), this, SLOT(makeswapfile())); |
118 | connect(rmSwap, SIGNAL(clicked()), this, SLOT(removeswapfile())); | 118 | connect(rmSwap, SIGNAL(clicked()), this, SLOT(removeswapfile())); |
119 | 119 | ||
120 | cfRB->setEnabled(FALSE); | 120 | cfRB->setEnabled(FALSE); |
121 | sdRB->setEnabled(FALSE); | 121 | sdRB->setEnabled(FALSE); |
122 | 122 | ||
123 | QCopChannel *pcmciaChannel = new QCopChannel("QPE/Card", this); | 123 | QCopChannel *pcmciaChannel = new QCopChannel("QPE/Card", this); |
124 | connect(pcmciaChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(cardnotify(const QCString&,const QByteArray&))); | 124 | connect(pcmciaChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(cardnotify(const QCString&,const QByteArray&))); |
125 | QCopChannel *sdChannel = new QCopChannel("QPE/Card", this); | 125 | QCopChannel *sdChannel = new QCopChannel("QPE/Card", this); |
126 | connect(sdChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(cardnotify(const QCString&,const QByteArray&))); | 126 | connect(sdChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(cardnotify(const QCString&,const QByteArray&))); |
127 | 127 | ||
128 | cardInPcmcia0 = FALSE; | 128 | cardInPcmcia0 = FALSE; |
129 | cardInPcmcia1 = FALSE; | 129 | cardInPcmcia1 = FALSE; |
130 | cardInSd = FALSE; | 130 | cardInSd = FALSE; |
131 | 131 | ||
132 | Swapfile::status(); | 132 | Swapfile::status(); |
133 | Swapfile::getStatusPcmcia(); | 133 | Swapfile::getStatusPcmcia(); |
134 | Swapfile::getStatusSd(); | 134 | Swapfile::getStatusSd(); |
135 | } | 135 | } |
136 | 136 | ||
137 | int Swapfile::exec(const QString& arg) | 137 | int Swapfile::exec(const QString& arg) |
138 | { | 138 | { |
139 | return system((!isRoot ? "sudo " : "") + arg); | 139 | return system((!isRoot ? "sudo " : "") + arg); |
140 | } | 140 | } |
141 | 141 | ||
142 | 142 | ||
143 | Swapfile::~Swapfile() | 143 | Swapfile::~Swapfile() |
144 | { | 144 | { |
145 | } | 145 | } |
146 | 146 | ||
147 | void Swapfile::cardnotify(const QCString & msg, const QByteArray &) | 147 | void Swapfile::cardnotify(const QCString & msg, const QByteArray &) |
148 | { | 148 | { |
149 | if (msg == "stabChanged()") | 149 | if (msg == "stabChanged()") |
150 | { | 150 | { |
151 | getStatusPcmcia(); | 151 | getStatusPcmcia(); |
152 | } | 152 | } |
153 | else if (msg == "mtabChanged()") | 153 | else if (msg == "mtabChanged()") |
154 | { | 154 | { |
155 | getStatusSd(); | 155 | getStatusSd(); |
156 | } | 156 | } |
157 | } | 157 | } |
158 | 158 | ||
159 | void Swapfile::getStatusPcmcia() | 159 | void Swapfile::getStatusPcmcia() |
160 | { | 160 | { |
161 | 161 | ||
162 | bool cardWas0 = cardInPcmcia0;// remember last state | 162 | bool cardWas0 = cardInPcmcia0;// remember last state |
163 | bool cardWas1 = cardInPcmcia1; | 163 | bool cardWas1 = cardInPcmcia1; |
164 | 164 | ||
165 | QString fileName; | 165 | QString fileName; |
166 | 166 | ||
167 | // one of these 3 files should exist | 167 | // one of these 3 files should exist |
168 | if (QFile::exists("/var/run/stab")) { | 168 | if (QFile::exists("/var/run/stab")) { |
169 | fileName = "/var/run/stab"; | 169 | fileName = "/var/run/stab"; |
170 | } else if (QFile::exists("/var/state/pcmcia/stab")) { | 170 | } else if (QFile::exists("/var/state/pcmcia/stab")) { |
171 | fileName = "/var/state/pcmcia/stab"; | 171 | fileName = "/var/state/pcmcia/stab"; |
172 | } else { | 172 | } else { |
173 | fileName = "/var/lib/pcmcia/stab"; | 173 | fileName = "/var/lib/pcmcia/stab"; |
174 | } | 174 | } |
175 | 175 | ||
176 | QFile f(fileName); | 176 | QFile f(fileName); |
177 | 177 | ||
178 | if (f.open(IO_ReadOnly)) { | 178 | if (f.open(IO_ReadOnly)) { |
179 | QStringList list; | 179 | QStringList list; |
180 | QTextStream stream(&f); | 180 | QTextStream stream(&f); |
181 | QString streamIn; | 181 | QString streamIn; |
182 | streamIn = stream.read(); | 182 | streamIn = stream.read(); |
183 | list = QStringList::split("\n", streamIn); | 183 | list = QStringList::split("\n", streamIn); |
184 | for (QStringList::Iterator line = list.begin(); line != list.end(); | 184 | for (QStringList::Iterator line = list.begin(); line != list.end(); |
185 | line++) { | 185 | line++) { |
186 | if ((*line).startsWith("Socket 0:")) { | 186 | if ((*line).startsWith("Socket 0:")) { |
187 | if ((*line).startsWith("Socket 0: empty") && cardInPcmcia0) { | 187 | if ((*line).startsWith("Socket 0: empty") && cardInPcmcia0) { |
188 | cardInPcmcia0 = FALSE; | 188 | cardInPcmcia0 = FALSE; |
189 | } else if (!(*line).startsWith("Socket 0: empty") | 189 | } else if (!(*line).startsWith("Socket 0: empty") |
190 | && !cardInPcmcia0) { | 190 | && !cardInPcmcia0) { |
191 | cardInPcmcia0 = TRUE; | 191 | cardInPcmcia0 = TRUE; |
192 | } | 192 | } |
193 | } else if ((*line).startsWith("Socket 1:")) { | 193 | } else if ((*line).startsWith("Socket 1:")) { |
194 | if ((*line).startsWith("Socket 1: empty") && cardInPcmcia1) { | 194 | if ((*line).startsWith("Socket 1: empty") && cardInPcmcia1) { |
195 | cardInPcmcia1 = FALSE; | 195 | cardInPcmcia1 = FALSE; |
196 | } else if (!(*line).startsWith("Socket 1: empty") | 196 | } else if (!(*line).startsWith("Socket 1: empty") |
197 | && !cardInPcmcia1) { | 197 | && !cardInPcmcia1) { |
198 | cardInPcmcia1 = TRUE; | 198 | cardInPcmcia1 = TRUE; |
199 | } | 199 | } |
200 | } | 200 | } |
201 | } | 201 | } |
202 | f.close(); | 202 | f.close(); |
203 | 203 | ||
204 | if (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1) { | 204 | if (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1) { |
205 | QString text = QString::null; | 205 | QString text = QString::null; |
206 | QString what = QString::null; | 206 | QString what = QString::null; |
207 | if (cardWas0 != cardInPcmcia0) { | 207 | if (cardWas0 != cardInPcmcia0) { |
208 | if (cardInPcmcia0) { | 208 | if (cardInPcmcia0) { |
209 | cfRB->setEnabled(TRUE); | 209 | cfRB->setEnabled(TRUE); |
210 | } else { | 210 | } else { |
211 | cfRB->setChecked(FALSE); | 211 | cfRB->setChecked(FALSE); |
212 | cfRB->setEnabled(FALSE); | 212 | cfRB->setEnabled(FALSE); |
213 | } | 213 | } |
214 | } | 214 | } |
215 | 215 | ||
216 | if (cardWas1 != cardInPcmcia1) { | 216 | if (cardWas1 != cardInPcmcia1) { |
217 | if (cardInPcmcia1) { | 217 | if (cardInPcmcia1) { |
218 | cfRB->setEnabled(TRUE); | 218 | cfRB->setEnabled(TRUE); |
219 | } else { | 219 | } else { |
220 | cfRB->setChecked(FALSE); | 220 | cfRB->setChecked(FALSE); |
221 | cfRB->setEnabled(FALSE); | 221 | cfRB->setEnabled(FALSE); |
222 | } | 222 | } |
223 | } | 223 | } |
224 | } | 224 | } |
225 | } else { | 225 | } else { |
226 | // no file found | 226 | // no file found |
227 | odebug << "no file found" << oendl; | 227 | odebug << "no file found" << oendl; |
228 | cardInPcmcia0 = FALSE; | 228 | cardInPcmcia0 = FALSE; |
229 | cardInPcmcia1 = FALSE; | 229 | cardInPcmcia1 = FALSE; |
230 | } | 230 | } |
231 | Swapfile::cfsdchecked(); | 231 | Swapfile::cfsdchecked(); |
232 | } | 232 | } |
233 | 233 | ||
234 | 234 | ||
235 | void Swapfile::getStatusSd() | 235 | void Swapfile::getStatusSd() |
236 | { | 236 | { |
237 | 237 | ||
238 | bool cardWas = cardInSd;// remember last state | 238 | bool cardWas = cardInSd;// remember last state |
239 | cardInSd = FALSE; | 239 | cardInSd = FALSE; |
240 | 240 | ||
241 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 241 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
242 | struct mntent *me; | 242 | struct mntent *me; |
243 | FILE *mntfp = setmntent("/etc/mtab", "r"); | 243 | FILE *mntfp = setmntent("/etc/mtab", "r"); |
244 | 244 | ||
245 | if (mntfp) { | 245 | if (mntfp) { |
246 | while ((me = getmntent(mntfp)) != 0) { | 246 | while ((me = getmntent(mntfp)) != 0) { |
247 | QString fs = me->mnt_fsname; | 247 | QString fs = me->mnt_fsname; |
248 | if (fs.left(14) == "/dev/mmc/part1" || fs.left(7) == "/dev/sd" | 248 | if (fs.left(14) == "/dev/mmc/part1" || fs.left(7) == "/dev/sd" |
249 | || fs.left(9) == "/dev/mmcd") { | 249 | || fs.left(9) == "/dev/mmcd") { |
250 | cardInSd = TRUE; | 250 | cardInSd = TRUE; |
251 | show(); | 251 | show(); |
252 | } | 252 | } |
253 | } | 253 | } |
254 | endmntent(mntfp); | 254 | endmntent(mntfp); |
255 | } | 255 | } |
256 | 256 | ||
257 | if (cardWas != cardInSd) { | 257 | if (cardWas != cardInSd) { |
258 | QString text = QString::null; | 258 | QString text = QString::null; |
259 | QString what = QString::null; | 259 | QString what = QString::null; |
260 | if (cardInSd) { | 260 | if (cardInSd) { |
261 | sdRB->setEnabled(TRUE); | 261 | sdRB->setEnabled(TRUE); |
262 | } else { | 262 | } else { |
263 | sdRB->setChecked(FALSE); | 263 | sdRB->setChecked(FALSE); |
264 | sdRB->setEnabled(FALSE); | 264 | sdRB->setEnabled(FALSE); |
265 | } | 265 | } |
266 | } | 266 | } |
267 | #else | 267 | #else |
268 | #error "Not on Linux" | 268 | #error "Not on Linux" |
269 | #endif | 269 | #endif |
270 | Swapfile::cfsdchecked(); | 270 | Swapfile::cfsdchecked(); |
271 | } | 271 | } |
272 | 272 | ||
273 | int rc=0; | 273 | int rc=0; |
274 | 274 | ||
275 | void Swapfile::swapon() | 275 | void Swapfile::swapon() |
276 | { | 276 | { |
277 | char swapcmd[128] ="swapon "; | 277 | char swapcmd[128] ="swapon "; |
278 | Swapfile::cfsdchecked(); | 278 | Swapfile::cfsdchecked(); |
279 | strcat(swapcmd,swapPath1->text()); | 279 | strcat(swapcmd,swapPath1->text()); |
280 | char *runcmd = swapcmd; | 280 | char *runcmd = swapcmd; |
281 | rc = exec(QString("%1").arg(runcmd)); | 281 | rc = exec(QString("%1").arg(runcmd)); |
282 | if (rc != 0) { | 282 | if (rc != 0) { |
283 | setStatusMessage("Failed to attach swapfile.", true); | 283 | setStatusMessage("Failed to attach swapfile.", true); |
284 | } | 284 | } |
285 | else { | 285 | else { |
286 | /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ | 286 | /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ |
287 | setStatusMessage("Swapfile activated."); | 287 | setStatusMessage("Swapfile activated."); |
288 | } | 288 | } |
289 | Swapfile::status(); | 289 | Swapfile::status(); |
290 | } | 290 | } |
291 | 291 | ||
292 | 292 | ||
293 | void Swapfile::setStatusMessage(const QString& text, bool error /* = false */) | 293 | void Swapfile::setStatusMessage(const QString& text, bool error /* = false */) |
294 | { | 294 | { |
295 | swapStatus->setText("<b>" + text + "</b>"); | 295 | swapStatus->setText("<b>" + text + "</b>"); |
296 | swapStatusIcon->setPixmap(Resource::loadPixmap(error ? "close" : "done")); | 296 | swapStatusIcon->setPixmap(Opie::Core::OResource::loadPixmap(error ? "close" : "done", Opie::Core::OResource::SmallIcon)); |
297 | } | 297 | } |
298 | 298 | ||
299 | 299 | ||
300 | void Swapfile::swapoff() | 300 | void Swapfile::swapoff() |
301 | { | 301 | { |
302 | char swapcmd[128] ="swapoff "; | 302 | char swapcmd[128] ="swapoff "; |
303 | if (Swapfile::cfRB->isChecked() == TRUE) | 303 | if (Swapfile::cfRB->isChecked() == TRUE) |
304 | Swapfile::cfsdchecked(); | 304 | Swapfile::cfsdchecked(); |
305 | strcat(swapcmd,swapPath1->text()); | 305 | strcat(swapcmd,swapPath1->text()); |
306 | char *runcmd = swapcmd; | 306 | char *runcmd = swapcmd; |
307 | rc = exec(QString("%1").arg(runcmd)); | 307 | rc = exec(QString("%1").arg(runcmd)); |
308 | if (rc != 0) { | 308 | if (rc != 0) { |
309 | setStatusMessage(tr("Failed to detach swapfile."), true); | 309 | setStatusMessage(tr("Failed to detach swapfile."), true); |
310 | } | 310 | } |
311 | else { | 311 | else { |
312 | /* QMessageBox::information(this, "Information", "Swapfile is inactive!"); */ | 312 | /* QMessageBox::information(this, "Information", "Swapfile is inactive!"); */ |
313 | setStatusMessage(tr("Swapfile deactivated.")); | 313 | setStatusMessage(tr("Swapfile deactivated.")); |
314 | /* Swapfile::swapPath->clear();*/ | 314 | /* Swapfile::swapPath->clear();*/ |
315 | } | 315 | } |
316 | Swapfile::status(); | 316 | Swapfile::status(); |
317 | } | 317 | } |
318 | 318 | ||
319 | void Swapfile::cfsdchecked() | 319 | void Swapfile::cfsdchecked() |
320 | { | 320 | { |
321 | /* Swapfile::swapPath->clear();*/ | 321 | /* Swapfile::swapPath->clear();*/ |
322 | Swapfile::swapPath1->clear(); | 322 | Swapfile::swapPath1->clear(); |
323 | if (Swapfile::ramRB->isChecked() == TRUE) | 323 | if (Swapfile::ramRB->isChecked() == TRUE) |
324 | { | 324 | { |
325 | Swapfile::swapPath1->insert("/home/swapfile"); | 325 | Swapfile::swapPath1->insert("/home/swapfile"); |
326 | } | 326 | } |
327 | if (Swapfile::sdRB->isChecked() == TRUE) | 327 | if (Swapfile::sdRB->isChecked() == TRUE) |
328 | { | 328 | { |
329 | Swapfile::swapPath1->insert("/mnt/card/swapfile"); | 329 | Swapfile::swapPath1->insert("/mnt/card/swapfile"); |
330 | } | 330 | } |
331 | if (Swapfile::cfRB->isChecked() == TRUE) | 331 | if (Swapfile::cfRB->isChecked() == TRUE) |
332 | { | 332 | { |
333 | Swapfile::swapPath1->insert("/mnt/cf/swapfile"); | 333 | Swapfile::swapPath1->insert("/mnt/cf/swapfile"); |
334 | } | 334 | } |
335 | /*Swapfile::swapPath->insert(Swapfile::swapPath1->text());*/ | 335 | /*Swapfile::swapPath->insert(Swapfile::swapPath1->text());*/ |
336 | } | 336 | } |
337 | 337 | ||
338 | void Swapfile::makeswapfile() | 338 | void Swapfile::makeswapfile() |
339 | { | 339 | { |
340 | int i = swapSize->currentItem(); | 340 | int i = swapSize->currentItem(); |
341 | 341 | ||
342 | mkswapProgress->setProgress(1); | 342 | mkswapProgress->setProgress(1); |
343 | switch ( i ) { | 343 | switch ( i ) { |
344 | case 0: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=2048").arg(swapPath1->text())); | 344 | case 0: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=2048").arg(swapPath1->text())); |
345 | break; | 345 | break; |
346 | case 1: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=4096").arg(swapPath1->text())); | 346 | case 1: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=4096").arg(swapPath1->text())); |
347 | break; | 347 | break; |
348 | case 2: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=6144").arg(swapPath1->text())); | 348 | case 2: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=6144").arg(swapPath1->text())); |
349 | break; | 349 | break; |
350 | case 3: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=8192").arg(swapPath1->text())); | 350 | case 3: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=8192").arg(swapPath1->text())); |
351 | break; | 351 | break; |
352 | case 4: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=16384").arg(swapPath1->text())); | 352 | case 4: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=16384").arg(swapPath1->text())); |
353 | break; | 353 | break; |
354 | case 5: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=32768").arg(swapPath1->text())); | 354 | case 5: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=32768").arg(swapPath1->text())); |
355 | break; | 355 | break; |
356 | case 6: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=65536").arg(swapPath1->text())); | 356 | case 6: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=65536").arg(swapPath1->text())); |
357 | break; | 357 | break; |
358 | 358 | ||
359 | } | 359 | } |
360 | if (rc != 0) { | 360 | if (rc != 0) { |
361 | setStatusMessage(tr("Failed to create swapfile."), true); | 361 | setStatusMessage(tr("Failed to create swapfile."), true); |
362 | } | 362 | } |
363 | 363 | ||
364 | mkswapProgress->setProgress(2); | 364 | mkswapProgress->setProgress(2); |
365 | rc=exec(QString("mkswap %1").arg(swapPath1->text())); | 365 | rc=exec(QString("mkswap %1").arg(swapPath1->text())); |
366 | if (rc != 0) { | 366 | if (rc != 0) { |
367 | setStatusMessage(tr("Failed to initialize swapfile."), true); | 367 | setStatusMessage(tr("Failed to initialize swapfile."), true); |
368 | } | 368 | } |
369 | mkswapProgress->setProgress(3); | 369 | mkswapProgress->setProgress(3); |
370 | mkswapProgress->reset(); | 370 | mkswapProgress->reset(); |
371 | setStatusMessage(tr("Swapfile created.")); | 371 | setStatusMessage(tr("Swapfile created.")); |
372 | } | 372 | } |
373 | 373 | ||
374 | void Swapfile::removeswapfile() | 374 | void Swapfile::removeswapfile() |
375 | { | 375 | { |
376 | exec(QString("swapoff %1").arg(swapPath1->text())); | 376 | exec(QString("swapoff %1").arg(swapPath1->text())); |
377 | rc=exec(QString("rm -rf %1").arg(swapPath1->text())); | 377 | rc=exec(QString("rm -rf %1").arg(swapPath1->text())); |
378 | if (rc != 0) { | 378 | if (rc != 0) { |
379 | setStatusMessage(tr("Failed to remove swapfile."), true); | 379 | setStatusMessage(tr("Failed to remove swapfile."), true); |
380 | } | 380 | } |
381 | Swapfile::status(); | 381 | Swapfile::status(); |
382 | Swapfile::cfsdchecked(); | 382 | Swapfile::cfsdchecked(); |
383 | setStatusMessage(tr("Swapfile removed.")); | 383 | setStatusMessage(tr("Swapfile removed.")); |
384 | } | 384 | } |
385 | 385 | ||
386 | void Swapfile::status() | 386 | void Swapfile::status() |
387 | { | 387 | { |
388 | FILE *fp; | 388 | FILE *fp; |
389 | char buffer[128], swapfile[128], temp[128]; | 389 | char buffer[128], swapfile[128], temp[128]; |
390 | int swapsize=2000, i=1; | 390 | int swapsize=2000, i=1; |
391 | 391 | ||
392 | fp=fopen("/proc/swaps", "r"); | 392 | fp=fopen("/proc/swaps", "r"); |
393 | while ( (fgets(buffer,128,fp)) != NULL ) { | 393 | while ( (fgets(buffer,128,fp)) != NULL ) { |
394 | sscanf(buffer, "%s %s %d %s %s\n", swapfile, temp, &swapsize, temp, temp); | 394 | sscanf(buffer, "%s %s %d %s %s\n", swapfile, temp, &swapsize, temp, temp); |
395 | } | 395 | } |
396 | fclose(fp); | 396 | fclose(fp); |
397 | 397 | ||
398 | ramRB->setChecked(FALSE); | 398 | ramRB->setChecked(FALSE); |
399 | cfRB->setChecked(FALSE); | 399 | cfRB->setChecked(FALSE); |
400 | sdRB->setChecked(FALSE); | 400 | sdRB->setChecked(FALSE); |
401 | 401 | ||
402 | i=strcmp(swapfile, "/home/swapfile"); | 402 | i=strcmp(swapfile, "/home/swapfile"); |
403 | if ( i == 0 ) { | 403 | if ( i == 0 ) { |
404 | ramRB->setChecked(TRUE); | 404 | ramRB->setChecked(TRUE); |
405 | /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ | 405 | /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ |
406 | setStatusMessage(tr("Swapfile activated.")); | 406 | setStatusMessage(tr("Swapfile activated.")); |
407 | } | 407 | } |
408 | i=strcmp(swapfile, "/usr/mnt.rom/cf/swapfile"); | 408 | i=strcmp(swapfile, "/usr/mnt.rom/cf/swapfile"); |
409 | if ( i == 0 ) { | 409 | if ( i == 0 ) { |
410 | cfRB->setChecked(TRUE); | 410 | cfRB->setChecked(TRUE); |
411 | /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ | 411 | /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ |
412 | setStatusMessage(tr("Swapfile activated.")); | 412 | setStatusMessage(tr("Swapfile activated.")); |
413 | } | 413 | } |
414 | i=strcmp(swapfile, "/mnt/cf/swapfile"); | 414 | i=strcmp(swapfile, "/mnt/cf/swapfile"); |
415 | if ( i == 0 ) { | 415 | if ( i == 0 ) { |
416 | cfRB->setChecked(TRUE); | 416 | cfRB->setChecked(TRUE); |
417 | /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ | 417 | /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ |
418 | setStatusMessage(tr("Swapfile activated.")); | 418 | setStatusMessage(tr("Swapfile activated.")); |
419 | } | 419 | } |
420 | i=strcmp(swapfile, "/usr/mnt.rom/card/swapfile"); | 420 | i=strcmp(swapfile, "/usr/mnt.rom/card/swapfile"); |
421 | if ( i == 0 ) { | 421 | if ( i == 0 ) { |
422 | sdRB->setChecked(TRUE); | 422 | sdRB->setChecked(TRUE); |
423 | /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ | 423 | /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ |
424 | setStatusMessage(tr("Swapfile activated.")); | 424 | setStatusMessage(tr("Swapfile activated.")); |
425 | } | 425 | } |
426 | i=strcmp(swapfile, "/mnt/card/swapfile"); | 426 | i=strcmp(swapfile, "/mnt/card/swapfile"); |
427 | if ( i == 0 ) { | 427 | if ( i == 0 ) { |
428 | sdRB->setChecked(TRUE); | 428 | sdRB->setChecked(TRUE); |
429 | /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ | 429 | /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ |
430 | setStatusMessage(tr("Swapfile activated.")); | 430 | setStatusMessage(tr("Swapfile activated.")); |
431 | } | 431 | } |
432 | 432 | ||
433 | Swapfile::cfsdchecked(); | 433 | Swapfile::cfsdchecked(); |
434 | 434 | ||
435 | 435 | ||
436 | swapsize /=1000; | 436 | swapsize /=1000; |
437 | 437 | ||
438 | switch ( swapsize ) { | 438 | switch ( swapsize ) { |
439 | case 2: swapSize->setCurrentItem(0); | 439 | case 2: swapSize->setCurrentItem(0); |
440 | break; | 440 | break; |
441 | case 4: swapSize->setCurrentItem(1); | 441 | case 4: swapSize->setCurrentItem(1); |
442 | break; | 442 | break; |
443 | case 6: swapSize->setCurrentItem(2); | 443 | case 6: swapSize->setCurrentItem(2); |
444 | break; | 444 | break; |
445 | case 8: swapSize->setCurrentItem(3); | 445 | case 8: swapSize->setCurrentItem(3); |
446 | break; | 446 | break; |
447 | case 16: swapSize->setCurrentItem(4); | 447 | case 16: swapSize->setCurrentItem(4); |
448 | break; | 448 | break; |
449 | case 32: swapSize->setCurrentItem(5); | 449 | case 32: swapSize->setCurrentItem(5); |
450 | break; | 450 | break; |
451 | case 64: swapSize->setCurrentItem(6); | 451 | case 64: swapSize->setCurrentItem(6); |
452 | break; | 452 | break; |
453 | } | 453 | } |
454 | 454 | ||
455 | 455 | ||
456 | } | 456 | } |
457 | 457 | ||
458 | 458 | ||