author | alwin <alwin> | 2004-03-02 12:21:11 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-03-02 12:21:11 (UTC) |
commit | b6b1c97559c0ed9f2e33632272426bf98f289232 (patch) (unidiff) | |
tree | d3a9987704770cdf5eb14e1136f6e3ecb2f36a04 /noncore/applets/memoryapplet/swapfile.cpp | |
parent | 0d59c780513da78033f4d9040475dee9db0256d4 (diff) | |
download | opie-b6b1c97559c0ed9f2e33632272426bf98f289232.zip opie-b6b1c97559c0ed9f2e33632272426bf98f289232.tar.gz opie-b6b1c97559c0ed9f2e33632272426bf98f289232.tar.bz2 |
applied the patch generated by the optimize_connect script from
TT.
Diffstat (limited to 'noncore/applets/memoryapplet/swapfile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/applets/memoryapplet/swapfile.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/applets/memoryapplet/swapfile.cpp b/noncore/applets/memoryapplet/swapfile.cpp index 04da8bb..9416db3 100644 --- a/noncore/applets/memoryapplet/swapfile.cpp +++ b/noncore/applets/memoryapplet/swapfile.cpp | |||
@@ -1,307 +1,307 @@ | |||
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 | #include <qfile.h> | 23 | #include <qfile.h> |
24 | #include <qtextstream.h> | 24 | #include <qtextstream.h> |
25 | #include <qlabel.h> | 25 | #include <qlabel.h> |
26 | #include <qtimer.h> | 26 | #include <qtimer.h> |
27 | #include <qlayout.h> | 27 | #include <qlayout.h> |
28 | #include <qpushbutton.h> | 28 | #include <qpushbutton.h> |
29 | #include <qhbuttongroup.h> | 29 | #include <qhbuttongroup.h> |
30 | #include <qradiobutton.h> | 30 | #include <qradiobutton.h> |
31 | #include <qlineedit.h> | 31 | #include <qlineedit.h> |
32 | #include <qprogressbar.h> | 32 | #include <qprogressbar.h> |
33 | #include <qcombobox.h> | 33 | #include <qcombobox.h> |
34 | #include <qvgroupbox.h> | 34 | #include <qvgroupbox.h> |
35 | #include <qhbox.h> | 35 | #include <qhbox.h> |
36 | #include <qmessagebox.h> | 36 | #include <qmessagebox.h> |
37 | #include <stdio.h> | 37 | #include <stdio.h> |
38 | #include <stdlib.h> | 38 | #include <stdlib.h> |
39 | #include <string.h> | 39 | #include <string.h> |
40 | 40 | ||
41 | #include <qcopchannel_qws.h> | 41 | #include <qcopchannel_qws.h> |
42 | #include <qpe/resource.h> | 42 | #include <qpe/resource.h> |
43 | 43 | ||
44 | #include <unistd.h> | 44 | #include <unistd.h> |
45 | #include <fcntl.h> | 45 | #include <fcntl.h> |
46 | #include <sys/vfs.h> | 46 | #include <sys/vfs.h> |
47 | #include <mntent.h> | 47 | #include <mntent.h> |
48 | #include <unistd.h> | 48 | #include <unistd.h> |
49 | #include <sys/types.h> | 49 | #include <sys/types.h> |
50 | 50 | ||
51 | Swapfile::Swapfile( QWidget *parent, const char *name, WFlags f ) | 51 | Swapfile::Swapfile( QWidget *parent, const char *name, WFlags f ) |
52 | : QWidget( parent, name, f ) | 52 | : QWidget( parent, name, f ) |
53 | { | 53 | { |
54 | // are we running as root? | 54 | // are we running as root? |
55 | isRoot = geteuid() == 0; | 55 | isRoot = geteuid() == 0; |
56 | 56 | ||
57 | QVBoxLayout* vb = new QVBoxLayout(this, 5); | 57 | QVBoxLayout* vb = new QVBoxLayout(this, 5); |
58 | 58 | ||
59 | QHButtonGroup* cfsdRBG = new QHButtonGroup(tr("Swapfile location"), this); | 59 | QHButtonGroup* cfsdRBG = new QHButtonGroup(tr("Swapfile location"), this); |
60 | cfsdRBG->setRadioButtonExclusive(true); | 60 | cfsdRBG->setRadioButtonExclusive(true); |
61 | vb->addWidget(cfsdRBG); | 61 | vb->addWidget(cfsdRBG); |
62 | 62 | ||
63 | ramRB = new QRadioButton(tr("RAM"), cfsdRBG); | 63 | ramRB = new QRadioButton(tr("RAM"), cfsdRBG); |
64 | cfRB = new QRadioButton(tr("CF Card"), cfsdRBG); | 64 | cfRB = new QRadioButton(tr("CF Card"), cfsdRBG); |
65 | sdRB = new QRadioButton(tr("SD Card"), cfsdRBG); | 65 | sdRB = new QRadioButton(tr("SD Card"), cfsdRBG); |
66 | 66 | ||
67 | QHBox *hb1 = new QHBox(this); | 67 | QHBox *hb1 = new QHBox(this); |
68 | hb1->setSpacing(5); | 68 | hb1->setSpacing(5); |
69 | 69 | ||
70 | swapPath1 = new QLineEdit(hb1); | 70 | swapPath1 = new QLineEdit(hb1); |
71 | swapPath1->setEnabled(false); | 71 | swapPath1->setEnabled(false); |
72 | 72 | ||
73 | QPushButton* swapOn = new QPushButton(tr(" On "), hb1); | 73 | QPushButton* swapOn = new QPushButton(tr(" On "), hb1); |
74 | QPushButton* swapOff = new QPushButton(tr(" Off "), hb1); | 74 | QPushButton* swapOff = new QPushButton(tr(" Off "), hb1); |
75 | vb->addWidget(hb1); | 75 | vb->addWidget(hb1); |
76 | 76 | ||
77 | QVGroupBox* box1 = new QVGroupBox(tr("Manage Swapfile"), this); | 77 | QVGroupBox* box1 = new QVGroupBox(tr("Manage Swapfile"), this); |
78 | vb->addWidget(box1); | 78 | vb->addWidget(box1); |
79 | 79 | ||
80 | QHBox *hb2 = new QHBox(box1); | 80 | QHBox *hb2 = new QHBox(box1); |
81 | hb2->setSpacing(5); | 81 | hb2->setSpacing(5); |
82 | QPushButton* mkSwap = new QPushButton(tr("Generate"), hb2); | 82 | QPushButton* mkSwap = new QPushButton(tr("Generate"), hb2); |
83 | QPushButton* rmSwap = new QPushButton(tr("Remove"), hb2); | 83 | QPushButton* rmSwap = new QPushButton(tr("Remove"), hb2); |
84 | 84 | ||
85 | QHBox *hb3 = new QHBox(box1); | 85 | QHBox *hb3 = new QHBox(box1); |
86 | hb3->setSpacing(5); | 86 | hb3->setSpacing(5); |
87 | swapSize = new QComboBox(hb3); | 87 | swapSize = new QComboBox(hb3); |
88 | swapSize->insertStringList(QStringList::split(",", tr("2 Mb,4 Mb,6 Mb,8 Mb"))); | 88 | swapSize->insertStringList(QStringList::split(",", tr("2 Mb,4 Mb,6 Mb,8 Mb"))); |
89 | 89 | ||
90 | mkswapProgress = new QProgressBar(3, hb3); | 90 | mkswapProgress = new QProgressBar(3, hb3); |
91 | mkswapProgress->setCenterIndicator(true); | 91 | mkswapProgress->setCenterIndicator(true); |
92 | 92 | ||
93 | QHBox *hb4 = new QHBox(this); | 93 | QHBox *hb4 = new QHBox(this); |
94 | hb4->setSpacing(5); | 94 | hb4->setSpacing(5); |
95 | 95 | ||
96 | swapStatusIcon = new QLabel(hb4); | 96 | swapStatusIcon = new QLabel(hb4); |
97 | swapStatus = new QLabel(tr(""), hb4); | 97 | swapStatus = new QLabel(tr(""), hb4); |
98 | hb4->setStretchFactor(swapStatus, 99); | 98 | hb4->setStretchFactor(swapStatus, 99); |
99 | vb->addWidget(hb4); | 99 | vb->addWidget(hb4); |
100 | 100 | ||
101 | connect(swapOn, SIGNAL(clicked()), this, SLOT(swapon())); | 101 | connect(swapOn, SIGNAL(clicked()), this, SLOT(swapon())); |
102 | connect(swapOff, SIGNAL(clicked()), this, SLOT(swapoff())); | 102 | connect(swapOff, SIGNAL(clicked()), this, SLOT(swapoff())); |
103 | connect(cfRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); | 103 | connect(cfRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); |
104 | connect(sdRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); | 104 | connect(sdRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); |
105 | connect(ramRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); | 105 | connect(ramRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); |
106 | connect(mkSwap, SIGNAL(clicked()), this, SLOT(makeswapfile())); | 106 | connect(mkSwap, SIGNAL(clicked()), this, SLOT(makeswapfile())); |
107 | connect(rmSwap, SIGNAL(clicked()), this, SLOT(removeswapfile())); | 107 | connect(rmSwap, SIGNAL(clicked()), this, SLOT(removeswapfile())); |
108 | 108 | ||
109 | cfRB->setEnabled(FALSE); | 109 | cfRB->setEnabled(FALSE); |
110 | sdRB->setEnabled(FALSE); | 110 | sdRB->setEnabled(FALSE); |
111 | 111 | ||
112 | QCopChannel *pcmciaChannel = new QCopChannel("QPE/Card", this); | 112 | QCopChannel *pcmciaChannel = new QCopChannel("QPE/Card", this); |
113 | connect(pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(cardnotify(const QCString &, const QByteArray &))); | 113 | connect(pcmciaChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(cardnotify(const QCString&,const QByteArray&))); |
114 | QCopChannel *sdChannel = new QCopChannel("QPE/Card", this); | 114 | QCopChannel *sdChannel = new QCopChannel("QPE/Card", this); |
115 | connect(sdChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(cardnotify(const QCString &, const QByteArray &))); | 115 | connect(sdChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(cardnotify(const QCString&,const QByteArray&))); |
116 | 116 | ||
117 | cardInPcmcia0 = FALSE; | 117 | cardInPcmcia0 = FALSE; |
118 | cardInPcmcia1 = FALSE; | 118 | cardInPcmcia1 = FALSE; |
119 | cardInSd = FALSE; | 119 | cardInSd = FALSE; |
120 | 120 | ||
121 | Swapfile::status(); | 121 | Swapfile::status(); |
122 | Swapfile::getStatusPcmcia(); | 122 | Swapfile::getStatusPcmcia(); |
123 | Swapfile::getStatusSd(); | 123 | Swapfile::getStatusSd(); |
124 | } | 124 | } |
125 | 125 | ||
126 | int Swapfile::exec(const QString& arg) | 126 | int Swapfile::exec(const QString& arg) |
127 | { | 127 | { |
128 | return system((!isRoot ? "sudo " : "") + arg); | 128 | return system((!isRoot ? "sudo " : "") + arg); |
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | ||
132 | Swapfile::~Swapfile() | 132 | Swapfile::~Swapfile() |
133 | { | 133 | { |
134 | } | 134 | } |
135 | 135 | ||
136 | void Swapfile::cardnotify(const QCString & msg, const QByteArray &) | 136 | void Swapfile::cardnotify(const QCString & msg, const QByteArray &) |
137 | { | 137 | { |
138 | if (msg == "stabChanged()") | 138 | if (msg == "stabChanged()") |
139 | { | 139 | { |
140 | getStatusPcmcia(); | 140 | getStatusPcmcia(); |
141 | } | 141 | } |
142 | else if (msg == "mtabChanged()") | 142 | else if (msg == "mtabChanged()") |
143 | { | 143 | { |
144 | getStatusSd(); | 144 | getStatusSd(); |
145 | } | 145 | } |
146 | } | 146 | } |
147 | 147 | ||
148 | void Swapfile::getStatusPcmcia() | 148 | void Swapfile::getStatusPcmcia() |
149 | { | 149 | { |
150 | 150 | ||
151 | bool cardWas0 = cardInPcmcia0;// remember last state | 151 | bool cardWas0 = cardInPcmcia0;// remember last state |
152 | bool cardWas1 = cardInPcmcia1; | 152 | bool cardWas1 = cardInPcmcia1; |
153 | 153 | ||
154 | QString fileName; | 154 | QString fileName; |
155 | 155 | ||
156 | // one of these 3 files should exist | 156 | // one of these 3 files should exist |
157 | if (QFile::exists("/var/run/stab")) { | 157 | if (QFile::exists("/var/run/stab")) { |
158 | fileName = "/var/run/stab"; | 158 | fileName = "/var/run/stab"; |
159 | } else if (QFile::exists("/var/state/pcmcia/stab")) { | 159 | } else if (QFile::exists("/var/state/pcmcia/stab")) { |
160 | fileName = "/var/state/pcmcia/stab"; | 160 | fileName = "/var/state/pcmcia/stab"; |
161 | } else { | 161 | } else { |
162 | fileName = "/var/lib/pcmcia/stab"; | 162 | fileName = "/var/lib/pcmcia/stab"; |
163 | } | 163 | } |
164 | 164 | ||
165 | QFile f(fileName); | 165 | QFile f(fileName); |
166 | 166 | ||
167 | if (f.open(IO_ReadOnly)) { | 167 | if (f.open(IO_ReadOnly)) { |
168 | QStringList list; | 168 | QStringList list; |
169 | QTextStream stream(&f); | 169 | QTextStream stream(&f); |
170 | QString streamIn; | 170 | QString streamIn; |
171 | streamIn = stream.read(); | 171 | streamIn = stream.read(); |
172 | list = QStringList::split("\n", streamIn); | 172 | list = QStringList::split("\n", streamIn); |
173 | for (QStringList::Iterator line = list.begin(); line != list.end(); | 173 | for (QStringList::Iterator line = list.begin(); line != list.end(); |
174 | line++) { | 174 | line++) { |
175 | if ((*line).startsWith("Socket 0:")) { | 175 | if ((*line).startsWith("Socket 0:")) { |
176 | if ((*line).startsWith("Socket 0: empty") && cardInPcmcia0) { | 176 | if ((*line).startsWith("Socket 0: empty") && cardInPcmcia0) { |
177 | cardInPcmcia0 = FALSE; | 177 | cardInPcmcia0 = FALSE; |
178 | } else if (!(*line).startsWith("Socket 0: empty") | 178 | } else if (!(*line).startsWith("Socket 0: empty") |
179 | && !cardInPcmcia0) { | 179 | && !cardInPcmcia0) { |
180 | cardInPcmcia0 = TRUE; | 180 | cardInPcmcia0 = TRUE; |
181 | } | 181 | } |
182 | } else if ((*line).startsWith("Socket 1:")) { | 182 | } else if ((*line).startsWith("Socket 1:")) { |
183 | if ((*line).startsWith("Socket 1: empty") && cardInPcmcia1) { | 183 | if ((*line).startsWith("Socket 1: empty") && cardInPcmcia1) { |
184 | cardInPcmcia1 = FALSE; | 184 | cardInPcmcia1 = FALSE; |
185 | } else if (!(*line).startsWith("Socket 1: empty") | 185 | } else if (!(*line).startsWith("Socket 1: empty") |
186 | && !cardInPcmcia1) { | 186 | && !cardInPcmcia1) { |
187 | cardInPcmcia1 = TRUE; | 187 | cardInPcmcia1 = TRUE; |
188 | } | 188 | } |
189 | } | 189 | } |
190 | } | 190 | } |
191 | f.close(); | 191 | f.close(); |
192 | 192 | ||
193 | if (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1) { | 193 | if (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1) { |
194 | QString text = QString::null; | 194 | QString text = QString::null; |
195 | QString what = QString::null; | 195 | QString what = QString::null; |
196 | if (cardWas0 != cardInPcmcia0) { | 196 | if (cardWas0 != cardInPcmcia0) { |
197 | if (cardInPcmcia0) { | 197 | if (cardInPcmcia0) { |
198 | cfRB->setEnabled(TRUE); | 198 | cfRB->setEnabled(TRUE); |
199 | } else { | 199 | } else { |
200 | cfRB->setChecked(FALSE); | 200 | cfRB->setChecked(FALSE); |
201 | cfRB->setEnabled(FALSE); | 201 | cfRB->setEnabled(FALSE); |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | if (cardWas1 != cardInPcmcia1) { | 205 | if (cardWas1 != cardInPcmcia1) { |
206 | if (cardInPcmcia1) { | 206 | if (cardInPcmcia1) { |
207 | cfRB->setEnabled(TRUE); | 207 | cfRB->setEnabled(TRUE); |
208 | } else { | 208 | } else { |
209 | cfRB->setChecked(FALSE); | 209 | cfRB->setChecked(FALSE); |
210 | cfRB->setEnabled(FALSE); | 210 | cfRB->setEnabled(FALSE); |
211 | } | 211 | } |
212 | } | 212 | } |
213 | } | 213 | } |
214 | } else { | 214 | } else { |
215 | // no file found | 215 | // no file found |
216 | qDebug("no file found"); | 216 | qDebug("no file found"); |
217 | cardInPcmcia0 = FALSE; | 217 | cardInPcmcia0 = FALSE; |
218 | cardInPcmcia1 = FALSE; | 218 | cardInPcmcia1 = FALSE; |
219 | } | 219 | } |
220 | Swapfile::cfsdchecked(); | 220 | Swapfile::cfsdchecked(); |
221 | } | 221 | } |
222 | 222 | ||
223 | 223 | ||
224 | void Swapfile::getStatusSd() | 224 | void Swapfile::getStatusSd() |
225 | { | 225 | { |
226 | 226 | ||
227 | bool cardWas = cardInSd;// remember last state | 227 | bool cardWas = cardInSd;// remember last state |
228 | cardInSd = FALSE; | 228 | cardInSd = FALSE; |
229 | 229 | ||
230 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 230 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
231 | struct mntent *me; | 231 | struct mntent *me; |
232 | FILE *mntfp = setmntent("/etc/mtab", "r"); | 232 | FILE *mntfp = setmntent("/etc/mtab", "r"); |
233 | 233 | ||
234 | if (mntfp) { | 234 | if (mntfp) { |
235 | while ((me = getmntent(mntfp)) != 0) { | 235 | while ((me = getmntent(mntfp)) != 0) { |
236 | QString fs = me->mnt_fsname; | 236 | QString fs = me->mnt_fsname; |
237 | if (fs.left(14) == "/dev/mmc/part1" || fs.left(7) == "/dev/sd" | 237 | if (fs.left(14) == "/dev/mmc/part1" || fs.left(7) == "/dev/sd" |
238 | || fs.left(9) == "/dev/mmcd") { | 238 | || fs.left(9) == "/dev/mmcd") { |
239 | cardInSd = TRUE; | 239 | cardInSd = TRUE; |
240 | show(); | 240 | show(); |
241 | } | 241 | } |
242 | } | 242 | } |
243 | endmntent(mntfp); | 243 | endmntent(mntfp); |
244 | } | 244 | } |
245 | 245 | ||
246 | if (cardWas != cardInSd) { | 246 | if (cardWas != cardInSd) { |
247 | QString text = QString::null; | 247 | QString text = QString::null; |
248 | QString what = QString::null; | 248 | QString what = QString::null; |
249 | if (cardInSd) { | 249 | if (cardInSd) { |
250 | sdRB->setEnabled(TRUE); | 250 | sdRB->setEnabled(TRUE); |
251 | } else { | 251 | } else { |
252 | sdRB->setChecked(FALSE); | 252 | sdRB->setChecked(FALSE); |
253 | sdRB->setEnabled(FALSE); | 253 | sdRB->setEnabled(FALSE); |
254 | } | 254 | } |
255 | } | 255 | } |
256 | #else | 256 | #else |
257 | #error "Not on Linux" | 257 | #error "Not on Linux" |
258 | #endif | 258 | #endif |
259 | Swapfile::cfsdchecked(); | 259 | Swapfile::cfsdchecked(); |
260 | } | 260 | } |
261 | 261 | ||
262 | int rc=0; | 262 | int rc=0; |
263 | 263 | ||
264 | void Swapfile::swapon() | 264 | void Swapfile::swapon() |
265 | { | 265 | { |
266 | char swapcmd[128] ="swapon "; | 266 | char swapcmd[128] ="swapon "; |
267 | Swapfile::cfsdchecked(); | 267 | Swapfile::cfsdchecked(); |
268 | strcat(swapcmd,swapPath1->text()); | 268 | strcat(swapcmd,swapPath1->text()); |
269 | char *runcmd = swapcmd; | 269 | char *runcmd = swapcmd; |
270 | rc = exec(QString("%1").arg(runcmd)); | 270 | rc = exec(QString("%1").arg(runcmd)); |
271 | if (rc != 0) { | 271 | if (rc != 0) { |
272 | setStatusMessage("Failed to attach swapfile.", true); | 272 | setStatusMessage("Failed to attach swapfile.", true); |
273 | } | 273 | } |
274 | else { | 274 | else { |
275 | /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ | 275 | /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ |
276 | setStatusMessage("Swapfile activated."); | 276 | setStatusMessage("Swapfile activated."); |
277 | } | 277 | } |
278 | Swapfile::status(); | 278 | Swapfile::status(); |
279 | } | 279 | } |
280 | 280 | ||
281 | 281 | ||
282 | void Swapfile::setStatusMessage(const QString& text, bool error /* = false */) | 282 | void Swapfile::setStatusMessage(const QString& text, bool error /* = false */) |
283 | { | 283 | { |
284 | swapStatus->setText("<b>" + text + "</b>"); | 284 | swapStatus->setText("<b>" + text + "</b>"); |
285 | swapStatusIcon->setPixmap(Resource::loadPixmap(error ? "close" : "done")); | 285 | swapStatusIcon->setPixmap(Resource::loadPixmap(error ? "close" : "done")); |
286 | } | 286 | } |
287 | 287 | ||
288 | 288 | ||
289 | void Swapfile::swapoff() | 289 | void Swapfile::swapoff() |
290 | { | 290 | { |
291 | char swapcmd[128] ="swapoff "; | 291 | char swapcmd[128] ="swapoff "; |
292 | if (Swapfile::cfRB->isChecked() == TRUE) | 292 | if (Swapfile::cfRB->isChecked() == TRUE) |
293 | Swapfile::cfsdchecked(); | 293 | Swapfile::cfsdchecked(); |
294 | strcat(swapcmd,swapPath1->text()); | 294 | strcat(swapcmd,swapPath1->text()); |
295 | char *runcmd = swapcmd; | 295 | char *runcmd = swapcmd; |
296 | rc = exec(QString("%1").arg(runcmd)); | 296 | rc = exec(QString("%1").arg(runcmd)); |
297 | if (rc != 0) { | 297 | if (rc != 0) { |
298 | setStatusMessage(tr("Failed to detach swapfile."), true); | 298 | setStatusMessage(tr("Failed to detach swapfile."), true); |
299 | } | 299 | } |
300 | else { | 300 | else { |
301 | /* QMessageBox::information(this, "Information", "Swapfile is inactive!"); */ | 301 | /* QMessageBox::information(this, "Information", "Swapfile is inactive!"); */ |
302 | setStatusMessage(tr("Swapfile deactivated.")); | 302 | setStatusMessage(tr("Swapfile deactivated.")); |
303 | /* Swapfile::swapPath->clear();*/ | 303 | /* Swapfile::swapPath->clear();*/ |
304 | } | 304 | } |
305 | Swapfile::status(); | 305 | Swapfile::status(); |
306 | } | 306 | } |
307 | 307 | ||