summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/memoryapplet/swapfile.cpp82
1 files changed, 42 insertions, 40 deletions
diff --git a/noncore/applets/memoryapplet/swapfile.cpp b/noncore/applets/memoryapplet/swapfile.cpp
index 7483592..04da8bb 100644
--- a/noncore/applets/memoryapplet/swapfile.cpp
+++ b/noncore/applets/memoryapplet/swapfile.cpp
@@ -17,50 +17,52 @@
** not clear to you.
**
**********************************************************************/
#include "swapfile.h"
+#include <qfile.h>
+#include <qtextstream.h>
#include <qlabel.h>
#include <qtimer.h>
#include <qlayout.h>
#include <qpushbutton.h>
-#include <qhbuttongroup.h>
-#include <qradiobutton.h>
-#include <qlineedit.h>
-#include <qprogressbar.h>
-#include <qcombobox.h>
-#include <qvgroupbox.h>
-#include <qhbox.h>
+#include <qhbuttongroup.h>
+#include <qradiobutton.h>
+#include <qlineedit.h>
+#include <qprogressbar.h>
+#include <qcombobox.h>
+#include <qvgroupbox.h>
+#include <qhbox.h>
#include <qmessagebox.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <qcopchannel_qws.h>
#include <qpe/resource.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/vfs.h>
#include <mntent.h>
-#include <unistd.h>
-#include <sys/types.h>
+#include <unistd.h>
+#include <sys/types.h>
Swapfile::Swapfile( QWidget *parent, const char *name, WFlags f )
: QWidget( parent, name, f )
{
// are we running as root?
isRoot = geteuid() == 0;
QVBoxLayout* vb = new QVBoxLayout(this, 5);
QHButtonGroup* cfsdRBG = new QHButtonGroup(tr("Swapfile location"), this);
cfsdRBG->setRadioButtonExclusive(true);
vb->addWidget(cfsdRBG);
-
+
ramRB = new QRadioButton(tr("RAM"), cfsdRBG);
cfRB = new QRadioButton(tr("CF Card"), cfsdRBG);
sdRB = new QRadioButton(tr("SD Card"), cfsdRBG);
QHBox *hb1 = new QHBox(this);
hb1->setSpacing(5);
@@ -103,18 +105,18 @@ Swapfile::Swapfile( QWidget *parent, const char *name, WFlags f )
connect(ramRB, SIGNAL(clicked()), this, SLOT(cfsdchecked()));
connect(mkSwap, SIGNAL(clicked()), this, SLOT(makeswapfile()));
connect(rmSwap, SIGNAL(clicked()), this, SLOT(removeswapfile()));
cfRB->setEnabled(FALSE);
sdRB->setEnabled(FALSE);
-
+
QCopChannel *pcmciaChannel = new QCopChannel("QPE/Card", this);
connect(pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(cardnotify(const QCString &, const QByteArray &)));
QCopChannel *sdChannel = new QCopChannel("QPE/Card", this);
connect(sdChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(cardnotify(const QCString &, const QByteArray &)));
-
+
cardInPcmcia0 = FALSE;
cardInPcmcia1 = FALSE;
cardInSd = FALSE;
Swapfile::status();
Swapfile::getStatusPcmcia();
@@ -130,17 +132,17 @@ int Swapfile::exec(const QString& arg)
Swapfile::~Swapfile()
{
}
void Swapfile::cardnotify(const QCString & msg, const QByteArray &)
{
- if (msg == "stabChanged()")
+ if (msg == "stabChanged()")
{
getStatusPcmcia();
- }
- else if (msg == "mtabChanged()")
+ }
+ else if (msg == "mtabChanged()")
{
getStatusSd();
}
}
void Swapfile::getStatusPcmcia()
@@ -190,25 +192,25 @@ void Swapfile::getStatusPcmcia()
if (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1) {
QString text = QString::null;
QString what = QString::null;
if (cardWas0 != cardInPcmcia0) {
if (cardInPcmcia0) {
- cfRB->setEnabled(TRUE);
+ cfRB->setEnabled(TRUE);
} else {
cfRB->setChecked(FALSE);
- cfRB->setEnabled(FALSE);
+ cfRB->setEnabled(FALSE);
}
}
if (cardWas1 != cardInPcmcia1) {
if (cardInPcmcia1) {
- cfRB->setEnabled(TRUE);
+ cfRB->setEnabled(TRUE);
} else {
cfRB->setChecked(FALSE);
- cfRB->setEnabled(FALSE);
+ cfRB->setEnabled(FALSE);
}
}
}
} else {
// no file found
qDebug("no file found");
@@ -242,16 +244,16 @@ void Swapfile::getStatusSd()
}
if (cardWas != cardInSd) {
QString text = QString::null;
QString what = QString::null;
if (cardInSd) {
- sdRB->setEnabled(TRUE);
+ sdRB->setEnabled(TRUE);
} else {
sdRB->setChecked(FALSE);
- sdRB->setEnabled(FALSE);
+ sdRB->setEnabled(FALSE);
}
}
#else
#error "Not on Linux"
#endif
Swapfile::cfsdchecked();
@@ -284,13 +286,13 @@ void Swapfile::setStatusMessage(const QString& text, bool error /* = false */)
}
void Swapfile::swapoff()
{
char swapcmd[128] ="swapoff ";
- if (Swapfile::cfRB->isChecked() == TRUE)
+ if (Swapfile::cfRB->isChecked() == TRUE)
Swapfile::cfsdchecked();
strcat(swapcmd,swapPath1->text());
char *runcmd = swapcmd;
rc = exec(QString("%1").arg(runcmd));
if (rc != 0) {
setStatusMessage(tr("Failed to detach swapfile."), true);
@@ -304,13 +306,13 @@ void Swapfile::swapoff()
}
void Swapfile::cfsdchecked()
{
/* Swapfile::swapPath->clear();*/
Swapfile::swapPath1->clear();
- if (Swapfile::ramRB->isChecked() == TRUE)
+ if (Swapfile::ramRB->isChecked() == TRUE)
{
Swapfile::swapPath1->insert("/home/swapfile");
}
if (Swapfile::sdRB->isChecked() == TRUE)
{
Swapfile::swapPath1->insert("/mnt/card/swapfile");
@@ -320,39 +322,39 @@ void Swapfile::cfsdchecked()
Swapfile::swapPath1->insert("/mnt/cf/swapfile");
}
/* Swapfile::swapPath->insert(Swapfile::swapPath1->text());*/
}
void Swapfile::makeswapfile()
-{
+{
int i = swapSize->currentItem();
- mkswapProgress->setProgress(1);
+ mkswapProgress->setProgress(1);
switch ( i ) {
case 0: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=2048").arg(swapPath1->text()));
break;
case 1: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=4096").arg(swapPath1->text()));
break;
case 2: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=6144").arg(swapPath1->text()));
break;
case 3: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=8192").arg(swapPath1->text()));
break;
- }
+ }
if (rc != 0) {
setStatusMessage(tr("Failed to create swapfile."), true);
}
- mkswapProgress->setProgress(2);
+ mkswapProgress->setProgress(2);
rc=exec(QString("mkswap %1").arg(swapPath1->text()));
if (rc != 0) {
setStatusMessage(tr("Failed to initialize swapfile."), true);
}
- mkswapProgress->setProgress(3);
- mkswapProgress->reset();
+ mkswapProgress->setProgress(3);
+ mkswapProgress->reset();
setStatusMessage(tr("Swapfile created."));
-}
+}
void Swapfile::removeswapfile()
{
exec(QString("swapoff %1").arg(swapPath1->text()));
rc=exec(QString("rm -rf %1").arg(swapPath1->text()));
if (rc != 0) {
@@ -371,62 +373,62 @@ void Swapfile::status()
fp=fopen("/proc/swaps", "r");
while ( (fgets(buffer,128,fp)) != NULL ) {
sscanf(buffer, "%s %s %d %s %s\n", swapfile, temp, &swapsize, temp, temp);
}
fclose(fp);
-
+
ramRB->setChecked(FALSE);
cfRB->setChecked(FALSE);
sdRB->setChecked(FALSE);
i=strcmp(swapfile, "/home/swapfile");
if ( i == 0 ) {
- ramRB->setChecked(TRUE);
+ ramRB->setChecked(TRUE);
/* QMessageBox::information(this, "Information", "Swapfile is active!"); */
setStatusMessage(tr("Swapfile activated."));
}
i=strcmp(swapfile, "/usr/mnt.rom/cf/swapfile");
if ( i == 0 ) {
- cfRB->setChecked(TRUE);
+ cfRB->setChecked(TRUE);
/* QMessageBox::information(this, "Information", "Swapfile is active!"); */
setStatusMessage(tr("Swapfile activated."));
}
i=strcmp(swapfile, "/mnt/cf/swapfile");
if ( i == 0 ) {
- cfRB->setChecked(TRUE);
+ cfRB->setChecked(TRUE);
/* QMessageBox::information(this, "Information", "Swapfile is active!"); */
setStatusMessage(tr("Swapfile activated."));
}
i=strcmp(swapfile, "/usr/mnt.rom/card/swapfile");
if ( i == 0 ) {
- sdRB->setChecked(TRUE);
+ sdRB->setChecked(TRUE);
/* QMessageBox::information(this, "Information", "Swapfile is active!"); */
setStatusMessage(tr("Swapfile activated."));
}
i=strcmp(swapfile, "/mnt/card/swapfile");
if ( i == 0 ) {
- sdRB->setChecked(TRUE);
+ sdRB->setChecked(TRUE);
/* QMessageBox::information(this, "Information", "Swapfile is active!"); */
setStatusMessage(tr("Swapfile activated."));
}
Swapfile::cfsdchecked();
-
-
+
+
swapsize /=1000;
switch ( swapsize ) {
case 2: swapSize->setCurrentItem(0);
break;
case 4: swapSize->setCurrentItem(1);
break;
case 6: swapSize->setCurrentItem(2);
break;
case 8: swapSize->setCurrentItem(3);
break;
- }
-
+ }
+
}