summaryrefslogtreecommitdiff
path: root/noncore/applets/memoryapplet/swapfile.cpp
Unidiff
Diffstat (limited to 'noncore/applets/memoryapplet/swapfile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/memoryapplet/swapfile.cpp4
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
@@ -17,195 +17,195 @@
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
51Swapfile::Swapfile( QWidget *parent, const char *name, WFlags f ) 51Swapfile::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
126int Swapfile::exec(const QString& arg) 126int 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
132Swapfile::~Swapfile() 132Swapfile::~Swapfile()
133{ 133{
134} 134}
135 135
136void Swapfile::cardnotify(const QCString & msg, const QByteArray &) 136void 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
148void Swapfile::getStatusPcmcia() 148void 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 }