29 #include <QtCore/QTextStream>
30 #include <QtCore/QFile>
35 #include <kconfiggroup.h>
40 static const QLatin1Char
Blank = QLatin1Char(
' ' );
41 static const QLatin1Char
Delimiter = QLatin1Char(
'#' );
47 :
QObject(parent), dfProc(new KProcess(this))
51 updatesDisabled =
false;
55 kDebug() <<
"df gives no FS_TYPE" ;
61 dfProc->setOutputChannelMode(KProcess::MergedChannels);
62 connect(dfProc,SIGNAL(finished(
int,QProcess::ExitStatus)),
63 this, SLOT(dfDone()) );
65 readingDFStdErrOut=
false;
66 config = KGlobal::config();
77 if( dfProc->state() == QProcess::Running )
80 dfProc->waitForFinished();
104 updatesDisabled = disable;
114 KConfigGroup group(config,
"DiskList");
119 for (; itr != end; ++itr)
143 const KConfigGroup group(config,
"DiskList");
148 for (; itr != end; ++itr)
159 QString icon=group.readPathEntry(key, QString());
168 for (
int i = 0; i < s.length(); i++)
170 if (s[i] == QLatin1Char(
'\\' ))
174 if( str == QLatin1Char(
'\\' ))
175 rc += QLatin1Char(
'\\' );
176 else if( str == QLatin1Char(
'0' ))
178 rc += QLatin1Char( s.mid(i,3).toULongLong(0, 8) );
185 rc += QLatin1Char(
'\\' );
204 if (readingDFStdErrOut || (dfProc->state() != QProcess::NotRunning))
208 if ( f.open(QIODevice::ReadOnly) )
221 if ( (!s.isEmpty() ) && (s.indexOf(
Delimiter)!=0) )
224 kDebug() <<
"GOT: [" << s <<
"]" ;
227 QFile path(QLatin1String(
"/dev/disk/by-uuid/" ));
230 if ( s.contains(QLatin1String(
"UUID=" )) )
234 QRegExp uuid( QLatin1String(
"UUID=(\\S+)(\\s+)" ));
236 if (uuid.indexIn(s) != -1)
238 extracted = uuid.cap(1);
241 if (! extracted.isEmpty() )
243 QString device = path.fileName() + extracted;
248 QString filesym = file.symLinkTarget();
253 kDebug() <<
"The device does not seems to exist" ;
259 kDebug() <<
"Invalid UUID" ;
265 kDebug() <<
"UUID OK but there is no /dev/disk/by-uuid/" ;
274 s=s.remove(0,s.indexOf(
Blank)+1 );
278 s=s.remove(0,s.indexOf(
Blank)+1 );
281 s=s.remove(0,s.indexOf(
Blank)+1 );
285 s=s.remove(0,s.indexOf(
Blank)+1 );
288 s=s.remove(0,s.indexOf(
Blank)+1 );
291 if ( (disk->
deviceName() != QLatin1String(
"none" ))
292 && (disk->
fsType() != QLatin1String(
"swap" ))
293 && (disk->
fsType() != QLatin1String(
"sysfs" ))
294 && (disk->
fsType() != QLatin1String(
"rootfs" ))
295 && (disk->
fsType() != QLatin1String(
"tmpfs" ))
296 && (disk->
fsType() != QLatin1String(
"debugfs" ))
297 && (disk->
fsType() != QLatin1String(
"devtmpfs" ))
298 && (disk->
mountPoint() != QLatin1String(
"/dev/swap" ))
299 && (disk->
mountPoint() != QLatin1String(
"/dev/pts" ))
300 && (disk->
mountPoint() != QLatin1String(
"/dev/shm" ))
301 && (!disk->
mountPoint().startsWith(QLatin1String(
"/sys/" )) )
302 && (!disk->
mountPoint().startsWith(QLatin1String(
"/proc/" )) ) )
304 replaceDeviceEntry(disk);
330 if (readingDFStdErrOut || (dfProc->state() != QProcess::NotRunning))
333 dfProc->clearProgram();
336 dfenv << QLatin1String(
"LANG=en_US" );
337 dfenv << QLatin1String(
"LC_ALL=en_US" );
338 dfenv << QLatin1String(
"LC_MESSAGES=en_US" );
339 dfenv << QLatin1String(
"LC_TYPE=en_US" );
340 dfenv << QLatin1String(
"LANGUAGE=en_US" );
341 dfenv << QLatin1String(
"LC_ALL=POSIX" );
342 dfProc->setEnvironment(dfenv);
346 if (!dfProc->waitForStarted(-1))
347 qFatal(
"%s", qPrintable(i18n(
"could not execute [%1]", QLatin1String(
DF_Command))));
356 void DiskList::dfDone()
363 readingDFStdErrOut=
true;
367 for (; itr != end; ++itr)
373 QString dfStringErrOut = QString::fromLatin1(dfProc->readAllStandardOutput());
374 QTextStream t (&dfStringErrOut, QIODevice::ReadOnly);
376 kDebug() << t.status();
382 if ( s.left(10) == QLatin1String(
"Filesystem" ) )
386 qFatal(
"Error running df command... got [%s]",qPrintable(s));
398 if (!s.contains(
Blank))
410 s=s.remove(0,s.indexOf(
Blank)+1 );
421 s=s.remove(0,s.indexOf(
Blank)+1 );
426 u=s.left(s.indexOf(
Blank));
428 s=s.remove(0,s.indexOf(
Blank)+1 );
431 u=s.left(s.indexOf(
Blank));
433 s=s.remove(0,s.indexOf(
Blank)+1 );
436 u=s.left(s.indexOf(
Blank));
438 s=s.remove(0,s.indexOf(
Blank)+1 );
442 s=s.remove(0,s.indexOf(
Blank)+1 );
447 && (disk->
deviceName() != QLatin1String(
"none" ))
448 && (disk->
fsType() != QLatin1String(
"swap" ))
449 && (disk->
fsType() != QLatin1String(
"sysfs" ))
450 && (disk->
fsType() != QLatin1String(
"rootfs" ))
451 && (disk->
fsType() != QLatin1String(
"tmpfs" ))
452 && (disk->
fsType() != QLatin1String(
"debugfs" ))
453 && (disk->
fsType() != QLatin1String(
"devtmpfs" ))
454 && (disk->
mountPoint() != QLatin1String(
"/dev/swap" ))
455 && (disk->
mountPoint() != QLatin1String(
"/dev/pts" ))
456 && (disk->
mountPoint() != QLatin1String(
"/dev/shm" ))
457 && (!disk->
mountPoint().startsWith(QLatin1String(
"/sys/" )) )
458 && (!disk->
mountPoint().startsWith(QLatin1String(
"/proc/" )) ) )
461 replaceDeviceEntry(disk);
471 readingDFStdErrOut=
false;
484 for (; itr != end; ++itr)
512 disks->removeOne( disk );
521 void DiskList::replaceDeviceEntry(
DiskEntry * disk)
536 for (; itr != end; ++itr)
547 if ((pos == -1) && (disk->
mounted()) )
549 if ((disk->
fsType() == QLatin1String(
"?" )) || (disk->
fsType() == QLatin1String(
"cachefs" )))
556 for (; itr != end; ++itr)
565 int ci=odiskName.indexOf(QLatin1Char(
':' ));
566 while ((ci =odiskName.indexOf(QLatin1Char(
'/' ),ci)) > 0)
568 odiskName.replace(ci,1,QLatin1String(
"_" ));
572 if ( ( (p=disk->
deviceName().lastIndexOf(odiskName
575 && (p + odiskName.length()
578 pos = disks->indexOf(disk);
598 if ( (olddisk->
mountOptions().contains(QLatin1String(
"user" ))) &&
599 ( disk->
mountOptions().contains(QLatin1String(
"user" ))) )
604 s.append(QLatin1String(
"," ));
605 s.append(QLatin1String(
"user" ));
615 if ( disk->
deviceName().count( QLatin1Char(
'/' ) ) > olddisk->
deviceName().count( QLatin1Char(
'/' ) ) )
641 disks->insert(pos,disk);
650 #include "disklist.moc"
static const bool No_FS_Type
qulonglong kBUsed() const
QList< DiskEntry * >::const_iterator DisksConstIterator
DisksIterator disksIteratorEnd()
QString mountOptions() const
QString mountCommand() const
sets the used mountCommand for the actual DiskEntry.
DisksConstIterator disksConstIteratorBegin()
bool realCompare(const DiskEntry &s2) const
void setIconName(const QString &iconName)
QString umountCommand() const
sets the used umountCommand for the actual DiskEntry.
static const QLatin1Char Separator
void criticallyFull(DiskEntry *disk)
void setKBSize(qulonglong kb_size)
void setKBUsed(qulonglong kb_used)
qulonglong kBAvail() const
static const QLatin1Char Blank
DisksConstIterator disksConstIteratorEnd()
float percentFull() const
qulonglong kBSize() const
static QLatin1String DF_Args
void setUmountCommand(const QString &umnt)
void setKBAvail(qulonglong kb_avail)
static const float Full_Percent
DiskList(QObject *parent=0)
void setMountCommand(const QString &mnt)
QString mountPoint() const
static QLatin1String FSTAB
QList< DiskEntry * > Disks
void setMounted(bool nowMounted)
QList< DiskEntry * >::iterator DisksIterator
void deleteAllMountedAt(const QString &mountpoint)
static QLatin1String DF_Command
void setMountOptions(const QString &mountOptions)
int find(DiskEntry *disk)
static QString expandEscapes(const QString &s)
QString deviceName() const
static const QLatin1Char Delimiter
void setMountPoint(const QString &mountPoint)
DisksIterator disksIteratorBegin()
void setDeviceName(const QString &deviceName)
void setUpdatesDisabled(bool disable)
Updated need to be disabled sometimes to avoid pulling the DiskEntry out from the popupmenu handler...
void setFsType(const QString &fsType)